KickJava   Java API By Example, From Geeks To Geeks.

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


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.cocoon.components.modules.input;
19
20 import java.util.Collections JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.apache.avalon.framework.configuration.Configuration;
25 import org.apache.avalon.framework.configuration.ConfigurationException;
26 import org.apache.avalon.framework.service.ServiceException;
27 import org.apache.avalon.framework.service.ServiceManager;
28 import org.apache.avalon.framework.service.Serviceable;
29 import org.apache.lenya.cms.publication.DocumentHelper;
30
31 /**
32  * <p>
33  * This module constructs the document url taking into account difference in the language .version
34  * being created and used.
35  * </p>
36  * <p>
37  * Example:
38  * <code>{document-url:{page-envelope:area}:{page-envelope:document-id}:{page-envelope:document-language}}</code>
39  * </p>
40  *
41  * @version: $Id: DocumentURLModule.java 43144 2004-07-26 17:33:10Z andreas $
42  */

43 public class DocumentURLModule extends AbstractPageEnvelopeModule implements Serviceable {
44
45     private ServiceManager manager;
46
47     /**
48      * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String,
49      * org.apache.avalon.framework.configuration.Configuration, java.util.Map)
50      */

51     public Object JavaDoc getAttribute(String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel)
52             throws ConfigurationException {
53
54         String JavaDoc url;
55
56         final String JavaDoc[] attributes = name.split(":");
57
58         if (attributes.length < 3) {
59             throw new ConfigurationException("Invalid number of parameters: " + attributes.length
60                     + ". Expected 3 (area, document-id, language)");
61         }
62
63         final String JavaDoc area = attributes[0];
64         final String JavaDoc documentId = attributes[1];
65         final String JavaDoc language = attributes[2];
66
67         try {
68             DocumentHelper helper = new DocumentHelper(objectModel);
69             url = helper.getDocumentUrl(documentId, area, language);
70         } catch (Exception JavaDoc e) {
71             throw new ConfigurationException("Resolving attribute [" + name + "] failed: ", e);
72         }
73
74         return url;
75     }
76
77     /**
78      * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration,
79      * java.util.Map)
80      */

81     public Iterator JavaDoc getAttributeNames(Configuration modeConf, Map JavaDoc objectModel)
82             throws ConfigurationException {
83         return Collections.EMPTY_SET.iterator();
84     }
85
86     /**
87      * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String,
88      * org.apache.avalon.framework.configuration.Configuration, java.util.Map)
89      */

90     public Object JavaDoc[] getAttributeValues(String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel)
91             throws ConfigurationException {
92         Object JavaDoc[] objects = { getAttribute(name, modeConf, objectModel) };
93         return objects;
94     }
95
96     /**
97      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
98      */

99     public void service(ServiceManager manager) throws ServiceException {
100         this.manager = manager;
101     }
102
103 }
Popular Tags