View Javadoc

1   /*
2    * Copyright 2006 the original author or authors.
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  
17  package org.springframework.xml.sax;
18  
19  import org.xml.sax.ContentHandler;
20  import org.xml.sax.DTDHandler;
21  import org.xml.sax.EntityResolver;
22  import org.xml.sax.ErrorHandler;
23  import org.xml.sax.SAXNotRecognizedException;
24  import org.xml.sax.SAXNotSupportedException;
25  import org.xml.sax.XMLReader;
26  import org.xml.sax.ext.LexicalHandler;
27  
28  /**
29   * Abstract base class for SAX <code>XMLReader</code> implementations. Contains properties as defined in {@link
30   * XMLReader}, and does not recognize any features
31   *
32   * @author Arjen Poutsma
33   * @see #setContentHandler(org.xml.sax.ContentHandler)
34   * @see #setDTDHandler(org.xml.sax.DTDHandler)
35   * @see #setEntityResolver(org.xml.sax.EntityResolver)
36   * @see #setErrorHandler(org.xml.sax.ErrorHandler)
37   * @since 1.0.0
38   */
39  public abstract class AbstractXmlReader implements XMLReader {
40  
41      private DTDHandler dtdHandler;
42  
43      private ContentHandler contentHandler;
44  
45      private EntityResolver entityResolver;
46  
47      private ErrorHandler errorHandler;
48  
49      private LexicalHandler lexicalHandler;
50  
51      public ContentHandler getContentHandler() {
52          return contentHandler;
53      }
54  
55      public void setContentHandler(ContentHandler contentHandler) {
56          this.contentHandler = contentHandler;
57      }
58  
59      public void setDTDHandler(DTDHandler dtdHandler) {
60          this.dtdHandler = dtdHandler;
61      }
62  
63      public DTDHandler getDTDHandler() {
64          return dtdHandler;
65      }
66  
67      public EntityResolver getEntityResolver() {
68          return entityResolver;
69      }
70  
71      public void setEntityResolver(EntityResolver entityResolver) {
72          this.entityResolver = entityResolver;
73      }
74  
75      public ErrorHandler getErrorHandler() {
76          return errorHandler;
77      }
78  
79      public void setErrorHandler(ErrorHandler errorHandler) {
80          this.errorHandler = errorHandler;
81      }
82  
83      public LexicalHandler getLexicalHandler() {
84          return lexicalHandler;
85      }
86  
87      public void setLexicalHandler(LexicalHandler lexicalHandler) {
88          this.lexicalHandler = lexicalHandler;
89      }
90  
91      /**
92       * Throws a <code>SAXNotRecognizedException</code> exception.
93       *
94       * @throws org.xml.sax.SAXNotRecognizedException
95       *          always
96       */
97      public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
98          throw new SAXNotRecognizedException(name);
99      }
100 
101     /**
102      * Throws a <code>SAXNotRecognizedException</code> exception.
103      *
104      * @throws SAXNotRecognizedException always
105      */
106     public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
107         throw new SAXNotRecognizedException(name);
108     }
109 
110     /**
111      * Throws a <code>SAXNotRecognizedException</code> exception when the given property does not signify a lexical
112      * handler. The property name for a lexical handler is <code>http://xml.org/sax/properties/lexical-handler</code>.
113      */
114     public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
115         if ("http://xml.org/sax/properties/lexical-handler".equals(name)) {
116             return lexicalHandler;
117         }
118         else {
119             throw new SAXNotRecognizedException(name);
120         }
121     }
122 
123     /**
124      * Throws a <code>SAXNotRecognizedException</code> exception when the given property does not signify a lexical
125      * handler. The property name for a lexical handler is <code>http://xml.org/sax/properties/lexical-handler</code>.
126      */
127     public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
128         if ("http://xml.org/sax/properties/lexical-handler".equals(name)) {
129             lexicalHandler = (LexicalHandler) value;
130         }
131         else {
132             throw new SAXNotRecognizedException(name);
133         }
134     }
135 }