001/* 002 * Copyright 2018 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.odf.program; 017 018import org.apache.cocoon.xml.XMLUtils; 019import org.apache.commons.lang3.StringUtils; 020import org.xml.sax.ContentHandler; 021import org.xml.sax.SAXException; 022 023import org.ametys.odf.bean.AbstractExternalAddress; 024import org.ametys.odf.cdmfr.CDMFRTagsConstants; 025 026/** 027 * Object that represents a website link : URL and label 028 */ 029public class WebsiteLink extends AbstractExternalAddress 030{ 031 /** 032 * Constructor 033 * @param url URL of the LOM sheet 034 * @param label Label of the LOM sheet 035 */ 036 public WebsiteLink(String url, String label) 037 { 038 super(url, label); 039 } 040 041 /** 042 * Transform the website to CDM 043 * @param contentHandler the content handler to sax into 044 * @throws SAXException if an error occurred while saxing 045 */ 046 public void toCDM(ContentHandler contentHandler) throws SAXException 047 { 048 XMLUtils.startElement(contentHandler, CDMFRTagsConstants.NAMESPACE_CDMFR + CDMFRTagsConstants.TAG_WEB_LINK); 049 if (StringUtils.isNotEmpty(getUrl())) 050 { 051 XMLUtils.createElement(contentHandler, CDMFRTagsConstants.TAG_HREF, getUrl()); 052 } 053 if (StringUtils.isNotEmpty(getLabel())) 054 { 055 XMLUtils.createElement(contentHandler, CDMFRTagsConstants.NAMESPACE_CDMFR + CDMFRTagsConstants.TAG_LINK_NAME, getLabel()); 056 } 057 XMLUtils.endElement(contentHandler, CDMFRTagsConstants.NAMESPACE_CDMFR + CDMFRTagsConstants.TAG_WEB_LINK); 058 } 059}