KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > ant > ResourcePublisher


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: ResourcePublisher.java 42616 2004-03-03 12:56:33Z gregor $ */
19
20 package org.apache.lenya.cms.ant;
21
22 import java.io.File JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Arrays JavaDoc;
25 import java.util.List JavaDoc;
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 JavaDoc documentId;
37
38     /**
39      * @see org.apache.tools.ant.Task#execute()
40      */

41     public void execute() throws BuildException {
42
43         try {
44             DocumentBuilder builder = getPublication().getDocumentBuilder();
45
46             String JavaDoc 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 JavaDoc liveUrl =
52                 builder.buildCanonicalUrl(getPublication(), Publication.LIVE_AREA, documentId);
53             Document liveDocument = builder.buildDocument(getPublication(), liveUrl);
54             ResourcesManager liveManager = new ResourcesManager(liveDocument);
55             
56             // find all resource files and their associated meta files
57
List JavaDoc resourcesList =
58                 new ArrayList JavaDoc(Arrays.asList(authoringManager.getResources()));
59             resourcesList.addAll(
60                 Arrays.asList(authoringManager.getMetaFiles()));
61             File JavaDoc[] resources =
62                 (File JavaDoc[])resourcesList.toArray(new File JavaDoc[resourcesList.size()]);
63             File JavaDoc liveDirectory = liveManager.getPath();
64             
65             for (int i = 0; i < resources.length; i++) {
66                 File JavaDoc liveResource = new File JavaDoc(liveDirectory, resources[i].getName());
67                 String JavaDoc 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 JavaDoc e) {
74             throw new BuildException(e);
75         }
76     }
77
78     /**
79      * Returns the document ID.
80      * @return A document ID.
81      */

82     public String JavaDoc getDocumentId() {
83         return documentId;
84     }
85
86     /**
87      * Sets the document ID.
88      * @param documentId A document ID.
89      */

90     public void setDocumentId(String JavaDoc documentId) {
91         this.documentId = documentId;
92     }
93
94 }
95
Popular Tags