KickJava   Java API By Example, From Geeks To Geeks.

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


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: DocumentIdExistsAction.java 160148 2005-04-05 09:40:13Z michi $ */
19
20 package org.apache.lenya.cms.cocoon.acting;
21
22 import java.util.Collections JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.apache.avalon.framework.parameters.ParameterException;
26 import org.apache.avalon.framework.parameters.Parameters;
27 import org.apache.cocoon.acting.AbstractAction;
28 import org.apache.cocoon.environment.Redirector;
29 import org.apache.cocoon.environment.SourceResolver;
30 import org.apache.lenya.cms.publication.PageEnvelope;
31 import org.apache.lenya.cms.publication.PageEnvelopeException;
32 import org.apache.lenya.cms.publication.PageEnvelopeFactory;
33 import org.apache.lenya.cms.publication.Publication;
34 import org.apache.lenya.cms.publication.SiteTree;
35 import org.apache.lenya.cms.publication.SiteTreeException;
36
37 /**
38  * Action that checks the sitetree if there is a node with the
39  * current document-id. This is used to prevent creation of documents
40  * with non-unique document-ids
41  */

42 public class DocumentIdExistsAction extends AbstractAction {
43
44     /**
45      * Check if there is a doument in the site tree with the given
46      * document-id and area [optional].
47      *
48      * If yes return an empty map, if not return null.
49      *
50      * @param redirector a <code>Redirector</code> value
51      * @param resolver a <code>SourceResolver</code> value
52      * @param objectModel a <code>Map</code> value
53      * @param source a <code>String</code> value
54      * @param parameters a <code>Parameters</code> value
55      *
56      * @return an empty <code>Map</code> if there is a document
57      * with the given document-id and area [optional, default is
58      * the authoring area], null otherwiese
59      *
60      * @exception PageEnvelopeException if the PageEnvelope could not be created.
61      * @exception SiteTreeException if the site tree can not be accessed.
62      * @exception ParameterException if the parameters can not be accessed.
63      */

64
65     public static final String JavaDoc DOCUMENT_ID_PARAMETER_NAME = "document-id";
66     public static final String JavaDoc AREA_PARAMETER_NAME="area";
67
68     public Map JavaDoc act(
69         Redirector redirector,
70         SourceResolver resolver,
71         Map JavaDoc objectModel,
72         String JavaDoc source,
73         Parameters parameters)
74         throws PageEnvelopeException, SiteTreeException, ParameterException{
75
76         if (!parameters.isParameter(DOCUMENT_ID_PARAMETER_NAME))
77             return null;
78         String JavaDoc documentId = parameters.getParameter(DOCUMENT_ID_PARAMETER_NAME);
79
80         /* Use authoring area as default area for backward compatibility. */
81         String JavaDoc area = parameters.getParameter(AREA_PARAMETER_NAME, Publication.AUTHORING_AREA);
82
83         PageEnvelope pageEnvelope =
84             PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
85
86         SiteTree siteTree =
87             pageEnvelope.getPublication().getTree(area);
88
89         if (siteTree.getNode(documentId) != null) {
90             return Collections.EMPTY_MAP;
91         } else {
92             return null;
93         }
94     }
95 }
96
Popular Tags