1 17 18 19 20 package org.apache.lenya.cms.ant; 21 22 import java.io.File ; 23 24 import org.apache.lenya.cms.publication.SiteTree; 25 import org.apache.lenya.cms.publication.Document; 26 import org.apache.lenya.cms.publication.DocumentBuildException; 27 import org.apache.lenya.cms.publication.DocumentBuilder; 28 import org.apache.lenya.cms.publication.Label; 29 import org.apache.lenya.cms.publication.Publication; 30 import org.apache.lenya.cms.publication.ResourcesManager; 31 import org.apache.lenya.cms.publication.SiteTreeException; 32 import org.apache.lenya.cms.publication.SiteTreeNode; 33 import org.apache.tools.ant.BuildException; 34 35 40 public class DeactivateResourcesTask extends PublicationTask { 41 private String area; 42 private String documentid; 43 private String language; 44 45 48 public DeactivateResourcesTask() { 49 super(); 50 } 51 52 66 public void deactivateResources(String language, String documentid, String area) 67 throws SiteTreeException { 68 Publication publication = getPublication(); 69 SiteTree tree = null; 70 71 try { 72 tree = publication.getTree(area); 73 SiteTreeNode node = tree.getNode(documentid); 74 Label[] labels = null; 75 if (node != null) { 76 labels = node.getLabels(); 77 } 78 if (node == null || (labels != null && labels.length < 1)) { 79 80 DocumentBuilder builder = publication.getDocumentBuilder(); 81 String url = builder.buildCanonicalUrl(publication, area, documentid, language); 82 Document doc; 83 try { 84 doc = builder.buildDocument(publication, url); 85 } catch (DocumentBuildException e) { 86 throw new BuildException(e); 87 } 88 ResourcesManager resourcesMgr = new ResourcesManager(doc); 89 File [] resources = resourcesMgr.getResources(); 90 for (int i = 0; i < resources.length; i++) { 91 resources[i].delete(); 92 } 93 File directory = resourcesMgr.getPath(); 94 directory.delete(); 95 } 96 } catch (Exception e) { 97 throw new SiteTreeException(e); 98 } 99 } 100 101 106 public void execute() throws BuildException { 107 try { 108 log("document-id : " + getDocumentid()); 109 log("area: " + getArea()); 110 log("language : " + getArea()); 111 deactivateResources(getLanguage(), getDocumentid(), getArea()); 112 } catch (Exception e) { 113 throw new BuildException(e); 114 } 115 } 116 117 122 public String getArea() { 123 return area; 124 } 125 126 131 public String getDocumentid() { 132 return documentid; 133 } 134 135 140 public String getLanguage() { 141 return language; 142 } 143 144 150 public void setArea(String string) { 151 area = string; 152 } 153 154 160 public void setDocumentid(String string) { 161 documentid = string; 162 } 163 164 170 public void setLanguage(String string) { 171 language = string; 172 } 173 174 } 175 | Popular Tags |