1 17 18 19 20 package org.apache.lenya.cms.ant; 21 22 import java.io.File ; 23 import java.io.FileNotFoundException ; 24 import java.io.IOException ; 25 26 import org.apache.lenya.cms.publication.Document; 27 import org.apache.lenya.cms.publication.DocumentBuildException; 28 import org.apache.lenya.cms.publication.DocumentBuilder; 29 import org.apache.lenya.cms.publication.Label; 30 import org.apache.lenya.cms.publication.Publication; 31 import org.apache.lenya.cms.publication.SiteTreeNode; 32 import org.apache.lenya.util.FileUtil; 33 import org.apache.tools.ant.BuildException; 34 35 39 public class CopyContentTask extends TwoDocumentsOperationTask { 40 41 44 public CopyContentTask() { 45 super(); 46 } 47 48 51 public void visitSiteTreeNode(SiteTreeNode node) { 52 Publication publication = getPublication(); 53 DocumentBuilder builder = publication.getDocumentBuilder(); 54 55 String srcDocumentid = node.getAbsoluteId(); 56 String destDocumentid = 57 srcDocumentid.replaceFirst( 58 getFirstdocumentid(), 59 getSecdocumentid()); 60 61 Label[] labels = node.getLabels(); 62 for (int i = 0; i < labels.length; i++) { 63 String language = labels[i].getLanguage(); 64 String srcUrl = 65 builder.buildCanonicalUrl( 66 publication, 67 getFirstarea(), 68 srcDocumentid, 69 language); 70 Document srcDoc; 71 try { 72 srcDoc = builder.buildDocument(publication, srcUrl); 73 } catch (DocumentBuildException e) { 74 throw new BuildException(e); 75 } 76 File srcFile = srcDoc.getFile(); 77 if (!srcFile.exists()) { 78 log("There are no file " + srcFile.getAbsolutePath()); 79 return; 80 } 81 String destUrl = 82 builder.buildCanonicalUrl( 83 publication, 84 getSecarea(), 85 destDocumentid, 86 language); 87 Document destDoc; 88 try { 89 destDoc = builder.buildDocument(publication, destUrl); 90 } catch (DocumentBuildException e) { 91 throw new BuildException(e); 92 } 93 File destFile = destDoc.getFile(); 94 95 log( 96 "copy file " 97 + srcFile.getAbsolutePath() 98 + "to file " 99 + destFile.getAbsolutePath()); 100 try { 101 FileUtil.copy( 102 srcFile.getAbsolutePath(), 103 destFile.getAbsolutePath()); 104 } catch (FileNotFoundException e) { 105 throw new BuildException(e); 106 } catch (IOException e) { 107 throw new BuildException(e); 108 } 109 } 110 111 } 112 } 113 | Popular Tags |