1 17 18 19 20 package org.apache.lenya.cms.ant; 21 22 import org.apache.lenya.cms.publication.SiteTree; 23 import org.apache.lenya.cms.publication.DocumentException; 24 import org.apache.lenya.cms.publication.Label; 25 import org.apache.lenya.cms.publication.SiteTreeException; 26 import org.apache.lenya.cms.publication.SiteTreeNode; 27 import org.apache.tools.ant.BuildException; 28 29 32 public class RenameLabelTask extends PublicationTask { 33 private String documentid; 34 private String labelName; 35 private String area; 36 private String language; 37 38 41 public RenameLabelTask() { 42 super(); 43 } 44 45 50 protected String getArea() { 51 return area; 52 } 53 54 59 public void setArea(String area) { 60 this.area = area; 61 } 62 63 68 public void setAbsolutetreepath(String area) { 69 this.area = area; 70 } 71 72 77 protected String getDocumentid() { 78 return documentid; 79 } 80 81 86 public void setDocumentid(String string) { 87 documentid = string; 88 } 89 90 95 public String getLabelName() { 96 return labelName; 97 } 98 99 104 public void setLabelName(String labelName) { 105 this.labelName = labelName; 106 } 107 108 113 public String getLanguage() { 114 return language; 115 } 116 117 122 public void setLanguage(String language) { 123 this.language = language; 124 } 125 126 136 public void renameLabel( 137 String documentid, 138 String labelName, 139 String language, 140 String area) 141 throws SiteTreeException, DocumentException { 142 143 SiteTree tree = getPublication().getTree(area); 144 SiteTreeNode node = tree.getNode(documentid); 145 if (node == null) { 146 throw new DocumentException( 147 "Document-id " + documentid + " not found."); 148 } 149 Label label = node.getLabel(language); 150 if (label == null) { 151 throw new DocumentException( 152 "Label for language " + language + " not found."); 153 } 154 tree.removeLabel(documentid, label); 159 label.setLabel(labelName); 160 tree.addLabel(documentid, label); 161 tree.save(); 162 } 163 164 167 public void execute() throws BuildException { 168 try { 169 log("document-id corresponding to the node: " + getDocumentid()); 170 log("label name: " + getLabelName()); 171 log("language: " + getLanguage()); 172 log("area: " + getArea()); 173 renameLabel( 174 getDocumentid(), 175 getLabelName(), 176 getLanguage(), 177 getArea()); 178 } catch (Exception e) { 179 throw new BuildException(e); 180 } 181 } 182 } 183 | Popular Tags |