KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > publication > file > FilePublication


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: FilePublication.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.cms.publication.file;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
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 /**
32  * A file-based publication.
33  */

34 public class FilePublication extends AbstractPublication {
35
36     /**
37      * Ctor.
38      * @param id The publication ID.
39      * @param servletContextPath The servlet context path.
40      * @throws PublicationException when something went wrong.
41      */

42     public FilePublication(String JavaDoc id, String JavaDoc servletContextPath) throws PublicationException {
43         super(id, servletContextPath);
44     }
45
46     /**
47      * Returns the directory where documents of a certain area are located.
48      * @param area
49      * @return
50      */

51     protected File JavaDoc getAreaDirectory(String JavaDoc area) {
52         File JavaDoc areaDirectory = new File JavaDoc(getDirectory(), "content" + File.separator + area);
53         return areaDirectory;
54     }
55
56     /**
57      * @see org.apache.lenya.cms.publication.AbstractPublication#copyDocumentToArea(org.apache.lenya.cms.publication.Document, java.lang.String)
58      */

59     public void copyDocumentToArea(Document document, String JavaDoc destinationArea)
60         throws PublicationException {
61         Document destinationDocument = getAreaVersion(document, destinationArea);
62         copyDocument(document, destinationDocument);
63     }
64
65     /**
66      * @see org.apache.lenya.cms.publication.AbstractPublication#copyDocumentSource(org.apache.lenya.cms.publication.Document, org.apache.lenya.cms.publication.Document)
67      */

68     public void copyDocumentSource(Document sourceDocument, Document destinationDocument)
69         throws PublicationException {
70         File JavaDoc file = sourceDocument.getFile();
71         File JavaDoc 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 JavaDoc e) {
79             throw new PublicationException(e);
80         }
81     }
82
83     /**
84      * @see org.apache.lenya.cms.publication.Publication#copyDocumentSetToArea(org.apache.lenya.cms.publication.DocumentSet, java.lang.String)
85      */

86     public void copyDocumentSetToArea(DocumentSet documentSet, String JavaDoc 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     /**
95      * @see org.apache.lenya.cms.publication.AbstractPublication#deleteDocumentSource(org.apache.lenya.cms.publication.Document)
96      */

97     protected void deleteDocumentSource(Document document) throws PublicationException {
98         File JavaDoc 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