KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > publication > XlinkCollection


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.lenya.cms.publication;
19
20 import java.io.IOException JavaDoc;
21
22 import javax.xml.parsers.ParserConfigurationException JavaDoc;
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 JavaDoc;
28 import org.xml.sax.SAXException JavaDoc;
29
30 /**
31  * Implementation of a Collection. In the collection are xlink inserted.
32  * @author <a HREF="mailto:edith@apache.org">Edith Chevrier </a>
33  * @author <a HREF="mailto:andreas@apache.org">Andreas Hartmann </a>
34  * @version $Id: XlinkCollection.java 123205 2004-12-23 16:23:56Z edith $
35  */

36 public class XlinkCollection extends CollectionImpl {
37
38     private static final Category log = Category.getInstance(XlinkCollection.class);
39
40     /**
41      * Ctor.
42      * @param publication A publication.
43      * @param id The document ID.
44      * @param area The area the document belongs to.
45      * @throws DocumentException when something went wrong.
46      */

47     public XlinkCollection(Publication publication, String JavaDoc id, String JavaDoc area)
48             throws DocumentException {
49         super(publication, id, area);
50     }
51
52     /**
53      * Ctor.
54      * @param publication A publication.
55      * @param id The document ID.
56      * @param area The area the document belongs to.
57      * @param language The language of the document.
58      * @throws DocumentException when something went wrong.
59      */

60     public XlinkCollection(Publication publication, String JavaDoc id, String JavaDoc area, String JavaDoc language)
61             throws DocumentException {
62         super(publication, id, area, language);
63     }
64
65     /**
66      * (non-Javadoc)
67      * @see org.apache.lenya.cms.publication.CollectionImpl#createDocumentElement(org.apache.lenya.cms.publication.Document,
68      * org.apache.lenya.xml.NamespaceHelper)
69      */

70     protected Element JavaDoc createDocumentElement(Document document, NamespaceHelper helper)
71             throws DocumentException {
72         Element JavaDoc element = super.createDocumentElement(document, helper);
73         String JavaDoc 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     /**
81      * Returns the href attribute string for a certain document.
82      * @param document The document.
83      * @return A string.
84      * @throws DocumentException when something went wrong.
85      */

86     protected String JavaDoc getXlinkHref(Document document) throws DocumentException {
87         String JavaDoc path = null;
88         try {
89             path = document.getFile().getCanonicalPath();
90         } catch (IOException JavaDoc e) {
91             throw new DocumentException("Couldn't found the file path for the document ["
92                     + document + "]", e);
93         }
94         return path;
95     }
96
97     /**
98      * Adds the XLink namespace declaration to the document element.
99      * @see org.apache.lenya.cms.publication.CollectionImpl#getNamespaceHelper()
100      */

101     protected NamespaceHelper getNamespaceHelper() throws DocumentException,
102             ParserConfigurationException JavaDoc, SAXException JavaDoc, IOException JavaDoc {
103
104         NamespaceHelper helper = super.getNamespaceHelper();
105         Element JavaDoc collectionElement = helper.getDocument().getDocumentElement();
106         String JavaDoc 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