KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > publication > PublicationHelper


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 package org.apache.lenya.cms.publication;
19
20 import java.util.List JavaDoc;
21
22 /**
23  * @version $Id: PublicationHelper.java 160151 2005-04-05 09:59:13Z michi $
24  */

25 public final class PublicationHelper {
26
27     private Publication publication;
28
29     public PublicationHelper(Publication publication) {
30         this.publication = publication;
31     }
32
33     /**
34      * Returns all documents of a publication.
35      * @param area
36      * @return
37      * @see Document
38      * @see Publication
39      */

40     public Document[] getAllDocuments(String JavaDoc area, String JavaDoc language) throws DocumentException {
41         try {
42             List JavaDoc allNodes = getPublication().getTree(area).getNode("/").preOrder();
43             Document[] documents = new Document[allNodes.size()-1];
44         
45             for(int i=1; i<allNodes.size(); i++) {
46                 documents[i-1] = DefaultDocumentBuilder.getInstance().createDocument(getPublication(), area,
47                         ((SiteTreeNode)allNodes.get(i)).getAbsoluteId(), language);
48             }
49             return documents;
50         } catch(SiteTreeException e) {
51             throw new DocumentException("Can not access sitetree to get document ids.", e);
52         } catch(DocumentBuildException e) {
53             throw new DocumentException("Can not build document from id obtained from sitetree.", e);
54         }
55     }
56
57     /**
58      * @return Returns the publication.
59      */

60     public Publication getPublication() {
61         return publication;
62     }
63 }
64
Popular Tags