1 17 18 19 20 package org.apache.lenya.cms.publication; 21 22 import org.apache.log4j.Category; 23 24 27 public final class DublinCoreHelper { 28 29 32 private DublinCoreHelper() { 33 } 34 35 private static Category log = Category.getInstance(DublinCoreHelper.class); 36 37 54 public static String getDCIdentifier(Publication publication, String area, String documentId) 55 throws SiteTreeException, DocumentBuildException, DocumentException { 56 String identifier = null; 57 String language = null; 58 String 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 |