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.Label; 26 import org.apache.lenya.cms.publication.Publication; 27 import org.apache.lenya.cms.publication.ResourcesManager; 28 import org.apache.lenya.cms.publication.SiteTree; 29 import org.apache.lenya.cms.publication.SiteTreeNode; 30 import org.apache.tools.ant.BuildException; 31 32 36 public class DeleteResourcesTask extends TwoDocumentsOperationTask { 37 38 41 public DeleteResourcesTask() { 42 super(); 43 } 44 45 50 public void visitSiteTreeNode(SiteTreeNode node) { 51 Publication publication = getPublication(); 52 DocumentBuilder builder = publication.getDocumentBuilder(); 53 54 String destDocumentid = node.getAbsoluteId(); 55 String srcDocumentid = 56 destDocumentid.replaceFirst( 57 getSecdocumentid(), 58 getFirstdocumentid()); 59 60 Label[] labels = node.getLabels(); 61 for (int i = 0; i < labels.length; i++) { 62 String language = labels[i].getLanguage(); 63 String url = 64 builder.buildCanonicalUrl( 65 publication, 66 getFirstarea(), 67 srcDocumentid, 68 language); 69 Document srcDoc; 70 try { 71 srcDoc = builder.buildDocument(publication, url); 72 } catch (DocumentBuildException e) { 73 throw new BuildException(e); 74 } 75 76 ResourcesManager resourcesMgr = new ResourcesManager(srcDoc); 77 resourcesMgr.deleteResources(); 78 } 79 } 80 81 84 public void execute() throws BuildException { 85 try { 86 log("document-id for the source :" + this.getFirstdocumentid()); 87 log("area for the source :" + this.getFirstarea()); 88 log("document-id for the destination :" + this.getSecdocumentid()); 89 log("area for the destination :" + this.getSecarea()); 90 91 Publication publication = getPublication(); 92 SiteTree tree = publication.getTree(this.getSecarea()); 93 SiteTreeNode node = tree.getNode(this.getSecdocumentid()); 94 node.acceptReverseSubtree(this); 95 } catch (Exception e) { 96 throw new BuildException(e); 97 } 98 } 99 100 } 101 | Popular Tags |