org.apache.xerces.jaxp.UnparsedEntityHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xercesImpl Show documentation
Show all versions of xercesImpl Show documentation
Xerces2 is the next generation of high performance, fully compliant XML parsers in the Apache Xerces family.
This new version of Xerces introduces the Xerces Native Interface (XNI), a complete framework for building
parser components and configurations that is extremely modular and easy to program. The Apache Xerces2 parser is
the reference implementation of XNI but other parser components, configurations, and parsers can be written
using the Xerces Native Interface. For complete design and implementation documents, refer to the XNI Manual.
Xerces2 is a fully conforming XML Schema 1.0 processor. A partial experimental implementation of the XML Schema
1.1 Structures and Datatypes Working Drafts (December 2009) and an experimental implementation of the XML Schema
Definition Language (XSD): Component Designators (SCD) Candidate Recommendation (January 2010) are provided for
evaluation. For more information, refer to the XML Schema page. Xerces2 also provides a complete implementation
of the Document Object Model Level 3 Core and Load/Save W3C Recommendations and provides a complete
implementation of the XML Inclusions (XInclude) W3C Recommendation. It also provides support for OASIS XML
Catalogs v1.1. Xerces2 is able to parse documents written according to the XML 1.1 Recommendation, except that
it does not yet provide an option to enable normalization checking as described in section 2.13 of this
specification. It also handles namespaces according to the XML Namespaces 1.1 Recommendation, and will correctly
serialize XML 1.1 documents if the DOM level 3 load/save APIs are in use.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xerces.jaxp;
import java.util.HashMap;
import org.apache.xerces.impl.validation.EntityState;
import org.apache.xerces.impl.validation.ValidationManager;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.XMLDTDHandler;
import org.apache.xerces.xni.XMLLocator;
import org.apache.xerces.xni.XMLResourceIdentifier;
import org.apache.xerces.xni.XMLString;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.parser.XMLDTDFilter;
import org.apache.xerces.xni.parser.XMLDTDSource;
/**
* This filter records which unparsed entities have been
* declared in the DTD and provides this information to a ValidationManager.
* Events are forwarded to the registered XMLDTDHandler without modification.
*
* @author Michael Glavassevich, IBM
* @version $Id: UnparsedEntityHandler.java 520055 2007-03-19 19:25:57Z mrglavas $
*/
final class UnparsedEntityHandler implements XMLDTDFilter, EntityState {
/** DTD source and handler. **/
private XMLDTDSource fDTDSource;
private XMLDTDHandler fDTDHandler;
/** Validation manager. */
private final ValidationManager fValidationManager;
/** Map for tracking unparsed entities. */
private HashMap fUnparsedEntities = null;
UnparsedEntityHandler(ValidationManager manager) {
fValidationManager = manager;
}
/*
* XMLDTDHandler methods
*/
public void startDTD(XMLLocator locator, Augmentations augmentations)
throws XNIException {
fValidationManager.setEntityState(this);
if (fDTDHandler != null) {
fDTDHandler.startDTD(locator, augmentations);
}
}
public void startParameterEntity(String name,
XMLResourceIdentifier identifier, String encoding,
Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.startParameterEntity(name, identifier, encoding, augmentations);
}
}
public void textDecl(String version, String encoding,
Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.textDecl(version, encoding, augmentations);
}
}
public void endParameterEntity(String name, Augmentations augmentations)
throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.endParameterEntity(name, augmentations);
}
}
public void startExternalSubset(XMLResourceIdentifier identifier,
Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.startExternalSubset(identifier, augmentations);
}
}
public void endExternalSubset(Augmentations augmentations)
throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.endExternalSubset(augmentations);
}
}
public void comment(XMLString text, Augmentations augmentations)
throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.comment(text, augmentations);
}
}
public void processingInstruction(String target, XMLString data,
Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.processingInstruction(target, data, augmentations);
}
}
public void elementDecl(String name, String contentModel,
Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.elementDecl(name, contentModel, augmentations);
}
}
public void startAttlist(String elementName, Augmentations augmentations)
throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.startAttlist(elementName, augmentations);
}
}
public void attributeDecl(String elementName, String attributeName,
String type, String[] enumeration, String defaultType,
XMLString defaultValue, XMLString nonNormalizedDefaultValue,
Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.attributeDecl(elementName, attributeName,
type, enumeration, defaultType,
defaultValue, nonNormalizedDefaultValue,
augmentations);
}
}
public void endAttlist(Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.endAttlist(augmentations);
}
}
public void internalEntityDecl(String name, XMLString text,
XMLString nonNormalizedText, Augmentations augmentations)
throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.internalEntityDecl(name, text,
nonNormalizedText, augmentations);
}
}
public void externalEntityDecl(String name,
XMLResourceIdentifier identifier, Augmentations augmentations)
throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.externalEntityDecl(name, identifier, augmentations);
}
}
public void unparsedEntityDecl(String name,
XMLResourceIdentifier identifier, String notation,
Augmentations augmentations) throws XNIException {
if (fUnparsedEntities == null) {
fUnparsedEntities = new HashMap();
}
fUnparsedEntities.put(name, name);
if (fDTDHandler != null) {
fDTDHandler.unparsedEntityDecl(name, identifier, notation, augmentations);
}
}
public void notationDecl(String name, XMLResourceIdentifier identifier,
Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.notationDecl(name, identifier, augmentations);
}
}
public void startConditional(short type, Augmentations augmentations)
throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.startConditional(type, augmentations);
}
}
public void ignoredCharacters(XMLString text, Augmentations augmentations)
throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.ignoredCharacters(text, augmentations);
}
}
public void endConditional(Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.endConditional(augmentations);
}
}
public void endDTD(Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.endDTD(augmentations);
}
}
public void setDTDSource(XMLDTDSource source) {
fDTDSource = source;
}
public XMLDTDSource getDTDSource() {
return fDTDSource;
}
/*
* XMLDTDSource methods
*/
public void setDTDHandler(XMLDTDHandler handler) {
fDTDHandler = handler;
}
public XMLDTDHandler getDTDHandler() {
return fDTDHandler;
}
/*
* EntityState methods
*/
public boolean isEntityDeclared(String name) {
return false;
}
public boolean isEntityUnparsed(String name) {
if (fUnparsedEntities != null) {
return fUnparsedEntities.containsKey(name);
}
return false;
}
/*
* Other methods
*/
public void reset() {
if (fUnparsedEntities != null && !fUnparsedEntities.isEmpty()) {
// should only clear this if the last document contained unparsed entities
fUnparsedEntities.clear();
}
}
}