KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xml > ContentHandlerAdapter


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.xml;
30
31 import org.xml.sax.AttributeList JavaDoc;
32 import org.xml.sax.Attributes JavaDoc;
33 import org.xml.sax.ContentHandler JavaDoc;
34 import org.xml.sax.DocumentHandler JavaDoc;
35 import org.xml.sax.Locator JavaDoc;
36 import org.xml.sax.SAXException JavaDoc;
37
38 /**
39  * Loose XML parser interface. The parser can parse directly into
40  * the DOM, or it can be used as a SAX parser.
41  */

42 class ContentHandlerAdapter implements ContentHandler JavaDoc {
43   private DocumentHandler JavaDoc handler;
44   private QAttributeList attributeList;
45
46   ContentHandlerAdapter(DocumentHandler JavaDoc handler)
47   {
48     this.handler = handler;
49     attributeList = new QAttributeList();
50   }
51   
52   public void setDocumentLocator(Locator JavaDoc locator)
53   {
54     handler.setDocumentLocator(locator);
55   }
56   
57   public void startDocument()
58     throws SAXException JavaDoc
59   {
60     handler.startDocument();
61   }
62   
63   public void endDocument()
64     throws SAXException JavaDoc
65   {
66     handler.endDocument();
67   }
68   
69   public void startPrefixMapping(String JavaDoc prefix, String JavaDoc uri)
70     throws SAXException JavaDoc
71   {
72   }
73   
74   public void endPrefixMapping(String JavaDoc prefix)
75     throws SAXException JavaDoc
76   {
77   }
78   
79   public void startElement(String JavaDoc namespaceURI, String JavaDoc localName,
80                            String JavaDoc qName, Attributes JavaDoc attrs)
81     throws SAXException JavaDoc
82   {
83     attributeList.init((QAttributes) attrs);
84     
85     handler.startElement(qName, attributeList);
86   }
87   
88   public void endElement (String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName)
89     throws SAXException JavaDoc
90   {
91     handler.endElement(qName);
92   }
93   
94   public void characters(char ch[], int start, int length)
95     throws SAXException JavaDoc
96   {
97     handler.characters(ch, start, length);
98   }
99   
100   public void ignorableWhitespace(char ch[], int start, int length)
101     throws SAXException JavaDoc
102   {
103     handler.ignorableWhitespace(ch, start, length);
104   }
105   
106   public void processingInstruction (String JavaDoc target, String JavaDoc data)
107     throws SAXException JavaDoc
108   {
109     handler.processingInstruction(target, data);
110   }
111   
112   public void skippedEntity(String JavaDoc name)
113     throws SAXException JavaDoc
114   {
115   }
116
117   static class QAttributeList implements AttributeList JavaDoc {
118     private QAttributes attributes;
119
120     void init(QAttributes attributes)
121     {
122       this.attributes = attributes;
123     }
124
125     public int getLength()
126     {
127       return attributes.getLength();
128     }
129
130     public String JavaDoc getName(int i)
131     {
132       return attributes.getQName(i);
133     }
134
135     public String JavaDoc getValue(int i)
136     {
137       return attributes.getValue(i);
138     }
139
140     public String JavaDoc getValue(String JavaDoc qName)
141     {
142       return attributes.getValue(qName);
143     }
144
145     public String JavaDoc getType(int i)
146     {
147       return attributes.getType(i);
148     }
149
150     public String JavaDoc getType(String JavaDoc qName)
151     {
152       return attributes.getType(qName);
153     }
154   }
155 }
156
Popular Tags