1 17 18 package org.apache.lenya.cms.publication; 19 20 import java.io.IOException ; 21 22 import javax.xml.parsers.ParserConfigurationException ; 23 24 import org.apache.lenya.xml.NamespaceHelper; 25 import org.apache.lenya.xml.XLink; 26 import org.apache.log4j.Category; 27 import org.w3c.dom.Element ; 28 import org.xml.sax.SAXException ; 29 30 36 public class XlinkCollection extends CollectionImpl { 37 38 private static final Category log = Category.getInstance(XlinkCollection.class); 39 40 47 public XlinkCollection(Publication publication, String id, String area) 48 throws DocumentException { 49 super(publication, id, area); 50 } 51 52 60 public XlinkCollection(Publication publication, String id, String area, String language) 61 throws DocumentException { 62 super(publication, id, area, language); 63 } 64 65 70 protected Element createDocumentElement(Document document, NamespaceHelper helper) 71 throws DocumentException { 72 Element element = super.createDocumentElement(document, helper); 73 String path = getXlinkHref(document); 74 element.setAttributeNS(XLink.XLINK_NAMESPACE, "xlink:" + XLink.ATTRIBUTE_HREF, path); 75 element.setAttributeNS(XLink.XLINK_NAMESPACE, "xlink:" + XLink.ATTRIBUTE_SHOW, "embed"); 76 element.normalize(); 77 return element; 78 } 79 80 86 protected String getXlinkHref(Document document) throws DocumentException { 87 String path = null; 88 try { 89 path = document.getFile().getCanonicalPath(); 90 } catch (IOException e) { 91 throw new DocumentException("Couldn't found the file path for the document [" 92 + document + "]", e); 93 } 94 return path; 95 } 96 97 101 protected NamespaceHelper getNamespaceHelper() throws DocumentException, 102 ParserConfigurationException , SAXException , IOException { 103 104 NamespaceHelper helper = super.getNamespaceHelper(); 105 Element collectionElement = helper.getDocument().getDocumentElement(); 106 String namespaceDeclaration = collectionElement.getAttributeNS( 107 "http://www.w3.org/2000/xmlns/", "xlink"); 108 if (namespaceDeclaration == null || !namespaceDeclaration.equals(XLink.XLINK_NAMESPACE)) { 109 collectionElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", 110 XLink.XLINK_NAMESPACE); 111 } 112 return helper; 113 } 114 115 } | Popular Tags |