1 17 18 19 20 package org.apache.lenya.cms.ant; 21 22 import org.apache.lenya.cms.publication.Document; 23 import org.apache.lenya.cms.publication.DocumentBuildException; 24 import org.apache.lenya.cms.publication.DocumentBuilder; 25 import org.apache.lenya.cms.publication.DocumentException; 26 import org.apache.lenya.cms.publication.DublinCore; 27 import org.apache.lenya.cms.publication.Label; 28 import org.apache.lenya.cms.publication.Publication; 29 import org.apache.lenya.cms.publication.SiteTree; 30 import org.apache.lenya.cms.publication.SiteTreeException; 31 import org.apache.lenya.cms.publication.SiteTreeNode; 32 import org.apache.tools.ant.BuildException; 33 34 38 public class SetIdentifier extends PublicationTask { 39 40 private String area; 41 private String documentid; 42 43 46 public SetIdentifier() { 47 super(); 48 } 49 50 53 public String getArea() { 54 return area; 55 } 56 57 60 public String getDocumentid() { 61 return documentid; 62 } 63 64 68 public void setArea(String string) { 69 area = string; 70 } 71 72 76 public void setDocumentid(String string) { 77 documentid = string; 78 } 79 80 92 public void writeDCIdentifier(Publication publication, String url) 93 throws DocumentBuildException, DocumentException { 94 assert url != null; 95 96 Document document = null; 97 document = publication.getDocumentBuilder().buildDocument(publication, url); 98 DublinCore dublincore = document.getDublinCore(); 99 dublincore.setValue("identifier", documentid); 100 dublincore.save(); 101 } 102 103 106 public void execute() throws BuildException { 107 log("document-id " + this.getDocumentid()); 108 log("area " + this.getArea()); 109 110 Publication publication = getPublication(); 111 112 String language = null; 113 String url = null; 114 SiteTree tree; 115 116 try { 117 tree = publication.getTree(area); 118 } catch (SiteTreeException e) { 119 throw new BuildException(e); 120 } 121 SiteTreeNode node = tree.getNode(documentid); 122 Label[] labels = node.getLabels(); 123 124 DocumentBuilder builder = publication.getDocumentBuilder(); 125 126 try { 127 if (labels.length < 1) { 128 log("no languages found for the node with id : " + node.getId()); 129 url = builder.buildCanonicalUrl(publication, area, documentid); 130 writeDCIdentifier(publication, url); 131 } else { 132 for (int i = 0; i < labels.length; i++) { 133 language = labels[i].getLanguage(); 134 url = builder.buildCanonicalUrl(publication, area, documentid, language); 135 writeDCIdentifier(publication, url); 136 } 137 } 138 } catch (DocumentException e1) { 139 throw new BuildException(e1); 140 } catch (DocumentBuildException e2) { 141 throw new BuildException(e2); 142 } 143 } 144 145 } 146 | Popular Tags |