/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2005 The Apache Software Foundation.
*
* Licensed 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
*
*
* 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.
*/
/**
* <p>
* This is a pipeline component which performs XInclude handling, according to the
* W3C specification for XML Inclusions.
* </p>
* <p>
* This component analyzes each event in the pipeline, looking for <include>
* elements. An <include> element is one which has a namespace of
* <code>http://www.w3.org/2001/XInclude</code> and a localname of <code>include</code>.
* When it finds an <include> element, it attempts to include the file specified
* in the <code>href</code> attribute of the element. If inclusion succeeds, all
* children of the <include> element are ignored (with the exception of
* checking for invalid children as outlined in the specification). If the inclusion
* fails, the <fallback> child of the <include> element is processed.
* </p>
* <p>
* See the <a href="http://www.w3.org/TR/xinclude/">XInclude specification</a> for
* more information on how XInclude is to be used.
* </p>
* <p>
* This component requires the following features and properties from the
* component manager that uses it:
* <ul>
* </ul>
* Optional property:
* <ul>
* </ul>
*
* Furthermore, the <code>NamespaceContext</code> used in the pipeline is required
* to be an instance of <code>XIncludeNamespaceSupport</code>.
* </p>
* <p>
* Currently, this implementation has only partial support for the XInclude specification.
* Specifically, it is missing support for XPointer document fragments. Thus, only whole
* documents can be included using this component in the pipeline.
* </p>
*
* @author Peter McCracken, IBM
* @author Michael Glavassevich, IBM
*
* @version $Id: XIncludeHandler.java,v 1.7 2010-11-01 04:40:18 joehw Exp $
*
* @see XIncludeNamespaceSupport
*/
public class XIncludeHandler
"com.sun.org.apache.xerces.internal.parsers.XIncludeParserConfiguration";
// Top Level Information Items have [included] property in infoset
/** The identifier for the Augmentation that contains the current base URI */
// used for adding [base URI] attributes
new QName(
// used for adding [language] attributes
new QName(
new QName(
"",
// Processing States
// we go into this state after a successful include (thus we ignore the children
// of the include) or after a fallback
// we go into this state after a failed include. If we don't encounter a fallback
// before we reach the end include tag, it's a fatal error
// recognized features and properties
/** Feature identifier: validation. */
/** Feature identifier: schema validation. */
/** Feature identifier: dynamic validation. */
/** Feature identifier: allow notation and unparsed entity events to be sent out of order. */
/** Feature identifier: fixup base URIs. */
/** Feature identifier: fixup language. */
/** Property identifier: symbol table. */
/** Property identifier: error reporter. */
/** Property identifier: entity resolver. */
/** property identifier: security manager. */
/** property identifier: buffer size. */
/** property identifier: access external dtd. */
/** access external dtd: file protocol
*/
/** Recognized features. */
/** Feature defaults. */
/** Recognized properties. */
/** Property defaults. */
private static final Object[] PROPERTY_DEFAULTS = { null, null, null, new Integer(XMLEntityManager.DEFAULT_BUFFER_SIZE) };
// instance variables
// for XMLDocumentFilter
// for XMLDTDFilter
// for XIncludeHandler
// for buffer size in XIncludeTextReader
// It "feels wrong" to store this value here. However,
// calculating it can be time consuming, so we cache it.
// It's never going to change in the lifetime of this XIncludeHandler
// we cache the child parser configuration, so we don't have to re-create
// the objects when the parser is re-used
// The cached child parser configuration, may contain a
// XInclude or XPointer Handler. Cache both these
// The XPointerProcessor
/**
* comma-delimited list of protocols that are allowed for the purpose
* of accessing external dtd or entity references
*/
// these are needed for text include processing
// these are needed for XML Base processing
// these are needed for Language Fixup
// used for passing features on to child XIncludeHandler objects
// The current element depth. We start at depth 0 (before we've reached any elements).
// The first element is at depth 1.
private int fDepth;
// The current element depth of the result infoset.
private int fResultDepth;
// this value must be at least 1
// Used to ensure that fallbacks are always children of include elements,
// and that include elements are never children of other include elements.
// An index contains true if the ancestor of the current element which resides
// at that depth was an include element.
// Ensures that only one fallback element can be at a single depth.
// An index contains true if we have seen any fallback elements at that depth,
// and it is only reset to false when the end tag of the parent is encountered.
// The state of the processor at each given depth.
// buffering the necessary DTD events
// flags which control whether base URI or language fixup is performed.
private boolean fFixupBaseURIs = true;
private boolean fFixupLanguage = true;
// for SAX compatibility.
// Has the value of the ALLOW_UE_AND_NOTATION_EVENTS feature
private boolean fSendUEAndNotationEvents;
// track the version of the document being parsed
private boolean fIsXML11;
// track whether a DTD is being parsed
private boolean fInDTD;
// track whether the root element of the result infoset has been processed
private boolean fSeenRootElement;
// track whether the child config needs its features refreshed
private boolean fNeedCopyFeatures = true;
// Constructors
public XIncludeHandler() {
fDepth = 0;
fSawFallback[fDepth] = false;
fSawInclude[fDepth] = false;
fNotations = new ArrayList();
fUnparsedEntities = new ArrayList();
fBaseURIScope = new IntStack();
fLiteralSystemID = new Stack();
fExpandedSystemID = new Stack();
fCurrentBaseURI = new XMLResourceIdentifierImpl();
fLanguageScope = new IntStack();
fLanguageStack = new Stack();
}
// XMLComponent methods
throws XNIException {
fDepth = 0;
fNotations.clear();
fIsXML11 = false;
fInDTD = false;
fSeenRootElement = false;
// REVISIT: Find a better method for maintaining
// the state of the XInclude processor. These arrays
// can potentially grow quite large. Cleaning them
// out on reset may be very time consuming. -- mrglavas
//
// clear the previous settings from the arrays
}
fSawFallback[i] = false;
}
fSawInclude[i] = false;
}
try {
// if parser settings have not changed return.
return;
}
}
catch (XMLConfigurationException e) {}
// parser settings changed. Need to refresh features on child config.
fNeedCopyFeatures = true;
try {
if (fChildConfig != null) {
}
}
catch (XMLConfigurationException e) {
}
try {
if (fChildConfig != null) {
}
}
catch (XMLConfigurationException e) {
fFixupBaseURIs = true;
}
try {
if (fChildConfig != null) {
}
}
catch (XMLConfigurationException e) {
fFixupLanguage = true;
}
// Get symbol table.
try {
if (fChildConfig != null) {
}
}
}
catch (XMLConfigurationException e) {
fSymbolTable = null;
}
// Get error reporter.
try {
if (fChildConfig != null) {
}
}
}
catch (XMLConfigurationException e) {
}
// Get entity resolver.
try {
if (fChildConfig != null) {
}
}
}
catch (XMLConfigurationException e) {
}
// Get security manager.
try {
if (fChildConfig != null) {
}
}
}
catch (XMLConfigurationException e) {
}
// Get buffer size.
try {
if (fChildConfig != null) {
}
}
else {
}
}
catch (XMLConfigurationException e) {
}
// Reset XML 1.0 text reader.
if (fXInclude10TextReader != null) {
}
// Reset XML 1.1 text reader.
if (fXInclude11TextReader != null) {
}
fSettings = new ParserConfigurationSettings();
// We don't want a schema validator on the new pipeline,
// so if it was enabled, we set the feature to false. If
// the validation feature was also enabled we turn on
// dynamic validation, so that DTD validation is performed
// on the included documents only if they have a DOCTYPE.
// This is consistent with the behaviour on the main pipeline.
try {
}
}
}
catch (XMLConfigurationException e) {}
// Don't reset fChildConfig -- we don't want it to share the same components.
// It will be reset when it is actually used to parse something.
} // reset(XMLComponentManager)
/**
* Returns a list of feature identifiers that are recognized by
* this component. This method may return null if no features
* are recognized by this component.
*/
} // getRecognizedFeatures():String[]
/**
* Sets the state of a feature. This method is called by the component
* manager any time after reset when a feature changes state.
* <p>
* <strong>Note:</strong> Components should silently ignore features
* that do not affect the operation of the component.
*
* @param featureId The feature identifier.
* @param state The state of the feature.
*
* @throws SAXNotRecognizedException The component should not throw
* this exception.
* @throws SAXNotSupportedException The component should not throw
* this exception.
*/
throws XMLConfigurationException {
}
fNeedCopyFeatures = true;
}
} // setFeature(String,boolean)
/**
* Returns a list of property identifiers that are recognized by
* this component. This method may return null if no properties
* are recognized by this component.
*/
} // getRecognizedProperties():String[]
/**
* Sets the value of a property. This method is called by the component
* manager any time after reset when a property changes value.
* <p>
* <strong>Note:</strong> Components should silently ignore properties
* that do not affect the operation of the component.
*
* @param propertyId The property identifier.
* @param value The value of the property.
*
* @throws SAXNotRecognizedException The component should not throw
* this exception.
* @throws SAXNotSupportedException The component should not throw
* this exception.
*/
throws XMLConfigurationException {
if (fChildConfig != null) {
}
return;
}
if (fChildConfig != null) {
}
return;
}
if (fChildConfig != null) {
}
return;
}
if (fChildConfig != null) {
}
return;
}
if (fChildConfig != null) {
}
return;
}
if (fChildConfig != null) {
}
// Reset XML 1.0 text reader.
if (fXInclude10TextReader != null) {
}
// Reset XML 1.1 text reader.
if (fXInclude11TextReader != null) {
}
}
return;
}
} // setProperty(String,Object)
/**
* Returns the default state for a feature, or null if this
* component does not want to report a default value for this
* feature.
*
* @param featureId The feature identifier.
*
* @since Xerces 2.2.0
*/
return FEATURE_DEFAULTS[i];
}
}
return null;
} // getFeatureDefault(String):Boolean
/**
* Returns the default state for a property, or null if this
* component does not want to report a default value for this
* property.
*
* @param propertyId The property identifier.
*
* @since Xerces 2.2.0
*/
return PROPERTY_DEFAULTS[i];
}
}
return null;
} // getPropertyDefault(String):Object
}
return fDocumentHandler;
}
// XMLDocumentHandler methods
/**
* Event sent at the start of the document.
*
* A fatal error will occur here, if it is detected that this document has been processed
* before.
*
* This event is only passed on to the document handler if this is the root document.
*/
public void startDocument(
throws XNIException {
// we do this to ensure that the proper location is reported in errors
// otherwise, the locator from the root document would always be used
if (!isRootDocument()
"RecursiveInclude",
}
if (!(namespaceContext instanceof XIncludeNamespaceSupport)) {
reportFatalError("IncompatibleNamespaceContext");
}
// initialize the current base URI
saveBaseURI();
augs = new AugmentationsImpl();
}
// initialize the current language
augs);
}
}
public void xmlDecl(
throws XNIException {
}
}
public void doctypeDecl(
throws XNIException {
}
}
throws XNIException {
if (!fInDTD) {
if (fDocumentHandler != null
&& getState() == STATE_NORMAL_PROCESSING) {
fDepth++;
fDepth--;
}
}
else if (fDTDHandler != null) {
}
}
public void processingInstruction(
throws XNIException {
if (!fInDTD) {
if (fDocumentHandler != null
&& getState() == STATE_NORMAL_PROCESSING) {
// we need to change the depth like this so that modifyAugmentations() works
fDepth++;
fDepth--;
}
}
else if (fDTDHandler != null) {
}
}
public void startElement(
throws XNIException {
fDepth++;
// If the last two states were fallback then this must be a descendant of an include
// child which isn't a fallback. The specification says we should ignore such elements
// and their children.
}
else {
}
// we process the xml:base and xml:lang attributes regardless
// of what type of element it is.
if (fFixupLanguage) {
}
if (isIncludeElement(element)) {
if (success) {
}
else {
}
}
else if (isFallbackElement(element)) {
this.handleFallbackElement();
}
else if (hasXIncludeNamespace(element)) {
"IncludeChild",
}
"FallbackChild",
}
if (getState() == STATE_NORMAL_PROCESSING) {
if (fResultDepth++ == 0) {
}
if (fDocumentHandler != null) {
}
}
}
else if (getState() == STATE_NORMAL_PROCESSING) {
if (fResultDepth++ == 0) {
}
if (fDocumentHandler != null) {
}
}
}
public void emptyElement(
throws XNIException {
fDepth++;
// If the last two states were fallback then this must be a descendant of an include
// child which isn't a fallback. The specification says we should ignore such elements
// and their children.
}
else {
}
// we process the xml:base and xml:lang attributes regardless
// of what type of element it is.
if (fFixupLanguage) {
}
if (isIncludeElement(element)) {
if (success) {
}
else {
reportFatalError("NoFallback",
}
}
else if (isFallbackElement(element)) {
this.handleFallbackElement();
}
else if (hasXIncludeNamespace(element)) {
"IncludeChild",
}
"FallbackChild",
}
if (getState() == STATE_NORMAL_PROCESSING) {
if (fResultDepth == 0) {
}
if (fDocumentHandler != null) {
}
}
}
else if (getState() == STATE_NORMAL_PROCESSING) {
if (fResultDepth == 0) {
}
if (fDocumentHandler != null) {
}
}
// reset the out of scope stack elements
setSawInclude(fDepth, false);
// check if an xml:base has gone out of scope
// pop the values from the stack
}
fDepth--;
}
throws XNIException {
if (isIncludeElement(element)) {
// if we're ending an include element, and we were expecting a fallback
// we check to see if the children of this include element contained a fallback
if (getState() == STATE_EXPECT_FALLBACK
reportFatalError("NoFallback",
new Object[] { "unknown" });
}
}
if (isFallbackElement(element)) {
// the state would have been set to normal processing if we were expecting the fallback element
// now that we're done processing it, we should ignore all the other children of the include element
if (getState() == STATE_NORMAL_PROCESSING) {
}
}
else if (getState() == STATE_NORMAL_PROCESSING) {
--fResultDepth;
if (fDocumentHandler != null) {
}
}
// reset the out of scope stack elements
setSawInclude(fDepth, false);
// check if an xml:base has gone out of scope
// pop the values from the stack
}
// check if an xml:lang has gone out of scope
// pop the language from the stack
}
fDepth--;
}
public void startGeneralEntity(
throws XNIException {
if (getState() == STATE_NORMAL_PROCESSING) {
if (fResultDepth == 0) {
reportFatalError("UnexpandedEntityReferenceIllegal");
}
}
else if (fDocumentHandler != null) {
}
}
}
throws XNIException {
if (fDocumentHandler != null
&& getState() == STATE_NORMAL_PROCESSING) {
}
}
throws XNIException {
if (fDocumentHandler != null
&& getState() == STATE_NORMAL_PROCESSING
&& fResultDepth != 0) {
}
}
throws XNIException {
if (getState() == STATE_NORMAL_PROCESSING) {
if (fResultDepth == 0) {
}
else if (fDocumentHandler != null) {
// we need to change the depth like this so that modifyAugmentations() works
fDepth++;
fDepth--;
}
}
}
throws XNIException {
if (fDocumentHandler != null
&& getState() == STATE_NORMAL_PROCESSING
&& fResultDepth != 0) {
}
}
if (fDocumentHandler != null
&& getState() == STATE_NORMAL_PROCESSING
&& fResultDepth != 0) {
}
}
if (fDocumentHandler != null
&& getState() == STATE_NORMAL_PROCESSING
&& fResultDepth != 0) {
}
}
if (isRootDocument()) {
if (!fSeenRootElement) {
reportFatalError("RootElementRequired");
}
if (fDocumentHandler != null) {
}
}
}
}
return fDocumentSource;
}
// DTDHandler methods
// We are only interested in the notation and unparsed entity declarations,
// the rest we just pass on
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#attributeDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String[], java.lang.String, com.sun.org.apache.xerces.internal.xni.XMLString, com.sun.org.apache.xerces.internal.xni.XMLString, com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
public void attributeDecl(
throws XNIException {
if (fDTDHandler != null) {
type,
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#elementDecl(java.lang.String, java.lang.String, com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
public void elementDecl(
throws XNIException {
if (fDTDHandler != null) {
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#endAttlist(com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
if (fDTDHandler != null) {
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#endConditional(com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
throws XNIException {
if (fDTDHandler != null) {
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#endDTD(com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
if (fDTDHandler != null) {
}
fInDTD = false;
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#endExternalSubset(com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
throws XNIException {
if (fDTDHandler != null) {
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#endParameterEntity(java.lang.String, com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
throws XNIException {
if (fDTDHandler != null) {
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#externalEntityDecl(java.lang.String, com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier, com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
public void externalEntityDecl(
throws XNIException {
if (fDTDHandler != null) {
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#getDTDSource()
*/
return fDTDSource;
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#ignoredCharacters(com.sun.org.apache.xerces.internal.xni.XMLString, com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
throws XNIException {
if (fDTDHandler != null) {
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#internalEntityDecl(java.lang.String, com.sun.org.apache.xerces.internal.xni.XMLString, com.sun.org.apache.xerces.internal.xni.XMLString, com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
public void internalEntityDecl(
throws XNIException {
if (fDTDHandler != null) {
name,
text,
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#notationDecl(java.lang.String, com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier, com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
public void notationDecl(
throws XNIException {
if (fDTDHandler != null) {
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#setDTDSource(com.sun.org.apache.xerces.internal.xni.parser.XMLDTDSource)
*/
fDTDSource = source;
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#startAttlist(java.lang.String, com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
throws XNIException {
if (fDTDHandler != null) {
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#startConditional(short, com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
throws XNIException {
if (fDTDHandler != null) {
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#startDTD(com.sun.org.apache.xerces.internal.xni.XMLLocator, com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
throws XNIException {
fInDTD = true;
if (fDTDHandler != null) {
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#startExternalSubset(com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier, com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
public void startExternalSubset(
throws XNIException {
if (fDTDHandler != null) {
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#startParameterEntity(java.lang.String, com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier, java.lang.String, com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
public void startParameterEntity(
throws XNIException {
if (fDTDHandler != null) {
name,
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#unparsedEntityDecl(java.lang.String, com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier, java.lang.String, com.sun.org.apache.xerces.internal.xni.Augmentations)
*/
public void unparsedEntityDecl(
throws XNIException {
if (fDTDHandler != null) {
name,
}
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.parser.XMLDTDSource#getDTDHandler()
*/
return fDTDHandler;
}
/* (non-Javadoc)
* @see com.sun.org.apache.xerces.internal.xni.parser.XMLDTDSource#setDTDHandler(com.sun.org.apache.xerces.internal.xni.XMLDTDHandler)
*/
}
// XIncludeHandler methods
if (fErrorReporter != null) {
// this ensures the proper location is displayed in error messages
if (fDocLocation != null) {
}
}
}
protected void handleFallbackElement() {
if (getState() == STATE_IGNORE) {
return;
}
reportFatalError("FallbackParent");
}
setSawInclude(fDepth, false);
if (getSawFallback(fDepth)) {
reportFatalError("MultipleFallbacks");
}
else {
setSawFallback(fDepth, true);
}
// Either the state is STATE_EXPECT_FALLBACK or it's STATE_IGNORE.
// If we're ignoring, we want to stay ignoring. But if we're expecting this fallback element,
// we want to signal that we should process the children.
if (getState() == STATE_EXPECT_FALLBACK) {
}
}
throws XNIException {
}
if (getState() == STATE_IGNORE) {
return true;
}
setSawInclude(fDepth, true);
// TODO: does Java use IURIs by default?
// [Definition: An internationalized URI reference, or IURI, is a URI reference that directly uses [Unicode] characters.]
// TODO: figure out what section 4.1.1 of the XInclude spec is talking about
// has to do with disallowed ASCII character escaping
// this ties in with the above IURI section, but I suspect Java already does it
}
}
reportFatalError("XpointerMissing");
}
else {
// When parse="xml" and an xpointer is specified treat
// all absences of the href attribute as a resource error.
return false;
}
}
// Check whether href is correct and perform escaping as per section 4.1.1 of the XInclude spec.
// Report fatal error if the href value contains a fragment identifier or if the value after
// escaping is a syntactically invalid URI or IRI.
try {
}
}
try {
}
}
}
}
else {
}
}
// that the value(s) don't contain disallowed characters.
}
}
if (fEntityResolver != null) {
try {
null,
href,
href,
false));
if (includedSource != null &&
!(includedSource instanceof HTTPInputSource) &&
}
}
catch (IOException e) {
"XMLResourceError",
return false;
}
}
if (includedSource == null) {
// setup an HTTPInputSource if either of the content negotation attributes were specified.
includedSource = createInputSource(null, href, fCurrentBaseURI.getExpandedSystemId(), accept, acceptLanguage);
}
else {
}
}
// Instead of always creating a new configuration, the first one can be reused
parserName = "com.sun.org.apache.xerces.internal.parsers.XPointerParserConfiguration";
true);
// use the same symbol table, error reporter, entity resolver, security manager and buffer size.
// features must be copied to child configuration
fNeedCopyFeatures = true;
// use the same namespace context
// If the xpointer attribute is present
// ???
if (fErrorReporter != null)
// ???
newHandler.setParent(this);
} else {
newHandler.setParent(this);
}
}
// If an xpointer attribute is present
// Parse the XPointer expression
try {
} catch (XNIException ex) {
// report the XPointer error as a resource error
"XMLResourceError",
return false;
}
} else {
}
// set all features on parserConfig to match this parser configuration
if (fNeedCopyFeatures) {
}
fNeedCopyFeatures = false;
try {
// necessary to make sure proper location is reported in errors
if (fErrorReporter != null) {
}
// If the xpointer attribute is present
// and it was not resolved
String reason = fXIncludeMessageFormatter.formatMessage(locale, "XPointerResolutionUnsuccessful", null);
// use the fallback
return false;
}
}
}
catch (XNIException e) {
// necessary to make sure proper location is reported in errors
if (fErrorReporter != null) {
}
}
catch (IOException e) {
// necessary to make sure proper location is reported in errors
if (fErrorReporter != null) {
}
// An IOException indicates that we had trouble reading the file, not
// that it was an invalid XML file. So we send a resource error, not a
// fatal error.
"XMLResourceError",
return false;
}
finally {
}
}
// we only care about encoding for parse="text"
try {
// Setup the appropriate text reader.
if (!fIsXML11) {
if (fXInclude10TextReader == null) {
}
else {
}
}
else {
if (fXInclude11TextReader == null) {
}
else {
}
}
textReader.parse();
}
// encoding errors
catch (MalformedByteSequenceException ex) {
}
catch (CharConversionException e) {
}
catch (IOException e) {
"TextResourceError",
return false;
}
finally {
if (textReader != null) {
try {
textReader.close();
}
catch (IOException e) {
"TextResourceError",
return false;
}
}
}
}
else {
}
return true;
}
/**
* Returns true if the element has the namespace "http://www.w3.org/2001/XInclude"
* @param element the element to check
* @return true if the element has the namespace "http://www.w3.org/2001/XInclude"
*/
// REVISIT: The namespace of this element should be bound
// already. Why are we looking it up from the namespace
// context? -- mrglavas
}
/**
* Checks if the element is an <include> element. The element must have
* the XInclude namespace, and a local name of "include".
*
* @param element the element to check
* @return true if the element is an <include> element
* @see #hasXIncludeNamespace(QName)
*/
}
/**
* Checks if the element is an <fallback> element. The element must have
* the XInclude namespace, and a local name of "fallback".
*
* @param element the element to check
* @return true if the element is an <fallback; element
* @see #hasXIncludeNamespace(QName)
*/
}
/**
* Returns true if the current [base URI] is the same as the [base URI] that
* was in effect on the include parent. This method should <em>only</em> be called
* when the current element is a top level included element, i.e. the direct child
* of a fallback element, or the root elements in an included document.
* The "include parent" is the element which, in the result infoset, will be the
* direct parent of the current element.
* @return true if the [base URIs] are the same string
*/
protected boolean sameBaseURIAsIncludeParent() {
// REVISIT: should we use File#sameFile() ?
// I think the benefit of using it is that it resolves host names
// instead of just doing a string comparison.
// TODO: [base URI] is still an open issue with the working group.
// They're deciding if xml:base should be added if the [base URI] is different in terms
// of resolving relative references, or if it should be added if they are different at all.
// Revisit this after a final decision has been made.
// The decision also affects whether we output the file name of the URI, or just the path.
}
/**
* Returns true if the current [language] is equivalent to the [language] that
* was in effect on the include parent, taking case-insensitivity into account
* as per [RFC 3066]. This method should <em>only</em> be called when the
* current element is a top level included element, i.e. the direct child
* of a fallback element, or the root elements in an included document.
* The "include parent" is the element which, in the result infoset, will be the
* direct parent of the current element.
*
* @return true if the [language] properties have the same value
* taking case-insensitivity into account as per [RFC 3066].
*/
protected boolean sameLanguageAsIncludeParent() {
}
/**
* Checks if the file indicated by the given XMLLocator has already been included
* in the current stack.
* @param includedSource the source to check for inclusion
* @return true if the source has already been included
*/
if (includedSystemId == null) {
try {
false);
}
catch (MalformedURIException e) {
reportFatalError("ExpandedSystemId");
}
}
return true;
}
if (fParentXIncludeHandler == null) {
return false;
}
}
/**
* Returns true if the current element is a top level included item. This means
* it's either the child of a fallback element, or the top level item in an
* included document
* @return true if the current element is a top level included item
*/
protected boolean isTopLevelIncludedItem() {
return isTopLevelIncludedItemViaInclude()
}
protected boolean isTopLevelIncludedItemViaInclude() {
}
protected boolean isTopLevelIncludedItemViaFallback() {
// Technically, this doesn't check if the parent was a fallback, it also
// would return true if any of the parent's sibling elements were fallbacks.
// However, this doesn't matter, since we will always be ignoring elements
// whose parent's siblings were fallbacks.
}
/**
* Processes the XMLAttributes object of startElement() calls. Performs the following tasks:
* <ul>
* <li> If the element is a top level included item whose [base URI] is different from the
* [base URI] of the include parent, then an xml:base attribute is added to specify the
* true [base URI]
* <li> For all namespace prefixes which are in-scope in an included item, but not in scope
* in the include parent, a xmlns:prefix attribute is added
* <li> For all attributes with a type of ENTITY, ENTITIES or NOTATIONS, the notations and
* unparsed entities are processed as described in the spec, sections 4.5.1 and 4.5.2
* </ul>
* @param attributes
* @return
*/
if (isTopLevelIncludedItem()) {
// Modify attributes to fix the base URI (spec 4.5.5).
// We only do it to top level included elements, which have a different
// base URI than their include parent.
if (fFixupBaseURIs && !sameBaseURIAsIncludeParent()) {
if (attributes == null) {
attributes = new XMLAttributesImpl();
}
// This causes errors with schema validation, if the schema doesn't
// specify that these elements can have an xml:base attribute
try {
uri = this.getRelativeBaseURI();
}
catch (MalformedURIException e) {
// this shouldn't ever happen, since by definition, we had to traverse
// the same URIs to even get to this place
}
int index =
uri);
}
// Modify attributes to perform language-fixup (spec 4.5.6).
// We only do it to top level included elements, which have a different
// [language] than their include parent.
if (fFixupLanguage && !sameLanguageAsIncludeParent()) {
if (attributes == null) {
attributes = new XMLAttributesImpl();
}
int index =
}
// Modify attributes of included items to do namespace-fixup. (spec 4.5.4)
while (inscopeNS.hasMoreElements()) {
if (attributes
.getValue(
== null) {
if (attributes == null) {
attributes = new XMLAttributesImpl();
}
int index =
ns,
// Need to re-declare this prefix in the current context
// in order for the SAX parser to report the appropriate
// start and end prefix mapping events. -- mrglavas
}
}
else if (
== null) {
if (attributes == null) {
attributes = new XMLAttributesImpl();
}
int index =
ns,
// Need to re-declare this prefix in the current context
// in order for the SAX parser to report the appropriate
// start and end prefix mapping events. -- mrglavas
}
}
}
}
if (attributes != null) {
for (int i = 0; i < length; i++) {
this.checkUnparsedEntity(value);
}
// 4.5.1 - Unparsed Entities
while (st.hasMoreTokens()) {
this.checkUnparsedEntity(entName);
}
}
// 4.5.2 - Notations
this.checkNotation(value);
}
/* We actually don't need to do anything for 4.5.3, because at this stage the
* value of the attribute is just a string. It will be taken care of later
* in the pipeline, when the IDREFs are actually resolved against IDs.
*
* if (type == XMLSymbols.fIDREFSymbol || type == XMLSymbols.fIDREFSSymbol) { }
*/
}
}
return attributes;
}
/**
* Returns a URI, relative to the include parent's base URI, of the current
* @return the relative URI
*/
int includeParentDepth = getIncludeParentDepth();
if (isRootDocument()) {
return relativeURI;
}
else {
}
if (includeParentDepth == 0) {
if (fParentRelativeURI == null) {
}
return relativeURI;
}
/** Check whether the scheme components are equal. */
return relativeURI;
}
/** Check whether the authority components are equal. */
return uri.getSchemeSpecificPart();
}
/**
* The scheme and authority components are equal,
* fragment which follow.
*/
if (literalPath != null) {
}
if (literalQuery != null) {
}
if (literalFragment != null) {
}
}
return literalPath;
}
else {
return relativeURI;
}
}
}
/**
* Returns the [base URI] of the include parent.
* @return the base URI of the include parent.
*/
int depth = getIncludeParentDepth();
}
else {
return this.getBaseURI(depth);
}
}
/**
* Returns the [language] of the include parent.
*
* @return the language property of the include parent.
*/
int depth = getIncludeParentDepth();
}
else {
return getLanguage(depth);
}
}
/**
* Returns the depth of the include parent. Here, the include parent is
* calculated as the last non-include or non-fallback element. It is assumed
* this method is called when the current element is a top level included item.
* Returning 0 indicates that the top level element in this document
* was an include element.
* @return the depth of the top level include element
*/
private int getIncludeParentDepth() {
// We don't start at fDepth, since it is either the top level included item,
// or an include element, when this method is called.
// This technically might not always return the first non-include/fallback
// element that it comes to, since sawFallback() returns true if a fallback
// was ever encountered at that depth. However, if a fallback was encountered
// at that depth, and it wasn't the direct descendant of the current element
// then we can't be in a situation where we're calling this method (because
// we'll always be in STATE_IGNORE)
if (!getSawInclude(i) && !getSawFallback(i)) {
return i;
}
}
// shouldn't get here, since depth 0 should never have an include element or
// a fallback element
return 0;
}
/**
* Returns the current element depth of the result infoset.
*/
private int getResultDepth() {
return fResultDepth;
}
/**
* Modify the augmentations. Add an [included] infoset item, if the current
* element is a top level included item.
* @param augs the Augmentations to modify.
* @return the modified Augmentations
*/
return modifyAugmentations(augs, false);
}
/**
* Modify the augmentations. Add an [included] infoset item, if <code>force</code>
* is true, or if the current element is a top level included item.
* @param augs the Augmentations to modify.
* @param force whether to force modification
* @return the modified Augmentations
*/
boolean force) {
if (force || isTopLevelIncludedItem()) {
augs = new AugmentationsImpl();
}
}
return augs;
}
}
protected int getState() {
}
}
}
/**
* Records that an <fallback> was encountered at the specified depth,
* as an ancestor of the current element, or as a sibling of an ancestor of the
* current element.
*
* @param depth
* @param val
*/
}
}
/**
* Returns whether an <fallback> was encountered at the specified depth,
* as an ancestor of the current element, or as a sibling of an ancestor of the
* current element.
*
* @param depth
*/
return false;
}
return fSawFallback[depth];
}
/**
* Records that an <include> was encountered at the specified depth,
* as an ancestor of the current item.
*
* @param depth
* @param val
*/
}
}
/**
* Return whether an <include> was encountered at the specified depth,
* as an ancestor of the current item.
*
* @param depth
* @return
*/
return false;
}
return fSawInclude[depth];
}
}
}
}
}
if (fErrorReporter != null) {
key,
args,
severity);
}
// we won't worry about when error reporter is null, since there should always be
// at least the default error reporter
}
/**
* Set the parent of this XIncludeHandler in the tree
* @param parent
*/
}
// used to know whether to pass declarations to the document handler
protected boolean isRootDocument() {
return fParentXIncludeHandler == null;
}
/**
* Caches an unparsed entity.
* @param name the name of the unparsed entity
* @param identifier the location of the unparsed entity
* @param augmentations any Augmentations that were on the original unparsed entity declaration
*/
protected void addUnparsedEntity(
}
/**
* Caches a notation.
* @param name the name of the notation
* @param identifier the location of the notation
* @param augmentations any Augmentations that were on the original notation declaration
*/
protected void addNotation(
}
/**
* Checks if an UnparsedEntity with the given name was declared in the DTD of the document
* for the current pipeline. If so, then the notation for the UnparsedEntity is checked.
* If that turns out okay, then the UnparsedEntity is passed to the root pipeline to
* be checked for conflicts, and sent to the root DTDHandler.
*
* @param entName the name of the UnparsedEntity to check
*/
if (index != -1) {
// first check the notation of the unparsed entity
}
}
/**
* Checks if a Notation with the given name was declared in the DTD of the document
* for the current pipeline. If so, that Notation is passed to the root pipeline to
* be checked for conflicts, and sent to the root DTDHandler
*
* @param notName the name of the Notation to check
*/
if (index != -1) {
}
}
/**
* The purpose of this method is to check if an UnparsedEntity conflicts with a previously
* declared entity in the current pipeline stack. If there is no conflict, the
* UnparsedEntity is sent by the root pipeline.
*
* @param ent the UnparsedEntity to check for conflicts
*/
if (isRootDocument()) {
if (index == -1) {
// There is no unparsed entity with the same name that we have sent.
// Calling unparsedEntityDecl() will add the entity to our local store,
// and also send the unparsed entity to the DTDHandler
id,
id,
}
}
else {
"NonDuplicateUnparsedEntity",
}
}
}
else {
}
}
/**
* The purpose of this method is to check if a Notation conflicts with a previously
* declared notation in the current pipeline stack. If there is no conflict, the
* Notation is sent by the root pipeline.
*
* @param not the Notation to check for conflicts
*/
if (isRootDocument()) {
if (index == -1) {
// There is no notation with the same name that we have sent.
}
}
else {
"NonDuplicateNotation",
}
}
}
else {
}
}
/**
* Checks whether the string only contains white space characters.
*
* @param value the text to check
*/
reportFatalError("ContentIllegalAtTopLevel");
return;
}
}
}
/**
* Checks whether the root element has already been processed.
*/
private void checkMultipleRootElements() {
if (getRootElementProcessed()) {
reportFatalError("MultipleRootElements");
}
setRootElementProcessed(true);
}
/**
* Sets whether the root element has been processed.
*/
if (isRootDocument()) {
return;
}
}
/**
* Returns whether the root element has been processed.
*/
private boolean getRootElementProcessed() {
}
// It would be nice if we didn't have to repeat code like this, but there's no interface that has
// setFeature() and addRecognizedFeatures() that the objects have in common.
protected void copyFeatures(
}
protected void copyFeatures(
}
private void copyFeatures1(
while (features.hasMoreElements()) {
try {
}
catch (XMLConfigurationException e) {
// componentManager doesn't support this feature,
// so we won't worry about it
}
}
}
private void copyFeatures1(
while (features.hasMoreElements()) {
try {
}
catch (XMLConfigurationException e) {
// componentManager doesn't support this feature,
// so we won't worry about it
}
}
}
// This is a storage class to hold information about the notations.
// We're not using XMLNotationDecl because we don't want to lose the augmentations.
protected static class Notation {
// equals() returns true if two Notations have the same name.
// Useful for searching Vectors for notations with the same name
}
public int hashCode() {
}
// from 4.5.2
// Notation items with the same [name], [system identifier],
// [public identifier], and [declaration base URI] are considered
// to be duplicate. An application may also be able to detect that
// notations are duplicate through other means. For instance, the URI
// resulting from combining the system identifier and the declaration
// base URI is the same.
}
return false;
}
}
// This is a storage class to hold information about the unparsed entities.
// We're not using XMLEntityDecl because we don't want to lose the augmentations.
protected static class UnparsedEntity {
// equals() returns true if two UnparsedEntities have the same name.
// Useful for searching Vectors for entities with the same name
}
public int hashCode() {
}
// from 4.5.1:
// Unparsed entity items with the same [name], [system identifier],
// [public identifier], [declaration base URI], [notation name], and
// [notation] are considered to be duplicate. An application may also
// be able to detect that unparsed entities are duplicate through other
// means. For instance, the URI resulting from combining the system
// identifier and the declaration base URI is the same.
}
return false;
}
}
// The following methods are used for XML Base processing
/**
* Saves the current base URI to the top of the stack.
*/
protected void saveBaseURI() {
}
/**
* Discards the URIs at the top of the stack, and restores the ones beneath it.
*/
protected void restoreBaseURI() {
fBaseURIScope.pop();
}
// The following methods are used for language processing
/**
* Saves the given language on the top of the stack.
*
* @param lanaguage the language to push onto the stack.
*/
}
/**
* Discards the language at the top of the stack, and returns the one beneath it.
*/
}
/**
* Gets the base URI that was in use at that depth
* @param depth
* @return the base URI
*/
}
/**
* Gets the language that was in use at that depth.
* @param depth
* @return the language
*/
}
/**
* Returns a relative URI, which when resolved against the base URI at the
* specified depth, will create the current base URI.
* This is accomplished by merged the literal system IDs.
* @param depth the depth at which to start creating the relative URI
* @return a relative URI to convert the base URI at the given depth to the current
* base URI
*/
// The literal system id at the location given by "start" is *in focus* at
// the given depth. So we need to adjust it to the next scope, so that we
// only process out of focus literal system ids
// If that is the last system id, then we don't need a relative URI
return "";
}
}
}
// We need to find two consecutive elements in the scope stack,
// such that the first is lower than 'depth' (or equal), and the
// second is higher.
return i;
}
// we should never get here, because 0 was put on the stack in startDocument()
return -1;
}
return i;
}
// we should never get here, because 0 was put on the stack in startDocument()
return -1;
}
/**
* Search for a xml:base attribute, and if one is found, put the new base URI into
* effect.
*/
if (baseURIValue != null) {
try {
false);
// push the new values on the stack
saveBaseURI();
}
catch (MalformedURIException e) {
// REVISIT: throw error here
}
}
}
/**
* Search for a xml:lang attribute, and if one is found, put the new
* [language] into effect.
*/
}
}
/**
* Returns <code>true</code> if the given string
* would be valid in an HTTP header.
*
* @param value string to check
* @return <code>true</code> if the given string
* would be valid in an HTTP header
*/
char ch;
return false;
}
}
return true;
}
/**
* Returns a new <code>XMLInputSource</code> from the given parameters.
*/
}
}
return httpSource;
}
// which ASCII characters need to be escaped
// the first hex character if a character needs to be escaped
// the second hex character if a character needs to be escaped
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
// initialize the above 3 arrays
static {
char ch;
for (int i = 0; i < len; i++) {
gNeedEscaping[ch] = true;
}
}
//
// Escape an href value according to (4.1.1):
//
// To convert the value of the href attribute to an IRI reference, the following characters must be escaped:
// space #x20
// the delimiters < #x3C, > #x3E and " #x22
// the unwise characters { #x7B, } #x7D, | #x7C, \ #x5C, ^ #x5E and ` #x60
//
// To convert an IRI reference to a URI reference, the following characters must also be escaped:
// the Unicode plane 0 characters #xA0 - #xD7FF, #xF900-#xFDCF, #xFDF0-#xFFEF
// the Unicode plane 1-14 characters #x10000-#x1FFFD ... #xE0000-#xEFFFD
//
int ch;
// for each character in the href
int i = 0;
for (; i < len; i++) {
// if it's not an ASCII character (excluding 0x7F), break here, and use UTF-8 encoding
if (ch > 0x7E) {
break;
}
// abort: href does not allow this character
if (ch < 0x20) {
return href;
}
if (gNeedEscaping[ch]) {
}
else {
}
}
// we saw some non-ascii character
if (i < len) {
// check if remainder of href contains any illegal characters before proceeding
for (int j = i; j < len; ++j) {
continue;
}
continue;
}
}
}
// abort: href does not allow this character
return href;
}
// get UTF-8 bytes for the remaining sub-string
byte b;
try {
// should never happen
return href;
}
// for each byte
for (i = 0; i < len; i++) {
b = bytes[i];
// for non-ascii character: make it positive, then escape
if (b < 0) {
ch = b + 256;
}
else if (gNeedEscaping[b]) {
}
else {
}
}
}
// If escaping happened, create a new string;
// otherwise, return the orginal one.
}
else {
return href;
}
}
}