KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > language > markup > xsp > XSPModuleHelper


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 package org.apache.cocoon.components.language.markup.xsp;
17
18
19 import org.apache.cocoon.components.modules.input.InputModuleHelper;
20
21 import org.xml.sax.ContentHandler JavaDoc;
22 import org.xml.sax.SAXException JavaDoc;
23 import org.xml.sax.helpers.AttributesImpl JavaDoc;
24
25 import java.util.Iterator JavaDoc;
26 import java.util.Map JavaDoc;
27
28 /**
29  * Helper class that caches references to InputModules for use in
30  * XSPs. Works in conjunction with the input.xsl
31  * logicsheet. References are obtained the first time a module is
32  * accessed and kept until the page is completely displayed.
33  *
34  * @author <a HREF="mailto:haul@apache.org">Christian Haul</a>
35  * @version CVS $Id: XSPModuleHelper.java 30932 2004-07-29 17:35:38Z vgritsenko $
36  */

37 public class XSPModuleHelper extends InputModuleHelper {
38
39     private static final String JavaDoc PREFIX = "input";
40     private static final String JavaDoc URI = "http://apache.org/cocoon/xsp/input/1.0";
41
42     /**
43      * Output the request attribute values for a given name to the
44      * content handler.
45      *
46      * @param objectModel The Map objectModel
47      * @param contentHandler The SAX content handler
48      * @param module a <code>String</code> value holding the module name
49      * @param name a <code>String</code> value holding the attribute name
50      * @exception SAXException If a SAX error occurs
51      * @exception RuntimeException if an error occurs
52      */

53     public void getAttributeValues(Map JavaDoc objectModel, ContentHandler JavaDoc contentHandler, String JavaDoc module, String JavaDoc name )
54         throws SAXException JavaDoc, RuntimeException JavaDoc {
55
56         AttributesImpl JavaDoc attr = new AttributesImpl JavaDoc();
57         XSPObjectHelper.addAttribute(attr, "name", name);
58
59         XSPObjectHelper.start(URI, PREFIX, contentHandler,
60             "attribute-values", attr);
61
62         Object JavaDoc[] values = this.getAttributeValues(objectModel, module, name, null);
63
64         if (values != null) {
65             for (int i = 0; i < values.length; i++) {
66                 XSPObjectHelper.elementData(URI, PREFIX, contentHandler,
67                     "value", String.valueOf(values[i]));
68             }
69         }
70
71         XSPObjectHelper.end(URI, PREFIX, contentHandler, "attribute-values");
72     }
73
74     /**
75      * Output attribute names for a given request
76      *
77      * @param objectModel The Map objectModel
78      * @param contentHandler The SAX content handler
79      * @param module the module's name
80      * @exception SAXException If a SAX error occurs
81      * @exception RuntimeException if an error occurs
82      */

83     public void getAttributeNames(Map JavaDoc objectModel, ContentHandler JavaDoc contentHandler, String JavaDoc module)
84         throws SAXException JavaDoc, RuntimeException JavaDoc {
85
86         XSPObjectHelper.start(URI, PREFIX, contentHandler, "attribute-names");
87
88         Iterator JavaDoc iter = this.getAttributeNames(objectModel, module);
89         while (iter.hasNext()) {
90             String JavaDoc name = (String JavaDoc) iter.next();
91             XSPObjectHelper.elementData(URI, PREFIX, contentHandler, "name", name);
92         }
93
94         XSPObjectHelper.end(URI, PREFIX, contentHandler, "attribute-names");
95     }
96
97
98 }
99
Popular Tags