feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,86 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.tools;
import com.sun.xml.internal.fastinfoset.Decoder;
import com.sun.xml.internal.fastinfoset.dom.DOMDocumentParser;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import org.w3c.dom.Document;
public class FI_DOM_Or_XML_DOM_SAX_SAXEvent extends TransformInputOutput {
public void parse(InputStream document, OutputStream events, String workingDirectory) throws Exception {
if (!document.markSupported()) {
document = new BufferedInputStream(document);
}
document.mark(4);
boolean isFastInfosetDocument = Decoder.isFastInfosetDocument(document);
document.reset();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document d;
if (isFastInfosetDocument) {
d = db.newDocument();
DOMDocumentParser ddp = new DOMDocumentParser();
ddp.parse(d, document);
} else {
if (workingDirectory != null) {
db.setEntityResolver(createRelativePathResolver(workingDirectory));
}
d = db.parse(document);
}
SAXEventSerializer ses = new SAXEventSerializer(events);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
t.transform(new DOMSource(d), new SAXResult(ses));
}
public void parse(InputStream document, OutputStream events) throws Exception {
parse(document, events, null);
}
public static void main(String[] args) throws Exception {
FI_DOM_Or_XML_DOM_SAX_SAXEvent p = new FI_DOM_Or_XML_DOM_SAX_SAXEvent();
p.parse(args);
}
}

View File

@@ -0,0 +1,101 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.tools;
import com.sun.xml.internal.fastinfoset.Decoder;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.sax.SAXSource;
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetSource;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
public class FI_SAX_Or_XML_SAX_DOM_SAX_SAXEvent extends TransformInputOutput {
public FI_SAX_Or_XML_SAX_DOM_SAX_SAXEvent() {
}
public void parse(InputStream document, OutputStream events, String workingDirectory) throws Exception {
if (!document.markSupported()) {
document = new BufferedInputStream(document);
}
document.mark(4);
boolean isFastInfosetDocument = Decoder.isFastInfosetDocument(document);
document.reset();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
DOMResult dr = new DOMResult();
if (isFastInfosetDocument) {
t.transform(new FastInfosetSource(document), dr);
} else if (workingDirectory != null) {
SAXParser parser = getParser();
XMLReader reader = parser.getXMLReader();
reader.setEntityResolver(createRelativePathResolver(workingDirectory));
SAXSource source = new SAXSource(reader, new InputSource(document));
t.transform(source, dr);
} else {
t.transform(new StreamSource(document), dr);
}
SAXEventSerializer ses = new SAXEventSerializer(events);
t.transform(new DOMSource(dr.getNode()), new SAXResult(ses));
}
public void parse(InputStream document, OutputStream events) throws Exception {
parse(document, events, null);
}
private SAXParser getParser() {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
try {
return saxParserFactory.newSAXParser();
} catch (Exception e) {
return null;
}
}
public static void main(String[] args) throws Exception {
FI_SAX_Or_XML_SAX_DOM_SAX_SAXEvent p = new FI_SAX_Or_XML_SAX_DOM_SAX_SAXEvent();
p.parse(args);
}
}

View File

@@ -0,0 +1,85 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.tools;
import com.sun.xml.internal.fastinfoset.Decoder;
import com.sun.xml.internal.fastinfoset.sax.SAXDocumentParser;
import com.sun.xml.internal.fastinfoset.sax.Properties;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
public class FI_SAX_Or_XML_SAX_SAXEvent extends TransformInputOutput {
public FI_SAX_Or_XML_SAX_SAXEvent() {
}
public void parse(InputStream document, OutputStream events, String workingDirectory) throws Exception {
if (!document.markSupported()) {
document = new BufferedInputStream(document);
}
document.mark(4);
boolean isFastInfosetDocument = Decoder.isFastInfosetDocument(document);
document.reset();
if (isFastInfosetDocument) {
SAXDocumentParser parser = new SAXDocumentParser();
SAXEventSerializer ses = new SAXEventSerializer(events);
parser.setContentHandler(ses);
parser.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, ses);
parser.parse(document);
} else {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
SAXParser parser = parserFactory.newSAXParser();
SAXEventSerializer ses = new SAXEventSerializer(events);
XMLReader reader = parser.getXMLReader();
reader.setProperty("http://xml.org/sax/properties/lexical-handler", ses);
reader.setContentHandler(ses);
if (workingDirectory != null) {
reader.setEntityResolver(createRelativePathResolver(workingDirectory));
}
reader.parse(new InputSource(document));
}
}
public void parse(InputStream document, OutputStream events) throws Exception {
parse(document, events, null);
}
public static void main(String[] args) throws Exception {
FI_SAX_Or_XML_SAX_SAXEvent p = new FI_SAX_Or_XML_SAX_SAXEvent();
p.parse(args);
}
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.tools;
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetSource;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
public class FI_SAX_XML extends TransformInputOutput {
public FI_SAX_XML() {
}
public void parse(InputStream finf, OutputStream xml) throws Exception {
Transformer tx = TransformerFactory.newInstance().newTransformer();
tx.transform(new FastInfosetSource(finf), new StreamResult(xml));
}
public static void main(String[] args) throws Exception {
FI_SAX_XML p = new FI_SAX_XML();
p.parse(args);
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.tools;
import com.sun.xml.internal.fastinfoset.Decoder;
import com.sun.xml.internal.fastinfoset.sax.Properties;
import com.sun.xml.internal.fastinfoset.stax.StAXDocumentParser;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import com.sun.xml.internal.fastinfoset.tools.StAX2SAXReader;
public class FI_StAX_SAX_Or_XML_SAX_SAXEvent extends TransformInputOutput {
public FI_StAX_SAX_Or_XML_SAX_SAXEvent() {
}
public void parse(InputStream document, OutputStream events) throws Exception {
if (!document.markSupported()) {
document = new BufferedInputStream(document);
}
document.mark(4);
boolean isFastInfosetDocument = Decoder.isFastInfosetDocument(document);
document.reset();
if (isFastInfosetDocument) {
StAXDocumentParser parser = new StAXDocumentParser();
parser.setInputStream(document);
SAXEventSerializer ses = new SAXEventSerializer(events);
StAX2SAXReader reader = new StAX2SAXReader(parser, ses);
reader.setLexicalHandler(ses);
reader.adapt();
} else {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
SAXParser parser = parserFactory.newSAXParser();
SAXEventSerializer ses = new SAXEventSerializer(events);
parser.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, ses);
parser.parse(document, ses);
}
}
public static void main(String[] args) throws Exception {
FI_StAX_SAX_Or_XML_SAX_SAXEvent p = new FI_StAX_SAX_Or_XML_SAX_SAXEvent();
p.parse(args);
}
}

View File

@@ -0,0 +1,127 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.tools;
import com.sun.xml.internal.fastinfoset.QualifiedName;
import java.io.File;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import com.sun.xml.internal.fastinfoset.util.CharArrayArray;
import com.sun.xml.internal.fastinfoset.util.ContiguousCharArrayArray;
import com.sun.xml.internal.fastinfoset.util.PrefixArray;
import com.sun.xml.internal.fastinfoset.util.QualifiedNameArray;
import com.sun.xml.internal.fastinfoset.util.StringArray;
import com.sun.xml.internal.fastinfoset.vocab.ParserVocabulary;
public class PrintTable {
/** Creates a new instance of PrintTable */
public PrintTable() {
}
public static void printVocabulary(ParserVocabulary vocabulary) {
printArray("Attribute Name Table", vocabulary.attributeName);
printArray("Attribute Value Table", vocabulary.attributeValue);
printArray("Character Content Chunk Table", vocabulary.characterContentChunk);
printArray("Element Name Table", vocabulary.elementName);
printArray("Local Name Table", vocabulary.localName);
printArray("Namespace Name Table", vocabulary.namespaceName);
printArray("Other NCName Table", vocabulary.otherNCName);
printArray("Other String Table", vocabulary.otherString);
printArray("Other URI Table", vocabulary.otherURI);
printArray("Prefix Table", vocabulary.prefix);
}
public static void printArray(String title, StringArray a) {
System.out.println(title);
for (int i = 0; i < a.getSize(); i++) {
System.out.println("" + (i + 1) + ": " + a.getArray()[i]);
}
}
public static void printArray(String title, PrefixArray a) {
System.out.println(title);
for (int i = 0; i < a.getSize(); i++) {
System.out.println("" + (i + 1) + ": " + a.getArray()[i]);
}
}
public static void printArray(String title, CharArrayArray a) {
System.out.println(title);
for (int i = 0; i < a.getSize(); i++) {
System.out.println("" + (i + 1) + ": " + a.getArray()[i]);
}
}
public static void printArray(String title, ContiguousCharArrayArray a) {
System.out.println(title);
for (int i = 0; i < a.getSize(); i++) {
System.out.println("" + (i + 1) + ": " + a.getString(i));
}
}
public static void printArray(String title, QualifiedNameArray a) {
System.out.println(title);
for (int i = 0; i < a.getSize(); i++) {
QualifiedName name = a.getArray()[i];
System.out.println("" + (name.index + 1) + ": " +
"{" + name.namespaceName + "}" +
name.prefix + ":" + name.localName);
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
SAXParser saxParser = saxParserFactory.newSAXParser();
ParserVocabulary referencedVocabulary = new ParserVocabulary();
VocabularyGenerator vocabularyGenerator = new VocabularyGenerator(referencedVocabulary);
File f = new File(args[0]);
saxParser.parse(f, vocabularyGenerator);
printVocabulary(referencedVocabulary);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,201 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.tools;
import com.sun.xml.internal.fastinfoset.QualifiedName;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.DefaultHandler;
public class SAX2StAXWriter extends DefaultHandler implements LexicalHandler {
private static final Logger logger = Logger.getLogger(SAX2StAXWriter.class.getName());
/**
* XML stream writer where events are pushed.
*/
XMLStreamWriter _writer;
/**
* List of namespace decl for upcoming element.
*/
ArrayList _namespaces = new ArrayList();
public SAX2StAXWriter(XMLStreamWriter writer) {
_writer = writer;
}
public XMLStreamWriter getWriter() {
return _writer;
}
public void startDocument() throws SAXException {
try {
_writer.writeStartDocument();
}
catch (XMLStreamException e) {
throw new SAXException(e);
}
}
public void endDocument() throws SAXException {
try {
_writer.writeEndDocument();
_writer.flush();
}
catch (XMLStreamException e) {
throw new SAXException(e);
}
}
public void characters(char[] ch, int start, int length)
throws SAXException
{
try {
_writer.writeCharacters(ch, start, length);
}
catch (XMLStreamException e) {
throw new SAXException(e);
}
}
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) throws SAXException
{
try {
int k = qName.indexOf(':');
String prefix = (k > 0) ? qName.substring(0, k) : "";
_writer.writeStartElement(prefix, localName, namespaceURI);
int length = _namespaces.size();
for (int i = 0; i < length; i++) {
QualifiedName nsh = (QualifiedName) _namespaces.get(i);
_writer.writeNamespace(nsh.prefix, nsh.namespaceName);
}
_namespaces.clear();
length = atts.getLength();
for (int i = 0; i < length; i++) {
_writer.writeAttribute(atts.getURI(i),
atts.getLocalName(i),
atts.getValue(i));
}
}
catch (XMLStreamException e) {
throw new SAXException(e);
}
}
public void endElement(String namespaceURI, String localName,
String qName) throws SAXException
{
try {
_writer.writeEndElement();
}
catch (XMLStreamException e) {
logger.log(Level.FINE, "Exception on endElement", e);
throw new SAXException(e);
}
}
public void startPrefixMapping(String prefix, String uri)
throws SAXException
{
// Commented as in StAX NS are declared for current element?
// now _writer.setPrefix() is invoked in _writer.writeNamespace()
// try {
// _writer.setPrefix(prefix, uri);
_namespaces.add(new QualifiedName(prefix, uri));
// }
// catch (XMLStreamException e) {
// throw new SAXException(e);
// }
}
public void endPrefixMapping(String prefix) throws SAXException {
}
public void ignorableWhitespace(char[] ch, int start, int length)
throws SAXException
{
characters(ch, start, length);
}
public void processingInstruction(String target, String data)
throws SAXException
{
try {
_writer.writeProcessingInstruction(target, data);
}
catch (XMLStreamException e) {
throw new SAXException(e);
}
}
public void setDocumentLocator(Locator locator) {
}
public void skippedEntity(String name) throws SAXException {
}
public void comment(char[] ch, int start, int length)
throws SAXException
{
try {
_writer.writeComment(new String(ch, start, length));
}
catch (XMLStreamException e) {
throw new SAXException(e);
}
}
public void endCDATA() throws SAXException {
}
public void endDTD() throws SAXException {
}
public void endEntity(String name) throws SAXException {
}
public void startCDATA() throws SAXException {
}
public void startDTD(String name, String publicId, String systemId) throws SAXException {
}
public void startEntity(String name) throws SAXException {
}
}

View File

@@ -0,0 +1,423 @@
/*
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.tools;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.DefaultHandler;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class SAXEventSerializer extends DefaultHandler
implements LexicalHandler {
private Writer _writer;
private boolean _charactersAreCDATA;
private StringBuffer _characters;
private Stack _namespaceStack = new Stack();
protected List _namespaceAttributes;
public SAXEventSerializer(OutputStream s) throws IOException {
_writer = new OutputStreamWriter(s);
_charactersAreCDATA = false;
}
// -- ContentHandler interface ---------------------------------------
public void startDocument() throws SAXException {
try {
_writer.write("<sax xmlns=\"http://www.sun.com/xml/sax-events\">\n");
_writer.write("<startDocument/>\n");
_writer.flush();
}
catch (IOException e) {
throw new SAXException(e);
}
}
public void endDocument() throws SAXException {
try {
_writer.write("<endDocument/>\n");
_writer.write("</sax>");
_writer.flush();
_writer.close();
}
catch (IOException e) {
throw new SAXException(e);
}
}
public void startPrefixMapping(String prefix, String uri)
throws SAXException
{
if (_namespaceAttributes == null) {
_namespaceAttributes = new ArrayList();
}
String qName = (prefix.length() == 0) ? "xmlns" : "xmlns" + prefix;
AttributeValueHolder attribute = new AttributeValueHolder(
qName,
prefix,
uri,
null,
null);
_namespaceAttributes.add(attribute);
}
public void endPrefixMapping(String prefix)
throws SAXException
{
/*
try {
outputCharacters();
_writer.write("<endPrefixMapping prefix=\"" +
prefix + "\"/>\n");
_writer.flush();
}
catch (IOException e) {
throw new SAXException(e);
}
*/
}
public void startElement(String uri, String localName,
String qName, Attributes attributes)
throws SAXException
{
try {
outputCharacters();
if (_namespaceAttributes != null) {
AttributeValueHolder[] attrsHolder = new AttributeValueHolder[0];
attrsHolder = (AttributeValueHolder[])_namespaceAttributes.toArray(attrsHolder);
// Sort attributes
quicksort(attrsHolder, 0, attrsHolder.length - 1);
for (int i = 0; i < attrsHolder.length; i++) {
_writer.write("<startPrefixMapping prefix=\"" +
attrsHolder[i].localName + "\" uri=\"" + attrsHolder[i].uri + "\"/>\n");
_writer.flush();
}
_namespaceStack.push(attrsHolder);
_namespaceAttributes = null;
} else {
_namespaceStack.push(null);
}
AttributeValueHolder[] attrsHolder =
new AttributeValueHolder[attributes.getLength()];
for (int i = 0; i < attributes.getLength(); i++) {
attrsHolder[i] = new AttributeValueHolder(
attributes.getQName(i),
attributes.getLocalName(i),
attributes.getURI(i),
attributes.getType(i),
attributes.getValue(i));
}
// Sort attributes
quicksort(attrsHolder, 0, attrsHolder.length - 1);
int attributeCount = 0;
for (int i = 0; i < attrsHolder.length; i++) {
if (attrsHolder[i].uri.equals("http://www.w3.org/2000/xmlns/")) {
// Ignore XMLNS attributes
continue;
}
attributeCount++;
}
if (attributeCount == 0) {
_writer.write("<startElement uri=\"" + uri
+ "\" localName=\"" + localName + "\" qName=\""
+ qName + "\"/>\n");
return;
}
_writer.write("<startElement uri=\"" + uri
+ "\" localName=\"" + localName + "\" qName=\""
+ qName + "\">\n");
// Serialize attributes as children
for (int i = 0; i < attrsHolder.length; i++) {
if (attrsHolder[i].uri.equals("http://www.w3.org/2000/xmlns/")) {
// Ignore XMLNS attributes
continue;
}
_writer.write(
" <attribute qName=\"" + attrsHolder[i].qName +
"\" localName=\"" + attrsHolder[i].localName +
"\" uri=\"" + attrsHolder[i].uri +
// "\" type=\"" + attrsHolder[i].type +
"\" value=\"" + attrsHolder[i].value +
"\"/>\n");
}
_writer.write("</startElement>\n");
_writer.flush();
}
catch (IOException e) {
throw new SAXException(e);
}
}
public void endElement(String uri, String localName, String qName)
throws SAXException
{
try {
outputCharacters();
_writer.write("<endElement uri=\"" + uri
+ "\" localName=\"" + localName + "\" qName=\""
+ qName + "\"/>\n");
_writer.flush();
// Write out the end prefix here rather than waiting
// for the explicit events
AttributeValueHolder[] attrsHolder = (AttributeValueHolder[])_namespaceStack.pop();
if (attrsHolder != null) {
for (int i = 0; i < attrsHolder.length; i++) {
_writer.write("<endPrefixMapping prefix=\"" +
attrsHolder[i].localName + "\"/>\n");
_writer.flush();
}
}
}
catch (IOException e) {
throw new SAXException(e);
}
}
public void characters(char[] ch, int start, int length)
throws SAXException
{
if (length == 0) {
return;
}
if (_characters == null) {
_characters = new StringBuffer();
}
// Coalesce multiple character events
_characters.append(ch, start, length);
/*
try {
_writer.write("<characters>" +
(_charactersAreCDATA ? "<![CDATA[" : "") +
new String(ch, start, length) +
(_charactersAreCDATA ? "]]>" : "") +
"</characters>\n");
_writer.flush();
}
catch (IOException e) {
throw new SAXException(e);
}
*/
}
private void outputCharacters() throws SAXException {
if (_characters == null) {
return;
}
try {
_writer.write("<characters>" +
(_charactersAreCDATA ? "<![CDATA[" : "") +
_characters +
(_charactersAreCDATA ? "]]>" : "") +
"</characters>\n");
_writer.flush();
_characters = null;
} catch (IOException e) {
throw new SAXException(e);
}
}
public void ignorableWhitespace(char[] ch, int start, int length)
throws SAXException
{
// Report ignorable ws as characters (assumes validation off)
characters(ch, start, length);
}
public void processingInstruction(String target, String data)
throws SAXException
{
try {
outputCharacters();
_writer.write("<processingInstruction target=\"" + target
+ "\" data=\"" + data + "\"/>\n");
_writer.flush();
}
catch (IOException e) {
throw new SAXException(e);
}
}
// -- LexicalHandler interface ---------------------------------------
public void startDTD(String name, String publicId, String systemId)
throws SAXException {
// Not implemented
}
public void endDTD()
throws SAXException {
// Not implemented
}
public void startEntity(String name)
throws SAXException {
// Not implemented
}
public void endEntity(String name)
throws SAXException {
// Not implemented
}
public void startCDATA()
throws SAXException {
_charactersAreCDATA = true;
}
public void endCDATA()
throws SAXException {
_charactersAreCDATA = false;
}
public void comment(char[] ch, int start, int length)
throws SAXException
{
try {
outputCharacters();
_writer.write("<comment>" +
new String(ch, start, length) +
"</comment>\n");
_writer.flush();
}
catch (IOException e) {
throw new SAXException(e);
}
}
// -- Utility methods ------------------------------------------------
private void quicksort(AttributeValueHolder[] attrs, int p, int r) {
while (p < r) {
final int q = partition(attrs, p, r);
quicksort(attrs, p, q);
p = q + 1;
}
}
private int partition(AttributeValueHolder[] attrs, int p, int r) {
AttributeValueHolder x = attrs[(p + r) >>> 1];
int i = p - 1;
int j = r + 1;
while (true) {
while (x.compareTo(attrs[--j]) < 0);
while (x.compareTo(attrs[++i]) > 0);
if (i < j) {
final AttributeValueHolder t = attrs[i];
attrs[i] = attrs[j];
attrs[j] = t;
}
else {
return j;
}
}
}
public static class AttributeValueHolder implements Comparable {
public final String qName;
public final String localName;
public final String uri;
public final String type;
public final String value;
public AttributeValueHolder(String qName,
String localName,
String uri,
String type,
String value)
{
this.qName = qName;
this.localName = localName;
this.uri = uri;
this.type = type;
this.value = value;
}
public int compareTo(Object o) {
try {
return qName.compareTo(((AttributeValueHolder) o).qName);
} catch (Exception e) {
throw new RuntimeException(CommonResourceBundle.getInstance().getString("message.AttributeValueHolderExpected"));
}
}
@Override
public boolean equals(Object o) {
try {
return (o instanceof AttributeValueHolder) &&
qName.equals(((AttributeValueHolder) o).qName);
} catch (Exception e) {
throw new RuntimeException(CommonResourceBundle.getInstance().getString("message.AttributeValueHolderExpected"));
}
}
@Override
public int hashCode() {
int hash = 7;
hash = 97 * hash + (this.qName != null ? this.qName.hashCode() : 0);
return hash;
}
}
}

View File

@@ -0,0 +1,171 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.tools;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.AttributesImpl;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class StAX2SAXReader {
/**
* Content handler where events are pushed.
*/
ContentHandler _handler;
/**
* Lexical handler to report lexical events.
*/
LexicalHandler _lexicalHandler;
/**
* XML stream reader where events are pulled.
*/
XMLStreamReader _reader;
public StAX2SAXReader(XMLStreamReader reader, ContentHandler handler) {
_handler = handler;
_reader = reader;
}
public StAX2SAXReader(XMLStreamReader reader) {
_reader = reader;
}
public void setContentHandler(ContentHandler handler) {
_handler = handler;
}
public void setLexicalHandler(LexicalHandler lexicalHandler) {
_lexicalHandler = lexicalHandler;
}
public void adapt() throws XMLStreamException, SAXException {
QName qname;
String prefix, localPart;
AttributesImpl attrs = new AttributesImpl();
char[] buffer;
int nsc;
int nat;
_handler.startDocument();
try {
while (_reader.hasNext()) {
int event = _reader.next();
switch(event) {
case XMLStreamConstants.START_ELEMENT: {
// Report namespace events first
nsc = _reader.getNamespaceCount();
for (int i = 0; i < nsc; i++) {
_handler.startPrefixMapping(_reader.getNamespacePrefix(i),
_reader.getNamespaceURI(i));
}
// Collect list of attributes
attrs.clear();
nat = _reader.getAttributeCount();
for (int i = 0; i < nat; i++) {
QName q = _reader.getAttributeName(i);
String qName = _reader.getAttributePrefix(i);
if (qName == null || qName == "") {
qName = q.getLocalPart();
} else {
qName = qName + ":" + q.getLocalPart();
}
attrs.addAttribute(_reader.getAttributeNamespace(i),
q.getLocalPart(),
qName,
_reader.getAttributeType(i),
_reader.getAttributeValue(i));
}
// Report start element
qname = _reader.getName();
prefix = qname.getPrefix();
localPart = qname.getLocalPart();
_handler.startElement(_reader.getNamespaceURI(),
localPart,
(prefix.length() > 0) ?
(prefix + ":" + localPart) : localPart,
attrs);
break;
}
case XMLStreamConstants.END_ELEMENT: {
// Report end element
qname = _reader.getName();
prefix = qname.getPrefix();
localPart = qname.getLocalPart();
_handler.endElement(_reader.getNamespaceURI(),
localPart,
(prefix.length() > 0) ?
(prefix + ":" + localPart) : localPart);
// Report end namespace events
nsc = _reader.getNamespaceCount();
for (int i = 0; i < nsc; i++) {
_handler.endPrefixMapping(_reader.getNamespacePrefix(i));
}
break;
}
case XMLStreamConstants.CHARACTERS:
_handler.characters(_reader.getTextCharacters(), _reader.getTextStart(), _reader.getTextLength());
break;
case XMLStreamConstants.COMMENT:
_lexicalHandler.comment(_reader.getTextCharacters(), _reader.getTextStart(), _reader.getTextLength());
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
_handler.processingInstruction(_reader.getPITarget(), _reader.getPIData());
break;
case XMLStreamConstants.END_DOCUMENT:
break;
default:
throw new RuntimeException(CommonResourceBundle.getInstance().getString("message.StAX2SAXReader", new Object[]{Integer.valueOf(event)}));
} // switch
}
}
catch (XMLStreamException e) {
_handler.endDocument(); // flush whatever we have
throw e;
}
_handler.endDocument();
}
}

View File

@@ -0,0 +1,151 @@
/*
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.tools;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
import java.net.URI;
import java.net.URISyntaxException;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public abstract class TransformInputOutput {
/** Creates a new instance of TransformInputOutput */
public TransformInputOutput() {
}
public void parse(String[] args) throws Exception {
InputStream in = null;
OutputStream out = null;
if (args.length == 0) {
in = new BufferedInputStream(System.in);
out = new BufferedOutputStream(System.out);
} else if (args.length == 1) {
in = new BufferedInputStream(new FileInputStream(args[0]));
out = new BufferedOutputStream(System.out);
} else if (args.length == 2) {
in = new BufferedInputStream(new FileInputStream(args[0]));
out = new BufferedOutputStream(new FileOutputStream(args[1]));
} else {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.optinalFileNotSpecified"));
}
parse(in, out);
}
abstract public void parse(InputStream in, OutputStream out) throws Exception;
// parse alternative with current working directory parameter
// is used to process xml documents, which have external imported entities
public void parse(InputStream in, OutputStream out, String workingDirectory) throws Exception {
throw new UnsupportedOperationException();
}
private static URI currentJavaWorkingDirectory;
static {
currentJavaWorkingDirectory = new File(System.getProperty("user.dir")).toURI();
}
protected static EntityResolver createRelativePathResolver(final String workingDirectory) {
return new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
if (systemId != null && systemId.startsWith("file:/")) {
URI workingDirectoryURI = new File(workingDirectory).toURI();
URI workingFile;
try {
// Construction new File(new URI(String)).toURI() is used to be sure URI has correct representation without redundant '/'
workingFile = convertToNewWorkingDirectory(currentJavaWorkingDirectory, workingDirectoryURI, new File(new URI(systemId)).toURI());
return new InputSource(workingFile.toString());
} catch (URISyntaxException ex) {
//Should not get here
}
}
return null;
}
};
}
private static URI convertToNewWorkingDirectory(URI oldwd, URI newwd, URI file) throws IOException, URISyntaxException {
String oldwdStr = oldwd.toString();
String newwdStr = newwd.toString();
String fileStr = file.toString();
String cmpStr = null;
// In simpliest case <user.dir>/file.xml - do it faster
if (fileStr.startsWith(oldwdStr) && (cmpStr = fileStr.substring(oldwdStr.length())).indexOf('/') == -1) {
return new URI(newwdStr + '/' + cmpStr);
}
String[] oldwdSplit = oldwdStr.split("/");
String[] newwdSplit = newwdStr.split("/");
String[] fileSplit = fileStr.split("/");
int diff;
for (diff = 0; diff < oldwdSplit.length && diff < fileSplit.length; diff++) {
if (!oldwdSplit[diff].equals(fileSplit[diff])) {
break;
}
}
int diffNew;
for(diffNew=0; diffNew<newwdSplit.length && diffNew<fileSplit.length; diffNew++) {
if (!newwdSplit[diffNew].equals(fileSplit[diffNew])) {
break;
}
}
//Workaround for case, when extrnal imported entity has imports other entity
//in that case systemId has correct path, not based on user.dir
if (diffNew > diff) {
return file;
}
int elemsToSub = oldwdSplit.length - diff;
StringBuffer resultStr = new StringBuffer(100);
for(int i=0; i<newwdSplit.length - elemsToSub; i++) {
resultStr.append(newwdSplit[i]);
resultStr.append('/');
}
for(int i=diff; i<fileSplit.length; i++) {
resultStr.append(fileSplit[i]);
if (i < fileSplit.length - 1) resultStr.append('/');
}
return new URI(resultStr.toString());
}
}

View File

@@ -0,0 +1,287 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.tools;
import com.sun.xml.internal.fastinfoset.QualifiedName;
import com.sun.xml.internal.fastinfoset.util.CharArray;
import com.sun.xml.internal.fastinfoset.util.DuplicateAttributeVerifier;
import com.sun.xml.internal.fastinfoset.util.KeyIntMap;
import com.sun.xml.internal.fastinfoset.util.LocalNameQualifiedNamesMap;
import com.sun.xml.internal.fastinfoset.util.PrefixArray;
import com.sun.xml.internal.fastinfoset.util.QualifiedNameArray;
import com.sun.xml.internal.fastinfoset.util.StringArray;
import com.sun.xml.internal.fastinfoset.util.StringIntMap;
import com.sun.xml.internal.fastinfoset.vocab.ParserVocabulary;
import com.sun.xml.internal.fastinfoset.vocab.SerializerVocabulary;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.DefaultHandler;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
import java.util.Set;
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetSerializer;
public class VocabularyGenerator extends DefaultHandler implements LexicalHandler {
protected SerializerVocabulary _serializerVocabulary;
protected ParserVocabulary _parserVocabulary;
protected com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary _v;
protected int attributeValueSizeConstraint = FastInfosetSerializer.MAX_ATTRIBUTE_VALUE_SIZE;
protected int characterContentChunkSizeContraint = FastInfosetSerializer.MAX_CHARACTER_CONTENT_CHUNK_SIZE;
/** Creates a new instance of VocabularyGenerator */
public VocabularyGenerator() {
_serializerVocabulary = new SerializerVocabulary();
_parserVocabulary = new ParserVocabulary();
_v = new com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary();
}
public VocabularyGenerator(SerializerVocabulary serializerVocabulary) {
_serializerVocabulary = serializerVocabulary;
_parserVocabulary = new ParserVocabulary();
_v = new com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary();
}
public VocabularyGenerator(ParserVocabulary parserVocabulary) {
_serializerVocabulary = new SerializerVocabulary();
_parserVocabulary = parserVocabulary;
_v = new com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary();
}
/** Creates a new instance of VocabularyGenerator */
public VocabularyGenerator(SerializerVocabulary serializerVocabulary, ParserVocabulary parserVocabulary) {
_serializerVocabulary = serializerVocabulary;
_parserVocabulary = parserVocabulary;
_v = new com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary();
}
public com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary getVocabulary() {
return _v;
}
public void setCharacterContentChunkSizeLimit(int size) {
if (size < 0 ) {
size = 0;
}
characterContentChunkSizeContraint = size;
}
public int getCharacterContentChunkSizeLimit() {
return characterContentChunkSizeContraint;
}
public void setAttributeValueSizeLimit(int size) {
if (size < 0 ) {
size = 0;
}
attributeValueSizeConstraint = size;
}
public int getAttributeValueSizeLimit() {
return attributeValueSizeConstraint;
}
// ContentHandler
public void startDocument() throws SAXException {
}
public void endDocument() throws SAXException {
}
public void startPrefixMapping(String prefix, String uri) throws SAXException {
addToTable(prefix, _v.prefixes, _serializerVocabulary.prefix, _parserVocabulary.prefix);
addToTable(uri, _v.namespaceNames, _serializerVocabulary.namespaceName, _parserVocabulary.namespaceName);
}
public void endPrefixMapping(String prefix) throws SAXException {
}
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
addToNameTable(namespaceURI, qName, localName,
_v.elements, _serializerVocabulary.elementName, _parserVocabulary.elementName, false);
for (int a = 0; a < atts.getLength(); a++) {
addToNameTable(atts.getURI(a), atts.getQName(a), atts.getLocalName(a),
_v.attributes, _serializerVocabulary.attributeName, _parserVocabulary.attributeName, true);
String value = atts.getValue(a);
if (value.length() < attributeValueSizeConstraint) {
addToTable(value, _v.attributeValues, _serializerVocabulary.attributeValue, _parserVocabulary.attributeValue);
}
}
}
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
}
public void characters(char[] ch, int start, int length) throws SAXException {
if (length < characterContentChunkSizeContraint) {
addToCharArrayTable(new CharArray(ch, start, length, true));
}
}
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
}
public void processingInstruction(String target, String data) throws SAXException {
}
public void setDocumentLocator(org.xml.sax.Locator locator) {
}
public void skippedEntity(String name) throws SAXException {
}
// LexicalHandler
public void comment(char[] ch, int start, int length) throws SAXException {
}
public void startCDATA() throws SAXException {
}
public void endCDATA() throws SAXException {
}
public void startDTD(String name, String publicId, String systemId) throws SAXException {
}
public void endDTD() throws SAXException {
}
public void startEntity(String name) throws SAXException {
}
public void endEntity(String name) throws SAXException {
}
public void addToTable(String s, Set v, StringIntMap m, StringArray a) {
if (s.length() == 0) {
return;
}
if (m.obtainIndex(s) == KeyIntMap.NOT_PRESENT) {
a.add(s);
}
v.add(s);
}
public void addToTable(String s, Set v, StringIntMap m, PrefixArray a) {
if (s.length() == 0) {
return;
}
if (m.obtainIndex(s) == KeyIntMap.NOT_PRESENT) {
a.add(s);
}
v.add(s);
}
public void addToCharArrayTable(CharArray c) {
if (_serializerVocabulary.characterContentChunk.obtainIndex(c.ch, c.start, c.length, false) == KeyIntMap.NOT_PRESENT) {
_parserVocabulary.characterContentChunk.add(c.ch, c.length);
}
_v.characterContentChunks.add(c.toString());
}
public void addToNameTable(String namespaceURI, String qName, String localName,
Set v, LocalNameQualifiedNamesMap m, QualifiedNameArray a,
boolean isAttribute) throws SAXException {
LocalNameQualifiedNamesMap.Entry entry = m.obtainEntry(qName);
if (entry._valueIndex > 0) {
QualifiedName[] names = entry._value;
for (int i = 0; i < entry._valueIndex; i++) {
if ((namespaceURI == names[i].namespaceName || namespaceURI.equals(names[i].namespaceName))) {
return;
}
}
}
String prefix = getPrefixFromQualifiedName(qName);
int namespaceURIIndex = -1;
int prefixIndex = -1;
int localNameIndex = -1;
if (namespaceURI.length() > 0) {
namespaceURIIndex = _serializerVocabulary.namespaceName.get(namespaceURI);
if (namespaceURIIndex == KeyIntMap.NOT_PRESENT) {
throw new SAXException(CommonResourceBundle.getInstance().
getString("message.namespaceURINotIndexed", new Object[]{Integer.valueOf(namespaceURIIndex)}));
}
if (prefix.length() > 0) {
prefixIndex = _serializerVocabulary.prefix.get(prefix);
if (prefixIndex == KeyIntMap.NOT_PRESENT) {
throw new SAXException(CommonResourceBundle.getInstance().
getString("message.prefixNotIndexed", new Object[]{Integer.valueOf(prefixIndex)}));
}
}
}
localNameIndex = _serializerVocabulary.localName.obtainIndex(localName);
if (localNameIndex == KeyIntMap.NOT_PRESENT) {
_parserVocabulary.localName.add(localName);
localNameIndex = _parserVocabulary.localName.getSize() - 1;
}
QualifiedName name = new QualifiedName(prefix, namespaceURI, localName, m.getNextIndex(),
prefixIndex, namespaceURIIndex, localNameIndex);
if (isAttribute) {
name.createAttributeValues(DuplicateAttributeVerifier.MAP_SIZE);
}
entry.addQualifiedName(name);
a.add(name);
v.add(name.getQName());
}
public static String getPrefixFromQualifiedName(String qName) {
int i = qName.indexOf(':');
String prefix = "";
if (i != -1) {
prefix = qName.substring(0, i);
}
return prefix;
}
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.tools;
import com.sun.xml.internal.fastinfoset.dom.DOMDocumentSerializer;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
public class XML_DOM_FI extends TransformInputOutput {
public XML_DOM_FI() {
}
public void parse(InputStream document, OutputStream finf, String workingDirectory) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
if (workingDirectory != null) {
db.setEntityResolver(createRelativePathResolver(workingDirectory));
}
Document d = db.parse(document);
DOMDocumentSerializer s = new DOMDocumentSerializer();
s.setOutputStream(finf);
s.serialize(d);
}
public void parse(InputStream document, OutputStream finf) throws Exception {
parse(document, finf, null);
}
public static void main(String[] args) throws Exception {
XML_DOM_FI p = new XML_DOM_FI();
p.parse(args);
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.tools;
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetResult;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import org.w3c.dom.Document;
public class XML_DOM_SAX_FI extends TransformInputOutput {
public XML_DOM_SAX_FI() {
}
public void parse(InputStream document, OutputStream finf, String workingDirectory) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
if (workingDirectory != null) {
db.setEntityResolver(createRelativePathResolver(workingDirectory));
}
Document d = db.parse(document);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
t.transform(new DOMSource(d), new FastInfosetResult(finf));
}
public void parse(InputStream document, OutputStream finf) throws Exception {
parse(document, finf, null);
}
public static void main(String[] args) throws Exception {
XML_DOM_SAX_FI p = new XML_DOM_SAX_FI();
p.parse(args);
}
}

View File

@@ -0,0 +1,92 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.tools;
import com.sun.xml.internal.fastinfoset.sax.SAXDocumentSerializer;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.Reader;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
public class XML_SAX_FI extends TransformInputOutput {
public XML_SAX_FI() {
}
public void parse(InputStream xml, OutputStream finf, String workingDirectory) throws Exception {
SAXParser saxParser = getParser();
SAXDocumentSerializer documentSerializer = getSerializer(finf);
XMLReader reader = saxParser.getXMLReader();
reader.setProperty("http://xml.org/sax/properties/lexical-handler", documentSerializer);
reader.setContentHandler(documentSerializer);
if (workingDirectory != null) {
reader.setEntityResolver(createRelativePathResolver(workingDirectory));
}
reader.parse(new InputSource(xml));
}
public void parse(InputStream xml, OutputStream finf) throws Exception {
parse(xml, finf, null);
}
public void convert(Reader reader, OutputStream finf) throws Exception {
InputSource is = new InputSource(reader);
SAXParser saxParser = getParser();
SAXDocumentSerializer documentSerializer = getSerializer(finf);
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", documentSerializer);
saxParser.parse(is, documentSerializer);
}
private SAXParser getParser() {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
try {
return saxParserFactory.newSAXParser();
} catch (Exception e) {
return null;
}
}
private SAXDocumentSerializer getSerializer(OutputStream finf) {
SAXDocumentSerializer documentSerializer = new SAXDocumentSerializer();
documentSerializer.setOutputStream(finf);
return documentSerializer;
}
public static void main(String[] args) throws Exception {
XML_SAX_FI s = new XML_SAX_FI();
s.parse(args);
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.tools;
import com.sun.xml.internal.fastinfoset.stax.StAXDocumentSerializer;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
public class XML_SAX_StAX_FI extends TransformInputOutput {
public XML_SAX_StAX_FI() {
}
public void parse(InputStream xml, OutputStream finf, String workingDirectory) throws Exception {
StAXDocumentSerializer documentSerializer = new StAXDocumentSerializer();
documentSerializer.setOutputStream(finf);
SAX2StAXWriter saxTostax = new SAX2StAXWriter(documentSerializer);
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
SAXParser saxParser = saxParserFactory.newSAXParser();
XMLReader reader = saxParser.getXMLReader();
reader.setProperty("http://xml.org/sax/properties/lexical-handler", saxTostax);
reader.setContentHandler(saxTostax);
if (workingDirectory != null) {
reader.setEntityResolver(createRelativePathResolver(workingDirectory));
}
reader.parse(new InputSource(xml));
xml.close();
finf.close();
}
public void parse(InputStream xml, OutputStream finf) throws Exception {
parse(xml, finf, null);
}
public static void main(String[] args) throws Exception {
XML_SAX_StAX_FI s = new XML_SAX_StAX_FI();
s.parse(args);
}
}