1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.commons.jxpath.xml; 18 19 import java.io.InputStream; 20 21 /** 22 * The abstract superclass of XML parsers that produce DOM Documents. 23 * The features have the same defaults as {@link javax.xml.parsers.DocumentBuilderFactory}. 24 * 25 * @author Dmitri Plotnikov 26 * @version $Revision: 652845 $ $Date: 2008-05-02 19:46:46 +0200 (Fr, 02 Mai 2008) $ 27 */ 28 public abstract class XMLParser2 implements XMLParser { 29 private boolean validating = false; 30 private boolean namespaceAware = true; 31 private boolean whitespace = false; 32 private boolean expandEntityRef = true; 33 private boolean ignoreComments = false; 34 private boolean coalescing = false; 35 36 /** 37 * Set whether the underlying parser should be validating. 38 * @param validating flag 39 * @see javax.xml.parsers.DocumentBuilderFactory#setValidating(boolean) 40 */ 41 public void setValidating(boolean validating) { 42 this.validating = validating; 43 } 44 45 /** 46 * Learn whether the underlying parser is validating. 47 * @return boolean 48 * @see javax.xml.parsers.DocumentBuilderFactory#isValidating() 49 */ 50 public boolean isValidating() { 51 return validating; 52 } 53 54 /** 55 * Learn whether the underlying parser is ns-aware. 56 * @return boolean 57 * @see javax.xml.parsers.DocumentBuilderFactory#isNamespaceAware() 58 */ 59 public boolean isNamespaceAware() { 60 return namespaceAware; 61 } 62 63 /** 64 * Set whether the underlying parser is ns-aware. 65 * @param namespaceAware flag 66 * @see javax.xml.parsers.DocumentBuilderFactory#setNamespaceAware(boolean) 67 */ 68 public void setNamespaceAware(boolean namespaceAware) { 69 this.namespaceAware = namespaceAware; 70 } 71 72 /** 73 * Set whether the underlying parser is ignoring whitespace. 74 * @param whitespace flag 75 * @see javax.xml.parsers.DocumentBuilderFactory#setIgnoringElementContentWhitespace(boolean) 76 */ 77 public void setIgnoringElementContentWhitespace(boolean whitespace) { 78 this.whitespace = whitespace; 79 } 80 81 /** 82 * Learn whether the underlying parser is ignoring whitespace. 83 * @return boolean 84 * @see javax.xml.parsers.DocumentBuilderFactory#isIgnoringElementContentWhitespace() 85 */ 86 public boolean isIgnoringElementContentWhitespace() { 87 return whitespace; 88 } 89 90 /** 91 * Learn whether the underlying parser expands entity references. 92 * @return boolean 93 * @see javax.xml.parsers.DocumentBuilderFactory#isExpandEntityReferences() 94 */ 95 public boolean isExpandEntityReferences() { 96 return expandEntityRef; 97 } 98 99 /** 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 }