KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > cocoon > acting > LanguageExistsAction


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: LanguageExistsAction.java 43248 2004-08-17 21:58:49Z michi $ */
19
20 package org.apache.lenya.cms.cocoon.acting;
21
22 import java.util.Arrays JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import org.apache.avalon.framework.parameters.Parameters;
28 import org.apache.cocoon.acting.AbstractAction;
29 import org.apache.cocoon.environment.Redirector;
30 import org.apache.cocoon.environment.SourceResolver;
31 import org.apache.lenya.cms.publication.Document;
32 import org.apache.lenya.cms.publication.DocumentDoesNotExistException;
33 import org.apache.lenya.cms.publication.DocumentException;
34 import org.apache.lenya.cms.publication.PageEnvelope;
35 import org.apache.lenya.cms.publication.PageEnvelopeException;
36 import org.apache.lenya.cms.publication.PageEnvelopeFactory;
37
38 /**
39  * Action that checks the sitetree if there is a node with the
40  * current document-id and the current language, i.e. if the
41  * current document has a version in the current language.
42  */

43 public class LanguageExistsAction extends AbstractAction {
44
45     /**
46      * Check if the current document-id has a document for the
47      * currently requested language.
48      *
49      * If yes return an empty map, if not return null.
50      *
51      * @param redirector a <code>Redirector</code> value
52      * @param resolver a <code>SourceResolver</code> value
53      * @param objectModel a <code>Map</code> value
54      * @param source a <code>String</code> value
55      * @param parameters a <code>Parameters</code> value
56      *
57      * @return an empty <code>Map</code> if there is a version of this
58      * document for the current language, null otherwiese
59      *
60      * @exception DocumentDoesNotExistException if there is no document with the specified document-id.
61      * @exception PageEnvelopeException if the PageEnvelope could not be created.
62      * @exception DocumentException if the language information could not be fetched from the document.
63      */

64     public Map JavaDoc act(
65         Redirector redirector,
66         SourceResolver resolver,
67         Map JavaDoc objectModel,
68         String JavaDoc source,
69         Parameters parameters)
70         throws PageEnvelopeException, DocumentDoesNotExistException, DocumentException {
71
72         PageEnvelope pageEnvelope =
73             PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
74
75         Document doc = pageEnvelope.getDocument();
76         String JavaDoc language = doc.getLanguage();
77
78         if (!doc.existsInAnyLanguage()) {
79             throw new DocumentDoesNotExistException("Document " + doc.getId() + " does not exist. Check sitetree, it might need to be reloaded.");
80         }
81         List JavaDoc availableLanguages = Arrays.asList(doc.getLanguages());
82
83         if (availableLanguages.contains(language)) {
84             return Collections.unmodifiableMap(Collections.EMPTY_MAP);
85         }
86         return null;
87     }
88 }
89
Popular Tags