001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.components.language.markup.xsp;
018:
019: import org.apache.cocoon.components.modules.input.InputModuleHelper;
020:
021: import org.xml.sax.ContentHandler;
022: import org.xml.sax.SAXException;
023: import org.xml.sax.helpers.AttributesImpl;
024:
025: import java.util.Iterator;
026: import java.util.Map;
027:
028: /**
029: * Helper class that caches references to InputModules for use in
030: * XSPs. Works in conjunction with the input.xsl
031: * logicsheet. References are obtained the first time a module is
032: * accessed and kept until the page is completely displayed.
033: *
034: * @author <a href="mailto:haul@apache.org">Christian Haul</a>
035: * @version CVS $Id: XSPModuleHelper.java 433543 2006-08-22 06:22:54Z crossley $
036: */
037: public class XSPModuleHelper extends InputModuleHelper {
038:
039: private static final String PREFIX = "input";
040: private static final String URI = "http://apache.org/cocoon/xsp/input/1.0";
041:
042: /**
043: * Output the request attribute values for a given name to the
044: * content handler.
045: *
046: * @param objectModel The Map objectModel
047: * @param contentHandler The SAX content handler
048: * @param module a <code>String</code> value holding the module name
049: * @param name a <code>String</code> value holding the attribute name
050: * @exception SAXException If a SAX error occurs
051: * @exception RuntimeException if an error occurs
052: */
053: public void getAttributeValues(Map objectModel,
054: ContentHandler contentHandler, String module, String name)
055: throws SAXException, RuntimeException {
056:
057: AttributesImpl attr = new AttributesImpl();
058: XSPObjectHelper.addAttribute(attr, "name", name);
059:
060: XSPObjectHelper.start(URI, PREFIX, contentHandler,
061: "attribute-values", attr);
062:
063: Object[] values = this .getAttributeValues(objectModel, module,
064: name, null);
065:
066: if (values != null) {
067: for (int i = 0; i < values.length; i++) {
068: XSPObjectHelper.elementData(URI, PREFIX,
069: contentHandler, "value", String
070: .valueOf(values[i]));
071: }
072: }
073:
074: XSPObjectHelper.end(URI, PREFIX, contentHandler,
075: "attribute-values");
076: }
077:
078: /**
079: * Output attribute names for a given request
080: *
081: * @param objectModel The Map objectModel
082: * @param contentHandler The SAX content handler
083: * @param module the module's name
084: * @exception SAXException If a SAX error occurs
085: * @exception RuntimeException if an error occurs
086: */
087: public void getAttributeNames(Map objectModel,
088: ContentHandler contentHandler, String module)
089: throws SAXException, RuntimeException {
090:
091: XSPObjectHelper.start(URI, PREFIX, contentHandler,
092: "attribute-names");
093:
094: Iterator iter = this .getAttributeNames(objectModel, module);
095: while (iter.hasNext()) {
096: String name = (String) iter.next();
097: XSPObjectHelper.elementData(URI, PREFIX, contentHandler,
098: "name", name);
099: }
100:
101: XSPObjectHelper.end(URI, PREFIX, contentHandler,
102: "attribute-names");
103: }
104:
105: }
|