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.Label; 24 import org.apache.lenya.cms.publication.SiteTreeException; 25 import org.apache.lenya.cms.publication.SiteTreeNode; 26 import org.apache.tools.ant.BuildException; 27 28 31 public class RemoveLabelTask extends PublicationTask { 32 private String documentid; 33 private String labelName; 34 private String area; 35 private String language; 36 37 40 public RemoveLabelTask() { 41 super(); 42 } 43 44 49 protected String getArea() { 50 return area; 51 } 52 53 58 public void setArea(String area) { 59 this.area = area; 60 } 61 62 67 public void setAbsolutetreepath(String area) { 68 this.area = area; 69 } 70 71 76 protected String getDocumentid() { 77 return documentid; 78 } 79 80 85 public void setDocumentid(String string) { 86 documentid = string; 87 } 88 89 94 public String getLabelName() { 95 return labelName; 96 } 97 98 103 public void setLabelName(String labelName) { 104 this.labelName = labelName; 105 } 106 107 112 public String getLanguage() { 113 return language; 114 } 115 116 121 public void setLanguage(String language) { 122 this.language = language; 123 } 124 125 136 public void removeLabel( 137 String documentid, 138 String labelName, 139 String language, 140 String area) 141 throws SiteTreeException { 142 143 SiteTree tree = null; 144 Label label = null; 145 try { 146 tree = getPublication().getTree(area); 147 SiteTreeNode node = tree.getNode(documentid); 148 if (node.getLabels().length > 1) { 150 label = new Label(labelName, language); 153 tree.removeLabel(documentid, label); 154 tree.save(); 155 } 156 157 } catch (Exception e) { 158 throw new SiteTreeException( 159 "Cannot remove label " + label + " from tree " + area, 160 e); 161 } 162 163 } 164 165 168 public void execute() throws BuildException { 169 try { 170 log("document-id corresponding to the node: " + getDocumentid()); 171 log("label name: " + getLabelName()); 172 log("language: " + getLanguage()); 173 log("area: " + getArea()); 174 removeLabel( 175 getDocumentid(), 176 getLabelName(), 177 getLanguage(), 178 getArea()); 179 } catch (Exception e) { 180 throw new BuildException(e); 181 } 182 } 183 } 184 | Popular Tags |