01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.lenya.cms.cocoon.components.modules.input;
20:
21: import java.util.Collections;
22: import java.util.Iterator;
23: import java.util.Map;
24:
25: import org.apache.avalon.framework.configuration.Configuration;
26: import org.apache.avalon.framework.configuration.ConfigurationException;
27: import org.apache.lenya.cms.publication.util.DocumentHelper;
28:
29: /**
30: * <p>
31: * This module constructs the document url taking into account difference in the language .version
32: * being created and used.
33: * </p>
34: * <p>
35: * Example:
36: * <code>{document-url:{page-envelope:area}:{page-envelope:document-uuid}:{page-envelope:document-language}}</code>
37: * </p>
38: * @version $Id: DocumentURLModule.java 586495 2007-10-19 15:13:36Z rfrovarp $
39: */
40: public class DocumentURLModule extends AbstractPageEnvelopeModule {
41:
42: /**
43: * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String,
44: * org.apache.avalon.framework.configuration.Configuration, java.util.Map)
45: */
46: public Object getAttribute(String name, Configuration modeConf,
47: Map objectModel) throws ConfigurationException {
48:
49: String url;
50:
51: final String[] attributes = name.split(":");
52:
53: if (attributes.length < 3) {
54: throw new ConfigurationException(
55: "Invalid number of parameters: "
56: + attributes.length
57: + ". Expected 3 (area, document-uuid, language)");
58: }
59:
60: final String area = attributes[0];
61: final String uuid = attributes[1];
62: final String language = attributes[2];
63:
64: try {
65: DocumentHelper helper = new DocumentHelper(this .manager,
66: objectModel);
67: url = helper.getDocumentUrl(uuid, area, language);
68: } catch (Exception e) {
69: throw new ConfigurationException("Resolving attribute ["
70: + name + "] failed: ", e);
71: }
72:
73: return url;
74: }
75:
76: /**
77: * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration,
78: * java.util.Map)
79: */
80: public Iterator getAttributeNames(Configuration modeConf,
81: Map objectModel) throws ConfigurationException {
82: return Collections.EMPTY_SET.iterator();
83: }
84:
85: /**
86: * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String,
87: * org.apache.avalon.framework.configuration.Configuration, java.util.Map)
88: */
89: public Object[] getAttributeValues(String name,
90: Configuration modeConf, Map objectModel)
91: throws ConfigurationException {
92: Object[] objects = { getAttribute(name, modeConf, objectModel) };
93: return objects;
94: }
95:
96: }
|