1 17 18 19 20 package org.apache.lenya.cms.ant; 21 22 import java.io.File ; 23 import java.util.ArrayList ; 24 import java.util.Arrays ; 25 import java.util.List ; 26 27 import org.apache.lenya.cms.publication.Document; 28 import org.apache.lenya.cms.publication.DocumentBuilder; 29 import org.apache.lenya.cms.publication.Publication; 30 import org.apache.lenya.cms.publication.ResourcesManager; 31 import org.apache.lenya.util.FileUtil; 32 import org.apache.tools.ant.BuildException; 33 34 public class ResourcePublisher extends PublicationTask { 35 36 private String documentId; 37 38 41 public void execute() throws BuildException { 42 43 try { 44 DocumentBuilder builder = getPublication().getDocumentBuilder(); 45 46 String authoringUrl = 47 builder.buildCanonicalUrl(getPublication(), Publication.AUTHORING_AREA, documentId); 48 Document authoringDocument = builder.buildDocument(getPublication(), authoringUrl); 49 ResourcesManager authoringManager = new ResourcesManager(authoringDocument); 50 51 String liveUrl = 52 builder.buildCanonicalUrl(getPublication(), Publication.LIVE_AREA, documentId); 53 Document liveDocument = builder.buildDocument(getPublication(), liveUrl); 54 ResourcesManager liveManager = new ResourcesManager(liveDocument); 55 56 List resourcesList = 58 new ArrayList (Arrays.asList(authoringManager.getResources())); 59 resourcesList.addAll( 60 Arrays.asList(authoringManager.getMetaFiles())); 61 File [] resources = 62 (File [])resourcesList.toArray(new File [resourcesList.size()]); 63 File liveDirectory = liveManager.getPath(); 64 65 for (int i = 0; i < resources.length; i++) { 66 File liveResource = new File (liveDirectory, resources[i].getName()); 67 String destPath = liveResource.getAbsolutePath(); 68 69 log("Copy file [" + resources[i].getAbsolutePath() + "] to [" + destPath + "]"); 70 FileUtil.copy(resources[i].getAbsolutePath(), destPath); 71 } 72 73 } catch (Exception e) { 74 throw new BuildException(e); 75 } 76 } 77 78 82 public String getDocumentId() { 83 return documentId; 84 } 85 86 90 public void setDocumentId(String documentId) { 91 this.documentId = documentId; 92 } 93 94 } 95 | Popular Tags |