KickJava   Java API By Example, From Geeks To Geeks.

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


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 /* $Id: DublinCoreHelper.java 160149 2005-04-05 09:51:54Z michi $ */
19
20 package org.apache.lenya.cms.publication;
21
22 import org.apache.log4j.Category;
23
24 /**
25  * Facade to get the DublinCore through the cms Document
26  */

27 public final class DublinCoreHelper {
28
29     /**
30      *
31      */

32     private DublinCoreHelper() {
33     }
34
35     private static Category log = Category.getInstance(DublinCoreHelper.class);
36
37     /**
38      * Get the value of the DCIdentifier corresponding to a document id.
39      *
40      * @param publication
41      * The publication the document(s) belongs to.
42      * @param area
43      * The area the document(s) belongs to.
44      * @param documentId
45      * The document id.
46      * @return a String. The value of the DCIdentifier.
47      * @throws SiteTreeException
48      * when something with the sitetree went wrong.
49      * @throws DocumentBuildException
50      * when the building of a document failed.
51      * @throws DocumentException
52      * when something with the document went wrong.
53      */

54     public static String JavaDoc getDCIdentifier(Publication publication, String JavaDoc area, String JavaDoc documentId)
55         throws SiteTreeException, DocumentBuildException, DocumentException {
56         String JavaDoc identifier = null;
57         String JavaDoc language = null;
58         String JavaDoc url = null;
59         Document document = null;
60
61         SiteTree tree = publication.getTree(area);
62         SiteTreeNode node = tree.getNode(documentId);
63
64         DocumentBuilder builder = publication.getDocumentBuilder();
65
66         int i = 0;
67         Label[] labels = node.getLabels();
68         if (labels.length > 0) {
69             while (identifier == null && i < labels.length) {
70                 language = labels[i].getLanguage();
71                 url = builder.buildCanonicalUrl(publication, area, documentId, language);
72                 document = builder.buildDocument(publication, url);
73                 log.debug("document file : " + document.getFile().getAbsolutePath());
74                 DublinCore dublincore = document.getDublinCore();
75                 log.debug("dublincore title : " + dublincore.getFirstValue(DublinCore.ELEMENT_TITLE));
76                 identifier = dublincore.getFirstValue(DublinCore.ELEMENT_IDENTIFIER);
77                 i = i + 1;
78             }
79         }
80         if (labels.length < 1 || identifier == null) {
81             url = builder.buildCanonicalUrl(publication, area, documentId);
82             document = builder.buildDocument(publication, url);
83             DublinCore dublincore = document.getDublinCore();
84             identifier = dublincore.getFirstValue(DublinCore.ELEMENT_IDENTIFIER);
85         }
86
87         return identifier;
88     }
89 }
90
Popular Tags