KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > cocoon > components > modules > input > SitetreeModule


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: SitetreeModule.java 160148 2005-04-05 09:40:13Z michi $ */
19
20 package org.apache.lenya.cms.cocoon.components.modules.input;
21
22 import java.util.Arrays JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.apache.avalon.framework.configuration.Configuration;
27 import org.apache.avalon.framework.configuration.ConfigurationException;
28 import org.apache.cocoon.components.modules.input.AbstractInputModule;
29 import org.apache.lenya.cms.publication.PageEnvelope;
30 import org.apache.lenya.cms.publication.PageEnvelopeFactory;
31 import org.apache.lenya.cms.publication.Publication;
32 import org.apache.lenya.cms.publication.SiteTree;
33 import org.apache.lenya.cms.publication.SiteTreeNode;
34
35 public class SitetreeModule extends AbstractInputModule {
36
37     public static final String JavaDoc AUTHORING_NODE = "authoring-node";
38     public static final String JavaDoc LIVE_NODE = "live-node";
39     public static final String JavaDoc TRASH_NODE = "trash-node";
40     public static final String JavaDoc ARCHIVE_NODE = "archive-node";
41     public static final String JavaDoc FIRST_CHILD_ID = "first-child-id";
42
43     protected static final String JavaDoc[] PARAMETER_NAMES = { AUTHORING_NODE, LIVE_NODE, TRASH_NODE, ARCHIVE_NODE, FIRST_CHILD_ID };
44
45     /**
46      * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
47      */

48     public Object JavaDoc getAttribute(String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel)
49         throws ConfigurationException {
50
51         Object JavaDoc value = null;
52
53         try {
54             PageEnvelope envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
55             Publication publication = envelope.getPublication();
56
57             if (name.equals(AUTHORING_NODE)) {
58                 SiteTree authoringTree = publication.getTree(Publication.AUTHORING_AREA);
59                 value = authoringTree.getNode(envelope.getDocument().getId());
60             }
61
62             if (name.equals(LIVE_NODE)) {
63                 SiteTree liveTree = publication.getTree(Publication.LIVE_AREA);
64                 value = liveTree.getNode(envelope.getDocument().getId());
65             }
66
67             if (name.equals(TRASH_NODE)) {
68                 SiteTree trashTree = publication.getTree(Publication.TRASH_AREA);
69                 value = trashTree.getNode(envelope.getDocument().getId());
70             }
71             
72             if (name.equals(ARCHIVE_NODE)) {
73                 SiteTree archiveTree = publication.getTree(Publication.ARCHIVE_AREA);
74                 value = archiveTree.getNode(envelope.getDocument().getId());
75             }
76             
77             if (name.equals(FIRST_CHILD_ID)) {
78                 SiteTree siteTree = publication.getTree(envelope.getDocument().getArea());
79                 SiteTreeNode node = siteTree.getNode(envelope.getDocument().getId());
80                 SiteTreeNode[] children = node.getChildren(envelope.getDocument().getLanguage());
81                 if (children.length > 0){
82                     value = children[0].getId();
83                 } else {
84                     value = null;
85                 }
86             }
87
88         } catch (Exception JavaDoc e) {
89             throw new ConfigurationException("Obtaining value for [" + name + "] failed: ", e);
90         }
91
92         return value;
93     }
94
95     /**
96      * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
97      */

98     public Iterator JavaDoc getAttributeNames(Configuration modeConf, Map JavaDoc objectModel)
99         throws ConfigurationException {
100         return Arrays.asList(PARAMETER_NAMES).iterator();
101     }
102
103     /**
104      * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
105      */

106     public Object JavaDoc[] getAttributeValues(String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel)
107         throws ConfigurationException {
108         Object JavaDoc[] objects = { getAttribute(name, modeConf, objectModel) };
109         return objects;
110     }
111
112 }
113
Popular Tags