/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999,2000,2001 The Apache Software Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package xni;
import org.apache.xerces.impl.Constants;
import org.apache.xerces.impl.XMLNamespaceBinder;
import org.apache.xerces.util.SymbolTable;
import org.apache.xerces.util.DefaultErrorHandler;
import org.apache.xerces.util.MessageFormatter;
import org.apache.xerces.util.XMLAttributesImpl;
//for testing
import org.apache.xerces.impl.xs.XSTypeDecl;
import org.apache.xerces.impl.xs.ElementPSVImpl;
import org.apache.xerces.impl.xs.AttributePSVImpl;
import org.apache.xml.serialize.IndentPrinter;
import org.apache.xml.serialize.EncodingInfo;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.Printer;
import org.apache.xml.serialize.LineSeparator;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLString;
import org.apache.xerces.xni.XMLLocator;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.NamespaceContext;
import org.apache.xerces.xni.XMLAttributes;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.XMLDocumentHandler;
import org.apache.xerces.xni.psvi.ItemPSVI;
import org.apache.xerces.xni.psvi.ElementPSVI;
import org.apache.xerces.xni.psvi.AttributePSVI;
import org.apache.xerces.xni.parser.XMLComponent;
import org.apache.xerces.xni.parser.XMLComponentManager;
import org.apache.xerces.xni.parser.XMLDocumentFilter;
import org.apache.xerces.xni.parser.XMLConfigurationException;
import org.apache.xerces.xni.parser.XMLErrorHandler;
import org.apache.xerces.xni.parser.XMLInputSource;
import org.apache.xerces.xni.parser.XMLParseException;
import java.io.*;
import java.util.*;
/**
* This class is a intersepts XNI events and serialized
* XML infoset and Post Schema Validation Infoset.
*
* @author Arun Yadav,Sun Miscrosystem.
* @version $Id: PSVIWriter.java,v 1.3 2001/12/17 17:50:21 elena Exp $
*/
public class PSVIWriter
implements XMLComponent, XMLDocumentFilter {
public static final String XERCES_PSVI_NS = "http://apache.org/xml/2001/PSVInfosetExtension";
/** Property identifier: Namespace Binder */
protected static final String NAMESPACE_BINDER =
Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;
/** Property identifier: symbol table. */
protected static final String SYMBOL_TABLE =
Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
/** Feature id: include ignorable whitespace. */
protected static final String INCLUDE_IGNORABLE_WHITESPACE =
"http://apache.org/xml/features/dom/include-ignorable-whitespace";
protected static final String PSVI_OUTPUT ="psvi_output.xml";
/** Include ignorable whitespace. */
protected boolean fIncludeIgnorableWhitespace;
/** Recognized features. */
protected static final String[] RECOGNIZED_FEATURES = {
NAMESPACE_BINDER,
INCLUDE_IGNORABLE_WHITESPACE,
// PSVINFOSET,
};
/** Recognized properties. */
protected static final String[] RECOGNIZED_PROPERTIES={
SYMBOL_TABLE,
};
/** PSVInfoset */
protected boolean fPSVInfoset;
/** Symbol: "". */
private String fEmptySymbol;
/** Symbol: "xml". */
private String fXmlSymbol;
/** Symbol: "xmlns". */
private String fXmlnsSymbol;
/** XMLNS namespace: XML-Infoset */
public static final String XMLNS_URI ="http://www.w3.org/2000/xmlns/";
/** Document handler. */
protected XMLDocumentHandler fDocumentHandler;
/** Symbol table. */
protected SymbolTable fSymbolTable;
/** NamespaceBinder*/
protected XMLNamespaceBinder fNamespaceBinder;
/** Attribute QName. */
private QName fAttrQName = new QName();
/** Attributes and Element Info is cached in stack */
private Stack _elementState =new Stack();
/** The output stream. */
private OutputStream _output;
/** The underlying writer. */
private java.io.Writer _writer;
private EncodingInfo _encodingInfo;
private final StringBuffer fErrorBuffer = new StringBuffer();
/** The printer used for printing text parts. */
protected Printer _printer;
public PSVIWriter() {
System.out.println("Generating Schema Information Set Contribution (PSVI) \n"
+ "which follow as a consequence of validation and/or assessment.");
System.out.println("NOTE: Requires use of -s and -v");
System.out.println("Output: generated in "+PSVI_OUTPUT);
} // <init>()
//REVISIT
// 1. where to output the PSVI info to user( output console or file)?
// 2. Is there any other better way to format the output.
public void reset(XMLComponentManager componentManager)
throws XNIException {
// Feature's name for PSVIWriter is not yet decided.
/* try {
fPSVInfoset = componentManager.getFeature(PSVINFOSET);
}
catch (XMLConfigurationException e) {
fPSVInfoset = false;
}*/
/**For Testing */
fPSVInfoset = true;
fNamespaceBinder = (XMLNamespaceBinder)componentManager.getProperty(NAME