001: //
002: // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v1.0.4-b18-fcs
003: // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
004: // Any modifications to this file will be lost upon recompilation of the source schema.
005: // Generated on: 2005.03.04 at 10:20:40 PST
006: //
007:
008: package com.nabhinc.portal.config.impl.runtime;
009:
010: import java.util.ArrayList;
011:
012: import org.xml.sax.Attributes;
013: import org.xml.sax.ContentHandler;
014: import org.xml.sax.Locator;
015: import org.xml.sax.SAXException;
016:
017: /**
018: * Receives SAX2 events and send the equivalent events to
019: * {@link com.sun.xml.bind.serializer.XMLSerializer}
020: *
021: * @author
022: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
023: */
024: public class ContentHandlerAdaptor implements ContentHandler {
025:
026: /** Stores newly declared prefix-URI mapping. */
027: private final ArrayList prefixMap = new ArrayList();
028:
029: /** Events will be sent to this object. */
030: private final XMLSerializer serializer;
031:
032: private final StringBuffer text = new StringBuffer();
033:
034: public ContentHandlerAdaptor(XMLSerializer _serializer) {
035: this .serializer = _serializer;
036: }
037:
038: public void startDocument() throws SAXException {
039: prefixMap.clear();
040: }
041:
042: public void endDocument() throws SAXException {
043: }
044:
045: public void startPrefixMapping(String prefix, String uri)
046: throws SAXException {
047: prefixMap.add(prefix);
048: prefixMap.add(uri);
049: }
050:
051: public void endPrefixMapping(String prefix) throws SAXException {
052: }
053:
054: public void startElement(String namespaceURI, String localName,
055: String qName, Attributes atts) throws SAXException {
056:
057: flushText();
058:
059: int len = atts.getLength();
060:
061: serializer.startElement(namespaceURI, localName);
062: // declare namespace events
063: for (int i = 0; i < len; i++) {
064: String qname = atts.getQName(i);
065: int idx = qname.indexOf(':');
066: String prefix = (idx == -1) ? qname : qname.substring(0,
067: idx);
068:
069: serializer.getNamespaceContext().declareNamespace(
070: atts.getURI(i), prefix, true);
071: }
072: for (int i = 0; i < prefixMap.size(); i += 2) {
073: String prefix = (String) prefixMap.get(i);
074: serializer.getNamespaceContext().declareNamespace(
075: (String) prefixMap.get(i + 1), prefix,
076: prefix.length() != 0);
077: }
078:
079: serializer.endNamespaceDecls();
080: // fire attribute events
081: for (int i = 0; i < len; i++) {
082: serializer.startAttribute(atts.getURI(i), atts
083: .getLocalName(i));
084: serializer.text(atts.getValue(i), null);
085: serializer.endAttribute();
086: }
087: prefixMap.clear();
088: serializer.endAttributes();
089: }
090:
091: public void endElement(String namespaceURI, String localName,
092: String qName) throws SAXException {
093: flushText();
094: serializer.endElement();
095: }
096:
097: private void flushText() throws SAXException {
098: if (text.length() != 0) {
099: serializer.text(text.toString(), null);
100: text.setLength(0);
101: }
102: }
103:
104: public void characters(char[] ch, int start, int length)
105: throws SAXException {
106: text.append(ch, start, length);
107: }
108:
109: public void ignorableWhitespace(char[] ch, int start, int length)
110: throws SAXException {
111: text.append(ch, start, length);
112: }
113:
114: public void setDocumentLocator(Locator locator) {
115: }
116:
117: public void processingInstruction(String target, String data)
118: throws SAXException {
119: }
120:
121: public void skippedEntity(String name) throws SAXException {
122: }
123:
124: }
|