1 17 18 19 20 package org.apache.lenya.cms.publication.file; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 25 import org.apache.avalon.excalibur.io.FileUtil; 26 import org.apache.lenya.cms.publication.AbstractPublication; 27 import org.apache.lenya.cms.publication.Document; 28 import org.apache.lenya.cms.publication.DocumentSet; 29 import org.apache.lenya.cms.publication.PublicationException; 30 31 34 public class FilePublication extends AbstractPublication { 35 36 42 public FilePublication(String id, String servletContextPath) throws PublicationException { 43 super(id, servletContextPath); 44 } 45 46 51 protected File getAreaDirectory(String area) { 52 File areaDirectory = new File (getDirectory(), "content" + File.separator + area); 53 return areaDirectory; 54 } 55 56 59 public void copyDocumentToArea(Document document, String destinationArea) 60 throws PublicationException { 61 Document destinationDocument = getAreaVersion(document, destinationArea); 62 copyDocument(document, destinationDocument); 63 } 64 65 68 public void copyDocumentSource(Document sourceDocument, Document destinationDocument) 69 throws PublicationException { 70 File file = sourceDocument.getFile(); 71 File destinationDirectory = destinationDocument.getFile().getParentFile(); 72 try { 73 if (!destinationDirectory.isDirectory()) { 74 destinationDirectory.mkdirs(); 75 } 76 FileUtil.copyFileToDirectory(file, destinationDirectory); 77 destinationDocument.getDublinCore().replaceBy(sourceDocument.getDublinCore()); 78 } catch (IOException e) { 79 throw new PublicationException(e); 80 } 81 } 82 83 86 public void copyDocumentSetToArea(DocumentSet documentSet, String destinationArea) 87 throws PublicationException { 88 Document[] documents = documentSet.getDocuments(); 89 for (int i = 0; i < documents.length; i++) { 90 copyDocumentToArea(documents[i], destinationArea); 91 } 92 } 93 94 97 protected void deleteDocumentSource(Document document) throws PublicationException { 98 File file = document.getFile(); 99 boolean deleted = file.delete(); 100 if (!deleted) { 101 throw new PublicationException( 102 "Source file [" + file + "] of document [" + document + "] could not be deleted!"); 103 } 104 } 105 106 } 107 | Popular Tags |