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.commons.jxpath.xml;
018    
019    import java.io.InputStream;
020    
021    /**
022     * The abstract superclass of XML parsers that produce DOM Documents.
023     * The features have the same defaults as {@link javax.xml.parsers.DocumentBuilderFactory}.
024     *
025     * @author Dmitri Plotnikov
026     * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $
027     */
028    public abstract class XMLParser2 implements XMLParser {
029        private boolean validating = false;
030        private boolean namespaceAware = true;
031        private boolean whitespace = false;
032        private boolean expandEntityRef = true;
033        private boolean ignoreComments = false;
034        private boolean coalescing = false;
035    
036        /**
037         * Set whether the underlying parser should be validating.
038         * @param validating flag
039         * @see javax.xml.parsers.DocumentBuilderFactory#setValidating(boolean)
040         */
041        public void setValidating(boolean validating) {
042            this.validating = validating;
043        }
044    
045        /**
046         * Learn whether the underlying parser is validating.
047         * @return boolean
048         * @see javax.xml.parsers.DocumentBuilderFactory#isValidating()
049         */
050        public boolean isValidating() {
051            return validating;
052        }
053    
054        /**
055         * Learn whether the underlying parser is ns-aware.
056         * @return boolean
057         * @see javax.xml.parsers.DocumentBuilderFactory#isNamespaceAware()
058         */
059        public boolean isNamespaceAware() {
060            return namespaceAware;
061        }
062    
063        /**
064         * Set whether the underlying parser is ns-aware.
065         * @param namespaceAware flag
066         * @see javax.xml.parsers.DocumentBuilderFactory#setNamespaceAware(boolean)
067         */
068        public void setNamespaceAware(boolean namespaceAware) {
069            this.namespaceAware = namespaceAware;
070        }
071    
072        /**
073         * Set whether the underlying parser is ignoring whitespace.
074         * @param whitespace flag
075         * @see javax.xml.parsers.DocumentBuilderFactory#setIgnoringElementContentWhitespace(boolean)
076         */
077        public void setIgnoringElementContentWhitespace(boolean whitespace) {
078            this.whitespace = whitespace;
079        }
080    
081        /**
082         * Learn whether the underlying parser is ignoring whitespace.
083         * @return boolean
084         * @see javax.xml.parsers.DocumentBuilderFactory#isIgnoringElementContentWhitespace()
085         */
086        public boolean isIgnoringElementContentWhitespace() {
087            return whitespace;
088        }
089    
090        /**
091         * Learn whether the underlying parser expands entity references.
092         * @return boolean
093         * @see javax.xml.parsers.DocumentBuilderFactory#isExpandEntityReferences()
094         */
095        public boolean isExpandEntityReferences() {
096            return expandEntityRef;
097        }
098    
099        /**
100         * Set whether the underlying parser expands entity references.
101         * @param expandEntityRef flag
102         * @see javax.xml.parsers.DocumentBuilderFactory#setExpandEntityReferences(boolean)
103         */
104        public void setExpandEntityReferences(boolean expandEntityRef) {
105            this.expandEntityRef = expandEntityRef;
106        }
107    
108        /**
109         * Learn whether the underlying parser ignores comments.
110         * @return boolean
111         * @see javax.xml.parsers.DocumentBuilderFactory#isIgnoringComments()
112         */
113        public boolean isIgnoringComments() {
114            return ignoreComments;
115        }
116    
117        /**
118         * Set whether the underlying parser ignores comments.
119         * @param ignoreComments flag
120         * @see javax.xml.parsers.DocumentBuilderFactory#setIgnoringComments(boolean)
121         */
122        public void setIgnoringComments(boolean ignoreComments) {
123            this.ignoreComments = ignoreComments;
124        }
125    
126        /**
127         * Learn whether the underlying parser is coalescing.
128         * @return boolean
129         * @see javax.xml.parsers.DocumentBuilderFactory#isCoalescing()
130         */
131        public boolean isCoalescing() {
132            return coalescing;
133        }
134    
135        /**
136         * Set whether the underlying parser is coalescing.
137         * @param coalescing flag
138         * @see javax.xml.parsers.DocumentBuilderFactory#setCoalescing(boolean)
139         */
140        public void setCoalescing(boolean coalescing) {
141            this.coalescing = coalescing;
142        }
143    
144        public abstract Object parseXML(InputStream stream);
145    }