/* * reserved comment block * DO NOT REMOVE OR ALTER! */ /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.sun.org.apache.xerces.internal.xpointer; import java.util.ArrayList; import java.util.HashMap; import com.sun.org.apache.xerces.internal.impl.Constants; import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; import com.sun.org.apache.xerces.internal.util.SymbolTable; import com.sun.org.apache.xerces.internal.util.XMLChar; import com.sun.org.apache.xerces.internal.util.XMLSymbols; import com.sun.org.apache.xerces.internal.xinclude.XIncludeHandler; import com.sun.org.apache.xerces.internal.xinclude.XIncludeNamespaceSupport; import com.sun.org.apache.xerces.internal.xni.Augmentations; import com.sun.org.apache.xerces.internal.xni.QName; import com.sun.org.apache.xerces.internal.xni.XMLAttributes; import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; import com.sun.org.apache.xerces.internal.xni.XMLString; import com.sun.org.apache.xerces.internal.xni.XNIException; import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler; /** *
* This is a pipeline component which extends the XIncludeHandler to perform * XPointer specific processing specified in the W3C XPointerFramework and * element() Scheme Recommendations. *
* ** This component analyzes each event in the pipeline, looking for an element * that matches a PointerPart in the parent XInclude element's xpointer attribute * value. If the match succeeds, all children are passed by this component. *
* ** See the XPointer Framework Recommendation for * more information on the XPointer Framework and ShortHand Pointers. * See the XPointer element() Scheme Recommendation for * more information on the XPointer element() Scheme. *
* * @xerces.internal * */ public final class XPointerHandler extends XIncludeHandler implements XPointerProcessor { // Fields // An ArrayList of XPointerParts protected ArrayList* Typically, a processing instruction's data will contain a series * of pseudo-attributes. These pseudo-attributes follow the form of * element attributes but are not parsed or presented * to the application as anything other than text. The application is * responsible for parsing the data. * * @param target The target. * @param data The data or null if none specified. * @param augs Additional information that may include infoset augmentations * * @exception XNIException * Thrown by handler to signal an error. */ public void processingInstruction(String target, XMLString data, Augmentations augs) throws XNIException { if (!isChildFragmentResolved()) { return; } super.processingInstruction(target, data, augs); } /** * The start of an element. * * @param element The name of the element. * @param attributes The element attributes. * @param augs Additional information that may include infoset augmentations * * @exception XNIException * Thrown by handler to signal an error. */ public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { if (!resolveXPointer(element, attributes, augs, XPointerPart.EVENT_ELEMENT_START)) { // xml:base and xml:lang processing if (fFixupBase) { processXMLBaseAttributes(attributes); } if (fFixupLang) { processXMLLangAttributes(attributes); } // set the context invalid if the element till an element from the result infoset is included fNamespaceContext.setContextInvalid(); return; } super.startElement(element, attributes, augs); } /** * An empty element. * * @param element The name of the element. * @param attributes The element attributes. * @param augs Additional information that may include infoset augmentations * * @exception XNIException * Thrown by handler to signal an error. */ public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { if (!resolveXPointer(element, attributes, augs, XPointerPart.EVENT_ELEMENT_EMPTY)) { // xml:base and xml:lang processing if (fFixupBase) { processXMLBaseAttributes(attributes); } if (fFixupLang) { processXMLLangAttributes(attributes); } // no need to restore restoreBaseURI() for xml:base and xml:lang processing // set the context invalid if the element till an element from the result infoset is included fNamespaceContext.setContextInvalid(); return; } super.emptyElement(element, attributes, augs); } /** * Character content. * * @param text The content. * @param augs Additional information that may include infoset augmentations * * @exception XNIException * Thrown by handler to signal an error. */ public void characters(XMLString text, Augmentations augs) throws XNIException { if (!isChildFragmentResolved()) { return; } super.characters(text, augs); } /** * Ignorable whitespace. For this method to be called, the document * source must have some way of determining that the text containing * only whitespace characters should be considered ignorable. For * example, the validator can determine if a length of whitespace * characters in the document are ignorable based on the element * content model. * * @param text The ignorable whitespace. * @param augs Additional information that may include infoset augmentations * * @exception XNIException * Thrown by handler to signal an error. */ public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException { if (!isChildFragmentResolved()) { return; } super.ignorableWhitespace(text, augs); } /** * The end of an element. * * @param element The name of the element. * @param augs Additional information that may include infoset augmentations * * @exception XNIException * Thrown by handler to signal an error. */ public void endElement(QName element, Augmentations augs) throws XNIException { if (!resolveXPointer(element, null, augs, XPointerPart.EVENT_ELEMENT_END)) { // no need to restore restoreBaseURI() for xml:base and xml:lang processing return; } super.endElement(element, augs); } /** * The start of a CDATA section. * * @param augs Additional information that may include infoset augmentations * * @exception XNIException * Thrown by handler to signal an error. */ public void startCDATA(Augmentations augs) throws XNIException { if (!isChildFragmentResolved()) { return; } super.startCDATA(augs); } /** * The end of a CDATA section. * * @param augs Additional information that may include infoset augmentations * * @exception XNIException * Thrown by handler to signal an error. */ public void endCDATA(Augmentations augs) throws XNIException { if (!isChildFragmentResolved()) { return; } super.endCDATA(augs); } // ************************************************************************ // Overridden XMLComponent methods // ************************************************************************ /** *
* 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. * * @param propertyId The property identifier. * @param value The value of the property. * * @throws XMLConfigurationException Thrown for configuration error. * In general, components should * only throw this exception if * it is really * a critical error. */ public void setProperty(String propertyId, Object value) throws XMLConfigurationException { // Error reporter if (propertyId == Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY) { if (value != null) { fXPointerErrorReporter = (XMLErrorReporter) value; } else { fXPointerErrorReporter = null; } } // Error handler if (propertyId == Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY) { if (value != null) { fErrorHandler = (XMLErrorHandler) value; } else { fErrorHandler = null; } } // xml:lang if (propertyId == Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_LANGUAGE_FEATURE) { if (value != null) { fFixupLang = ((Boolean)value).booleanValue(); } else { fFixupLang = false; } } // xml:base if (propertyId == Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FIXUP_BASE_URIS_FEATURE) { if (value != null) { fFixupBase = ((Boolean)value).booleanValue(); } else { fFixupBase = false; } } // if (propertyId == Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY) { fNamespaceContext = (XIncludeNamespaceSupport) value; } super.setProperty(propertyId, value); } }