001/* 002 * Copyright 2010 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.course; 017 018import org.apache.cocoon.xml.AttributesImpl; 019import org.apache.cocoon.xml.XMLUtils; 020import org.apache.commons.lang3.StringUtils; 021import org.xml.sax.ContentHandler; 022import org.xml.sax.SAXException; 023 024import org.ametys.odf.bean.AbstractExternalAddress; 025import org.ametys.odf.cdmfr.CDMFRTagsConstants; 026 027/** 028 * LOM Sheet object 029 */ 030public class LOMSheet extends AbstractExternalAddress 031{ 032 /** 033 * Constructor 034 * @param url URL of the LOM sheet 035 * @param label Label of the LOM sheet 036 */ 037 public LOMSheet(String url, String label) 038 { 039 super(url, label); 040 } 041 042 /** 043 * Transform the LOM sheet to CDM 044 * @param contentHandler the content handler to sax into 045 * @throws SAXException if an error occurred while saxing 046 */ 047 public void toCDM(ContentHandler contentHandler) throws SAXException 048 { 049 AttributesImpl attrs = new AttributesImpl(); 050 attrs.addCDATAAttribute(CDMFRTagsConstants.ATTRIBUTE_ROLE, "learningObjectMetadata"); 051 XMLUtils.startElement(contentHandler, CDMFRTagsConstants.TAG_WEB_LINK, attrs); 052 if (StringUtils.isNotEmpty(getUrl())) 053 { 054 XMLUtils.createElement(contentHandler, CDMFRTagsConstants.TAG_HREF, getUrl()); 055 } 056 if (StringUtils.isNotEmpty(getLabel())) 057 { 058 XMLUtils.createElement(contentHandler, CDMFRTagsConstants.TAG_LINK_NAME, getLabel()); 059 } 060 XMLUtils.endElement(contentHandler, CDMFRTagsConstants.TAG_WEB_LINK); 061 } 062}