src/com/sun/org/apache/xerces/internal/parsers/DOMParser.java

Print this page




  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.xerces.internal.parsers;
  22 
  23 import java.io.IOException;
  24 
  25 import com.sun.org.apache.xerces.internal.impl.Constants;
  26 import com.sun.org.apache.xerces.internal.util.EntityResolverWrapper;
  27 import com.sun.org.apache.xerces.internal.util.EntityResolver2Wrapper;
  28 import com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper;
  29 import com.sun.org.apache.xerces.internal.util.SAXMessageFormatter;
  30 import com.sun.org.apache.xerces.internal.util.Status;
  31 import com.sun.org.apache.xerces.internal.util.SymbolTable;

  32 import com.sun.org.apache.xerces.internal.xni.XNIException;
  33 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
  34 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
  35 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;
  36 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
  37 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
  38 import com.sun.org.apache.xerces.internal.xni.parser.XMLParseException;
  39 import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration;
  40 import org.w3c.dom.Node;
  41 import org.xml.sax.EntityResolver;
  42 import org.xml.sax.ErrorHandler;
  43 import org.xml.sax.InputSource;
  44 import org.xml.sax.SAXException;
  45 import org.xml.sax.SAXNotRecognizedException;
  46 import org.xml.sax.SAXNotSupportedException;
  47 import org.xml.sax.SAXParseException;
  48 import org.xml.sax.ext.EntityResolver2;
  49 import org.xml.sax.helpers.LocatorImpl;
  50 
  51 /**


  57  * @author Andy Clark, IBM
  58  *
  59  * @version $Id: DOMParser.java,v 1.7 2010-11-01 04:40:09 joehw Exp $
  60  */
  61 public class DOMParser
  62     extends AbstractDOMParser {
  63 
  64     //
  65     // Constants
  66     //
  67 
  68     // features
  69 
  70     /** Feature identifier: EntityResolver2. */
  71     protected static final String USE_ENTITY_RESOLVER2 =
  72         Constants.SAX_FEATURE_PREFIX + Constants.USE_ENTITY_RESOLVER2_FEATURE;
  73 
  74     protected static final String REPORT_WHITESPACE =
  75             Constants.SUN_SCHEMA_FEATURE_PREFIX + Constants.SUN_REPORT_IGNORED_ELEMENT_CONTENT_WHITESPACE;
  76 




  77     // recognized features:
  78     private static final String[] RECOGNIZED_FEATURES = {
  79         REPORT_WHITESPACE
  80     };
  81 
  82     // properties
  83 
  84     /** Property identifier: symbol table. */
  85     protected static final String SYMBOL_TABLE =
  86         Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
  87 
  88     /** Property identifier: XML grammar pool. */
  89     protected static final String XMLGRAMMAR_POOL =
  90         Constants.XERCES_PROPERTY_PREFIX+Constants.XMLGRAMMAR_POOL_PROPERTY;
  91 
  92     /** Recognized properties. */
  93     private static final String[] RECOGNIZED_PROPERTIES = {
  94         SYMBOL_TABLE,
  95         XMLGRAMMAR_POOL,
  96     };


 562      */
 563     public Object getProperty(String propertyId)
 564         throws SAXNotRecognizedException, SAXNotSupportedException {
 565 
 566        if (propertyId.equals(CURRENT_ELEMENT_NODE)) {
 567            boolean deferred = false;
 568            try {
 569                deferred = getFeature(DEFER_NODE_EXPANSION);
 570            }
 571            catch (XMLConfigurationException e){
 572                // ignore
 573            }
 574            if (deferred) {
 575                throw new SAXNotSupportedException("Current element node cannot be queried when node expansion is deferred.");
 576            }
 577            return (fCurrentNode!=null &&
 578                    fCurrentNode.getNodeType() == Node.ELEMENT_NODE)? fCurrentNode:null;
 579        }
 580 
 581         try {







 582             return fConfiguration.getProperty(propertyId);
 583         }
 584         catch (XMLConfigurationException e) {
 585             String identifier = e.getIdentifier();
 586             if (e.getType() == Status.NOT_RECOGNIZED) {
 587                 throw new SAXNotRecognizedException(
 588                     SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
 589                     "property-not-recognized", new Object [] {identifier}));
 590             }
 591             else {
 592                 throw new SAXNotSupportedException(
 593                     SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
 594                     "property-not-supported", new Object [] {identifier}));
 595             }
 596         }
 597 
 598     } // getProperty(String):Object
 599 
 600     /**
 601      * Returns this parser's XMLParserConfiguration.


  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.xerces.internal.parsers;
  22 
  23 import java.io.IOException;
  24 
  25 import com.sun.org.apache.xerces.internal.impl.Constants;
  26 import com.sun.org.apache.xerces.internal.util.EntityResolverWrapper;
  27 import com.sun.org.apache.xerces.internal.util.EntityResolver2Wrapper;
  28 import com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper;
  29 import com.sun.org.apache.xerces.internal.util.SAXMessageFormatter;
  30 import com.sun.org.apache.xerces.internal.util.Status;
  31 import com.sun.org.apache.xerces.internal.util.SymbolTable;
  32 import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
  33 import com.sun.org.apache.xerces.internal.xni.XNIException;
  34 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
  35 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
  36 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver;
  37 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
  38 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
  39 import com.sun.org.apache.xerces.internal.xni.parser.XMLParseException;
  40 import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration;
  41 import org.w3c.dom.Node;
  42 import org.xml.sax.EntityResolver;
  43 import org.xml.sax.ErrorHandler;
  44 import org.xml.sax.InputSource;
  45 import org.xml.sax.SAXException;
  46 import org.xml.sax.SAXNotRecognizedException;
  47 import org.xml.sax.SAXNotSupportedException;
  48 import org.xml.sax.SAXParseException;
  49 import org.xml.sax.ext.EntityResolver2;
  50 import org.xml.sax.helpers.LocatorImpl;
  51 
  52 /**


  58  * @author Andy Clark, IBM
  59  *
  60  * @version $Id: DOMParser.java,v 1.7 2010-11-01 04:40:09 joehw Exp $
  61  */
  62 public class DOMParser
  63     extends AbstractDOMParser {
  64 
  65     //
  66     // Constants
  67     //
  68 
  69     // features
  70 
  71     /** Feature identifier: EntityResolver2. */
  72     protected static final String USE_ENTITY_RESOLVER2 =
  73         Constants.SAX_FEATURE_PREFIX + Constants.USE_ENTITY_RESOLVER2_FEATURE;
  74 
  75     protected static final String REPORT_WHITESPACE =
  76             Constants.SUN_SCHEMA_FEATURE_PREFIX + Constants.SUN_REPORT_IGNORED_ELEMENT_CONTENT_WHITESPACE;
  77 
  78     /** Property identifier: Security property manager. */
  79     private static final String XML_SECURITY_PROPERTY_MANAGER =
  80             Constants.XML_SECURITY_PROPERTY_MANAGER;
  81 
  82     // recognized features:
  83     private static final String[] RECOGNIZED_FEATURES = {
  84         REPORT_WHITESPACE
  85     };
  86 
  87     // properties
  88 
  89     /** Property identifier: symbol table. */
  90     protected static final String SYMBOL_TABLE =
  91         Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
  92 
  93     /** Property identifier: XML grammar pool. */
  94     protected static final String XMLGRAMMAR_POOL =
  95         Constants.XERCES_PROPERTY_PREFIX+Constants.XMLGRAMMAR_POOL_PROPERTY;
  96 
  97     /** Recognized properties. */
  98     private static final String[] RECOGNIZED_PROPERTIES = {
  99         SYMBOL_TABLE,
 100         XMLGRAMMAR_POOL,
 101     };


 567      */
 568     public Object getProperty(String propertyId)
 569         throws SAXNotRecognizedException, SAXNotSupportedException {
 570 
 571        if (propertyId.equals(CURRENT_ELEMENT_NODE)) {
 572            boolean deferred = false;
 573            try {
 574                deferred = getFeature(DEFER_NODE_EXPANSION);
 575            }
 576            catch (XMLConfigurationException e){
 577                // ignore
 578            }
 579            if (deferred) {
 580                throw new SAXNotSupportedException("Current element node cannot be queried when node expansion is deferred.");
 581            }
 582            return (fCurrentNode!=null &&
 583                    fCurrentNode.getNodeType() == Node.ELEMENT_NODE)? fCurrentNode:null;
 584        }
 585 
 586         try {
 587             XMLSecurityPropertyManager spm = (XMLSecurityPropertyManager) 
 588                     fConfiguration.getProperty(XML_SECURITY_PROPERTY_MANAGER);
 589             int index = spm.getIndex(propertyId);
 590             if (index > -1) {
 591                 return spm.getValueByIndex(index);
 592             }
 593 
 594             return fConfiguration.getProperty(propertyId);
 595         }
 596         catch (XMLConfigurationException e) {
 597             String identifier = e.getIdentifier();
 598             if (e.getType() == Status.NOT_RECOGNIZED) {
 599                 throw new SAXNotRecognizedException(
 600                     SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
 601                     "property-not-recognized", new Object [] {identifier}));
 602             }
 603             else {
 604                 throw new SAXNotSupportedException(
 605                     SAXMessageFormatter.formatMessage(fConfiguration.getLocale(),
 606                     "property-not-supported", new Object [] {identifier}));
 607             }
 608         }
 609 
 610     } // getProperty(String):Object
 611 
 612     /**
 613      * Returns this parser's XMLParserConfiguration.