| Method from org.apache.xerces.xinclude.XIncludeHandler Detail: |
protected void addNotation(String name,
XMLResourceIdentifier identifier,
Augmentations augmentations) {
Notation not = new Notation();
not.name = name;
not.systemId = identifier.getLiteralSystemId();
not.publicId = identifier.getPublicId();
not.baseURI = identifier.getBaseSystemId();
not.expandedSystemId = identifier.getExpandedSystemId();
not.augmentations = augmentations;
fNotations.add(not);
}
|
protected void addUnparsedEntity(String name,
XMLResourceIdentifier identifier,
String notation,
Augmentations augmentations) {
UnparsedEntity ent = new UnparsedEntity();
ent.name = name;
ent.systemId = identifier.getLiteralSystemId();
ent.publicId = identifier.getPublicId();
ent.baseURI = identifier.getBaseSystemId();
ent.expandedSystemId = identifier.getExpandedSystemId();
ent.notation = notation;
ent.augmentations = augmentations;
fUnparsedEntities.add(ent);
}
Caches an unparsed entity. |
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 characters(XMLString text,
Augmentations augs) throws XNIException {
if (getState() == STATE_NORMAL_PROCESSING) {
if (fResultDepth == 0) {
checkWhitespace(text);
}
else if (fDocumentHandler != null) {
// we need to change the depth like this so that modifyAugmentations() works
fDepth++;
augs = modifyAugmentations(augs);
fDocumentHandler.characters(text, augs);
fDepth--;
}
}
}
|
protected void checkAndSendNotation(XIncludeHandler.Notation not) {
if (isRootDocument()) {
int index = fNotations.indexOf(not);
if (index == -1) {
// There is no notation with the same name that we have sent.
XMLResourceIdentifier id =
new XMLResourceIdentifierImpl(
not.publicId,
not.systemId,
not.baseURI,
not.expandedSystemId);
addNotation(not.name, id, not.augmentations);
if (fSendUEAndNotationEvents && fDTDHandler != null) {
fDTDHandler.notationDecl(not.name, id, not.augmentations);
}
}
else {
Notation localNotation = (Notation)fNotations.get(index);
if (!not.isDuplicate(localNotation)) {
reportFatalError(
"NonDuplicateNotation",
new Object[] { not.name });
}
}
}
else {
fParentXIncludeHandler.checkAndSendNotation(not);
}
}
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. |
protected void checkAndSendUnparsedEntity(XIncludeHandler.UnparsedEntity ent) {
if (isRootDocument()) {
int index = fUnparsedEntities.indexOf(ent);
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
XMLResourceIdentifier id =
new XMLResourceIdentifierImpl(
ent.publicId,
ent.systemId,
ent.baseURI,
ent.expandedSystemId);
addUnparsedEntity(
ent.name,
id,
ent.notation,
ent.augmentations);
if (fSendUEAndNotationEvents && fDTDHandler != null) {
fDTDHandler.unparsedEntityDecl(
ent.name,
id,
ent.notation,
ent.augmentations);
}
}
else {
UnparsedEntity localEntity =
(UnparsedEntity)fUnparsedEntities.get(index);
if (!ent.isDuplicate(localEntity)) {
reportFatalError(
"NonDuplicateUnparsedEntity",
new Object[] { ent.name });
}
}
}
else {
fParentXIncludeHandler.checkAndSendUnparsedEntity(ent);
}
}
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. |
protected void checkNotation(String notName) {
Notation not = new Notation();
not.name = notName;
int index = fNotations.indexOf(not);
if (index != -1) {
not = (Notation)fNotations.get(index);
checkAndSendNotation(not);
}
}
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 |
protected void checkUnparsedEntity(String entName) {
UnparsedEntity ent = new UnparsedEntity();
ent.name = entName;
int index = fUnparsedEntities.indexOf(ent);
if (index != -1) {
ent = (UnparsedEntity)fUnparsedEntities.get(index);
// first check the notation of the unparsed entity
checkNotation(ent.notation);
checkAndSendUnparsedEntity(ent);
}
}
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. |
public void comment(XMLString text,
Augmentations augs) throws XNIException {
if (!fInDTD) {
if (fDocumentHandler != null
&& getState() == STATE_NORMAL_PROCESSING) {
fDepth++;
augs = modifyAugmentations(augs);
fDocumentHandler.comment(text, augs);
fDepth--;
}
}
else if (fDTDHandler != null) {
fDTDHandler.comment(text, augs);
}
}
|
protected void copyFeatures(XMLComponentManager from,
ParserConfigurationSettings to) {
Enumeration features = Constants.getXercesFeatures();
copyFeatures1(features, Constants.XERCES_FEATURE_PREFIX, from, to);
features = Constants.getSAXFeatures();
copyFeatures1(features, Constants.SAX_FEATURE_PREFIX, from, to);
}
|
protected void copyFeatures(XMLComponentManager from,
XMLParserConfiguration to) {
Enumeration features = Constants.getXercesFeatures();
copyFeatures1(features, Constants.XERCES_FEATURE_PREFIX, from, to);
features = Constants.getSAXFeatures();
copyFeatures1(features, Constants.SAX_FEATURE_PREFIX, from, to);
}
|
public void doctypeDecl(String rootElement,
String publicId,
String systemId,
Augmentations augs) throws XNIException {
if (isRootDocument() && fDocumentHandler != null) {
fDocumentHandler.doctypeDecl(rootElement, publicId, systemId, augs);
}
}
|
public void elementDecl(String name,
String contentModel,
Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.elementDecl(name, contentModel, augmentations);
}
}
|
public void emptyElement(QName element,
XMLAttributes attributes,
Augmentations augs) throws XNIException {
fDepth++;
int lastState = getState(fDepth - 1);
// 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.
if (lastState == STATE_EXPECT_FALLBACK && getState(fDepth - 2) == STATE_EXPECT_FALLBACK) {
setState(STATE_IGNORE);
}
else {
setState(lastState);
}
// we process the xml:base and xml:lang attributes regardless
// of what type of element it is.
processXMLBaseAttributes(attributes);
if (fFixupLanguage) {
processXMLLangAttributes(attributes);
}
if (isIncludeElement(element)) {
boolean success = this.handleIncludeElement(attributes);
if (success) {
setState(STATE_IGNORE);
}
else {
reportFatalError("NoFallback");
}
}
else if (isFallbackElement(element)) {
this.handleFallbackElement();
}
else if (hasXIncludeNamespace(element)) {
if (getSawInclude(fDepth - 1)) {
reportFatalError(
"IncludeChild",
new Object[] { element.rawname });
}
if (getSawFallback(fDepth - 1)) {
reportFatalError(
"FallbackChild",
new Object[] { element.rawname });
}
if (getState() == STATE_NORMAL_PROCESSING) {
if (fResultDepth == 0) {
checkMultipleRootElements();
}
if (fDocumentHandler != null) {
augs = modifyAugmentations(augs);
attributes = processAttributes(attributes);
fDocumentHandler.emptyElement(element, attributes, augs);
}
}
}
else if (getState() == STATE_NORMAL_PROCESSING) {
if (fResultDepth == 0) {
checkMultipleRootElements();
}
if (fDocumentHandler != null) {
augs = modifyAugmentations(augs);
attributes = processAttributes(attributes);
fDocumentHandler.emptyElement(element, attributes, augs);
}
}
// reset the out of scope stack elements
setSawFallback(fDepth + 1, false);
setSawInclude(fDepth, false);
// check if an xml:base has gone out of scope
if (fBaseURIScope.size() > 0 && fDepth == fBaseURIScope.peek()) {
// pop the values from the stack
restoreBaseURI();
}
fDepth--;
}
|
public void endAttlist(Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.endAttlist(augmentations);
}
}
|
public void endCDATA(Augmentations augs) throws XNIException {
if (fDocumentHandler != null
&& getState() == STATE_NORMAL_PROCESSING
&& fResultDepth != 0) {
fDocumentHandler.endCDATA(augs);
}
}
|
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);
}
fInDTD = false;
}
|
public void endDocument(Augmentations augs) throws XNIException {
if (isRootDocument()) {
if (!fSeenRootElement) {
reportFatalError("RootElementRequired");
}
if (fDocumentHandler != null) {
fDocumentHandler.endDocument(augs);
}
}
}
|
public void endElement(QName element,
Augmentations augs) 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
&& !getSawFallback(fDepth + 1)) {
reportFatalError("NoFallback");
}
}
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) {
setState(STATE_IGNORE);
}
}
else if (getState() == STATE_NORMAL_PROCESSING) {
--fResultDepth;
if (fDocumentHandler != null) {
fDocumentHandler.endElement(element, augs);
}
}
// reset the out of scope stack elements
setSawFallback(fDepth + 1, false);
setSawInclude(fDepth, false);
// check if an xml:base has gone out of scope
if (fBaseURIScope.size() > 0 && fDepth == fBaseURIScope.peek()) {
// pop the values from the stack
restoreBaseURI();
}
// check if an xml:lang has gone out of scope
if (fLanguageScope.size() > 0 && fDepth == fLanguageScope.peek()) {
// pop the language from the stack
fCurrentLanguage = restoreLanguage();
}
fDepth--;
}
|
public void endExternalSubset(Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.endExternalSubset(augmentations);
}
}
|
public void endGeneralEntity(String name,
Augmentations augs) throws XNIException {
if (fDocumentHandler != null
&& getState() == STATE_NORMAL_PROCESSING
&& fResultDepth != 0) {
fDocumentHandler.endGeneralEntity(name, augs);
}
}
|
public void endParameterEntity(String name,
Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.endParameterEntity(name, augmentations);
}
}
|
public void externalEntityDecl(String name,
XMLResourceIdentifier identifier,
Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.externalEntityDecl(name, identifier, augmentations);
}
}
|
public String getBaseURI(int depth) {
int scope = scopeOfBaseURI(depth);
return (String)fExpandedSystemID.elementAt(scope);
}
Gets the base URI that was in use at that depth |
public XMLDTDHandler getDTDHandler() {
return fDTDHandler;
}
|
public XMLDTDSource getDTDSource() {
return fDTDSource;
}
|
public XMLDocumentHandler getDocumentHandler() {
return fDocumentHandler;
}
|
public XMLDocumentSource getDocumentSource() {
return fDocumentSource;
}
|
public Boolean getFeatureDefault(String featureId) {
for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) {
if (RECOGNIZED_FEATURES[i].equals(featureId)) {
return FEATURE_DEFAULTS[i];
}
}
return null;
}
Returns the default state for a feature, or null if this
component does not want to report a default value for this
feature. |
public String getLanguage(int depth) {
int scope = scopeOfLanguage(depth);
return (String)fLanguageStack.elementAt(scope);
}
Gets the language that was in use at that depth. |
public Object getPropertyDefault(String propertyId) {
for (int i = 0; i < RECOGNIZED_PROPERTIES.length; i++) {
if (RECOGNIZED_PROPERTIES[i].equals(propertyId)) {
return PROPERTY_DEFAULTS[i];
}
}
return null;
}
Returns the default state for a property, or null if this
component does not want to report a default value for this
property. |
public String[] getRecognizedFeatures() {
return (String[])(RECOGNIZED_FEATURES.clone());
}
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. |
public String[] getRecognizedProperties() {
return (String[])(RECOGNIZED_PROPERTIES.clone());
}
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. |
protected String getRelativeBaseURI() throws MalformedURIException {
int includeParentDepth = getIncludeParentDepth();
String relativeURI = this.getRelativeURI(includeParentDepth);
if (isRootDocument()) {
return relativeURI;
}
else {
if (relativeURI.equals("")) {
relativeURI = fCurrentBaseURI.getLiteralSystemId();
}
if (includeParentDepth == 0) {
if (fParentRelativeURI == null) {
fParentRelativeURI =
fParentXIncludeHandler.getRelativeBaseURI();
}
if (fParentRelativeURI.equals("")) {
return relativeURI;
}
URI base = new URI(fParentRelativeURI, true);
URI uri = new URI(base, relativeURI);
/** Check whether the scheme components are equal. */
final String baseScheme = base.getScheme();
final String literalScheme = uri.getScheme();
if (!isEqual(baseScheme, literalScheme)) {
return relativeURI;
}
/** Check whether the authority components are equal. */
final String baseAuthority = base.getAuthority();
final String literalAuthority = uri.getAuthority();
if (!isEqual(baseAuthority, literalAuthority)) {
return uri.getSchemeSpecificPart();
}
/**
* The scheme and authority components are equal,
* return the path and the possible query and/or
* fragment which follow.
*/
final String literalPath = uri.getPath();
final String literalQuery = uri.getQueryString();
final String literalFragment = uri.getFragment();
if (literalQuery != null || literalFragment != null) {
StringBuffer buffer = new StringBuffer();
if (literalPath != null) {
buffer.append(literalPath);
}
if (literalQuery != null) {
buffer.append('?");
buffer.append(literalQuery);
}
if (literalFragment != null) {
buffer.append('#");
buffer.append(literalFragment);
}
return buffer.toString();
}
return literalPath;
}
else {
return relativeURI;
}
}
}
Returns a URI, relative to the include parent's base URI, of the current
[base URI]. For instance, if the current [base URI] was "dir1/dir2/file.xml"
and the include parent's [base URI] was "dir/", this would return "dir2/file.xml". |
public String getRelativeURI(int depth) throws MalformedURIException {
// 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
int start = scopeOfBaseURI(depth) + 1;
if (start == fBaseURIScope.size()) {
// If that is the last system id, then we don't need a relative URI
return "";
}
URI uri = new URI("file", (String)fLiteralSystemID.elementAt(start));
for (int i = start + 1; i < fBaseURIScope.size(); i++) {
uri = new URI(uri, (String)fLiteralSystemID.elementAt(i));
}
return uri.getPath();
}
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. |
protected boolean getSawFallback(int depth) {
if (depth >= fSawFallback.length) {
return false;
}
return fSawFallback[depth];
}
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. |
protected boolean getSawInclude(int depth) {
if (depth >= fSawInclude.length) {
return false;
}
return fSawInclude[depth];
}
Return whether an <include> was encountered at the specified depth,
as an ancestor of the current item. |
protected int getState() {
return fState[fDepth];
}
|
protected int getState(int depth) {
return fState[depth];
}
|
protected void handleFallbackElement() {
if (!getSawInclude(fDepth - 1)) {
if (getState() == STATE_IGNORE) {
return;
}
reportFatalError("FallbackParent");
}
setSawInclude(fDepth, false);
fNamespaceContext.setContextInvalid();
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) {
setState(STATE_NORMAL_PROCESSING);
}
}
|
protected boolean handleIncludeElement(XMLAttributes attributes) throws XNIException {
if (getSawInclude(fDepth - 1)) {
reportFatalError("IncludeChild", new Object[] { XINCLUDE_INCLUDE });
}
if (getState() == STATE_IGNORE) {
return true;
}
setSawInclude(fDepth, true);
fNamespaceContext.setContextInvalid();
// 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
String href = attributes.getValue(XINCLUDE_ATTR_HREF);
String parse = attributes.getValue(XINCLUDE_ATTR_PARSE);
String xpointer = attributes.getValue(XPOINTER);
String accept = attributes.getValue(XINCLUDE_ATTR_ACCEPT);
String acceptLanguage = attributes.getValue(XINCLUDE_ATTR_ACCEPT_LANGUAGE);
if (parse == null) {
parse = XINCLUDE_PARSE_XML;
}
if (href == null) {
href = XMLSymbols.EMPTY_STRING;
}
if (href.length() == 0 && XINCLUDE_PARSE_XML.equals(parse)) {
if (xpointer == null) {
reportFatalError("XpointerMissing");
}
else {
// When parse="xml" and an xpointer is specified treat
// all absences of the href attribute as a resource error.
Locale locale = (fErrorReporter != null) ? fErrorReporter.getLocale() : null;
String reason = fXIncludeMessageFormatter.formatMessage(locale, "XPointerStreamability", null);
reportResourceError("XMLResourceError", new Object[] { href, reason });
return false;
}
}
URI hrefURI = null;
// 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 {
hrefURI = new URI(href, true);
if (hrefURI.getFragment() != null) {
reportFatalError("HrefFragmentIdentifierIllegal", new Object[] {href});
}
}
catch (URI.MalformedURIException exc) {
String newHref = escapeHref(href);
if (href != newHref) {
href = newHref;
try {
hrefURI = new URI(href, true);
if (hrefURI.getFragment() != null) {
reportFatalError("HrefFragmentIdentifierIllegal", new Object[] {href});
}
}
catch (URI.MalformedURIException exc2) {
reportFatalError("HrefSyntacticallyInvalid", new Object[] {href});
}
}
else {
reportFatalError("HrefSyntacticallyInvalid", new Object[] {href});
}
}
// Verify that if an accept and/or an accept-language attribute exist
// that the value(s) don't contain disallowed characters.
if (accept != null && !isValidInHTTPHeader(accept)) {
reportFatalError("AcceptMalformed", null);
accept = null;
}
if (acceptLanguage != null && !isValidInHTTPHeader(acceptLanguage)) {
reportFatalError("AcceptLanguageMalformed", null);
acceptLanguage = null;
}
XMLInputSource includedSource = null;
if (fEntityResolver != null) {
try {
XMLResourceIdentifier resourceIdentifier =
new XMLResourceIdentifierImpl(
null,
href,
fCurrentBaseURI.getExpandedSystemId(),
XMLEntityManager.expandSystemId(
href,
fCurrentBaseURI.getExpandedSystemId(),
false));
includedSource =
fEntityResolver.resolveEntity(resourceIdentifier);
if (includedSource != null &&
!(includedSource instanceof HTTPInputSource) &&
(accept != null || acceptLanguage != null) &&
includedSource.getCharacterStream() == null &&
includedSource.getByteStream() == null) {
includedSource = createInputSource(includedSource.getPublicId(), includedSource.getSystemId(),
includedSource.getBaseSystemId(), accept, acceptLanguage);
}
}
catch (IOException e) {
reportResourceError(
"XMLResourceError",
new Object[] { href, e.getMessage()});
return false;
}
}
if (includedSource == null) {
// setup an HTTPInputSource if either of the content negotation attributes were specified.
if (accept != null || acceptLanguage != null) {
includedSource = createInputSource(null, href, fCurrentBaseURI.getExpandedSystemId(), accept, acceptLanguage);
}
else {
includedSource = new XMLInputSource(null, href, fCurrentBaseURI.getExpandedSystemId());
}
}
if (parse.equals(XINCLUDE_PARSE_XML)) {
// Instead of always creating a new configuration, the first one can be reused
if ((xpointer != null && fXPointerChildConfig == null)
|| (xpointer == null && fXIncludeChildConfig == null) ) {
String parserName = XINCLUDE_DEFAULT_CONFIGURATION;
if (xpointer != null)
parserName = "org.apache.xerces.parsers.XPointerParserConfiguration";
fChildConfig =
(XMLParserConfiguration)ObjectFactory.newInstance(
parserName,
ObjectFactory.findClassLoader(),
true);
// use the same symbol table, error reporter, entity resolver, security manager and buffer size.
if (fSymbolTable != null) fChildConfig.setProperty(SYMBOL_TABLE, fSymbolTable);
if (fErrorReporter != null) fChildConfig.setProperty(ERROR_REPORTER, fErrorReporter);
if (fEntityResolver != null) fChildConfig.setProperty(ENTITY_RESOLVER, fEntityResolver);
fChildConfig.setProperty(SECURITY_MANAGER, fSecurityManager);
fChildConfig.setProperty(BUFFER_SIZE, new Integer(fBufferSize));
// features must be copied to child configuration
fNeedCopyFeatures = true;
// use the same namespace context
fChildConfig.setProperty(
Constants.XERCES_PROPERTY_PREFIX
+ Constants.NAMESPACE_CONTEXT_PROPERTY,
fNamespaceContext);
fChildConfig.setFeature(
XINCLUDE_FIXUP_BASE_URIS,
fFixupBaseURIs);
fChildConfig.setFeature(
XINCLUDE_FIXUP_LANGUAGE,
fFixupLanguage);
// If the xpointer attribute is present
if (xpointer != null ) {
XPointerHandler newHandler =
(XPointerHandler)fChildConfig.getProperty(
Constants.XERCES_PROPERTY_PREFIX
+ Constants.XPOINTER_HANDLER_PROPERTY);
fXPtrProcessor = newHandler;
// ???
((XPointerHandler)fXPtrProcessor).setProperty(
Constants.XERCES_PROPERTY_PREFIX
+ Constants.NAMESPACE_CONTEXT_PROPERTY,
fNamespaceContext);
((XPointerHandler)fXPtrProcessor).setProperty(XINCLUDE_FIXUP_BASE_URIS,
fFixupBaseURIs ? Boolean.TRUE : Boolean.FALSE);
((XPointerHandler)fXPtrProcessor).setProperty(
XINCLUDE_FIXUP_LANGUAGE,
fFixupLanguage ? Boolean.TRUE : Boolean.FALSE);
if (fErrorReporter != null)
((XPointerHandler)fXPtrProcessor).setProperty(ERROR_REPORTER, fErrorReporter);
// ???
newHandler.setParent(this);
newHandler.setHref(href);
newHandler.setXIncludeLocator(fXIncludeLocator);
newHandler.setDocumentHandler(this.getDocumentHandler());
fXPointerChildConfig = fChildConfig;
} else {
XIncludeHandler newHandler =
(XIncludeHandler)fChildConfig.getProperty(
Constants.XERCES_PROPERTY_PREFIX
+ Constants.XINCLUDE_HANDLER_PROPERTY);
newHandler.setParent(this);
newHandler.setHref(href);
newHandler.setXIncludeLocator(fXIncludeLocator);
newHandler.setDocumentHandler(this.getDocumentHandler());
fXIncludeChildConfig = fChildConfig;
}
}
// If an xpointer attribute is present
if (xpointer != null ) {
fChildConfig = fXPointerChildConfig;
// Parse the XPointer expression
try {
((XPointerProcessor)fXPtrProcessor).parseXPointer(xpointer);
} catch (XNIException ex) {
// report the XPointer error as a resource error
reportResourceError(
"XMLResourceError",
new Object[] { href, ex.getMessage()});
return false;
}
} else {
fChildConfig = fXIncludeChildConfig;
}
// set all features on parserConfig to match this parser configuration
if (fNeedCopyFeatures) {
copyFeatures(fSettings, fChildConfig);
}
fNeedCopyFeatures = false;
try {
fHasIncludeReportedContent = false;
fNamespaceContext.pushScope();
fChildConfig.parse(includedSource);
// necessary to make sure proper location is reported to the application and in errors
fXIncludeLocator.setLocator(fDocLocation);
if (fErrorReporter != null) {
fErrorReporter.setDocumentLocator(fDocLocation);
}
// If the xpointer attribute is present
if (xpointer != null ) {
// and it was not resolved
if (!((XPointerProcessor)fXPtrProcessor).isXPointerResolved()) {
Locale locale = (fErrorReporter != null) ? fErrorReporter.getLocale() : null;
String reason = fXIncludeMessageFormatter.formatMessage(locale, "XPointerResolutionUnsuccessful", null);
reportResourceError("XMLResourceError", new Object[] {href, reason});
// use the fallback
return false;
}
}
}
catch (XNIException e) {
// necessary to make sure proper location is reported to the application and in errors
fXIncludeLocator.setLocator(fDocLocation);
if (fErrorReporter != null) {
fErrorReporter.setDocumentLocator(fDocLocation);
}
reportFatalError("XMLParseError", new Object[] { href });
}
catch (IOException e) {
// necessary to make sure proper location is reported to the application and in errors
fXIncludeLocator.setLocator(fDocLocation);
if (fErrorReporter != null) {
fErrorReporter.setDocumentLocator(fDocLocation);
}
// If the start document event has been seen on the child pipeline it
// means the resource was successfully opened and we started reporting
// document events. If an IOException is thrown after the start document
// event we had a failure midstream and cannot recover.
if (fHasIncludeReportedContent) {
throw new XNIException(e);
}
// In other circumstances an IOException indicates that we had trouble
// accessing or opening the file, not that it was an invalid XML file. So we
// send a resource error, not a fatal error.
reportResourceError(
"XMLResourceError",
new Object[] { href, e.getMessage()});
return false;
}
finally {
fNamespaceContext.popScope();
}
}
else if (parse.equals(XINCLUDE_PARSE_TEXT)) {
// we only care about encoding for parse="text"
String encoding = attributes.getValue(XINCLUDE_ATTR_ENCODING);
includedSource.setEncoding(encoding);
XIncludeTextReader textReader = null;
try {
fHasIncludeReportedContent = false;
// Setup the appropriate text reader.
if (!fIsXML11) {
if (fXInclude10TextReader == null) {
fXInclude10TextReader = new XIncludeTextReader(includedSource, this, fBufferSize);
}
else {
fXInclude10TextReader.setInputSource(includedSource);
}
textReader = fXInclude10TextReader;
}
else {
if (fXInclude11TextReader == null) {
fXInclude11TextReader = new XInclude11TextReader(includedSource, this, fBufferSize);
}
else {
fXInclude11TextReader.setInputSource(includedSource);
}
textReader = fXInclude11TextReader;
}
textReader.setErrorReporter(fErrorReporter);
textReader.parse();
}
// encoding errors
catch (MalformedByteSequenceException ex) {
fErrorReporter.reportError(ex.getDomain(), ex.getKey(),
ex.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR, ex);
}
catch (CharConversionException e) {
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
"CharConversionFailure", null, XMLErrorReporter.SEVERITY_FATAL_ERROR, e);
}
catch (IOException e) {
// If a characters event has already been sent down the pipeline it
// means the resource was successfully opened and that this IOException
// is from a failure midstream from which we cannot recover.
if (fHasIncludeReportedContent) {
throw new XNIException(e);
}
reportResourceError(
"TextResourceError",
new Object[] { href, e.getMessage()});
return false;
}
finally {
if (textReader != null) {
try {
textReader.close();
}
catch (IOException e) {
reportResourceError(
"TextResourceError",
new Object[] { href, e.getMessage()});
return false;
}
}
}
}
else {
reportFatalError("InvalidParseValue", new Object[] { parse });
}
return true;
}
|
protected boolean hasXIncludeNamespace(QName element) {
// REVISIT: The namespace of this element should be bound
// already. Why are we looking it up from the namespace
// context? -- mrglavas
return element.uri == XINCLUDE_NS_URI
|| fNamespaceContext.getURI(element.prefix) == XINCLUDE_NS_URI;
}
Returns true if the element has the namespace "http://www.w3.org/2001/XInclude" |
public void ignorableWhitespace(XMLString text,
Augmentations augs) throws XNIException {
if (fDocumentHandler != null
&& getState() == STATE_NORMAL_PROCESSING
&& fResultDepth != 0) {
fDocumentHandler.ignorableWhitespace(text, augs);
}
}
|
public void ignoredCharacters(XMLString text,
Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.ignoredCharacters(text, augmentations);
}
}
|
public void internalEntityDecl(String name,
XMLString text,
XMLString nonNormalizedText,
Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.internalEntityDecl(
name,
text,
nonNormalizedText,
augmentations);
}
}
|
protected boolean isFallbackElement(QName element) {
return element.localpart.equals(XINCLUDE_FALLBACK) &&
hasXIncludeNamespace(element);
}
Checks if the element is an <fallback> element. The element must have
the XInclude namespace, and a local name of "fallback". |
protected boolean isIncludeElement(QName element) {
return element.localpart.equals(XINCLUDE_INCLUDE) &&
hasXIncludeNamespace(element);
}
Checks if the element is an <include> element. The element must have
the XInclude namespace, and a local name of "include". |
protected boolean isRootDocument() {
return fParentXIncludeHandler == null;
}
|
protected boolean isTopLevelIncludedItem() {
return isTopLevelIncludedItemViaInclude()
|| isTopLevelIncludedItemViaFallback();
}
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 |
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.
return getSawFallback(fDepth - 1);
}
|
protected boolean isTopLevelIncludedItemViaInclude() {
return fDepth == 1 && !isRootDocument();
}
|
protected Augmentations modifyAugmentations(Augmentations augs) {
return modifyAugmentations(augs, false);
}
Modify the augmentations. Add an [included] infoset item, if the current
element is a top level included item. |
protected Augmentations modifyAugmentations(Augmentations augs,
boolean force) {
if (force || isTopLevelIncludedItem()) {
if (augs == null) {
augs = new AugmentationsImpl();
}
augs.putItem(XINCLUDE_INCLUDED, Boolean.TRUE);
}
return augs;
}
Modify the augmentations. Add an [included] infoset item, if force
is true, or if the current element is a top level included item. |
public void notationDecl(String name,
XMLResourceIdentifier identifier,
Augmentations augmentations) throws XNIException {
this.addNotation(name, identifier, augmentations);
if (fDTDHandler != null) {
fDTDHandler.notationDecl(name, identifier, augmentations);
}
}
|
protected XMLAttributes processAttributes(XMLAttributes attributes) {
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
String uri = null;
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
uri = fCurrentBaseURI.getExpandedSystemId();
}
int index =
attributes.addAttribute(
XML_BASE_QNAME,
XMLSymbols.fCDATASymbol,
uri);
attributes.setSpecified(index, true);
}
// 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 =
attributes.addAttribute(
XML_LANG_QNAME,
XMLSymbols.fCDATASymbol,
fCurrentLanguage);
attributes.setSpecified(index, true);
}
// Modify attributes of included items to do namespace-fixup. (spec 4.5.4)
Enumeration inscopeNS = fNamespaceContext.getAllPrefixes();
while (inscopeNS.hasMoreElements()) {
String prefix = (String)inscopeNS.nextElement();
String parentURI =
fNamespaceContext.getURIFromIncludeParent(prefix);
String uri = fNamespaceContext.getURI(prefix);
if (parentURI != uri && attributes != null) {
if (prefix == XMLSymbols.EMPTY_STRING) {
if (attributes
.getValue(
NamespaceContext.XMLNS_URI,
XMLSymbols.PREFIX_XMLNS)
== null) {
if (attributes == null) {
attributes = new XMLAttributesImpl();
}
QName ns = (QName)NEW_NS_ATTR_QNAME.clone();
ns.prefix = null;
ns.localpart = XMLSymbols.PREFIX_XMLNS;
ns.rawname = XMLSymbols.PREFIX_XMLNS;
int index =
attributes.addAttribute(
ns,
XMLSymbols.fCDATASymbol,
uri != null ? uri : XMLSymbols.EMPTY_STRING);
attributes.setSpecified(index, true);
// 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
fNamespaceContext.declarePrefix(prefix, uri);
}
}
else if (
attributes.getValue(NamespaceContext.XMLNS_URI, prefix)
== null) {
if (attributes == null) {
attributes = new XMLAttributesImpl();
}
QName ns = (QName)NEW_NS_ATTR_QNAME.clone();
ns.localpart = prefix;
ns.rawname += prefix;
ns.rawname = (fSymbolTable != null) ?
fSymbolTable.addSymbol(ns.rawname) :
ns.rawname.intern();
int index =
attributes.addAttribute(
ns,
XMLSymbols.fCDATASymbol,
uri != null ? uri : XMLSymbols.EMPTY_STRING);
attributes.setSpecified(index, true);
// 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
fNamespaceContext.declarePrefix(prefix, uri);
}
}
}
}
if (attributes != null) {
int length = attributes.getLength();
for (int i = 0; i < length; i++) {
String type = attributes.getType(i);
String value = attributes.getValue(i);
if (type == XMLSymbols.fENTITYSymbol) {
this.checkUnparsedEntity(value);
}
if (type == XMLSymbols.fENTITIESSymbol) {
// 4.5.1 - Unparsed Entities
StringTokenizer st = new StringTokenizer(value);
while (st.hasMoreTokens()) {
String entName = st.nextToken();
this.checkUnparsedEntity(entName);
}
}
else if (type == XMLSymbols.fNOTATIONSymbol) {
// 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;
}
Processes the XMLAttributes object of startElement() calls. Performs the following tasks:
- 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]
- 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
- 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
|
protected void processXMLBaseAttributes(XMLAttributes attributes) {
String baseURIValue =
attributes.getValue(NamespaceContext.XML_URI, "base");
if (baseURIValue != null) {
try {
String expandedValue =
XMLEntityManager.expandSystemId(
baseURIValue,
fCurrentBaseURI.getExpandedSystemId(),
false);
fCurrentBaseURI.setLiteralSystemId(baseURIValue);
fCurrentBaseURI.setBaseSystemId(
fCurrentBaseURI.getExpandedSystemId());
fCurrentBaseURI.setExpandedSystemId(expandedValue);
// push the new values on the stack
saveBaseURI();
}
catch (MalformedURIException e) {
// REVISIT: throw error here
}
}
}
Search for a xml:base attribute, and if one is found, put the new base URI into
effect. |
protected void processXMLLangAttributes(XMLAttributes attributes) {
String language = attributes.getValue(NamespaceContext.XML_URI, "lang");
if (language != null) {
fCurrentLanguage = language;
saveLanguage(fCurrentLanguage);
}
}
Search for a xml:lang attribute, and if one is found, put the new
[language] into effect. |
public void processingInstruction(String target,
XMLString data,
Augmentations augs) throws XNIException {
if (!fInDTD) {
if (fDocumentHandler != null
&& getState() == STATE_NORMAL_PROCESSING) {
// we need to change the depth like this so that modifyAugmentations() works
fDepth++;
augs = modifyAugmentations(augs);
fDocumentHandler.processingInstruction(target, data, augs);
fDepth--;
}
}
else if (fDTDHandler != null) {
fDTDHandler.processingInstruction(target, data, augs);
}
}
|
protected void reportFatalError(String key) {
this.reportFatalError(key, null);
}
|
protected void reportFatalError(String key,
Object[] args) {
this.reportError(key, args, XMLErrorReporter.SEVERITY_FATAL_ERROR);
}
|
protected void reportResourceError(String key) {
this.reportFatalError(key, null);
}
|
protected void reportResourceError(String key,
Object[] args) {
this.reportError(key, args, XMLErrorReporter.SEVERITY_WARNING);
}
|
public void reset(XMLComponentManager componentManager) throws XNIException {
fNamespaceContext = null;
fDepth = 0;
fResultDepth = isRootDocument() ? 0 : fParentXIncludeHandler.getResultDepth();
fNotations.clear();
fUnparsedEntities.clear();
fParentRelativeURI = null;
fIsXML11 = false;
fInDTD = false;
fSeenRootElement = false;
fBaseURIScope.clear();
fBaseURI.clear();
fLiteralSystemID.clear();
fExpandedSystemID.clear();
fLanguageScope.clear();
fLanguageStack.clear();
// 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
for (int i = 0; i < fState.length; ++i) {
fState[i] = STATE_NORMAL_PROCESSING;
}
for (int i = 0; i < fSawFallback.length; ++i) {
fSawFallback[i] = false;
}
for (int i = 0; i < fSawInclude.length; ++i) {
fSawInclude[i] = false;
}
try {
if (!componentManager.getFeature(PARSER_SETTINGS)) {
// if parser settings have not changed return.
return;
}
}
catch (XMLConfigurationException e) {}
// parser settings changed. Need to refresh features on child config.
fNeedCopyFeatures = true;
try {
fSendUEAndNotationEvents =
componentManager.getFeature(ALLOW_UE_AND_NOTATION_EVENTS);
if (fChildConfig != null) {
fChildConfig.setFeature(
ALLOW_UE_AND_NOTATION_EVENTS,
fSendUEAndNotationEvents);
}
}
catch (XMLConfigurationException e) {
}
try {
fFixupBaseURIs =
componentManager.getFeature(XINCLUDE_FIXUP_BASE_URIS);
if (fChildConfig != null) {
fChildConfig.setFeature(
XINCLUDE_FIXUP_BASE_URIS,
fFixupBaseURIs);
}
}
catch (XMLConfigurationException e) {
fFixupBaseURIs = true;
}
try {
fFixupLanguage =
componentManager.getFeature(XINCLUDE_FIXUP_LANGUAGE);
if (fChildConfig != null) {
fChildConfig.setFeature(
XINCLUDE_FIXUP_LANGUAGE,
fFixupLanguage);
}
}
catch (XMLConfigurationException e) {
fFixupLanguage = true;
}
// Get symbol table.
try {
SymbolTable value =
(SymbolTable)componentManager.getProperty(SYMBOL_TABLE);
if (value != null) {
fSymbolTable = value;
if (fChildConfig != null) {
fChildConfig.setProperty(SYMBOL_TABLE, value);
}
}
}
catch (XMLConfigurationException e) {
fSymbolTable = null;
}
// Get error reporter.
try {
XMLErrorReporter value =
(XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);
if (value != null) {
setErrorReporter(value);
if (fChildConfig != null) {
fChildConfig.setProperty(ERROR_REPORTER, value);
}
}
}
catch (XMLConfigurationException e) {
fErrorReporter = null;
}
// Get entity resolver.
try {
XMLEntityResolver value =
(XMLEntityResolver)componentManager.getProperty(
ENTITY_RESOLVER);
if (value != null) {
fEntityResolver = value;
if (fChildConfig != null) {
fChildConfig.setProperty(ENTITY_RESOLVER, value);
}
}
}
catch (XMLConfigurationException e) {
fEntityResolver = null;
}
// Get security manager.
try {
SecurityManager value =
(SecurityManager)componentManager.getProperty(
SECURITY_MANAGER);
if (value != null) {
fSecurityManager = value;
if (fChildConfig != null) {
fChildConfig.setProperty(SECURITY_MANAGER, value);
}
}
}
catch (XMLConfigurationException e) {
fSecurityManager = null;
}
// Get buffer size.
try {
Integer value =
(Integer)componentManager.getProperty(
BUFFER_SIZE);
if (value != null && value.intValue() > 0) {
fBufferSize = value.intValue();
if (fChildConfig != null) {
fChildConfig.setProperty(BUFFER_SIZE, value);
}
}
else {
fBufferSize = ((Integer)getPropertyDefault(BUFFER_SIZE)).intValue();
}
}
catch (XMLConfigurationException e) {
fBufferSize = ((Integer)getPropertyDefault(BUFFER_SIZE)).intValue();
}
// Reset XML 1.0 text reader.
if (fXInclude10TextReader != null) {
fXInclude10TextReader.setBufferSize(fBufferSize);
}
// Reset XML 1.1 text reader.
if (fXInclude11TextReader != null) {
fXInclude11TextReader.setBufferSize(fBufferSize);
}
fSettings = new ParserConfigurationSettings();
copyFeatures(componentManager, fSettings);
// We don't want a schema validator on the new pipeline,
// so if it was enabled, we set the feature to false.
try {
if (componentManager.getFeature(SCHEMA_VALIDATION)) {
fSettings.setFeature(SCHEMA_VALIDATION, false);
// If the value of the JAXP 1.2 schema language property
// is http://www.w3.org/2001/XMLSchema we're only validating
// against XML schema so we disable validation on the new pipeline.
if (Constants.NS_XMLSCHEMA.equals(componentManager.getProperty(JAXP_SCHEMA_LANGUAGE))) {
fSettings.setFeature(VALIDATION, 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.
else if (componentManager.getFeature(VALIDATION)) {
fSettings.setFeature(DYNAMIC_VALIDATION, true);
}
}
}
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.
}
|
protected void restoreBaseURI() {
fBaseURI.pop();
fLiteralSystemID.pop();
fExpandedSystemID.pop();
fBaseURIScope.pop();
fCurrentBaseURI.setBaseSystemId((String)fBaseURI.peek());
fCurrentBaseURI.setLiteralSystemId((String)fLiteralSystemID.peek());
fCurrentBaseURI.setExpandedSystemId((String)fExpandedSystemID.peek());
}
Discards the URIs at the top of the stack, and restores the ones beneath it. |
public String restoreLanguage() {
fLanguageStack.pop();
fLanguageScope.pop();
return (String) fLanguageStack.peek();
}
Discards the language at the top of the stack, and returns the one beneath it. |
protected boolean sameBaseURIAsIncludeParent() {
String parentBaseURI = getIncludeParentBaseURI();
String baseURI = fCurrentBaseURI.getExpandedSystemId();
// 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.
return parentBaseURI != null && parentBaseURI.equals(baseURI);
}
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 only 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. |
protected boolean sameLanguageAsIncludeParent() {
String parentLanguage = getIncludeParentLanguage();
return parentLanguage != null && parentLanguage.equalsIgnoreCase(fCurrentLanguage);
}
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 only 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. |
protected void saveBaseURI() {
fBaseURIScope.push(fDepth);
fBaseURI.push(fCurrentBaseURI.getBaseSystemId());
fLiteralSystemID.push(fCurrentBaseURI.getLiteralSystemId());
fExpandedSystemID.push(fCurrentBaseURI.getExpandedSystemId());
}
Saves the current base URI to the top of the stack. |
protected void saveLanguage(String language) {
fLanguageScope.push(fDepth);
fLanguageStack.push(language);
}
Saves the given language on the top of the stack. |
protected boolean searchForRecursiveIncludes(String includedSysId) {
if (includedSysId.equals(fCurrentBaseURI.getExpandedSystemId())) {
return true;
}
else if (fParentXIncludeHandler == null) {
return false;
}
else {
return fParentXIncludeHandler.searchForRecursiveIncludes(includedSysId);
}
}
Checks if the file indicated by the given system id has already been
included in the current stack. |
public void setDTDHandler(XMLDTDHandler handler) {
fDTDHandler = handler;
}
|
public void setDTDSource(XMLDTDSource source) {
fDTDSource = source;
}
|
public void setDocumentHandler(XMLDocumentHandler handler) {
if (fDocumentHandler != handler) {
fDocumentHandler = handler;
if (fXIncludeChildConfig != null) {
fXIncludeChildConfig.setDocumentHandler(handler);
}
if (fXPointerChildConfig != null) {
fXPointerChildConfig.setDocumentHandler(handler);
}
}
}
|
public void setDocumentSource(XMLDocumentSource source) {
fDocumentSource = source;
}
|
public void setFeature(String featureId,
boolean state) throws XMLConfigurationException {
if (featureId.equals(ALLOW_UE_AND_NOTATION_EVENTS)) {
fSendUEAndNotationEvents = state;
}
if (fSettings != null) {
fNeedCopyFeatures = true;
fSettings.setFeature(featureId, state);
}
}
|
protected void setHref(String href) {
fHrefFromParent = href;
}
|
protected void setParent(XIncludeHandler parent) {
fParentXIncludeHandler = parent;
}
Set the parent of this XIncludeHandler in the tree |
public void setProperty(String propertyId,
Object value) throws XMLConfigurationException {
if (propertyId.equals(SYMBOL_TABLE)) {
fSymbolTable = (SymbolTable)value;
if (fChildConfig != null) {
fChildConfig.setProperty(propertyId, value);
}
return;
}
if (propertyId.equals(ERROR_REPORTER)) {
setErrorReporter((XMLErrorReporter)value);
if (fChildConfig != null) {
fChildConfig.setProperty(propertyId, value);
}
return;
}
if (propertyId.equals(ENTITY_RESOLVER)) {
fEntityResolver = (XMLEntityResolver)value;
if (fChildConfig != null) {
fChildConfig.setProperty(propertyId, value);
}
return;
}
if (propertyId.equals(SECURITY_MANAGER)) {
fSecurityManager = (SecurityManager)value;
if (fChildConfig != null) {
fChildConfig.setProperty(propertyId, value);
}
return;
}
if (propertyId.equals(BUFFER_SIZE)) {
Integer bufferSize = (Integer) value;
if (fChildConfig != null) {
fChildConfig.setProperty(propertyId, value);
}
if (bufferSize != null && bufferSize.intValue() > 0) {
fBufferSize = bufferSize.intValue();
// Reset XML 1.0 text reader.
if (fXInclude10TextReader != null) {
fXInclude10TextReader.setBufferSize(fBufferSize);
}
// Reset XML 1.1 text reader.
if (fXInclude11TextReader != null) {
fXInclude11TextReader.setBufferSize(fBufferSize);
}
}
return;
}
}
Sets the value of a property. This method is called by the component
manager any time after reset when a property changes value.
Note: Components should silently ignore properties
that do not affect the operation of the component. |
protected void setSawFallback(int depth,
boolean val) {
if (depth >= fSawFallback.length) {
boolean[] newarray = new boolean[depth * 2];
System.arraycopy(fSawFallback, 0, newarray, 0, fSawFallback.length);
fSawFallback = newarray;
}
fSawFallback[depth] = val;
}
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. |
protected void setSawInclude(int depth,
boolean val) {
if (depth >= fSawInclude.length) {
boolean[] newarray = new boolean[depth * 2];
System.arraycopy(fSawInclude, 0, newarray, 0, fSawInclude.length);
fSawInclude = newarray;
}
fSawInclude[depth] = val;
}
Records that an <include> was encountered at the specified depth,
as an ancestor of the current item. |
protected void setState(int state) {
if (fDepth >= fState.length) {
int[] newarray = new int[fDepth * 2];
System.arraycopy(fState, 0, newarray, 0, fState.length);
fState = newarray;
}
fState[fDepth] = state;
}
|
protected void setXIncludeLocator(XMLLocatorWrapper locator) {
fXIncludeLocator = locator;
}
|
protected void setupCurrentBaseURI(XMLLocator locator) {
fCurrentBaseURI.setBaseSystemId(locator.getBaseSystemId());
if (locator.getLiteralSystemId() != null) {
fCurrentBaseURI.setLiteralSystemId(locator.getLiteralSystemId());
}
else {
fCurrentBaseURI.setLiteralSystemId(fHrefFromParent);
}
String expandedSystemId = locator.getExpandedSystemId();
if (expandedSystemId == null) {
// attempt to expand it ourselves
try {
expandedSystemId =
XMLEntityManager.expandSystemId(
fCurrentBaseURI.getLiteralSystemId(),
fCurrentBaseURI.getBaseSystemId(),
false);
if (expandedSystemId == null) {
expandedSystemId = fCurrentBaseURI.getLiteralSystemId();
}
}
catch (MalformedURIException e) {
reportFatalError("ExpandedSystemId");
}
}
fCurrentBaseURI.setExpandedSystemId(expandedSystemId);
}
|
public void startAttlist(String elementName,
Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.startAttlist(elementName, augmentations);
}
}
|
public void startCDATA(Augmentations augs) throws XNIException {
if (fDocumentHandler != null
&& getState() == STATE_NORMAL_PROCESSING
&& fResultDepth != 0) {
fDocumentHandler.startCDATA(augs);
}
}
|
public void startConditional(short type,
Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.startConditional(type, augmentations);
}
}
|
public void startDTD(XMLLocator locator,
Augmentations augmentations) throws XNIException {
fInDTD = true;
if (fDTDHandler != null) {
fDTDHandler.startDTD(locator, augmentations);
}
}
|
public void startDocument(XMLLocator locator,
String encoding,
NamespaceContext namespaceContext,
Augmentations augs) 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
fErrorReporter.setDocumentLocator(locator);
if (!(namespaceContext instanceof XIncludeNamespaceSupport)) {
reportFatalError("IncompatibleNamespaceContext");
}
fNamespaceContext = (XIncludeNamespaceSupport)namespaceContext;
fDocLocation = locator;
fXIncludeLocator.setLocator(fDocLocation);
// initialize the current base URI
setupCurrentBaseURI(locator);
saveBaseURI();
if (augs == null) {
augs = new AugmentationsImpl();
}
augs.putItem(CURRENT_BASE_URI, fCurrentBaseURI);
// abort here if we detect a recursive include
if (!isRootDocument()) {
fParentXIncludeHandler.fHasIncludeReportedContent = true;
if (fParentXIncludeHandler.searchForRecursiveIncludes(
fCurrentBaseURI.getExpandedSystemId())) {
reportFatalError(
"RecursiveInclude",
new Object[] { fCurrentBaseURI.getExpandedSystemId()});
}
}
// initialize the current language
fCurrentLanguage = XMLSymbols.EMPTY_STRING;
saveLanguage(fCurrentLanguage);
if (isRootDocument() && fDocumentHandler != null) {
fDocumentHandler.startDocument(
fXIncludeLocator,
encoding,
namespaceContext,
augs);
}
}
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 startElement(QName element,
XMLAttributes attributes,
Augmentations augs) throws XNIException {
fDepth++;
int lastState = getState(fDepth - 1);
// 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.
if (lastState == STATE_EXPECT_FALLBACK && getState(fDepth - 2) == STATE_EXPECT_FALLBACK) {
setState(STATE_IGNORE);
}
else {
setState(lastState);
}
// we process the xml:base and xml:lang attributes regardless
// of what type of element it is.
processXMLBaseAttributes(attributes);
if (fFixupLanguage) {
processXMLLangAttributes(attributes);
}
if (isIncludeElement(element)) {
boolean success = this.handleIncludeElement(attributes);
if (success) {
setState(STATE_IGNORE);
}
else {
setState(STATE_EXPECT_FALLBACK);
}
}
else if (isFallbackElement(element)) {
this.handleFallbackElement();
}
else if (hasXIncludeNamespace(element)) {
if (getSawInclude(fDepth - 1)) {
reportFatalError(
"IncludeChild",
new Object[] { element.rawname });
}
if (getSawFallback(fDepth - 1)) {
reportFatalError(
"FallbackChild",
new Object[] { element.rawname });
}
if (getState() == STATE_NORMAL_PROCESSING) {
if (fResultDepth++ == 0) {
checkMultipleRootElements();
}
if (fDocumentHandler != null) {
augs = modifyAugmentations(augs);
attributes = processAttributes(attributes);
fDocumentHandler.startElement(element, attributes, augs);
}
}
}
else if (getState() == STATE_NORMAL_PROCESSING) {
if (fResultDepth++ == 0) {
checkMultipleRootElements();
}
if (fDocumentHandler != null) {
augs = modifyAugmentations(augs);
attributes = processAttributes(attributes);
fDocumentHandler.startElement(element, attributes, augs);
}
}
}
|
public void startExternalSubset(XMLResourceIdentifier identifier,
Augmentations augmentations) throws XNIException {
if (fDTDHandler != null) {
fDTDHandler.startExternalSubset(identifier, augmentations);
}
}
|
public void startGeneralEntity(String name,
XMLResourceIdentifier resId,
String encoding,
Augmentations augs) throws XNIException {
if (getState() == STATE_NORMAL_PROCESSING) {
if (fResultDepth == 0) {
if (augs != null && Boolean.TRUE.equals(augs.getItem(Constants.ENTITY_SKIPPED))) {
reportFatalError("UnexpandedEntityReferenceIllegal");
}
}
else if (fDocumentHandler != null) {
fDocumentHandler.startGeneralEntity(name, resId, encoding, augs);
}
}
}
|
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 augs) throws XNIException {
if (fDocumentHandler != null
&& getState() == STATE_NORMAL_PROCESSING) {
fDocumentHandler.textDecl(version, encoding, augs);
}
}
|
public void unparsedEntityDecl(String name,
XMLResourceIdentifier identifier,
String notation,
Augmentations augmentations) throws XNIException {
this.addUnparsedEntity(name, identifier, notation, augmentations);
if (fDTDHandler != null) {
fDTDHandler.unparsedEntityDecl(
name,
identifier,
notation,
augmentations);
}
}
|
public void xmlDecl(String version,
String encoding,
String standalone,
Augmentations augs) throws XNIException {
fIsXML11 = "1.1".equals(version);
if (isRootDocument() && fDocumentHandler != null) {
fDocumentHandler.xmlDecl(version, encoding, standalone, augs);
}
}
|