KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > publication > xsp > DocumentLanguagesHelper


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: DocumentLanguagesHelper.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.cms.publication.xsp;
21
22 import java.util.Map JavaDoc;
23
24 import org.apache.cocoon.ProcessingException;
25 import org.apache.lenya.cms.publication.Document;
26 import org.apache.lenya.cms.publication.DocumentBuilder;
27 import org.apache.lenya.cms.publication.PageEnvelope;
28 import org.apache.lenya.cms.publication.PageEnvelopeException;
29 import org.apache.lenya.cms.publication.PageEnvelopeFactory;
30
31 /**
32  * Helper class for the policy GUI.
33  */

34 public class DocumentLanguagesHelper {
35
36     private PageEnvelope pageEnvelope = null;
37
38     /**
39      * Create a new DocumentlanguageHelper.
40      *
41      * @param objectModel the objectModel
42      *
43      * @throws ProcessingException if the page envelope could not be created.
44      */

45     public DocumentLanguagesHelper(Map JavaDoc objectModel) throws ProcessingException {
46         try {
47             this.pageEnvelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
48         } catch (PageEnvelopeException e) {
49             throw new ProcessingException(e);
50         }
51     }
52
53     /**
54      * Compute the URL for a given language and the parameters given in the contructor.
55      *
56      * @param language the language
57      *
58      * @return the url for the given language
59      *
60      * @throws ProcessingException if the document for the given language could not be created.
61      */

62     public String JavaDoc getUrl(String JavaDoc language) throws ProcessingException {
63         Document doc = getDocument(language);
64         return pageEnvelope.getContext() + doc.getCompleteURL();
65     }
66
67     /**
68      * Compute the info area URL for a given language and the parameters given in the contructor.
69      *
70      * @param language the language
71      *
72      * @return the url for the given language
73      *
74      * @throws ProcessingException if the document for the given language could not be created.
75      */

76     public String JavaDoc getInfoUrl(String JavaDoc language) throws ProcessingException {
77         Document doc = getDocument(language);
78         return pageEnvelope.getContext() + doc.getCompleteInfoURL();
79     }
80
81     /**
82      * Create a document for a given language and the parameters given in the contructor.
83      *
84      * @param language the language
85      *
86      * @return the document with the given language
87      *
88      * @throws ProcessingException if the document for the given language could not be created.
89      */

90     protected Document getDocument(String JavaDoc language) throws ProcessingException {
91         DocumentBuilder builder = pageEnvelope.getPublication().getDocumentBuilder();
92         Document document = builder.buildLanguageVersion(pageEnvelope.getDocument(), language);
93         return document;
94     }
95 }
96
Popular Tags