001: /*
002: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * [See end of file]
004: */
005:
006: package com.hp.hpl.jena.rdf.arp.impl;
007:
008: import org.xml.sax.Attributes;
009: import org.xml.sax.ContentHandler;
010: import org.xml.sax.ErrorHandler;
011: import org.xml.sax.SAXException;
012: import org.xml.sax.SAXParseException;
013: import org.xml.sax.ext.LexicalHandler;
014:
015: import com.hp.hpl.jena.rdf.arp.SAX2RDF;
016:
017: /**
018: * This class is public merely to reduce the amount of irrelevant documentation
019: * generated by Javadoc for {@link SAX2RDF}.
020: *
021: * There is nothing of interest in this JavaDoc. This if (depth>0) superclass
022: * implements the functionality needed by {@link SAX2RDF}. The API given here
023: * is the familiar SAX.
024: *
025: * @author Jeremy J. Carroll
026: *
027: */
028: public class SAX2RDFImpl extends XMLHandler implements LexicalHandler,
029: ContentHandler, ErrorHandler {
030: private int depth;
031: final private String lang;
032:
033: protected SAX2RDFImpl(String base, String l) {
034: lang = l;
035: }
036:
037: protected void initParse(String b) throws SAXParseException {
038: super .initParse(b, lang == null ? "" : lang);
039:
040: }
041:
042: /*
043: * (non-Javadoc)
044: *
045: * @see org.xml.sax.ext.LexicalHandler#endCDATA()
046: */
047: public void endCDATA() throws SAXException {
048: if (depth > 0)
049: super .endCDATA();
050:
051: }
052:
053: /*
054: * (non-Javadoc)
055: *
056: * @see org.xml.sax.ext.LexicalHandler#endDTD()
057: */
058: public void endDTD() throws SAXException {
059: if (depth > 0)
060: super .endDTD();
061:
062: }
063:
064: /*
065: * (non-Javadoc)
066: *
067: * @see org.xml.sax.ext.LexicalHandler#startCDATA()
068: */
069: public void startCDATA() throws SAXException {
070: if (depth > 0)
071: super .startCDATA();
072:
073: }
074:
075: /*
076: * (non-Javadoc)
077: *
078: * @see org.xml.sax.ext.LexicalHandler#comment(char[], int, int)
079: */
080: public void comment(char[] ch, int start, int length)
081: throws SAXParseException {
082: if (depth > 0)
083: super .comment(ch, start, length);
084:
085: }
086:
087: /*
088: * (non-Javadoc)
089: *
090: * @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String)
091: */
092: public void endEntity(String name) throws SAXException {
093: if (depth > 0)
094: super .endEntity(name);
095:
096: }
097:
098: /*
099: * (non-Javadoc)
100: *
101: * @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String)
102: */
103: public void startEntity(String name) throws SAXException {
104: if (depth > 0)
105: super .startEntity(name);
106:
107: }
108:
109: /*
110: * (non-Javadoc)
111: *
112: * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String,
113: * java.lang.String, java.lang.String)
114: */
115: public void startDTD(String name, String publicId, String systemId)
116: throws SAXException {
117: if (depth > 0)
118: super .startDTD(name, publicId, systemId);
119:
120: }
121:
122: /*
123: * (non-Javadoc)
124: *
125: * @see org.xml.sax.ContentHandler#endDocument()
126: */
127: public void endDocument() throws SAXException {
128: if (depth > 0)
129: super .endDocument();
130:
131: }
132:
133: /*
134: * (non-Javadoc)
135: *
136: * @see org.xml.sax.ContentHandler#startDocument()
137: */
138: public void startDocument() throws SAXException {
139: if (depth > 0)
140: super .startDocument();
141:
142: }
143:
144: /*
145: * (non-Javadoc)
146: *
147: * @see org.xml.sax.ContentHandler#characters(char[], int, int)
148: */
149: public void characters(char[] ch, int start, int length)
150: throws SAXException {
151: if (depth > 0)
152: super .characters(ch, start, length);
153:
154: }
155:
156: /*
157: * (non-Javadoc)
158: *
159: * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
160: */
161: public void ignorableWhitespace(char[] ch, int start, int length)
162: throws SAXException {
163: if (depth > 0)
164: super .ignorableWhitespace(ch, start, length);
165:
166: }
167:
168: /*
169: * (non-Javadoc)
170: *
171: * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
172: */
173: public void endPrefixMapping(String prefix) {
174: if (depth > 0)
175: super .endPrefixMapping(prefix);
176:
177: }
178:
179: /*
180: * (non-Javadoc)
181: *
182: * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
183: */
184: public void skippedEntity(String name) throws SAXException {
185: if (depth > 0)
186: super .skippedEntity(name);
187:
188: }
189:
190: /*
191: * (non-Javadoc)
192: *
193: * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String,
194: * java.lang.String)
195: */
196: public void processingInstruction(String target, String data)
197: throws SAXException {
198: if (depth > 0)
199: super .processingInstruction(target, data);
200:
201: }
202:
203: /*
204: * (non-Javadoc)
205: *
206: * @see org.xml.sax.ContentHandler#endElement(java.lang.String,
207: * java.lang.String, java.lang.String)
208: */
209: public void endElement(String namespaceURI, String localName,
210: String qName) throws SAXException {
211: if (depth <= 0) {
212: // Does not return.
213: fatalError(new SAXParseException("Unmatched end tag: "
214: + qName, getLocator()));
215: }
216: super .endElement(namespaceURI, localName, qName);
217: if (--depth == 0) {
218: close();
219: }
220:
221: }
222:
223: protected void close() {
224: afterParse();
225: }
226:
227: /*
228: * (non-Javadoc)
229: *
230: * @see org.xml.sax.ContentHandler#startElement(java.lang.String,
231: * java.lang.String, java.lang.String, org.xml.sax.Attributes)
232: */
233: public void startElement(String namespaceURI, String localName,
234: String qName, Attributes atts) throws SAXException {
235: depth++;
236: super .startElement(namespaceURI, localName, qName, atts);
237:
238: }
239:
240: /*
241: * (non-Javadoc)
242: *
243: * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
244: */
245: public void error(SAXParseException exception)
246: throws SAXParseException {
247:
248: super .error(exception);
249:
250: }
251:
252: /*
253: * (non-Javadoc)
254: * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
255: */
256: public void fatalError(SAXParseException exception)
257: throws SAXException {
258:
259: super .fatalError(exception);
260:
261: }
262:
263: /*
264: * (non-Javadoc)
265: *
266: * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
267: */
268: public void warning(SAXParseException exception)
269: throws SAXParseException {
270: super .warning(exception);
271:
272: }
273: }
274:
275: /*
276: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP All rights
277: * reserved.
278: *
279: * Redistribution and use in source and binary forms, with or without
280: * modification, are permitted provided that the following conditions are met:
281: * 1. Redistributions of source code must retain the above copyright notice,
282: * this list of conditions and the following disclaimer. 2. Redistributions in
283: * binary form must reproduce the above copyright notice, this list of
284: * conditions and the following disclaimer in the documentation and/or other
285: * materials provided with the distribution. 3. The name of the author may not
286: * be used to endorse or promote products derived from this software without
287: * specific prior written permission.
288: *
289: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
290: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
291: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
292: * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
293: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
294: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
295: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
296: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
297: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
298: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
299: */
|