com.sun.org.apache.xerces.internal.jaxp.UnparsedEntityHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.apache.servicemix.bundles.jaxp-ri
Show all versions of org.apache.servicemix.bundles.jaxp-ri
This OSGi bundle wraps ${pkgArtifactId} ${pkgVersion} jar file.
The newest version!
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* 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 com.sun.org.apache.xerces.internal.jaxp;
import java.util.HashMap;
import com.sun.org.apache.xerces.internal.impl.validation.EntityState;
import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
import com.sun.org.apache.xerces.internal.xni.Augmentations;
import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;
import com.sun.org.apache.xerces.internal.xni.XMLLocator;
import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
import com.sun.org.apache.xerces.internal.xni.XMLString;
import com.sun.org.apache.xerces.internal.xni.XNIException;
import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDFilter;
import com.sun.org.apache.xerces.internal.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,v 1.6 2010-11-01 04:40:07 joehw Exp $
*/
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();
}
}
}