286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 1999-2002,2004, 2005 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xerces.internal.dom;
286N/A
286N/A
286N/Aimport java.io.IOException;
286N/Aimport java.util.ArrayList;
286N/Aimport java.io.StringReader;
286N/Aimport java.util.Vector;
286N/A
286N/Aimport com.sun.org.apache.xerces.internal.impl.Constants;
286N/Aimport com.sun.org.apache.xerces.internal.impl.RevalidationHandler;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dtd.DTDGrammar;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDDescription;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator;
286N/Aimport com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;
286N/Aimport com.sun.org.apache.xerces.internal.impl.xs.util.SimpleLocator;
286N/Aimport com.sun.org.apache.xerces.internal.parsers.XMLGrammarPreparser;
286N/Aimport com.sun.org.apache.xerces.internal.util.AugmentationsImpl;
286N/Aimport com.sun.org.apache.xerces.internal.util.NamespaceSupport;
286N/Aimport com.sun.org.apache.xerces.internal.util.SymbolTable;
286N/Aimport com.sun.org.apache.xerces.internal.util.XML11Char;
286N/Aimport com.sun.org.apache.xerces.internal.util.XMLChar;
286N/Aimport com.sun.org.apache.xerces.internal.util.XMLGrammarPoolImpl;
286N/Aimport com.sun.org.apache.xerces.internal.util.XMLSymbols;
286N/Aimport com.sun.org.apache.xerces.internal.xni.Augmentations;
286N/Aimport com.sun.org.apache.xerces.internal.xni.NamespaceContext;
286N/Aimport com.sun.org.apache.xerces.internal.xni.QName;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XMLAttributes;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XMLLocator;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XMLString;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XNIException;
286N/Aimport com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription;
286N/Aimport com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;
286N/Aimport com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
286N/Aimport com.sun.org.apache.xerces.internal.xs.AttributePSVI;
286N/Aimport com.sun.org.apache.xerces.internal.xs.ElementPSVI;
286N/Aimport com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;
286N/Aimport org.w3c.dom.Attr;
286N/Aimport org.w3c.dom.Comment;
286N/Aimport org.w3c.dom.DOMError;
286N/Aimport org.w3c.dom.DOMErrorHandler;
286N/Aimport org.w3c.dom.Document;
286N/Aimport org.w3c.dom.DocumentType;
286N/Aimport org.w3c.dom.Element;
286N/Aimport org.w3c.dom.Entity;
286N/Aimport org.w3c.dom.NamedNodeMap;
286N/Aimport org.w3c.dom.Node;
286N/Aimport org.w3c.dom.NodeList;
286N/Aimport org.w3c.dom.ProcessingInstruction;
286N/Aimport org.w3c.dom.Text;
286N/A/**
286N/A * This class adds implementation for normalizeDocument method.
286N/A * It acts as if the document was going through a save and load cycle, putting
286N/A * the document in a "normal" form. The actual result depends on the features being set
286N/A * and governing what operations actually take place. See setNormalizationFeature for details.
286N/A * Noticeably this method normalizes Text nodes, makes the document "namespace wellformed",
286N/A * according to the algorithm described below in pseudo code, by adding missing namespace
286N/A * declaration attributes and adding or changing namespace prefixes, updates the replacement
286N/A * tree of EntityReference nodes, normalizes attribute values, etc.
286N/A * Mutation events, when supported, are generated to reflect the changes occuring on the
286N/A * document.
286N/A * See Namespace normalization for details on how namespace declaration attributes and prefixes
286N/A * are normalized.
286N/A *
286N/A * NOTE: There is an initial support for DOM revalidation with XML Schema as a grammar.
286N/A * The tree might not be validated correctly if entityReferences, CDATA sections are
286N/A * present in the tree. The PSVI information is not exposed, normalized data (including element
286N/A * default content is not available).
286N/A *
286N/A * @xerces.experimental
286N/A *
286N/A * @author Elena Litani, IBM
286N/A * @author Neeraj Bajaj, Sun Microsystems, inc.
286N/A * @version $Id: DOMNormalizer.java,v 1.9 2010-11-01 04:39:38 joehw Exp $
286N/A */
286N/Apublic class DOMNormalizer implements XMLDocumentHandler {
286N/A
286N/A //
286N/A // constants
286N/A //
286N/A /** Debug normalize document*/
286N/A protected final static boolean DEBUG_ND = false;
286N/A /** Debug namespace fix up algorithm*/
286N/A protected final static boolean DEBUG = false;
286N/A /** Debug document handler events */
286N/A protected final static boolean DEBUG_EVENTS = false;
286N/A
286N/A /** prefix added by namespace fixup algorithm should follow a pattern "NS" + index*/
286N/A protected final static String PREFIX = "NS";
286N/A
286N/A //
286N/A // Data
286N/A //
286N/A protected DOMConfigurationImpl fConfiguration = null;
286N/A protected CoreDocumentImpl fDocument = null;
286N/A protected final XMLAttributesProxy fAttrProxy = new XMLAttributesProxy();
286N/A protected final QName fQName = new QName();
286N/A
286N/A /** Validation handler represents validator instance. */
286N/A protected RevalidationHandler fValidationHandler;
286N/A
286N/A /** symbol table */
286N/A protected SymbolTable fSymbolTable;
286N/A /** error handler. may be null. */
286N/A protected DOMErrorHandler fErrorHandler;
286N/A
286N/A /**
286N/A * Cached {@link DOMError} impl.
286N/A * The same object is re-used to report multiple errors.
286N/A */
286N/A private final DOMErrorImpl fError = new DOMErrorImpl();
286N/A
286N/A // Validation against namespace aware grammar
286N/A protected boolean fNamespaceValidation = false;
286N/A
286N/A // Update PSVI information in the tree
286N/A protected boolean fPSVI = false;
286N/A
286N/A /** The namespace context of this document: stores namespaces in scope */
286N/A protected final NamespaceContext fNamespaceContext = new NamespaceSupport();
286N/A
286N/A /** Stores all namespace bindings on the current element */
286N/A protected final NamespaceContext fLocalNSBinder = new NamespaceSupport();
286N/A
286N/A /** list of attributes */
286N/A protected final ArrayList fAttributeList = new ArrayList(5);
286N/A
286N/A /** DOM Locator - for namespace fixup algorithm */
286N/A protected final DOMLocatorImpl fLocator = new DOMLocatorImpl();
286N/A
286N/A /** for setting the PSVI */
286N/A protected Node fCurrentNode = null;
286N/A private QName fAttrQName = new QName();
286N/A
286N/A // attribute value normalization
286N/A final XMLString fNormalizedValue = new XMLString(new char[16], 0, 0);
286N/A
286N/A /**
286N/A * If the user stops the process, this exception will be thrown.
286N/A */
286N/A public static final RuntimeException abort = new RuntimeException();
286N/A
286N/A //DTD validator
286N/A private XMLDTDValidator fDTDValidator;
286N/A
286N/A //Check if element content is all "ignorable whitespace"
286N/A private boolean allWhitespace = false;
286N/A
286N/A // Constructor
286N/A //
286N/A
286N/A public DOMNormalizer(){}
286N/A
286N/A
286N/A
286N/A /**
286N/A * Normalizes document.
286N/A * Note: reset() must be called before this method.
286N/A */
286N/A protected void normalizeDocument(CoreDocumentImpl document, DOMConfigurationImpl config) {
286N/A
286N/A fDocument = document;
286N/A fConfiguration = config;
286N/A
286N/A // intialize and reset DOMNormalizer component
286N/A //
286N/A fSymbolTable = (SymbolTable) fConfiguration.getProperty(DOMConfigurationImpl.SYMBOL_TABLE);
286N/A // reset namespace context
286N/A fNamespaceContext.reset();
286N/A fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING);
286N/A
286N/A if ((fConfiguration.features & DOMConfigurationImpl.VALIDATE) != 0) {
286N/A String schemaLang = (String)fConfiguration.getProperty(DOMConfigurationImpl.JAXP_SCHEMA_LANGUAGE);
286N/A
286N/A if(schemaLang != null && schemaLang.equals(Constants.NS_XMLSCHEMA)) {
286N/A fValidationHandler =
286N/A CoreDOMImplementationImpl.singleton.getValidator(XMLGrammarDescription.XML_SCHEMA);
286N/A fConfiguration.setFeature(DOMConfigurationImpl.SCHEMA, true);
286N/A fConfiguration.setFeature(DOMConfigurationImpl.SCHEMA_FULL_CHECKING, true);
286N/A // report fatal error on DOM Level 1 nodes
286N/A fNamespaceValidation = true;
286N/A
286N/A // check if we need to fill in PSVI
286N/A fPSVI = ((fConfiguration.features & DOMConfigurationImpl.PSVI) !=0)?true:false;
286N/A }
286N/A
286N/A fConfiguration.setFeature(DOMConfigurationImpl.XERCES_VALIDATION, true);
286N/A
286N/A // reset ID table
286N/A fDocument.clearIdentifiers();
286N/A
286N/A if(fValidationHandler != null)
286N/A // reset schema validator
286N/A ((XMLComponent) fValidationHandler).reset(fConfiguration);
286N/A
286N/A }
286N/A
286N/A fErrorHandler = (DOMErrorHandler) fConfiguration.getParameter(Constants.DOM_ERROR_HANDLER);
286N/A if (fValidationHandler != null) {
286N/A fValidationHandler.setDocumentHandler(this);
286N/A fValidationHandler.startDocument(
286N/A new SimpleLocator(fDocument.fDocumentURI, fDocument.fDocumentURI,
286N/A -1, -1 ), fDocument.encoding, fNamespaceContext, null);
286N/A
286N/A }
286N/A try {
286N/A Node kid, next;
286N/A for (kid = fDocument.getFirstChild(); kid != null; kid = next) {
286N/A next = kid.getNextSibling();
286N/A kid = normalizeNode(kid);
286N/A if (kid != null) { // don't advance
286N/A next = kid;
286N/A }
286N/A }
286N/A
286N/A // release resources
286N/A if (fValidationHandler != null) {
286N/A fValidationHandler.endDocument(null);
286N/A CoreDOMImplementationImpl.singleton.releaseValidator(
286N/A XMLGrammarDescription.XML_SCHEMA, fValidationHandler);
286N/A fValidationHandler = null;
286N/A }
286N/A }
286N/A catch (RuntimeException e) {
286N/A if( e==abort )
286N/A return; // processing aborted by the user
286N/A throw e; // otherwise re-throw.
286N/A }
286N/A
286N/A }
286N/A
286N/A
286N/A /**
286N/A *
286N/A * This method acts as if the document was going through a save
286N/A * and load cycle, putting the document in a "normal" form. The actual result
286N/A * depends on the features being set and governing what operations actually
286N/A * take place. See setNormalizationFeature for details. Noticeably this method
286N/A * normalizes Text nodes, makes the document "namespace wellformed",
286N/A * according to the algorithm described below in pseudo code, by adding missing
286N/A * namespace declaration attributes and adding or changing namespace prefixes, updates
286N/A * the replacement tree of EntityReference nodes,normalizes attribute values, etc.
286N/A *
286N/A * @param node Modified node or null. If node is returned, we need
286N/A * to normalize again starting on the node returned.
286N/A * @return the normalized Node
286N/A */
286N/A protected Node normalizeNode (Node node){
286N/A
286N/A int type = node.getNodeType();
286N/A boolean wellformed;
286N/A fLocator.fRelatedNode=node;
286N/A
286N/A switch (type) {
286N/A case Node.DOCUMENT_TYPE_NODE: {
286N/A if (DEBUG_ND) {
286N/A System.out.println("==>normalizeNode:{doctype}");
286N/A }
286N/A DocumentTypeImpl docType = (DocumentTypeImpl)node;
286N/A fDTDValidator = (XMLDTDValidator)CoreDOMImplementationImpl.singleton.getValidator(XMLGrammarDescription.XML_DTD);
286N/A fDTDValidator.setDocumentHandler(this);
286N/A fConfiguration.setProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY, createGrammarPool(docType));
286N/A fDTDValidator.reset(fConfiguration);
286N/A fDTDValidator.startDocument(
286N/A new SimpleLocator(fDocument.fDocumentURI, fDocument.fDocumentURI,
286N/A -1, -1 ), fDocument.encoding, fNamespaceContext, null);
286N/A fDTDValidator.doctypeDecl(docType.getName(), docType.getPublicId(), docType.getSystemId(), null);
286N/A //REVISIT: well-formness encoding info
286N/A break;
286N/A }
286N/A
286N/A case Node.ELEMENT_NODE: {
286N/A if (DEBUG_ND) {
286N/A System.out.println("==>normalizeNode:{element} "+node.getNodeName());
286N/A }
286N/A
286N/A //do the name check only when version of the document was changed &
286N/A //application has set the value of well-formed features to true
286N/A if (fDocument.errorChecking) {
286N/A if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) &&
286N/A fDocument.isXMLVersionChanged()){
286N/A if (fNamespaceValidation){
286N/A wellformed = CoreDocumentImpl.isValidQName(node.getPrefix() , node.getLocalName(), fDocument.isXML11Version()) ;
286N/A }
286N/A else {
286N/A wellformed = CoreDocumentImpl.isXMLName(node.getNodeName() , fDocument.isXML11Version());
286N/A }
286N/A if (!wellformed){
286N/A String msg = DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN,
286N/A "wf-invalid-character-in-node-name",
286N/A new Object[]{"Element", node.getNodeName()});
286N/A reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR,
286N/A "wf-invalid-character-in-node-name");
286N/A }
286N/A }
286N/A }
286N/A // push namespace context
286N/A fNamespaceContext.pushContext();
286N/A fLocalNSBinder.reset();
286N/A
286N/A ElementImpl elem = (ElementImpl)node;
286N/A if (elem.needsSyncChildren()) {
286N/A elem.synchronizeChildren();
286N/A }
286N/A AttributeMap attributes = (elem.hasAttributes()) ? (AttributeMap) elem.getAttributes() : null;
286N/A
286N/A // fix namespaces and remove default attributes
286N/A if ((fConfiguration.features & DOMConfigurationImpl.NAMESPACES) !=0) {
286N/A // fix namespaces
286N/A // normalize attribute values
286N/A // remove default attributes
286N/A namespaceFixUp(elem, attributes);
286N/A
286N/A if ((fConfiguration.features & DOMConfigurationImpl.NSDECL) == 0 && attributes != null ) {
286N/A for (int i = 0; i < attributes.getLength(); ++i) {
286N/A Attr att = (Attr)attributes.getItem(i);
286N/A if (XMLSymbols.PREFIX_XMLNS.equals(att.getPrefix()) ||
286N/A XMLSymbols.PREFIX_XMLNS.equals(att.getName())) {
286N/A elem.removeAttributeNode(att);
286N/A --i;
286N/A }
286N/A }
286N/A }
286N/A
286N/A } else {
286N/A if ( attributes!=null ) {
286N/A for ( int i=0; i<attributes.getLength(); ++i ) {
286N/A Attr attr = (Attr)attributes.item(i);
286N/A //removeDefault(attr, attributes);
286N/A attr.normalize();
286N/A if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0)){
286N/A isAttrValueWF(fErrorHandler, fError, fLocator, attributes, (AttrImpl)attr, attr.getValue(), fDocument.isXML11Version());
286N/A if (fDocument.isXMLVersionChanged()){
286N/A wellformed=CoreDocumentImpl.isXMLName(node.getNodeName() , fDocument.isXML11Version());
286N/A if (!wellformed){
286N/A String msg = DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN,
286N/A "wf-invalid-character-in-node-name",
286N/A new Object[]{"Attr",node.getNodeName()});
286N/A reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR,
286N/A "wf-invalid-character-in-node-name");
286N/A }
286N/A }
286N/A }
286N/A }
286N/A }
286N/A }
286N/A
286N/A
286N/A if (fValidationHandler != null) {
286N/A // REVISIT: possible solutions to discard default content are:
286N/A // either we pass some flag to XML Schema validator
286N/A // or rely on the PSVI information.
286N/A fAttrProxy.setAttributes(attributes, fDocument, elem);
286N/A updateQName(elem, fQName); // updates global qname
286N/A // set error node in the dom error wrapper
286N/A // so if error occurs we can report an error node
286N/A fConfiguration.fErrorHandlerWrapper.fCurrentNode = node;
286N/A fCurrentNode = node;
286N/A // call re-validation handler
286N/A fValidationHandler.startElement(fQName, fAttrProxy, null);
286N/A }
286N/A
286N/A if (fDTDValidator != null) {
286N/A // REVISIT: possible solutions to discard default content are:
286N/A // either we pass some flag to XML Schema validator
286N/A // or rely on the PSVI information.
286N/A fAttrProxy.setAttributes(attributes, fDocument, elem);
286N/A updateQName(elem, fQName); // updates global qname
286N/A // set error node in the dom error wrapper
286N/A // so if error occurs we can report an error node
286N/A fConfiguration.fErrorHandlerWrapper.fCurrentNode = node;
286N/A fCurrentNode = node;
286N/A // call re-validation handler
286N/A fDTDValidator.startElement(fQName, fAttrProxy, null);
286N/A }
286N/A
286N/A // normalize children
286N/A Node kid, next;
286N/A for (kid = elem.getFirstChild(); kid != null; kid = next) {
286N/A next = kid.getNextSibling();
286N/A kid = normalizeNode(kid);
286N/A if (kid !=null) {
286N/A next = kid; // don't advance
286N/A }
286N/A }
286N/A if (DEBUG_ND) {
286N/A // normalized subtree
286N/A System.out.println("***The children of {"+node.getNodeName()+"} are normalized");
286N/A for (kid = elem.getFirstChild(); kid != null; kid = next) {
286N/A next = kid.getNextSibling();
286N/A System.out.println(kid.getNodeName() +"["+kid.getNodeValue()+"]");
286N/A }
286N/A
286N/A }
286N/A
286N/A
286N/A if (fValidationHandler != null) {
286N/A updateQName(elem, fQName); // updates global qname
286N/A //
286N/A // set error node in the dom error wrapper
286N/A // so if error occurs we can report an error node
286N/A fConfiguration.fErrorHandlerWrapper.fCurrentNode = node;
286N/A fCurrentNode = node;
286N/A fValidationHandler.endElement(fQName, null);
286N/A }
286N/A
286N/A if (fDTDValidator != null) {
286N/A updateQName(elem, fQName); // updates global qname
286N/A //
286N/A // set error node in the dom error wrapper
286N/A // so if error occurs we can report an error node
286N/A fConfiguration.fErrorHandlerWrapper.fCurrentNode = node;
286N/A fCurrentNode = node;
286N/A fDTDValidator.endElement(fQName, null);
286N/A }
286N/A
286N/A // pop namespace context
286N/A fNamespaceContext.popContext();
286N/A
286N/A break;
286N/A }
286N/A
286N/A case Node.COMMENT_NODE: {
286N/A if (DEBUG_ND) {
286N/A System.out.println("==>normalizeNode:{comments}");
286N/A }
286N/A
286N/A if ((fConfiguration.features & DOMConfigurationImpl.COMMENTS) == 0) {
286N/A Node prevSibling = node.getPreviousSibling();
286N/A Node parent = node.getParentNode();
286N/A // remove the comment node
286N/A parent.removeChild(node);
286N/A if (prevSibling != null && prevSibling.getNodeType() == Node.TEXT_NODE) {
286N/A Node nextSibling = prevSibling.getNextSibling();
286N/A if (nextSibling != null && nextSibling.getNodeType() == Node.TEXT_NODE) {
286N/A ((TextImpl)nextSibling).insertData(0, prevSibling.getNodeValue());
286N/A parent.removeChild(prevSibling);
286N/A return nextSibling;
286N/A }
286N/A }
286N/A }//if comment node need not be removed
286N/A else {
286N/A if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0)){
286N/A String commentdata = ((Comment)node).getData();
286N/A // check comments for invalid xml chracter as per the version
286N/A // of the document
286N/A isCommentWF(fErrorHandler, fError, fLocator, commentdata, fDocument.isXML11Version());
286N/A }
286N/A }//end-else if comment node is not to be removed.
286N/A break;
286N/A }
286N/A case Node.ENTITY_REFERENCE_NODE: {
286N/A if (DEBUG_ND) {
286N/A System.out.println("==>normalizeNode:{entityRef} "+node.getNodeName());
286N/A }
286N/A
286N/A if ((fConfiguration.features & DOMConfigurationImpl.ENTITIES) == 0) {
286N/A Node prevSibling = node.getPreviousSibling();
286N/A Node parent = node.getParentNode();
286N/A ((EntityReferenceImpl)node).setReadOnly(false, true);
286N/A expandEntityRef (parent, node);
286N/A parent.removeChild(node);
286N/A Node next = (prevSibling != null)?prevSibling.getNextSibling():parent.getFirstChild();
286N/A // The list of children #text -> &ent;
286N/A // and entity has a first child as a text
286N/A // we should not advance
286N/A if (prevSibling != null && next != null && prevSibling.getNodeType() == Node.TEXT_NODE &&
286N/A next.getNodeType() == Node.TEXT_NODE) {
286N/A return prevSibling; // Don't advance
286N/A }
286N/A return next;
286N/A } else {
286N/A if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) &&
286N/A fDocument.isXMLVersionChanged()){
286N/A CoreDocumentImpl.isXMLName(node.getNodeName() , fDocument.isXML11Version());
286N/A }
286N/A // REVISIT: traverse entity reference and send appropriate calls to the validator
286N/A // (no normalization should be performed for the children).
286N/A }
286N/A break;
286N/A }
286N/A
286N/A case Node.CDATA_SECTION_NODE: {
286N/A if (DEBUG_ND) {
286N/A System.out.println("==>normalizeNode:{cdata}");
286N/A }
286N/A
286N/A if ((fConfiguration.features & DOMConfigurationImpl.CDATA) == 0) {
286N/A // convert CDATA to TEXT nodes
286N/A Node prevSibling = node.getPreviousSibling();
286N/A if (prevSibling != null && prevSibling.getNodeType() == Node.TEXT_NODE){
286N/A ((Text)prevSibling).appendData(node.getNodeValue());
286N/A node.getParentNode().removeChild(node);
286N/A return prevSibling; //don't advance
286N/A }
286N/A else {
286N/A Text text = fDocument.createTextNode(node.getNodeValue());
286N/A Node parent = node.getParentNode();
286N/A node = parent.replaceChild(text, node);
286N/A return text; //don't advance
286N/A
286N/A }
286N/A }
286N/A
286N/A // send characters call for CDATA
286N/A if (fValidationHandler != null) {
286N/A // set error node in the dom error wrapper
286N/A // so if error occurs we can report an error node
286N/A fConfiguration.fErrorHandlerWrapper.fCurrentNode = node;
286N/A fCurrentNode = node;
286N/A fValidationHandler.startCDATA(null);
286N/A fValidationHandler.characterData(node.getNodeValue(), null);
286N/A fValidationHandler.endCDATA(null);
286N/A }
286N/A
286N/A if (fDTDValidator != null) {
286N/A // set error node in the dom error wrapper
286N/A // so if error occurs we can report an error node
286N/A fConfiguration.fErrorHandlerWrapper.fCurrentNode = node;
286N/A fCurrentNode = node;
286N/A fDTDValidator.startCDATA(null);
286N/A fDTDValidator.characterData(node.getNodeValue(), null);
286N/A fDTDValidator.endCDATA(null);
286N/A }
286N/A String value = node.getNodeValue();
286N/A
286N/A if ((fConfiguration.features & DOMConfigurationImpl.SPLITCDATA) != 0) {
286N/A int index;
286N/A Node parent = node.getParentNode();
286N/A if (fDocument.errorChecking) {
286N/A isXMLCharWF(fErrorHandler, fError, fLocator, node.getNodeValue(), fDocument.isXML11Version());
286N/A }
286N/A while ( (index=value.indexOf("]]>")) >= 0 ) {
286N/A node.setNodeValue(value.substring(0, index+2));
286N/A value = value.substring(index +2);
286N/A
286N/A Node firstSplitNode = node;
286N/A Node newChild = fDocument.createCDATASection(value);
286N/A parent.insertBefore(newChild, node.getNextSibling());
286N/A node = newChild;
286N/A // issue warning
286N/A fLocator.fRelatedNode = firstSplitNode;
286N/A String msg = DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN,
286N/A "cdata-sections-splitted",
286N/A null);
286N/A reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_WARNING,
286N/A "cdata-sections-splitted");
286N/A }
286N/A
286N/A }
286N/A else if (fDocument.errorChecking) {
286N/A // check well-formedness
286N/A isCDataWF(fErrorHandler, fError, fLocator, value, fDocument.isXML11Version());
286N/A }
286N/A break;
286N/A }
286N/A
286N/A case Node.TEXT_NODE: {
286N/A if (DEBUG_ND) {
286N/A System.out.println("==>normalizeNode(text):{"+node.getNodeValue()+"}");
286N/A }
286N/A // If node is a text node, we need to check for one of two
286N/A // conditions:
286N/A // 1) There is an adjacent text node
286N/A // 2) There is no adjacent text node, but node is
286N/A // an empty text node.
286N/A Node next = node.getNextSibling();
286N/A // If an adjacent text node, merge it with this node
286N/A if ( next!=null && next.getNodeType() == Node.TEXT_NODE ) {
286N/A ((Text)node).appendData(next.getNodeValue());
286N/A node.getParentNode().removeChild( next );
286N/A // We don't need to check well-formness here since we are not yet
286N/A // done with this node.
286N/A
286N/A return node; // Don't advance;
286N/A } else if (node.getNodeValue().length()==0) {
286N/A // If kid is empty, remove it
286N/A node.getParentNode().removeChild( node );
286N/A } else {
286N/A // validator.characters() call and well-formness
286N/A // Don't send characters or check well-formness in the following cases:
286N/A // 1. entities is false, next child is entity reference: expand tree first
286N/A // 2. comments is false, and next child is comment
286N/A // 3. cdata is false, and next child is cdata
286N/A
286N/A short nextType = (next != null)?next.getNodeType():-1;
286N/A if (nextType == -1 || !(((fConfiguration.features & DOMConfigurationImpl.ENTITIES) == 0 &&
286N/A nextType == Node.ENTITY_NODE) ||
286N/A ((fConfiguration.features & DOMConfigurationImpl.COMMENTS) == 0 &&
286N/A nextType == Node.COMMENT_NODE) ||
286N/A ((fConfiguration.features & DOMConfigurationImpl.CDATA) == 0) &&
286N/A nextType == Node.CDATA_SECTION_NODE)) {
286N/A if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) ){
286N/A isXMLCharWF(fErrorHandler, fError, fLocator, node.getNodeValue(), fDocument.isXML11Version());
286N/A }
286N/A if (fValidationHandler != null) {
286N/A fConfiguration.fErrorHandlerWrapper.fCurrentNode = node;
286N/A fCurrentNode = node;
286N/A fValidationHandler.characterData(node.getNodeValue(), null);
286N/A if (DEBUG_ND) {
286N/A System.out.println("=====>characterData(),"+nextType);
286N/A
286N/A }
286N/A }
286N/A if (fDTDValidator != null) {
286N/A fConfiguration.fErrorHandlerWrapper.fCurrentNode = node;
286N/A fCurrentNode = node;
286N/A fDTDValidator.characterData(node.getNodeValue(), null);
286N/A if (DEBUG_ND) {
286N/A System.out.println("=====>characterData(),"+nextType);
286N/A
286N/A }
286N/A if(allWhitespace) {
286N/A allWhitespace = false;
286N/A ((TextImpl)node).setIgnorableWhitespace(true);
286N/A }
286N/A }
286N/A }
286N/A else {
286N/A if (DEBUG_ND) {
286N/A System.out.println("=====>don't send characters(),"+nextType);
286N/A
286N/A }
286N/A }
286N/A }
286N/A break;
286N/A }
286N/A case Node.PROCESSING_INSTRUCTION_NODE: {
286N/A
286N/A //do the well-formed valid PI target name , data check when application has set the value of well-formed feature to true
286N/A if (fDocument.errorChecking && (fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0 ) {
286N/A ProcessingInstruction pinode = (ProcessingInstruction)node ;
286N/A
286N/A String target = pinode.getTarget();
286N/A //1.check PI target name
286N/A if(fDocument.isXML11Version()){
286N/A wellformed = XML11Char.isXML11ValidName(target);
286N/A }
286N/A else{
286N/A wellformed = XMLChar.isValidName(target);
286N/A }
286N/A
286N/A if (!wellformed) {
286N/A String msg = DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN,
286N/A "wf-invalid-character-in-node-name",
286N/A new Object[]{"Element", node.getNodeName()});
286N/A reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR,
286N/A "wf-invalid-character-in-node-name");
286N/A }
286N/A
286N/A //2. check PI data
286N/A //processing isntruction data may have certain characters
286N/A //which may not be valid XML character
286N/A isXMLCharWF(fErrorHandler, fError, fLocator, pinode.getData(), fDocument.isXML11Version());
286N/A }
286N/A }//end case Node.PROCESSING_INSTRUCTION_NODE
286N/A
286N/A }//end of switch
286N/A return null;
286N/A }//normalizeNode
286N/A
286N/A private XMLGrammarPool createGrammarPool(DocumentTypeImpl docType) {
286N/A
286N/A XMLGrammarPoolImpl pool = new XMLGrammarPoolImpl();
286N/A
286N/A XMLGrammarPreparser preParser = new XMLGrammarPreparser(fSymbolTable);
286N/A preParser.registerPreparser(XMLGrammarDescription.XML_DTD, null);
286N/A preParser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
286N/A preParser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, true);
286N/A preParser.setProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY, pool);
286N/A
286N/A String internalSubset = docType.getInternalSubset();
286N/A XMLInputSource is = new XMLInputSource(docType.getPublicId(), docType.getSystemId(), null);
286N/A
286N/A if(internalSubset != null)
286N/A is.setCharacterStream(new StringReader(internalSubset));
286N/A try {
286N/A DTDGrammar g = (DTDGrammar)preParser.preparseGrammar(XMLGrammarDescription.XML_DTD, is);
286N/A ((XMLDTDDescription)g.getGrammarDescription()).setRootName(docType.getName());
286N/A is.setCharacterStream(null);
286N/A g = (DTDGrammar)preParser.preparseGrammar(XMLGrammarDescription.XML_DTD, is);
286N/A ((XMLDTDDescription)g.getGrammarDescription()).setRootName(docType.getName());
286N/A
286N/A } catch (XNIException e) {
286N/A } catch (IOException e) {
286N/A }
286N/A
286N/A return pool;
286N/A }
286N/A
286N/A
286N/A
286N/A protected final void expandEntityRef (Node parent, Node reference){
286N/A Node kid, next;
286N/A for (kid = reference.getFirstChild(); kid != null; kid = next) {
286N/A next = kid.getNextSibling();
286N/A parent.insertBefore(kid, reference);
286N/A }
286N/A }
286N/A
286N/A // fix namespaces
286N/A // normalize attribute values
286N/A // remove default attributes
286N/A // check attribute names if the version of the document changed.
286N/A
286N/A protected final void namespaceFixUp (ElementImpl element, AttributeMap attributes){
286N/A if (DEBUG) {
286N/A System.out.println("[ns-fixup] element:" +element.getNodeName()+
286N/A " uri: "+element.getNamespaceURI());
286N/A }
286N/A
286N/A // ------------------------------------
286N/A // pick up local namespace declarations
286N/A // <xsl:stylesheet xmlns:xsl="http://xslt">
286N/A // <!-- add the following via DOM
286N/A // body is bound to http://xslt
286N/A // -->
286N/A // <xsl:body xmlns:xsl="http://bound"/>
286N/A //
286N/A // ------------------------------------
286N/A
286N/A String value, name, uri, prefix;
286N/A if (attributes != null) {
286N/A
286N/A // Record all valid local declarations
286N/A for (int k = 0; k < attributes.getLength(); ++k) {
286N/A Attr attr = (Attr)attributes.getItem(k);
286N/A
286N/A //do the name check only when version of the document was changed &
286N/A //application has set the value of well-formed features to true
286N/A if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) &&
286N/A fDocument.isXMLVersionChanged()) {
286N/A //checkQName does checking based on the version of the document
286N/A fDocument.checkQName(attr.getPrefix() , attr.getLocalName()) ;
286N/A }
286N/A
286N/A uri = attr.getNamespaceURI();
286N/A if (uri != null && uri.equals(NamespaceContext.XMLNS_URI)) {
286N/A // namespace attribute
286N/A
286N/A // "namespace-declarations" == false; Discard all namespace declaration attributes
286N/A if ((fConfiguration.features & DOMConfigurationImpl.NSDECL) == 0) {
286N/A continue;
286N/A }
286N/A
286N/A value = attr.getNodeValue();
286N/A if (value == null) {
286N/A value=XMLSymbols.EMPTY_STRING;
286N/A }
286N/A
286N/A // Check for invalid namespace declaration:
286N/A if (fDocument.errorChecking && value.equals(NamespaceContext.XMLNS_URI)) {
286N/A //A null value for locale is passed to formatMessage,
286N/A //which means that the default locale will be used
286N/A fLocator.fRelatedNode = attr;
286N/A String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,"CantBindXMLNS",null );
286N/A reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, "CantBindXMLNS");
286N/A } else {
286N/A // XML 1.0 Attribute value normalization
286N/A // value = normalizeAttributeValue(value, attr);
286N/A prefix = attr.getPrefix();
286N/A prefix = (prefix == null ||
286N/A prefix.length() == 0) ? XMLSymbols.EMPTY_STRING :fSymbolTable.addSymbol(prefix);
286N/A String localpart = fSymbolTable.addSymbol( attr.getLocalName());
286N/A if (prefix == XMLSymbols.PREFIX_XMLNS) { //xmlns:prefix
286N/A
286N/A value = fSymbolTable.addSymbol(value);
286N/A if (value.length() != 0) {
286N/A fNamespaceContext.declarePrefix(localpart, value);
286N/A } else {
286N/A // REVISIT: issue error on invalid declarations
286N/A // xmlns:foo = ""
286N/A
286N/A }
286N/A //removeDefault (attr, attributes);
286N/A continue;
286N/A } else { // (localpart == fXmlnsSymbol && prefix == fEmptySymbol) -- xmlns
286N/A // empty prefix is always bound ("" or some string)
286N/A value = fSymbolTable.addSymbol(value);
286N/A fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING, value);
286N/A //removeDefault (attr, attributes);
286N/A continue;
286N/A }
286N/A } // end-else: valid declaration
286N/A } // end-if: namespace attribute
286N/A }
286N/A }
286N/A
286N/A
286N/A
286N/A // ---------------------------------------------------------
286N/A // Fix up namespaces for element: per DOM L3
286N/A // Need to consider the following cases:
286N/A //
286N/A // case 1: <xsl:stylesheet xmlns:xsl="http://xsl">
286N/A // We create another element body bound to the "http://xsl" namespace
286N/A // as well as namespace attribute rebounding xsl to another namespace.
286N/A // <xsl:body xmlns:xsl="http://another">
286N/A // Need to make sure that the new namespace decl value is changed to
286N/A // "http://xsl"
286N/A //
286N/A // ---------------------------------------------------------
286N/A // check if prefix/namespace is correct for current element
286N/A // ---------------------------------------------------------
286N/A
286N/A uri = element.getNamespaceURI();
286N/A prefix = element.getPrefix();
286N/A
286N/A // "namespace-declarations" == false? Discard all namespace declaration attributes
286N/A if ((fConfiguration.features & DOMConfigurationImpl.NSDECL) == 0) {
286N/A // no namespace declaration == no namespace URI, semantics are to keep prefix
286N/A uri = null;
286N/A } else if (uri != null) { // Element has a namespace
286N/A uri = fSymbolTable.addSymbol(uri);
286N/A prefix = (prefix == null ||
286N/A prefix.length() == 0) ? XMLSymbols.EMPTY_STRING :fSymbolTable.addSymbol(prefix);
286N/A if (fNamespaceContext.getURI(prefix) == uri) {
286N/A // The xmlns:prefix=namespace or xmlns="default" was declared at parent.
286N/A // The binder always stores mapping of empty prefix to "".
286N/A } else {
286N/A // the prefix is either undeclared
286N/A // or
286N/A // conflict: the prefix is bound to another URI
286N/A addNamespaceDecl(prefix, uri, element);
286N/A fLocalNSBinder.declarePrefix(prefix, uri);
286N/A fNamespaceContext.declarePrefix(prefix, uri);
286N/A }
286N/A } else { // Element has no namespace
286N/A if (element.getLocalName() == null) {
286N/A
286N/A // Error: DOM Level 1 node!
286N/A if (fNamespaceValidation) {
286N/A String msg = DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN, "NullLocalElementName",
286N/A new Object[]{element.getNodeName()});
286N/A reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_FATAL_ERROR,
286N/A "NullLocalElementName");
286N/A } else {
286N/A String msg = DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN, "NullLocalElementName",
286N/A new Object[]{element.getNodeName()});
286N/A reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR,
286N/A "NullLocalElementName");
286N/A }
286N/A
286N/A } else { // uri=null and no colon (DOM L2 node)
286N/A uri = fNamespaceContext.getURI(XMLSymbols.EMPTY_STRING);
286N/A if (uri !=null && uri.length() > 0) {
286N/A // undeclare default namespace declaration (before that element
286N/A // bound to non-zero length uir), but adding xmlns="" decl
286N/A addNamespaceDecl (XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING, element);
286N/A fLocalNSBinder.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING);
286N/A fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING);
286N/A }
286N/A }
286N/A }
286N/A
286N/A // -----------------------------------------
286N/A // Fix up namespaces for attributes: per DOM L3
286N/A // check if prefix/namespace is correct the attributes
286N/A // -----------------------------------------
286N/A if (attributes != null) {
286N/A
286N/A // clone content of the attributes
286N/A attributes.cloneMap(fAttributeList);
286N/A for (int i = 0; i < fAttributeList.size(); i++) {
286N/A Attr attr = (Attr) fAttributeList.get(i);
286N/A fLocator.fRelatedNode = attr;
286N/A
286N/A if (DEBUG) {
286N/A System.out.println("==>[ns-fixup] process attribute: "+attr.getNodeName());
286N/A }
286N/A // normalize attribute value
286N/A attr.normalize();
286N/A value = attr.getValue();
286N/A name = attr.getNodeName();
286N/A uri = attr.getNamespaceURI();
286N/A
286N/A // make sure that value is never null.
286N/A if (value == null) {
286N/A value=XMLSymbols.EMPTY_STRING;
286N/A }
286N/A
286N/A if (uri != null) { // attribute has namespace !=null
286N/A prefix = attr.getPrefix();
286N/A prefix = (prefix == null ||
286N/A prefix.length() == 0) ? XMLSymbols.EMPTY_STRING :fSymbolTable.addSymbol(prefix);
286N/A /*String localpart =*/ fSymbolTable.addSymbol( attr.getLocalName());
286N/A
286N/A // ---------------------------------------
286N/A // skip namespace declarations
286N/A // ---------------------------------------
286N/A // REVISIT: can we assume that "uri" is from some symbol
286N/A // table, and compare by reference? -SG
286N/A if (uri != null && uri.equals(NamespaceContext.XMLNS_URI)) {
286N/A continue;
286N/A }
286N/A //---------------------------------------
286N/A // check if value of the attribute is namespace well-formed
286N/A //---------------------------------------
286N/A if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0)) {
286N/A isAttrValueWF(fErrorHandler, fError, fLocator, attributes, (AttrImpl)attr, attr.getValue(), fDocument.isXML11Version());
286N/A if (fDocument.isXMLVersionChanged()){
286N/A boolean wellformed=CoreDocumentImpl.isXMLName(attr.getNodeName() , fDocument.isXML11Version());
286N/A if (!wellformed){
286N/A String msg = DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN,
286N/A "wf-invalid-character-in-node-name",
286N/A new Object[]{"Attribute", attr.getNodeName()});
286N/A reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR,
286N/A "wf-invalid-character-in-node-name");
286N/A }
286N/A }
286N/A }
286N/A
286N/A // ---------------------------------------
286N/A // remove default attributes
286N/A // ---------------------------------------
286N/A /*
286N/A if (removeDefault(attr, attributes)) {
286N/A continue;
286N/A }
286N/A */
286N/A // XML 1.0 Attribute value normalization
286N/A //value = normalizeAttributeValue(value, attr);
286N/A
286N/A // reset id-attributes
286N/A ((AttrImpl)attr).setIdAttribute(false);
286N/A
286N/A
286N/A uri = fSymbolTable.addSymbol(uri);
286N/A
286N/A // find if for this prefix a URI was already declared
286N/A String declaredURI = fNamespaceContext.getURI(prefix);
286N/A
286N/A if (prefix == XMLSymbols.EMPTY_STRING || declaredURI != uri) {
286N/A // attribute has no prefix (default namespace decl does not apply to attributes)
286N/A // OR
286N/A // attribute prefix is not declared
286N/A // OR
286N/A // conflict: attribute has a prefix that conficlicts with a binding
286N/A // already active in scope
286N/A
286N/A name = attr.getNodeName();
286N/A // Find if any prefix for attributes namespace URI is available
286N/A // in the scope
286N/A String declaredPrefix = fNamespaceContext.getPrefix(uri);
286N/A if (declaredPrefix !=null && declaredPrefix !=XMLSymbols.EMPTY_STRING) {
286N/A
286N/A // use the prefix that was found (declared previously for this URI
286N/A prefix = declaredPrefix;
286N/A } else {
286N/A if (prefix != XMLSymbols.EMPTY_STRING && fLocalNSBinder.getURI(prefix) == null) {
286N/A // the current prefix is not null and it has no in scope declaration
286N/A
286N/A // use this prefix
286N/A } else {
286N/A
286N/A // find a prefix following the pattern "NS" +index (starting at 1)
286N/A // make sure this prefix is not declared in the current scope.
286N/A int counter = 1;
286N/A prefix = fSymbolTable.addSymbol(PREFIX +counter++);
286N/A while (fLocalNSBinder.getURI(prefix)!=null) {
286N/A prefix = fSymbolTable.addSymbol(PREFIX +counter++);
286N/A }
286N/A
286N/A }
286N/A // add declaration for the new prefix
286N/A addNamespaceDecl(prefix, uri, element);
286N/A value = fSymbolTable.addSymbol(value);
286N/A fLocalNSBinder.declarePrefix(prefix, value);
286N/A fNamespaceContext.declarePrefix(prefix, uri);
286N/A }
286N/A
286N/A // change prefix for this attribute
286N/A attr.setPrefix(prefix);
286N/A }
286N/A } else { // attribute uri == null
286N/A
286N/A // XML 1.0 Attribute value normalization
286N/A //value = normalizeAttributeValue(value, attr);
286N/A
286N/A // reset id-attributes
286N/A ((AttrImpl)attr).setIdAttribute(false);
286N/A
286N/A if (attr.getLocalName() == null) {
286N/A // It is an error if document has DOM L1 nodes.
286N/A if (fNamespaceValidation) {
286N/A String msg = DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN,
286N/A "NullLocalAttrName", new Object[]{attr.getNodeName()});
286N/A reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_FATAL_ERROR,
286N/A "NullLocalAttrName");
286N/A } else {
286N/A String msg = DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN,
286N/A "NullLocalAttrName", new Object[]{attr.getNodeName()});
286N/A reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR,
286N/A "NullLocalAttrName");
286N/A }
286N/A } else {
286N/A // uri=null and no colon
286N/A // no fix up is needed: default namespace decl does not
286N/A
286N/A // ---------------------------------------
286N/A // remove default attributes
286N/A // ---------------------------------------
286N/A // removeDefault(attr, attributes);
286N/A }
286N/A }
286N/A }
286N/A } // end loop for attributes
286N/A }
286N/A
286N/A /**
286N/A * Adds a namespace attribute or replaces the value of existing namespace
286N/A * attribute with the given prefix and value for URI.
286N/A * In case prefix is empty will add/update default namespace declaration.
286N/A *
286N/A * @param prefix
286N/A * @param uri
286N/A * @exception IOException
286N/A */
286N/A
286N/A protected final void addNamespaceDecl(String prefix, String uri, ElementImpl element){
286N/A if (DEBUG) {
286N/A System.out.println("[ns-fixup] addNamespaceDecl ["+prefix+"]");
286N/A }
286N/A if (prefix == XMLSymbols.EMPTY_STRING) {
286N/A if (DEBUG) {
286N/A System.out.println("=>add xmlns=\""+uri+"\" declaration");
286N/A }
286N/A element.setAttributeNS(NamespaceContext.XMLNS_URI, XMLSymbols.PREFIX_XMLNS, uri);
286N/A } else {
286N/A if (DEBUG) {
286N/A System.out.println("=>add xmlns:"+prefix+"=\""+uri+"\" declaration");
286N/A }
286N/A element.setAttributeNS(NamespaceContext.XMLNS_URI, "xmlns:"+prefix, uri);
286N/A }
286N/A }
286N/A
286N/A
286N/A //
286N/A // Methods for well-formness checking
286N/A //
286N/A
286N/A
286N/A /**
286N/A * Check if CDATA section is well-formed
286N/A * @param datavalue
286N/A * @param isXML11Version = true if XML 1.1
286N/A */
286N/A public static final void isCDataWF(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
286N/A String datavalue, boolean isXML11Version)
286N/A {
286N/A if (datavalue == null || (datavalue.length() == 0) ) {
286N/A return;
286N/A }
286N/A
286N/A char [] dataarray = datavalue.toCharArray();
286N/A int datalength = dataarray.length;
286N/A
286N/A // version of the document is XML 1.1
286N/A if (isXML11Version) {
286N/A // we need to check all chracters as per production rules of XML11
286N/A int i = 0;
286N/A while(i < datalength){
286N/A char c = dataarray[i++];
286N/A if ( XML11Char.isXML11Invalid(c) ) {
286N/A // check if this is a supplemental character
286N/A if (XMLChar.isHighSurrogate(c) && i < datalength) {
286N/A char c2 = dataarray[i++];
286N/A if (XMLChar.isLowSurrogate(c2) &&
286N/A XMLChar.isSupplemental(XMLChar.supplemental(c, c2))) {
286N/A continue;
286N/A }
286N/A }
286N/A String msg = DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.XML_DOMAIN,
286N/A "InvalidCharInCDSect",
286N/A new Object[] { Integer.toString(c, 16)});
286N/A reportDOMError(
286N/A errorHandler,
286N/A error,
286N/A locator,
286N/A msg,
286N/A DOMError.SEVERITY_ERROR,
286N/A "wf-invalid-character");
286N/A }
286N/A else if (c == ']') {
286N/A int count = i;
286N/A if (count < datalength && dataarray[count] == ']') {
286N/A while (++count < datalength && dataarray[count] == ']') {
286N/A // do nothing
286N/A }
286N/A if (count < datalength && dataarray[count] == '>') {
286N/A // CDEndInContent
286N/A String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN, "CDEndInContent", null);
286N/A reportDOMError(errorHandler, error, locator,msg, DOMError.SEVERITY_ERROR, "wf-invalid-character");
286N/A }
286N/A }
286N/A
286N/A }
286N/A }
286N/A } // version of the document is XML 1.0
286N/A else {
286N/A // we need to check all chracters as per production rules of XML 1.0
286N/A int i = 0;
286N/A while (i < datalength) {
286N/A char c = dataarray[i++];
286N/A if( XMLChar.isInvalid(c) ) {
286N/A // check if this is a supplemental character
286N/A if (XMLChar.isHighSurrogate(c) && i < datalength) {
286N/A char c2 = dataarray[i++];
286N/A if (XMLChar.isLowSurrogate(c2) &&
286N/A XMLChar.isSupplemental(XMLChar.supplemental(c, c2))) {
286N/A continue;
286N/A }
286N/A }
286N/A // Note: The key InvalidCharInCDSect from XMLMessages.properties
286N/A // is being used to obtain the message and DOM error type
286N/A // "wf-invalid-character" is used. Also per DOM it is error but
286N/A // as per XML spec. it is fatal error
286N/A String msg = DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.XML_DOMAIN,
286N/A "InvalidCharInCDSect",
286N/A new Object[]{Integer.toString(c, 16)});
286N/A reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character");
286N/A }
286N/A else if (c==']') {
286N/A int count = i;
286N/A if ( count< datalength && dataarray[count]==']' ) {
286N/A while (++count < datalength && dataarray[count]==']' ) {
286N/A // do nothing
286N/A }
286N/A if ( count < datalength && dataarray[count]=='>' ) {
286N/A String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN, "CDEndInContent", null);
286N/A reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character");
286N/A }
286N/A }
286N/A
286N/A }
286N/A }
286N/A } // end-else fDocument.isXMLVersion()
286N/A
286N/A } // isCDataWF
286N/A
286N/A /**
286N/A * NON-DOM: check for valid XML characters as per the XML version
286N/A * @param datavalue
286N/A * @param isXML11Version = true if XML 1.1
286N/A */
286N/A public static final void isXMLCharWF(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
286N/A String datavalue, boolean isXML11Version)
286N/A {
286N/A if ( datavalue == null || (datavalue.length() == 0) ) {
286N/A return;
286N/A }
286N/A
286N/A char [] dataarray = datavalue.toCharArray();
286N/A int datalength = dataarray.length;
286N/A
286N/A // version of the document is XML 1.1
286N/A if(isXML11Version){
286N/A //we need to check all characters as per production rules of XML11
286N/A int i = 0 ;
286N/A while (i < datalength) {
286N/A if(XML11Char.isXML11Invalid(dataarray[i++])){
286N/A // check if this is a supplemental character
286N/A char ch = dataarray[i-1];
286N/A if (XMLChar.isHighSurrogate(ch) && i < datalength) {
286N/A char ch2 = dataarray[i++];
286N/A if (XMLChar.isLowSurrogate(ch2) &&
286N/A XMLChar.isSupplemental(XMLChar.supplemental(ch, ch2))) {
286N/A continue;
286N/A }
286N/A }
286N/A String msg = DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN, "InvalidXMLCharInDOM",
286N/A new Object[]{Integer.toString(dataarray[i-1], 16)});
286N/A reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR,
286N/A "wf-invalid-character");
286N/A }
286N/A }
286N/A } // version of the document is XML 1.0
286N/A else{
286N/A // we need to check all characters as per production rules of XML 1.0
286N/A int i = 0 ;
286N/A while (i < datalength) {
286N/A if( XMLChar.isInvalid(dataarray[i++]) ) {
286N/A // check if this is a supplemental character
286N/A char ch = dataarray[i-1];
286N/A if (XMLChar.isHighSurrogate(ch) && i < datalength) {
286N/A char ch2 = dataarray[i++];
286N/A if (XMLChar.isLowSurrogate(ch2) &&
286N/A XMLChar.isSupplemental(XMLChar.supplemental(ch, ch2))) {
286N/A continue;
286N/A }
286N/A }
286N/A String msg = DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN, "InvalidXMLCharInDOM",
286N/A new Object[]{Integer.toString(dataarray[i-1], 16)});
286N/A reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR,
286N/A "wf-invalid-character");
286N/A }
286N/A }
286N/A } // end-else fDocument.isXMLVersion()
286N/A
286N/A } // isXMLCharWF
286N/A
286N/A /**
286N/A * NON-DOM: check if value of the comment is well-formed
286N/A * @param datavalue
286N/A * @param isXML11Version = true if XML 1.1
286N/A */
286N/A public static final void isCommentWF(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
286N/A String datavalue, boolean isXML11Version)
286N/A {
286N/A if ( datavalue == null || (datavalue.length() == 0) ) {
286N/A return;
286N/A }
286N/A
286N/A char [] dataarray = datavalue.toCharArray();
286N/A int datalength = dataarray.length ;
286N/A
286N/A // version of the document is XML 1.1
286N/A if (isXML11Version) {
286N/A // we need to check all chracters as per production rules of XML11
286N/A int i = 0 ;
286N/A while (i < datalength){
286N/A char c = dataarray[i++];
286N/A if ( XML11Char.isXML11Invalid(c) ) {
286N/A // check if this is a supplemental character
286N/A if (XMLChar.isHighSurrogate(c) && i < datalength) {
286N/A char c2 = dataarray[i++];
286N/A if (XMLChar.isLowSurrogate(c2) &&
286N/A XMLChar.isSupplemental(XMLChar.supplemental(c, c2))) {
286N/A continue;
286N/A }
286N/A }
286N/A String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,
286N/A "InvalidCharInComment",
286N/A new Object [] {Integer.toString(dataarray[i-1], 16)});
286N/A reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character");
286N/A }
286N/A else if (c == '-' && i < datalength && dataarray[i] == '-') {
286N/A String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,
286N/A "DashDashInComment", null);
286N/A // invalid: '--' in comment
286N/A reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character");
286N/A }
286N/A }
286N/A } // version of the document is XML 1.0
286N/A else {
286N/A // we need to check all chracters as per production rules of XML 1.0
286N/A int i = 0;
286N/A while (i < datalength){
286N/A char c = dataarray[i++];
286N/A if( XMLChar.isInvalid(c) ){
286N/A // check if this is a supplemental character
286N/A if (XMLChar.isHighSurrogate(c) && i < datalength) {
286N/A char c2 = dataarray[i++];
286N/A if (XMLChar.isLowSurrogate(c2) &&
286N/A XMLChar.isSupplemental(XMLChar.supplemental(c, c2))) {
286N/A continue;
286N/A }
286N/A }
286N/A String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,
286N/A "InvalidCharInComment", new Object [] {Integer.toString(dataarray[i-1], 16)});
286N/A reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character");
286N/A }
286N/A else if (c == '-' && i<datalength && dataarray[i]=='-'){
286N/A String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,
286N/A "DashDashInComment", null);
286N/A // invalid: '--' in comment
286N/A reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character");
286N/A }
286N/A }
286N/A
286N/A } // end-else fDocument.isXMLVersion()
286N/A
286N/A } // isCommentWF
286N/A
286N/A /** NON-DOM: check if attribute value is well-formed
286N/A * @param attributes
286N/A * @param a
286N/A * @param value
286N/A */
286N/A public static final void isAttrValueWF(DOMErrorHandler errorHandler, DOMErrorImpl error,
286N/A DOMLocatorImpl locator, NamedNodeMap attributes, Attr a, String value, boolean xml11Version) {
286N/A if (a instanceof AttrImpl && ((AttrImpl)a).hasStringValue()) {
286N/A isXMLCharWF(errorHandler, error, locator, value, xml11Version);
286N/A } else {
286N/A NodeList children = a.getChildNodes();
286N/A //check each child node of the attribute's value
286N/A for (int j = 0; j < children.getLength(); j++) {
286N/A Node child = children.item(j);
286N/A //If the attribute's child is an entity refernce
286N/A if (child.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
286N/A Document owner = a.getOwnerDocument();
286N/A Entity ent = null;
286N/A //search for the entity in the docType
286N/A //of the attribute's ownerDocument
286N/A if (owner != null) {
286N/A DocumentType docType = owner.getDoctype();
286N/A if (docType != null) {
286N/A NamedNodeMap entities = docType.getEntities();
286N/A ent = (Entity) entities.getNamedItemNS(
286N/A "*",
286N/A child.getNodeName());
286N/A }
286N/A }
286N/A //If the entity was not found issue a fatal error
286N/A if (ent == null) {
286N/A String msg = DOMMessageFormatter.formatMessage(
286N/A DOMMessageFormatter.DOM_DOMAIN, "UndeclaredEntRefInAttrValue",
286N/A new Object[]{a.getNodeName()});
286N/A reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR,
286N/A "UndeclaredEntRefInAttrValue");
286N/A }
286N/A }
286N/A else {
286N/A // Text node
286N/A isXMLCharWF(errorHandler, error, locator, child.getNodeValue(), xml11Version);
286N/A }
286N/A }
286N/A }
286N/A }
286N/A
286N/A
286N/A
286N/A /**
286N/A * Reports a DOM error to the user handler.
286N/A *
286N/A * If the error is fatal, the processing will be always aborted.
286N/A */
286N/A public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator,
286N/A String message, short severity, String type ) {
286N/A if( errorHandler!=null ) {
286N/A error.reset();
286N/A error.fMessage = message;
286N/A error.fSeverity = severity;
286N/A error.fLocator = locator;
286N/A error.fType = type;
286N/A error.fRelatedData = locator.fRelatedNode;
286N/A
286N/A if(!errorHandler.handleError(error))
286N/A throw abort;
286N/A }
286N/A if( severity==DOMError.SEVERITY_FATAL_ERROR )
286N/A throw abort;
286N/A }
286N/A
286N/A protected final void updateQName (Node node, QName qname){
286N/A
286N/A String prefix = node.getPrefix();
286N/A String namespace = node.getNamespaceURI();
286N/A String localName = node.getLocalName();
286N/A // REVISIT: the symbols are added too often: start/endElement
286N/A // and in the namespaceFixup. Should reduce number of calls to symbol table.
286N/A qname.prefix = (prefix!=null && prefix.length()!=0)?fSymbolTable.addSymbol(prefix):null;
286N/A qname.localpart = (localName != null)?fSymbolTable.addSymbol(localName):null;
286N/A qname.rawname = fSymbolTable.addSymbol(node.getNodeName());
286N/A qname.uri = (namespace != null)?fSymbolTable.addSymbol(namespace):null;
286N/A }
286N/A
286N/A
286N/A
286N/A /* REVISIT: remove this method if DOM does not change spec.
286N/A * Performs partial XML 1.0 attribute value normalization and replaces
286N/A * attribute value if the value is changed after the normalization.
286N/A * DOM defines that normalizeDocument acts as if the document was going
286N/A * through a save and load cycle, given that serializer will not escape
286N/A * any '\n' or '\r' characters on load those will be normalized.
286N/A * Thus during normalize document we need to do the following:
286N/A * - perform "2.11 End-of-Line Handling"
286N/A * - replace #xD, #xA, #x9 with #x20 (white space).
286N/A * Note: This alg. won't attempt to resolve entity references or character entity
286N/A * references, since '&' will be escaped during serialization and during loading
286N/A * this won't be recognized as entity reference, i.e. attribute value "&foo;" will
286N/A * be serialized as "&amp;foo;" and thus after loading will be "&foo;" again.
286N/A * @param value current attribute value
286N/A * @param attr current attribute
286N/A * @return String the value (could be original if normalization did not change
286N/A * the string)
286N/A */
286N/A final String normalizeAttributeValue(String value, Attr attr) {
286N/A if (!attr.getSpecified()){
286N/A // specified attributes should already have a normalized form
286N/A // since those were added by validator
286N/A return value;
286N/A }
286N/A int end = value.length();
286N/A // ensure capacity
286N/A if (fNormalizedValue.ch.length < end) {
286N/A fNormalizedValue.ch = new char[end];
286N/A }
286N/A fNormalizedValue.length = 0;
286N/A boolean normalized = false;
286N/A for (int i = 0; i < end; i++) {
286N/A char c = value.charAt(i);
286N/A if (c==0x0009 || c==0x000A) {
286N/A fNormalizedValue.ch[fNormalizedValue.length++] = ' ';
286N/A normalized = true;
286N/A }
286N/A else if(c==0x000D){
286N/A normalized = true;
286N/A fNormalizedValue.ch[fNormalizedValue.length++] = ' ';
286N/A int next = i+1;
286N/A if (next < end && value.charAt(next)==0x000A) i=next; // skip following xA
286N/A }
286N/A else {
286N/A fNormalizedValue.ch[fNormalizedValue.length++] = c;
286N/A }
286N/A }
286N/A if (normalized){
286N/A value = fNormalizedValue.toString();
286N/A attr.setValue(value);
286N/A }
286N/A return value;
286N/A }
286N/A
286N/A protected final class XMLAttributesProxy
286N/A implements XMLAttributes {
286N/A protected AttributeMap fAttributes;
286N/A protected CoreDocumentImpl fDocument;
286N/A protected ElementImpl fElement;
286N/A
286N/A protected final Vector fAugmentations = new Vector(5);
286N/A
286N/A
286N/A public void setAttributes(AttributeMap attributes, CoreDocumentImpl doc, ElementImpl elem) {
286N/A fDocument = doc;
286N/A fAttributes = attributes;
286N/A fElement = elem;
286N/A if (attributes != null) {
286N/A int length = attributes.getLength();
286N/A
286N/A fAugmentations.setSize(length);
286N/A // REVISIT: this implementation does not store any value in augmentations
286N/A // and basically not keeping augs in parallel to attributes map
286N/A // untill all attributes are added (default attributes)
286N/A for (int i = 0; i < length; i++) {
286N/A fAugmentations.setElementAt(new AugmentationsImpl(), i);
286N/A }
286N/A } else {
286N/A fAugmentations.setSize(0);
286N/A }
286N/A }
286N/A
286N/A
286N/A /**
286N/A * This method adds default declarations
286N/A * @see com.sun.org.apache.xerces.internal.xni.XMLAttributes#addAttribute(QName, String, String)
286N/A */
286N/A public int addAttribute(QName qname, String attrType, String attrValue) {
286N/A int index = fElement.getXercesAttribute(qname.uri, qname.localpart);
286N/A // add defaults to the tree
286N/A if (index < 0) {
286N/A // the default attribute was removed by a user and needed to
286N/A // be added back
286N/A AttrImpl attr = (AttrImpl)
286N/A ((CoreDocumentImpl) fElement.getOwnerDocument()).createAttributeNS(
286N/A qname.uri,
286N/A qname.rawname,
286N/A qname.localpart);
286N/A // REVISIT: the following should also update ID table
286N/A attr.setNodeValue(attrValue);
286N/A index = fElement.setXercesAttributeNode(attr);
286N/A fAugmentations.insertElementAt(new AugmentationsImpl(), index);
286N/A attr.setSpecified(false);
286N/A }
286N/A else {
286N/A // default attribute is in the tree
286N/A // we don't need to do anything since prefix was already fixed
286N/A // at the namespace fixup time and value must be same value, otherwise
286N/A // attribute will be treated as specified and we will never reach
286N/A // this method.
286N/A
286N/A }
286N/A return index;
286N/A }
286N/A
286N/A
286N/A public void removeAllAttributes(){
286N/A // REVISIT: implement
286N/A }
286N/A
286N/A
286N/A public void removeAttributeAt(int attrIndex){
286N/A // REVISIT: implement
286N/A }
286N/A
286N/A
286N/A public int getLength(){
286N/A return(fAttributes != null)?fAttributes.getLength():0;
286N/A }
286N/A
286N/A
286N/A public int getIndex(String qName){
286N/A // REVISIT: implement
286N/A return -1;
286N/A }
286N/A
286N/A public int getIndex(String uri, String localPart){
286N/A // REVISIT: implement
286N/A return -1;
286N/A }
286N/A
286N/A public void setName(int attrIndex, QName attrName){
286N/A // REVISIT: implement
286N/A }
286N/A
286N/A public void getName(int attrIndex, QName attrName){
286N/A if (fAttributes !=null) {
286N/A updateQName((Node)fAttributes.getItem(attrIndex), attrName);
286N/A }
286N/A }
286N/A
286N/A public String getPrefix(int index){
286N/A // REVISIT: implement
286N/A return null;
286N/A }
286N/A
286N/A
286N/A public String getURI(int index){
286N/A // REVISIT: implement
286N/A return null;
286N/A }
286N/A
286N/A
286N/A public String getLocalName(int index){
286N/A // REVISIT: implement
286N/A return null;
286N/A }
286N/A
286N/A
286N/A public String getQName(int index){
286N/A // REVISIT: implement
286N/A return null;
286N/A }
286N/A
286N/A public QName getQualifiedName(int index){
286N/A //return fAttributes.item(index).ge);
286N/A return null;
286N/A }
286N/A
286N/A public void setType(int attrIndex, String attrType){
286N/A // REVISIT: implement
286N/A }
286N/A
286N/A
286N/A public String getType(int index){
286N/A return "CDATA";
286N/A }
286N/A
286N/A
286N/A public String getType(String qName){
286N/A return "CDATA";
286N/A }
286N/A
286N/A
286N/A public String getType(String uri, String localName){
286N/A return "CDATA";
286N/A }
286N/A
286N/A
286N/A public void setValue(int attrIndex, String attrValue){
286N/A // REVISIT: is this desired behaviour?
286N/A // The values are updated in the case datatype-normalization is turned on
286N/A // in this case we need to make sure that specified attributes stay specified
286N/A
286N/A if (fAttributes != null){
286N/A AttrImpl attr = (AttrImpl)fAttributes.getItem(attrIndex);
286N/A boolean specified = attr.getSpecified();
286N/A attr.setValue(attrValue);
286N/A attr.setSpecified(specified);
286N/A
286N/A }
286N/A }
286N/A
286N/A public void setValue(int attrIndex, String attrValue, XMLString value){
286N/A setValue(attrIndex, value.toString());
286N/A }
286N/A
286N/A public String getValue(int index){
286N/A return (fAttributes !=null)?fAttributes.item(index).getNodeValue():"";
286N/A
286N/A }
286N/A
286N/A
286N/A public String getValue(String qName){
286N/A // REVISIT: implement
286N/A return null;
286N/A }
286N/A
286N/A
286N/A public String getValue(String uri, String localName){
286N/A if (fAttributes != null) {
286N/A Node node = fAttributes.getNamedItemNS(uri, localName);
286N/A return(node != null)? node.getNodeValue():null;
286N/A }
286N/A return null;
286N/A }
286N/A
286N/A
286N/A public void setNonNormalizedValue(int attrIndex, String attrValue){
286N/A // REVISIT: implement
286N/A
286N/A }
286N/A
286N/A
286N/A public String getNonNormalizedValue(int attrIndex){
286N/A // REVISIT: implement
286N/A return null;
286N/A }
286N/A
286N/A
286N/A public void setSpecified(int attrIndex, boolean specified){
286N/A AttrImpl attr = (AttrImpl)fAttributes.getItem(attrIndex);
286N/A attr.setSpecified(specified);
286N/A }
286N/A
286N/A public boolean isSpecified(int attrIndex){
286N/A return((Attr)fAttributes.getItem(attrIndex)).getSpecified();
286N/A }
286N/A
286N/A public Augmentations getAugmentations (int attributeIndex){
286N/A return(Augmentations)fAugmentations.elementAt(attributeIndex);
286N/A }
286N/A
286N/A public Augmentations getAugmentations (String uri, String localPart){
286N/A // REVISIT: implement
286N/A return null;
286N/A }
286N/A
286N/A public Augmentations getAugmentations(String qName){
286N/A // REVISIT: implement
286N/A return null;
286N/A }
286N/A
286N/A /**
286N/A * Sets the augmentations of the attribute at the specified index.
286N/A *
286N/A * @param attrIndex The attribute index.
286N/A * @param augs The augmentations.
286N/A */
286N/A public void setAugmentations(int attrIndex, Augmentations augs) {
286N/A fAugmentations.setElementAt(augs, attrIndex);
286N/A }
286N/A }
286N/A
286N/A //
286N/A // XMLDocumentHandler methods
286N/A //
286N/A
286N/A /**
286N/A * The start of the document.
286N/A *
286N/A * @param locator The document locator, or null if the document
286N/A * location cannot be reported during the parsing
286N/A * of this document. However, it is <em>strongly</em>
286N/A * recommended that a locator be supplied that can
286N/A * at least report the system identifier of the
286N/A * document.
286N/A * @param encoding The auto-detected IANA encoding name of the entity
286N/A * stream. This value will be null in those situations
286N/A * where the entity encoding is not auto-detected (e.g.
286N/A * internal entities or a document entity that is
286N/A * parsed from a java.io.Reader).
286N/A * @param namespaceContext
286N/A * The namespace context in effect at the
286N/A * start of this document.
286N/A * This object represents the current context.
286N/A * Implementors of this class are responsible
286N/A * for copying the namespace bindings from the
286N/A * the current context (and its parent contexts)
286N/A * if that information is important.
286N/A *
286N/A * @param augs Additional information that may include infoset augmentations
286N/A * @exception XNIException
286N/A * Thrown by handler to signal an error.
286N/A */
286N/A public void startDocument(XMLLocator locator, String encoding,
286N/A NamespaceContext namespaceContext,
286N/A Augmentations augs)
286N/A throws XNIException{
286N/A }
286N/A
286N/A /**
286N/A * Notifies of the presence of an XMLDecl line in the document. If
286N/A * present, this method will be called immediately following the
286N/A * startDocument call.
286N/A *
286N/A * @param version The XML version.
286N/A * @param encoding The IANA encoding name of the document, or null if
286N/A * not specified.
286N/A * @param standalone The standalone value, or null if not specified.
286N/A * @param augs Additional information that may include infoset augmentations
286N/A *
286N/A * @exception XNIException
286N/A * Thrown by handler to signal an error.
286N/A */
286N/A public void xmlDecl(String version, String encoding, String standalone, Augmentations augs)
286N/A throws XNIException{
286N/A }
286N/A
286N/A /**
286N/A * Notifies of the presence of the DOCTYPE line in the document.
286N/A *
286N/A * @param rootElement
286N/A * The name of the root element.
286N/A * @param publicId The public identifier if an external DTD or null
286N/A * if the external DTD is specified using SYSTEM.
286N/A * @param systemId The system identifier if an external DTD, null
286N/A * otherwise.
286N/A * @param augs Additional information that may include infoset augmentations
286N/A *
286N/A * @exception XNIException
286N/A * Thrown by handler to signal an error.
286N/A */
286N/A public void doctypeDecl(String rootElement, String publicId, String systemId, Augmentations augs)
286N/A throws XNIException{
286N/A }
286N/A
286N/A /**
286N/A * A comment.
286N/A *
286N/A * @param text The text in the comment.
286N/A * @param augs Additional information that may include infoset augmentations
286N/A *
286N/A * @exception XNIException
286N/A * Thrown by application to signal an error.
286N/A */
286N/A public void comment(XMLString text, Augmentations augs) throws XNIException{
286N/A }
286N/A
286N/A /**
286N/A * A processing instruction. Processing instructions consist of a
286N/A * target name and, optionally, text data. The data is only meaningful
286N/A * to the application.
286N/A * <p>
286N/A * Typically, a processing instruction's data will contain a series
286N/A * of pseudo-attributes. These pseudo-attributes follow the form of
286N/A * element attributes but are <strong>not</strong> parsed or presented
286N/A * to the application as anything other than text. The application is
286N/A * responsible for parsing the data.
286N/A *
286N/A * @param target The target.
286N/A * @param data The data or null if none specified.
286N/A * @param augs Additional information that may include infoset augmentations
286N/A *
286N/A * @exception XNIException
286N/A * Thrown by handler to signal an error.
286N/A */
286N/A public void processingInstruction(String target, XMLString data, Augmentations augs)
286N/A throws XNIException{
286N/A }
286N/A
286N/A /**
286N/A * The start of an element.
286N/A *
286N/A * @param element The name of the element.
286N/A * @param attributes The element attributes.
286N/A * @param augs Additional information that may include infoset augmentations
286N/A *
286N/A * @exception XNIException
286N/A * Thrown by handler to signal an error.
286N/A */
286N/A public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
286N/A throws XNIException {
286N/A Element currentElement = (Element) fCurrentNode;
286N/A int attrCount = attributes.getLength();
286N/A if (DEBUG_EVENTS) {
286N/A System.out.println("==>startElement: " +element+
286N/A " attrs.length="+attrCount);
286N/A }
286N/A
286N/A for (int i = 0; i < attrCount; i++) {
286N/A attributes.getName(i, fAttrQName);
286N/A Attr attr = null;
286N/A
286N/A attr = currentElement.getAttributeNodeNS(fAttrQName.uri, fAttrQName.localpart);
286N/A AttributePSVI attrPSVI =
286N/A (AttributePSVI) attributes.getAugmentations(i).getItem(Constants.ATTRIBUTE_PSVI);
286N/A
286N/A if (attrPSVI != null) {
286N/A //REVISIT: instead we should be using augmentations:
286N/A // to set/retrieve Id attributes
286N/A XSTypeDefinition decl = attrPSVI.getMemberTypeDefinition();
286N/A boolean id = false;
286N/A if (decl != null){
286N/A id = ((XSSimpleType)decl).isIDType();
286N/A } else{
286N/A decl = attrPSVI.getTypeDefinition();
286N/A if (decl !=null){
286N/A id = ((XSSimpleType)decl).isIDType();
286N/A }
286N/A }
286N/A if (id){
286N/A ((ElementImpl)currentElement).setIdAttributeNode(attr, true);
286N/A }
286N/A
286N/A if (fPSVI) {
286N/A ((PSVIAttrNSImpl) attr).setPSVI(attrPSVI);
286N/A }
286N/A if ((fConfiguration.features & DOMConfigurationImpl.DTNORMALIZATION) != 0) {
286N/A // datatype-normalization
286N/A // NOTE: The specified value MUST be set after we set
286N/A // the node value because that turns the "specified"
286N/A // flag to "true" which may overwrite a "false"
286N/A // value from the attribute list.
286N/A boolean specified = attr.getSpecified();
286N/A attr.setValue(attrPSVI.getSchemaNormalizedValue());
286N/A if (!specified) {
286N/A ((AttrImpl) attr).setSpecified(specified);
286N/A }
286N/A }
286N/A }
286N/A }
286N/A }
286N/A
286N/A
286N/A /**
286N/A * An empty element.
286N/A *
286N/A * @param element The name of the element.
286N/A * @param attributes The element attributes.
286N/A * @param augs Additional information that may include infoset augmentations
286N/A *
286N/A * @exception XNIException
286N/A * Thrown by handler to signal an error.
286N/A */
286N/A public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs)
286N/A throws XNIException {
286N/A if (DEBUG_EVENTS) {
286N/A System.out.println("==>emptyElement: " +element);
286N/A }
286N/A
286N/A startElement(element, attributes, augs);
286N/A endElement(element, augs);
286N/A }
286N/A
286N/A /**
286N/A * This method notifies the start of a general entity.
286N/A * <p>
286N/A * <strong>Note:</strong> This method is not called for entity references
286N/A * appearing as part of attribute values.
286N/A *
286N/A * @param name The name of the general entity.
286N/A * @param identifier The resource identifier.
286N/A * @param encoding The auto-detected IANA encoding name of the entity
286N/A * stream. This value will be null in those situations
286N/A * where the entity encoding is not auto-detected (e.g.
286N/A * internal entities or a document entity that is
286N/A * parsed from a java.io.Reader).
286N/A * @param augs Additional information that may include infoset augmentations
286N/A *
286N/A * @exception XNIException Thrown by handler to signal an error.
286N/A */
286N/A public void startGeneralEntity(String name,
286N/A XMLResourceIdentifier identifier,
286N/A String encoding,
286N/A Augmentations augs) throws XNIException{
286N/A }
286N/A
286N/A /**
286N/A * Notifies of the presence of a TextDecl line in an entity. If present,
286N/A * this method will be called immediately following the startEntity call.
286N/A * <p>
286N/A * <strong>Note:</strong> This method will never be called for the
286N/A * document entity; it is only called for external general entities
286N/A * referenced in document content.
286N/A * <p>
286N/A * <strong>Note:</strong> This method is not called for entity references
286N/A * appearing as part of attribute values.
286N/A *
286N/A * @param version The XML version, or null if not specified.
286N/A * @param encoding The IANA encoding name of the entity.
286N/A * @param augs Additional information that may include infoset augmentations
286N/A *
286N/A * @exception XNIException
286N/A * Thrown by handler to signal an error.
286N/A */
286N/A public void textDecl(String version, String encoding, Augmentations augs) throws XNIException{
286N/A }
286N/A
286N/A /**
286N/A * This method notifies the end of a general entity.
286N/A * <p>
286N/A * <strong>Note:</strong> This method is not called for entity references
286N/A * appearing as part of attribute values.
286N/A *
286N/A * @param name The name of the entity.
286N/A * @param augs Additional information that may include infoset augmentations
286N/A *
286N/A * @exception XNIException
286N/A * Thrown by handler to signal an error.
286N/A */
286N/A public void endGeneralEntity(String name, Augmentations augs) throws XNIException{
286N/A }
286N/A
286N/A /**
286N/A * Character content.
286N/A *
286N/A * @param text The content.
286N/A * @param augs Additional information that may include infoset augmentations
286N/A *
286N/A * @exception XNIException
286N/A * Thrown by handler to signal an error.
286N/A */
286N/A public void characters(XMLString text, Augmentations augs) throws XNIException{
286N/A }
286N/A
286N/A /**
286N/A * Ignorable whitespace. For this method to be called, the document
286N/A * source must have some way of determining that the text containing
286N/A * only whitespace characters should be considered ignorable. For
286N/A * example, the validator can determine if a length of whitespace
286N/A * characters in the document are ignorable based on the element
286N/A * content model.
286N/A *
286N/A * @param text The ignorable whitespace.
286N/A * @param augs Additional information that may include infoset augmentations
286N/A *
286N/A * @exception XNIException
286N/A * Thrown by handler to signal an error.
286N/A */
286N/A public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException{
286N/A allWhitespace = true;
286N/A }
286N/A
286N/A /**
286N/A * The end of an element.
286N/A *
286N/A * @param element The name of the element.
286N/A * @param augs Additional information that may include infoset augmentations
286N/A *
286N/A * @exception XNIException
286N/A * Thrown by handler to signal an error.
286N/A */
286N/A public void endElement(QName element, Augmentations augs) throws XNIException {
286N/A if (DEBUG_EVENTS) {
286N/A System.out.println("==>endElement: " + element);
286N/A }
286N/A
286N/A if(augs != null) {
286N/A ElementPSVI elementPSVI = (ElementPSVI) augs.getItem(Constants.ELEMENT_PSVI);
286N/A if (elementPSVI != null) {
286N/A ElementImpl elementNode = (ElementImpl) fCurrentNode;
286N/A if (fPSVI) {
286N/A ((PSVIElementNSImpl) fCurrentNode).setPSVI(elementPSVI);
286N/A }
286N/A // include element default content (if one is available)
286N/A String normalizedValue = elementPSVI.getSchemaNormalizedValue();
286N/A if ((fConfiguration.features & DOMConfigurationImpl.DTNORMALIZATION) != 0) {
286N/A if (normalizedValue !=null)
286N/A elementNode.setTextContent(normalizedValue);
286N/A }
286N/A else {
286N/A // NOTE: this is a hack: it is possible that DOM had an empty element
286N/A // and validator sent default value using characters(), which we don't
286N/A // implement. Thus, here we attempt to add the default value.
286N/A String text = elementNode.getTextContent();
286N/A if (text.length() == 0) {
286N/A // default content could be provided
286N/A if (normalizedValue !=null)
286N/A elementNode.setTextContent(normalizedValue);
286N/A }
286N/A }
286N/A }
286N/A }
286N/A }
286N/A
286N/A
286N/A /**
286N/A * The start of a CDATA section.
286N/A *
286N/A * @param augs Additional information that may include infoset augmentations
286N/A *
286N/A * @exception XNIException
286N/A * Thrown by handler to signal an error.
286N/A */
286N/A public void startCDATA(Augmentations augs) throws XNIException{
286N/A }
286N/A
286N/A /**
286N/A * The end of a CDATA section.
286N/A *
286N/A * @param augs Additional information that may include infoset augmentations
286N/A *
286N/A * @exception XNIException
286N/A * Thrown by handler to signal an error.
286N/A */
286N/A public void endCDATA(Augmentations augs) throws XNIException{
286N/A }
286N/A
286N/A /**
286N/A * The end of the document.
286N/A *
286N/A * @param augs Additional information that may include infoset augmentations
286N/A *
286N/A * @exception XNIException
286N/A * Thrown by handler to signal an error.
286N/A */
286N/A public void endDocument(Augmentations augs) throws XNIException{
286N/A }
286N/A
286N/A
286N/A /** Sets the document source. */
286N/A public void setDocumentSource(XMLDocumentSource source){
286N/A }
286N/A
286N/A
286N/A /** Returns the document source. */
286N/A public XMLDocumentSource getDocumentSource(){
286N/A return null;
286N/A }
286N/A
286N/A
286N/A} // DOMNormalizer class