KickJava   Java API By Example, From Geeks To Geeks.

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


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: DublinCoreModule.java 42598 2004-03-01 16:18:28Z gregor $ */
19
20 package org.apache.lenya.cms.cocoon.components.modules.input;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import org.apache.avalon.framework.configuration.Configuration;
29 import org.apache.avalon.framework.configuration.ConfigurationException;
30 import org.apache.lenya.cms.publication.Document;
31 import org.apache.lenya.cms.publication.DocumentException;
32 import org.apache.lenya.cms.publication.DublinCoreImpl;
33
34 /**
35  * Input module to access the dublin core values.
36  */

37 public class DublinCoreModule extends AbstractPageEnvelopeModule {
38
39     /**
40      * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
41      */

42     public Object JavaDoc getAttribute(String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel)
43         throws ConfigurationException {
44
45         if (!Arrays.asList(DublinCoreImpl.ELEMENTS).contains(name)
46             && !Arrays.asList(DublinCoreImpl.TERMS).contains(name)) {
47             throw new ConfigurationException("The attribute [" + name + "] is not supported!");
48         }
49
50         Document document = getEnvelope(objectModel).getDocument();
51
52         if (document == null) {
53             throw new ConfigurationException("There is no document for this page envelope!");
54         }
55         Object JavaDoc value;
56         try {
57             value = document.getDublinCore().getFirstValue(name);
58         } catch (DocumentException e) {
59             throw new ConfigurationException(
60                 "Obtaining dublin core value for [" + name + "] failed: ",
61                 e);
62         }
63
64         return value;
65     }
66
67     /**
68      * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
69      */

70     public Iterator JavaDoc getAttributeNames(Configuration modeConf, Map JavaDoc objectModel)
71         throws ConfigurationException {
72
73         List JavaDoc names = new ArrayList JavaDoc();
74         names.addAll(Arrays.asList(DublinCoreImpl.ELEMENTS));
75         names.addAll(Arrays.asList(DublinCoreImpl.TERMS));
76         return names.iterator();
77     }
78
79     /**
80      * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
81      */

82     public Object JavaDoc[] getAttributeValues(String JavaDoc name, Configuration modeConf, Map JavaDoc objectModel)
83         throws ConfigurationException {
84         Object JavaDoc[] objects = { getAttribute(name, modeConf, objectModel)};
85         return objects;
86     }
87
88 }
89
Popular Tags