feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* This code is subject to the freebxml License, Version 1.1
|
||||
*
|
||||
* Copyright (c) 2001 - 2005 freebxml.org. All rights reserved.
|
||||
*
|
||||
* $Header: /zpool01/javanet/scm/svn/tmp/cvs2svn/fi/FastInfoset/src/com/sun/xml/internal/fastinfoset/AbstractResourceBundle.java,v 1.3.2.4 2009-05-13 08:53:01 oleksiys Exp $
|
||||
*/
|
||||
package com.sun.xml.internal.fastinfoset;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
|
||||
/**
|
||||
* This class contains methods common to all *ResourceBundle classes
|
||||
*
|
||||
* @author FastInfoset team
|
||||
*/
|
||||
public abstract class AbstractResourceBundle extends ResourceBundle {
|
||||
|
||||
public static final String LOCALE = "com.sun.xml.internal.fastinfoset.locale";
|
||||
|
||||
/**
|
||||
* Gets 'key' from ResourceBundle and format mesage using 'args'.
|
||||
*
|
||||
* @param key String key for message.
|
||||
* @param args Array of arguments for message.
|
||||
* @return String formatted message.
|
||||
*/
|
||||
public String getString(String key, Object args[]) {
|
||||
String pattern = getBundle().getString(key);
|
||||
return MessageFormat.format(pattern, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a locale string, return corresponding Locale instance.
|
||||
*
|
||||
* @param localeString
|
||||
* Name for the locale of interest. If null, use VM default locale.
|
||||
* @return New Locale instance.
|
||||
*/
|
||||
public static Locale parseLocale(String localeString) {
|
||||
Locale locale = null;
|
||||
if (localeString == null) {
|
||||
locale = Locale.getDefault();
|
||||
} else {
|
||||
try {
|
||||
String[] args = localeString.split("_");
|
||||
if (args.length == 1) {
|
||||
locale = new Locale(args[0]);
|
||||
} else if (args.length == 2) {
|
||||
locale = new Locale(args[0], args[1]);
|
||||
} else if (args.length == 3) {
|
||||
locale = new Locale(args[0], args[1], args[2]);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
}
|
||||
return locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses of this class must implement this method so that the
|
||||
* correct resource bundle is passed to methods in this class
|
||||
*
|
||||
* @return
|
||||
* A java.util.ResourceBundle from the subsclass. Methods in this class
|
||||
* will use this reference.
|
||||
*/
|
||||
public abstract ResourceBundle getBundle();
|
||||
|
||||
|
||||
/**
|
||||
* Since we are changing the ResourceBundle extension point, must
|
||||
* implement handleGetObject() using delegate getBundle(). Uses
|
||||
* getObject() call to work around protected access to
|
||||
* ResourceBundle.handleGetObject(). Happily, this means parent tree
|
||||
* of delegate bundle is searched for a match.
|
||||
*
|
||||
* Implements java.util.ResourceBundle.handleGetObject; inherits that
|
||||
* javadoc information.
|
||||
*
|
||||
* @see java.util.ResourceBundle#handleGetObject(String)
|
||||
*/
|
||||
protected Object handleGetObject(String key) {
|
||||
return getBundle().getObject(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Since we are changing the ResourceBundle extension point, must
|
||||
* implement getKeys() using delegate getBundle().
|
||||
*
|
||||
* Implements java.util.ResourceBundle.getKeys; inherits that javadoc
|
||||
* information.
|
||||
*
|
||||
* @see java.util.ResourceBundle#getKeys()
|
||||
*/
|
||||
public final Enumeration getKeys() {
|
||||
return getBundle().getKeys();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/** Resource bundle implementation for localized messages.
|
||||
*/
|
||||
public class CommonResourceBundle extends AbstractResourceBundle {
|
||||
|
||||
public static final String BASE_NAME = "com.sun.xml.internal.fastinfoset.resources.ResourceBundle";
|
||||
private static volatile CommonResourceBundle instance = null;
|
||||
private static Locale locale = null;
|
||||
private ResourceBundle bundle = null;
|
||||
|
||||
protected CommonResourceBundle() {
|
||||
// Load the resource bundle of default locale
|
||||
bundle = ResourceBundle.getBundle(BASE_NAME);
|
||||
}
|
||||
|
||||
protected CommonResourceBundle(Locale locale) {
|
||||
// Load the resource bundle of specified locale
|
||||
bundle = ResourceBundle.getBundle(BASE_NAME, locale);
|
||||
}
|
||||
|
||||
public static CommonResourceBundle getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (CommonResourceBundle.class) {
|
||||
instance = new CommonResourceBundle();
|
||||
//**need to know where to get the locale
|
||||
//String localeString = CommonProperties.getInstance()
|
||||
// .getProperty("omar.common.locale");
|
||||
locale = parseLocale(/*localeString*/null);
|
||||
}
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static CommonResourceBundle getInstance(Locale locale) {
|
||||
if (instance == null) {
|
||||
synchronized (CommonResourceBundle.class) {
|
||||
instance = new CommonResourceBundle(locale);
|
||||
}
|
||||
} else {
|
||||
synchronized (CommonResourceBundle.class) {
|
||||
if (CommonResourceBundle.locale != locale) {
|
||||
instance = new CommonResourceBundle(locale);
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
public ResourceBundle getBundle() {
|
||||
return bundle;
|
||||
}
|
||||
public ResourceBundle getBundle(Locale locale) {
|
||||
return ResourceBundle.getBundle(BASE_NAME, locale);
|
||||
}
|
||||
|
||||
}
|
||||
2010
jdkSrc/jdk8/com/sun/xml/internal/fastinfoset/Decoder.java
Normal file
2010
jdkSrc/jdk8/com/sun/xml/internal/fastinfoset/Decoder.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,824 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class DecoderStateTables {
|
||||
private static int RANGE_INDEX_END = 0;
|
||||
private static int RANGE_INDEX_VALUE = 1;
|
||||
|
||||
public final static int STATE_ILLEGAL = 255;
|
||||
public final static int STATE_UNSUPPORTED = 254;
|
||||
|
||||
// EII child states
|
||||
public final static int EII_NO_AIIS_INDEX_SMALL = 0;
|
||||
public final static int EII_AIIS_INDEX_SMALL = 1;
|
||||
public final static int EII_INDEX_MEDIUM = 2;
|
||||
public final static int EII_INDEX_LARGE = 3;
|
||||
public final static int EII_NAMESPACES = 4;
|
||||
public final static int EII_LITERAL = 5;
|
||||
public final static int CII_UTF8_SMALL_LENGTH = 6;
|
||||
public final static int CII_UTF8_MEDIUM_LENGTH = 7;
|
||||
public final static int CII_UTF8_LARGE_LENGTH = 8;
|
||||
public final static int CII_UTF16_SMALL_LENGTH = 9;
|
||||
public final static int CII_UTF16_MEDIUM_LENGTH = 10;
|
||||
public final static int CII_UTF16_LARGE_LENGTH = 11;
|
||||
public final static int CII_RA = 12;
|
||||
public final static int CII_EA = 13;
|
||||
public final static int CII_INDEX_SMALL = 14;
|
||||
public final static int CII_INDEX_MEDIUM = 15;
|
||||
public final static int CII_INDEX_LARGE = 16;
|
||||
public final static int CII_INDEX_LARGE_LARGE = 17;
|
||||
public final static int COMMENT_II = 18;
|
||||
public final static int PROCESSING_INSTRUCTION_II = 19;
|
||||
public final static int DOCUMENT_TYPE_DECLARATION_II = 20;
|
||||
public final static int UNEXPANDED_ENTITY_REFERENCE_II = 21;
|
||||
public final static int TERMINATOR_SINGLE = 22;
|
||||
public final static int TERMINATOR_DOUBLE = 23;
|
||||
|
||||
private static final int[] DII = new int[256];
|
||||
|
||||
private static final int[][] DII_RANGES = {
|
||||
// EII
|
||||
|
||||
// %00000000 to %00011111 EII no attributes small index
|
||||
{ 0x1F, EII_NO_AIIS_INDEX_SMALL },
|
||||
|
||||
// %00100000 to %00100111 EII medium index
|
||||
{ 0x27, EII_INDEX_MEDIUM },
|
||||
|
||||
// %00101000 to %00101111 EII large index
|
||||
// %00110000 EII very large index
|
||||
// %00101000 to %00110000
|
||||
{ 0x30, EII_INDEX_LARGE },
|
||||
|
||||
// %00110001 to %00110111 ILLEGAL
|
||||
{ 0x37, STATE_ILLEGAL },
|
||||
|
||||
// %00111000 EII namespaces
|
||||
{ 0x38, EII_NAMESPACES },
|
||||
|
||||
// %00111001 to %00111011 ILLEGAL
|
||||
{ 0x3B, STATE_ILLEGAL },
|
||||
|
||||
// %00111100 EII literal (no prefix, no namespace)
|
||||
{ 0x3C, EII_LITERAL },
|
||||
|
||||
// %00111101 EII literal (no prefix, namespace)
|
||||
{ 0x3D, EII_LITERAL },
|
||||
|
||||
// %00111110 ILLEGAL
|
||||
{ 0x3E, STATE_ILLEGAL },
|
||||
|
||||
// %00111111 EII literal (prefix, namespace)
|
||||
{ 0x3F, EII_LITERAL },
|
||||
|
||||
// %01000000 to %01011111 EII attributes small index
|
||||
{ 0x5F, EII_AIIS_INDEX_SMALL },
|
||||
|
||||
// %01100000 to %01100111 EII medium index
|
||||
{ 0x67, EII_INDEX_MEDIUM },
|
||||
|
||||
// %01101000 to %01101111 EII large index
|
||||
// %01110000 EII very large index
|
||||
// %01101000 to %01110000
|
||||
{ 0x70, EII_INDEX_LARGE },
|
||||
|
||||
// %01110001 to %01110111 ILLEGAL
|
||||
{ 0x77, STATE_ILLEGAL },
|
||||
|
||||
// %01111000 EII attributes namespaces
|
||||
{ 0x78, EII_NAMESPACES },
|
||||
|
||||
// %01111001 to %01111011 ILLEGAL
|
||||
{ 0x7B, STATE_ILLEGAL },
|
||||
|
||||
// %01111100 EII attributes literal (no prefix, no namespace)
|
||||
{ 0x7C, EII_LITERAL },
|
||||
|
||||
// %01111101 EII attributes literal (no prefix, namespace)
|
||||
{ 0x7D, EII_LITERAL },
|
||||
|
||||
// %01111110 ILLEGAL
|
||||
{ 0x7E, STATE_ILLEGAL },
|
||||
|
||||
// %01111111 EII attributes literal (prefix, namespace)
|
||||
{ 0x7F, EII_LITERAL },
|
||||
|
||||
// %10000000 to %11000011
|
||||
{ 0xC3, STATE_ILLEGAL },
|
||||
|
||||
// %11000100 to %11000111
|
||||
{ 0xC7, DOCUMENT_TYPE_DECLARATION_II },
|
||||
|
||||
// %11001000 to %1110000
|
||||
{ 0xE0, STATE_ILLEGAL },
|
||||
|
||||
// %11100001 processing instruction
|
||||
{ 0xE1, PROCESSING_INSTRUCTION_II },
|
||||
|
||||
// %11100010 comment
|
||||
{ 0xE2, COMMENT_II},
|
||||
|
||||
// %111000011 to %11101111
|
||||
{ 0xEF, STATE_ILLEGAL },
|
||||
|
||||
// Terminators
|
||||
|
||||
// %11110000 single terminator
|
||||
{ 0xF0, TERMINATOR_SINGLE },
|
||||
|
||||
// %11110000 to %11111110 ILLEGAL
|
||||
{ 0xFE, STATE_ILLEGAL },
|
||||
|
||||
// %11111111 double terminator
|
||||
{ 0xFF, TERMINATOR_DOUBLE }
|
||||
};
|
||||
|
||||
private static final int[] EII = new int[256];
|
||||
|
||||
private static final int[][] EII_RANGES = {
|
||||
// EII
|
||||
|
||||
// %00000000 to %00011111 EII no attributes small index
|
||||
{ 0x1F, EII_NO_AIIS_INDEX_SMALL },
|
||||
|
||||
// %00100000 to %00100111 EII medium index
|
||||
{ 0x27, EII_INDEX_MEDIUM },
|
||||
|
||||
// %00101000 to %00101111 EII large index
|
||||
// %00110000 EII very large index
|
||||
// %00101000 to %00110000
|
||||
{ 0x30, EII_INDEX_LARGE },
|
||||
|
||||
// %00110001 to %00110111 ILLEGAL
|
||||
{ 0x37, STATE_ILLEGAL },
|
||||
|
||||
// %00111000 EII namespaces
|
||||
{ 0x38, EII_NAMESPACES },
|
||||
|
||||
// %00111001 to %00111011 ILLEGAL
|
||||
{ 0x3B, STATE_ILLEGAL },
|
||||
|
||||
// %00111100 EII literal (no prefix, no namespace)
|
||||
{ 0x3C, EII_LITERAL },
|
||||
|
||||
// %00111101 EII literal (no prefix, namespace)
|
||||
{ 0x3D, EII_LITERAL },
|
||||
|
||||
// %00111110 ILLEGAL
|
||||
{ 0x3E, STATE_ILLEGAL },
|
||||
|
||||
// %00111111 EII literal (prefix, namespace)
|
||||
{ 0x3F, EII_LITERAL },
|
||||
|
||||
// %01000000 to %01011111 EII attributes small index
|
||||
{ 0x5F, EII_AIIS_INDEX_SMALL },
|
||||
|
||||
// %01100000 to %01100111 EII medium index
|
||||
{ 0x67, EII_INDEX_MEDIUM },
|
||||
|
||||
// %01101000 to %01101111 EII large index
|
||||
// %01110000 EII very large index
|
||||
// %01101000 to %01110000
|
||||
{ 0x70, EII_INDEX_LARGE },
|
||||
|
||||
// %01110001 to %01110111 ILLEGAL
|
||||
{ 0x77, STATE_ILLEGAL },
|
||||
|
||||
// %01111000 EII attributes namespaces
|
||||
{ 0x78, EII_NAMESPACES },
|
||||
|
||||
// %01111001 to %01111011 ILLEGAL
|
||||
{ 0x7B, STATE_ILLEGAL },
|
||||
|
||||
// %01111100 EII attributes literal (no prefix, no namespace)
|
||||
{ 0x7C, EII_LITERAL },
|
||||
|
||||
// %01111101 EII attributes literal (no prefix, namespace)
|
||||
{ 0x7D, EII_LITERAL },
|
||||
|
||||
// %01111110 ILLEGAL
|
||||
{ 0x7E, STATE_ILLEGAL },
|
||||
|
||||
// %01111111 EII attributes literal (prefix, namespace)
|
||||
{ 0x7F, EII_LITERAL },
|
||||
|
||||
// CII
|
||||
|
||||
// UTF-8 string
|
||||
|
||||
// %10000000 to %10000001 CII UTF-8 no add to table small length
|
||||
{ 0x81, CII_UTF8_SMALL_LENGTH },
|
||||
|
||||
// %10000010 CII UTF-8 no add to table medium length
|
||||
{ 0x82, CII_UTF8_MEDIUM_LENGTH },
|
||||
|
||||
// %10000011 CII UTF-8 no add to table large length
|
||||
{ 0x83, CII_UTF8_LARGE_LENGTH },
|
||||
|
||||
// UTF-16 string
|
||||
|
||||
// %10000100 to %10000101 CII UTF-16 no add to table small length
|
||||
{ 0x85, CII_UTF16_SMALL_LENGTH },
|
||||
|
||||
// %10000110 CII UTF-16 no add to table medium length
|
||||
{ 0x86, CII_UTF16_MEDIUM_LENGTH },
|
||||
|
||||
// %10000111 CII UTF-16 no add to table large length
|
||||
{ 0x87, CII_UTF16_LARGE_LENGTH },
|
||||
|
||||
// Resitricted alphabet
|
||||
|
||||
// %10001000 to %10001011 CII RA no add to table
|
||||
{ 0x8B, CII_RA },
|
||||
|
||||
// Encoding algorithm
|
||||
|
||||
// %10001100 to %10001111 CII EA no add to table
|
||||
{ 0x8F, CII_EA },
|
||||
|
||||
// UTF-8 string, add to table
|
||||
|
||||
// %10010000 to %10010001 CII add to table small length
|
||||
{ 0x91, CII_UTF8_SMALL_LENGTH },
|
||||
|
||||
// %10010010 CII add to table medium length
|
||||
{ 0x92, CII_UTF8_MEDIUM_LENGTH },
|
||||
|
||||
// %10010011 CII add to table large length
|
||||
{ 0x93, CII_UTF8_LARGE_LENGTH },
|
||||
|
||||
// UTF-16 string, add to table
|
||||
|
||||
// %10010100 to %10010101 CII UTF-16 add to table small length
|
||||
{ 0x95, CII_UTF16_SMALL_LENGTH },
|
||||
|
||||
// %10010110 CII UTF-16 add to table medium length
|
||||
{ 0x96, CII_UTF16_MEDIUM_LENGTH },
|
||||
|
||||
// %10010111 CII UTF-16 add to table large length
|
||||
{ 0x97, CII_UTF16_LARGE_LENGTH },
|
||||
|
||||
// Restricted alphabet, add to table
|
||||
|
||||
// %10011000 to %10011011 CII RA add to table
|
||||
{ 0x9B, CII_RA },
|
||||
|
||||
// Encoding algorithm, add to table
|
||||
|
||||
// %10011100 to %10011111 CII EA add to table
|
||||
{ 0x9F, CII_EA },
|
||||
|
||||
// Index
|
||||
|
||||
// %10100000 to %10101111 CII small index
|
||||
{ 0xAF, CII_INDEX_SMALL },
|
||||
|
||||
// %10110000 to %10110011 CII medium index
|
||||
{ 0xB3, CII_INDEX_MEDIUM },
|
||||
|
||||
// %10110100 to %10110111 CII large index
|
||||
{ 0xB7, CII_INDEX_LARGE },
|
||||
|
||||
// %10111000 CII very large index
|
||||
{ 0xB8, CII_INDEX_LARGE_LARGE },
|
||||
|
||||
// %10111001 to %11000111 ILLEGAL
|
||||
{ 0xC7, STATE_ILLEGAL },
|
||||
|
||||
// %11001000 to %11001011
|
||||
{ 0xCB, UNEXPANDED_ENTITY_REFERENCE_II },
|
||||
|
||||
// %11001100 to %11100000 ILLEGAL
|
||||
{ 0xE0, STATE_ILLEGAL },
|
||||
|
||||
// %11100001 processing instruction
|
||||
{ 0xE1, PROCESSING_INSTRUCTION_II },
|
||||
|
||||
// %11100010 comment
|
||||
{ 0xE2, COMMENT_II},
|
||||
|
||||
// %111000011 to %11101111
|
||||
{ 0xEF, STATE_ILLEGAL },
|
||||
|
||||
// Terminators
|
||||
|
||||
// %11110000 single terminator
|
||||
{ 0xF0, TERMINATOR_SINGLE },
|
||||
|
||||
// %11110000 to %11111110 ILLEGAL
|
||||
{ 0xFE, STATE_ILLEGAL },
|
||||
|
||||
// %11111111 double terminator
|
||||
{ 0xFF, TERMINATOR_DOUBLE }
|
||||
};
|
||||
|
||||
|
||||
// AII states
|
||||
public final static int AII_INDEX_SMALL = 0;
|
||||
public final static int AII_INDEX_MEDIUM = 1;
|
||||
public final static int AII_INDEX_LARGE = 2;
|
||||
public final static int AII_LITERAL = 3;
|
||||
public final static int AII_TERMINATOR_SINGLE = 4;
|
||||
public final static int AII_TERMINATOR_DOUBLE = 5;
|
||||
|
||||
private static final int[] AII = new int[256];
|
||||
|
||||
private static final int[][] AII_RANGES = {
|
||||
// %00000000 to %00111111 AII small index
|
||||
{ 0x3F, AII_INDEX_SMALL },
|
||||
|
||||
// %01000000 to %01011111 AII medium index
|
||||
{ 0x5F, AII_INDEX_MEDIUM },
|
||||
|
||||
// %01100000 to %01101111 AII large index
|
||||
{ 0x6F, AII_INDEX_LARGE },
|
||||
|
||||
// %01110000 to %01110111 ILLEGAL
|
||||
{ 0x77, STATE_ILLEGAL },
|
||||
|
||||
// %01111000 AII literal (no prefix, no namespace)
|
||||
// %01111001 AII literal (no prefix, namespace)
|
||||
{ 0x79, AII_LITERAL },
|
||||
|
||||
// %01111010 ILLEGAL
|
||||
{ 0x7A, STATE_ILLEGAL },
|
||||
|
||||
// %01111011 AII literal (prefix, namespace)
|
||||
{ 0x7B, AII_LITERAL },
|
||||
|
||||
// %10000000 to %11101111 ILLEGAL
|
||||
{ 0xEF, STATE_ILLEGAL },
|
||||
|
||||
// Terminators
|
||||
|
||||
// %11110000 single terminator
|
||||
{ 0xF0, AII_TERMINATOR_SINGLE },
|
||||
|
||||
// %11110000 to %11111110 ILLEGAL
|
||||
{ 0xFE, STATE_ILLEGAL },
|
||||
|
||||
// %11111111 double terminator
|
||||
{ 0xFF, AII_TERMINATOR_DOUBLE }
|
||||
};
|
||||
|
||||
|
||||
// AII value states
|
||||
public final static int NISTRING_UTF8_SMALL_LENGTH = 0;
|
||||
public final static int NISTRING_UTF8_MEDIUM_LENGTH = 1;
|
||||
public final static int NISTRING_UTF8_LARGE_LENGTH = 2;
|
||||
public final static int NISTRING_UTF16_SMALL_LENGTH = 3;
|
||||
public final static int NISTRING_UTF16_MEDIUM_LENGTH = 4;
|
||||
public final static int NISTRING_UTF16_LARGE_LENGTH = 5;
|
||||
public final static int NISTRING_RA = 6;
|
||||
public final static int NISTRING_EA = 7;
|
||||
public final static int NISTRING_INDEX_SMALL = 8;
|
||||
public final static int NISTRING_INDEX_MEDIUM = 9;
|
||||
public final static int NISTRING_INDEX_LARGE = 10;
|
||||
public final static int NISTRING_EMPTY = 11;
|
||||
|
||||
private static final int[] NISTRING = new int[256];
|
||||
|
||||
private static final int[][] NISTRING_RANGES = {
|
||||
// UTF-8 string
|
||||
|
||||
// %00000000 to %00000111 UTF-8 no add to table small length
|
||||
{ 0x07, NISTRING_UTF8_SMALL_LENGTH },
|
||||
|
||||
// %00001000 UTF-8 no add to table medium length
|
||||
{ 0x08, NISTRING_UTF8_MEDIUM_LENGTH },
|
||||
|
||||
// %00001001 to %00001011 ILLEGAL
|
||||
{ 0x0B, STATE_ILLEGAL },
|
||||
|
||||
// %00001100 UTF-8 no add to table large length
|
||||
{ 0x0C, NISTRING_UTF8_LARGE_LENGTH },
|
||||
|
||||
// %00001101 to %00001111 ILLEGAL
|
||||
{ 0x0F, STATE_ILLEGAL },
|
||||
|
||||
// UTF-16 string
|
||||
|
||||
// %00010000 to %00010111 UTF-16 no add to table small length
|
||||
{ 0x17, NISTRING_UTF16_SMALL_LENGTH },
|
||||
|
||||
// %00001000 UTF-16 no add to table medium length
|
||||
{ 0x18, NISTRING_UTF16_MEDIUM_LENGTH },
|
||||
|
||||
// %00011001 to %00011011 ILLEGAL
|
||||
{ 0x1B, STATE_ILLEGAL },
|
||||
|
||||
// %00011100 UTF-16 no add to table large length
|
||||
{ 0x1C, NISTRING_UTF16_LARGE_LENGTH },
|
||||
|
||||
// %00011101 to %00011111 ILLEGAL
|
||||
{ 0x1F, STATE_ILLEGAL },
|
||||
|
||||
// Restricted alphabet
|
||||
|
||||
// %00100000 to %00101111 RA no add to table small length
|
||||
{ 0x2F, NISTRING_RA },
|
||||
|
||||
// Encoding algorithm
|
||||
|
||||
// %00110000 to %00111111 EA no add to table
|
||||
{ 0x3F, NISTRING_EA },
|
||||
|
||||
// UTF-8 string, add to table
|
||||
|
||||
// %01000000 to %01000111 UTF-8 add to table small length
|
||||
{ 0x47, NISTRING_UTF8_SMALL_LENGTH },
|
||||
|
||||
// %01001000 UTF-8 add to table medium length
|
||||
{ 0x48, NISTRING_UTF8_MEDIUM_LENGTH },
|
||||
|
||||
// %01001001 to %01001011 ILLEGAL
|
||||
{ 0x4B, STATE_ILLEGAL },
|
||||
|
||||
// %01001100 UTF-8 add to table large length
|
||||
{ 0x4C, NISTRING_UTF8_LARGE_LENGTH },
|
||||
|
||||
// %01001101 to %01001111 ILLEGAL
|
||||
{ 0x4F, STATE_ILLEGAL },
|
||||
|
||||
// UTF-16 string, add to table
|
||||
|
||||
// %01010000 to %01010111 UTF-16 add to table small length
|
||||
{ 0x57, NISTRING_UTF16_SMALL_LENGTH },
|
||||
|
||||
// %01001000 UTF-16 add to table medium length
|
||||
{ 0x58, NISTRING_UTF16_MEDIUM_LENGTH },
|
||||
|
||||
// %01011001 to %01011011 ILLEGAL
|
||||
{ 0x5B, STATE_ILLEGAL },
|
||||
|
||||
// %01011100 UTF-16 add to table large length
|
||||
{ 0x5C, NISTRING_UTF16_LARGE_LENGTH },
|
||||
|
||||
// %01011101 to %01011111 ILLEGAL
|
||||
{ 0x5F, STATE_ILLEGAL },
|
||||
|
||||
// Restricted alphabet, add to table
|
||||
|
||||
// %01100000 to %01101111 RA no add to table small length
|
||||
{ 0x6F, NISTRING_RA },
|
||||
|
||||
// Encoding algorithm, add to table
|
||||
|
||||
// %01110000 to %01111111 EA add to table
|
||||
{ 0x7F, NISTRING_EA },
|
||||
|
||||
// Index
|
||||
|
||||
// %10000000 to %10111111 index small
|
||||
{ 0xBF, NISTRING_INDEX_SMALL },
|
||||
|
||||
// %11000000 to %11011111 index medium
|
||||
{ 0xDF, NISTRING_INDEX_MEDIUM },
|
||||
|
||||
// %11100000 to %11101111 index large
|
||||
{ 0xEF, NISTRING_INDEX_LARGE },
|
||||
|
||||
// %11110000 to %11111110 ILLEGAL
|
||||
{ 0xFE, STATE_ILLEGAL },
|
||||
|
||||
// %11111111 Empty value
|
||||
{ 0xFF, NISTRING_EMPTY },
|
||||
};
|
||||
|
||||
|
||||
/* package */ final static int ISTRING_SMALL_LENGTH = 0;
|
||||
/* package */ final static int ISTRING_MEDIUM_LENGTH = 1;
|
||||
/* package */ final static int ISTRING_LARGE_LENGTH = 2;
|
||||
/* package */ final static int ISTRING_INDEX_SMALL = 3;
|
||||
/* package */ final static int ISTRING_INDEX_MEDIUM = 4;
|
||||
/* package */ final static int ISTRING_INDEX_LARGE = 5;
|
||||
|
||||
private static final int[] ISTRING = new int[256];
|
||||
|
||||
private static final int[][] ISTRING_RANGES = {
|
||||
// %00000000 to %00111111 small length
|
||||
{ 0x3F, ISTRING_SMALL_LENGTH },
|
||||
|
||||
// %01000000 medium length
|
||||
{ 0x40, ISTRING_MEDIUM_LENGTH },
|
||||
|
||||
// %01000001 to %01011111 ILLEGAL
|
||||
{ 0x5F, STATE_ILLEGAL },
|
||||
|
||||
// %01100000 large length
|
||||
{ 0x60, ISTRING_LARGE_LENGTH },
|
||||
|
||||
// %01100001 to %01111111 ILLEGAL
|
||||
{ 0x7F, STATE_ILLEGAL },
|
||||
|
||||
// %10000000 to %10111111 index small
|
||||
{ 0xBF, ISTRING_INDEX_SMALL },
|
||||
|
||||
// %11000000 to %11011111 index medium
|
||||
{ 0xDF, ISTRING_INDEX_MEDIUM },
|
||||
|
||||
// %11100000 to %11101111 index large
|
||||
{ 0xEF, ISTRING_INDEX_LARGE },
|
||||
|
||||
// %11110000 to %11111111 ILLEGAL
|
||||
{ 0xFF, STATE_ILLEGAL },
|
||||
};
|
||||
|
||||
|
||||
/* package */ final static int ISTRING_PREFIX_NAMESPACE_LENGTH_3 = 6;
|
||||
/* package */ final static int ISTRING_PREFIX_NAMESPACE_LENGTH_5 = 7;
|
||||
/* package */ final static int ISTRING_PREFIX_NAMESPACE_LENGTH_29 = 8;
|
||||
/* package */ final static int ISTRING_PREFIX_NAMESPACE_LENGTH_36 = 9;
|
||||
/* package */ final static int ISTRING_PREFIX_NAMESPACE_INDEX_ZERO = 10;
|
||||
|
||||
private static final int[] ISTRING_PREFIX_NAMESPACE = new int[256];
|
||||
|
||||
private static final int[][] ISTRING_PREFIX_NAMESPACE_RANGES = {
|
||||
// %00000000 to %00000001 small length
|
||||
{ 0x01, ISTRING_SMALL_LENGTH },
|
||||
|
||||
// %00000010 small length
|
||||
{ 0x02, ISTRING_PREFIX_NAMESPACE_LENGTH_3 },
|
||||
|
||||
// %00000011 small length
|
||||
{ 0x03, ISTRING_SMALL_LENGTH },
|
||||
|
||||
// %00000100 small length
|
||||
{ 0x04, ISTRING_PREFIX_NAMESPACE_LENGTH_5 },
|
||||
|
||||
// %00011011 small length
|
||||
{ 0x1B, ISTRING_SMALL_LENGTH },
|
||||
|
||||
// %00011100 small length
|
||||
{ 0x1C, ISTRING_PREFIX_NAMESPACE_LENGTH_29 },
|
||||
|
||||
// %00100010 small length
|
||||
{ 0x22, ISTRING_SMALL_LENGTH },
|
||||
|
||||
// %00100011 small length
|
||||
{ 0x23, ISTRING_PREFIX_NAMESPACE_LENGTH_36 },
|
||||
|
||||
// %00000101 to %00111111 small length
|
||||
{ 0x3F, ISTRING_SMALL_LENGTH },
|
||||
|
||||
|
||||
|
||||
|
||||
// %01000000 medium length
|
||||
{ 0x40, ISTRING_MEDIUM_LENGTH },
|
||||
|
||||
// %01000001 to %01011111 ILLEGAL
|
||||
{ 0x5F, STATE_ILLEGAL },
|
||||
|
||||
// %01100000 large length
|
||||
{ 0x60, ISTRING_LARGE_LENGTH },
|
||||
|
||||
// %01100001 to %01111111 ILLEGAL
|
||||
{ 0x7F, STATE_ILLEGAL },
|
||||
|
||||
// %10000000 index small, 0
|
||||
{ 0x80, ISTRING_PREFIX_NAMESPACE_INDEX_ZERO },
|
||||
|
||||
// %10000000 to %10111111 index small
|
||||
{ 0xBF, ISTRING_INDEX_SMALL },
|
||||
|
||||
// %11000000 to %11011111 index medium
|
||||
{ 0xDF, ISTRING_INDEX_MEDIUM },
|
||||
|
||||
// %11100000 to %11101111 index large
|
||||
{ 0xEF, ISTRING_INDEX_LARGE },
|
||||
|
||||
// %11110000 to %11111111 ILLEGAL
|
||||
{ 0xFF, STATE_ILLEGAL },
|
||||
};
|
||||
|
||||
// UTF-8 states
|
||||
/* package */ final static int UTF8_NCNAME_NCNAME = 0;
|
||||
/* package */ final static int UTF8_NCNAME_NCNAME_CHAR = 1;
|
||||
/* package */ final static int UTF8_TWO_BYTES = 2;
|
||||
/* package */ final static int UTF8_THREE_BYTES = 3;
|
||||
/* package */ final static int UTF8_FOUR_BYTES = 4;
|
||||
|
||||
private static final int[] UTF8_NCNAME = new int[256];
|
||||
|
||||
private static final int[][] UTF8_NCNAME_RANGES = {
|
||||
|
||||
// Basic Latin
|
||||
|
||||
// %00000000 to %00101100
|
||||
{ 0x2C, STATE_ILLEGAL },
|
||||
|
||||
// '-' '.'
|
||||
// %%00101101 to %00101110 [#x002D-#x002E]
|
||||
{ 0x2E, UTF8_NCNAME_NCNAME_CHAR },
|
||||
|
||||
// %00101111
|
||||
{ 0x2F, STATE_ILLEGAL },
|
||||
|
||||
// [0-9]
|
||||
// %0011000 to %00111001 [#x0030-#x0039]
|
||||
{ 0x39, UTF8_NCNAME_NCNAME_CHAR },
|
||||
|
||||
// %01000000
|
||||
{ 0x40, STATE_ILLEGAL },
|
||||
|
||||
// [A-Z]
|
||||
// %01000001 to %01011010 [#x0041-#x005A]
|
||||
{ 0x5A, UTF8_NCNAME_NCNAME },
|
||||
|
||||
// %01011110
|
||||
{ 0x5E, STATE_ILLEGAL },
|
||||
|
||||
// '_'
|
||||
// %01011111 [#x005F]
|
||||
{ 0x5F, UTF8_NCNAME_NCNAME },
|
||||
|
||||
// %01100000
|
||||
{ 0x60, STATE_ILLEGAL },
|
||||
|
||||
// [a-z]
|
||||
// %01100001 to %01111010 [#x0061-#x007A]
|
||||
{ 0x7A, UTF8_NCNAME_NCNAME },
|
||||
|
||||
// %01111011 to %01111111
|
||||
{ 0x7F, STATE_ILLEGAL },
|
||||
|
||||
|
||||
// Two bytes
|
||||
|
||||
// %10000000 to %11000001
|
||||
{ 0xC1, STATE_ILLEGAL },
|
||||
|
||||
// %11000010 to %11011111
|
||||
{ 0xDF, UTF8_TWO_BYTES },
|
||||
|
||||
|
||||
// Three bytes
|
||||
|
||||
// %11100000 to %11101111
|
||||
{ 0xEF, UTF8_THREE_BYTES },
|
||||
|
||||
|
||||
// Four bytes
|
||||
|
||||
// %11110000 to %11110111
|
||||
{ 0xF7, UTF8_FOUR_BYTES },
|
||||
|
||||
|
||||
// %11111000 to %11111111
|
||||
{ 0xFF, STATE_ILLEGAL }
|
||||
};
|
||||
|
||||
/* package */ final static int UTF8_ONE_BYTE = 1;
|
||||
|
||||
private static final int[] UTF8 = new int[256];
|
||||
|
||||
private static final int[][] UTF8_RANGES = {
|
||||
|
||||
// Basic Latin
|
||||
|
||||
// %00000000 to %00001000
|
||||
{ 0x08, STATE_ILLEGAL },
|
||||
|
||||
// CHARACTER TABULATION, LINE FEED
|
||||
// %%00001001 to %00001010 [#x0009-#x000A]
|
||||
{ 0x0A, UTF8_ONE_BYTE },
|
||||
|
||||
// %00001011 to %00001100
|
||||
{ 0x0C, STATE_ILLEGAL },
|
||||
|
||||
// CARRIAGE RETURN
|
||||
// %00001101 [#x000D]
|
||||
{ 0x0D, UTF8_ONE_BYTE },
|
||||
|
||||
// %00001110 to %00011111
|
||||
{ 0x1F, STATE_ILLEGAL },
|
||||
|
||||
// %0010000 to %01111111
|
||||
{ 0x7F, UTF8_ONE_BYTE },
|
||||
|
||||
|
||||
// Two bytes
|
||||
|
||||
// %10000000 to %11000001
|
||||
{ 0xC1, STATE_ILLEGAL },
|
||||
|
||||
// %11000010 to %11011111
|
||||
{ 0xDF, UTF8_TWO_BYTES },
|
||||
|
||||
|
||||
// Three bytes
|
||||
|
||||
// %11100000 to %11101111
|
||||
{ 0xEF, UTF8_THREE_BYTES },
|
||||
|
||||
|
||||
// Four bytes
|
||||
|
||||
// %11110000 to %11110111
|
||||
{ 0xF7, UTF8_FOUR_BYTES },
|
||||
|
||||
|
||||
// %11111000 to %11111111
|
||||
{ 0xFF, STATE_ILLEGAL }
|
||||
};
|
||||
|
||||
private static void constructTable(int[] table, int[][] ranges) {
|
||||
int start = 0x00;
|
||||
for (int range = 0; range < ranges.length; range++) {
|
||||
int end = ranges[range][RANGE_INDEX_END];
|
||||
int value = ranges[range][RANGE_INDEX_VALUE];
|
||||
for (int i = start; i<= end; i++) {
|
||||
table[i] = value;
|
||||
}
|
||||
start = end + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public static final int DII(final int index) {
|
||||
return DII[index];
|
||||
}
|
||||
|
||||
public static final int EII(final int index) {
|
||||
return EII[index];
|
||||
}
|
||||
|
||||
public static final int AII(final int index) {
|
||||
return AII[index];
|
||||
}
|
||||
|
||||
public static final int NISTRING(final int index) {
|
||||
return NISTRING[index];
|
||||
}
|
||||
|
||||
public static final int ISTRING(final int index) {
|
||||
return ISTRING[index];
|
||||
}
|
||||
|
||||
public static final int ISTRING_PREFIX_NAMESPACE(final int index) {
|
||||
return ISTRING_PREFIX_NAMESPACE[index];
|
||||
}
|
||||
|
||||
public static final int UTF8(final int index) {
|
||||
return UTF8[index];
|
||||
}
|
||||
|
||||
public static final int UTF8_NCNAME(final int index) {
|
||||
return UTF8_NCNAME[index];
|
||||
}
|
||||
|
||||
static {
|
||||
// DII
|
||||
constructTable(DII, DII_RANGES);
|
||||
|
||||
// EII
|
||||
constructTable(EII, EII_RANGES);
|
||||
|
||||
// AII
|
||||
constructTable(AII, AII_RANGES);
|
||||
|
||||
// AII Value
|
||||
constructTable(NISTRING, NISTRING_RANGES);
|
||||
|
||||
// Identifying string
|
||||
constructTable(ISTRING, ISTRING_RANGES);
|
||||
|
||||
// Identifying string
|
||||
constructTable(ISTRING_PREFIX_NAMESPACE, ISTRING_PREFIX_NAMESPACE_RANGES);
|
||||
|
||||
// UTF-8 NCNAME states
|
||||
constructTable(UTF8_NCNAME, UTF8_NCNAME_RANGES);
|
||||
|
||||
// UTF-8 states
|
||||
constructTable(UTF8, UTF8_RANGES);
|
||||
}
|
||||
|
||||
private DecoderStateTables() {
|
||||
}
|
||||
}
|
||||
2594
jdkSrc/jdk8/com/sun/xml/internal/fastinfoset/Encoder.java
Normal file
2594
jdkSrc/jdk8/com/sun/xml/internal/fastinfoset/Encoder.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public final class EncodingConstants {
|
||||
static {
|
||||
initiateXMLDeclarationValues();
|
||||
}
|
||||
|
||||
public static final String XML_NAMESPACE_PREFIX = "xml";
|
||||
public static final int XML_NAMESPACE_PREFIX_LENGTH = XML_NAMESPACE_PREFIX.length();
|
||||
public static final String XML_NAMESPACE_NAME = "http://www.w3.org/XML/1998/namespace";
|
||||
public static final int XML_NAMESPACE_NAME_LENGTH = XML_NAMESPACE_NAME.length();
|
||||
|
||||
public static final String XMLNS_NAMESPACE_PREFIX = "xmlns";
|
||||
public static final int XMLNS_NAMESPACE_PREFIX_LENGTH = XMLNS_NAMESPACE_PREFIX.length();
|
||||
public static final String XMLNS_NAMESPACE_NAME = "http://www.w3.org/2000/xmlns/";
|
||||
public static final int XMLNS_NAMESPACE_NAME_LENGTH = XMLNS_NAMESPACE_NAME.length();
|
||||
|
||||
public static final QualifiedName DEFAULT_NAMESPACE_DECLARATION = new QualifiedName(
|
||||
"",
|
||||
EncodingConstants.XMLNS_NAMESPACE_NAME,
|
||||
EncodingConstants.XMLNS_NAMESPACE_PREFIX,
|
||||
EncodingConstants.XMLNS_NAMESPACE_PREFIX);
|
||||
|
||||
public static final int DOCUMENT_ADDITIONAL_DATA_FLAG = 0x40; // 01000000
|
||||
public static final int DOCUMENT_INITIAL_VOCABULARY_FLAG = 0x20; // 00100000
|
||||
public static final int DOCUMENT_NOTATIONS_FLAG = 0x10; // 00010000
|
||||
public static final int DOCUMENT_UNPARSED_ENTITIES_FLAG = 0x08; // 00001000
|
||||
public static final int DOCUMENT_CHARACTER_ENCODING_SCHEME = 0x04; // 00000100
|
||||
public static final int DOCUMENT_STANDALONE_FLAG = 0x02; // 00000010
|
||||
public static final int DOCUMENT_VERSION_FLAG = 0x01; // 00000001
|
||||
|
||||
public static final int INITIAL_VOCABULARY_EXTERNAL_VOCABULARY_FLAG = 0x10; // 00010000
|
||||
public static final int INITIAL_VOCABULARY_RESTRICTED_ALPHABETS_FLAG = 0x08; // 00001000
|
||||
public static final int INITIAL_VOCABULARY_ENCODING_ALGORITHMS_FLAG = 0x04; // 00000100
|
||||
public static final int INITIAL_VOCABULARY_PREFIXES_FLAG = 0x02; // 00000010
|
||||
public static final int INITIAL_VOCABULARY_NAMESPACE_NAMES_FLAG = 0x01; // 00000001
|
||||
public static final int INITIAL_VOCABULARY_LOCAL_NAMES_FLAG = 0x80; // 1000000
|
||||
public static final int INITIAL_VOCABULARY_OTHER_NCNAMES_FLAG = 0x40; // 01000000
|
||||
public static final int INITIAL_VOCABULARY_OTHER_URIS_FLAG = 0x20; // 00100000
|
||||
public static final int INITIAL_VOCABULARY_ATTRIBUTE_VALUES_FLAG = 0x10; // 00010000
|
||||
public static final int INITIAL_VOCABULARY_CONTENT_CHARACTER_CHUNKS_FLAG = 0x08; // 00001000
|
||||
public static final int INITIAL_VOCABULARY_OTHER_STRINGS_FLAG = 0x04; // 00000100
|
||||
public static final int INITIAL_VOCABULARY_ELEMENT_NAME_SURROGATES_FLAG = 0x02; // 0000010
|
||||
public static final int INITIAL_VOCABULARY_ATTRIBUTE_NAME_SURROGATES_FLAG = 0x01; // 00000001
|
||||
|
||||
public static final int NAME_SURROGATE_PREFIX_FLAG = 0x02;
|
||||
public static final int NAME_SURROGATE_NAME_FLAG = 0x01;
|
||||
|
||||
public static final int NOTATIONS = 0xC0; // 110000
|
||||
public static final int NOTATIONS_MASK = 0xFC; // 6 bits
|
||||
public static final int NOTATIONS_SYSTEM_IDENTIFIER_FLAG = 0x02;
|
||||
public static final int NOTATIONS_PUBLIC_IDENTIFIER_FLAG = 0x01;
|
||||
|
||||
public static final int UNPARSED_ENTITIES = 0xD0; // 1101000
|
||||
public static final int UNPARSED_ENTITIES_MASK = 0xFE; // 7 bits
|
||||
public static final int UNPARSED_ENTITIES_PUBLIC_IDENTIFIER_FLAG = 0x01;
|
||||
|
||||
public static final int PROCESSING_INSTRUCTION = 0xE1; // 11100001
|
||||
public static final int PROCESSING_INSTRUCTION_MASK = 0xFF; // 8 bits
|
||||
|
||||
public static final int COMMENT = 0xE2; // 11100010
|
||||
public static final int COMMENT_MASK = 0xFF; // 8 bits
|
||||
|
||||
public static final int DOCUMENT_TYPE_DECLARATION = 0xC4; // 110001
|
||||
public static final int DOCUMENT_TYPE_DECLARATION_MASK = 0xFC; // 6 bits
|
||||
public static final int DOCUMENT_TYPE_SYSTEM_IDENTIFIER_FLAG = 0x02;
|
||||
public static final int DOCUMENT_TYPE_PUBLIC_IDENTIFIER_FLAG = 0x01;
|
||||
|
||||
public static final int ELEMENT = 0x00; // 0
|
||||
public static final int ELEMENT_ATTRIBUTE_FLAG = 0x40; // 01000000
|
||||
public static final int ELEMENT_NAMESPACES_FLAG = 0x38; // 00111000
|
||||
public static final int ELEMENT_LITERAL_QNAME_FLAG = 0x3C; // 00111100
|
||||
|
||||
public static final int NAMESPACE_ATTRIBUTE = 0xCC; // 110011 00
|
||||
public static final int NAMESPACE_ATTRIBUTE_MASK = 0xFC; // 6 bits
|
||||
public static final int NAMESPACE_ATTRIBUTE_PREFIX_NAME_MASK = 0x03; // 2 bits
|
||||
public static final int NAMESPACE_ATTRIBUTE_PREFIX_FLAG = 0x02;
|
||||
public static final int NAMESPACE_ATTRIBUTE_NAME_FLAG = 0x01;
|
||||
|
||||
public static final int ATTRIBUTE_LITERAL_QNAME_FLAG = 0x78; // 01111000
|
||||
|
||||
public static final int LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK = 0x03;
|
||||
public static final int LITERAL_QNAME_PREFIX_FLAG = 0x02;
|
||||
public static final int LITERAL_QNAME_NAMESPACE_NAME_FLAG = 0x01;
|
||||
|
||||
public static final int CHARACTER_CHUNK = 0x80; // 10
|
||||
public static final int CHARACTER_CHUNK_ADD_TO_TABLE_FLAG = 0x10; // 00010000
|
||||
public static final int CHARACTER_CHUNK_UTF_8_FLAG = 0x00; // 00000000
|
||||
public static final int CHARACTER_CHUNK_UTF_16_FLAG = 0x04; // 00000100
|
||||
public static final int CHARACTER_CHUNK_RESTRICTED_ALPHABET_FLAG = 0x08; // 00001000
|
||||
public static final int CHARACTER_CHUNK_ENCODING_ALGORITHM_FLAG = 0x0C; // 00001100
|
||||
|
||||
public static final int UNEXPANDED_ENTITY_REFERENCE = 0xC8; // 110010
|
||||
public static final int UNEXPANDED_ENTITY_REFERENCE_MASK = 0xFC; // 6 bits
|
||||
public static final int UNEXPANDED_ENTITY_SYSTEM_IDENTIFIER_FLAG = 0x02;
|
||||
public static final int UNEXPANDED_ENTITY_PUBLIC_IDENTIFIER_FLAG = 0x01;
|
||||
|
||||
public static final int NISTRING_ADD_TO_TABLE_FLAG = 0x40; // 01000000
|
||||
public static final int NISTRING_UTF_8_FLAG = 0x00; // 00000000
|
||||
public static final int NISTRING_UTF_16_FLAG = 0x10; // 00010000
|
||||
public static final int NISTRING_RESTRICTED_ALPHABET_FLAG = 0x20; // 00100000
|
||||
public static final int NISTRING_ENCODING_ALGORITHM_FLAG = 0x30; // 00110000
|
||||
|
||||
public static final int TERMINATOR = 0xF0;
|
||||
public static final int DOUBLE_TERMINATOR = 0xFF;
|
||||
|
||||
|
||||
public static final int ENCODING_ALGORITHM_BUILTIN_END = 9;
|
||||
public static final int ENCODING_ALGORITHM_APPLICATION_START = 32;
|
||||
public static final int ENCODING_ALGORITHM_APPLICATION_MAX = 255;
|
||||
|
||||
public static final int RESTRICTED_ALPHABET_BUILTIN_END = 1;
|
||||
public static final int RESTRICTED_ALPHABET_APPLICATION_START = 32;
|
||||
public static final int RESTRICTED_ALPHABET_APPLICATION_MAX = 255;
|
||||
|
||||
// Octet string length contants
|
||||
|
||||
public static final int OCTET_STRING_LENGTH_SMALL_LIMIT = 0;
|
||||
public static final int OCTET_STRING_LENGTH_MEDIUM_LIMIT = 1;
|
||||
public static final int OCTET_STRING_LENGTH_MEDIUM_FLAG = 2;
|
||||
public static final int OCTET_STRING_LENGTH_LARGE_FLAG = 3;
|
||||
|
||||
public static final long OCTET_STRING_MAXIMUM_LENGTH = 4294967296L;
|
||||
|
||||
/*
|
||||
* C.22
|
||||
*/
|
||||
public static final int OCTET_STRING_LENGTH_2ND_BIT_SMALL_LIMIT = 65;
|
||||
public static final int OCTET_STRING_LENGTH_2ND_BIT_MEDIUM_LIMIT = 321;
|
||||
public static final int OCTET_STRING_LENGTH_2ND_BIT_MEDIUM_FLAG = 0x40;
|
||||
public static final int OCTET_STRING_LENGTH_2ND_BIT_LARGE_FLAG = 0x60;
|
||||
public static final int OCTET_STRING_LENGTH_2ND_BIT_SMALL_MASK = 0x1F;
|
||||
|
||||
/* package */ static final int[] OCTET_STRING_LENGTH_2ND_BIT_VALUES = {
|
||||
OCTET_STRING_LENGTH_2ND_BIT_SMALL_LIMIT,
|
||||
OCTET_STRING_LENGTH_2ND_BIT_MEDIUM_LIMIT,
|
||||
OCTET_STRING_LENGTH_2ND_BIT_MEDIUM_FLAG,
|
||||
OCTET_STRING_LENGTH_2ND_BIT_LARGE_FLAG
|
||||
};
|
||||
|
||||
/*
|
||||
* C.23
|
||||
*/
|
||||
public static final int OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT = 9;
|
||||
public static final int OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT = 265;
|
||||
public static final int OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_FLAG = 0x08;
|
||||
public static final int OCTET_STRING_LENGTH_5TH_BIT_LARGE_FLAG = 0x0C;
|
||||
public static final int OCTET_STRING_LENGTH_5TH_BIT_SMALL_MASK = 0x07;
|
||||
|
||||
/* package */ static final int[] OCTET_STRING_LENGTH_5TH_BIT_VALUES = {
|
||||
OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT,
|
||||
OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT,
|
||||
OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_FLAG,
|
||||
OCTET_STRING_LENGTH_5TH_BIT_LARGE_FLAG
|
||||
};
|
||||
|
||||
/*
|
||||
* C.24
|
||||
*/
|
||||
public static final int OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT = 3;
|
||||
public static final int OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT = 259;
|
||||
public static final int OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_FLAG = 0x02;
|
||||
public static final int OCTET_STRING_LENGTH_7TH_BIT_LARGE_FLAG = 0x03;
|
||||
public static final int OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK = 0x01;
|
||||
|
||||
/* package */ static final int[] OCTET_STRING_LENGTH_7TH_BIT_VALUES = {
|
||||
OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT,
|
||||
OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT,
|
||||
OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_FLAG,
|
||||
OCTET_STRING_LENGTH_7TH_BIT_LARGE_FLAG
|
||||
};
|
||||
|
||||
|
||||
// Integer
|
||||
|
||||
public static final int INTEGER_SMALL_LIMIT = 0;
|
||||
public static final int INTEGER_MEDIUM_LIMIT = 1;
|
||||
public static final int INTEGER_LARGE_LIMIT = 2;
|
||||
public static final int INTEGER_MEDIUM_FLAG = 3;
|
||||
public static final int INTEGER_LARGE_FLAG = 4;
|
||||
public static final int INTEGER_LARGE_LARGE_FLAG = 5;
|
||||
|
||||
public static final int INTEGER_MAXIMUM_SIZE = 1048576;
|
||||
|
||||
/*
|
||||
* C.25
|
||||
*/
|
||||
public static final int INTEGER_2ND_BIT_SMALL_LIMIT = 64;
|
||||
public static final int INTEGER_2ND_BIT_MEDIUM_LIMIT = 8256;
|
||||
public static final int INTEGER_2ND_BIT_LARGE_LIMIT = INTEGER_MAXIMUM_SIZE;
|
||||
public static final int INTEGER_2ND_BIT_MEDIUM_FLAG = 0x40;
|
||||
public static final int INTEGER_2ND_BIT_LARGE_FLAG = 0x60;
|
||||
public static final int INTEGER_2ND_BIT_SMALL_MASK = 0x3F;
|
||||
public static final int INTEGER_2ND_BIT_MEDIUM_MASK = 0x1F;
|
||||
public static final int INTEGER_2ND_BIT_LARGE_MASK = 0x0F;
|
||||
|
||||
/* package */ static final int[] INTEGER_2ND_BIT_VALUES = {
|
||||
INTEGER_2ND_BIT_SMALL_LIMIT,
|
||||
INTEGER_2ND_BIT_MEDIUM_LIMIT,
|
||||
INTEGER_2ND_BIT_LARGE_LIMIT,
|
||||
INTEGER_2ND_BIT_MEDIUM_FLAG,
|
||||
INTEGER_2ND_BIT_LARGE_FLAG,
|
||||
-1
|
||||
};
|
||||
|
||||
/*
|
||||
* C.27
|
||||
*/
|
||||
public static final int INTEGER_3RD_BIT_SMALL_LIMIT = 32;
|
||||
public static final int INTEGER_3RD_BIT_MEDIUM_LIMIT = 2080;
|
||||
public static final int INTEGER_3RD_BIT_LARGE_LIMIT = 526368;
|
||||
public static final int INTEGER_3RD_BIT_MEDIUM_FLAG = 0x20;
|
||||
public static final int INTEGER_3RD_BIT_LARGE_FLAG = 0x28;
|
||||
public static final int INTEGER_3RD_BIT_LARGE_LARGE_FLAG = 0x30;
|
||||
public static final int INTEGER_3RD_BIT_SMALL_MASK = 0x1F;
|
||||
public static final int INTEGER_3RD_BIT_MEDIUM_MASK = 0x07;
|
||||
public static final int INTEGER_3RD_BIT_LARGE_MASK = 0x07;
|
||||
public static final int INTEGER_3RD_BIT_LARGE_LARGE_MASK = 0x0F;
|
||||
|
||||
/* package */ static final int[] INTEGER_3RD_BIT_VALUES = {
|
||||
INTEGER_3RD_BIT_SMALL_LIMIT,
|
||||
INTEGER_3RD_BIT_MEDIUM_LIMIT,
|
||||
INTEGER_3RD_BIT_LARGE_LIMIT,
|
||||
INTEGER_3RD_BIT_MEDIUM_FLAG,
|
||||
INTEGER_3RD_BIT_LARGE_FLAG,
|
||||
INTEGER_3RD_BIT_LARGE_LARGE_FLAG
|
||||
};
|
||||
|
||||
/*
|
||||
* C.28
|
||||
*/
|
||||
public static final int INTEGER_4TH_BIT_SMALL_LIMIT = 16;
|
||||
public static final int INTEGER_4TH_BIT_MEDIUM_LIMIT = 1040;
|
||||
public static final int INTEGER_4TH_BIT_LARGE_LIMIT = 263184;
|
||||
public static final int INTEGER_4TH_BIT_MEDIUM_FLAG = 0x10;
|
||||
public static final int INTEGER_4TH_BIT_LARGE_FLAG = 0x14;
|
||||
public static final int INTEGER_4TH_BIT_LARGE_LARGE_FLAG = 0x18;
|
||||
public static final int INTEGER_4TH_BIT_SMALL_MASK = 0x0F;
|
||||
public static final int INTEGER_4TH_BIT_MEDIUM_MASK = 0x03;
|
||||
public static final int INTEGER_4TH_BIT_LARGE_MASK = 0x03;
|
||||
|
||||
/* package */ static final int[] INTEGER_4TH_BIT_VALUES = {
|
||||
INTEGER_4TH_BIT_SMALL_LIMIT,
|
||||
INTEGER_4TH_BIT_MEDIUM_LIMIT,
|
||||
INTEGER_4TH_BIT_LARGE_LIMIT,
|
||||
INTEGER_4TH_BIT_MEDIUM_FLAG,
|
||||
INTEGER_4TH_BIT_LARGE_FLAG,
|
||||
INTEGER_4TH_BIT_LARGE_LARGE_FLAG
|
||||
};
|
||||
|
||||
/* package */ static final byte[] BINARY_HEADER = {(byte)0xE0, 0, 0, 1};
|
||||
|
||||
/* package */ static byte[][] XML_DECLARATION_VALUES;
|
||||
|
||||
private static void initiateXMLDeclarationValues() {
|
||||
|
||||
XML_DECLARATION_VALUES = new byte[9][];
|
||||
|
||||
try {
|
||||
XML_DECLARATION_VALUES[0] = "<?xml encoding='finf'?>".getBytes("UTF-8");
|
||||
XML_DECLARATION_VALUES[1] = "<?xml version='1.0' encoding='finf'?>".getBytes("UTF-8");
|
||||
XML_DECLARATION_VALUES[2] = "<?xml version='1.1' encoding='finf'?>".getBytes("UTF-8");
|
||||
XML_DECLARATION_VALUES[3] = "<?xml encoding='finf' standalone='no'?>".getBytes("UTF-8");
|
||||
XML_DECLARATION_VALUES[4] = "<?xml encoding='finf' standalone='yes'?>".getBytes("UTF-8");
|
||||
XML_DECLARATION_VALUES[5] = "<?xml version='1.0' encoding='finf' standalone='no'?>".getBytes("UTF-8");
|
||||
XML_DECLARATION_VALUES[6] = "<?xml version='1.1' encoding='finf' standalone='no'?>".getBytes("UTF-8");
|
||||
XML_DECLARATION_VALUES[7] = "<?xml version='1.0' encoding='finf' standalone='yes'?>".getBytes("UTF-8");
|
||||
XML_DECLARATION_VALUES[8] = "<?xml version='1.1' encoding='finf' standalone='yes'?>".getBytes("UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
42
jdkSrc/jdk8/com/sun/xml/internal/fastinfoset/Notation.java
Normal file
42
jdkSrc/jdk8/com/sun/xml/internal/fastinfoset/Notation.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class Notation {
|
||||
public final String name;
|
||||
public final String systemIdentifier;
|
||||
public final String publicIdentifier;
|
||||
|
||||
/** Creates a new instance of Notation */
|
||||
public Notation(String _name, String _systemIdentifier, String _publicIdentifier) {
|
||||
name = _name;
|
||||
systemIdentifier = _systemIdentifier;
|
||||
publicIdentifier = _publicIdentifier;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Paul Sandoz
|
||||
* @author Alexey Stashok
|
||||
*/
|
||||
public interface OctetBufferListener {
|
||||
/**
|
||||
* Callback method that will be called before the
|
||||
* (@link Decoder) octet buffer content is going to be changed.
|
||||
* So it will be possible to preserve a read data by
|
||||
* cloning, or perform other actions.
|
||||
*/
|
||||
public void onBeforeOctetBufferOverwrite();
|
||||
}
|
||||
310
jdkSrc/jdk8/com/sun/xml/internal/fastinfoset/QualifiedName.java
Normal file
310
jdkSrc/jdk8/com/sun/xml/internal/fastinfoset/QualifiedName.java
Normal file
@@ -0,0 +1,310 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
public class QualifiedName {
|
||||
public String prefix;
|
||||
public String namespaceName;
|
||||
public String localName;
|
||||
public String qName;
|
||||
public int index;
|
||||
public int prefixIndex;
|
||||
public int namespaceNameIndex;
|
||||
public int localNameIndex;
|
||||
public int attributeId;
|
||||
public int attributeHash;
|
||||
private QName qNameObject;
|
||||
|
||||
public QualifiedName() { }
|
||||
|
||||
public QualifiedName(String prefix, String namespaceName, String localName, String qName) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = localName;
|
||||
this.qName = qName;
|
||||
this.index = -1;
|
||||
this.prefixIndex = 0;
|
||||
this.namespaceNameIndex = 0;
|
||||
this.localNameIndex = -1;
|
||||
}
|
||||
|
||||
public void set(String prefix, String namespaceName, String localName, String qName) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = localName;
|
||||
this.qName = qName;
|
||||
this.index = -1;
|
||||
this.prefixIndex = 0;
|
||||
this.namespaceNameIndex = 0;
|
||||
this.localNameIndex = -1;
|
||||
this.qNameObject = null;
|
||||
}
|
||||
|
||||
public QualifiedName(String prefix, String namespaceName, String localName, String qName, int index) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = localName;
|
||||
this.qName = qName;
|
||||
this.index = index;
|
||||
this.prefixIndex = 0;
|
||||
this.namespaceNameIndex = 0;
|
||||
this.localNameIndex = -1;
|
||||
}
|
||||
|
||||
public final QualifiedName set(String prefix, String namespaceName, String localName, String qName, int index) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = localName;
|
||||
this.qName = qName;
|
||||
this.index = index;
|
||||
this.prefixIndex = 0;
|
||||
this.namespaceNameIndex = 0;
|
||||
this.localNameIndex = -1;
|
||||
this.qNameObject = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public QualifiedName(String prefix, String namespaceName, String localName, String qName, int index,
|
||||
int prefixIndex, int namespaceNameIndex, int localNameIndex) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = localName;
|
||||
this.qName = qName;
|
||||
this.index = index;
|
||||
this.prefixIndex = prefixIndex + 1;
|
||||
this.namespaceNameIndex = namespaceNameIndex + 1;
|
||||
this.localNameIndex = localNameIndex;
|
||||
}
|
||||
|
||||
public final QualifiedName set(String prefix, String namespaceName, String localName, String qName, int index,
|
||||
int prefixIndex, int namespaceNameIndex, int localNameIndex) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = localName;
|
||||
this.qName = qName;
|
||||
this.index = index;
|
||||
this.prefixIndex = prefixIndex + 1;
|
||||
this.namespaceNameIndex = namespaceNameIndex + 1;
|
||||
this.localNameIndex = localNameIndex;
|
||||
this.qNameObject = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public QualifiedName(String prefix, String namespaceName, String localName) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = localName;
|
||||
this.qName = createQNameString(prefix, localName);
|
||||
this.index = -1;
|
||||
this.prefixIndex = 0;
|
||||
this.namespaceNameIndex = 0;
|
||||
this.localNameIndex = -1;
|
||||
}
|
||||
|
||||
public final QualifiedName set(String prefix, String namespaceName, String localName) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = localName;
|
||||
this.qName = createQNameString(prefix, localName);
|
||||
this.index = -1;
|
||||
this.prefixIndex = 0;
|
||||
this.namespaceNameIndex = 0;
|
||||
this.localNameIndex = -1;
|
||||
this.qNameObject = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public QualifiedName(String prefix, String namespaceName, String localName,
|
||||
int prefixIndex, int namespaceNameIndex, int localNameIndex,
|
||||
char[] charBuffer) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = localName;
|
||||
|
||||
if (charBuffer != null) {
|
||||
final int l1 = prefix.length();
|
||||
final int l2 = localName.length();
|
||||
final int total = l1 + l2 + 1;
|
||||
if (total < charBuffer.length) {
|
||||
prefix.getChars(0, l1, charBuffer, 0);
|
||||
charBuffer[l1] = ':';
|
||||
localName.getChars(0, l2, charBuffer, l1 + 1);
|
||||
this.qName = new String(charBuffer, 0, total);
|
||||
} else {
|
||||
this.qName = createQNameString(prefix, localName);
|
||||
}
|
||||
} else {
|
||||
this.qName = this.localName;
|
||||
}
|
||||
|
||||
this.prefixIndex = prefixIndex + 1;
|
||||
this.namespaceNameIndex = namespaceNameIndex + 1;
|
||||
this.localNameIndex = localNameIndex;
|
||||
this.index = -1;
|
||||
}
|
||||
|
||||
public final QualifiedName set(String prefix, String namespaceName, String localName,
|
||||
int prefixIndex, int namespaceNameIndex, int localNameIndex,
|
||||
char[] charBuffer) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = localName;
|
||||
|
||||
if (charBuffer != null) {
|
||||
final int l1 = prefix.length();
|
||||
final int l2 = localName.length();
|
||||
final int total = l1 + l2 + 1;
|
||||
if (total < charBuffer.length) {
|
||||
prefix.getChars(0, l1, charBuffer, 0);
|
||||
charBuffer[l1] = ':';
|
||||
localName.getChars(0, l2, charBuffer, l1 + 1);
|
||||
this.qName = new String(charBuffer, 0, total);
|
||||
} else {
|
||||
this.qName = createQNameString(prefix, localName);
|
||||
}
|
||||
} else {
|
||||
this.qName = this.localName;
|
||||
}
|
||||
|
||||
this.prefixIndex = prefixIndex + 1;
|
||||
this.namespaceNameIndex = namespaceNameIndex + 1;
|
||||
this.localNameIndex = localNameIndex;
|
||||
this.index = -1;
|
||||
this.qNameObject = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public QualifiedName(String prefix, String namespaceName, String localName, int index) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = localName;
|
||||
this.qName = createQNameString(prefix, localName);
|
||||
this.index = index;
|
||||
this.prefixIndex = 0;
|
||||
this.namespaceNameIndex = 0;
|
||||
this.localNameIndex = -1;
|
||||
}
|
||||
|
||||
public final QualifiedName set(String prefix, String namespaceName, String localName, int index) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = localName;
|
||||
this.qName = createQNameString(prefix, localName);
|
||||
this.index = index;
|
||||
this.prefixIndex = 0;
|
||||
this.namespaceNameIndex = 0;
|
||||
this.localNameIndex = -1;
|
||||
this.qNameObject = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public QualifiedName(String prefix, String namespaceName, String localName, int index,
|
||||
int prefixIndex, int namespaceNameIndex, int localNameIndex) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = localName;
|
||||
this.qName = createQNameString(prefix, localName);
|
||||
this.index = index;
|
||||
this.prefixIndex = prefixIndex + 1;
|
||||
this.namespaceNameIndex = namespaceNameIndex + 1;
|
||||
this.localNameIndex = localNameIndex;
|
||||
}
|
||||
|
||||
public final QualifiedName set(String prefix, String namespaceName, String localName, int index,
|
||||
int prefixIndex, int namespaceNameIndex, int localNameIndex) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = localName;
|
||||
this.qName = createQNameString(prefix, localName);
|
||||
this.index = index;
|
||||
this.prefixIndex = prefixIndex + 1;
|
||||
this.namespaceNameIndex = namespaceNameIndex + 1;
|
||||
this.localNameIndex = localNameIndex;
|
||||
this.qNameObject = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
// Qualified Name as a Namespace Name
|
||||
public QualifiedName(String prefix, String namespaceName) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = "";
|
||||
this.qName = "";
|
||||
this.index = -1;
|
||||
this.prefixIndex = 0;
|
||||
this.namespaceNameIndex = 0;
|
||||
this.localNameIndex = -1;
|
||||
}
|
||||
|
||||
public final QualifiedName set(String prefix, String namespaceName) {
|
||||
this.prefix = prefix;
|
||||
this.namespaceName = namespaceName;
|
||||
this.localName = "";
|
||||
this.qName = "";
|
||||
this.index = -1;
|
||||
this.prefixIndex = 0;
|
||||
this.namespaceNameIndex = 0;
|
||||
this.localNameIndex = -1;
|
||||
this.qNameObject = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public final QName getQName() {
|
||||
if (qNameObject == null) {
|
||||
qNameObject = new QName(namespaceName, localName, prefix);
|
||||
}
|
||||
|
||||
return qNameObject;
|
||||
}
|
||||
|
||||
public final String getQNameString() {
|
||||
if (this.qName != "") {
|
||||
return this.qName;
|
||||
}
|
||||
|
||||
return this.qName = createQNameString(prefix, localName);
|
||||
}
|
||||
|
||||
public final void createAttributeValues(int size) {
|
||||
attributeId = localNameIndex | (namespaceNameIndex << 20);
|
||||
attributeHash = localNameIndex % size;
|
||||
}
|
||||
|
||||
private final String createQNameString(String p, String l) {
|
||||
if (p != null && p.length() > 0) {
|
||||
final StringBuffer b = new StringBuffer(p);
|
||||
b.append(':');
|
||||
b.append(l);
|
||||
return b.toString();
|
||||
} else {
|
||||
return l;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class UnparsedEntity extends Notation {
|
||||
public final String notationName;
|
||||
|
||||
/** Creates a new instance of UnparsedEntityDeclaration */
|
||||
public UnparsedEntity(String _name, String _systemIdentifier, String _publicIdentifier, String _notationName) {
|
||||
super(_name, _systemIdentifier, _publicIdentifier);
|
||||
notationName = _notationName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2013, 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.algorithm;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class BASE64EncodingAlgorithm extends BuiltInEncodingAlgorithm {
|
||||
|
||||
/* package */ static final char encodeBase64[] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
|
||||
};
|
||||
|
||||
/* package */ static final int decodeBase64[] = {
|
||||
/*'+'*/ 62,
|
||||
-1, -1, -1,
|
||||
/*'/'*/ 63,
|
||||
/*'0'*/ 52,
|
||||
/*'1'*/ 53,
|
||||
/*'2'*/ 54,
|
||||
/*'3'*/ 55,
|
||||
/*'4'*/ 56,
|
||||
/*'5'*/ 57,
|
||||
/*'6'*/ 58,
|
||||
/*'7'*/ 59,
|
||||
/*'8'*/ 60,
|
||||
/*'9'*/ 61,
|
||||
-1, -1, -1, -1, -1, -1, -1,
|
||||
/*'A'*/ 0,
|
||||
/*'B'*/ 1,
|
||||
/*'C'*/ 2,
|
||||
/*'D'*/ 3,
|
||||
/*'E'*/ 4,
|
||||
/*'F'*/ 5,
|
||||
/*'G'*/ 6,
|
||||
/*'H'*/ 7,
|
||||
/*'I'*/ 8,
|
||||
/*'J'*/ 9,
|
||||
/*'K'*/ 10,
|
||||
/*'L'*/ 11,
|
||||
/*'M'*/ 12,
|
||||
/*'N'*/ 13,
|
||||
/*'O'*/ 14,
|
||||
/*'P'*/ 15,
|
||||
/*'Q'*/ 16,
|
||||
/*'R'*/ 17,
|
||||
/*'S'*/ 18,
|
||||
/*'T'*/ 19,
|
||||
/*'U'*/ 20,
|
||||
/*'V'*/ 21,
|
||||
/*'W'*/ 22,
|
||||
/*'X'*/ 23,
|
||||
/*'Y'*/ 24,
|
||||
/*'Z'*/ 25,
|
||||
-1, -1, -1, -1, -1, -1,
|
||||
/*'a'*/ 26,
|
||||
/*'b'*/ 27,
|
||||
/*'c'*/ 28,
|
||||
/*'d'*/ 29,
|
||||
/*'e'*/ 30,
|
||||
/*'f'*/ 31,
|
||||
/*'g'*/ 32,
|
||||
/*'h'*/ 33,
|
||||
/*'i'*/ 34,
|
||||
/*'j'*/ 35,
|
||||
/*'k'*/ 36,
|
||||
/*'l'*/ 37,
|
||||
/*'m'*/ 38,
|
||||
/*'n'*/ 39,
|
||||
/*'o'*/ 40,
|
||||
/*'p'*/ 41,
|
||||
/*'q'*/ 42,
|
||||
/*'r'*/ 43,
|
||||
/*'s'*/ 44,
|
||||
/*'t'*/ 45,
|
||||
/*'u'*/ 46,
|
||||
/*'v'*/ 47,
|
||||
/*'w'*/ 48,
|
||||
/*'x'*/ 49,
|
||||
/*'y'*/ 50,
|
||||
/*'z'*/ 51
|
||||
};
|
||||
|
||||
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
|
||||
final byte[] data = new byte[length];
|
||||
System.arraycopy(b, start, data, 0, length);
|
||||
return data;
|
||||
}
|
||||
|
||||
public final Object decodeFromInputStream(InputStream s) throws IOException {
|
||||
throw new UnsupportedOperationException(CommonResourceBundle.getInstance().getString("message.notImplemented"));
|
||||
}
|
||||
|
||||
|
||||
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
|
||||
if (!(data instanceof byte[])) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotByteArray"));
|
||||
}
|
||||
|
||||
s.write((byte[])data);
|
||||
}
|
||||
|
||||
public final Object convertFromCharacters(char[] ch, int start, int length) {
|
||||
if (length == 0) {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
StringBuilder encodedValue = removeWhitespace(ch, start, length);
|
||||
int encodedLength = encodedValue.length();
|
||||
if (encodedLength == 0) {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
int blockCount = encodedLength / 4;
|
||||
int partialBlockLength = 3;
|
||||
|
||||
if (encodedValue.charAt(encodedLength - 1) == '=') {
|
||||
--partialBlockLength;
|
||||
if (encodedValue.charAt(encodedLength - 2) == '=') {
|
||||
--partialBlockLength;
|
||||
}
|
||||
}
|
||||
|
||||
int valueLength = (blockCount - 1) * 3 + partialBlockLength;
|
||||
byte[] value = new byte[valueLength];
|
||||
|
||||
int idx = 0;
|
||||
int encodedIdx = 0;
|
||||
for (int i = 0; i < blockCount; ++i) {
|
||||
int x1 = decodeBase64[encodedValue.charAt(encodedIdx++) - '+'];
|
||||
int x2 = decodeBase64[encodedValue.charAt(encodedIdx++) - '+'];
|
||||
int x3 = decodeBase64[encodedValue.charAt(encodedIdx++) - '+'];
|
||||
int x4 = decodeBase64[encodedValue.charAt(encodedIdx++) - '+'];
|
||||
|
||||
value[idx++] = (byte) ((x1 << 2) | (x2 >> 4));
|
||||
if (idx < valueLength) {
|
||||
value[idx++] = (byte) (((x2 & 0x0f) << 4) | (x3 >> 2));
|
||||
}
|
||||
if (idx < valueLength) {
|
||||
value[idx++] = (byte) (((x3 & 0x03) << 6) | x4);
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public final void convertToCharacters(Object data, StringBuffer s) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
final byte[] value = (byte[]) data;
|
||||
|
||||
convertToCharacters(value, 0, value.length, s);
|
||||
}
|
||||
|
||||
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
|
||||
return octetLength;
|
||||
}
|
||||
|
||||
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
|
||||
return primitiveLength;
|
||||
}
|
||||
|
||||
public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
|
||||
System.arraycopy((byte[])array, astart, b, start, alength);
|
||||
}
|
||||
|
||||
public final void convertToCharacters(byte[] data, int offset, int length, StringBuffer s) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
final byte[] value = data;
|
||||
if (length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int partialBlockLength = length % 3;
|
||||
final int blockCount = (partialBlockLength != 0) ?
|
||||
length / 3 + 1 :
|
||||
length / 3;
|
||||
|
||||
final int encodedLength = blockCount * 4;
|
||||
final int originalBufferSize = s.length();
|
||||
s.ensureCapacity(encodedLength + originalBufferSize);
|
||||
|
||||
int idx = offset;
|
||||
int lastIdx = offset + length;
|
||||
for (int i = 0; i < blockCount; ++i) {
|
||||
int b1 = value[idx++] & 0xFF;
|
||||
int b2 = (idx < lastIdx) ? value[idx++] & 0xFF : 0;
|
||||
int b3 = (idx < lastIdx) ? value[idx++] & 0xFF : 0;
|
||||
|
||||
s.append(encodeBase64[b1 >> 2]);
|
||||
|
||||
s.append(encodeBase64[((b1 & 0x03) << 4) | (b2 >> 4)]);
|
||||
|
||||
s.append(encodeBase64[((b2 & 0x0f) << 2) | (b3 >> 6)]);
|
||||
|
||||
s.append(encodeBase64[b3 & 0x3f]);
|
||||
}
|
||||
|
||||
switch (partialBlockLength) {
|
||||
case 1 :
|
||||
s.setCharAt(originalBufferSize + encodedLength - 1, '=');
|
||||
s.setCharAt(originalBufferSize + encodedLength - 2, '=');
|
||||
break;
|
||||
case 2 :
|
||||
s.setCharAt(originalBufferSize + encodedLength - 1, '=');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2013, 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.algorithm;
|
||||
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.CharBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* An encoder for handling boolean values. Suppports the builtin BOOLEAN encoder.
|
||||
*
|
||||
* @author Alan Hudson
|
||||
* @author Paul Sandoz
|
||||
*
|
||||
*/
|
||||
public class BooleanEncodingAlgorithm extends BuiltInEncodingAlgorithm {
|
||||
|
||||
/** Table for setting a particular bit of a byte */
|
||||
private static final int[] BIT_TABLE = {
|
||||
1 << 7,
|
||||
1 << 6,
|
||||
1 << 5,
|
||||
1 << 4,
|
||||
1 << 3,
|
||||
1 << 2,
|
||||
1 << 1,
|
||||
1 << 0};
|
||||
|
||||
public int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
|
||||
// Cannot determine the number of boolean values from just the octet length
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
|
||||
if (primitiveLength < 5) {
|
||||
return 1;
|
||||
} else {
|
||||
final int div = primitiveLength / 8;
|
||||
return (div == 0) ? 2 : 1 + div;
|
||||
}
|
||||
}
|
||||
|
||||
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
|
||||
final int blength = getPrimtiveLengthFromOctetLength(length, b[start]);
|
||||
boolean[] data = new boolean[blength];
|
||||
|
||||
decodeFromBytesToBooleanArray(data, 0, blength, b, start, length);
|
||||
return data;
|
||||
}
|
||||
|
||||
public final Object decodeFromInputStream(InputStream s) throws IOException {
|
||||
final List booleanList = new ArrayList();
|
||||
|
||||
int value = s.read();
|
||||
if (value == -1) {
|
||||
throw new EOFException();
|
||||
}
|
||||
final int unusedBits = (value >> 4) & 0xFF;
|
||||
|
||||
int bitPosition = 4;
|
||||
int bitPositionEnd = 8;
|
||||
int valueNext = 0;
|
||||
do {
|
||||
valueNext = s.read();
|
||||
if (valueNext == -1) {
|
||||
bitPositionEnd -= unusedBits;
|
||||
}
|
||||
|
||||
while(bitPosition < bitPositionEnd) {
|
||||
booleanList.add(
|
||||
Boolean.valueOf((value & BIT_TABLE[bitPosition++]) > 0));
|
||||
}
|
||||
|
||||
value = valueNext;
|
||||
} while (value != -1);
|
||||
|
||||
return generateArrayFromList(booleanList);
|
||||
}
|
||||
|
||||
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
|
||||
if (!(data instanceof boolean[])) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotBoolean"));
|
||||
}
|
||||
|
||||
boolean array[] = (boolean[])data;
|
||||
final int alength = array.length;
|
||||
|
||||
final int mod = (alength + 4) % 8;
|
||||
final int unusedBits = (mod == 0) ? 0 : 8 - mod;
|
||||
|
||||
int bitPosition = 4;
|
||||
int value = unusedBits << 4;
|
||||
int astart = 0;
|
||||
while (astart < alength) {
|
||||
if (array[astart++]) {
|
||||
value |= BIT_TABLE[bitPosition];
|
||||
}
|
||||
|
||||
if (++bitPosition == 8) {
|
||||
s.write(value);
|
||||
bitPosition = value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (bitPosition != 8) {
|
||||
s.write(value);
|
||||
}
|
||||
}
|
||||
|
||||
public final Object convertFromCharacters(char[] ch, int start, int length) {
|
||||
if (length == 0) {
|
||||
return new boolean[0];
|
||||
}
|
||||
|
||||
final CharBuffer cb = CharBuffer.wrap(ch, start, length);
|
||||
final List booleanList = new ArrayList();
|
||||
|
||||
matchWhiteSpaceDelimnatedWords(cb,
|
||||
new WordListener() {
|
||||
public void word(int start, int end) {
|
||||
if (cb.charAt(start) == 't') {
|
||||
booleanList.add(Boolean.TRUE);
|
||||
} else {
|
||||
booleanList.add(Boolean.FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return generateArrayFromList(booleanList);
|
||||
}
|
||||
|
||||
public final void convertToCharacters(Object data, StringBuffer s) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean[] value = (boolean[]) data;
|
||||
if (value.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Insure conservately as all false
|
||||
s.ensureCapacity(value.length * 5);
|
||||
|
||||
final int end = value.length - 1;
|
||||
for (int i = 0; i <= end; i++) {
|
||||
if (value[i]) {
|
||||
s.append("true");
|
||||
} else {
|
||||
s.append("false");
|
||||
}
|
||||
if (i != end) {
|
||||
s.append(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getPrimtiveLengthFromOctetLength(int octetLength, int firstOctet) throws EncodingAlgorithmException {
|
||||
final int unusedBits = (firstOctet >> 4) & 0xFF;
|
||||
if (octetLength == 1) {
|
||||
if (unusedBits > 3) {
|
||||
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.unusedBits4"));
|
||||
}
|
||||
return 4 - unusedBits;
|
||||
} else {
|
||||
if (unusedBits > 7) {
|
||||
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.unusedBits8"));
|
||||
}
|
||||
return octetLength * 8 - 4 - unusedBits;
|
||||
}
|
||||
}
|
||||
|
||||
public final void decodeFromBytesToBooleanArray(boolean[] bdata, int bstart, int blength, byte[] b, int start, int length) {
|
||||
int value = b[start++] & 0xFF;
|
||||
int bitPosition = 4;
|
||||
final int bend = bstart + blength;
|
||||
while (bstart < bend) {
|
||||
if (bitPosition == 8) {
|
||||
value = b[start++] & 0xFF;
|
||||
bitPosition = 0;
|
||||
}
|
||||
|
||||
bdata[bstart++] = (value & BIT_TABLE[bitPosition++]) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
|
||||
if (!(array instanceof boolean[])) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotBoolean"));
|
||||
}
|
||||
|
||||
encodeToBytesFromBooleanArray((boolean[])array, astart, alength, b, start);
|
||||
}
|
||||
|
||||
public void encodeToBytesFromBooleanArray(boolean[] array, int astart, int alength, byte[] b, int start) {
|
||||
final int mod = (alength + 4) % 8;
|
||||
final int unusedBits = (mod == 0) ? 0 : 8 - mod;
|
||||
|
||||
int bitPosition = 4;
|
||||
int value = unusedBits << 4;
|
||||
final int aend = astart + alength;
|
||||
while (astart < aend) {
|
||||
if (array[astart++]) {
|
||||
value |= BIT_TABLE[bitPosition];
|
||||
}
|
||||
|
||||
if (++bitPosition == 8) {
|
||||
b[start++] = (byte)value;
|
||||
bitPosition = value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (bitPosition > 0) {
|
||||
b[start] = (byte)value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generate a boolean array from a list of Booleans.
|
||||
*
|
||||
* @param array The array
|
||||
*
|
||||
*/
|
||||
private boolean[] generateArrayFromList(List array) {
|
||||
boolean[] bdata = new boolean[array.size()];
|
||||
for (int i = 0; i < bdata.length; i++) {
|
||||
bdata[i] = ((Boolean)array.get(i)).booleanValue();
|
||||
}
|
||||
|
||||
return bdata;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2013, 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.algorithm;
|
||||
|
||||
import java.nio.CharBuffer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithm;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
|
||||
|
||||
public abstract class BuiltInEncodingAlgorithm implements EncodingAlgorithm {
|
||||
protected final static Pattern SPACE_PATTERN = Pattern.compile("\\s");
|
||||
|
||||
public abstract int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException;
|
||||
|
||||
public abstract int getOctetLengthFromPrimitiveLength(int primitiveLength);
|
||||
|
||||
public abstract void encodeToBytes(Object array, int astart, int alength, byte[] b, int start);
|
||||
|
||||
public interface WordListener {
|
||||
public void word(int start, int end);
|
||||
}
|
||||
|
||||
public void matchWhiteSpaceDelimnatedWords(CharBuffer cb, WordListener wl) {
|
||||
Matcher m = SPACE_PATTERN.matcher(cb);
|
||||
int i = 0;
|
||||
int s = 0;
|
||||
while(m.find()) {
|
||||
s = m.start();
|
||||
if (s != i) {
|
||||
wl.word(i, s);
|
||||
}
|
||||
i = m.end();
|
||||
}
|
||||
if (i != cb.length())
|
||||
wl.word(i, cb.length());
|
||||
}
|
||||
|
||||
public StringBuilder removeWhitespace(char[] ch, int start, int length) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
int firstNonWS = 0;
|
||||
int idx = 0;
|
||||
for (; idx < length; ++idx) {
|
||||
if (Character.isWhitespace(ch[idx + start])) {
|
||||
if (firstNonWS < idx) {
|
||||
buf.append(ch, firstNonWS + start, idx - firstNonWS);
|
||||
}
|
||||
firstNonWS = idx + 1;
|
||||
}
|
||||
}
|
||||
if (firstNonWS < idx) {
|
||||
buf.append(ch, firstNonWS + start, idx - firstNonWS);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.algorithm;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.EncodingConstants;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmIndexes;
|
||||
|
||||
public final class BuiltInEncodingAlgorithmFactory {
|
||||
|
||||
private final static BuiltInEncodingAlgorithm[] table =
|
||||
new BuiltInEncodingAlgorithm[EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END + 1];
|
||||
|
||||
public final static HexadecimalEncodingAlgorithm hexadecimalEncodingAlgorithm = new HexadecimalEncodingAlgorithm();
|
||||
|
||||
public final static BASE64EncodingAlgorithm base64EncodingAlgorithm = new BASE64EncodingAlgorithm();
|
||||
|
||||
public final static BooleanEncodingAlgorithm booleanEncodingAlgorithm = new BooleanEncodingAlgorithm();
|
||||
|
||||
public final static ShortEncodingAlgorithm shortEncodingAlgorithm = new ShortEncodingAlgorithm();
|
||||
|
||||
public final static IntEncodingAlgorithm intEncodingAlgorithm = new IntEncodingAlgorithm();
|
||||
|
||||
public final static LongEncodingAlgorithm longEncodingAlgorithm = new LongEncodingAlgorithm();
|
||||
|
||||
public final static FloatEncodingAlgorithm floatEncodingAlgorithm = new FloatEncodingAlgorithm();
|
||||
|
||||
public final static DoubleEncodingAlgorithm doubleEncodingAlgorithm = new DoubleEncodingAlgorithm();
|
||||
|
||||
public final static UUIDEncodingAlgorithm uuidEncodingAlgorithm = new UUIDEncodingAlgorithm();
|
||||
|
||||
static {
|
||||
table[EncodingAlgorithmIndexes.HEXADECIMAL] = hexadecimalEncodingAlgorithm;
|
||||
table[EncodingAlgorithmIndexes.BASE64] = base64EncodingAlgorithm;
|
||||
table[EncodingAlgorithmIndexes.SHORT] = shortEncodingAlgorithm;
|
||||
table[EncodingAlgorithmIndexes.INT] = intEncodingAlgorithm;
|
||||
table[EncodingAlgorithmIndexes.LONG] = longEncodingAlgorithm;
|
||||
table[EncodingAlgorithmIndexes.BOOLEAN] = booleanEncodingAlgorithm;
|
||||
table[EncodingAlgorithmIndexes.FLOAT] = floatEncodingAlgorithm;
|
||||
table[EncodingAlgorithmIndexes.DOUBLE] = doubleEncodingAlgorithm;
|
||||
table[EncodingAlgorithmIndexes.UUID] = uuidEncodingAlgorithm;
|
||||
}
|
||||
|
||||
public static BuiltInEncodingAlgorithm getAlgorithm(int index) {
|
||||
return table[index];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.algorithm;
|
||||
|
||||
public class BuiltInEncodingAlgorithmState {
|
||||
|
||||
public static final int INITIAL_LENGTH = 8;
|
||||
|
||||
public boolean[] booleanArray = new boolean[INITIAL_LENGTH];
|
||||
|
||||
public short[] shortArray = new short[INITIAL_LENGTH];
|
||||
|
||||
public int[] intArray = new int[INITIAL_LENGTH];
|
||||
|
||||
public long[] longArray = new long[INITIAL_LENGTH];
|
||||
|
||||
public float[] floatArray = new float[INITIAL_LENGTH];
|
||||
|
||||
public double[] doubleArray = new double[INITIAL_LENGTH];
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* 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.algorithm;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.CharBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
|
||||
|
||||
public class DoubleEncodingAlgorithm extends IEEE754FloatingPointEncodingAlgorithm {
|
||||
|
||||
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
|
||||
if (octetLength % DOUBLE_SIZE != 0) {
|
||||
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
|
||||
getString("message.lengthIsNotMultipleOfDouble", new Object[]{Integer.valueOf(DOUBLE_SIZE)}));
|
||||
}
|
||||
|
||||
return octetLength / DOUBLE_SIZE;
|
||||
}
|
||||
|
||||
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
|
||||
return primitiveLength * DOUBLE_SIZE;
|
||||
}
|
||||
|
||||
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
|
||||
double[] data = new double[getPrimtiveLengthFromOctetLength(length)];
|
||||
decodeFromBytesToDoubleArray(data, 0, b, start, length);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public final Object decodeFromInputStream(InputStream s) throws IOException {
|
||||
return decodeFromInputStreamToDoubleArray(s);
|
||||
}
|
||||
|
||||
|
||||
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
|
||||
if (!(data instanceof double[])) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotDouble"));
|
||||
}
|
||||
|
||||
final double[] fdata = (double[])data;
|
||||
|
||||
encodeToOutputStreamFromDoubleArray(fdata, s);
|
||||
}
|
||||
|
||||
public final Object convertFromCharacters(char[] ch, int start, int length) {
|
||||
final CharBuffer cb = CharBuffer.wrap(ch, start, length);
|
||||
final List doubleList = new ArrayList();
|
||||
|
||||
matchWhiteSpaceDelimnatedWords(cb,
|
||||
new WordListener() {
|
||||
public void word(int start, int end) {
|
||||
String fStringValue = cb.subSequence(start, end).toString();
|
||||
doubleList.add(Double.valueOf(fStringValue));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return generateArrayFromList(doubleList);
|
||||
}
|
||||
|
||||
public final void convertToCharacters(Object data, StringBuffer s) {
|
||||
if (!(data instanceof double[])) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotDouble"));
|
||||
}
|
||||
|
||||
final double[] fdata = (double[])data;
|
||||
|
||||
convertToCharactersFromDoubleArray(fdata, s);
|
||||
}
|
||||
|
||||
|
||||
public final void decodeFromBytesToDoubleArray(double[] data, int fstart, byte[] b, int start, int length) {
|
||||
final int size = length / DOUBLE_SIZE;
|
||||
for (int i = 0; i < size; i++) {
|
||||
final long bits =
|
||||
((long)(b[start++] & 0xFF) << 56) |
|
||||
((long)(b[start++] & 0xFF) << 48) |
|
||||
((long)(b[start++] & 0xFF) << 40) |
|
||||
((long)(b[start++] & 0xFF) << 32) |
|
||||
((long)(b[start++] & 0xFF) << 24) |
|
||||
((long)(b[start++] & 0xFF) << 16) |
|
||||
((long)(b[start++] & 0xFF) << 8) |
|
||||
(long)(b[start++] & 0xFF);
|
||||
data[fstart++] = Double.longBitsToDouble(bits);
|
||||
}
|
||||
}
|
||||
|
||||
public final double[] decodeFromInputStreamToDoubleArray(InputStream s) throws IOException {
|
||||
final List doubleList = new ArrayList();
|
||||
final byte[] b = new byte[DOUBLE_SIZE];
|
||||
|
||||
while (true) {
|
||||
int n = s.read(b);
|
||||
if (n != DOUBLE_SIZE) {
|
||||
if (n == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
while(n != DOUBLE_SIZE) {
|
||||
final int m = s.read(b, n, DOUBLE_SIZE - n);
|
||||
if (m == -1) {
|
||||
throw new EOFException();
|
||||
}
|
||||
n += m;
|
||||
}
|
||||
}
|
||||
|
||||
final long bits =
|
||||
((long)(b[0] & 0xFF) << 56) |
|
||||
((long)(b[1] & 0xFF) << 48) |
|
||||
((long)(b[2] & 0xFF) << 40) |
|
||||
((long)(b[3] & 0xFF) << 32) |
|
||||
((b[4] & 0xFF) << 24) |
|
||||
((b[5] & 0xFF) << 16) |
|
||||
((b[6] & 0xFF) << 8) |
|
||||
(b[7] & 0xFF);
|
||||
|
||||
doubleList.add(Double.valueOf(Double.longBitsToDouble(bits)));
|
||||
}
|
||||
|
||||
return generateArrayFromList(doubleList);
|
||||
}
|
||||
|
||||
|
||||
public final void encodeToOutputStreamFromDoubleArray(double[] fdata, OutputStream s) throws IOException {
|
||||
for (int i = 0; i < fdata.length; i++) {
|
||||
final long bits = Double.doubleToLongBits(fdata[i]);
|
||||
s.write((int)((bits >>> 56) & 0xFF));
|
||||
s.write((int)((bits >>> 48) & 0xFF));
|
||||
s.write((int)((bits >>> 40) & 0xFF));
|
||||
s.write((int)((bits >>> 32) & 0xFF));
|
||||
s.write((int)((bits >>> 24) & 0xFF));
|
||||
s.write((int)((bits >>> 16) & 0xFF));
|
||||
s.write((int)((bits >>> 8) & 0xFF));
|
||||
s.write((int)(bits & 0xFF));
|
||||
}
|
||||
}
|
||||
|
||||
public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
|
||||
encodeToBytesFromDoubleArray((double[])array, astart, alength, b, start);
|
||||
}
|
||||
|
||||
public final void encodeToBytesFromDoubleArray(double[] fdata, int fstart, int flength, byte[] b, int start) {
|
||||
final int fend = fstart + flength;
|
||||
for (int i = fstart; i < fend; i++) {
|
||||
final long bits = Double.doubleToLongBits(fdata[i]);
|
||||
b[start++] = (byte)((bits >>> 56) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 48) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 40) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 32) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 24) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 16) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 8) & 0xFF);
|
||||
b[start++] = (byte)(bits & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final void convertToCharactersFromDoubleArray(double[] fdata, StringBuffer s) {
|
||||
final int end = fdata.length - 1;
|
||||
for (int i = 0; i <= end; i++) {
|
||||
s.append(Double.toString(fdata[i]));
|
||||
if (i != end) {
|
||||
s.append(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final double[] generateArrayFromList(List array) {
|
||||
double[] fdata = new double[array.size()];
|
||||
for (int i = 0; i < fdata.length; i++) {
|
||||
fdata[i] = ((Double)array.get(i)).doubleValue();
|
||||
}
|
||||
|
||||
return fdata;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2013, 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.algorithm;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.CharBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
|
||||
|
||||
public class FloatEncodingAlgorithm extends IEEE754FloatingPointEncodingAlgorithm {
|
||||
|
||||
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
|
||||
if (octetLength % FLOAT_SIZE != 0) {
|
||||
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
|
||||
getString("message.lengthNotMultipleOfFloat", new Object[]{Integer.valueOf(FLOAT_SIZE)}));
|
||||
}
|
||||
|
||||
return octetLength / FLOAT_SIZE;
|
||||
}
|
||||
|
||||
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
|
||||
return primitiveLength * FLOAT_SIZE;
|
||||
}
|
||||
|
||||
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
|
||||
float[] data = new float[getPrimtiveLengthFromOctetLength(length)];
|
||||
decodeFromBytesToFloatArray(data, 0, b, start, length);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public final Object decodeFromInputStream(InputStream s) throws IOException {
|
||||
return decodeFromInputStreamToFloatArray(s);
|
||||
}
|
||||
|
||||
|
||||
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
|
||||
if (!(data instanceof float[])) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotFloat"));
|
||||
}
|
||||
|
||||
final float[] fdata = (float[])data;
|
||||
|
||||
encodeToOutputStreamFromFloatArray(fdata, s);
|
||||
}
|
||||
|
||||
public final Object convertFromCharacters(char[] ch, int start, int length) {
|
||||
final CharBuffer cb = CharBuffer.wrap(ch, start, length);
|
||||
final List floatList = new ArrayList();
|
||||
|
||||
matchWhiteSpaceDelimnatedWords(cb,
|
||||
new WordListener() {
|
||||
public void word(int start, int end) {
|
||||
String fStringValue = cb.subSequence(start, end).toString();
|
||||
floatList.add(Float.valueOf(fStringValue));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return generateArrayFromList(floatList);
|
||||
}
|
||||
|
||||
public final void convertToCharacters(Object data, StringBuffer s) {
|
||||
if (!(data instanceof float[])) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotFloat"));
|
||||
}
|
||||
|
||||
final float[] fdata = (float[])data;
|
||||
|
||||
convertToCharactersFromFloatArray(fdata, s);
|
||||
}
|
||||
|
||||
|
||||
public final void decodeFromBytesToFloatArray(float[] data, int fstart, byte[] b, int start, int length) {
|
||||
final int size = length / FLOAT_SIZE;
|
||||
for (int i = 0; i < size; i++) {
|
||||
final int bits = ((b[start++] & 0xFF) << 24) |
|
||||
((b[start++] & 0xFF) << 16) |
|
||||
((b[start++] & 0xFF) << 8) |
|
||||
(b[start++] & 0xFF);
|
||||
data[fstart++] = Float.intBitsToFloat(bits);
|
||||
}
|
||||
}
|
||||
|
||||
public final float[] decodeFromInputStreamToFloatArray(InputStream s) throws IOException {
|
||||
final List floatList = new ArrayList();
|
||||
final byte[] b = new byte[FLOAT_SIZE];
|
||||
|
||||
while (true) {
|
||||
int n = s.read(b);
|
||||
if (n != 4) {
|
||||
if (n == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
while(n != 4) {
|
||||
final int m = s.read(b, n, FLOAT_SIZE - n);
|
||||
if (m == -1) {
|
||||
throw new EOFException();
|
||||
}
|
||||
n += m;
|
||||
}
|
||||
}
|
||||
|
||||
final int bits = ((b[0] & 0xFF) << 24) |
|
||||
((b[1] & 0xFF) << 16) |
|
||||
((b[2] & 0xFF) << 8) |
|
||||
(b[3] & 0xFF);
|
||||
floatList.add(Float.valueOf(Float.intBitsToFloat(bits)));
|
||||
}
|
||||
|
||||
return generateArrayFromList(floatList);
|
||||
}
|
||||
|
||||
|
||||
public final void encodeToOutputStreamFromFloatArray(float[] fdata, OutputStream s) throws IOException {
|
||||
for (int i = 0; i < fdata.length; i++) {
|
||||
final int bits = Float.floatToIntBits(fdata[i]);
|
||||
s.write((bits >>> 24) & 0xFF);
|
||||
s.write((bits >>> 16) & 0xFF);
|
||||
s.write((bits >>> 8) & 0xFF);
|
||||
s.write(bits & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
|
||||
encodeToBytesFromFloatArray((float[])array, astart, alength, b, start);
|
||||
}
|
||||
|
||||
public final void encodeToBytesFromFloatArray(float[] fdata, int fstart, int flength, byte[] b, int start) {
|
||||
final int fend = fstart + flength;
|
||||
for (int i = fstart; i < fend; i++) {
|
||||
final int bits = Float.floatToIntBits(fdata[i]);
|
||||
b[start++] = (byte)((bits >>> 24) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 16) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 8) & 0xFF);
|
||||
b[start++] = (byte)(bits & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final void convertToCharactersFromFloatArray(float[] fdata, StringBuffer s) {
|
||||
final int end = fdata.length - 1;
|
||||
for (int i = 0; i <= end; i++) {
|
||||
s.append(Float.toString(fdata[i]));
|
||||
if (i != end) {
|
||||
s.append(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final float[] generateArrayFromList(List array) {
|
||||
float[] fdata = new float[array.size()];
|
||||
for (int i = 0; i < fdata.length; i++) {
|
||||
fdata[i] = ((Float)array.get(i)).floatValue();
|
||||
}
|
||||
|
||||
return fdata;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2013, 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.algorithm;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class HexadecimalEncodingAlgorithm extends BuiltInEncodingAlgorithm {
|
||||
private static final char NIBBLE_TO_HEXADECIMAL_TABLE[] =
|
||||
{ '0','1','2','3','4','5','6','7',
|
||||
'8','9','A','B','C','D','E','F' };
|
||||
|
||||
private static final int HEXADECIMAL_TO_NIBBLE_TABLE[] = {
|
||||
/*'0'*/ 0,
|
||||
/*'1'*/ 1,
|
||||
/*'2'*/ 2,
|
||||
/*'3'*/ 3,
|
||||
/*'4'*/ 4,
|
||||
/*'5'*/ 5,
|
||||
/*'6'*/ 6,
|
||||
/*'7'*/ 7,
|
||||
/*'8'*/ 8,
|
||||
/*'9'*/ 9, -1, -1, -1, -1, -1, -1, -1,
|
||||
/*'A'*/ 10,
|
||||
/*'B'*/ 11,
|
||||
/*'C'*/ 12,
|
||||
/*'D'*/ 13,
|
||||
/*'E'*/ 14,
|
||||
/*'F'*/ 15,
|
||||
/*'G'-'Z'*/-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
/*'[' - '`'*/ -1, -1, -1, -1, -1, -1,
|
||||
/*'a'*/ 10,
|
||||
/*'b'*/ 11,
|
||||
/*'c'*/ 12,
|
||||
/*'d'*/ 13,
|
||||
/*'e'*/ 14,
|
||||
/*'f'*/ 15 };
|
||||
|
||||
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
|
||||
final byte[] data = new byte[length];
|
||||
System.arraycopy(b, start, data, 0, length);
|
||||
return data;
|
||||
}
|
||||
|
||||
public final Object decodeFromInputStream(InputStream s) throws IOException {
|
||||
throw new UnsupportedOperationException(CommonResourceBundle.getInstance().getString("message.notImplemented"));
|
||||
}
|
||||
|
||||
|
||||
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
|
||||
if (!(data instanceof byte[])) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotByteArray"));
|
||||
}
|
||||
|
||||
s.write((byte[])data);
|
||||
}
|
||||
|
||||
public final Object convertFromCharacters(char[] ch, int start, int length) {
|
||||
if (length == 0) {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
StringBuilder encodedValue = removeWhitespace(ch, start, length);
|
||||
int encodedLength = encodedValue.length();
|
||||
if (encodedLength == 0) {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
int valueLength = encodedValue.length() / 2;
|
||||
byte[] value = new byte[valueLength];
|
||||
|
||||
int encodedIdx = 0;
|
||||
for (int i = 0; i < valueLength; ++i) {
|
||||
int nibble1 = HEXADECIMAL_TO_NIBBLE_TABLE[encodedValue.charAt(encodedIdx++) - '0'];
|
||||
int nibble2 = HEXADECIMAL_TO_NIBBLE_TABLE[encodedValue.charAt(encodedIdx++) - '0'];
|
||||
value[i] = (byte) ((nibble1 << 4) | nibble2);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public final void convertToCharacters(Object data, StringBuffer s) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
final byte[] value = (byte[]) data;
|
||||
if (value.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
s.ensureCapacity(value.length * 2);
|
||||
for (int i = 0; i < value.length; ++i) {
|
||||
s.append(NIBBLE_TO_HEXADECIMAL_TABLE[(value[i] >>> 4) & 0xf]);
|
||||
s.append(NIBBLE_TO_HEXADECIMAL_TABLE[value[i] & 0xf]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
|
||||
return octetLength * 2;
|
||||
}
|
||||
|
||||
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
|
||||
return primitiveLength / 2;
|
||||
}
|
||||
|
||||
public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
|
||||
System.arraycopy((byte[])array, astart, b, start, alength);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.algorithm;
|
||||
|
||||
public abstract class IEEE754FloatingPointEncodingAlgorithm extends BuiltInEncodingAlgorithm {
|
||||
public final static int FLOAT_SIZE = 4;
|
||||
public final static int DOUBLE_SIZE = 8;
|
||||
|
||||
public final static int FLOAT_MAX_CHARACTER_SIZE = 14;
|
||||
public final static int DOUBLE_MAX_CHARACTER_SIZE = 24;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* 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.algorithm;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.CharBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
|
||||
|
||||
public class IntEncodingAlgorithm extends IntegerEncodingAlgorithm {
|
||||
|
||||
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
|
||||
if (octetLength % INT_SIZE != 0) {
|
||||
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
|
||||
getString("message.lengthNotMultipleOfInt", new Object[]{Integer.valueOf(INT_SIZE)}));
|
||||
}
|
||||
|
||||
return octetLength / INT_SIZE;
|
||||
}
|
||||
|
||||
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
|
||||
return primitiveLength * INT_SIZE;
|
||||
}
|
||||
|
||||
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
|
||||
int[] data = new int[getPrimtiveLengthFromOctetLength(length)];
|
||||
decodeFromBytesToIntArray(data, 0, b, start, length);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public final Object decodeFromInputStream(InputStream s) throws IOException {
|
||||
return decodeFromInputStreamToIntArray(s);
|
||||
}
|
||||
|
||||
|
||||
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
|
||||
if (!(data instanceof int[])) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotIntArray"));
|
||||
}
|
||||
|
||||
final int[] idata = (int[])data;
|
||||
|
||||
encodeToOutputStreamFromIntArray(idata, s);
|
||||
}
|
||||
|
||||
|
||||
public final Object convertFromCharacters(char[] ch, int start, int length) {
|
||||
final CharBuffer cb = CharBuffer.wrap(ch, start, length);
|
||||
final List integerList = new ArrayList();
|
||||
|
||||
matchWhiteSpaceDelimnatedWords(cb,
|
||||
new WordListener() {
|
||||
public void word(int start, int end) {
|
||||
String iStringValue = cb.subSequence(start, end).toString();
|
||||
integerList.add(Integer.valueOf(iStringValue));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return generateArrayFromList(integerList);
|
||||
}
|
||||
|
||||
public final void convertToCharacters(Object data, StringBuffer s) {
|
||||
if (!(data instanceof int[])) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotIntArray"));
|
||||
}
|
||||
|
||||
final int[] idata = (int[])data;
|
||||
|
||||
convertToCharactersFromIntArray(idata, s);
|
||||
}
|
||||
|
||||
|
||||
public final void decodeFromBytesToIntArray(int[] idata, int istart, byte[] b, int start, int length) {
|
||||
final int size = length / INT_SIZE;
|
||||
for (int i = 0; i < size; i++) {
|
||||
idata[istart++] = ((b[start++] & 0xFF) << 24) |
|
||||
((b[start++] & 0xFF) << 16) |
|
||||
((b[start++] & 0xFF) << 8) |
|
||||
(b[start++] & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
public final int[] decodeFromInputStreamToIntArray(InputStream s) throws IOException {
|
||||
final List integerList = new ArrayList();
|
||||
final byte[] b = new byte[INT_SIZE];
|
||||
|
||||
while (true) {
|
||||
int n = s.read(b);
|
||||
if (n != 4) {
|
||||
if (n == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
while(n != 4) {
|
||||
final int m = s.read(b, n, INT_SIZE - n);
|
||||
if (m == -1) {
|
||||
throw new EOFException();
|
||||
}
|
||||
n += m;
|
||||
}
|
||||
}
|
||||
|
||||
final int i = ((b[0] & 0xFF) << 24) |
|
||||
((b[1] & 0xFF) << 16) |
|
||||
((b[2] & 0xFF) << 8) |
|
||||
(b[3] & 0xFF);
|
||||
integerList.add(Integer.valueOf(i));
|
||||
}
|
||||
|
||||
return generateArrayFromList(integerList);
|
||||
}
|
||||
|
||||
|
||||
public final void encodeToOutputStreamFromIntArray(int[] idata, OutputStream s) throws IOException {
|
||||
for (int i = 0; i < idata.length; i++) {
|
||||
final int bits = idata[i];
|
||||
s.write((bits >>> 24) & 0xFF);
|
||||
s.write((bits >>> 16) & 0xFF);
|
||||
s.write((bits >>> 8) & 0xFF);
|
||||
s.write(bits & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
|
||||
encodeToBytesFromIntArray((int[])array, astart, alength, b, start);
|
||||
}
|
||||
|
||||
public final void encodeToBytesFromIntArray(int[] idata, int istart, int ilength, byte[] b, int start) {
|
||||
final int iend = istart + ilength;
|
||||
for (int i = istart; i < iend; i++) {
|
||||
final int bits = idata[i];
|
||||
b[start++] = (byte)((bits >>> 24) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 16) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 8) & 0xFF);
|
||||
b[start++] = (byte)(bits & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final void convertToCharactersFromIntArray(int[] idata, StringBuffer s) {
|
||||
final int end = idata.length - 1;
|
||||
for (int i = 0; i <= end; i++) {
|
||||
s.append(Integer.toString(idata[i]));
|
||||
if (i != end) {
|
||||
s.append(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final int[] generateArrayFromList(List array) {
|
||||
int[] idata = new int[array.size()];
|
||||
for (int i = 0; i < idata.length; i++) {
|
||||
idata[i] = ((Integer)array.get(i)).intValue();
|
||||
}
|
||||
|
||||
return idata;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.algorithm;
|
||||
|
||||
public abstract class IntegerEncodingAlgorithm extends BuiltInEncodingAlgorithm {
|
||||
public final static int SHORT_SIZE = 2;
|
||||
public final static int INT_SIZE = 4;
|
||||
public final static int LONG_SIZE = 8;
|
||||
|
||||
public final static int SHORT_MAX_CHARACTER_SIZE = 6;
|
||||
public final static int INT_MAX_CHARACTER_SIZE = 11;
|
||||
public final static int LONG_MAX_CHARACTER_SIZE = 20;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* 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.algorithm;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.CharBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
|
||||
public class LongEncodingAlgorithm extends IntegerEncodingAlgorithm {
|
||||
|
||||
public int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
|
||||
if (octetLength % LONG_SIZE != 0) {
|
||||
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
|
||||
getString("message.lengthNotMultipleOfLong", new Object[]{Integer.valueOf(LONG_SIZE)}));
|
||||
}
|
||||
|
||||
return octetLength / LONG_SIZE;
|
||||
}
|
||||
|
||||
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
|
||||
return primitiveLength * LONG_SIZE;
|
||||
}
|
||||
|
||||
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
|
||||
long[] data = new long[getPrimtiveLengthFromOctetLength(length)];
|
||||
decodeFromBytesToLongArray(data, 0, b, start, length);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public final Object decodeFromInputStream(InputStream s) throws IOException {
|
||||
return decodeFromInputStreamToIntArray(s);
|
||||
}
|
||||
|
||||
|
||||
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
|
||||
if (!(data instanceof long[])) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotLongArray"));
|
||||
}
|
||||
|
||||
final long[] ldata = (long[])data;
|
||||
|
||||
encodeToOutputStreamFromLongArray(ldata, s);
|
||||
}
|
||||
|
||||
|
||||
public Object convertFromCharacters(char[] ch, int start, int length) {
|
||||
final CharBuffer cb = CharBuffer.wrap(ch, start, length);
|
||||
final List longList = new ArrayList();
|
||||
|
||||
matchWhiteSpaceDelimnatedWords(cb,
|
||||
new WordListener() {
|
||||
public void word(int start, int end) {
|
||||
String lStringValue = cb.subSequence(start, end).toString();
|
||||
longList.add(Long.valueOf(lStringValue));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return generateArrayFromList(longList);
|
||||
}
|
||||
|
||||
public void convertToCharacters(Object data, StringBuffer s) {
|
||||
if (!(data instanceof long[])) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotLongArray"));
|
||||
}
|
||||
|
||||
final long[] ldata = (long[])data;
|
||||
|
||||
convertToCharactersFromLongArray(ldata, s);
|
||||
}
|
||||
|
||||
|
||||
public final void decodeFromBytesToLongArray(long[] ldata, int istart, byte[] b, int start, int length) {
|
||||
final int size = length / LONG_SIZE;
|
||||
for (int i = 0; i < size; i++) {
|
||||
ldata[istart++] =
|
||||
((long)(b[start++] & 0xFF) << 56) |
|
||||
((long)(b[start++] & 0xFF) << 48) |
|
||||
((long)(b[start++] & 0xFF) << 40) |
|
||||
((long)(b[start++] & 0xFF) << 32) |
|
||||
((long)(b[start++] & 0xFF) << 24) |
|
||||
((long)(b[start++] & 0xFF) << 16) |
|
||||
((long)(b[start++] & 0xFF) << 8) |
|
||||
(long)(b[start++] & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
public final long[] decodeFromInputStreamToIntArray(InputStream s) throws IOException {
|
||||
final List longList = new ArrayList();
|
||||
final byte[] b = new byte[LONG_SIZE];
|
||||
|
||||
while (true) {
|
||||
int n = s.read(b);
|
||||
if (n != LONG_SIZE) {
|
||||
if (n == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
while(n != LONG_SIZE) {
|
||||
final int m = s.read(b, n, LONG_SIZE - n);
|
||||
if (m == -1) {
|
||||
throw new EOFException();
|
||||
}
|
||||
n += m;
|
||||
}
|
||||
}
|
||||
|
||||
final long l =
|
||||
(((long) b[0] << 56) +
|
||||
((long) (b[1] & 0xFF) << 48) +
|
||||
((long) (b[2] & 0xFF) << 40) +
|
||||
((long) (b[3] & 0xFF) << 32) +
|
||||
((long) (b[4] & 0xFF) << 24) +
|
||||
((b[5] & 0xFF) << 16) +
|
||||
((b[6] & 0xFF) << 8) +
|
||||
((b[7] & 0xFF) << 0));
|
||||
|
||||
longList.add(Long.valueOf(l));
|
||||
}
|
||||
|
||||
return generateArrayFromList(longList);
|
||||
}
|
||||
|
||||
|
||||
public final void encodeToOutputStreamFromLongArray(long[] ldata, OutputStream s) throws IOException {
|
||||
for (int i = 0; i < ldata.length; i++) {
|
||||
final long bits = ldata[i];
|
||||
s.write((int)((bits >>> 56) & 0xFF));
|
||||
s.write((int)((bits >>> 48) & 0xFF));
|
||||
s.write((int)((bits >>> 40) & 0xFF));
|
||||
s.write((int)((bits >>> 32) & 0xFF));
|
||||
s.write((int)((bits >>> 24) & 0xFF));
|
||||
s.write((int)((bits >>> 16) & 0xFF));
|
||||
s.write((int)((bits >>> 8) & 0xFF));
|
||||
s.write((int)(bits & 0xFF));
|
||||
}
|
||||
}
|
||||
|
||||
public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
|
||||
encodeToBytesFromLongArray((long[])array, astart, alength, b, start);
|
||||
}
|
||||
|
||||
public final void encodeToBytesFromLongArray(long[] ldata, int lstart, int llength, byte[] b, int start) {
|
||||
final int lend = lstart + llength;
|
||||
for (int i = lstart; i < lend; i++) {
|
||||
final long bits = ldata[i];
|
||||
b[start++] = (byte)((bits >>> 56) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 48) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 40) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 32) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 24) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 16) & 0xFF);
|
||||
b[start++] = (byte)((bits >>> 8) & 0xFF);
|
||||
b[start++] = (byte)(bits & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final void convertToCharactersFromLongArray(long[] ldata, StringBuffer s) {
|
||||
final int end = ldata.length - 1;
|
||||
for (int i = 0; i <= end; i++) {
|
||||
s.append(Long.toString(ldata[i]));
|
||||
if (i != end) {
|
||||
s.append(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final long[] generateArrayFromList(List array) {
|
||||
long[] ldata = new long[array.size()];
|
||||
for (int i = 0; i < ldata.length; i++) {
|
||||
ldata[i] = ((Long)array.get(i)).longValue();
|
||||
}
|
||||
|
||||
return ldata;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* 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.algorithm;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.CharBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
|
||||
/**
|
||||
* An encoder for handling Short values. Suppports the builtin SHORT encoder.
|
||||
*
|
||||
* @author Alan Hudson
|
||||
* @author Paul Sandoz
|
||||
*/
|
||||
public class ShortEncodingAlgorithm extends IntegerEncodingAlgorithm {
|
||||
|
||||
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
|
||||
if (octetLength % SHORT_SIZE != 0) {
|
||||
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
|
||||
getString("message.lengthNotMultipleOfShort", new Object[]{Integer.valueOf(SHORT_SIZE)}));
|
||||
}
|
||||
|
||||
return octetLength / SHORT_SIZE;
|
||||
}
|
||||
|
||||
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
|
||||
return primitiveLength * SHORT_SIZE;
|
||||
}
|
||||
|
||||
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
|
||||
short[] data = new short[getPrimtiveLengthFromOctetLength(length)];
|
||||
decodeFromBytesToShortArray(data, 0, b, start, length);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public final Object decodeFromInputStream(InputStream s) throws IOException {
|
||||
return decodeFromInputStreamToShortArray(s);
|
||||
}
|
||||
|
||||
|
||||
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
|
||||
if (!(data instanceof short[])) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotShortArray"));
|
||||
}
|
||||
|
||||
final short[] idata = (short[])data;
|
||||
|
||||
encodeToOutputStreamFromShortArray(idata, s);
|
||||
}
|
||||
|
||||
|
||||
public final Object convertFromCharacters(char[] ch, int start, int length) {
|
||||
final CharBuffer cb = CharBuffer.wrap(ch, start, length);
|
||||
final List shortList = new ArrayList();
|
||||
|
||||
matchWhiteSpaceDelimnatedWords(cb,
|
||||
new WordListener() {
|
||||
public void word(int start, int end) {
|
||||
String iStringValue = cb.subSequence(start, end).toString();
|
||||
shortList.add(Short.valueOf(iStringValue));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return generateArrayFromList(shortList);
|
||||
}
|
||||
|
||||
public final void convertToCharacters(Object data, StringBuffer s) {
|
||||
if (!(data instanceof short[])) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotShortArray"));
|
||||
}
|
||||
|
||||
final short[] idata = (short[])data;
|
||||
|
||||
convertToCharactersFromShortArray(idata, s);
|
||||
}
|
||||
|
||||
|
||||
public final void decodeFromBytesToShortArray(short[] sdata, int istart, byte[] b, int start, int length) {
|
||||
final int size = length / SHORT_SIZE;
|
||||
for (int i = 0; i < size; i++) {
|
||||
sdata[istart++] = (short) (((b[start++] & 0xFF) << 8) |
|
||||
(b[start++] & 0xFF));
|
||||
}
|
||||
}
|
||||
|
||||
public final short[] decodeFromInputStreamToShortArray(InputStream s) throws IOException {
|
||||
final List shortList = new ArrayList();
|
||||
final byte[] b = new byte[SHORT_SIZE];
|
||||
|
||||
while (true) {
|
||||
int n = s.read(b);
|
||||
if (n != 2) {
|
||||
if (n == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
while(n != 2) {
|
||||
final int m = s.read(b, n, SHORT_SIZE - n);
|
||||
if (m == -1) {
|
||||
throw new EOFException();
|
||||
}
|
||||
n += m;
|
||||
}
|
||||
}
|
||||
|
||||
final int i = ((b[0] & 0xFF) << 8) |
|
||||
(b[1] & 0xFF);
|
||||
shortList.add(Short.valueOf((short)i));
|
||||
}
|
||||
|
||||
return generateArrayFromList(shortList);
|
||||
}
|
||||
|
||||
|
||||
public final void encodeToOutputStreamFromShortArray(short[] idata, OutputStream s) throws IOException {
|
||||
for (int i = 0; i < idata.length; i++) {
|
||||
final int bits = idata[i];
|
||||
s.write((bits >>> 8) & 0xFF);
|
||||
s.write(bits & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
|
||||
encodeToBytesFromShortArray((short[])array, astart, alength, b, start);
|
||||
}
|
||||
|
||||
public final void encodeToBytesFromShortArray(short[] sdata, int istart, int ilength, byte[] b, int start) {
|
||||
final int iend = istart + ilength;
|
||||
for (int i = istart; i < iend; i++) {
|
||||
final short bits = sdata[i];
|
||||
b[start++] = (byte)((bits >>> 8) & 0xFF);
|
||||
b[start++] = (byte)(bits & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final void convertToCharactersFromShortArray(short[] sdata, StringBuffer s) {
|
||||
final int end = sdata.length - 1;
|
||||
for (int i = 0; i <= end; i++) {
|
||||
s.append(Short.toString(sdata[i]));
|
||||
if (i != end) {
|
||||
s.append(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final short[] generateArrayFromList(List array) {
|
||||
short[] sdata = new short[array.size()];
|
||||
for (int i = 0; i < sdata.length; i++) {
|
||||
sdata[i] = ((Short)array.get(i)).shortValue();
|
||||
}
|
||||
|
||||
return sdata;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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.algorithm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.nio.CharBuffer;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class UUIDEncodingAlgorithm extends LongEncodingAlgorithm {
|
||||
|
||||
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
|
||||
if (octetLength % (LONG_SIZE * 2) != 0) {
|
||||
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
|
||||
getString("message.lengthNotMultipleOfUUID",new Object[]{Integer.valueOf(LONG_SIZE * 2)}));
|
||||
}
|
||||
|
||||
return octetLength / LONG_SIZE;
|
||||
}
|
||||
|
||||
public final Object convertFromCharacters(char[] ch, int start, int length) {
|
||||
final CharBuffer cb = CharBuffer.wrap(ch, start, length);
|
||||
final List longList = new ArrayList();
|
||||
|
||||
matchWhiteSpaceDelimnatedWords(cb,
|
||||
new WordListener() {
|
||||
public void word(int start, int end) {
|
||||
String uuidValue = cb.subSequence(start, end).toString();
|
||||
fromUUIDString(uuidValue);
|
||||
longList.add(Long.valueOf(_msb));
|
||||
longList.add(Long.valueOf(_lsb));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return generateArrayFromList(longList);
|
||||
}
|
||||
|
||||
public final void convertToCharacters(Object data, StringBuffer s) {
|
||||
if (!(data instanceof long[])) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotLongArray"));
|
||||
}
|
||||
|
||||
final long[] ldata = (long[])data;
|
||||
|
||||
final int end = ldata.length - 2;
|
||||
for (int i = 0; i <= end; i += 2) {
|
||||
s.append(toUUIDString(ldata[i], ldata[i + 1]));
|
||||
if (i != end) {
|
||||
s.append(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private long _msb;
|
||||
private long _lsb;
|
||||
|
||||
final void fromUUIDString(String name) {
|
||||
String[] components = name.split("-");
|
||||
if (components.length != 5)
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
|
||||
getString("message.invalidUUID", new Object[]{name}));
|
||||
|
||||
for (int i=0; i<5; i++)
|
||||
components[i] = "0x"+components[i];
|
||||
|
||||
_msb = Long.parseLong(components[0], 16);
|
||||
_msb <<= 16;
|
||||
_msb |= Long.parseLong(components[1], 16);
|
||||
_msb <<= 16;
|
||||
_msb |= Long.parseLong(components[2], 16);
|
||||
|
||||
_lsb = Long.parseLong(components[3], 16);
|
||||
_lsb <<= 48;
|
||||
_lsb |= Long.parseLong(components[4], 16);
|
||||
}
|
||||
|
||||
final String toUUIDString(long msb, long lsb) {
|
||||
return (digits(msb >> 32, 8) + "-" +
|
||||
digits(msb >> 16, 4) + "-" +
|
||||
digits(msb, 4) + "-" +
|
||||
digits(lsb >> 48, 4) + "-" +
|
||||
digits(lsb, 12));
|
||||
}
|
||||
|
||||
final String digits(long val, int digits) {
|
||||
long hi = 1L << (digits * 4);
|
||||
return Long.toHexString(hi | (val & (hi - 1))).substring(1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.alphabet;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.EncodingConstants;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.RestrictedAlphabet;
|
||||
|
||||
public final class BuiltInRestrictedAlphabets {
|
||||
public final static char[][] table =
|
||||
new char[EncodingConstants.RESTRICTED_ALPHABET_BUILTIN_END + 1][];
|
||||
|
||||
static {
|
||||
table[RestrictedAlphabet.NUMERIC_CHARACTERS_INDEX] = RestrictedAlphabet.NUMERIC_CHARACTERS.toCharArray();
|
||||
table[RestrictedAlphabet.DATE_TIME_CHARACTERS_INDEX] = RestrictedAlphabet.DATE_TIME_CHARACTERS.toCharArray();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,353 @@
|
||||
/*
|
||||
* 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.dom;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.Encoder;
|
||||
import com.sun.xml.internal.fastinfoset.EncodingConstants;
|
||||
import com.sun.xml.internal.fastinfoset.QualifiedName;
|
||||
import com.sun.xml.internal.fastinfoset.util.NamespaceContextImplementation;
|
||||
import com.sun.xml.internal.fastinfoset.util.LocalNameQualifiedNamesMap;
|
||||
import java.io.IOException;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* The Fast Infoset DOM serializer.
|
||||
* <p>
|
||||
* Instantiate this serializer to serialize a fast infoset document in accordance
|
||||
* with the DOM API.
|
||||
*
|
||||
*/
|
||||
public class DOMDocumentSerializer extends Encoder {
|
||||
|
||||
/**
|
||||
* Serialize a {@link Node}.
|
||||
*
|
||||
* @param n the node to serialize.
|
||||
*/
|
||||
public final void serialize(Node n) throws IOException {
|
||||
switch (n.getNodeType()) {
|
||||
case Node.DOCUMENT_NODE:
|
||||
serialize((Document)n);
|
||||
break;
|
||||
case Node.ELEMENT_NODE:
|
||||
serializeElementAsDocument(n);
|
||||
break;
|
||||
case Node.COMMENT_NODE:
|
||||
serializeComment(n);
|
||||
break;
|
||||
case Node.PROCESSING_INSTRUCTION_NODE:
|
||||
serializeProcessingInstruction(n);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a {@link Document}.
|
||||
*
|
||||
* @param d the document to serialize.
|
||||
*/
|
||||
public final void serialize(Document d) throws IOException {
|
||||
reset();
|
||||
encodeHeader(false);
|
||||
encodeInitialVocabulary();
|
||||
|
||||
final NodeList nl = d.getChildNodes();
|
||||
for (int i = 0; i < nl.getLength(); i++) {
|
||||
final Node n = nl.item(i);
|
||||
switch (n.getNodeType()) {
|
||||
case Node.ELEMENT_NODE:
|
||||
serializeElement(n);
|
||||
break;
|
||||
case Node.COMMENT_NODE:
|
||||
serializeComment(n);
|
||||
break;
|
||||
case Node.PROCESSING_INSTRUCTION_NODE:
|
||||
serializeProcessingInstruction(n);
|
||||
break;
|
||||
}
|
||||
}
|
||||
encodeDocumentTermination();
|
||||
}
|
||||
|
||||
protected final void serializeElementAsDocument(Node e) throws IOException {
|
||||
reset();
|
||||
encodeHeader(false);
|
||||
encodeInitialVocabulary();
|
||||
|
||||
serializeElement(e);
|
||||
|
||||
encodeDocumentTermination();
|
||||
}
|
||||
|
||||
// protected Node[] _namespaceAttributes = new Node[4];
|
||||
|
||||
// map which will hold all current scope prefixes and associated attributes
|
||||
// Collection of populated namespace available for current scope
|
||||
protected NamespaceContextImplementation _namespaceScopeContext = new NamespaceContextImplementation();
|
||||
protected Node[] _attributes = new Node[32];
|
||||
|
||||
protected final void serializeElement(Node e) throws IOException {
|
||||
encodeTermination();
|
||||
|
||||
int attributesSize = 0;
|
||||
|
||||
_namespaceScopeContext.pushContext();
|
||||
|
||||
if (e.hasAttributes()) {
|
||||
/*
|
||||
* Split the attribute nodes into namespace attributes
|
||||
* or normal attributes.
|
||||
*/
|
||||
final NamedNodeMap nnm = e.getAttributes();
|
||||
for (int i = 0; i < nnm.getLength(); i++) {
|
||||
final Node a = nnm.item(i);
|
||||
final String namespaceURI = a.getNamespaceURI();
|
||||
if (namespaceURI != null && namespaceURI.equals("http://www.w3.org/2000/xmlns/")) {
|
||||
String attrPrefix = a.getLocalName();
|
||||
String attrNamespace = a.getNodeValue();
|
||||
if (attrPrefix == "xmlns" || attrPrefix.equals("xmlns")) {
|
||||
attrPrefix = "";
|
||||
}
|
||||
_namespaceScopeContext.declarePrefix(attrPrefix, attrNamespace);
|
||||
} else {
|
||||
if (attributesSize == _attributes.length) {
|
||||
final Node[] attributes = new Node[attributesSize * 3 / 2 + 1];
|
||||
System.arraycopy(_attributes, 0, attributes, 0, attributesSize);
|
||||
_attributes = attributes;
|
||||
}
|
||||
_attributes[attributesSize++] = a;
|
||||
|
||||
String attrNamespaceURI = a.getNamespaceURI();
|
||||
String attrPrefix = a.getPrefix();
|
||||
if (attrPrefix != null && !_namespaceScopeContext.getNamespaceURI(attrPrefix).equals(attrNamespaceURI)) {
|
||||
_namespaceScopeContext.declarePrefix(attrPrefix, attrNamespaceURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String elementNamespaceURI = e.getNamespaceURI();
|
||||
String elementPrefix = e.getPrefix();
|
||||
if (elementPrefix == null) elementPrefix = "";
|
||||
if (elementNamespaceURI != null &&
|
||||
!_namespaceScopeContext.getNamespaceURI(elementPrefix).equals(elementNamespaceURI)) {
|
||||
_namespaceScopeContext.declarePrefix(elementPrefix, elementNamespaceURI);
|
||||
}
|
||||
|
||||
if (!_namespaceScopeContext.isCurrentContextEmpty()) {
|
||||
if (attributesSize > 0) {
|
||||
write(EncodingConstants.ELEMENT | EncodingConstants.ELEMENT_NAMESPACES_FLAG |
|
||||
EncodingConstants.ELEMENT_ATTRIBUTE_FLAG);
|
||||
} else {
|
||||
write(EncodingConstants.ELEMENT | EncodingConstants.ELEMENT_NAMESPACES_FLAG);
|
||||
}
|
||||
|
||||
for (int i = _namespaceScopeContext.getCurrentContextStartIndex();
|
||||
i < _namespaceScopeContext.getCurrentContextEndIndex(); i++) {
|
||||
|
||||
String prefix = _namespaceScopeContext.getPrefix(i);
|
||||
String uri = _namespaceScopeContext.getNamespaceURI(i);
|
||||
encodeNamespaceAttribute(prefix, uri);
|
||||
}
|
||||
write(EncodingConstants.TERMINATOR);
|
||||
_b = 0;
|
||||
} else {
|
||||
_b = (attributesSize > 0) ? EncodingConstants.ELEMENT | EncodingConstants.ELEMENT_ATTRIBUTE_FLAG :
|
||||
EncodingConstants.ELEMENT;
|
||||
}
|
||||
|
||||
String namespaceURI = elementNamespaceURI;
|
||||
// namespaceURI = (namespaceURI == null) ? _namespaceScopeContext.getNamespaceURI("") : namespaceURI;
|
||||
namespaceURI = (namespaceURI == null) ? "" : namespaceURI;
|
||||
encodeElement(namespaceURI, e.getNodeName(), e.getLocalName());
|
||||
|
||||
if (attributesSize > 0) {
|
||||
// Serialize the attributes
|
||||
for (int i = 0; i < attributesSize; i++) {
|
||||
final Node a = _attributes[i];
|
||||
_attributes[i] = null;
|
||||
namespaceURI = a.getNamespaceURI();
|
||||
namespaceURI = (namespaceURI == null) ? "" : namespaceURI;
|
||||
encodeAttribute(namespaceURI, a.getNodeName(), a.getLocalName());
|
||||
|
||||
final String value = a.getNodeValue();
|
||||
final boolean addToTable = isAttributeValueLengthMatchesLimit(value.length());
|
||||
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, false);
|
||||
}
|
||||
|
||||
_b = EncodingConstants.TERMINATOR;
|
||||
_terminate = true;
|
||||
}
|
||||
|
||||
if (e.hasChildNodes()) {
|
||||
// Serialize the children
|
||||
final NodeList nl = e.getChildNodes();
|
||||
for (int i = 0; i < nl.getLength(); i++) {
|
||||
final Node n = nl.item(i);
|
||||
switch (n.getNodeType()) {
|
||||
case Node.ELEMENT_NODE:
|
||||
serializeElement(n);
|
||||
break;
|
||||
case Node.TEXT_NODE:
|
||||
serializeText(n);
|
||||
break;
|
||||
case Node.CDATA_SECTION_NODE:
|
||||
serializeCDATA(n);
|
||||
break;
|
||||
case Node.COMMENT_NODE:
|
||||
serializeComment(n);
|
||||
break;
|
||||
case Node.PROCESSING_INSTRUCTION_NODE:
|
||||
serializeProcessingInstruction(n);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
encodeElementTermination();
|
||||
_namespaceScopeContext.popContext();
|
||||
}
|
||||
|
||||
|
||||
protected final void serializeText(Node t) throws IOException {
|
||||
final String text = t.getNodeValue();
|
||||
|
||||
final int length = (text != null) ? text.length() : 0;
|
||||
if (length == 0) {
|
||||
return;
|
||||
} else if (length < _charBuffer.length) {
|
||||
text.getChars(0, length, _charBuffer, 0);
|
||||
if (getIgnoreWhiteSpaceTextContent() &&
|
||||
isWhiteSpace(_charBuffer, 0, length)) return;
|
||||
|
||||
encodeTermination();
|
||||
encodeCharacters(_charBuffer, 0, length);
|
||||
} else {
|
||||
final char ch[] = text.toCharArray();
|
||||
if (getIgnoreWhiteSpaceTextContent() &&
|
||||
isWhiteSpace(ch, 0, length)) return;
|
||||
|
||||
encodeTermination();
|
||||
encodeCharactersNoClone(ch, 0, length);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void serializeCDATA(Node t) throws IOException {
|
||||
final String text = t.getNodeValue();
|
||||
|
||||
final int length = (text != null) ? text.length() : 0;
|
||||
if (length == 0) {
|
||||
return;
|
||||
} else {
|
||||
final char ch[] = text.toCharArray();
|
||||
if (getIgnoreWhiteSpaceTextContent() &&
|
||||
isWhiteSpace(ch, 0, length)) return;
|
||||
|
||||
encodeTermination();
|
||||
try {
|
||||
encodeCIIBuiltInAlgorithmDataAsCDATA(ch, 0, length);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new IOException("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected final void serializeComment(Node c) throws IOException {
|
||||
if (getIgnoreComments()) return;
|
||||
|
||||
encodeTermination();
|
||||
|
||||
final String comment = c.getNodeValue();
|
||||
|
||||
final int length = (comment != null) ? comment.length() : 0;
|
||||
if (length == 0) {
|
||||
encodeComment(_charBuffer, 0, 0);
|
||||
} else if (length < _charBuffer.length) {
|
||||
comment.getChars(0, length, _charBuffer, 0);
|
||||
encodeComment(_charBuffer, 0, length);
|
||||
} else {
|
||||
final char ch[] = comment.toCharArray();
|
||||
encodeCommentNoClone(ch, 0, length);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void serializeProcessingInstruction(Node pi) throws IOException {
|
||||
if (getIgnoreProcesingInstructions()) return;
|
||||
|
||||
encodeTermination();
|
||||
|
||||
final String target = pi.getNodeName();
|
||||
final String data = pi.getNodeValue();
|
||||
encodeProcessingInstruction(target, data);
|
||||
}
|
||||
|
||||
protected final void encodeElement(String namespaceURI, String qName, String localName) throws IOException {
|
||||
LocalNameQualifiedNamesMap.Entry entry = _v.elementName.obtainEntry(qName);
|
||||
if (entry._valueIndex > 0) {
|
||||
final QualifiedName[] names = entry._value;
|
||||
for (int i = 0; i < entry._valueIndex; i++) {
|
||||
if ((namespaceURI == names[i].namespaceName || namespaceURI.equals(names[i].namespaceName))) {
|
||||
encodeNonZeroIntegerOnThirdBit(names[i].index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Was DOM node created using an NS-aware call?
|
||||
if (localName != null) {
|
||||
encodeLiteralElementQualifiedNameOnThirdBit(namespaceURI, getPrefixFromQualifiedName(qName),
|
||||
localName, entry);
|
||||
} else {
|
||||
encodeLiteralElementQualifiedNameOnThirdBit(namespaceURI, "", qName, entry);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void encodeAttribute(String namespaceURI, String qName, String localName) throws IOException {
|
||||
LocalNameQualifiedNamesMap.Entry entry = _v.attributeName.obtainEntry(qName);
|
||||
if (entry._valueIndex > 0) {
|
||||
final QualifiedName[] names = entry._value;
|
||||
for (int i = 0; i < entry._valueIndex; i++) {
|
||||
if ((namespaceURI == names[i].namespaceName || namespaceURI.equals(names[i].namespaceName))) {
|
||||
encodeNonZeroIntegerOnSecondBitFirstBitZero(names[i].index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Was DOM node created using an NS-aware call?
|
||||
if (localName != null) {
|
||||
encodeLiteralAttributeQualifiedNameOnSecondBit(namespaceURI, getPrefixFromQualifiedName(qName),
|
||||
localName, entry);
|
||||
} else {
|
||||
encodeLiteralAttributeQualifiedNameOnSecondBit(namespaceURI, "", qName, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2013, 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.sax;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.EncodingConstants;
|
||||
import com.sun.xml.internal.fastinfoset.QualifiedName;
|
||||
import com.sun.xml.internal.fastinfoset.algorithm.BuiltInEncodingAlgorithmFactory;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithm;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmIndexes;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
|
||||
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.sax.EncodingAlgorithmAttributes;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class AttributesHolder implements EncodingAlgorithmAttributes {
|
||||
private static final int DEFAULT_CAPACITY = 8;
|
||||
|
||||
private Map _registeredEncodingAlgorithms;
|
||||
|
||||
private int _attributeCount;
|
||||
|
||||
private QualifiedName[] _names;
|
||||
private String[] _values;
|
||||
|
||||
private String[] _algorithmURIs;
|
||||
private int[] _algorithmIds;
|
||||
private Object[] _algorithmData;
|
||||
|
||||
public AttributesHolder() {
|
||||
_names = new QualifiedName[DEFAULT_CAPACITY];
|
||||
_values = new String[DEFAULT_CAPACITY];
|
||||
|
||||
_algorithmURIs = new String[DEFAULT_CAPACITY];
|
||||
_algorithmIds = new int[DEFAULT_CAPACITY];
|
||||
_algorithmData = new Object[DEFAULT_CAPACITY];
|
||||
}
|
||||
|
||||
public AttributesHolder(Map registeredEncodingAlgorithms) {
|
||||
this();
|
||||
_registeredEncodingAlgorithms = registeredEncodingAlgorithms;
|
||||
}
|
||||
|
||||
// org.xml.sax.Attributes
|
||||
|
||||
public final int getLength() {
|
||||
return _attributeCount;
|
||||
}
|
||||
|
||||
public final String getLocalName(int index) {
|
||||
return _names[index].localName;
|
||||
}
|
||||
|
||||
public final String getQName(int index) {
|
||||
return _names[index].getQNameString();
|
||||
}
|
||||
|
||||
public final String getType(int index) {
|
||||
return "CDATA";
|
||||
}
|
||||
|
||||
public final String getURI(int index) {
|
||||
return _names[index].namespaceName;
|
||||
}
|
||||
|
||||
public final String getValue(int index) {
|
||||
final String value = _values[index];
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (_algorithmData[index] == null ||
|
||||
(_algorithmIds[index] >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START &&
|
||||
_registeredEncodingAlgorithms == null)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return _values[index] = convertEncodingAlgorithmDataToString(
|
||||
_algorithmIds[index],
|
||||
_algorithmURIs[index],
|
||||
_algorithmData[index]).toString();
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
} catch (FastInfosetException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final int getIndex(String qName) {
|
||||
int i = qName.indexOf(':');
|
||||
String prefix = "";
|
||||
String localName = qName;
|
||||
if (i >= 0) {
|
||||
prefix = qName.substring(0, i);
|
||||
localName = qName.substring(i + 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < _attributeCount; i++) {
|
||||
QualifiedName name = _names[i];
|
||||
if (localName.equals(name.localName) &&
|
||||
prefix.equals(name.prefix)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public final String getType(String qName) {
|
||||
int index = getIndex(qName);
|
||||
if (index >= 0) {
|
||||
return "CDATA";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final String getValue(String qName) {
|
||||
int index = getIndex(qName);
|
||||
if (index >= 0) {
|
||||
return _values[index];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final int getIndex(String uri, String localName) {
|
||||
for (int i = 0; i < _attributeCount; i++) {
|
||||
QualifiedName name = _names[i];
|
||||
if (localName.equals(name.localName) &&
|
||||
uri.equals(name.namespaceName)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public final String getType(String uri, String localName) {
|
||||
int index = getIndex(uri, localName);
|
||||
if (index >= 0) {
|
||||
return "CDATA";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final String getValue(String uri, String localName) {
|
||||
int index = getIndex(uri, localName);
|
||||
if (index >= 0) {
|
||||
return _values[index];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final void clear() {
|
||||
for (int i = 0; i < _attributeCount; i++) {
|
||||
_values[i] = null;
|
||||
_algorithmData[i] = null;
|
||||
}
|
||||
_attributeCount = 0;
|
||||
}
|
||||
|
||||
// EncodingAlgorithmAttributes
|
||||
|
||||
public final String getAlgorithmURI(int index) {
|
||||
return _algorithmURIs[index];
|
||||
}
|
||||
|
||||
public final int getAlgorithmIndex(int index) {
|
||||
return _algorithmIds[index];
|
||||
}
|
||||
|
||||
public final Object getAlgorithmData(int index) {
|
||||
return _algorithmData[index];
|
||||
}
|
||||
|
||||
public String getAlpababet(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean getToIndex(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
public final void addAttribute(QualifiedName name, String value) {
|
||||
if (_attributeCount == _names.length) {
|
||||
resize();
|
||||
}
|
||||
_names[_attributeCount] = name;
|
||||
_values[_attributeCount++] = value;
|
||||
}
|
||||
|
||||
public final void addAttributeWithAlgorithmData(QualifiedName name, String URI, int id, Object data) {
|
||||
if (_attributeCount == _names.length) {
|
||||
resize();
|
||||
}
|
||||
_names[_attributeCount] = name;
|
||||
_values[_attributeCount] = null;
|
||||
|
||||
_algorithmURIs[_attributeCount] = URI;
|
||||
_algorithmIds[_attributeCount] = id;
|
||||
_algorithmData[_attributeCount++] = data;
|
||||
}
|
||||
|
||||
public final QualifiedName getQualifiedName(int index) {
|
||||
return _names[index];
|
||||
}
|
||||
|
||||
public final String getPrefix(int index) {
|
||||
return _names[index].prefix;
|
||||
}
|
||||
|
||||
private final void resize() {
|
||||
final int newLength = _attributeCount * 3 / 2 + 1;
|
||||
|
||||
QualifiedName[] names = new QualifiedName[newLength];
|
||||
String[] values = new String[newLength];
|
||||
|
||||
String[] algorithmURIs = new String[newLength];
|
||||
int[] algorithmIds = new int[newLength];
|
||||
Object[] algorithmData = new Object[newLength];
|
||||
|
||||
System.arraycopy(_names, 0, names, 0, _attributeCount);
|
||||
System.arraycopy(_values, 0, values, 0, _attributeCount);
|
||||
|
||||
System.arraycopy(_algorithmURIs, 0, algorithmURIs, 0, _attributeCount);
|
||||
System.arraycopy(_algorithmIds, 0, algorithmIds, 0, _attributeCount);
|
||||
System.arraycopy(_algorithmData, 0, algorithmData, 0, _attributeCount);
|
||||
|
||||
_names = names;
|
||||
_values = values;
|
||||
|
||||
_algorithmURIs = algorithmURIs;
|
||||
_algorithmIds = algorithmIds;
|
||||
_algorithmData = algorithmData;
|
||||
}
|
||||
|
||||
private final StringBuffer convertEncodingAlgorithmDataToString(int identifier, String URI, Object data) throws FastInfosetException, IOException {
|
||||
EncodingAlgorithm ea = null;
|
||||
if (identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
|
||||
ea = BuiltInEncodingAlgorithmFactory.getAlgorithm(identifier);
|
||||
} else if (identifier == EncodingAlgorithmIndexes.CDATA) {
|
||||
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.CDATAAlgorithmNotSupported"));
|
||||
} else if (identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
|
||||
if (URI == null) {
|
||||
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.URINotPresent") + identifier);
|
||||
}
|
||||
|
||||
ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(URI);
|
||||
if (ea == null) {
|
||||
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.algorithmNotRegistered") + URI);
|
||||
}
|
||||
} else {
|
||||
// Reserved built-in algorithms for future use
|
||||
// TODO should use sax property to decide if event will be
|
||||
// reported, allows for support through handler if required.
|
||||
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.identifiers10to31Reserved"));
|
||||
}
|
||||
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
ea.convertToCharacters(data, sb);
|
||||
return sb;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.sax;
|
||||
|
||||
public class Features {
|
||||
public static final String NAMESPACES_FEATURE =
|
||||
"http://xml.org/sax/features/namespaces";
|
||||
public static final String NAMESPACE_PREFIXES_FEATURE =
|
||||
"http://xml.org/sax/features/namespace-prefixes";
|
||||
public static final String STRING_INTERNING_FEATURE =
|
||||
"http://xml.org/sax/features/string-interning";
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.sax;
|
||||
|
||||
public class Properties {
|
||||
public static final String LEXICAL_HANDLER_PROPERTY =
|
||||
"http://xml.org/sax/properties/lexical-handler";
|
||||
public static final String DTD_DECLARATION_HANDLER_PROPERTY =
|
||||
"http://xml.org/sax/properties/declaration-handler";
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,597 @@
|
||||
/*
|
||||
* 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.sax;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.Encoder;
|
||||
import com.sun.xml.internal.fastinfoset.EncodingConstants;
|
||||
import com.sun.xml.internal.fastinfoset.QualifiedName;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.sax.FastInfosetWriter;
|
||||
import com.sun.xml.internal.fastinfoset.util.LocalNameQualifiedNamesMap;
|
||||
import java.io.IOException;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmIndexes;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.RestrictedAlphabet;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.sax.EncodingAlgorithmAttributes;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
/**
|
||||
* The Fast Infoset SAX serializer.
|
||||
* <p>
|
||||
* Instantiate this serializer to serialize a fast infoset document in accordance
|
||||
* with the SAX API.
|
||||
* <p>
|
||||
* This utilizes the SAX API in a reverse manner to that of parsing. It is the
|
||||
* responsibility of the client to call the appropriate event methods on the
|
||||
* SAX handlers, and to ensure that such a sequence of methods calls results
|
||||
* in the production well-formed fast infoset documents. The
|
||||
* SAXDocumentSerializer performs no well-formed checks.
|
||||
*
|
||||
* <p>
|
||||
* More than one fast infoset document may be encoded to the
|
||||
* {@link java.io.OutputStream}.
|
||||
*/
|
||||
public class SAXDocumentSerializer extends Encoder implements FastInfosetWriter {
|
||||
protected boolean _elementHasNamespaces = false;
|
||||
|
||||
protected boolean _charactersAsCDATA = false;
|
||||
|
||||
protected SAXDocumentSerializer(boolean v) {
|
||||
super(v);
|
||||
}
|
||||
|
||||
public SAXDocumentSerializer() {
|
||||
}
|
||||
|
||||
|
||||
public void reset() {
|
||||
super.reset();
|
||||
|
||||
_elementHasNamespaces = false;
|
||||
_charactersAsCDATA = false;
|
||||
}
|
||||
|
||||
// ContentHandler
|
||||
|
||||
public final void startDocument() throws SAXException {
|
||||
try {
|
||||
reset();
|
||||
encodeHeader(false);
|
||||
encodeInitialVocabulary();
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("startDocument", e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void endDocument() throws SAXException {
|
||||
try {
|
||||
encodeDocumentTermination();
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("endDocument", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void startPrefixMapping(String prefix, String uri) throws SAXException {
|
||||
try {
|
||||
if (_elementHasNamespaces == false) {
|
||||
encodeTermination();
|
||||
|
||||
// Mark the current buffer position to flag attributes if necessary
|
||||
mark();
|
||||
_elementHasNamespaces = true;
|
||||
|
||||
// Write out Element byte with namespaces
|
||||
write(EncodingConstants.ELEMENT | EncodingConstants.ELEMENT_NAMESPACES_FLAG);
|
||||
}
|
||||
|
||||
encodeNamespaceAttribute(prefix, uri);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("startElement", e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
|
||||
// TODO consider using buffer for encoding of attributes, then pre-counting is not necessary
|
||||
final int attributeCount = (atts != null && atts.getLength() > 0)
|
||||
? countAttributes(atts) : 0;
|
||||
try {
|
||||
if (_elementHasNamespaces) {
|
||||
_elementHasNamespaces = false;
|
||||
|
||||
if (attributeCount > 0) {
|
||||
// Flag the marked byte with attributes
|
||||
_octetBuffer[_markIndex] |= EncodingConstants.ELEMENT_ATTRIBUTE_FLAG;
|
||||
}
|
||||
resetMark();
|
||||
|
||||
write(EncodingConstants.TERMINATOR);
|
||||
|
||||
_b = 0;
|
||||
} else {
|
||||
encodeTermination();
|
||||
|
||||
_b = EncodingConstants.ELEMENT;
|
||||
if (attributeCount > 0) {
|
||||
_b |= EncodingConstants.ELEMENT_ATTRIBUTE_FLAG;
|
||||
}
|
||||
}
|
||||
|
||||
encodeElement(namespaceURI, qName, localName);
|
||||
|
||||
if (attributeCount > 0) {
|
||||
encodeAttributes(atts);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("startElement", e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException("startElement", e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void endElement(String namespaceURI, String localName, String qName) throws SAXException {
|
||||
try {
|
||||
encodeElementTermination();
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("endElement", e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void characters(char[] ch, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getIgnoreWhiteSpaceTextContent() &&
|
||||
isWhiteSpace(ch, start, length)) return;
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
if (!_charactersAsCDATA) {
|
||||
encodeCharacters(ch, start, length);
|
||||
} else {
|
||||
encodeCIIBuiltInAlgorithmDataAsCDATA(ch, start, length);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
|
||||
if (getIgnoreWhiteSpaceTextContent()) return;
|
||||
|
||||
characters(ch, start, length);
|
||||
}
|
||||
|
||||
public final void processingInstruction(String target, String data) throws SAXException {
|
||||
try {
|
||||
if (getIgnoreProcesingInstructions()) return;
|
||||
|
||||
if (target.length() == 0) {
|
||||
throw new SAXException(CommonResourceBundle.getInstance().
|
||||
getString("message.processingInstructionTargetIsEmpty"));
|
||||
}
|
||||
encodeTermination();
|
||||
|
||||
encodeProcessingInstruction(target, data);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("processingInstruction", e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void setDocumentLocator(org.xml.sax.Locator locator) {
|
||||
}
|
||||
|
||||
public final void skippedEntity(String name) throws SAXException {
|
||||
}
|
||||
|
||||
|
||||
|
||||
// LexicalHandler
|
||||
|
||||
public final void comment(char[] ch, int start, int length) throws SAXException {
|
||||
try {
|
||||
if (getIgnoreComments()) return;
|
||||
|
||||
encodeTermination();
|
||||
|
||||
encodeComment(ch, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("startElement", e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void startCDATA() throws SAXException {
|
||||
_charactersAsCDATA = true;
|
||||
}
|
||||
|
||||
public final void endCDATA() throws SAXException {
|
||||
_charactersAsCDATA = false;
|
||||
}
|
||||
|
||||
public final void startDTD(String name, String publicId, String systemId) throws SAXException {
|
||||
if (getIgnoreDTD()) return;
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeDocumentTypeDeclaration(publicId, systemId);
|
||||
encodeElementTermination();
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("startDTD", e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void endDTD() throws SAXException {
|
||||
}
|
||||
|
||||
public final void startEntity(String name) throws SAXException {
|
||||
}
|
||||
|
||||
public final void endEntity(String name) throws SAXException {
|
||||
}
|
||||
|
||||
|
||||
// EncodingAlgorithmContentHandler
|
||||
|
||||
public final void octets(String URI, int id, byte[] b, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeNonIdentifyingStringOnThirdBit(URI, id, b, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void object(String URI, int id, Object data) throws SAXException {
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeNonIdentifyingStringOnThirdBit(URI, id, data);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// PrimitiveTypeContentHandler
|
||||
|
||||
public final void bytes(byte[] b, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIOctetAlgorithmData(EncodingAlgorithmIndexes.BASE64, b, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void shorts(short[] s, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.SHORT, s, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void ints(int[] i, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.INT, i, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void longs(long[] l, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.LONG, l, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void booleans(boolean[] b, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.BOOLEAN, b, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void floats(float[] f, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.FLOAT, f, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void doubles(double[] d, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.DOUBLE, d, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void uuids(long[] msblsb, int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIBuiltInAlgorithmData(EncodingAlgorithmIndexes.UUID, msblsb, start, length);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// RestrictedAlphabetContentHandler
|
||||
|
||||
public void numericCharacters(char ch[], int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
final boolean addToTable = isCharacterContentChunkLengthMatchesLimit(length);
|
||||
encodeNumericFourBitCharacters(ch, start, length, addToTable);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void dateTimeCharacters(char ch[], int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
final boolean addToTable = isCharacterContentChunkLengthMatchesLimit(length);
|
||||
encodeDateTimeFourBitCharacters(ch, start, length, addToTable);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void alphabetCharacters(String alphabet, char ch[], int start, int length) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
final boolean addToTable = isCharacterContentChunkLengthMatchesLimit(length);
|
||||
encodeAlphabetCharacters(alphabet, ch, start, length, addToTable);
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// ExtendedContentHandler
|
||||
|
||||
public void characters(char[] ch, int start, int length, boolean index) throws SAXException {
|
||||
if (length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getIgnoreWhiteSpaceTextContent() &&
|
||||
isWhiteSpace(ch, start, length)) return;
|
||||
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
if (!_charactersAsCDATA) {
|
||||
encodeNonIdentifyingStringOnThirdBit(ch, start, length, _v.characterContentChunk, index, true);
|
||||
} else {
|
||||
encodeCIIBuiltInAlgorithmDataAsCDATA(ch, start, length);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new SAXException(e);
|
||||
} catch (FastInfosetException e) {
|
||||
throw new SAXException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected final int countAttributes(Attributes atts) {
|
||||
// Count attributes ignoring any in the XMLNS namespace
|
||||
// Note, such attributes may be produced when transforming from a DOM node
|
||||
int count = 0;
|
||||
for (int i = 0; i < atts.getLength(); i++) {
|
||||
final String uri = atts.getURI(i);
|
||||
if (uri == "http://www.w3.org/2000/xmlns/" || uri.equals("http://www.w3.org/2000/xmlns/")) {
|
||||
continue;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
protected void encodeAttributes(Attributes atts) throws IOException, FastInfosetException {
|
||||
boolean addToTable;
|
||||
boolean mustBeAddedToTable;
|
||||
String value;
|
||||
if (atts instanceof EncodingAlgorithmAttributes) {
|
||||
final EncodingAlgorithmAttributes eAtts = (EncodingAlgorithmAttributes)atts;
|
||||
Object data;
|
||||
String alphabet;
|
||||
for (int i = 0; i < eAtts.getLength(); i++) {
|
||||
if (encodeAttribute(atts.getURI(i), atts.getQName(i), atts.getLocalName(i))) {
|
||||
data = eAtts.getAlgorithmData(i);
|
||||
// If data is null then there is no algorithm data
|
||||
if (data == null) {
|
||||
value = eAtts.getValue(i);
|
||||
addToTable = isAttributeValueLengthMatchesLimit(value.length());
|
||||
mustBeAddedToTable = eAtts.getToIndex(i);
|
||||
|
||||
alphabet = eAtts.getAlpababet(i);
|
||||
if (alphabet == null) {
|
||||
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, mustBeAddedToTable);
|
||||
} else if (alphabet == RestrictedAlphabet.DATE_TIME_CHARACTERS) {
|
||||
encodeDateTimeNonIdentifyingStringOnFirstBit(
|
||||
value, addToTable, mustBeAddedToTable);
|
||||
} else if (alphabet == RestrictedAlphabet.NUMERIC_CHARACTERS) {
|
||||
encodeNumericNonIdentifyingStringOnFirstBit(
|
||||
value, addToTable, mustBeAddedToTable);
|
||||
} else {
|
||||
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, mustBeAddedToTable);
|
||||
}
|
||||
} else {
|
||||
encodeNonIdentifyingStringOnFirstBit(eAtts.getAlgorithmURI(i),
|
||||
eAtts.getAlgorithmIndex(i), data);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < atts.getLength(); i++) {
|
||||
if (encodeAttribute(atts.getURI(i), atts.getQName(i), atts.getLocalName(i))) {
|
||||
value = atts.getValue(i);
|
||||
addToTable = isAttributeValueLengthMatchesLimit(value.length());
|
||||
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
_b = EncodingConstants.TERMINATOR;
|
||||
_terminate = true;
|
||||
}
|
||||
|
||||
protected void encodeElement(String namespaceURI, String qName, String localName) throws IOException {
|
||||
LocalNameQualifiedNamesMap.Entry entry = _v.elementName.obtainEntry(qName);
|
||||
if (entry._valueIndex > 0) {
|
||||
QualifiedName[] names = entry._value;
|
||||
for (int i = 0; i < entry._valueIndex; i++) {
|
||||
final QualifiedName n = names[i];
|
||||
if ((namespaceURI == n.namespaceName || namespaceURI.equals(n.namespaceName))) {
|
||||
encodeNonZeroIntegerOnThirdBit(names[i].index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
encodeLiteralElementQualifiedNameOnThirdBit(namespaceURI, getPrefixFromQualifiedName(qName),
|
||||
localName, entry);
|
||||
}
|
||||
|
||||
protected boolean encodeAttribute(String namespaceURI, String qName, String localName) throws IOException {
|
||||
LocalNameQualifiedNamesMap.Entry entry = _v.attributeName.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))) {
|
||||
encodeNonZeroIntegerOnSecondBitFirstBitZero(names[i].index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return encodeLiteralAttributeQualifiedNameOnSecondBit(namespaceURI, getPrefixFromQualifiedName(qName),
|
||||
localName, entry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
/*
|
||||
* 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.sax;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.EncodingConstants;
|
||||
import com.sun.xml.internal.fastinfoset.QualifiedName;
|
||||
import com.sun.xml.internal.fastinfoset.util.KeyIntMap;
|
||||
import com.sun.xml.internal.fastinfoset.util.LocalNameQualifiedNamesMap;
|
||||
import com.sun.xml.internal.fastinfoset.util.StringIntMap;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import org.xml.sax.SAXException;
|
||||
import java.util.Map;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.RestrictedAlphabet;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.sax.EncodingAlgorithmAttributes;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
/**
|
||||
* The Fast Infoset SAX serializer that maps prefixes to user specified prefixes
|
||||
* that are specified in a namespace URI to prefix map.
|
||||
* <p>
|
||||
* This serializer will not preserve the original prefixes and this serializer
|
||||
* should not be used when prefixes need to be preserved, such as the case
|
||||
* when there are qualified names in content.
|
||||
* <p>
|
||||
* A namespace URI to prefix map is utilized such that the prefixes
|
||||
* in the map are utilized rather than the prefixes specified in
|
||||
* the qualified name for elements and attributes.
|
||||
* <p>
|
||||
* Any namespace declarations with a namespace URI that is not present in
|
||||
* the map are added.
|
||||
* <p>
|
||||
*/
|
||||
public class SAXDocumentSerializerWithPrefixMapping extends SAXDocumentSerializer {
|
||||
protected Map _namespaceToPrefixMapping;
|
||||
protected Map _prefixToPrefixMapping;
|
||||
protected String _lastCheckedNamespace;
|
||||
protected String _lastCheckedPrefix;
|
||||
|
||||
protected StringIntMap _declaredNamespaces;
|
||||
|
||||
public SAXDocumentSerializerWithPrefixMapping(Map namespaceToPrefixMapping) {
|
||||
// Use the local name to look up elements/attributes
|
||||
super(true);
|
||||
_namespaceToPrefixMapping = new HashMap(namespaceToPrefixMapping);
|
||||
_prefixToPrefixMapping = new HashMap();
|
||||
|
||||
// Empty prefix
|
||||
_namespaceToPrefixMapping.put("", "");
|
||||
// 'xml' prefix
|
||||
_namespaceToPrefixMapping.put(EncodingConstants.XML_NAMESPACE_NAME, EncodingConstants.XML_NAMESPACE_PREFIX);
|
||||
|
||||
_declaredNamespaces = new StringIntMap(4);
|
||||
}
|
||||
|
||||
public final void startPrefixMapping(String prefix, String uri) throws SAXException {
|
||||
try {
|
||||
if (_elementHasNamespaces == false) {
|
||||
encodeTermination();
|
||||
|
||||
// Mark the current buffer position to flag attributes if necessary
|
||||
mark();
|
||||
_elementHasNamespaces = true;
|
||||
|
||||
// Write out Element byte with namespaces
|
||||
write(EncodingConstants.ELEMENT | EncodingConstants.ELEMENT_NAMESPACES_FLAG);
|
||||
|
||||
_declaredNamespaces.clear();
|
||||
_declaredNamespaces.obtainIndex(uri);
|
||||
} else {
|
||||
if (_declaredNamespaces.obtainIndex(uri) != KeyIntMap.NOT_PRESENT) {
|
||||
final String p = getPrefix(uri);
|
||||
if (p != null) {
|
||||
_prefixToPrefixMapping.put(prefix, p);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final String p = getPrefix(uri);
|
||||
if (p != null) {
|
||||
encodeNamespaceAttribute(p, uri);
|
||||
_prefixToPrefixMapping.put(prefix, p);
|
||||
} else {
|
||||
putPrefix(uri, prefix);
|
||||
encodeNamespaceAttribute(prefix, uri);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new SAXException("startElement", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void encodeElement(String namespaceURI, String qName, String localName) throws IOException {
|
||||
LocalNameQualifiedNamesMap.Entry entry = _v.elementName.obtainEntry(localName);
|
||||
if (entry._valueIndex > 0) {
|
||||
if (encodeElementMapEntry(entry, namespaceURI)) return;
|
||||
// Check the entry is a member of the read only map
|
||||
if (_v.elementName.isQNameFromReadOnlyMap(entry._value[0])) {
|
||||
entry = _v.elementName.obtainDynamicEntry(localName);
|
||||
if (entry._valueIndex > 0) {
|
||||
if (encodeElementMapEntry(entry, namespaceURI)) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
encodeLiteralElementQualifiedNameOnThirdBit(namespaceURI, getPrefix(namespaceURI),
|
||||
localName, entry);
|
||||
}
|
||||
|
||||
protected boolean encodeElementMapEntry(LocalNameQualifiedNamesMap.Entry entry, String namespaceURI) throws IOException {
|
||||
QualifiedName[] names = entry._value;
|
||||
for (int i = 0; i < entry._valueIndex; i++) {
|
||||
if ((namespaceURI == names[i].namespaceName || namespaceURI.equals(names[i].namespaceName))) {
|
||||
encodeNonZeroIntegerOnThirdBit(names[i].index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected final void encodeAttributes(Attributes atts) throws IOException, FastInfosetException {
|
||||
boolean addToTable;
|
||||
boolean mustToBeAddedToTable;
|
||||
String value;
|
||||
if (atts instanceof EncodingAlgorithmAttributes) {
|
||||
final EncodingAlgorithmAttributes eAtts = (EncodingAlgorithmAttributes)atts;
|
||||
Object data;
|
||||
String alphabet;
|
||||
for (int i = 0; i < eAtts.getLength(); i++) {
|
||||
final String uri = atts.getURI(i);
|
||||
if (encodeAttribute(uri, atts.getQName(i), atts.getLocalName(i))) {
|
||||
data = eAtts.getAlgorithmData(i);
|
||||
// If data is null then there is no algorithm data
|
||||
if (data == null) {
|
||||
value = eAtts.getValue(i);
|
||||
addToTable = isAttributeValueLengthMatchesLimit(value.length());
|
||||
mustToBeAddedToTable = eAtts.getToIndex(i);
|
||||
alphabet = eAtts.getAlpababet(i);
|
||||
if (alphabet == null) {
|
||||
if (uri == "http://www.w3.org/2001/XMLSchema-instance" ||
|
||||
uri.equals("http://www.w3.org/2001/XMLSchema-instance")) {
|
||||
value = convertQName(value);
|
||||
}
|
||||
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, mustToBeAddedToTable);
|
||||
} else if (alphabet == RestrictedAlphabet.DATE_TIME_CHARACTERS) {
|
||||
encodeDateTimeNonIdentifyingStringOnFirstBit(
|
||||
value, addToTable, mustToBeAddedToTable);
|
||||
} else if (alphabet == RestrictedAlphabet.NUMERIC_CHARACTERS) {
|
||||
encodeNumericNonIdentifyingStringOnFirstBit(
|
||||
value, addToTable, mustToBeAddedToTable);
|
||||
} else {
|
||||
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, mustToBeAddedToTable);
|
||||
}
|
||||
} else {
|
||||
encodeNonIdentifyingStringOnFirstBit(eAtts.getAlgorithmURI(i),
|
||||
eAtts.getAlgorithmIndex(i), data);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < atts.getLength(); i++) {
|
||||
final String uri = atts.getURI(i);
|
||||
if (encodeAttribute(atts.getURI(i), atts.getQName(i), atts.getLocalName(i))) {
|
||||
value = atts.getValue(i);
|
||||
addToTable = isAttributeValueLengthMatchesLimit(value.length());
|
||||
|
||||
if (uri == "http://www.w3.org/2001/XMLSchema-instance" ||
|
||||
uri.equals("http://www.w3.org/2001/XMLSchema-instance")) {
|
||||
value = convertQName(value);
|
||||
}
|
||||
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
_b = EncodingConstants.TERMINATOR;
|
||||
_terminate = true;
|
||||
}
|
||||
|
||||
private String convertQName(String qName) {
|
||||
int i = qName.indexOf(':');
|
||||
String prefix = "";
|
||||
String localName = qName;
|
||||
if (i != -1) {
|
||||
prefix = qName.substring(0, i);
|
||||
localName = qName.substring(i + 1);
|
||||
}
|
||||
|
||||
String p = (String)_prefixToPrefixMapping.get(prefix);
|
||||
if (p != null) {
|
||||
if (p.length() == 0)
|
||||
return localName;
|
||||
else
|
||||
return p + ":" + localName;
|
||||
} else {
|
||||
return qName;
|
||||
}
|
||||
}
|
||||
|
||||
protected final boolean encodeAttribute(String namespaceURI, String qName, String localName) throws IOException {
|
||||
LocalNameQualifiedNamesMap.Entry entry = _v.attributeName.obtainEntry(localName);
|
||||
if (entry._valueIndex > 0) {
|
||||
if (encodeAttributeMapEntry(entry, namespaceURI)) return true;
|
||||
// Check the entry is a member of the read only map
|
||||
if (_v.attributeName.isQNameFromReadOnlyMap(entry._value[0])) {
|
||||
entry = _v.attributeName.obtainDynamicEntry(localName);
|
||||
if (entry._valueIndex > 0) {
|
||||
if (encodeAttributeMapEntry(entry, namespaceURI)) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return encodeLiteralAttributeQualifiedNameOnSecondBit(namespaceURI, getPrefix(namespaceURI),
|
||||
localName, entry);
|
||||
}
|
||||
|
||||
protected boolean encodeAttributeMapEntry(LocalNameQualifiedNamesMap.Entry entry, String namespaceURI) throws IOException {
|
||||
QualifiedName[] names = entry._value;
|
||||
for (int i = 0; i < entry._valueIndex; i++) {
|
||||
if ((namespaceURI == names[i].namespaceName || namespaceURI.equals(names[i].namespaceName))) {
|
||||
encodeNonZeroIntegerOnSecondBitFirstBitZero(names[i].index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected final String getPrefix(String namespaceURI) {
|
||||
if (_lastCheckedNamespace == namespaceURI) return _lastCheckedPrefix;
|
||||
|
||||
_lastCheckedNamespace = namespaceURI;
|
||||
return _lastCheckedPrefix = (String)_namespaceToPrefixMapping.get(namespaceURI);
|
||||
}
|
||||
|
||||
protected final void putPrefix(String namespaceURI, String prefix) {
|
||||
_namespaceToPrefixMapping.put(namespaceURI, prefix);
|
||||
|
||||
_lastCheckedNamespace = namespaceURI;
|
||||
_lastCheckedPrefix = prefix;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* 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.sax;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class SystemIdResolver {
|
||||
|
||||
public SystemIdResolver() {
|
||||
}
|
||||
|
||||
public static String getAbsoluteURIFromRelative(String localPath) {
|
||||
if (localPath == null || localPath.length() == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String absolutePath = localPath;
|
||||
if (!isAbsolutePath(localPath)) {
|
||||
try {
|
||||
absolutePath = getAbsolutePathFromRelativePath(localPath);
|
||||
}
|
||||
catch (SecurityException se) {
|
||||
return "file:" + localPath;
|
||||
}
|
||||
}
|
||||
|
||||
String urlString;
|
||||
if (null != absolutePath) {
|
||||
urlString = absolutePath.startsWith(File.separator) ?
|
||||
("file://" + absolutePath) :
|
||||
("file:///" + absolutePath);
|
||||
}
|
||||
else {
|
||||
urlString = "file:" + localPath;
|
||||
}
|
||||
|
||||
return replaceChars(urlString);
|
||||
}
|
||||
|
||||
private static String getAbsolutePathFromRelativePath(String relativePath) {
|
||||
return new File(relativePath).getAbsolutePath();
|
||||
}
|
||||
|
||||
public static boolean isAbsoluteURI(String systemId) {
|
||||
if (systemId == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isWindowsAbsolutePath(systemId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final int fragmentIndex = systemId.indexOf('#');
|
||||
final int queryIndex = systemId.indexOf('?');
|
||||
final int slashIndex = systemId.indexOf('/');
|
||||
final int colonIndex = systemId.indexOf(':');
|
||||
|
||||
int index = systemId.length() -1;
|
||||
if (fragmentIndex > 0) {
|
||||
index = fragmentIndex;
|
||||
}
|
||||
if (queryIndex > 0 && queryIndex < index) {
|
||||
index = queryIndex;
|
||||
}
|
||||
if (slashIndex > 0 && slashIndex <index) {
|
||||
index = slashIndex;
|
||||
}
|
||||
return (colonIndex > 0) && (colonIndex < index);
|
||||
}
|
||||
|
||||
public static boolean isAbsolutePath(String systemId) {
|
||||
if(systemId == null)
|
||||
return false;
|
||||
final File file = new File(systemId);
|
||||
return file.isAbsolute();
|
||||
|
||||
}
|
||||
|
||||
private static boolean isWindowsAbsolutePath(String systemId) {
|
||||
if(!isAbsolutePath(systemId))
|
||||
return false;
|
||||
if (systemId.length() > 2
|
||||
&& systemId.charAt(1) == ':'
|
||||
&& Character.isLetter(systemId.charAt(0))
|
||||
&& (systemId.charAt(2) == '\\' || systemId.charAt(2) == '/'))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String replaceChars(String str) {
|
||||
StringBuffer buf = new StringBuffer(str);
|
||||
int length = buf.length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
char currentChar = buf.charAt(i);
|
||||
// Replace space with "%20"
|
||||
if (currentChar == ' ') {
|
||||
buf.setCharAt(i, '%');
|
||||
buf.insert(i+1, "20");
|
||||
length = length + 2;
|
||||
i = i + 2;
|
||||
}
|
||||
// Replace backslash with forward slash
|
||||
else if (currentChar == '\\') {
|
||||
buf.setCharAt(i, '/');
|
||||
}
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static String getAbsoluteURI(String systemId) {
|
||||
String absoluteURI = systemId;
|
||||
if (isAbsoluteURI(systemId)) {
|
||||
if (systemId.startsWith("file:")) {
|
||||
String str = systemId.substring(5);
|
||||
|
||||
if (str != null && str.startsWith("/")) {
|
||||
if (str.startsWith("///") || !str.startsWith("//")) {
|
||||
int secondColonIndex = systemId.indexOf(':', 5);
|
||||
if (secondColonIndex > 0) {
|
||||
String localPath = systemId.substring(secondColonIndex-1);
|
||||
try {
|
||||
if (!isAbsolutePath(localPath))
|
||||
absoluteURI = systemId.substring(0, secondColonIndex-1) +
|
||||
getAbsolutePathFromRelativePath(localPath);
|
||||
}
|
||||
catch (SecurityException se) {
|
||||
return systemId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return getAbsoluteURIFromRelative(systemId.substring(5));
|
||||
}
|
||||
|
||||
return replaceChars(absoluteURI);
|
||||
}
|
||||
else {
|
||||
return systemId;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return getAbsoluteURIFromRelative(systemId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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.stax;
|
||||
|
||||
import javax.xml.stream.Location;
|
||||
|
||||
|
||||
public class EventLocation implements Location{
|
||||
String _systemId = null;
|
||||
String _publicId = null;
|
||||
int _column = -1;
|
||||
int _line = -1;
|
||||
int _charOffset = -1;
|
||||
|
||||
EventLocation() {
|
||||
}
|
||||
|
||||
//explicitly create a nil location
|
||||
public static Location getNilLocation() {
|
||||
return new EventLocation();
|
||||
}
|
||||
/**
|
||||
* Return the line number where the current event ends,
|
||||
* returns -1 if none is available.
|
||||
* @return the current line number
|
||||
*/
|
||||
public int getLineNumber(){
|
||||
return _line;
|
||||
}
|
||||
/**
|
||||
* Return the column number where the current event ends,
|
||||
* returns -1 if none is available.
|
||||
* @return the current column number
|
||||
*/
|
||||
public int getColumnNumber() {
|
||||
return _column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the byte or character offset into the input source this location
|
||||
* is pointing to. If the input source is a file or a byte stream then
|
||||
* this is the byte offset into that stream, but if the input source is
|
||||
* a character media then the offset is the character offset.
|
||||
* Returns -1 if there is no offset available.
|
||||
* @return the current offset
|
||||
*/
|
||||
public int getCharacterOffset(){
|
||||
return _charOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the public ID of the XML
|
||||
* @return the public ID, or null if not available
|
||||
*/
|
||||
public String getPublicId(){
|
||||
return _publicId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the system ID of the XML
|
||||
* @return the system ID, or null if not available
|
||||
*/
|
||||
public String getSystemId(){
|
||||
return _systemId;
|
||||
}
|
||||
|
||||
public void setLineNumber(int line) {
|
||||
_line = line;
|
||||
}
|
||||
public void setColumnNumber(int col) {
|
||||
_column = col;
|
||||
}
|
||||
public void setCharacterOffset(int offset) {
|
||||
_charOffset = offset;
|
||||
}
|
||||
public void setPublicId(String id) {
|
||||
_publicId = id;
|
||||
}
|
||||
public void setSystemId(String id) {
|
||||
_systemId = id;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
StringBuffer sbuffer = new StringBuffer() ;
|
||||
sbuffer.append("Line number = " + _line);
|
||||
sbuffer.append("\n") ;
|
||||
sbuffer.append("Column number = " + _column);
|
||||
sbuffer.append("\n") ;
|
||||
sbuffer.append("System Id = " + _systemId);
|
||||
sbuffer.append("\n") ;
|
||||
sbuffer.append("Public Id = " + _publicId);
|
||||
sbuffer.append("\n") ;
|
||||
sbuffer.append("CharacterOffset = " + _charOffset);
|
||||
sbuffer.append("\n") ;
|
||||
return sbuffer.toString();
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,856 @@
|
||||
/*
|
||||
* 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.stax;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.Encoder;
|
||||
import com.sun.xml.internal.fastinfoset.EncodingConstants;
|
||||
import com.sun.xml.internal.fastinfoset.util.NamespaceContextImplementation;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.EmptyStackException;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmIndexes;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
import com.sun.xml.internal.fastinfoset.QualifiedName;
|
||||
import com.sun.xml.internal.fastinfoset.util.LocalNameQualifiedNamesMap;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.stax.LowLevelFastInfosetStreamWriter;
|
||||
|
||||
/**
|
||||
* The Fast Infoset StAX serializer.
|
||||
* <p>
|
||||
* Instantiate this serializer to serialize a fast infoset document in accordance
|
||||
* with the StAX API.
|
||||
*
|
||||
* <p>
|
||||
* More than one fast infoset document may be encoded to the
|
||||
* {@link java.io.OutputStream}.
|
||||
*/
|
||||
public class StAXDocumentSerializer extends Encoder
|
||||
implements XMLStreamWriter, LowLevelFastInfosetStreamWriter {
|
||||
protected StAXManager _manager;
|
||||
|
||||
protected String _encoding;
|
||||
/**
|
||||
* Local name of current element.
|
||||
*/
|
||||
protected String _currentLocalName;
|
||||
|
||||
/**
|
||||
* Namespace of current element.
|
||||
*/
|
||||
protected String _currentUri;
|
||||
|
||||
/**
|
||||
* Prefix of current element.
|
||||
*/
|
||||
protected String _currentPrefix;
|
||||
|
||||
/**
|
||||
* This flag indicates when there is a pending start element event.
|
||||
*/
|
||||
protected boolean _inStartElement = false;
|
||||
|
||||
/**
|
||||
* This flag indicates if the current element is empty.
|
||||
*/
|
||||
protected boolean _isEmptyElement = false;
|
||||
|
||||
/**
|
||||
* List of attributes qnames and values defined in the current element.
|
||||
*/
|
||||
protected String[] _attributesArray = new String[4 * 16];
|
||||
protected int _attributesArrayIndex = 0;
|
||||
|
||||
protected boolean[] _nsSupportContextStack = new boolean[32];
|
||||
protected int _stackCount = -1;
|
||||
|
||||
/**
|
||||
* Mapping between uris and prefixes.
|
||||
*/
|
||||
protected NamespaceContextImplementation _nsContext =
|
||||
new NamespaceContextImplementation();
|
||||
|
||||
/**
|
||||
* List of namespaces defined in the current element.
|
||||
*/
|
||||
protected String[] _namespacesArray = new String[2 * 8];
|
||||
protected int _namespacesArrayIndex = 0;
|
||||
|
||||
public StAXDocumentSerializer() {
|
||||
super(true);
|
||||
_manager = new StAXManager(StAXManager.CONTEXT_WRITER);
|
||||
}
|
||||
|
||||
public StAXDocumentSerializer(OutputStream outputStream) {
|
||||
super(true);
|
||||
setOutputStream(outputStream);
|
||||
_manager = new StAXManager(StAXManager.CONTEXT_WRITER);
|
||||
}
|
||||
|
||||
public StAXDocumentSerializer(OutputStream outputStream, StAXManager manager) {
|
||||
super(true);
|
||||
setOutputStream(outputStream);
|
||||
_manager = manager;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
super.reset();
|
||||
|
||||
_attributesArrayIndex = 0;
|
||||
_namespacesArrayIndex = 0;
|
||||
|
||||
_nsContext.reset();
|
||||
_stackCount = -1;
|
||||
|
||||
_currentUri = _currentPrefix = null;
|
||||
_currentLocalName = null;
|
||||
|
||||
_inStartElement = _isEmptyElement = false;
|
||||
}
|
||||
|
||||
// -- XMLStreamWriter Interface -------------------------------------------
|
||||
|
||||
public void writeStartDocument() throws XMLStreamException {
|
||||
writeStartDocument("finf", "1.0");
|
||||
}
|
||||
|
||||
public void writeStartDocument(String version) throws XMLStreamException {
|
||||
writeStartDocument("finf", version);
|
||||
}
|
||||
|
||||
public void writeStartDocument(String encoding, String version)
|
||||
throws XMLStreamException
|
||||
{
|
||||
reset();
|
||||
|
||||
try {
|
||||
encodeHeader(false);
|
||||
encodeInitialVocabulary();
|
||||
} catch (IOException e) {
|
||||
throw new XMLStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeEndDocument() throws XMLStreamException {
|
||||
try {
|
||||
|
||||
// terminate all elements not terminated
|
||||
// by writeEndElement
|
||||
for(;_stackCount >= 0; _stackCount--) {
|
||||
writeEndElement();
|
||||
}
|
||||
|
||||
encodeDocumentTermination();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new XMLStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void close() throws XMLStreamException {
|
||||
reset();
|
||||
}
|
||||
|
||||
public void flush() throws XMLStreamException {
|
||||
try {
|
||||
_s.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new XMLStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeStartElement(String localName)
|
||||
throws XMLStreamException
|
||||
{
|
||||
// TODO is it necessary for FI to obtain the default namespace in scope?
|
||||
writeStartElement("", localName, "");
|
||||
}
|
||||
|
||||
public void writeStartElement(String namespaceURI, String localName)
|
||||
throws XMLStreamException
|
||||
{
|
||||
writeStartElement("", localName, namespaceURI);
|
||||
}
|
||||
|
||||
public void writeStartElement(String prefix, String localName,
|
||||
String namespaceURI) throws XMLStreamException
|
||||
{
|
||||
encodeTerminationAndCurrentElement(false);
|
||||
|
||||
_inStartElement = true;
|
||||
_isEmptyElement = false;
|
||||
|
||||
_currentLocalName = localName;
|
||||
_currentPrefix = prefix;
|
||||
_currentUri = namespaceURI;
|
||||
|
||||
_stackCount++;
|
||||
if (_stackCount == _nsSupportContextStack.length) {
|
||||
boolean[] nsSupportContextStack = new boolean[_stackCount * 2];
|
||||
System.arraycopy(_nsSupportContextStack, 0, nsSupportContextStack, 0, _nsSupportContextStack.length);
|
||||
_nsSupportContextStack = nsSupportContextStack;
|
||||
}
|
||||
|
||||
_nsSupportContextStack[_stackCount] = false;
|
||||
}
|
||||
|
||||
public void writeEmptyElement(String localName)
|
||||
throws XMLStreamException
|
||||
{
|
||||
writeEmptyElement("", localName, "");
|
||||
}
|
||||
|
||||
public void writeEmptyElement(String namespaceURI, String localName)
|
||||
throws XMLStreamException
|
||||
{
|
||||
writeEmptyElement("", localName, namespaceURI);
|
||||
}
|
||||
|
||||
public void writeEmptyElement(String prefix, String localName,
|
||||
String namespaceURI) throws XMLStreamException
|
||||
{
|
||||
encodeTerminationAndCurrentElement(false);
|
||||
|
||||
_isEmptyElement = _inStartElement = true;
|
||||
|
||||
_currentLocalName = localName;
|
||||
_currentPrefix = prefix;
|
||||
_currentUri = namespaceURI;
|
||||
|
||||
_stackCount++;
|
||||
if (_stackCount == _nsSupportContextStack.length) {
|
||||
boolean[] nsSupportContextStack = new boolean[_stackCount * 2];
|
||||
System.arraycopy(_nsSupportContextStack, 0, nsSupportContextStack, 0, _nsSupportContextStack.length);
|
||||
_nsSupportContextStack = nsSupportContextStack;
|
||||
}
|
||||
|
||||
_nsSupportContextStack[_stackCount] = false;
|
||||
}
|
||||
|
||||
public void writeEndElement() throws XMLStreamException {
|
||||
if (_inStartElement) {
|
||||
encodeTerminationAndCurrentElement(false);
|
||||
}
|
||||
|
||||
try {
|
||||
encodeElementTermination();
|
||||
if (_nsSupportContextStack[_stackCount--] == true) {
|
||||
_nsContext.popContext();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new XMLStreamException(e);
|
||||
}
|
||||
catch (EmptyStackException e) {
|
||||
throw new XMLStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void writeAttribute(String localName, String value)
|
||||
throws XMLStreamException
|
||||
{
|
||||
writeAttribute("", "", localName, value);
|
||||
}
|
||||
|
||||
public void writeAttribute(String namespaceURI, String localName,
|
||||
String value) throws XMLStreamException
|
||||
{
|
||||
String prefix = "";
|
||||
|
||||
// Find prefix for attribute, ignoring default namespace
|
||||
if (namespaceURI.length() > 0) {
|
||||
prefix = _nsContext.getNonDefaultPrefix(namespaceURI);
|
||||
|
||||
// Undeclared prefix or ignorable default ns?
|
||||
if (prefix == null || prefix.length() == 0) {
|
||||
// Workaround for BUG in SAX NamespaceSupport helper
|
||||
// which incorrectly defines namespace declaration URI
|
||||
if (namespaceURI == EncodingConstants.XMLNS_NAMESPACE_NAME ||
|
||||
namespaceURI.equals(EncodingConstants.XMLNS_NAMESPACE_NAME)) {
|
||||
// TODO
|
||||
// Need to check carefully the rule for the writing of
|
||||
// namespaces in StAX. Is it safe to ignore such
|
||||
// attributes, as declarations will be made using the
|
||||
// writeNamespace method
|
||||
return;
|
||||
}
|
||||
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.URIUnbound", new Object[]{namespaceURI}));
|
||||
}
|
||||
}
|
||||
writeAttribute(prefix, namespaceURI, localName, value);
|
||||
}
|
||||
|
||||
public void writeAttribute(String prefix, String namespaceURI,
|
||||
String localName, String value) throws XMLStreamException
|
||||
{
|
||||
if (!_inStartElement) {
|
||||
throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.attributeWritingNotAllowed"));
|
||||
}
|
||||
|
||||
// TODO
|
||||
// Need to check carefully the rule for the writing of
|
||||
// namespaces in StAX. Is it safe to ignore such
|
||||
// attributes, as declarations will be made using the
|
||||
// writeNamespace method
|
||||
if (namespaceURI == EncodingConstants.XMLNS_NAMESPACE_NAME ||
|
||||
namespaceURI.equals(EncodingConstants.XMLNS_NAMESPACE_NAME)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_attributesArrayIndex == _attributesArray.length) {
|
||||
final String[] attributesArray = new String[_attributesArrayIndex * 2];
|
||||
System.arraycopy(_attributesArray, 0, attributesArray, 0, _attributesArrayIndex);
|
||||
_attributesArray = attributesArray;
|
||||
}
|
||||
|
||||
_attributesArray[_attributesArrayIndex++] = namespaceURI;
|
||||
_attributesArray[_attributesArrayIndex++] = prefix;
|
||||
_attributesArray[_attributesArrayIndex++] = localName;
|
||||
_attributesArray[_attributesArrayIndex++] = value;
|
||||
}
|
||||
|
||||
public void writeNamespace(String prefix, String namespaceURI)
|
||||
throws XMLStreamException
|
||||
{
|
||||
if (prefix == null || prefix.length() == 0 || prefix.equals(EncodingConstants.XMLNS_NAMESPACE_PREFIX)) {
|
||||
writeDefaultNamespace(namespaceURI);
|
||||
}
|
||||
else {
|
||||
if (!_inStartElement) {
|
||||
throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.attributeWritingNotAllowed"));
|
||||
}
|
||||
|
||||
if (_namespacesArrayIndex == _namespacesArray.length) {
|
||||
final String[] namespacesArray = new String[_namespacesArrayIndex * 2];
|
||||
System.arraycopy(_namespacesArray, 0, namespacesArray, 0, _namespacesArrayIndex);
|
||||
_namespacesArray = namespacesArray;
|
||||
}
|
||||
|
||||
_namespacesArray[_namespacesArrayIndex++] = prefix;
|
||||
_namespacesArray[_namespacesArrayIndex++] = namespaceURI;
|
||||
setPrefix(prefix, namespaceURI);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeDefaultNamespace(String namespaceURI)
|
||||
throws XMLStreamException
|
||||
{
|
||||
if (!_inStartElement) {
|
||||
throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.attributeWritingNotAllowed"));
|
||||
}
|
||||
|
||||
if (_namespacesArrayIndex == _namespacesArray.length) {
|
||||
final String[] namespacesArray = new String[_namespacesArrayIndex * 2];
|
||||
System.arraycopy(_namespacesArray, 0, namespacesArray, 0, _namespacesArrayIndex);
|
||||
_namespacesArray = namespacesArray;
|
||||
}
|
||||
|
||||
_namespacesArray[_namespacesArrayIndex++] = "";
|
||||
_namespacesArray[_namespacesArrayIndex++] = namespaceURI;
|
||||
setPrefix("", namespaceURI);
|
||||
}
|
||||
|
||||
public void writeComment(String data) throws XMLStreamException {
|
||||
try {
|
||||
if (getIgnoreComments()) return;
|
||||
|
||||
encodeTerminationAndCurrentElement(true);
|
||||
|
||||
// TODO: avoid array copy here
|
||||
encodeComment(data.toCharArray(), 0, data.length());
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new XMLStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeProcessingInstruction(String target)
|
||||
throws XMLStreamException
|
||||
{
|
||||
writeProcessingInstruction(target, "");
|
||||
}
|
||||
|
||||
public void writeProcessingInstruction(String target, String data)
|
||||
throws XMLStreamException
|
||||
{
|
||||
try {
|
||||
if (getIgnoreProcesingInstructions()) return;
|
||||
|
||||
encodeTerminationAndCurrentElement(true);
|
||||
|
||||
encodeProcessingInstruction(target, data);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new XMLStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeCData(String text) throws XMLStreamException {
|
||||
try {
|
||||
final int length = text.length();
|
||||
if (length == 0) {
|
||||
return;
|
||||
} else if (length < _charBuffer.length) {
|
||||
if (getIgnoreWhiteSpaceTextContent() &&
|
||||
isWhiteSpace(text)) return;
|
||||
|
||||
// Warning: this method must be called before any state
|
||||
// is modified, such as the _charBuffer contents,
|
||||
// so the characters of text cannot be copied to _charBuffer
|
||||
// before this call
|
||||
encodeTerminationAndCurrentElement(true);
|
||||
|
||||
text.getChars(0, length, _charBuffer, 0);
|
||||
encodeCIIBuiltInAlgorithmDataAsCDATA(_charBuffer, 0, length);
|
||||
} else {
|
||||
final char ch[] = text.toCharArray();
|
||||
if (getIgnoreWhiteSpaceTextContent() &&
|
||||
isWhiteSpace(ch, 0, length)) return;
|
||||
|
||||
encodeTerminationAndCurrentElement(true);
|
||||
|
||||
encodeCIIBuiltInAlgorithmDataAsCDATA(ch, 0, length);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new XMLStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeDTD(String dtd) throws XMLStreamException {
|
||||
throw new UnsupportedOperationException(CommonResourceBundle.getInstance().getString("message.notImplemented"));
|
||||
}
|
||||
|
||||
public void writeEntityRef(String name) throws XMLStreamException {
|
||||
throw new UnsupportedOperationException(CommonResourceBundle.getInstance().getString("message.notImplemented"));
|
||||
}
|
||||
|
||||
public void writeCharacters(String text) throws XMLStreamException {
|
||||
try {
|
||||
final int length = text.length();
|
||||
if (length == 0) {
|
||||
return;
|
||||
} else if (length < _charBuffer.length) {
|
||||
if (getIgnoreWhiteSpaceTextContent() &&
|
||||
isWhiteSpace(text)) return;
|
||||
|
||||
// Warning: this method must be called before any state
|
||||
// is modified, such as the _charBuffer contents,
|
||||
// so the characters of text cannot be copied to _charBuffer
|
||||
// before this call
|
||||
encodeTerminationAndCurrentElement(true);
|
||||
|
||||
text.getChars(0, length, _charBuffer, 0);
|
||||
encodeCharacters(_charBuffer, 0, length);
|
||||
} else {
|
||||
final char ch[] = text.toCharArray();
|
||||
if (getIgnoreWhiteSpaceTextContent() &&
|
||||
isWhiteSpace(ch, 0, length)) return;
|
||||
|
||||
encodeTerminationAndCurrentElement(true);
|
||||
|
||||
encodeCharactersNoClone(ch, 0, length);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new XMLStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeCharacters(char[] text, int start, int len)
|
||||
throws XMLStreamException
|
||||
{
|
||||
try {
|
||||
if (len <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getIgnoreWhiteSpaceTextContent() &&
|
||||
isWhiteSpace(text, start, len)) return;
|
||||
|
||||
encodeTerminationAndCurrentElement(true);
|
||||
|
||||
encodeCharacters(text, start, len);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new XMLStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getPrefix(String uri) throws XMLStreamException {
|
||||
return _nsContext.getPrefix(uri);
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix, String uri)
|
||||
throws XMLStreamException
|
||||
{
|
||||
if (_stackCount > -1 && _nsSupportContextStack[_stackCount] == false) {
|
||||
_nsSupportContextStack[_stackCount] = true;
|
||||
_nsContext.pushContext();
|
||||
}
|
||||
|
||||
_nsContext.declarePrefix(prefix, uri);
|
||||
}
|
||||
|
||||
public void setDefaultNamespace(String uri) throws XMLStreamException {
|
||||
setPrefix("", uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current namespace context for prefix and uri bindings.
|
||||
* This context becomes the root namespace context for writing and
|
||||
* will replace the current root namespace context. Subsequent calls
|
||||
* to setPrefix and setDefaultNamespace will bind namespaces using
|
||||
* the context passed to the method as the root context for resolving
|
||||
* namespaces. This method may only be called once at the start of
|
||||
* the document. It does not cause the namespaces to be declared.
|
||||
* If a namespace URI to prefix mapping is found in the namespace
|
||||
* context it is treated as declared and the prefix may be used
|
||||
* by the StreamWriter.
|
||||
* @param context the namespace context to use for this writer, may not be null
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void setNamespaceContext(NamespaceContext context)
|
||||
throws XMLStreamException
|
||||
{
|
||||
throw new UnsupportedOperationException("setNamespaceContext");
|
||||
}
|
||||
|
||||
public NamespaceContext getNamespaceContext() {
|
||||
return _nsContext;
|
||||
}
|
||||
|
||||
public Object getProperty(java.lang.String name)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (_manager != null) {
|
||||
return _manager.getProperty(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setManager(StAXManager manager) {
|
||||
_manager = manager;
|
||||
}
|
||||
|
||||
public void setEncoding(String encoding) {
|
||||
_encoding = encoding;
|
||||
}
|
||||
|
||||
|
||||
public void writeOctets(byte[] b, int start, int len)
|
||||
throws XMLStreamException
|
||||
{
|
||||
try {
|
||||
if (len == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
encodeTerminationAndCurrentElement(true);
|
||||
|
||||
encodeCIIOctetAlgorithmData(EncodingAlgorithmIndexes.BASE64, b, start, len);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new XMLStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void encodeTerminationAndCurrentElement(boolean terminateAfter) throws XMLStreamException {
|
||||
try {
|
||||
encodeTermination();
|
||||
|
||||
if (_inStartElement) {
|
||||
|
||||
_b = EncodingConstants.ELEMENT;
|
||||
if (_attributesArrayIndex > 0) {
|
||||
_b |= EncodingConstants.ELEMENT_ATTRIBUTE_FLAG;
|
||||
}
|
||||
|
||||
// Encode namespace decls associated with this element
|
||||
if (_namespacesArrayIndex > 0) {
|
||||
write(_b | EncodingConstants.ELEMENT_NAMESPACES_FLAG);
|
||||
for (int i = 0; i < _namespacesArrayIndex;) {
|
||||
encodeNamespaceAttribute(_namespacesArray[i++], _namespacesArray[i++]);
|
||||
}
|
||||
_namespacesArrayIndex = 0;
|
||||
|
||||
write(EncodingConstants.TERMINATOR);
|
||||
|
||||
_b = 0;
|
||||
}
|
||||
|
||||
// If element's prefix is empty - apply default scope namespace
|
||||
if (_currentPrefix.length() == 0) {
|
||||
if (_currentUri.length() == 0) {
|
||||
_currentUri = _nsContext.getNamespaceURI("");
|
||||
} else {
|
||||
String tmpPrefix = getPrefix(_currentUri);
|
||||
if (tmpPrefix != null) {
|
||||
_currentPrefix = tmpPrefix;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
encodeElementQualifiedNameOnThirdBit(_currentUri, _currentPrefix, _currentLocalName);
|
||||
|
||||
for (int i = 0; i < _attributesArrayIndex;) {
|
||||
encodeAttributeQualifiedNameOnSecondBit(
|
||||
_attributesArray[i++], _attributesArray[i++], _attributesArray[i++]);
|
||||
|
||||
final String value = _attributesArray[i];
|
||||
_attributesArray[i++] = null;
|
||||
final boolean addToTable = isAttributeValueLengthMatchesLimit(value.length());
|
||||
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, false);
|
||||
|
||||
_b = EncodingConstants.TERMINATOR;
|
||||
_terminate = true;
|
||||
}
|
||||
_attributesArrayIndex = 0;
|
||||
_inStartElement = false;
|
||||
|
||||
if (_isEmptyElement) {
|
||||
encodeElementTermination();
|
||||
if (_nsSupportContextStack[_stackCount--] == true) {
|
||||
_nsContext.popContext();
|
||||
}
|
||||
|
||||
_isEmptyElement = false;
|
||||
}
|
||||
|
||||
if (terminateAfter) {
|
||||
encodeTermination();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new XMLStreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// LowLevelFastInfosetSerializer
|
||||
|
||||
public final void initiateLowLevelWriting() throws XMLStreamException {
|
||||
encodeTerminationAndCurrentElement(false);
|
||||
}
|
||||
|
||||
public final int getNextElementIndex() {
|
||||
return _v.elementName.getNextIndex();
|
||||
}
|
||||
|
||||
public final int getNextAttributeIndex() {
|
||||
return _v.attributeName.getNextIndex();
|
||||
}
|
||||
|
||||
public final int getLocalNameIndex() {
|
||||
return _v.localName.getIndex();
|
||||
}
|
||||
|
||||
public final int getNextLocalNameIndex() {
|
||||
return _v.localName.getNextIndex();
|
||||
}
|
||||
|
||||
public final void writeLowLevelTerminationAndMark() throws IOException {
|
||||
encodeTermination();
|
||||
mark();
|
||||
}
|
||||
|
||||
public final void writeLowLevelStartElementIndexed(int type, int index) throws IOException {
|
||||
_b = type;
|
||||
encodeNonZeroIntegerOnThirdBit(index);
|
||||
}
|
||||
|
||||
public final boolean writeLowLevelStartElement(int type, String prefix, String localName,
|
||||
String namespaceURI) throws IOException {
|
||||
final boolean isIndexed = encodeElement(type, namespaceURI, prefix, localName);
|
||||
|
||||
if (!isIndexed)
|
||||
encodeLiteral(type | EncodingConstants.ELEMENT_LITERAL_QNAME_FLAG,
|
||||
namespaceURI, prefix, localName);
|
||||
|
||||
return isIndexed;
|
||||
}
|
||||
|
||||
public final void writeLowLevelStartNamespaces() throws IOException {
|
||||
write(EncodingConstants.ELEMENT | EncodingConstants.ELEMENT_NAMESPACES_FLAG);
|
||||
}
|
||||
|
||||
public final void writeLowLevelNamespace(String prefix, String namespaceName)
|
||||
throws IOException {
|
||||
encodeNamespaceAttribute(prefix, namespaceName);
|
||||
}
|
||||
|
||||
public final void writeLowLevelEndNamespaces() throws IOException {
|
||||
write(EncodingConstants.TERMINATOR);
|
||||
}
|
||||
|
||||
public final void writeLowLevelStartAttributes() throws IOException {
|
||||
if (hasMark()) {
|
||||
_octetBuffer[_markIndex] |= EncodingConstants.ELEMENT_ATTRIBUTE_FLAG;
|
||||
resetMark();
|
||||
}
|
||||
}
|
||||
|
||||
public final void writeLowLevelAttributeIndexed(int index) throws IOException {
|
||||
encodeNonZeroIntegerOnSecondBitFirstBitZero(index);
|
||||
}
|
||||
|
||||
public final boolean writeLowLevelAttribute(String prefix, String namespaceURI, String localName) throws IOException {
|
||||
final boolean isIndexed = encodeAttribute(namespaceURI, prefix, localName);
|
||||
|
||||
if (!isIndexed)
|
||||
encodeLiteral(EncodingConstants.ATTRIBUTE_LITERAL_QNAME_FLAG,
|
||||
namespaceURI, prefix, localName);
|
||||
|
||||
return isIndexed;
|
||||
}
|
||||
|
||||
public final void writeLowLevelAttributeValue(String value) throws IOException
|
||||
{
|
||||
final boolean addToTable = isAttributeValueLengthMatchesLimit(value.length());
|
||||
encodeNonIdentifyingStringOnFirstBit(value, _v.attributeValue, addToTable, false);
|
||||
}
|
||||
|
||||
public final void writeLowLevelStartNameLiteral(int type, String prefix, byte[] utf8LocalName,
|
||||
String namespaceURI) throws IOException {
|
||||
encodeLiteralHeader(type, namespaceURI, prefix);
|
||||
encodeNonZeroOctetStringLengthOnSecondBit(utf8LocalName.length);
|
||||
write(utf8LocalName, 0, utf8LocalName.length);
|
||||
}
|
||||
|
||||
public final void writeLowLevelStartNameLiteral(int type, String prefix, int localNameIndex,
|
||||
String namespaceURI) throws IOException {
|
||||
encodeLiteralHeader(type, namespaceURI, prefix);
|
||||
encodeNonZeroIntegerOnSecondBitFirstBitOne(localNameIndex);
|
||||
}
|
||||
|
||||
public final void writeLowLevelEndStartElement() throws IOException {
|
||||
if (hasMark()) {
|
||||
resetMark();
|
||||
} else {
|
||||
// Terminate the attributes
|
||||
_b = EncodingConstants.TERMINATOR;
|
||||
_terminate = true;
|
||||
}
|
||||
}
|
||||
|
||||
public final void writeLowLevelEndElement() throws IOException {
|
||||
encodeElementTermination();
|
||||
}
|
||||
|
||||
public final void writeLowLevelText(char[] text, int length) throws IOException {
|
||||
if (length == 0)
|
||||
return;
|
||||
|
||||
encodeTermination();
|
||||
|
||||
encodeCharacters(text, 0, length);
|
||||
}
|
||||
|
||||
public final void writeLowLevelText(String text) throws IOException {
|
||||
final int length = text.length();
|
||||
if (length == 0)
|
||||
return;
|
||||
|
||||
encodeTermination();
|
||||
|
||||
if (length < _charBuffer.length) {
|
||||
text.getChars(0, length, _charBuffer, 0);
|
||||
encodeCharacters(_charBuffer, 0, length);
|
||||
} else {
|
||||
final char ch[] = text.toCharArray();
|
||||
encodeCharactersNoClone(ch, 0, length);
|
||||
}
|
||||
}
|
||||
|
||||
public final void writeLowLevelOctets(byte[] octets, int length) throws IOException {
|
||||
if (length == 0)
|
||||
return;
|
||||
|
||||
encodeTermination();
|
||||
|
||||
encodeCIIOctetAlgorithmData(EncodingAlgorithmIndexes.BASE64, octets, 0, length);
|
||||
}
|
||||
|
||||
private boolean encodeElement(int type, String namespaceURI, String prefix, String localName) throws IOException {
|
||||
final LocalNameQualifiedNamesMap.Entry entry = _v.elementName.obtainEntry(localName);
|
||||
for (int i = 0; i < entry._valueIndex; i++) {
|
||||
final QualifiedName name = entry._value[i];
|
||||
if ((prefix == name.prefix || prefix.equals(name.prefix))
|
||||
&& (namespaceURI == name.namespaceName || namespaceURI.equals(name.namespaceName))) {
|
||||
_b = type;
|
||||
encodeNonZeroIntegerOnThirdBit(name.index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
entry.addQualifiedName(new QualifiedName(prefix, namespaceURI, localName, "", _v.elementName.getNextIndex()));
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean encodeAttribute(String namespaceURI, String prefix, String localName) throws IOException {
|
||||
final LocalNameQualifiedNamesMap.Entry entry = _v.attributeName.obtainEntry(localName);
|
||||
for (int i = 0; i < entry._valueIndex; i++) {
|
||||
final QualifiedName name = entry._value[i];
|
||||
if ((prefix == name.prefix || prefix.equals(name.prefix))
|
||||
&& (namespaceURI == name.namespaceName || namespaceURI.equals(name.namespaceName))) {
|
||||
encodeNonZeroIntegerOnSecondBitFirstBitZero(name.index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
entry.addQualifiedName(new QualifiedName(prefix, namespaceURI, localName, "", _v.attributeName.getNextIndex()));
|
||||
return false;
|
||||
}
|
||||
|
||||
private void encodeLiteralHeader(int type, String namespaceURI, String prefix) throws IOException {
|
||||
if (namespaceURI != "") {
|
||||
type |= EncodingConstants.LITERAL_QNAME_NAMESPACE_NAME_FLAG;
|
||||
if (prefix != "")
|
||||
type |= EncodingConstants.LITERAL_QNAME_PREFIX_FLAG;
|
||||
|
||||
write(type);
|
||||
if (prefix != "")
|
||||
encodeNonZeroIntegerOnSecondBitFirstBitOne(_v.prefix.get(prefix));
|
||||
encodeNonZeroIntegerOnSecondBitFirstBitOne(_v.namespaceName.get(namespaceURI));
|
||||
} else
|
||||
write(type);
|
||||
}
|
||||
|
||||
private void encodeLiteral(int type, String namespaceURI, String prefix, String localName) throws IOException {
|
||||
encodeLiteralHeader(type, namespaceURI, prefix);
|
||||
|
||||
final int localNameIndex = _v.localName.obtainIndex(localName);
|
||||
if (localNameIndex == -1) {
|
||||
encodeNonEmptyOctetStringOnSecondBit(localName);
|
||||
} else
|
||||
encodeNonZeroIntegerOnSecondBitFirstBitOne(localNameIndex);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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.stax;
|
||||
|
||||
import java.util.HashMap;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class StAXManager {
|
||||
protected static final String STAX_NOTATIONS = "javax.xml.stream.notations";
|
||||
protected static final String STAX_ENTITIES = "javax.xml.stream.entities";
|
||||
|
||||
HashMap features = new HashMap();
|
||||
|
||||
public static final int CONTEXT_READER = 1;
|
||||
public static final int CONTEXT_WRITER = 2;
|
||||
|
||||
|
||||
/** Creates a new instance of StAXManager */
|
||||
public StAXManager() {
|
||||
}
|
||||
|
||||
public StAXManager(int context) {
|
||||
switch(context){
|
||||
case CONTEXT_READER:{
|
||||
initConfigurableReaderProperties();
|
||||
break;
|
||||
}
|
||||
case CONTEXT_WRITER:{
|
||||
initWriterProps();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public StAXManager(StAXManager manager){
|
||||
|
||||
HashMap properties = manager.getProperties();
|
||||
features.putAll(properties);
|
||||
}
|
||||
|
||||
private HashMap getProperties(){
|
||||
return features ;
|
||||
}
|
||||
|
||||
private void initConfigurableReaderProperties(){
|
||||
//spec v1.0 default values
|
||||
features.put(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
|
||||
features.put(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
|
||||
features.put(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
|
||||
features.put(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE);
|
||||
features.put(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
|
||||
features.put(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
|
||||
features.put(XMLInputFactory.REPORTER, null);
|
||||
features.put(XMLInputFactory.RESOLVER, null);
|
||||
features.put(XMLInputFactory.ALLOCATOR, null);
|
||||
features.put(STAX_NOTATIONS,null );
|
||||
}
|
||||
|
||||
private void initWriterProps(){
|
||||
features.put(XMLOutputFactory.IS_REPAIRING_NAMESPACES , Boolean.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* public void reset(){
|
||||
* features.clear() ;
|
||||
* }
|
||||
*/
|
||||
public boolean containsProperty(String property){
|
||||
return features.containsKey(property) ;
|
||||
}
|
||||
|
||||
public Object getProperty(String name){
|
||||
checkProperty(name);
|
||||
return features.get(name);
|
||||
}
|
||||
|
||||
public void setProperty(String name, Object value){
|
||||
checkProperty(name);
|
||||
if (name.equals(XMLInputFactory.IS_VALIDATING) &&
|
||||
Boolean.TRUE.equals(value)){
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.validationNotSupported") +
|
||||
CommonResourceBundle.getInstance().getString("support_validation"));
|
||||
} else if (name.equals(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES) &&
|
||||
Boolean.TRUE.equals(value)) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.externalEntities") +
|
||||
CommonResourceBundle.getInstance().getString("resolve_external_entities_"));
|
||||
}
|
||||
features.put(name,value);
|
||||
|
||||
}
|
||||
|
||||
public void checkProperty(String name) {
|
||||
if (!features.containsKey(name))
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object[]{name}));
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return features.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.events.Attribute;
|
||||
|
||||
|
||||
|
||||
public class AttributeBase extends EventBase implements Attribute
|
||||
|
||||
{
|
||||
//an Attribute consists of a qualified name and value
|
||||
private QName _QName;
|
||||
private String _value;
|
||||
|
||||
private String _attributeType = null;
|
||||
//A flag indicating whether this attribute was actually specified in the start-tag
|
||||
//of its element or was defaulted from the schema.
|
||||
private boolean _specified = false;
|
||||
|
||||
public AttributeBase(){
|
||||
super(ATTRIBUTE);
|
||||
}
|
||||
|
||||
public AttributeBase(String name, String value) {
|
||||
super(ATTRIBUTE);
|
||||
_QName = new QName(name);
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public AttributeBase(QName qname, String value) {
|
||||
_QName = qname;
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public AttributeBase(String prefix, String localName, String value) {
|
||||
this(prefix, null,localName, value, null);
|
||||
}
|
||||
|
||||
public AttributeBase(String prefix, String namespaceURI, String localName,
|
||||
String value, String attributeType) {
|
||||
if (prefix == null) prefix = "";
|
||||
_QName = new QName(namespaceURI, localName,prefix);
|
||||
_value = value;
|
||||
_attributeType = (attributeType == null) ? "CDATA":attributeType;
|
||||
}
|
||||
|
||||
|
||||
public void setName(QName name){
|
||||
_QName = name ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the QName for this attribute
|
||||
*/
|
||||
public QName getName() {
|
||||
return _QName;
|
||||
}
|
||||
|
||||
public void setValue(String value){
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public String getLocalName() {
|
||||
return _QName.getLocalPart();
|
||||
}
|
||||
/**
|
||||
* Gets the normalized value of this attribute
|
||||
*/
|
||||
public String getValue() {
|
||||
return _value;
|
||||
}
|
||||
|
||||
public void setAttributeType(String attributeType){
|
||||
_attributeType = attributeType ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of this attribute, default is
|
||||
* the String "CDATA"
|
||||
* @return the type as a String, default is "CDATA"
|
||||
*/
|
||||
public String getDTDType() {
|
||||
return _attributeType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A flag indicating whether this attribute was actually
|
||||
* specified in the start-tag of its element, or was defaulted from the schema.
|
||||
* @return returns true if this was specified in the start element
|
||||
*/
|
||||
public boolean isSpecified() {
|
||||
return _specified ;
|
||||
}
|
||||
|
||||
public void setSpecified(boolean isSpecified){
|
||||
_specified = isSpecified ;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
String prefix = _QName.getPrefix();
|
||||
if (!Util.isEmptyString(prefix))
|
||||
return prefix + ":" + _QName.getLocalPart() + "='" + _value + "'";
|
||||
|
||||
return _QName.getLocalPart() + "='" + _value + "'";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.org.apache.xerces.util.XMLChar;
|
||||
import javax.xml.stream.events.Characters;
|
||||
|
||||
|
||||
public class CharactersEvent extends EventBase implements Characters {
|
||||
private String _text;
|
||||
private boolean isCData=false;
|
||||
private boolean isSpace=false;
|
||||
private boolean isIgnorable=false;
|
||||
private boolean needtoCheck = true;
|
||||
|
||||
public CharactersEvent() {
|
||||
super(CHARACTERS);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param data Character Data.
|
||||
*/
|
||||
public CharactersEvent(String data) {
|
||||
super(CHARACTERS);
|
||||
_text = data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data Character Data.
|
||||
* @param isCData true if is CData
|
||||
*/
|
||||
public CharactersEvent(String data, boolean isCData) {
|
||||
super(CHARACTERS);
|
||||
_text = data;
|
||||
this.isCData = isCData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the character data of this event
|
||||
*/
|
||||
public String getData() {
|
||||
return _text;
|
||||
}
|
||||
|
||||
public void setData(String data){
|
||||
_text = data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean returns true if the data is CData
|
||||
*/
|
||||
public boolean isCData() {
|
||||
return isCData;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return String return the String representation of this event.
|
||||
*/
|
||||
public String toString() {
|
||||
if(isCData)
|
||||
return "<![CDATA[" + _text + "]]>";
|
||||
else
|
||||
return _text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this is ignorableWhiteSpace. If
|
||||
* this event is ignorableWhiteSpace its event type will
|
||||
* be SPACE.
|
||||
* @return boolean true if this is ignorableWhiteSpace.
|
||||
*/
|
||||
public boolean isIgnorableWhiteSpace() {
|
||||
return isIgnorable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this set of Characters are all whitespace. Whitspace inside a document
|
||||
* is reported as CHARACTERS. This method allows checking of CHARACTERS events to see
|
||||
* if they are composed of only whitespace characters
|
||||
* @return boolean true if this set of Characters are all whitespace
|
||||
*/
|
||||
public boolean isWhiteSpace() {
|
||||
//no synchronization checks made.
|
||||
if(needtoCheck){
|
||||
checkWhiteSpace();
|
||||
needtoCheck = false;
|
||||
}
|
||||
return isSpace;
|
||||
}
|
||||
|
||||
public void setSpace(boolean isSpace) {
|
||||
this.isSpace = isSpace;
|
||||
needtoCheck = false;
|
||||
}
|
||||
public void setIgnorable(boolean isIgnorable){
|
||||
this.isIgnorable = isIgnorable;
|
||||
setEventType(SPACE);
|
||||
}
|
||||
private void checkWhiteSpace(){
|
||||
//refer to xerces XMLChar
|
||||
if(!Util.isEmptyString(_text)){
|
||||
isSpace = true;
|
||||
for(int i=0;i<_text.length();i++){
|
||||
if(!XMLChar.isSpace(_text.charAt(i))){
|
||||
isSpace = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
|
||||
import javax.xml.stream.events.Comment;
|
||||
|
||||
public class CommentEvent extends EventBase implements Comment {
|
||||
|
||||
/* String data for this event */
|
||||
private String _text;
|
||||
|
||||
public CommentEvent() {
|
||||
super(COMMENT);
|
||||
}
|
||||
|
||||
public CommentEvent(String text) {
|
||||
this();
|
||||
_text = text;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return String String representation of this event
|
||||
*/
|
||||
public String toString() {
|
||||
return "<!--" + _text + "-->";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the string data of the comment, returns empty string if it
|
||||
* does not exist
|
||||
*/
|
||||
public String getText() {
|
||||
return _text ;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
_text = text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.stream.events.DTD;
|
||||
import javax.xml.stream.events.EntityDeclaration;
|
||||
import javax.xml.stream.events.NotationDeclaration;
|
||||
|
||||
/**
|
||||
* DTDEvent. Notations and Entities are not used
|
||||
*/
|
||||
public class DTDEvent extends EventBase implements DTD{
|
||||
|
||||
private String _dtd;
|
||||
private List _notations;
|
||||
private List _entities;
|
||||
|
||||
/** Creates a new instance of DTDEvent */
|
||||
public DTDEvent() {
|
||||
setEventType(DTD);
|
||||
}
|
||||
|
||||
public DTDEvent(String dtd){
|
||||
setEventType(DTD);
|
||||
_dtd = dtd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entire Document Type Declaration as a string, including
|
||||
* the internal DTD subset.
|
||||
* This may be null if there is not an internal subset.
|
||||
* If it is not null it must return the entire
|
||||
* Document Type Declaration which matches the doctypedecl
|
||||
* production in the XML 1.0 specification
|
||||
*/
|
||||
public String getDocumentTypeDeclaration() {
|
||||
return _dtd;
|
||||
}
|
||||
public void setDTD(String dtd){
|
||||
_dtd = dtd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a List containing the general entities,
|
||||
* both external and internal, declared in the DTD.
|
||||
* This list must contain EntityDeclaration events.
|
||||
* @see EntityDeclaration
|
||||
* @return an unordered list of EntityDeclaration events
|
||||
*/
|
||||
public List getEntities() {
|
||||
return _entities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a List containing the notations declared in the DTD.
|
||||
* This list must contain NotationDeclaration events.
|
||||
* @see NotationDeclaration
|
||||
* @return an unordered list of NotationDeclaration events
|
||||
*/
|
||||
public List getNotations() {
|
||||
return _notations;
|
||||
}
|
||||
|
||||
/**
|
||||
*Returns an implementation defined representation of the DTD.
|
||||
* This method may return null if no representation is available.
|
||||
*
|
||||
*/
|
||||
public Object getProcessedDTD() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setEntities(List entites){
|
||||
_entities = entites;
|
||||
}
|
||||
|
||||
public void setNotations(List notations){
|
||||
_notations = notations;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return _dtd ;
|
||||
}
|
||||
}
|
||||
@@ -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.stax.events;
|
||||
import java.util.Iterator;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
|
||||
public class EmptyIterator implements Iterator {
|
||||
public static final EmptyIterator instance = new EmptyIterator();
|
||||
/** Creates a new instance of EmptyIterator */
|
||||
private EmptyIterator() {
|
||||
}
|
||||
public static EmptyIterator getInstance() {
|
||||
return instance;
|
||||
}
|
||||
public boolean hasNext() {
|
||||
return false;
|
||||
}
|
||||
public Object next() throws NoSuchElementException {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException(CommonResourceBundle.getInstance().getString("message.emptyIterator"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import javax.xml.stream.events.EndDocument;
|
||||
|
||||
|
||||
public class EndDocumentEvent extends EventBase implements EndDocument {
|
||||
|
||||
public EndDocumentEvent() {
|
||||
super(END_DOCUMENT);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "<? EndDocument ?>";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.events.EndElement;
|
||||
import javax.xml.stream.events.Namespace;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.stax.events.EmptyIterator;
|
||||
|
||||
|
||||
public class EndElementEvent extends EventBase implements EndElement {
|
||||
|
||||
List _namespaces = null;
|
||||
QName _qname ;
|
||||
|
||||
public void reset() {
|
||||
if (_namespaces != null) _namespaces.clear();
|
||||
}
|
||||
|
||||
public EndElementEvent() {
|
||||
setEventType(END_ELEMENT);
|
||||
}
|
||||
|
||||
public EndElementEvent(String prefix, String namespaceURI, String localpart) {
|
||||
_qname = getQName(namespaceURI,localpart,prefix);
|
||||
setEventType(END_ELEMENT);
|
||||
}
|
||||
|
||||
public EndElementEvent(QName qname) {
|
||||
_qname = qname;
|
||||
setEventType(END_ELEMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of this event
|
||||
* @return the qualified name of this event
|
||||
*/
|
||||
public QName getName() {
|
||||
return _qname;
|
||||
}
|
||||
|
||||
public void setName(QName qname) {
|
||||
_qname = qname;
|
||||
}
|
||||
|
||||
|
||||
/** Returns an Iterator of namespaces that have gone out
|
||||
* of scope. Returns an empty iterator if no namespaces have gone
|
||||
* out of scope.
|
||||
* @return an Iterator over Namespace interfaces, or an
|
||||
* empty iterator
|
||||
*/
|
||||
public Iterator getNamespaces() {
|
||||
if(_namespaces != null)
|
||||
return _namespaces.iterator();
|
||||
return EmptyIterator.getInstance();
|
||||
}
|
||||
|
||||
public void addNamespace(Namespace namespace){
|
||||
if (_namespaces == null) {
|
||||
_namespaces = new ArrayList();
|
||||
}
|
||||
_namespaces.add(namespace);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("</").append(nameAsString());
|
||||
Iterator namespaces = getNamespaces();
|
||||
while(namespaces.hasNext()) {
|
||||
sb.append(" ").append(namespaces.next().toString());
|
||||
}
|
||||
sb.append(">");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
private String nameAsString() {
|
||||
if("".equals(_qname.getNamespaceURI()))
|
||||
return _qname.getLocalPart();
|
||||
if(_qname.getPrefix() != null)
|
||||
return "['" + _qname.getNamespaceURI() + "']:" + _qname.getPrefix() + ":" + _qname.getLocalPart();
|
||||
else
|
||||
return "['" + _qname.getNamespaceURI() + "']:" + _qname.getLocalPart();
|
||||
}
|
||||
private QName getQName(String uri, String localPart, String prefix){
|
||||
QName qn = null;
|
||||
if(prefix != null && uri != null)
|
||||
qn = new QName(uri, localPart, prefix);
|
||||
else if(prefix == null && uri != null)
|
||||
qn = new QName(uri, localPart);
|
||||
else if(prefix == null && uri == null)
|
||||
qn = new QName(localPart);
|
||||
return qn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import javax.xml.stream.events.EntityDeclaration;
|
||||
|
||||
|
||||
public class EntityDeclarationImpl extends EventBase implements EntityDeclaration {
|
||||
private String _publicId;
|
||||
private String _systemId;
|
||||
private String _baseURI;
|
||||
private String _entityName;
|
||||
private String _replacement;
|
||||
private String _notationName;
|
||||
|
||||
/** Creates a new instance of EntityDeclarationImpl */
|
||||
public EntityDeclarationImpl() {
|
||||
init();
|
||||
}
|
||||
|
||||
public EntityDeclarationImpl(String entityName , String replacement){
|
||||
init();
|
||||
_entityName = entityName;
|
||||
_replacement = replacement;
|
||||
}
|
||||
|
||||
/**
|
||||
* The entity's public identifier, or null if none was given
|
||||
* @return the public ID for this declaration or null
|
||||
*/
|
||||
public String getPublicId(){
|
||||
return _publicId;
|
||||
}
|
||||
|
||||
/**
|
||||
* The entity's system identifier.
|
||||
* @return the system ID for this declaration or null
|
||||
*/
|
||||
public String getSystemId(){
|
||||
return _systemId;
|
||||
}
|
||||
|
||||
/**
|
||||
* The entity's name
|
||||
* @return the name, may not be null
|
||||
*/
|
||||
public String getName(){
|
||||
return _entityName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the associated notation.
|
||||
* @return the notation name
|
||||
*/
|
||||
public String getNotationName() {
|
||||
return _notationName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The replacement text of the entity.
|
||||
* This method will only return non-null
|
||||
* if this is an internal entity.
|
||||
* @return null or the replacment text
|
||||
*/
|
||||
public String getReplacementText() {
|
||||
return _replacement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base URI for this reference
|
||||
* or null if this information is not available
|
||||
* @return the base URI or null
|
||||
*/
|
||||
public String getBaseURI() {
|
||||
return _baseURI;
|
||||
}
|
||||
|
||||
public void setPublicId(String publicId) {
|
||||
_publicId = publicId;
|
||||
}
|
||||
|
||||
public void setSystemId(String systemId) {
|
||||
_systemId = systemId;
|
||||
}
|
||||
|
||||
public void setBaseURI(String baseURI) {
|
||||
_baseURI = baseURI;
|
||||
}
|
||||
|
||||
public void setName(String entityName){
|
||||
_entityName = entityName;
|
||||
}
|
||||
|
||||
public void setReplacementText(String replacement){
|
||||
_replacement = replacement;
|
||||
}
|
||||
|
||||
public void setNotationName(String notationName){
|
||||
_notationName = notationName;
|
||||
}
|
||||
|
||||
protected void init(){
|
||||
setEventType(ENTITY_DECLARATION);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import javax.xml.stream.events.EntityDeclaration;
|
||||
import javax.xml.stream.events.EntityReference;
|
||||
|
||||
|
||||
public class EntityReferenceEvent extends EventBase implements EntityReference {
|
||||
private EntityDeclaration _entityDeclaration ;
|
||||
private String _entityName;
|
||||
|
||||
public EntityReferenceEvent() {
|
||||
init();
|
||||
}
|
||||
|
||||
public EntityReferenceEvent(String entityName , EntityDeclaration entityDeclaration) {
|
||||
init();
|
||||
_entityName = entityName;
|
||||
_entityDeclaration = entityDeclaration;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the entity
|
||||
* @return the entity's name, may not be null
|
||||
*/
|
||||
public String getName() {
|
||||
return _entityName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the declaration of this entity.
|
||||
*/
|
||||
public EntityDeclaration getDeclaration(){
|
||||
return _entityDeclaration ;
|
||||
}
|
||||
|
||||
public void setName(String name){
|
||||
_entityName = name;
|
||||
}
|
||||
|
||||
public void setDeclaration(EntityDeclaration declaration) {
|
||||
_entityDeclaration = declaration ;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String text = _entityDeclaration.getReplacementText();
|
||||
if(text == null)
|
||||
text = "";
|
||||
return "&" + getName() + ";='" + text + "'";
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
setEventType(ENTITY_REFERENCE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import javax.xml.stream.Location;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
import javax.xml.stream.events.Characters;
|
||||
import javax.xml.stream.events.EndElement;
|
||||
import javax.xml.stream.events.StartElement;
|
||||
import javax.xml.namespace.QName;
|
||||
import java.io.Writer;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
|
||||
public abstract class EventBase implements XMLEvent {
|
||||
|
||||
/* Event type this event corresponds to */
|
||||
protected int _eventType;
|
||||
protected Location _location = null;
|
||||
|
||||
public EventBase() {
|
||||
|
||||
}
|
||||
|
||||
public EventBase(int eventType) {
|
||||
_eventType = eventType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an integer code for this event.
|
||||
*/
|
||||
public int getEventType() {
|
||||
return _eventType;
|
||||
}
|
||||
|
||||
protected void setEventType(int eventType){
|
||||
_eventType = eventType;
|
||||
}
|
||||
|
||||
|
||||
public boolean isStartElement() {
|
||||
return _eventType == START_ELEMENT;
|
||||
}
|
||||
|
||||
public boolean isEndElement() {
|
||||
return _eventType == END_ELEMENT;
|
||||
}
|
||||
|
||||
public boolean isEntityReference() {
|
||||
return _eventType == ENTITY_REFERENCE;
|
||||
}
|
||||
|
||||
public boolean isProcessingInstruction() {
|
||||
return _eventType == PROCESSING_INSTRUCTION;
|
||||
}
|
||||
|
||||
public boolean isStartDocument() {
|
||||
return _eventType == START_DOCUMENT;
|
||||
}
|
||||
|
||||
public boolean isEndDocument() {
|
||||
return _eventType == END_DOCUMENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the location of this event. The Location
|
||||
* returned from this method is non-volatile and
|
||||
* will retain its information.
|
||||
* @see javax.xml.stream.Location
|
||||
*/
|
||||
public Location getLocation(){
|
||||
return _location;
|
||||
}
|
||||
|
||||
public void setLocation(Location loc){
|
||||
_location = loc;
|
||||
}
|
||||
public String getSystemId() {
|
||||
if(_location == null )
|
||||
return "";
|
||||
else
|
||||
return _location.getSystemId();
|
||||
}
|
||||
|
||||
/** Returns this event as Characters, may result in
|
||||
* a class cast exception if this event is not Characters.
|
||||
*/
|
||||
public Characters asCharacters() {
|
||||
if (isCharacters()) {
|
||||
return (Characters)this;
|
||||
} else
|
||||
throw new ClassCastException(CommonResourceBundle.getInstance().getString("message.charactersCast", new Object[]{getEventTypeString()}));
|
||||
}
|
||||
|
||||
/** Returns this event as an end element event, may result in
|
||||
* a class cast exception if this event is not a end element.
|
||||
*/
|
||||
public EndElement asEndElement() {
|
||||
if (isEndElement()) {
|
||||
return (EndElement)this;
|
||||
} else
|
||||
throw new ClassCastException(CommonResourceBundle.getInstance().getString("message.endElementCase", new Object[]{getEventTypeString()}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this event as a start element event, may result in
|
||||
* a class cast exception if this event is not a start element.
|
||||
*/
|
||||
public StartElement asStartElement() {
|
||||
if (isStartElement()) {
|
||||
return (StartElement)this;
|
||||
} else
|
||||
throw new ClassCastException(CommonResourceBundle.getInstance().getString("message.startElementCase", new Object[]{getEventTypeString()}));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is provided for implementations to provide
|
||||
* optional type information about the associated event.
|
||||
* It is optional and will return null if no information
|
||||
* is available.
|
||||
*/
|
||||
public QName getSchemaType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** A utility function to check if this event is an Attribute.
|
||||
* @see javax.xml.stream.events.Attribute
|
||||
*/
|
||||
public boolean isAttribute() {
|
||||
return _eventType == ATTRIBUTE;
|
||||
}
|
||||
|
||||
/** A utility function to check if this event is Characters.
|
||||
* @see javax.xml.stream.events.Characters
|
||||
*/
|
||||
public boolean isCharacters() {
|
||||
return _eventType == CHARACTERS;
|
||||
}
|
||||
|
||||
/** A utility function to check if this event is a Namespace.
|
||||
* @see javax.xml.stream.events.Namespace
|
||||
*/
|
||||
public boolean isNamespace() {
|
||||
return _eventType == NAMESPACE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method will write the XMLEvent as per the XML 1.0 specification as Unicode characters.
|
||||
* No indentation or whitespace should be outputted.
|
||||
*
|
||||
* Any user defined event type SHALL have this method
|
||||
* called when being written to on an output stream.
|
||||
* Built in Event types MUST implement this method,
|
||||
* but implementations MAY choose not call these methods
|
||||
* for optimizations reasons when writing out built in
|
||||
* Events to an output stream.
|
||||
* The output generated MUST be equivalent in terms of the
|
||||
* infoset expressed.
|
||||
*
|
||||
* @param writer The writer that will output the data
|
||||
* @throws XMLStreamException if there is a fatal error writing the event
|
||||
*/
|
||||
public void writeAsEncodedUnicode(Writer writer) throws javax.xml.stream.XMLStreamException {
|
||||
}
|
||||
|
||||
private String getEventTypeString() {
|
||||
switch (_eventType){
|
||||
case START_ELEMENT:
|
||||
return "StartElementEvent";
|
||||
case END_ELEMENT:
|
||||
return "EndElementEvent";
|
||||
case PROCESSING_INSTRUCTION:
|
||||
return "ProcessingInstructionEvent";
|
||||
case CHARACTERS:
|
||||
return "CharacterEvent";
|
||||
case COMMENT:
|
||||
return "CommentEvent";
|
||||
case START_DOCUMENT:
|
||||
return "StartDocumentEvent";
|
||||
case END_DOCUMENT:
|
||||
return "EndDocumentEvent";
|
||||
case ENTITY_REFERENCE:
|
||||
return "EntityReferenceEvent";
|
||||
case ATTRIBUTE:
|
||||
return "AttributeBase";
|
||||
case DTD:
|
||||
return "DTDEvent";
|
||||
case CDATA:
|
||||
return "CDATA";
|
||||
}
|
||||
return "UNKNOWN_EVENT_TYPE";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.events.Namespace;
|
||||
|
||||
|
||||
public class NamespaceBase extends AttributeBase implements Namespace{
|
||||
//J2SE1.5.0 javax.xml.XMLConstants
|
||||
static final String DEFAULT_NS_PREFIX = "";
|
||||
static final String XML_NS_URI = "http://www.w3.org/XML/1998/namespace";
|
||||
static final String XML_NS_PREFIX = "xml";
|
||||
static final String XMLNS_ATTRIBUTE_NS_URI = "http://www.w3.org/2000/xmlns/";
|
||||
static final String XMLNS_ATTRIBUTE = "xmlns";
|
||||
static final String W3C_XML_SCHEMA_NS_URI = "http://www.w3.org/2001/XMLSchema";
|
||||
static final String W3C_XML_SCHEMA_INSTANCE_NS_URI = "http://www.w3.org/2001/XMLSchema-instance";
|
||||
|
||||
//is this namespace default declaration?
|
||||
private boolean defaultDeclaration = false;
|
||||
|
||||
/** a namespace attribute has a form: xmlns:NCName="URI reference" */
|
||||
public NamespaceBase(String namespaceURI) {
|
||||
super(XMLNS_ATTRIBUTE, "", namespaceURI);
|
||||
setEventType(NAMESPACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Namespace
|
||||
* @param prefix prefix of a namespace is the local name for an attribute
|
||||
* @param namespaceURI the uri reference of a namespace is the value for an attribute
|
||||
*/
|
||||
public NamespaceBase(String prefix, String namespaceURI){
|
||||
super(XMLNS_ATTRIBUTE, prefix, namespaceURI);
|
||||
setEventType(NAMESPACE);
|
||||
if (Util.isEmptyString(prefix)) {
|
||||
defaultDeclaration=true;
|
||||
}
|
||||
}
|
||||
|
||||
void setPrefix(String prefix){
|
||||
if(prefix == null)
|
||||
setName(new QName(XMLNS_ATTRIBUTE_NS_URI,DEFAULT_NS_PREFIX,XMLNS_ATTRIBUTE));
|
||||
else// new QName(uri, localpart, prefix)
|
||||
setName(new QName(XMLNS_ATTRIBUTE_NS_URI,prefix,XMLNS_ATTRIBUTE));
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
if (defaultDeclaration) return "";
|
||||
return super.getLocalName();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set Namespace URI reference (xmlns:prefix = "uri")
|
||||
* @param uri the uri reference of a namespace is the value for an attribute
|
||||
*/
|
||||
void setNamespaceURI(String uri) {
|
||||
setValue(uri);
|
||||
}
|
||||
public String getNamespaceURI() {
|
||||
return getValue();
|
||||
}
|
||||
|
||||
|
||||
public boolean isNamespace(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isDefaultNamespaceDeclaration() {
|
||||
return defaultDeclaration;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.events.ProcessingInstruction;
|
||||
|
||||
|
||||
public class ProcessingInstructionEvent extends EventBase implements ProcessingInstruction {
|
||||
|
||||
private String targetName;
|
||||
private String _data;
|
||||
|
||||
public ProcessingInstructionEvent() {
|
||||
init();
|
||||
}
|
||||
|
||||
public ProcessingInstructionEvent(String targetName, String data) {
|
||||
this.targetName = targetName;
|
||||
_data = data;
|
||||
init();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
setEventType(XMLStreamConstants.PROCESSING_INSTRUCTION);
|
||||
}
|
||||
|
||||
public String getTarget() {
|
||||
return targetName;
|
||||
}
|
||||
|
||||
public void setTarget(String targetName) {
|
||||
this.targetName = targetName;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return _data;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if(_data != null && targetName != null)
|
||||
return "<?" + targetName + " " + _data + "?>";
|
||||
if(targetName != null)
|
||||
return "<?" + targetName + "?>";
|
||||
if(_data != null)
|
||||
return "<?" + _data + "?>";
|
||||
else
|
||||
return "<??>";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import java.util.Iterator;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class ReadIterator implements Iterator {
|
||||
|
||||
Iterator iterator = EmptyIterator.getInstance();
|
||||
|
||||
public ReadIterator(){
|
||||
}
|
||||
|
||||
public ReadIterator(Iterator iterator){
|
||||
if (iterator != null) {
|
||||
this.iterator = iterator;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return iterator.hasNext();
|
||||
}
|
||||
|
||||
public Object next() {
|
||||
return iterator.next();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException(CommonResourceBundle.getInstance().getString("message.readonlyList"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import javax.xml.stream.XMLEventFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.events.Namespace;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
import javax.xml.stream.util.XMLEventAllocator;
|
||||
import javax.xml.stream.util.XMLEventConsumer;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
/**
|
||||
* allows a user to register a way to allocate events given an XMLStreamReader.
|
||||
* The XMLEventAllocator can be set on an XMLInputFactory
|
||||
* using the property "javax.xml.stream.allocator"
|
||||
*
|
||||
* This base class uses EventFactory to create events as recommended in the JavaDoc of XMLEventAllocator.
|
||||
* However, creating new object per each event reduces performance. The implementation of
|
||||
* EventReader therefore will set the Allocator to StAXEventAllocator which implements the
|
||||
* Allocate methods without creating new objects.
|
||||
*
|
||||
* The spec for the first Allocate method states that it must NOT modify the state of the Reader
|
||||
* while the second MAY. For consistency, both Allocate methods in this implementation will
|
||||
* NOT modify the state.
|
||||
*
|
||||
*/
|
||||
public class StAXEventAllocatorBase implements XMLEventAllocator {
|
||||
XMLEventFactory factory;
|
||||
|
||||
/** Creates a new instance of XMLEventAllocator */
|
||||
public StAXEventAllocatorBase() {
|
||||
if (System.getProperty("javax.xml.stream.XMLEventFactory")==null) {
|
||||
System.setProperty("javax.xml.stream.XMLEventFactory",
|
||||
"com.sun.xml.internal.fastinfoset.stax.factory.StAXEventFactory");
|
||||
}
|
||||
factory = XMLEventFactory.newInstance();
|
||||
}
|
||||
|
||||
// ---------------------methods defined by XMLEventAllocator-----------------//
|
||||
|
||||
/**
|
||||
* This method creates an instance of the XMLEventAllocator. This
|
||||
* allows the XMLInputFactory to allocate a new instance per reader.
|
||||
*/
|
||||
public XMLEventAllocator newInstance() {
|
||||
return new StAXEventAllocatorBase();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allocates an event given the current state of the XMLStreamReader.
|
||||
* If this XMLEventAllocator does not have a one-to-one mapping between reader state
|
||||
* and events this method will return null.
|
||||
* @param streamReader The XMLStreamReader to allocate from
|
||||
* @return the event corresponding to the current reader state
|
||||
*/
|
||||
public XMLEvent allocate(XMLStreamReader streamReader) throws XMLStreamException {
|
||||
if(streamReader == null )
|
||||
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.nullReader"));
|
||||
return getXMLEvent(streamReader);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allocates an event or set of events given the current state of
|
||||
* the XMLStreamReader and adds the event or set of events to the consumer that
|
||||
* was passed in.
|
||||
* @param streamReader The XMLStreamReader to allocate from
|
||||
* @param consumer The XMLEventConsumer to add to.
|
||||
*/
|
||||
public void allocate(XMLStreamReader streamReader, XMLEventConsumer consumer) throws XMLStreamException {
|
||||
consumer.add(getXMLEvent(streamReader));
|
||||
|
||||
}
|
||||
// ---------------------end of methods defined by XMLEventAllocator-----------------//
|
||||
|
||||
|
||||
XMLEvent getXMLEvent(XMLStreamReader reader){
|
||||
XMLEvent event = null;
|
||||
//returns the current event
|
||||
int eventType = reader.getEventType();
|
||||
//this needs to be set before creating events
|
||||
factory.setLocation(reader.getLocation());
|
||||
switch(eventType){
|
||||
|
||||
case XMLEvent.START_ELEMENT:
|
||||
{
|
||||
StartElementEvent startElement = (StartElementEvent)factory.createStartElement(reader.getPrefix(),
|
||||
reader.getNamespaceURI(), reader.getLocalName());
|
||||
|
||||
addAttributes(startElement,reader);
|
||||
addNamespaces(startElement, reader);
|
||||
//need to fix it along with the Reader
|
||||
//setNamespaceContext(startElement,reader);
|
||||
event = startElement;
|
||||
break;
|
||||
}
|
||||
case XMLEvent.END_ELEMENT:
|
||||
{
|
||||
EndElementEvent endElement = (EndElementEvent)factory.createEndElement(
|
||||
reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName());
|
||||
addNamespaces(endElement,reader);
|
||||
event = endElement ;
|
||||
break;
|
||||
}
|
||||
case XMLEvent.PROCESSING_INSTRUCTION:
|
||||
{
|
||||
event = factory.createProcessingInstruction(reader.getPITarget(),reader.getPIData());
|
||||
break;
|
||||
}
|
||||
case XMLEvent.CHARACTERS:
|
||||
{
|
||||
if (reader.isWhiteSpace())
|
||||
event = factory.createSpace(reader.getText());
|
||||
else
|
||||
event = factory.createCharacters(reader.getText());
|
||||
|
||||
break;
|
||||
}
|
||||
case XMLEvent.COMMENT:
|
||||
{
|
||||
event = factory.createComment(reader.getText());
|
||||
break;
|
||||
}
|
||||
case XMLEvent.START_DOCUMENT:
|
||||
{
|
||||
StartDocumentEvent docEvent = (StartDocumentEvent)factory.createStartDocument(
|
||||
reader.getVersion(), reader.getEncoding(), reader.isStandalone());
|
||||
if(reader.getCharacterEncodingScheme() != null){
|
||||
docEvent.setDeclaredEncoding(true);
|
||||
}else{
|
||||
docEvent.setDeclaredEncoding(false);
|
||||
}
|
||||
event = docEvent ;
|
||||
break;
|
||||
}
|
||||
case XMLEvent.END_DOCUMENT:{
|
||||
EndDocumentEvent endDocumentEvent = new EndDocumentEvent() ;
|
||||
event = endDocumentEvent ;
|
||||
break;
|
||||
}
|
||||
case XMLEvent.ENTITY_REFERENCE:{
|
||||
event = factory.createEntityReference(reader.getLocalName(),
|
||||
new EntityDeclarationImpl(reader.getLocalName(),reader.getText()));
|
||||
break;
|
||||
|
||||
}
|
||||
case XMLEvent.ATTRIBUTE:{
|
||||
event = null ;
|
||||
break;
|
||||
}
|
||||
case XMLEvent.DTD:{
|
||||
event = factory.createDTD(reader.getText());
|
||||
break;
|
||||
}
|
||||
case XMLEvent.CDATA:{
|
||||
event = factory.createCData(reader.getText());
|
||||
break;
|
||||
}
|
||||
case XMLEvent.SPACE:{
|
||||
event = factory.createSpace(reader.getText());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return event ;
|
||||
}
|
||||
|
||||
//use event.addAttribute instead of addAttributes to avoid creating another list
|
||||
protected void addAttributes(StartElementEvent event,XMLStreamReader streamReader){
|
||||
AttributeBase attr = null;
|
||||
for(int i=0; i<streamReader.getAttributeCount() ;i++){
|
||||
attr = (AttributeBase)factory.createAttribute(streamReader.getAttributeName(i),
|
||||
streamReader.getAttributeValue(i));
|
||||
attr.setAttributeType(streamReader.getAttributeType(i));
|
||||
attr.setSpecified(streamReader.isAttributeSpecified(i));
|
||||
event.addAttribute(attr);
|
||||
}
|
||||
}
|
||||
|
||||
//add namespaces to StartElement/EndElement
|
||||
protected void addNamespaces(StartElementEvent event,XMLStreamReader streamReader){
|
||||
Namespace namespace = null;
|
||||
for(int i=0; i<streamReader.getNamespaceCount(); i++){
|
||||
namespace = factory.createNamespace(streamReader.getNamespacePrefix(i),
|
||||
streamReader.getNamespaceURI(i));
|
||||
event.addNamespace(namespace);
|
||||
}
|
||||
}
|
||||
protected void addNamespaces(EndElementEvent event,XMLStreamReader streamReader){
|
||||
Namespace namespace = null;
|
||||
for(int i=0; i<streamReader.getNamespaceCount(); i++){
|
||||
namespace = factory.createNamespace(streamReader.getNamespacePrefix(i),
|
||||
streamReader.getNamespaceURI(i));
|
||||
event.addNamespace(namespace);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.stax.*;
|
||||
import java.util.NoSuchElementException;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
import javax.xml.stream.util.XMLEventAllocator;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
|
||||
|
||||
public class StAXEventReader implements javax.xml.stream.XMLEventReader{
|
||||
protected XMLStreamReader _streamReader ;
|
||||
protected XMLEventAllocator _eventAllocator;
|
||||
private XMLEvent _currentEvent; //the current event
|
||||
private XMLEvent[] events = new XMLEvent[3];
|
||||
private int size = 3;
|
||||
private int currentIndex = 0;
|
||||
private boolean hasEvent = false; //true when current event exists, false initially & at end
|
||||
|
||||
//only constructor will do because we delegate everything to underlying XMLStreamReader
|
||||
public StAXEventReader(XMLStreamReader reader) throws XMLStreamException {
|
||||
_streamReader = reader ;
|
||||
_eventAllocator = (XMLEventAllocator)reader.getProperty(XMLInputFactory.ALLOCATOR);
|
||||
if(_eventAllocator == null){
|
||||
_eventAllocator = new StAXEventAllocatorBase();
|
||||
}
|
||||
//initialize
|
||||
if (_streamReader.hasNext())
|
||||
{
|
||||
_streamReader.next();
|
||||
_currentEvent =_eventAllocator.allocate(_streamReader);
|
||||
events[0] = _currentEvent;
|
||||
hasEvent = true;
|
||||
} else {
|
||||
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.noElement"));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return hasEvent;
|
||||
}
|
||||
|
||||
public XMLEvent nextEvent() throws XMLStreamException {
|
||||
XMLEvent event = null;
|
||||
XMLEvent nextEvent = null;
|
||||
if (hasEvent)
|
||||
{
|
||||
event = events[currentIndex];
|
||||
events[currentIndex] = null;
|
||||
if (_streamReader.hasNext())
|
||||
{
|
||||
//advance and read the next
|
||||
_streamReader.next();
|
||||
nextEvent = _eventAllocator.allocate(_streamReader);
|
||||
if (++currentIndex==size)
|
||||
currentIndex = 0;
|
||||
events[currentIndex] = nextEvent;
|
||||
hasEvent = true;
|
||||
} else {
|
||||
_currentEvent = null;
|
||||
hasEvent = false;
|
||||
}
|
||||
return event;
|
||||
}
|
||||
else{
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
//stream reader is read-only.
|
||||
throw new java.lang.UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
public void close() throws XMLStreamException {
|
||||
_streamReader.close();
|
||||
}
|
||||
|
||||
/** Reads the content of a text-only element. Precondition:
|
||||
* the current event is START_ELEMENT. Postcondition:
|
||||
* The current event is the corresponding END_ELEMENT.
|
||||
* @throws XMLStreamException if the current event is not a START_ELEMENT
|
||||
* or if a non text element is encountered
|
||||
*/
|
||||
public String getElementText() throws XMLStreamException {
|
||||
if(!hasEvent) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
if(!_currentEvent.isStartElement()) {
|
||||
StAXDocumentParser parser = (StAXDocumentParser)_streamReader;
|
||||
return parser.getElementText(true);
|
||||
} else {
|
||||
return _streamReader.getElementText();
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the value of a feature/property from the underlying implementation
|
||||
* @param name The name of the property
|
||||
* @return The value of the property
|
||||
* @throws IllegalArgumentException if the property is not supported
|
||||
*/
|
||||
public Object getProperty(java.lang.String name) throws java.lang.IllegalArgumentException {
|
||||
return _streamReader.getProperty(name) ;
|
||||
}
|
||||
|
||||
/** Skips any insignificant space events until a START_ELEMENT or
|
||||
* END_ELEMENT is reached. If anything other than space characters are
|
||||
* encountered, an exception is thrown. This method should
|
||||
* be used when processing element-only content because
|
||||
* the parser is not able to recognize ignorable whitespace if
|
||||
* the DTD is missing or not interpreted.
|
||||
* @throws XMLStreamException if anything other than space characters are encountered
|
||||
*/
|
||||
public XMLEvent nextTag() throws XMLStreamException {
|
||||
if(!hasEvent) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
StAXDocumentParser parser = (StAXDocumentParser)_streamReader;
|
||||
parser.nextTag(true);
|
||||
return _eventAllocator.allocate(_streamReader);
|
||||
}
|
||||
|
||||
//XMLEventReader extends Iterator;
|
||||
public Object next() {
|
||||
try{
|
||||
return nextEvent();
|
||||
}catch(XMLStreamException streamException){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public XMLEvent peek() throws XMLStreamException{
|
||||
if (!hasEvent)
|
||||
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.noElement"));
|
||||
_currentEvent = events[currentIndex];
|
||||
return _currentEvent;
|
||||
}
|
||||
|
||||
public void setAllocator(XMLEventAllocator allocator) {
|
||||
if (allocator == null)
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.nullXMLEventAllocator"));
|
||||
|
||||
_eventAllocator = allocator;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import java.util.Iterator;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
import javax.xml.stream.XMLEventWriter;
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.events.*;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class StAXEventWriter implements XMLEventWriter {
|
||||
|
||||
private XMLStreamWriter _streamWriter ;
|
||||
/**
|
||||
*
|
||||
* @param streamWriter
|
||||
*/
|
||||
public StAXEventWriter(XMLStreamWriter streamWriter){
|
||||
_streamWriter = streamWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes any cached events to the underlying output mechanism
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void flush() throws XMLStreamException {
|
||||
_streamWriter.flush();
|
||||
}
|
||||
/**
|
||||
* Frees any resources associated with this stream
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void close() throws javax.xml.stream.XMLStreamException {
|
||||
_streamWriter.close();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param eventReader
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void add(XMLEventReader eventReader) throws XMLStreamException {
|
||||
if(eventReader == null) throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.nullEventReader"));
|
||||
while(eventReader.hasNext()){
|
||||
add(eventReader.nextEvent());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event to the output stream
|
||||
* Adding a START_ELEMENT will open a new namespace scope that
|
||||
* will be closed when the corresponding END_ELEMENT is written.
|
||||
*
|
||||
* @param event
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void add(XMLEvent event) throws XMLStreamException {
|
||||
int type = event.getEventType();
|
||||
switch(type){
|
||||
case XMLEvent.DTD:{
|
||||
DTD dtd = (DTD)event ;
|
||||
_streamWriter.writeDTD(dtd.getDocumentTypeDeclaration());
|
||||
break;
|
||||
}
|
||||
case XMLEvent.START_DOCUMENT :{
|
||||
StartDocument startDocument = (StartDocument)event ;
|
||||
_streamWriter.writeStartDocument(startDocument.getCharacterEncodingScheme(), startDocument.getVersion());
|
||||
break;
|
||||
}
|
||||
case XMLEvent.START_ELEMENT :{
|
||||
StartElement startElement = event.asStartElement() ;
|
||||
QName qname = startElement.getName();
|
||||
_streamWriter.writeStartElement(qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI());
|
||||
|
||||
Iterator iterator = startElement.getNamespaces();
|
||||
while(iterator.hasNext()){
|
||||
Namespace namespace = (Namespace)iterator.next();
|
||||
_streamWriter.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI());
|
||||
}
|
||||
|
||||
Iterator attributes = startElement.getAttributes();
|
||||
while(attributes.hasNext()){
|
||||
Attribute attribute = (Attribute)attributes.next();
|
||||
QName name = attribute.getName();
|
||||
_streamWriter.writeAttribute(name.getPrefix(), name.getNamespaceURI(),
|
||||
name.getLocalPart(),attribute.getValue());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case XMLEvent.NAMESPACE:{
|
||||
Namespace namespace = (Namespace)event;
|
||||
_streamWriter.writeNamespace(namespace.getPrefix(), namespace.getNamespaceURI());
|
||||
break ;
|
||||
}
|
||||
case XMLEvent.COMMENT: {
|
||||
Comment comment = (Comment)event ;
|
||||
_streamWriter.writeComment(comment.getText());
|
||||
break;
|
||||
}
|
||||
case XMLEvent.PROCESSING_INSTRUCTION:{
|
||||
ProcessingInstruction processingInstruction = (ProcessingInstruction)event ;
|
||||
_streamWriter.writeProcessingInstruction(processingInstruction.getTarget(), processingInstruction.getData());
|
||||
break;
|
||||
}
|
||||
case XMLEvent.CHARACTERS:{
|
||||
Characters characters = event.asCharacters();
|
||||
//check if the CHARACTERS are CDATA
|
||||
if(characters.isCData()){
|
||||
_streamWriter.writeCData(characters.getData());
|
||||
}
|
||||
else{
|
||||
_streamWriter.writeCharacters(characters.getData());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case XMLEvent.ENTITY_REFERENCE:{
|
||||
EntityReference entityReference = (EntityReference)event ;
|
||||
_streamWriter.writeEntityRef(entityReference.getName());
|
||||
break;
|
||||
}
|
||||
case XMLEvent.ATTRIBUTE:{
|
||||
Attribute attribute = (Attribute)event;
|
||||
QName qname = attribute.getName();
|
||||
_streamWriter.writeAttribute(qname.getPrefix(), qname.getNamespaceURI(), qname.getLocalPart(),attribute.getValue());
|
||||
break;
|
||||
}
|
||||
case XMLEvent.CDATA:{
|
||||
//there is no separate CDATA datatype but CDATA event can be reported
|
||||
//by using vendor specific CDATA property.
|
||||
Characters characters = (Characters)event;
|
||||
if(characters.isCData()){
|
||||
_streamWriter.writeCData(characters.getData());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case XMLEvent.END_ELEMENT:{
|
||||
_streamWriter.writeEndElement();
|
||||
break;
|
||||
}
|
||||
case XMLEvent.END_DOCUMENT:{
|
||||
_streamWriter.writeEndDocument();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.eventTypeNotSupported", new Object[]{Util.getEventTypeString(type)}));
|
||||
//throw new XMLStreamException("Unknown Event type = " + type);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the prefix the uri is bound to
|
||||
* @param uri the uri to look up
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public String getPrefix(String uri) throws XMLStreamException {
|
||||
return _streamWriter.getPrefix(uri);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current namespace context.
|
||||
* @return the current namespace context
|
||||
*/
|
||||
public NamespaceContext getNamespaceContext() {
|
||||
return _streamWriter.getNamespaceContext();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a URI to the default namespace
|
||||
* This URI is bound
|
||||
* in the scope of the current START_ELEMENT / END_ELEMENT pair.
|
||||
* If this method is called before a START_ELEMENT has been written
|
||||
* the uri is bound in the root scope.
|
||||
* @param uri the uri to bind to the default namespace
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void setDefaultNamespace(String uri) throws XMLStreamException {
|
||||
_streamWriter.setDefaultNamespace(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current namespace context for prefix and uri bindings.
|
||||
* This context becomes the root namespace context for writing and
|
||||
* will replace the current root namespace context. Subsequent calls
|
||||
* to setPrefix and setDefaultNamespace will bind namespaces using
|
||||
* the context passed to the method as the root context for resolving
|
||||
* namespaces.
|
||||
* @param namespaceContext the namespace context to use for this writer
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void setNamespaceContext(NamespaceContext namespaceContext) throws XMLStreamException {
|
||||
_streamWriter.setNamespaceContext(namespaceContext);
|
||||
}
|
||||
/**
|
||||
* Sets the prefix the uri is bound to. This prefix is bound
|
||||
* in the scope of the current START_ELEMENT / END_ELEMENT pair.
|
||||
* If this method is called before a START_ELEMENT has been written
|
||||
* the prefix is bound in the root scope.
|
||||
* @param prefix the prefix to bind to the uri
|
||||
* @param uri the uri to bind to the prefix
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public void setPrefix(String prefix, String uri) throws XMLStreamException {
|
||||
_streamWriter.setPrefix(prefix, uri);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 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.stax.events;
|
||||
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
import javax.xml.stream.EventFilter;
|
||||
import javax.xml.stream.events.Characters;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class StAXFilteredEvent implements XMLEventReader {
|
||||
private XMLEventReader eventReader;
|
||||
private EventFilter _filter;
|
||||
|
||||
/** Creates a new instance of StAXFilteredEvent */
|
||||
public StAXFilteredEvent() {
|
||||
}
|
||||
|
||||
public StAXFilteredEvent(XMLEventReader reader, EventFilter filter) throws XMLStreamException
|
||||
{
|
||||
eventReader = reader;
|
||||
_filter = filter;
|
||||
}
|
||||
|
||||
public void setEventReader(XMLEventReader reader) {
|
||||
eventReader = reader;
|
||||
}
|
||||
|
||||
public void setFilter(EventFilter filter) {
|
||||
_filter = filter;
|
||||
}
|
||||
|
||||
public Object next() {
|
||||
try {
|
||||
return nextEvent();
|
||||
} catch (XMLStreamException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public XMLEvent nextEvent() throws XMLStreamException
|
||||
{
|
||||
if (hasNext())
|
||||
return eventReader.nextEvent();
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getElementText() throws XMLStreamException
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
XMLEvent e = nextEvent();
|
||||
if (!e.isStartElement())
|
||||
throw new XMLStreamException(
|
||||
CommonResourceBundle.getInstance().getString("message.mustBeOnSTART_ELEMENT"));
|
||||
|
||||
while(hasNext()) {
|
||||
e = nextEvent();
|
||||
if(e.isStartElement())
|
||||
throw new XMLStreamException(
|
||||
CommonResourceBundle.getInstance().getString("message.getElementTextExpectTextOnly"));
|
||||
if(e.isCharacters())
|
||||
buffer.append(((Characters) e).getData());
|
||||
if(e.isEndElement())
|
||||
return buffer.toString();
|
||||
}
|
||||
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.END_ELEMENTnotFound"));
|
||||
}
|
||||
|
||||
public XMLEvent nextTag() throws XMLStreamException {
|
||||
while(hasNext()) {
|
||||
XMLEvent e = nextEvent();
|
||||
if (e.isStartElement() || e.isEndElement())
|
||||
return e;
|
||||
}
|
||||
throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.startOrEndNotFound"));
|
||||
}
|
||||
|
||||
|
||||
public boolean hasNext()
|
||||
{
|
||||
try {
|
||||
while(eventReader.hasNext()) {
|
||||
if (_filter.accept(eventReader.peek())) return true;
|
||||
eventReader.nextEvent();
|
||||
}
|
||||
return false;
|
||||
} catch (XMLStreamException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public XMLEvent peek() throws XMLStreamException
|
||||
{
|
||||
if (hasNext())
|
||||
return eventReader.peek();
|
||||
return null;
|
||||
}
|
||||
|
||||
public void close() throws XMLStreamException
|
||||
{
|
||||
eventReader.close();
|
||||
}
|
||||
|
||||
public Object getProperty(String name) {
|
||||
return eventReader.getProperty(name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.events.StartDocument;
|
||||
|
||||
|
||||
public class StartDocumentEvent extends EventBase implements StartDocument {
|
||||
|
||||
protected String _systemId;
|
||||
protected String _encoding = XMLConstants.ENCODING; //default
|
||||
protected boolean _standalone = true;
|
||||
protected String _version = XMLConstants.XMLVERSION;
|
||||
private boolean _encodingSet = false;
|
||||
private boolean _standaloneSet = false;
|
||||
|
||||
public void reset() {
|
||||
_encoding = XMLConstants.ENCODING;
|
||||
_standalone = true;
|
||||
_version = XMLConstants.XMLVERSION;
|
||||
_encodingSet = false;
|
||||
_standaloneSet=false;
|
||||
}
|
||||
public StartDocumentEvent() {
|
||||
this(null ,null);
|
||||
}
|
||||
|
||||
public StartDocumentEvent(String encoding){
|
||||
this(encoding, null);
|
||||
}
|
||||
|
||||
public StartDocumentEvent(String encoding, String version){
|
||||
if (encoding != null) {
|
||||
_encoding = encoding;
|
||||
_encodingSet = true;
|
||||
}
|
||||
if (version != null)
|
||||
_version = version;
|
||||
setEventType(XMLStreamConstants.START_DOCUMENT);
|
||||
}
|
||||
|
||||
|
||||
// ------------------- methods defined in StartDocument -------------------------
|
||||
/**
|
||||
* Returns the system ID of the XML data
|
||||
* @return the system ID, defaults to ""
|
||||
*/
|
||||
public String getSystemId() {
|
||||
return super.getSystemId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the encoding style of the XML data
|
||||
* @return the character encoding, defaults to "UTF-8"
|
||||
*/
|
||||
public String getCharacterEncodingScheme() {
|
||||
return _encoding;
|
||||
}
|
||||
/**
|
||||
* Returns true if CharacterEncodingScheme was set in
|
||||
* the encoding declaration of the document
|
||||
*/
|
||||
public boolean encodingSet() {
|
||||
return _encodingSet;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns if this XML is standalone
|
||||
* @return the standalone state of XML, defaults to "no"
|
||||
*/
|
||||
public boolean isStandalone() {
|
||||
return _standalone;
|
||||
}
|
||||
/**
|
||||
* Returns true if the standalone attribute was set in
|
||||
* the encoding declaration of the document.
|
||||
*/
|
||||
public boolean standaloneSet() {
|
||||
return _standaloneSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version of XML of this XML stream
|
||||
* @return the version of XML, defaults to "1.0"
|
||||
*/
|
||||
public String getVersion() {
|
||||
return _version;
|
||||
}
|
||||
// ------------------- end of methods defined in StartDocument -------------------------
|
||||
|
||||
public void setStandalone(boolean standalone) {
|
||||
_standaloneSet = true;
|
||||
_standalone = standalone;
|
||||
}
|
||||
|
||||
public void setStandalone(String s) {
|
||||
_standaloneSet = true;
|
||||
if(s == null) {
|
||||
_standalone = true;
|
||||
return;
|
||||
}
|
||||
if(s.equals("yes"))
|
||||
_standalone = true;
|
||||
else
|
||||
_standalone = false;
|
||||
}
|
||||
|
||||
|
||||
public void setEncoding(String encoding) {
|
||||
_encoding = encoding;
|
||||
_encodingSet = true;
|
||||
}
|
||||
|
||||
void setDeclaredEncoding(boolean value){
|
||||
_encodingSet = value;
|
||||
}
|
||||
|
||||
public void setVersion(String s) {
|
||||
_version = s;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_encoding = "UTF-8";
|
||||
_standalone = true;
|
||||
_version = "1.0";
|
||||
_encodingSet = false;
|
||||
_standaloneSet = false;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String s = "<?xml version=\"" + _version + "\"";
|
||||
s = s + " encoding='" + _encoding + "'";
|
||||
if(_standaloneSet) {
|
||||
if(_standalone)
|
||||
s = s + " standalone='yes'?>";
|
||||
else
|
||||
s = s + " standalone='no'?>";
|
||||
} else {
|
||||
s = s + "?>";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public boolean isStartDocument() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.events.Attribute;
|
||||
import javax.xml.stream.events.Namespace;
|
||||
import javax.xml.stream.events.StartElement;
|
||||
|
||||
|
||||
public class StartElementEvent extends EventBase implements StartElement {
|
||||
|
||||
private Map _attributes;
|
||||
private List _namespaces;
|
||||
private NamespaceContext _context = null;
|
||||
private QName _qname;
|
||||
|
||||
public void reset() {
|
||||
if (_attributes != null) _attributes.clear();
|
||||
if (_namespaces != null) _namespaces.clear();
|
||||
if (_context != null) _context = null;
|
||||
}
|
||||
|
||||
public StartElementEvent() {
|
||||
init();
|
||||
}
|
||||
|
||||
public StartElementEvent(String prefix, String uri, String localpart) {
|
||||
init();
|
||||
if (uri == null) uri = "";
|
||||
if (prefix == null) prefix ="";
|
||||
_qname = new QName(uri, localpart, prefix);
|
||||
setEventType(START_ELEMENT);
|
||||
}
|
||||
|
||||
public StartElementEvent(QName qname) {
|
||||
init();
|
||||
_qname = qname;
|
||||
}
|
||||
|
||||
public StartElementEvent(StartElement startelement) {
|
||||
this(startelement.getName());
|
||||
addAttributes(startelement.getAttributes());
|
||||
addNamespaces(startelement.getNamespaces());
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
setEventType(XMLStreamConstants.START_ELEMENT);
|
||||
_attributes = new HashMap();
|
||||
_namespaces = new ArrayList();
|
||||
}
|
||||
|
||||
// ---------------------methods defined by StartElement-----------------//
|
||||
/**
|
||||
* Get the name of this event
|
||||
* @return the qualified name of this event
|
||||
*/
|
||||
public QName getName() {
|
||||
return _qname;
|
||||
}
|
||||
/**
|
||||
* Returns an Iterator of non-namespace declared attributes
|
||||
* returns an empty iterator if there are no attributes. The
|
||||
* iterator must contain only implementations of the javax.xml.stream.Attribute
|
||||
* interface. Attributes are fundamentally unordered and may not be reported
|
||||
* in any order.
|
||||
*
|
||||
* @return a readonly Iterator over Attribute interfaces, or an
|
||||
* empty iterator
|
||||
*/
|
||||
public Iterator getAttributes() {
|
||||
if(_attributes != null){
|
||||
Collection coll = _attributes.values();
|
||||
return new ReadIterator(coll.iterator());
|
||||
}
|
||||
return EmptyIterator.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Iterator of namespaces declared on this element.
|
||||
* This Iterator does not contain previously declared namespaces
|
||||
* unless they appear on the current START_ELEMENT.
|
||||
* Therefore this list may contain redeclared namespaces and duplicate namespace
|
||||
* declarations. Use the getNamespaceContext() method to get the
|
||||
* current context of namespace declarations.
|
||||
*
|
||||
* <p>The iterator must contain only implementations of the
|
||||
* javax.xml.stream.Namespace interface.
|
||||
*
|
||||
* <p>A Namespace is an Attribute. One
|
||||
* can iterate over a list of namespaces as a list of attributes.
|
||||
* However this method returns only the list of namespaces
|
||||
* declared on this START_ELEMENT and does not
|
||||
* include the attributes declared on this START_ELEMENT.
|
||||
*
|
||||
* @return a readonly Iterator over Namespace interfaces, or an
|
||||
* empty iterator if there are no namespaces.
|
||||
*
|
||||
*/
|
||||
public Iterator getNamespaces() {
|
||||
if(_namespaces != null){
|
||||
return new ReadIterator(_namespaces.iterator());
|
||||
}
|
||||
return EmptyIterator.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attribute referred to by this name
|
||||
* @param qname the qname of the desired name
|
||||
* @return the attribute corresponding to the name value or null
|
||||
*/
|
||||
public Attribute getAttributeByName(QName qname) {
|
||||
if(qname == null)
|
||||
return null;
|
||||
return (Attribute)_attributes.get(qname);
|
||||
}
|
||||
|
||||
/** Gets a read-only namespace context. If no context is
|
||||
* available this method will return an empty namespace context.
|
||||
* The NamespaceContext contains information about all namespaces
|
||||
* in scope for this StartElement.
|
||||
*
|
||||
* @return the current namespace context
|
||||
*/
|
||||
public NamespaceContext getNamespaceContext() {
|
||||
return _context;
|
||||
}
|
||||
// ---------------------end of methods defined by StartElement-----------------//
|
||||
|
||||
public void setName(QName qname) {
|
||||
this._qname = qname;
|
||||
}
|
||||
|
||||
|
||||
public String getNamespace(){
|
||||
return _qname.getNamespaceURI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value that the prefix is bound to in the
|
||||
* context of this element. Returns null if
|
||||
* the prefix is not bound in this context
|
||||
* @param prefix the prefix to lookup
|
||||
* @return the uri bound to the prefix or null
|
||||
*/
|
||||
public String getNamespaceURI(String prefix) {
|
||||
//first check if the URI was supplied when creating this startElement event
|
||||
if( getNamespace() != null ) return getNamespace();
|
||||
//else check the namespace context
|
||||
if(_context != null)
|
||||
return _context.getNamespaceURI(prefix);
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder(64);
|
||||
|
||||
sb.append('<').append(nameAsString());
|
||||
|
||||
if(_attributes != null){
|
||||
Iterator it = this.getAttributes();
|
||||
Attribute attr = null;
|
||||
while(it.hasNext()){
|
||||
attr = (Attribute)it.next();
|
||||
sb.append(' ').append(attr.toString());
|
||||
}
|
||||
}
|
||||
|
||||
if(_namespaces != null){
|
||||
Iterator it = _namespaces.iterator();
|
||||
Namespace attr = null;
|
||||
while(it.hasNext()){
|
||||
attr = (Namespace)it.next();
|
||||
sb.append(' ').append(attr.toString());
|
||||
}
|
||||
}
|
||||
sb.append('>');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/** Return this event as String
|
||||
* @return String Event returned as string.
|
||||
*/
|
||||
public String nameAsString() {
|
||||
if("".equals(_qname.getNamespaceURI()))
|
||||
return _qname.getLocalPart();
|
||||
if(_qname.getPrefix() != null)
|
||||
return "['" + _qname.getNamespaceURI() + "']:" + _qname.getPrefix() + ":" + _qname.getLocalPart();
|
||||
else
|
||||
return "['" + _qname.getNamespaceURI() + "']:" + _qname.getLocalPart();
|
||||
}
|
||||
|
||||
|
||||
public void setNamespaceContext(NamespaceContext context) {
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public void addAttribute(Attribute attr){
|
||||
_attributes.put(attr.getName(),attr);
|
||||
}
|
||||
|
||||
public void addAttributes(Iterator attrs){
|
||||
if(attrs != null) {
|
||||
while(attrs.hasNext()){
|
||||
Attribute attr = (Attribute)attrs.next();
|
||||
_attributes.put(attr.getName(),attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addNamespace(Namespace namespace){
|
||||
if(namespace != null) {
|
||||
_namespaces.add(namespace);
|
||||
}
|
||||
}
|
||||
|
||||
public void addNamespaces(Iterator namespaces){
|
||||
if(namespaces != null) {
|
||||
while(namespaces.hasNext()){
|
||||
Namespace namespace = (Namespace)namespaces.next();
|
||||
_namespaces.add(namespace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.stax.events;
|
||||
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
|
||||
/** A Utility class for the StAX Events implementation.
|
||||
*/
|
||||
public class Util {
|
||||
|
||||
/**
|
||||
* A string is empty if it's null or contains nothing
|
||||
*
|
||||
* @param s The string to check.
|
||||
*/
|
||||
public static boolean isEmptyString(String s) {
|
||||
if (s != null && !s.equals(""))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
public final static String getEventTypeString(int eventType) {
|
||||
switch (eventType){
|
||||
case XMLStreamConstants.START_ELEMENT:
|
||||
return "START_ELEMENT";
|
||||
case XMLStreamConstants.END_ELEMENT:
|
||||
return "END_ELEMENT";
|
||||
case XMLStreamConstants.PROCESSING_INSTRUCTION:
|
||||
return "PROCESSING_INSTRUCTION";
|
||||
case XMLStreamConstants.CHARACTERS:
|
||||
return "CHARACTERS";
|
||||
case XMLStreamConstants.COMMENT:
|
||||
return "COMMENT";
|
||||
case XMLStreamConstants.START_DOCUMENT:
|
||||
return "START_DOCUMENT";
|
||||
case XMLStreamConstants.END_DOCUMENT:
|
||||
return "END_DOCUMENT";
|
||||
case XMLStreamConstants.ENTITY_REFERENCE:
|
||||
return "ENTITY_REFERENCE";
|
||||
case XMLStreamConstants.ATTRIBUTE:
|
||||
return "ATTRIBUTE";
|
||||
case XMLStreamConstants.DTD:
|
||||
return "DTD";
|
||||
case XMLStreamConstants.CDATA:
|
||||
return "CDATA";
|
||||
}
|
||||
return "UNKNOWN_EVENT_TYPE";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.stax.events;
|
||||
|
||||
|
||||
public class XMLConstants {
|
||||
|
||||
public static final String ENCODING = "UTF-8";
|
||||
public static final String XMLVERSION = "1.0";
|
||||
}
|
||||
@@ -0,0 +1,342 @@
|
||||
/*
|
||||
* 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.stax.factory;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
import javax.xml.stream.Location;
|
||||
import javax.xml.stream.XMLEventFactory;
|
||||
import javax.xml.stream.events.*;
|
||||
import java.util.Iterator;
|
||||
import com.sun.xml.internal.fastinfoset.stax.events.*;
|
||||
|
||||
|
||||
public class StAXEventFactory extends XMLEventFactory {
|
||||
Location location = null;
|
||||
|
||||
/** Creates a new instance of StAXEventFactory */
|
||||
public StAXEventFactory() {
|
||||
}
|
||||
/**
|
||||
* This method allows setting of the Location on each event that
|
||||
* is created by this factory. The values are copied by value into
|
||||
* the events created by this factory. To reset the location
|
||||
* information set the location to null.
|
||||
* @param location the location to set on each event created
|
||||
*/
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Attribute
|
||||
* @param prefix the prefix of this attribute, may not be null
|
||||
* @param namespaceURI the attribute value is set to this value, may not be null
|
||||
* @param localName the local name of the XML name of the attribute, localName cannot be null
|
||||
* @param value the attribute value to set, may not be null
|
||||
* @return the Attribute with specified values
|
||||
*/
|
||||
public Attribute createAttribute(String prefix, String namespaceURI, String localName, String value) {
|
||||
AttributeBase attr = new AttributeBase(prefix, namespaceURI, localName, value, null);
|
||||
if(location != null)attr.setLocation(location);
|
||||
return attr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Attribute
|
||||
* @param localName the local name of the XML name of the attribute, localName cannot be null
|
||||
* @param value the attribute value to set, may not be null
|
||||
* @return the Attribute with specified values
|
||||
*/
|
||||
public Attribute createAttribute(String localName, String value) {
|
||||
AttributeBase attr = new AttributeBase(localName, value);
|
||||
if(location != null)attr.setLocation(location);
|
||||
return attr;
|
||||
}
|
||||
|
||||
public Attribute createAttribute(QName name, String value) {
|
||||
AttributeBase attr = new AttributeBase(name, value);
|
||||
if(location != null)attr.setLocation(location);
|
||||
return attr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new default Namespace
|
||||
* @param namespaceURI the default namespace uri
|
||||
* @return the Namespace with the specified value
|
||||
*/
|
||||
public Namespace createNamespace(String namespaceURI) {
|
||||
NamespaceBase event = new NamespaceBase(namespaceURI);
|
||||
if(location != null)event.setLocation(location);
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Namespace
|
||||
* @param prefix the prefix of this namespace, may not be null
|
||||
* @param namespaceURI the attribute value is set to this value, may not be null
|
||||
* @return the Namespace with the specified values
|
||||
*/
|
||||
public Namespace createNamespace(String prefix, String namespaceURI) {
|
||||
NamespaceBase event = new NamespaceBase(prefix, namespaceURI);
|
||||
if(location != null)event.setLocation(location);
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new StartElement.
|
||||
* @param name the qualified name of the attribute, may not be null
|
||||
* @param attributes an optional unordered set of objects that
|
||||
* implement Attribute to add to the new StartElement, may be null
|
||||
* @param namespaces an optional unordered set of objects that
|
||||
* implement Namespace to add to the new StartElement, may be null
|
||||
* @return an instance of the requested StartElement
|
||||
*/
|
||||
public StartElement createStartElement(QName name, Iterator attributes, Iterator namespaces) {
|
||||
return createStartElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), attributes, namespaces);
|
||||
}
|
||||
|
||||
public StartElement createStartElement(String prefix, String namespaceUri, String localName) {
|
||||
StartElementEvent event = new StartElementEvent(prefix, namespaceUri, localName);
|
||||
if(location != null)event.setLocation(location);
|
||||
return event;
|
||||
}
|
||||
|
||||
public StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces) {
|
||||
return createStartElement(prefix, namespaceUri, localName, attributes, namespaces, null);
|
||||
}
|
||||
|
||||
public StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces, NamespaceContext context) {
|
||||
StartElementEvent elem = new StartElementEvent(prefix, namespaceUri, localName);
|
||||
elem.addAttributes(attributes);
|
||||
elem.addNamespaces(namespaces);
|
||||
elem.setNamespaceContext(context);
|
||||
if(location != null)elem.setLocation(location);
|
||||
return elem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new EndElement
|
||||
* @param name the qualified name of the EndElement
|
||||
* @param namespaces an optional unordered set of objects that
|
||||
* implement Namespace that have gone out of scope, may be null
|
||||
* @return an instance of the requested EndElement
|
||||
*/
|
||||
public EndElement createEndElement(QName name, Iterator namespaces) {
|
||||
return createEndElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), namespaces);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new EndElement
|
||||
* @param namespaceUri the uri of the QName of the new StartElement
|
||||
* @param localName the local name of the QName of the new StartElement
|
||||
* @param prefix the prefix of the QName of the new StartElement
|
||||
* @return an instance of the requested EndElement
|
||||
*/
|
||||
public EndElement createEndElement(String prefix, String namespaceUri, String localName) {
|
||||
EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName);
|
||||
if(location != null)event.setLocation(location);
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new EndElement
|
||||
* @param namespaceUri the uri of the QName of the new StartElement
|
||||
* @param localName the local name of the QName of the new StartElement
|
||||
* @param prefix the prefix of the QName of the new StartElement
|
||||
* @param namespaces an unordered set of objects that implement
|
||||
* Namespace that have gone out of scope, may be null
|
||||
* @return an instance of the requested EndElement
|
||||
*/
|
||||
public EndElement createEndElement(String prefix, String namespaceUri, String localName, Iterator namespaces) {
|
||||
|
||||
EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName);
|
||||
if(namespaces!=null){
|
||||
while(namespaces.hasNext())
|
||||
event.addNamespace((Namespace)namespaces.next());
|
||||
}
|
||||
if(location != null)event.setLocation(location);
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Characters event, this method does not check if the content
|
||||
* is all whitespace. To create a space event use #createSpace(String)
|
||||
* @param content the string to create
|
||||
* @return a Characters event
|
||||
*/
|
||||
public Characters createCharacters(String content) {
|
||||
CharactersEvent charEvent = new CharactersEvent(content);
|
||||
if(location != null)charEvent.setLocation(location);
|
||||
return charEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Characters event with the CData flag set to true
|
||||
* @param content the string to create
|
||||
* @return a Characters event
|
||||
*/
|
||||
public Characters createCData(String content) {
|
||||
CharactersEvent charEvent = new CharactersEvent(content, true);
|
||||
if(location != null)charEvent.setLocation(location);
|
||||
return charEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Characters event with the isSpace flag set to true
|
||||
* @param content the content of the space to create
|
||||
* @return a Characters event
|
||||
*/
|
||||
public Characters createSpace(String content) {
|
||||
CharactersEvent event = new CharactersEvent(content);
|
||||
event.setSpace(true);
|
||||
if(location != null)event.setLocation(location);
|
||||
return event;
|
||||
}
|
||||
/**
|
||||
* Create an ignorable space
|
||||
* @param content the space to create
|
||||
* @return a Characters event
|
||||
*/
|
||||
public Characters createIgnorableSpace(String content) {
|
||||
CharactersEvent event = new CharactersEvent(content, false);
|
||||
event.setSpace(true);
|
||||
event.setIgnorable(true);
|
||||
if(location != null)event.setLocation(location);
|
||||
return event;
|
||||
}
|
||||
/**
|
||||
* Creates a new instance of a StartDocument event
|
||||
* @return a StartDocument event
|
||||
*/
|
||||
public StartDocument createStartDocument() {
|
||||
StartDocumentEvent event = new StartDocumentEvent();
|
||||
if(location != null)event.setLocation(location);
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of a StartDocument event
|
||||
*
|
||||
* @param encoding the encoding style
|
||||
* @return a StartDocument event
|
||||
*/
|
||||
public StartDocument createStartDocument(String encoding) {
|
||||
StartDocumentEvent event = new StartDocumentEvent(encoding);
|
||||
if(location != null)event.setLocation(location);
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of a StartDocument event
|
||||
*
|
||||
* @param encoding the encoding style
|
||||
* @param version the XML version
|
||||
* @return a StartDocument event
|
||||
*/
|
||||
public StartDocument createStartDocument(String encoding, String version) {
|
||||
StartDocumentEvent event = new StartDocumentEvent(encoding, version);
|
||||
if(location != null)event.setLocation(location);
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of a StartDocument event
|
||||
*
|
||||
* @param encoding the encoding style
|
||||
* @param version the XML version
|
||||
* @param standalone the status of standalone may be set to "true" or "false"
|
||||
* @return a StartDocument event
|
||||
*/
|
||||
public StartDocument createStartDocument(String encoding, String version, boolean standalone) {
|
||||
StartDocumentEvent event = new StartDocumentEvent(encoding, version);
|
||||
event.setStandalone(standalone);
|
||||
if(location != null)event.setLocation(location);
|
||||
return event;
|
||||
}
|
||||
|
||||
public EndDocument createEndDocument() {
|
||||
EndDocumentEvent event =new EndDocumentEvent();
|
||||
if(location != null)event.setLocation(location);
|
||||
return event;
|
||||
}
|
||||
|
||||
/** Creates a new instance of a EntityReference event
|
||||
*
|
||||
* @param name The name of the reference
|
||||
* @param entityDeclaration the declaration for the event
|
||||
* @return an EntityReference event
|
||||
*/
|
||||
public EntityReference createEntityReference(String name, EntityDeclaration entityDeclaration) {
|
||||
EntityReferenceEvent event = new EntityReferenceEvent(name, entityDeclaration);
|
||||
if(location != null)event.setLocation(location);
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a comment
|
||||
* @param text The text of the comment
|
||||
* a Comment event
|
||||
*/
|
||||
public Comment createComment(String text) {
|
||||
CommentEvent charEvent = new CommentEvent(text);
|
||||
if(location != null)charEvent.setLocation(location);
|
||||
return charEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a document type definition event
|
||||
* This string contains the entire document type declaration that matches
|
||||
* the doctypedecl in the XML 1.0 specification
|
||||
* @param dtd the text of the document type definition
|
||||
* @return a DTD event
|
||||
*/
|
||||
public DTD createDTD(String dtd) {
|
||||
DTDEvent dtdEvent = new DTDEvent(dtd);
|
||||
if(location != null)dtdEvent.setLocation(location);
|
||||
return dtdEvent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a processing instruction
|
||||
* @param target The target of the processing instruction
|
||||
* @param data The text of the processing instruction
|
||||
* @return a ProcessingInstruction event
|
||||
*/
|
||||
public ProcessingInstruction createProcessingInstruction(String target, String data) {
|
||||
ProcessingInstructionEvent event = new ProcessingInstructionEvent(target, data);
|
||||
if(location != null)event.setLocation(location);
|
||||
return event;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* 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.stax.factory;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.stax.*;
|
||||
import com.sun.xml.internal.fastinfoset.stax.events.StAXEventReader;
|
||||
import com.sun.xml.internal.fastinfoset.stax.events.StAXFilteredEvent;
|
||||
import com.sun.xml.internal.fastinfoset.stax.util.StAXFilteredParser;
|
||||
import com.sun.xml.internal.fastinfoset.tools.XML_SAX_FI;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
|
||||
import javax.xml.stream.*;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.util.XMLEventAllocator ;
|
||||
import javax.xml.transform.Source;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class StAXInputFactory extends XMLInputFactory {
|
||||
//List of supported properties and default values.
|
||||
private StAXManager _manager = new StAXManager(StAXManager.CONTEXT_READER) ;
|
||||
|
||||
public StAXInputFactory() {
|
||||
}
|
||||
|
||||
public static XMLInputFactory newInstance() {
|
||||
return XMLInputFactory.newInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new XMLStreamReader from a reader
|
||||
* @param xmlfile the XML data to read from
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public XMLStreamReader createXMLStreamReader(Reader xmlfile) throws XMLStreamException {
|
||||
return getXMLStreamReader(xmlfile);
|
||||
}
|
||||
|
||||
public XMLStreamReader createXMLStreamReader(InputStream s) throws XMLStreamException {
|
||||
return new StAXDocumentParser(s, _manager);
|
||||
}
|
||||
|
||||
public XMLStreamReader createXMLStreamReader(String systemId, Reader xmlfile) throws XMLStreamException {
|
||||
return getXMLStreamReader(xmlfile);
|
||||
}
|
||||
|
||||
public XMLStreamReader createXMLStreamReader(Source source) throws XMLStreamException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public XMLStreamReader createXMLStreamReader(String systemId, InputStream inputstream) throws XMLStreamException {
|
||||
return createXMLStreamReader(inputstream);
|
||||
}
|
||||
|
||||
|
||||
public XMLStreamReader createXMLStreamReader(InputStream inputstream, String encoding) throws XMLStreamException {
|
||||
return createXMLStreamReader(inputstream);
|
||||
}
|
||||
|
||||
|
||||
XMLStreamReader getXMLStreamReader(String systemId, InputStream inputstream, String encoding)
|
||||
throws XMLStreamException{
|
||||
return createXMLStreamReader(inputstream);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param inputstream
|
||||
* @throws XMLStreamException
|
||||
* @return
|
||||
*/
|
||||
XMLStreamReader getXMLStreamReader(Reader xmlfile)
|
||||
throws XMLStreamException{
|
||||
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
BufferedOutputStream bufferedStream = new BufferedOutputStream(byteStream);
|
||||
StAXDocumentParser sr = null;
|
||||
try {
|
||||
XML_SAX_FI convertor = new XML_SAX_FI();
|
||||
convertor.convert(xmlfile, bufferedStream);
|
||||
|
||||
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(byteStream.toByteArray());
|
||||
InputStream document = new BufferedInputStream(byteInputStream);
|
||||
sr = new StAXDocumentParser();
|
||||
sr.setInputStream(document);
|
||||
sr.setManager(_manager);
|
||||
return sr;
|
||||
//return new StAXDocumentParser(document, _manager);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param inputstream
|
||||
* @throws XMLStreamException
|
||||
* @return XMLEventReader
|
||||
*/
|
||||
public XMLEventReader createXMLEventReader(InputStream inputstream) throws XMLStreamException {
|
||||
return new StAXEventReader(createXMLStreamReader(inputstream));
|
||||
}
|
||||
|
||||
public XMLEventReader createXMLEventReader(Reader reader) throws XMLStreamException {
|
||||
return new StAXEventReader(createXMLStreamReader(reader));
|
||||
}
|
||||
|
||||
public XMLEventReader createXMLEventReader(Source source) throws XMLStreamException {
|
||||
return new StAXEventReader(createXMLStreamReader(source));
|
||||
}
|
||||
|
||||
public XMLEventReader createXMLEventReader(String systemId, InputStream inputstream) throws XMLStreamException {
|
||||
return new StAXEventReader(createXMLStreamReader(systemId, inputstream));
|
||||
}
|
||||
|
||||
public XMLEventReader createXMLEventReader(java.io.InputStream stream, String encoding) throws XMLStreamException {
|
||||
return new StAXEventReader(createXMLStreamReader(stream, encoding));
|
||||
}
|
||||
|
||||
public XMLEventReader createXMLEventReader(String systemId, Reader reader) throws XMLStreamException {
|
||||
return new StAXEventReader(createXMLStreamReader(systemId, reader));
|
||||
}
|
||||
|
||||
/** Create a new XMLEventReader from an XMLStreamReader. After being used
|
||||
* to construct the XMLEventReader instance returned from this method
|
||||
* the XMLStreamReader must not be used.
|
||||
* @param streamReader the XMLStreamReader to read from (may not be modified)
|
||||
* @return a new XMLEventReader
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public XMLEventReader createXMLEventReader(XMLStreamReader streamReader) throws XMLStreamException {
|
||||
return new StAXEventReader(streamReader);
|
||||
}
|
||||
|
||||
public XMLEventAllocator getEventAllocator() {
|
||||
return (XMLEventAllocator)getProperty(XMLInputFactory.ALLOCATOR);
|
||||
}
|
||||
|
||||
public XMLReporter getXMLReporter() {
|
||||
return (XMLReporter)_manager.getProperty(XMLInputFactory.REPORTER);
|
||||
}
|
||||
|
||||
public XMLResolver getXMLResolver() {
|
||||
Object object = _manager.getProperty(XMLInputFactory.RESOLVER);
|
||||
return (XMLResolver)object;
|
||||
//return (XMLResolver)_manager.getProperty(XMLInputFactory.RESOLVER);
|
||||
}
|
||||
|
||||
public void setXMLReporter(XMLReporter xmlreporter) {
|
||||
_manager.setProperty(XMLInputFactory.REPORTER, xmlreporter);
|
||||
}
|
||||
|
||||
public void setXMLResolver(XMLResolver xmlresolver) {
|
||||
_manager.setProperty(XMLInputFactory.RESOLVER, xmlresolver);
|
||||
}
|
||||
|
||||
/** Create a filtered event reader that wraps the filter around the event reader
|
||||
* @param reader the event reader to wrap
|
||||
* @param filter the filter to apply to the event reader
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter) throws XMLStreamException {
|
||||
return new StAXFilteredEvent(reader, filter);
|
||||
}
|
||||
|
||||
/** Create a filtered reader that wraps the filter around the reader
|
||||
* @param reader the reader to filter
|
||||
* @param filter the filter to apply to the reader
|
||||
* @throws XMLStreamException
|
||||
*/
|
||||
public XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter) throws XMLStreamException {
|
||||
|
||||
if( reader != null && filter != null )
|
||||
return new StAXFilteredParser(reader,filter);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Get the value of a feature/property from the underlying implementation
|
||||
* @param name The name of the property (may not be null)
|
||||
* @return The value of the property
|
||||
* @throws IllegalArgumentException if the property is not supported
|
||||
*/
|
||||
public Object getProperty(String name) throws IllegalArgumentException {
|
||||
if(name == null){
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.nullPropertyName"));
|
||||
}
|
||||
if(_manager.containsProperty(name))
|
||||
return _manager.getProperty(name);
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object[]{name}));
|
||||
}
|
||||
|
||||
/** Query the set of Properties that this factory supports.
|
||||
*
|
||||
* @param name The name of the property (may not be null)
|
||||
* @return true if the property is supported and false otherwise
|
||||
*/
|
||||
public boolean isPropertySupported(String name) {
|
||||
if(name == null)
|
||||
return false ;
|
||||
else
|
||||
return _manager.containsProperty(name);
|
||||
}
|
||||
|
||||
/** Set a user defined event allocator for events
|
||||
* @param allocator the user defined allocator
|
||||
*/
|
||||
public void setEventAllocator(XMLEventAllocator allocator) {
|
||||
_manager.setProperty(XMLInputFactory.ALLOCATOR, allocator);
|
||||
}
|
||||
|
||||
/** Allows the user to set specific feature/property on the underlying implementation. The underlying implementation
|
||||
* is not required to support every setting of every property in the specification and may use IllegalArgumentException
|
||||
* to signal that an unsupported property may not be set with the specified value.
|
||||
* @param name The name of the property (may not be null)
|
||||
* @param value The value of the property
|
||||
* @throws IllegalArgumentException if the property is not supported
|
||||
*/
|
||||
public void setProperty(String name, Object value) throws IllegalArgumentException {
|
||||
_manager.setProperty(name,value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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.stax.factory;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.stax.*;
|
||||
import com.sun.xml.internal.fastinfoset.stax.events.StAXEventWriter;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.stream.XMLOutputFactory ;
|
||||
import javax.xml.stream.XMLEventWriter;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Writer;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class StAXOutputFactory extends XMLOutputFactory {
|
||||
|
||||
//List of supported properties and default values.
|
||||
private StAXManager _manager = null ;
|
||||
|
||||
/** Creates a new instance of StAXOutputFactory */
|
||||
public StAXOutputFactory() {
|
||||
_manager = new StAXManager(StAXManager.CONTEXT_WRITER);
|
||||
}
|
||||
|
||||
public XMLEventWriter createXMLEventWriter(Result result) throws XMLStreamException {
|
||||
return new StAXEventWriter(createXMLStreamWriter(result));
|
||||
}
|
||||
|
||||
public XMLEventWriter createXMLEventWriter(Writer writer) throws XMLStreamException {
|
||||
return new StAXEventWriter(createXMLStreamWriter(writer));
|
||||
}
|
||||
|
||||
public XMLEventWriter createXMLEventWriter(OutputStream outputStream) throws XMLStreamException {
|
||||
return new StAXEventWriter(createXMLStreamWriter(outputStream));
|
||||
}
|
||||
|
||||
public XMLEventWriter createXMLEventWriter(OutputStream outputStream, String encoding) throws XMLStreamException {
|
||||
return new StAXEventWriter(createXMLStreamWriter(outputStream, encoding));
|
||||
}
|
||||
|
||||
public XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException {
|
||||
if (result instanceof StreamResult) {
|
||||
StreamResult streamResult = (StreamResult) result;
|
||||
if (streamResult.getWriter() != null) {
|
||||
return createXMLStreamWriter(streamResult.getWriter());
|
||||
} else if (streamResult.getOutputStream() != null) {
|
||||
return createXMLStreamWriter(streamResult.getOutputStream());
|
||||
} else if (streamResult.getSystemId() != null) {
|
||||
FileWriter writer = null;
|
||||
boolean isError = true;
|
||||
|
||||
try {
|
||||
writer = new FileWriter(new File(streamResult.getSystemId()));
|
||||
final XMLStreamWriter streamWriter = createXMLStreamWriter(writer);
|
||||
isError = false;
|
||||
|
||||
return streamWriter;
|
||||
} catch (IOException ie) {
|
||||
throw new XMLStreamException(ie);
|
||||
} finally {
|
||||
if (isError && writer != null) {
|
||||
try {
|
||||
writer.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
FileWriter writer = null;
|
||||
boolean isError = true;
|
||||
|
||||
try {
|
||||
//xxx: should we be using FileOutputStream - nb.
|
||||
writer = new FileWriter(new File(result.getSystemId()));
|
||||
final XMLStreamWriter streamWriter = createXMLStreamWriter(writer);
|
||||
isError = false;
|
||||
|
||||
return streamWriter;
|
||||
} catch (IOException ie) {
|
||||
throw new XMLStreamException(ie);
|
||||
} finally {
|
||||
if (isError && writer != null) {
|
||||
try {
|
||||
writer.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new java.lang.UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/** this is assumed that user wants to write the file in xml format
|
||||
*
|
||||
*/
|
||||
public XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException {
|
||||
throw new java.lang.UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public XMLStreamWriter createXMLStreamWriter(OutputStream outputStream) throws XMLStreamException {
|
||||
return new StAXDocumentSerializer(outputStream, new StAXManager(_manager));
|
||||
}
|
||||
|
||||
public XMLStreamWriter createXMLStreamWriter(OutputStream outputStream, String encoding) throws XMLStreamException {
|
||||
StAXDocumentSerializer serializer = new StAXDocumentSerializer(outputStream, new StAXManager(_manager));
|
||||
serializer.setEncoding(encoding);
|
||||
return serializer;
|
||||
}
|
||||
|
||||
public Object getProperty(String name) throws java.lang.IllegalArgumentException {
|
||||
if(name == null){
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object[]{null}));
|
||||
}
|
||||
if(_manager.containsProperty(name))
|
||||
return _manager.getProperty(name);
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object[]{name}));
|
||||
}
|
||||
|
||||
public boolean isPropertySupported(String name) {
|
||||
if(name == null)
|
||||
return false ;
|
||||
else
|
||||
return _manager.containsProperty(name);
|
||||
}
|
||||
|
||||
public void setProperty(String name, Object value) throws java.lang.IllegalArgumentException {
|
||||
_manager.setProperty(name,value);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.stax.util;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.StreamFilter;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
|
||||
public class StAXFilteredParser extends StAXParserWrapper {
|
||||
private StreamFilter _filter;
|
||||
|
||||
/** Creates a new instance of StAXFilteredParser */
|
||||
public StAXFilteredParser() {
|
||||
}
|
||||
public StAXFilteredParser(XMLStreamReader reader, StreamFilter filter) {
|
||||
super(reader);
|
||||
_filter = filter;
|
||||
}
|
||||
|
||||
public void setFilter(StreamFilter filter) {
|
||||
_filter = filter;
|
||||
}
|
||||
|
||||
public int next() throws XMLStreamException
|
||||
{
|
||||
if (hasNext())
|
||||
return super.next();
|
||||
throw new IllegalStateException(CommonResourceBundle.getInstance().getString("message.noMoreItems"));
|
||||
}
|
||||
|
||||
public boolean hasNext() throws XMLStreamException
|
||||
{
|
||||
while (super.hasNext()) {
|
||||
if (_filter.accept(getReader())) return true;
|
||||
super.next();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
* 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.stax.util;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.Location;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
|
||||
public class StAXParserWrapper implements XMLStreamReader{
|
||||
private XMLStreamReader _reader;
|
||||
|
||||
/** Creates a new instance of StAXParserWrapper */
|
||||
public StAXParserWrapper() {
|
||||
}
|
||||
|
||||
public StAXParserWrapper(XMLStreamReader reader) {
|
||||
_reader = reader;
|
||||
}
|
||||
public void setReader(XMLStreamReader reader) {
|
||||
_reader = reader;
|
||||
}
|
||||
public XMLStreamReader getReader() {
|
||||
return _reader;
|
||||
}
|
||||
|
||||
public int next() throws XMLStreamException
|
||||
{
|
||||
return _reader.next();
|
||||
}
|
||||
|
||||
public int nextTag() throws XMLStreamException
|
||||
{
|
||||
return _reader.nextTag();
|
||||
}
|
||||
|
||||
public String getElementText() throws XMLStreamException
|
||||
{
|
||||
return _reader.getElementText();
|
||||
}
|
||||
|
||||
public void require(int type, String namespaceURI, String localName) throws XMLStreamException
|
||||
{
|
||||
_reader.require(type,namespaceURI,localName);
|
||||
}
|
||||
|
||||
public boolean hasNext() throws XMLStreamException
|
||||
{
|
||||
return _reader.hasNext();
|
||||
}
|
||||
|
||||
public void close() throws XMLStreamException
|
||||
{
|
||||
_reader.close();
|
||||
}
|
||||
|
||||
public String getNamespaceURI(String prefix)
|
||||
{
|
||||
return _reader.getNamespaceURI(prefix);
|
||||
}
|
||||
|
||||
public NamespaceContext getNamespaceContext() {
|
||||
return _reader.getNamespaceContext();
|
||||
}
|
||||
|
||||
public boolean isStartElement() {
|
||||
return _reader.isStartElement();
|
||||
}
|
||||
|
||||
public boolean isEndElement() {
|
||||
return _reader.isEndElement();
|
||||
}
|
||||
|
||||
public boolean isCharacters() {
|
||||
return _reader.isCharacters();
|
||||
}
|
||||
|
||||
public boolean isWhiteSpace() {
|
||||
return _reader.isWhiteSpace();
|
||||
}
|
||||
|
||||
public QName getAttributeName(int index) {
|
||||
return _reader.getAttributeName(index);
|
||||
}
|
||||
|
||||
public int getTextCharacters(int sourceStart, char[] target, int targetStart,
|
||||
int length) throws XMLStreamException
|
||||
{
|
||||
return _reader.getTextCharacters(sourceStart, target, targetStart, length);
|
||||
}
|
||||
|
||||
public String getAttributeValue(String namespaceUri,
|
||||
String localName)
|
||||
{
|
||||
return _reader.getAttributeValue(namespaceUri,localName);
|
||||
}
|
||||
public int getAttributeCount() {
|
||||
return _reader.getAttributeCount();
|
||||
}
|
||||
public String getAttributePrefix(int index) {
|
||||
return _reader.getAttributePrefix(index);
|
||||
}
|
||||
public String getAttributeNamespace(int index) {
|
||||
return _reader.getAttributeNamespace(index);
|
||||
}
|
||||
public String getAttributeLocalName(int index) {
|
||||
return _reader.getAttributeLocalName(index);
|
||||
}
|
||||
public String getAttributeType(int index) {
|
||||
return _reader.getAttributeType(index);
|
||||
}
|
||||
public String getAttributeValue(int index) {
|
||||
return _reader.getAttributeValue(index);
|
||||
}
|
||||
public boolean isAttributeSpecified(int index) {
|
||||
return _reader.isAttributeSpecified(index);
|
||||
}
|
||||
|
||||
public int getNamespaceCount() {
|
||||
return _reader.getNamespaceCount();
|
||||
}
|
||||
public String getNamespacePrefix(int index) {
|
||||
return _reader.getNamespacePrefix(index);
|
||||
}
|
||||
public String getNamespaceURI(int index) {
|
||||
return _reader.getNamespaceURI(index);
|
||||
}
|
||||
|
||||
public int getEventType() {
|
||||
return _reader.getEventType();
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return _reader.getText();
|
||||
}
|
||||
|
||||
public char[] getTextCharacters() {
|
||||
return _reader.getTextCharacters();
|
||||
}
|
||||
|
||||
public int getTextStart() {
|
||||
return _reader.getTextStart();
|
||||
}
|
||||
|
||||
public int getTextLength() {
|
||||
return _reader.getTextLength();
|
||||
}
|
||||
|
||||
public String getEncoding() {
|
||||
return _reader.getEncoding();
|
||||
}
|
||||
|
||||
public boolean hasText() {
|
||||
return _reader.hasText();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return _reader.getLocation();
|
||||
}
|
||||
|
||||
public QName getName() {
|
||||
return _reader.getName();
|
||||
}
|
||||
|
||||
public String getLocalName() {
|
||||
return _reader.getLocalName();
|
||||
}
|
||||
|
||||
public boolean hasName() {
|
||||
return _reader.hasName();
|
||||
}
|
||||
|
||||
public String getNamespaceURI() {
|
||||
return _reader.getNamespaceURI();
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return _reader.getPrefix();
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return _reader.getVersion();
|
||||
}
|
||||
|
||||
public boolean isStandalone() {
|
||||
return _reader.isStandalone();
|
||||
}
|
||||
|
||||
public boolean standaloneSet() {
|
||||
return _reader.standaloneSet();
|
||||
}
|
||||
|
||||
public String getCharacterEncodingScheme() {
|
||||
return _reader.getCharacterEncodingScheme();
|
||||
}
|
||||
|
||||
public String getPITarget() {
|
||||
return _reader.getPITarget();
|
||||
}
|
||||
|
||||
public String getPIData() {
|
||||
return _reader.getPIData();
|
||||
}
|
||||
|
||||
public Object getProperty(String name) {
|
||||
return _reader.getProperty(name);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
158
jdkSrc/jdk8/com/sun/xml/internal/fastinfoset/util/CharArray.java
Normal file
158
jdkSrc/jdk8/com/sun/xml/internal/fastinfoset/util/CharArray.java
Normal file
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
public class CharArray implements CharSequence {
|
||||
public char[] ch;
|
||||
public int start;
|
||||
public int length;
|
||||
|
||||
protected int _hash;
|
||||
|
||||
protected CharArray() {
|
||||
}
|
||||
|
||||
public CharArray(char[] _ch, int _start, int _length, boolean copy) {
|
||||
set(_ch, _start, _length, copy);
|
||||
}
|
||||
|
||||
public final void set(char[] _ch, int _start, int _length, boolean copy) {
|
||||
if (copy) {
|
||||
ch = new char[_length];
|
||||
start = 0;
|
||||
length = _length;
|
||||
System.arraycopy(_ch, _start, ch, 0, _length);
|
||||
} else {
|
||||
ch = _ch;
|
||||
start = _start;
|
||||
length = _length;
|
||||
}
|
||||
_hash = 0;
|
||||
}
|
||||
|
||||
public final void cloneArray() {
|
||||
char[] _ch = new char[length];
|
||||
System.arraycopy(ch, start, _ch, 0, length);
|
||||
ch = _ch;
|
||||
start = 0;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return new String(ch, start, length);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
if (_hash == 0) {
|
||||
// Same hash code algorithm as used for String
|
||||
// s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
|
||||
for (int i = start; i < start + length; i++) {
|
||||
_hash = 31*_hash + ch[i];
|
||||
}
|
||||
}
|
||||
return _hash;
|
||||
}
|
||||
|
||||
public static final int hashCode(char[] ch, int start, int length) {
|
||||
// Same hash code algorithm as used for String
|
||||
// s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
|
||||
int hash = 0;
|
||||
for (int i = start; i < start + length; i++) {
|
||||
hash = 31*hash + ch[i];
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
public final boolean equalsCharArray(CharArray cha) {
|
||||
if (this == cha) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (length == cha.length) {
|
||||
int n = length;
|
||||
int i = start;
|
||||
int j = cha.start;
|
||||
while (n-- != 0) {
|
||||
if (ch[i++] != cha.ch[j++])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean equalsCharArray(char[] ch, int start, int length) {
|
||||
if (this.length == length) {
|
||||
int n = this.length;
|
||||
int i = this.start;
|
||||
int j = start;
|
||||
while (n-- != 0) {
|
||||
if (this.ch[i++] != ch[j++])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof CharArray) {
|
||||
CharArray cha = (CharArray)obj;
|
||||
if (length == cha.length) {
|
||||
int n = length;
|
||||
int i = start;
|
||||
int j = cha.start;
|
||||
while (n-- != 0) {
|
||||
if (ch[i++] != cha.ch[j++])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// CharSequence interface
|
||||
|
||||
public final int length() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public final char charAt(int index) {
|
||||
return ch[start + index];
|
||||
}
|
||||
|
||||
public final CharSequence subSequence(int start, int end) {
|
||||
return new CharArray(ch, this.start + start, end - start, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class CharArrayArray extends ValueArray {
|
||||
|
||||
private CharArray[] _array;
|
||||
|
||||
private CharArrayArray _readOnlyArray;
|
||||
|
||||
public CharArrayArray(int initialCapacity, int maximumCapacity) {
|
||||
_array = new CharArray[initialCapacity];
|
||||
_maximumCapacity = maximumCapacity;
|
||||
}
|
||||
|
||||
public CharArrayArray() {
|
||||
this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY);
|
||||
}
|
||||
|
||||
public final void clear() {
|
||||
for (int i = 0; i < _size; i++) {
|
||||
_array[i] = null;
|
||||
}
|
||||
_size = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns cloned version of internal CharArray[].
|
||||
* @return cloned version of internal CharArray[].
|
||||
*/
|
||||
public final CharArray[] getArray() {
|
||||
if (_array == null) return null;
|
||||
|
||||
final CharArray[] clonedArray = new CharArray[_array.length];
|
||||
System.arraycopy(_array, 0, clonedArray, 0, _array.length);
|
||||
return clonedArray;
|
||||
}
|
||||
|
||||
public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) {
|
||||
if (!(readOnlyArray instanceof CharArrayArray)) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.illegalClass", new Object[]{readOnlyArray}));
|
||||
}
|
||||
|
||||
setReadOnlyArray((CharArrayArray)readOnlyArray, clear);
|
||||
}
|
||||
|
||||
public final void setReadOnlyArray(CharArrayArray readOnlyArray, boolean clear) {
|
||||
if (readOnlyArray != null) {
|
||||
_readOnlyArray = readOnlyArray;
|
||||
_readOnlyArraySize = readOnlyArray.getSize();
|
||||
|
||||
if (clear) {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final CharArray get(int i) {
|
||||
if (_readOnlyArray == null) {
|
||||
return _array[i];
|
||||
} else {
|
||||
if (i < _readOnlyArraySize) {
|
||||
return _readOnlyArray.get(i);
|
||||
} else {
|
||||
return _array[i - _readOnlyArraySize];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void add(CharArray s) {
|
||||
if (_size == _array.length) {
|
||||
resize();
|
||||
}
|
||||
|
||||
_array[_size++] = s;
|
||||
}
|
||||
|
||||
protected final void resize() {
|
||||
if (_size == _maximumCapacity) {
|
||||
throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity"));
|
||||
}
|
||||
|
||||
int newSize = _size * 3 / 2 + 1;
|
||||
if (newSize > _maximumCapacity) {
|
||||
newSize = _maximumCapacity;
|
||||
}
|
||||
|
||||
final CharArray[] newArray = new CharArray[newSize];
|
||||
System.arraycopy(_array, 0, newArray, 0, _size);
|
||||
_array = newArray;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class CharArrayIntMap extends KeyIntMap {
|
||||
|
||||
private CharArrayIntMap _readOnlyMap;
|
||||
|
||||
// Total character count of Map
|
||||
protected int _totalCharacterCount;
|
||||
|
||||
static class Entry extends BaseEntry {
|
||||
final char[] _ch;
|
||||
final int _start;
|
||||
final int _length;
|
||||
Entry _next;
|
||||
|
||||
public Entry(char[] ch, int start, int length, int hash, int value, Entry next) {
|
||||
super(hash, value);
|
||||
_ch = ch;
|
||||
_start = start;
|
||||
_length = length;
|
||||
_next = next;
|
||||
}
|
||||
|
||||
public final boolean equalsCharArray(char[] ch, int start, int length) {
|
||||
if (_length == length) {
|
||||
int n = _length;
|
||||
int i = _start;
|
||||
int j = start;
|
||||
while (n-- != 0) {
|
||||
if (_ch[i++] != ch[j++])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Entry[] _table;
|
||||
|
||||
public CharArrayIntMap(int initialCapacity, float loadFactor) {
|
||||
super(initialCapacity, loadFactor);
|
||||
|
||||
_table = new Entry[_capacity];
|
||||
}
|
||||
|
||||
public CharArrayIntMap(int initialCapacity) {
|
||||
this(initialCapacity, DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
public CharArrayIntMap() {
|
||||
this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
public final void clear() {
|
||||
for (int i = 0; i < _table.length; i++) {
|
||||
_table[i] = null;
|
||||
}
|
||||
_size = 0;
|
||||
_totalCharacterCount = 0;
|
||||
}
|
||||
|
||||
public final void setReadOnlyMap(KeyIntMap readOnlyMap, boolean clear) {
|
||||
if (!(readOnlyMap instanceof CharArrayIntMap)) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
|
||||
getString("message.illegalClass", new Object[]{readOnlyMap}));
|
||||
}
|
||||
|
||||
setReadOnlyMap((CharArrayIntMap)readOnlyMap, clear);
|
||||
}
|
||||
|
||||
public final void setReadOnlyMap(CharArrayIntMap readOnlyMap, boolean clear) {
|
||||
_readOnlyMap = readOnlyMap;
|
||||
if (_readOnlyMap != null) {
|
||||
_readOnlyMapSize = _readOnlyMap.size();
|
||||
|
||||
if (clear) {
|
||||
clear();
|
||||
}
|
||||
} else {
|
||||
_readOnlyMapSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method returns an index of the passed character buffer in
|
||||
* <code>CharArrayIntMap</code>.
|
||||
*
|
||||
* @return index of character buffer in <code>CharArrayIntMap</code>,
|
||||
* otherwise NOT_PRESENT.
|
||||
*/
|
||||
public final int get(char[] ch, int start, int length) {
|
||||
final int hash = hashHash(CharArray.hashCode(ch, start, length));
|
||||
return get(ch, start, length, hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method returns an index of the passed character buffer in
|
||||
* <code>CharArrayIntMap</code>. If character buffer is not in
|
||||
* <code>CharArrayIntMap</code> - it will be added.
|
||||
*
|
||||
* @return index of character buffer in <code>CharArrayIntMap</code>, or
|
||||
* NOT_PRESENT if character buffer was just added.
|
||||
*/
|
||||
public final int obtainIndex(char[] ch, int start, int length, boolean clone) {
|
||||
final int hash = hashHash(CharArray.hashCode(ch, start, length));
|
||||
|
||||
if (_readOnlyMap != null) {
|
||||
final int index = _readOnlyMap.get(ch, start, length, hash);
|
||||
if (index != -1) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
final int tableIndex = indexFor(hash, _table.length);
|
||||
for (Entry e = _table[tableIndex]; e != null; e = e._next) {
|
||||
if (e._hash == hash && e.equalsCharArray(ch, start, length)) {
|
||||
return e._value;
|
||||
}
|
||||
}
|
||||
|
||||
if (clone) {
|
||||
char[] chClone = new char[length];
|
||||
System.arraycopy(ch, start, chClone, 0, length);
|
||||
|
||||
ch = chClone;
|
||||
start = 0;
|
||||
}
|
||||
|
||||
addEntry(ch, start, length, hash, _size + _readOnlyMapSize, tableIndex);
|
||||
return NOT_PRESENT;
|
||||
}
|
||||
|
||||
public final int getTotalCharacterCount() {
|
||||
return _totalCharacterCount;
|
||||
}
|
||||
|
||||
private final int get(char[] ch, int start, int length, int hash) {
|
||||
if (_readOnlyMap != null) {
|
||||
final int i = _readOnlyMap.get(ch, start, length, hash);
|
||||
if (i != -1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
final int tableIndex = indexFor(hash, _table.length);
|
||||
for (Entry e = _table[tableIndex]; e != null; e = e._next) {
|
||||
if (e._hash == hash && e.equalsCharArray(ch, start, length)) {
|
||||
return e._value;
|
||||
}
|
||||
}
|
||||
|
||||
return NOT_PRESENT;
|
||||
}
|
||||
|
||||
private final void addEntry(char[] ch, int start, int length, int hash, int value, int bucketIndex) {
|
||||
Entry e = _table[bucketIndex];
|
||||
_table[bucketIndex] = new Entry(ch, start, length, hash, value, e);
|
||||
_totalCharacterCount += length;
|
||||
if (_size++ >= _threshold) {
|
||||
resize(2 * _table.length);
|
||||
}
|
||||
}
|
||||
|
||||
private final void resize(int newCapacity) {
|
||||
_capacity = newCapacity;
|
||||
Entry[] oldTable = _table;
|
||||
int oldCapacity = oldTable.length;
|
||||
if (oldCapacity == MAXIMUM_CAPACITY) {
|
||||
_threshold = Integer.MAX_VALUE;
|
||||
return;
|
||||
}
|
||||
|
||||
Entry[] newTable = new Entry[_capacity];
|
||||
transfer(newTable);
|
||||
_table = newTable;
|
||||
_threshold = (int)(_capacity * _loadFactor);
|
||||
}
|
||||
|
||||
private final void transfer(Entry[] newTable) {
|
||||
Entry[] src = _table;
|
||||
int newCapacity = newTable.length;
|
||||
for (int j = 0; j < src.length; j++) {
|
||||
Entry e = src[j];
|
||||
if (e != null) {
|
||||
src[j] = null;
|
||||
do {
|
||||
Entry next = e._next;
|
||||
int i = indexFor(e._hash, newCapacity);
|
||||
e._next = newTable[i];
|
||||
newTable[i] = e;
|
||||
e = next;
|
||||
} while (e != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
public class CharArrayString extends CharArray {
|
||||
protected String _s;
|
||||
|
||||
public CharArrayString(String s) {
|
||||
this(s, true);
|
||||
}
|
||||
|
||||
public CharArrayString(String s, boolean createArray) {
|
||||
_s = s;
|
||||
if (createArray) {
|
||||
ch = _s.toCharArray();
|
||||
start = 0;
|
||||
length = ch.length;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return _s;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return _s.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof CharArrayString) {
|
||||
CharArrayString chas = (CharArrayString)obj;
|
||||
return _s.equals(chas._s);
|
||||
} else if (obj instanceof CharArray) {
|
||||
CharArray cha = (CharArray)obj;
|
||||
if (length == cha.length) {
|
||||
int n = length;
|
||||
int i = start;
|
||||
int j = cha.start;
|
||||
while (n-- != 0) {
|
||||
if (ch[i++] != cha.ch[j++])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
* 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.util;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class ContiguousCharArrayArray extends ValueArray {
|
||||
public static final int INITIAL_CHARACTER_SIZE = 512;
|
||||
public static final int MAXIMUM_CHARACTER_SIZE = Integer.MAX_VALUE;
|
||||
|
||||
protected int _maximumCharacterSize;
|
||||
|
||||
public int[] _offset;
|
||||
public int[] _length;
|
||||
|
||||
public char[] _array;
|
||||
public int _arrayIndex;
|
||||
public int _readOnlyArrayIndex;
|
||||
|
||||
private String[] _cachedStrings;
|
||||
|
||||
public int _cachedIndex;
|
||||
|
||||
private ContiguousCharArrayArray _readOnlyArray;
|
||||
|
||||
public ContiguousCharArrayArray(int initialCapacity, int maximumCapacity,
|
||||
int initialCharacterSize, int maximumCharacterSize) {
|
||||
_offset = new int[initialCapacity];
|
||||
_length = new int[initialCapacity];
|
||||
_array = new char[initialCharacterSize];
|
||||
_maximumCapacity = maximumCapacity;
|
||||
_maximumCharacterSize = maximumCharacterSize;
|
||||
}
|
||||
|
||||
public ContiguousCharArrayArray() {
|
||||
this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY,
|
||||
INITIAL_CHARACTER_SIZE, MAXIMUM_CHARACTER_SIZE);
|
||||
}
|
||||
|
||||
public final void clear() {
|
||||
_arrayIndex = _readOnlyArrayIndex;
|
||||
_size = _readOnlyArraySize;
|
||||
|
||||
if (_cachedStrings != null) {
|
||||
for (int i = _readOnlyArraySize; i < _cachedStrings.length; i++) {
|
||||
_cachedStrings[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final int getArrayIndex() {
|
||||
return _arrayIndex;
|
||||
}
|
||||
|
||||
public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) {
|
||||
if (!(readOnlyArray instanceof ContiguousCharArrayArray)) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.illegalClass", new Object[]{readOnlyArray}));
|
||||
}
|
||||
|
||||
setReadOnlyArray((ContiguousCharArrayArray)readOnlyArray, clear);
|
||||
}
|
||||
|
||||
public final void setReadOnlyArray(ContiguousCharArrayArray readOnlyArray, boolean clear) {
|
||||
if (readOnlyArray != null) {
|
||||
_readOnlyArray = readOnlyArray;
|
||||
_readOnlyArraySize = readOnlyArray.getSize();
|
||||
_readOnlyArrayIndex = readOnlyArray.getArrayIndex();
|
||||
|
||||
if (clear) {
|
||||
clear();
|
||||
}
|
||||
|
||||
_array = getCompleteCharArray();
|
||||
_offset = getCompleteOffsetArray();
|
||||
_length = getCompleteLengthArray();
|
||||
_size = _readOnlyArraySize;
|
||||
_arrayIndex = _readOnlyArrayIndex;
|
||||
}
|
||||
}
|
||||
|
||||
public final char[] getCompleteCharArray() {
|
||||
if (_readOnlyArray == null) {
|
||||
if (_array == null) return null;
|
||||
|
||||
// Return cloned version of internal _array
|
||||
final char[] clonedArray = new char[_array.length];
|
||||
System.arraycopy(_array, 0, clonedArray, 0, _array.length);
|
||||
return clonedArray;
|
||||
// return _array;
|
||||
} else {
|
||||
final char[] ra = _readOnlyArray.getCompleteCharArray();
|
||||
final char[] a = new char[_readOnlyArrayIndex + _array.length];
|
||||
System.arraycopy(ra, 0, a, 0, _readOnlyArrayIndex);
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
public final int[] getCompleteOffsetArray() {
|
||||
if (_readOnlyArray == null) {
|
||||
if (_offset == null) return null;
|
||||
|
||||
// Return cloned version of internal _offset
|
||||
final int[] clonedArray = new int[_offset.length];
|
||||
System.arraycopy(_offset, 0, clonedArray, 0, _offset.length);
|
||||
return clonedArray;
|
||||
// return _offset;
|
||||
} else {
|
||||
final int[] ra = _readOnlyArray.getCompleteOffsetArray();
|
||||
final int[] a = new int[_readOnlyArraySize + _offset.length];
|
||||
System.arraycopy(ra, 0, a, 0, _readOnlyArraySize);
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
public final int[] getCompleteLengthArray() {
|
||||
if (_readOnlyArray == null) {
|
||||
if (_length == null) return null;
|
||||
|
||||
// Return cloned version of internal _length
|
||||
final int[] clonedArray = new int[_length.length];
|
||||
System.arraycopy(_length, 0, clonedArray, 0, _length.length);
|
||||
return clonedArray;
|
||||
// return _length;
|
||||
} else {
|
||||
final int[] ra = _readOnlyArray.getCompleteLengthArray();
|
||||
final int[] a = new int[_readOnlyArraySize + _length.length];
|
||||
System.arraycopy(ra, 0, a, 0, _readOnlyArraySize);
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
public final String getString(int i) {
|
||||
if (_cachedStrings != null && i < _cachedStrings.length) {
|
||||
final String s = _cachedStrings[i];
|
||||
return (s != null) ? s : (_cachedStrings[i] = new String(_array, _offset[i], _length[i]));
|
||||
}
|
||||
|
||||
final String[] newCachedStrings = new String[_offset.length];
|
||||
if (_cachedStrings != null && i >= _cachedStrings.length) {
|
||||
System.arraycopy(_cachedStrings, 0, newCachedStrings, 0, _cachedStrings.length);
|
||||
}
|
||||
_cachedStrings = newCachedStrings;
|
||||
|
||||
return _cachedStrings[i] = new String(_array, _offset[i], _length[i]);
|
||||
}
|
||||
|
||||
public final void ensureSize(int l) {
|
||||
if (_arrayIndex + l >= _array.length) {
|
||||
resizeArray(_arrayIndex + l);
|
||||
}
|
||||
}
|
||||
|
||||
public final void add(int l) {
|
||||
if (_size == _offset.length) {
|
||||
resize();
|
||||
}
|
||||
|
||||
_cachedIndex = _size;
|
||||
_offset[_size] = _arrayIndex;
|
||||
_length[_size++] = l;
|
||||
|
||||
_arrayIndex += l;
|
||||
}
|
||||
|
||||
public final int add(char[] c, int l) {
|
||||
if (_size == _offset.length) {
|
||||
resize();
|
||||
}
|
||||
|
||||
final int oldArrayIndex = _arrayIndex;
|
||||
final int arrayIndex = oldArrayIndex + l;
|
||||
|
||||
_cachedIndex = _size;
|
||||
_offset[_size] = oldArrayIndex;
|
||||
_length[_size++] = l;
|
||||
|
||||
if (arrayIndex >= _array.length) {
|
||||
resizeArray(arrayIndex);
|
||||
}
|
||||
|
||||
System.arraycopy(c, 0, _array, oldArrayIndex, l);
|
||||
|
||||
_arrayIndex = arrayIndex;
|
||||
return oldArrayIndex;
|
||||
}
|
||||
|
||||
protected final void resize() {
|
||||
if (_size == _maximumCapacity) {
|
||||
throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity"));
|
||||
}
|
||||
|
||||
int newSize = _size * 3 / 2 + 1;
|
||||
if (newSize > _maximumCapacity) {
|
||||
newSize = _maximumCapacity;
|
||||
}
|
||||
|
||||
final int[] offset = new int[newSize];
|
||||
System.arraycopy(_offset, 0, offset, 0, _size);
|
||||
_offset = offset;
|
||||
|
||||
final int[] length = new int[newSize];
|
||||
System.arraycopy(_length, 0, length, 0, _size);
|
||||
_length = length;
|
||||
}
|
||||
|
||||
protected final void resizeArray(int requestedSize) {
|
||||
if (_arrayIndex == _maximumCharacterSize) {
|
||||
throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.maxNumberOfCharacters"));
|
||||
}
|
||||
|
||||
int newSize = requestedSize * 3 / 2 + 1;
|
||||
if (newSize > _maximumCharacterSize) {
|
||||
newSize = _maximumCharacterSize;
|
||||
}
|
||||
|
||||
final char[] array = new char[newSize];
|
||||
System.arraycopy(_array, 0, array, 0, _arrayIndex);
|
||||
_array = array;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
|
||||
public class DuplicateAttributeVerifier {
|
||||
public static final int MAP_SIZE = 256;
|
||||
|
||||
public int _currentIteration;
|
||||
|
||||
public static class Entry {
|
||||
private int iteration;
|
||||
private int value;
|
||||
|
||||
private Entry hashNext;
|
||||
|
||||
private Entry poolNext;
|
||||
}
|
||||
|
||||
private Entry[] _map;
|
||||
|
||||
public final Entry _poolHead;
|
||||
public Entry _poolCurrent;
|
||||
private Entry _poolTail;
|
||||
|
||||
|
||||
public DuplicateAttributeVerifier() {
|
||||
_poolTail = _poolHead = new Entry();
|
||||
}
|
||||
|
||||
public final void clear() {
|
||||
_currentIteration = 0;
|
||||
|
||||
Entry e = _poolHead;
|
||||
while (e != null) {
|
||||
e.iteration = 0;
|
||||
e = e.poolNext;
|
||||
}
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
public final void reset() {
|
||||
_poolCurrent = _poolHead;
|
||||
if (_map == null) {
|
||||
_map = new Entry[MAP_SIZE];
|
||||
}
|
||||
}
|
||||
|
||||
private final void increasePool(int capacity) {
|
||||
if (_map == null) {
|
||||
_map = new Entry[MAP_SIZE];
|
||||
_poolCurrent = _poolHead;
|
||||
} else {
|
||||
final Entry tail = _poolTail;
|
||||
for (int i = 0; i < capacity; i++) {
|
||||
final Entry e = new Entry();
|
||||
_poolTail.poolNext = e;
|
||||
_poolTail = e;
|
||||
}
|
||||
|
||||
_poolCurrent = tail.poolNext;
|
||||
}
|
||||
}
|
||||
|
||||
public final void checkForDuplicateAttribute(int hash, int value) throws FastInfosetException {
|
||||
if (_poolCurrent == null) {
|
||||
increasePool(16);
|
||||
}
|
||||
|
||||
// Get next free entry
|
||||
final Entry newEntry = _poolCurrent;
|
||||
_poolCurrent = _poolCurrent.poolNext;
|
||||
|
||||
final Entry head = _map[hash];
|
||||
if (head == null || head.iteration < _currentIteration) {
|
||||
newEntry.hashNext = null;
|
||||
_map[hash] = newEntry;
|
||||
newEntry.iteration = _currentIteration;
|
||||
newEntry.value = value;
|
||||
} else {
|
||||
Entry e = head;
|
||||
do {
|
||||
if (e.value == value) {
|
||||
reset();
|
||||
throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.duplicateAttribute"));
|
||||
}
|
||||
} while ((e = e.hashNext) != null);
|
||||
|
||||
newEntry.hashNext = head;
|
||||
_map[hash] = newEntry;
|
||||
newEntry.iteration = _currentIteration;
|
||||
newEntry.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class FixedEntryStringIntMap extends StringIntMap {
|
||||
|
||||
private Entry _fixedEntry;
|
||||
|
||||
public FixedEntryStringIntMap(String fixedEntry, int initialCapacity, float loadFactor) {
|
||||
super(initialCapacity, loadFactor);
|
||||
|
||||
// Add the fixed entry
|
||||
final int hash = hashHash(fixedEntry.hashCode());
|
||||
final int tableIndex = indexFor(hash, _table.length);
|
||||
_table[tableIndex] = _fixedEntry = new Entry(fixedEntry, hash, _index++, null);
|
||||
if (_size++ >= _threshold) {
|
||||
resize(2 * _table.length);
|
||||
}
|
||||
}
|
||||
|
||||
public FixedEntryStringIntMap(String fixedEntry, int initialCapacity) {
|
||||
this(fixedEntry, initialCapacity, DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
public FixedEntryStringIntMap(String fixedEntry) {
|
||||
this(fixedEntry, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
public final void clear() {
|
||||
for (int i = 0; i < _table.length; i++) {
|
||||
_table[i] = null;
|
||||
}
|
||||
_lastEntry = NULL_ENTRY;
|
||||
|
||||
if (_fixedEntry != null) {
|
||||
final int tableIndex = indexFor(_fixedEntry._hash, _table.length);
|
||||
_table[tableIndex] = _fixedEntry;
|
||||
_fixedEntry._next = null;
|
||||
_size = 1;
|
||||
_index = _readOnlyMapSize + 1;
|
||||
} else {
|
||||
_size = 0;
|
||||
_index = _readOnlyMapSize;
|
||||
}
|
||||
}
|
||||
|
||||
public final void setReadOnlyMap(KeyIntMap readOnlyMap, boolean clear) {
|
||||
if (!(readOnlyMap instanceof FixedEntryStringIntMap)) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
|
||||
getString("message.illegalClass", new Object[]{readOnlyMap}));
|
||||
}
|
||||
|
||||
setReadOnlyMap((FixedEntryStringIntMap)readOnlyMap, clear);
|
||||
}
|
||||
|
||||
public final void setReadOnlyMap(FixedEntryStringIntMap readOnlyMap, boolean clear) {
|
||||
_readOnlyMap = readOnlyMap;
|
||||
if (_readOnlyMap != null) {
|
||||
readOnlyMap.removeFixedEntry();
|
||||
_readOnlyMapSize = readOnlyMap.size();
|
||||
_index = _readOnlyMapSize + _size;
|
||||
if (clear) {
|
||||
clear();
|
||||
}
|
||||
} else {
|
||||
_readOnlyMapSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private final void removeFixedEntry() {
|
||||
if (_fixedEntry != null) {
|
||||
final int tableIndex = indexFor(_fixedEntry._hash, _table.length);
|
||||
final Entry firstEntry = _table[tableIndex];
|
||||
if (firstEntry == _fixedEntry) {
|
||||
_table[tableIndex] = _fixedEntry._next;
|
||||
} else {
|
||||
Entry previousEntry = firstEntry;
|
||||
while (previousEntry._next != _fixedEntry) {
|
||||
previousEntry = previousEntry._next;
|
||||
}
|
||||
previousEntry._next = _fixedEntry._next;
|
||||
}
|
||||
|
||||
_fixedEntry = null;
|
||||
_size--;
|
||||
}
|
||||
}
|
||||
}
|
||||
136
jdkSrc/jdk8/com/sun/xml/internal/fastinfoset/util/KeyIntMap.java
Normal file
136
jdkSrc/jdk8/com/sun/xml/internal/fastinfoset/util/KeyIntMap.java
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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.util;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public abstract class KeyIntMap {
|
||||
public static final int NOT_PRESENT = -1;
|
||||
|
||||
/**
|
||||
* The default initial capacity - MUST be a power of two.
|
||||
*/
|
||||
static final int DEFAULT_INITIAL_CAPACITY = 16;
|
||||
|
||||
/**
|
||||
* The maximum capacity, used if a higher value is implicitly specified
|
||||
* by either of the constructors with arguments.
|
||||
* MUST be a power of two <= 1<<30.
|
||||
*/
|
||||
static final int MAXIMUM_CAPACITY = 1 << 20;
|
||||
|
||||
/**
|
||||
* The load factor used when none specified in constructor.
|
||||
**/
|
||||
static final float DEFAULT_LOAD_FACTOR = 0.75f;
|
||||
|
||||
int _readOnlyMapSize;
|
||||
|
||||
/**
|
||||
* The number of key-value mappings contained in this identity hash map.
|
||||
*/
|
||||
int _size;
|
||||
|
||||
int _capacity;
|
||||
|
||||
/**
|
||||
* The next size value at which to resize (capacity * load factor).
|
||||
*/
|
||||
int _threshold;
|
||||
|
||||
/**
|
||||
* The load factor for the hash table.
|
||||
*/
|
||||
final float _loadFactor;
|
||||
|
||||
static class BaseEntry {
|
||||
final int _hash;
|
||||
final int _value;
|
||||
|
||||
public BaseEntry(int hash, int value) {
|
||||
_hash = hash;
|
||||
_value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public KeyIntMap(int initialCapacity, float loadFactor) {
|
||||
if (initialCapacity < 0)
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
|
||||
getString("message.illegalInitialCapacity", new Object[]{Integer.valueOf(initialCapacity)}));
|
||||
if (initialCapacity > MAXIMUM_CAPACITY)
|
||||
initialCapacity = MAXIMUM_CAPACITY;
|
||||
if (loadFactor <= 0 || Float.isNaN(loadFactor))
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
|
||||
getString("message.illegalLoadFactor", new Object[]{Float.valueOf(loadFactor)}));
|
||||
|
||||
// Find a power of 2 >= initialCapacity
|
||||
if (initialCapacity != DEFAULT_INITIAL_CAPACITY) {
|
||||
_capacity = 1;
|
||||
while (_capacity < initialCapacity)
|
||||
_capacity <<= 1;
|
||||
|
||||
_loadFactor = loadFactor;
|
||||
_threshold = (int)(_capacity * _loadFactor);
|
||||
} else {
|
||||
_capacity = DEFAULT_INITIAL_CAPACITY;
|
||||
_loadFactor = DEFAULT_LOAD_FACTOR;
|
||||
_threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
}
|
||||
|
||||
public KeyIntMap(int initialCapacity) {
|
||||
this(initialCapacity, DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
public KeyIntMap() {
|
||||
_capacity = DEFAULT_INITIAL_CAPACITY;
|
||||
_loadFactor = DEFAULT_LOAD_FACTOR;
|
||||
_threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
public final int size() {
|
||||
return _size + _readOnlyMapSize;
|
||||
}
|
||||
|
||||
public abstract void clear();
|
||||
|
||||
public abstract void setReadOnlyMap(KeyIntMap readOnlyMap, boolean clear);
|
||||
|
||||
|
||||
public static final int hashHash(int h) {
|
||||
h += ~(h << 9);
|
||||
h ^= (h >>> 14);
|
||||
h += (h << 4);
|
||||
h ^= (h >>> 10);
|
||||
return h;
|
||||
}
|
||||
|
||||
public static final int indexFor(int h, int length) {
|
||||
return h & (length-1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.QualifiedName;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class LocalNameQualifiedNamesMap extends KeyIntMap {
|
||||
|
||||
private LocalNameQualifiedNamesMap _readOnlyMap;
|
||||
|
||||
private int _index;
|
||||
|
||||
public static class Entry {
|
||||
final String _key;
|
||||
final int _hash;
|
||||
public QualifiedName[] _value;
|
||||
public int _valueIndex;
|
||||
Entry _next;
|
||||
|
||||
public Entry(String key, int hash, Entry next) {
|
||||
_key = key;
|
||||
_hash = hash;
|
||||
_next = next;
|
||||
_value = new QualifiedName[1];
|
||||
}
|
||||
|
||||
public void addQualifiedName(QualifiedName name) {
|
||||
if (_valueIndex < _value.length) {
|
||||
_value[_valueIndex++] = name;
|
||||
} else if (_valueIndex == _value.length) {
|
||||
QualifiedName[] newValue = new QualifiedName[_valueIndex * 3 / 2 + 1];
|
||||
System.arraycopy(_value, 0, newValue, 0, _valueIndex);
|
||||
_value = newValue;
|
||||
_value[_valueIndex++] = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Entry[] _table;
|
||||
|
||||
public LocalNameQualifiedNamesMap(int initialCapacity, float loadFactor) {
|
||||
super(initialCapacity, loadFactor);
|
||||
|
||||
_table = new Entry[_capacity];
|
||||
}
|
||||
|
||||
public LocalNameQualifiedNamesMap(int initialCapacity) {
|
||||
this(initialCapacity, DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
public LocalNameQualifiedNamesMap() {
|
||||
this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
public final void clear() {
|
||||
for (int i = 0; i < _table.length; i++) {
|
||||
_table[i] = null;
|
||||
}
|
||||
_size = 0;
|
||||
|
||||
if (_readOnlyMap != null) {
|
||||
_index = _readOnlyMap.getIndex();
|
||||
} else {
|
||||
_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public final void setReadOnlyMap(KeyIntMap readOnlyMap, boolean clear) {
|
||||
if (!(readOnlyMap instanceof LocalNameQualifiedNamesMap)) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
|
||||
getString("message.illegalClass", new Object[]{readOnlyMap}));
|
||||
}
|
||||
|
||||
setReadOnlyMap((LocalNameQualifiedNamesMap)readOnlyMap, clear);
|
||||
}
|
||||
|
||||
public final void setReadOnlyMap(LocalNameQualifiedNamesMap readOnlyMap, boolean clear) {
|
||||
_readOnlyMap = readOnlyMap;
|
||||
if (_readOnlyMap != null) {
|
||||
_readOnlyMapSize = _readOnlyMap.size();
|
||||
_index = _readOnlyMap.getIndex();
|
||||
if (clear) {
|
||||
clear();
|
||||
}
|
||||
} else {
|
||||
_readOnlyMapSize = 0;
|
||||
_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean isQNameFromReadOnlyMap(QualifiedName name) {
|
||||
return (_readOnlyMap != null && name.index <= _readOnlyMap.getIndex());
|
||||
}
|
||||
|
||||
public final int getNextIndex() {
|
||||
return _index++;
|
||||
}
|
||||
|
||||
public final int getIndex() {
|
||||
return _index;
|
||||
}
|
||||
|
||||
public final Entry obtainEntry(String key) {
|
||||
final int hash = hashHash(key.hashCode());
|
||||
|
||||
if (_readOnlyMap != null) {
|
||||
final Entry entry = _readOnlyMap.getEntry(key, hash);
|
||||
if (entry != null) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
final int tableIndex = indexFor(hash, _table.length);
|
||||
for (Entry e = _table[tableIndex]; e != null; e = e._next) {
|
||||
if (e._hash == hash && eq(key, e._key)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
return addEntry(key, hash, tableIndex);
|
||||
}
|
||||
|
||||
public final Entry obtainDynamicEntry(String key) {
|
||||
final int hash = hashHash(key.hashCode());
|
||||
|
||||
final int tableIndex = indexFor(hash, _table.length);
|
||||
for (Entry e = _table[tableIndex]; e != null; e = e._next) {
|
||||
if (e._hash == hash && eq(key, e._key)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
return addEntry(key, hash, tableIndex);
|
||||
}
|
||||
|
||||
private final Entry getEntry(String key, int hash) {
|
||||
if (_readOnlyMap != null) {
|
||||
final Entry entry = _readOnlyMap.getEntry(key, hash);
|
||||
if (entry != null) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
final int tableIndex = indexFor(hash, _table.length);
|
||||
for (Entry e = _table[tableIndex]; e != null; e = e._next) {
|
||||
if (e._hash == hash && eq(key, e._key)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private final Entry addEntry(String key, int hash, int bucketIndex) {
|
||||
Entry e = _table[bucketIndex];
|
||||
_table[bucketIndex] = new Entry(key, hash, e);
|
||||
e = _table[bucketIndex];
|
||||
if (_size++ >= _threshold) {
|
||||
resize(2 * _table.length);
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
private final void resize(int newCapacity) {
|
||||
_capacity = newCapacity;
|
||||
Entry[] oldTable = _table;
|
||||
int oldCapacity = oldTable.length;
|
||||
if (oldCapacity == MAXIMUM_CAPACITY) {
|
||||
_threshold = Integer.MAX_VALUE;
|
||||
return;
|
||||
}
|
||||
|
||||
Entry[] newTable = new Entry[_capacity];
|
||||
transfer(newTable);
|
||||
_table = newTable;
|
||||
_threshold = (int)(_capacity * _loadFactor);
|
||||
}
|
||||
|
||||
private final void transfer(Entry[] newTable) {
|
||||
Entry[] src = _table;
|
||||
int newCapacity = newTable.length;
|
||||
for (int j = 0; j < src.length; j++) {
|
||||
Entry e = src[j];
|
||||
if (e != null) {
|
||||
src[j] = null;
|
||||
do {
|
||||
Entry next = e._next;
|
||||
int i = indexFor(e._hash, newCapacity);
|
||||
e._next = newTable[i];
|
||||
newTable[i] = e;
|
||||
e = next;
|
||||
} while (e != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final boolean eq(String x, String y) {
|
||||
return x == y || x.equals(y);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Paul.Sandoz@Sun.Com
|
||||
*/
|
||||
final public class NamespaceContextImplementation implements NamespaceContext {
|
||||
private static int DEFAULT_SIZE = 8;
|
||||
|
||||
private String[] prefixes = new String[DEFAULT_SIZE];
|
||||
private String[] namespaceURIs = new String[DEFAULT_SIZE];
|
||||
private int namespacePosition;
|
||||
|
||||
private int[] contexts = new int[DEFAULT_SIZE];
|
||||
private int contextPosition;
|
||||
|
||||
private int currentContext;
|
||||
|
||||
public NamespaceContextImplementation() {
|
||||
prefixes[0] = "xml";
|
||||
namespaceURIs[0] = "http://www.w3.org/XML/1998/namespace";
|
||||
prefixes[1] = "xmlns";
|
||||
namespaceURIs[1] = "http://www.w3.org/2000/xmlns/";
|
||||
|
||||
currentContext = namespacePosition = 2;
|
||||
}
|
||||
|
||||
|
||||
public String getNamespaceURI(String prefix) {
|
||||
if (prefix == null) throw new IllegalArgumentException();
|
||||
|
||||
// prefix = prefix.intern();
|
||||
|
||||
for (int i = namespacePosition - 1; i >= 0; i--) {
|
||||
final String declaredPrefix = prefixes[i];
|
||||
if (declaredPrefix.equals(prefix)) {
|
||||
return namespaceURIs[i];
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getPrefix(String namespaceURI) {
|
||||
if (namespaceURI == null) throw new IllegalArgumentException();
|
||||
|
||||
// namespaceURI = namespaceURI.intern();
|
||||
|
||||
for (int i = namespacePosition - 1; i >= 0; i--) {
|
||||
final String declaredNamespaceURI = namespaceURIs[i];
|
||||
if (declaredNamespaceURI.equals(namespaceURI)) {
|
||||
final String declaredPrefix = prefixes[i];
|
||||
|
||||
// Check if prefix is out of scope
|
||||
boolean isOutOfScope = false;
|
||||
for (int j = i + 1; j < namespacePosition; j++)
|
||||
if (declaredPrefix.equals(prefixes[j])) {
|
||||
isOutOfScope = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isOutOfScope) {
|
||||
return declaredPrefix;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getNonDefaultPrefix(String namespaceURI) {
|
||||
if (namespaceURI == null) throw new IllegalArgumentException();
|
||||
|
||||
// namespaceURI = namespaceURI.intern();
|
||||
|
||||
for (int i = namespacePosition - 1; i >= 0; i--) {
|
||||
final String declaredNamespaceURI = namespaceURIs[i];
|
||||
if (declaredNamespaceURI.equals(namespaceURI) &&
|
||||
prefixes[i].length() > 0){
|
||||
final String declaredPrefix = prefixes[i];
|
||||
|
||||
// Check if prefix is out of scope
|
||||
for (++i; i < namespacePosition; i++)
|
||||
if (declaredPrefix.equals(prefixes[i]))
|
||||
return null;
|
||||
|
||||
return declaredPrefix;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Iterator getPrefixes(String namespaceURI) {
|
||||
if (namespaceURI == null) throw new IllegalArgumentException();
|
||||
|
||||
// namespaceURI = namespaceURI.intern();
|
||||
|
||||
List l = new ArrayList();
|
||||
|
||||
NAMESPACE_LOOP: for (int i = namespacePosition - 1; i >= 0; i--) {
|
||||
final String declaredNamespaceURI = namespaceURIs[i];
|
||||
if (declaredNamespaceURI.equals(namespaceURI)) {
|
||||
final String declaredPrefix = prefixes[i];
|
||||
|
||||
// Check if prefix is out of scope
|
||||
for (int j = i + 1; j < namespacePosition; j++)
|
||||
if (declaredPrefix.equals(prefixes[j]))
|
||||
continue NAMESPACE_LOOP;
|
||||
|
||||
l.add(declaredPrefix);
|
||||
}
|
||||
}
|
||||
|
||||
return l.iterator();
|
||||
}
|
||||
|
||||
|
||||
public String getPrefix(int index) {
|
||||
return prefixes[index];
|
||||
}
|
||||
|
||||
public String getNamespaceURI(int index) {
|
||||
return namespaceURIs[index];
|
||||
}
|
||||
|
||||
public int getCurrentContextStartIndex() {
|
||||
return currentContext;
|
||||
}
|
||||
|
||||
public int getCurrentContextEndIndex() {
|
||||
return namespacePosition;
|
||||
}
|
||||
|
||||
public boolean isCurrentContextEmpty() {
|
||||
return currentContext == namespacePosition;
|
||||
}
|
||||
|
||||
public void declarePrefix(String prefix, String namespaceURI) {
|
||||
prefix = prefix.intern();
|
||||
namespaceURI = namespaceURI.intern();
|
||||
|
||||
// Ignore the "xml" or "xmlns" declarations
|
||||
if (prefix == "xml" || prefix == "xmlns")
|
||||
return;
|
||||
|
||||
// Replace any previous declaration
|
||||
for (int i = currentContext; i < namespacePosition; i++) {
|
||||
final String declaredPrefix = prefixes[i];
|
||||
if (declaredPrefix == prefix) {
|
||||
prefixes[i] = prefix;
|
||||
namespaceURIs[i] = namespaceURI;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (namespacePosition == namespaceURIs.length)
|
||||
resizeNamespaces();
|
||||
|
||||
// Add new declaration
|
||||
prefixes[namespacePosition] = prefix;
|
||||
namespaceURIs[namespacePosition++] = namespaceURI;
|
||||
}
|
||||
|
||||
private void resizeNamespaces() {
|
||||
final int newLength = namespaceURIs.length * 3 / 2 + 1;
|
||||
|
||||
String[] newPrefixes = new String[newLength];
|
||||
System.arraycopy(prefixes, 0, newPrefixes, 0, prefixes.length);
|
||||
prefixes = newPrefixes;
|
||||
|
||||
String[] newNamespaceURIs = new String[newLength];
|
||||
System.arraycopy(namespaceURIs, 0, newNamespaceURIs, 0, namespaceURIs.length);
|
||||
namespaceURIs = newNamespaceURIs;
|
||||
}
|
||||
|
||||
public void pushContext() {
|
||||
if (contextPosition == contexts.length)
|
||||
resizeContexts();
|
||||
|
||||
contexts[contextPosition++] = currentContext = namespacePosition;
|
||||
}
|
||||
|
||||
private void resizeContexts() {
|
||||
int[] newContexts = new int[contexts.length * 3 / 2 + 1];
|
||||
System.arraycopy(contexts, 0, newContexts, 0, contexts.length);
|
||||
contexts = newContexts;
|
||||
}
|
||||
|
||||
public void popContext() {
|
||||
if (contextPosition > 0) {
|
||||
namespacePosition = currentContext = contexts[--contextPosition];
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
currentContext = namespacePosition = 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,518 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.EncodingConstants;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
|
||||
|
||||
public class PrefixArray extends ValueArray {
|
||||
public static final int PREFIX_MAP_SIZE = 64;
|
||||
|
||||
private int _initialCapacity;
|
||||
|
||||
public String[] _array;
|
||||
|
||||
private PrefixArray _readOnlyArray;
|
||||
|
||||
private static class PrefixEntry {
|
||||
private PrefixEntry next;
|
||||
private int prefixId;
|
||||
}
|
||||
|
||||
private PrefixEntry[] _prefixMap = new PrefixEntry[PREFIX_MAP_SIZE];
|
||||
|
||||
private PrefixEntry _prefixPool;
|
||||
|
||||
private static class NamespaceEntry {
|
||||
private NamespaceEntry next;
|
||||
private int declarationId;
|
||||
private int namespaceIndex;
|
||||
|
||||
private String prefix;
|
||||
private String namespaceName;
|
||||
private int prefixEntryIndex;
|
||||
}
|
||||
|
||||
private NamespaceEntry _namespacePool;
|
||||
|
||||
private NamespaceEntry[] _inScopeNamespaces;
|
||||
|
||||
public int[] _currentInScope;
|
||||
|
||||
public int _declarationId;
|
||||
|
||||
public PrefixArray(int initialCapacity, int maximumCapacity) {
|
||||
_initialCapacity = initialCapacity;
|
||||
_maximumCapacity = maximumCapacity;
|
||||
|
||||
_array = new String[initialCapacity];
|
||||
// Sizes of _inScopeNamespaces and _currentInScope need to be two
|
||||
// greater than _array because 0 represents the empty string and
|
||||
// 1 represents the xml prefix
|
||||
_inScopeNamespaces = new NamespaceEntry[initialCapacity + 2];
|
||||
_currentInScope = new int[initialCapacity + 2];
|
||||
|
||||
increaseNamespacePool(initialCapacity);
|
||||
increasePrefixPool(initialCapacity);
|
||||
|
||||
initializeEntries();
|
||||
}
|
||||
|
||||
public PrefixArray() {
|
||||
this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY);
|
||||
}
|
||||
|
||||
private final void initializeEntries() {
|
||||
_inScopeNamespaces[0] = _namespacePool;
|
||||
_namespacePool = _namespacePool.next;
|
||||
_inScopeNamespaces[0].next = null;
|
||||
_inScopeNamespaces[0].prefix = "";
|
||||
_inScopeNamespaces[0].namespaceName = "";
|
||||
_inScopeNamespaces[0].namespaceIndex = _currentInScope[0] = 0;
|
||||
|
||||
int index = KeyIntMap.indexFor(KeyIntMap.hashHash(_inScopeNamespaces[0].prefix.hashCode()), _prefixMap.length);
|
||||
_prefixMap[index] = _prefixPool;
|
||||
_prefixPool = _prefixPool.next;
|
||||
_prefixMap[index].next = null;
|
||||
_prefixMap[index].prefixId = 0;
|
||||
|
||||
|
||||
_inScopeNamespaces[1] = _namespacePool;
|
||||
_namespacePool = _namespacePool.next;
|
||||
_inScopeNamespaces[1].next = null;
|
||||
_inScopeNamespaces[1].prefix = EncodingConstants.XML_NAMESPACE_PREFIX;
|
||||
_inScopeNamespaces[1].namespaceName = EncodingConstants.XML_NAMESPACE_NAME;
|
||||
_inScopeNamespaces[1].namespaceIndex = _currentInScope[1] = 1;
|
||||
|
||||
index = KeyIntMap.indexFor(KeyIntMap.hashHash(_inScopeNamespaces[1].prefix.hashCode()), _prefixMap.length);
|
||||
if (_prefixMap[index] == null) {
|
||||
_prefixMap[index] = _prefixPool;
|
||||
_prefixPool = _prefixPool.next;
|
||||
_prefixMap[index].next = null;
|
||||
} else {
|
||||
final PrefixEntry e = _prefixMap[index];
|
||||
_prefixMap[index] = _prefixPool;
|
||||
_prefixPool = _prefixPool.next;
|
||||
_prefixMap[index].next = e;
|
||||
}
|
||||
_prefixMap[index].prefixId = 1;
|
||||
}
|
||||
|
||||
private final void increaseNamespacePool(int capacity) {
|
||||
if (_namespacePool == null) {
|
||||
_namespacePool = new NamespaceEntry();
|
||||
}
|
||||
|
||||
for (int i = 0; i < capacity; i++) {
|
||||
NamespaceEntry ne = new NamespaceEntry();
|
||||
ne.next = _namespacePool;
|
||||
_namespacePool = ne;
|
||||
}
|
||||
}
|
||||
|
||||
private final void increasePrefixPool(int capacity) {
|
||||
if (_prefixPool == null) {
|
||||
_prefixPool = new PrefixEntry();
|
||||
}
|
||||
|
||||
for (int i = 0; i < capacity; i++) {
|
||||
PrefixEntry pe = new PrefixEntry();
|
||||
pe.next = _prefixPool;
|
||||
_prefixPool = pe;
|
||||
}
|
||||
}
|
||||
|
||||
public int countNamespacePool() {
|
||||
int i = 0;
|
||||
NamespaceEntry e = _namespacePool;
|
||||
while (e != null) {
|
||||
i++;
|
||||
e = e.next;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public int countPrefixPool() {
|
||||
int i = 0;
|
||||
PrefixEntry e = _prefixPool;
|
||||
while (e != null) {
|
||||
i++;
|
||||
e = e.next;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public final void clear() {
|
||||
for (int i = _readOnlyArraySize; i < _size; i++) {
|
||||
_array[i] = null;
|
||||
}
|
||||
_size = _readOnlyArraySize;
|
||||
}
|
||||
|
||||
public final void clearCompletely() {
|
||||
_prefixPool = null;
|
||||
_namespacePool = null;
|
||||
|
||||
for (int i = 0; i < _size + 2; i++) {
|
||||
_currentInScope[i] = 0;
|
||||
_inScopeNamespaces[i] = null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _prefixMap.length; i++) {
|
||||
_prefixMap[i] = null;
|
||||
}
|
||||
|
||||
increaseNamespacePool(_initialCapacity);
|
||||
increasePrefixPool(_initialCapacity);
|
||||
|
||||
initializeEntries();
|
||||
|
||||
_declarationId = 0;
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns cloned version of internal String[].
|
||||
* @return cloned version of internal String[].
|
||||
*/
|
||||
public final String[] getArray() {
|
||||
if (_array == null) return null;
|
||||
|
||||
final String[] clonedArray = new String[_array.length];
|
||||
System.arraycopy(_array, 0, clonedArray, 0, _array.length);
|
||||
return clonedArray;
|
||||
}
|
||||
|
||||
public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) {
|
||||
if (!(readOnlyArray instanceof PrefixArray)) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
|
||||
getString("message.illegalClass", new Object[]{readOnlyArray}));
|
||||
}
|
||||
|
||||
setReadOnlyArray((PrefixArray)readOnlyArray, clear);
|
||||
}
|
||||
|
||||
public final void setReadOnlyArray(PrefixArray readOnlyArray, boolean clear) {
|
||||
if (readOnlyArray != null) {
|
||||
_readOnlyArray = readOnlyArray;
|
||||
_readOnlyArraySize = readOnlyArray.getSize();
|
||||
|
||||
clearCompletely();
|
||||
|
||||
// Resize according to size of read only arrays
|
||||
_inScopeNamespaces = new NamespaceEntry[_readOnlyArraySize + _inScopeNamespaces.length];
|
||||
_currentInScope = new int[_readOnlyArraySize + _currentInScope.length];
|
||||
// Intialize first two entries
|
||||
initializeEntries();
|
||||
|
||||
if (clear) {
|
||||
clear();
|
||||
}
|
||||
|
||||
_array = getCompleteArray();
|
||||
_size = _readOnlyArraySize;
|
||||
}
|
||||
}
|
||||
|
||||
public final String[] getCompleteArray() {
|
||||
if (_readOnlyArray == null) {
|
||||
// Return cloned version of internal _array
|
||||
return getArray();
|
||||
// return _array;
|
||||
} else {
|
||||
final String[] ra = _readOnlyArray.getCompleteArray();
|
||||
final String[] a = new String[_readOnlyArraySize + _array.length];
|
||||
System.arraycopy(ra, 0, a, 0, _readOnlyArraySize);
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
public final String get(int i) {
|
||||
return _array[i];
|
||||
}
|
||||
|
||||
public final int add(String s) {
|
||||
if (_size == _array.length) {
|
||||
resize();
|
||||
}
|
||||
|
||||
_array[_size++] = s;
|
||||
return _size;
|
||||
}
|
||||
|
||||
protected final void resize() {
|
||||
if (_size == _maximumCapacity) {
|
||||
throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity"));
|
||||
}
|
||||
|
||||
int newSize = _size * 3 / 2 + 1;
|
||||
if (newSize > _maximumCapacity) {
|
||||
newSize = _maximumCapacity;
|
||||
}
|
||||
|
||||
final String[] newArray = new String[newSize];
|
||||
System.arraycopy(_array, 0, newArray, 0, _size);
|
||||
_array = newArray;
|
||||
|
||||
newSize += 2;
|
||||
final NamespaceEntry[] newInScopeNamespaces = new NamespaceEntry[newSize];
|
||||
System.arraycopy(_inScopeNamespaces, 0, newInScopeNamespaces, 0, _inScopeNamespaces.length);
|
||||
_inScopeNamespaces = newInScopeNamespaces;
|
||||
|
||||
final int[] newCurrentInScope = new int[newSize];
|
||||
System.arraycopy(_currentInScope, 0, newCurrentInScope, 0, _currentInScope.length);
|
||||
_currentInScope = newCurrentInScope;
|
||||
}
|
||||
|
||||
public final void clearDeclarationIds() {
|
||||
for (int i = 0; i < _size; i++) {
|
||||
final NamespaceEntry e = _inScopeNamespaces[i];
|
||||
if (e != null) {
|
||||
e.declarationId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
_declarationId = 1;
|
||||
}
|
||||
|
||||
public final void pushScope(int prefixIndex, int namespaceIndex) throws FastInfosetException {
|
||||
if (_namespacePool == null) {
|
||||
increaseNamespacePool(16);
|
||||
}
|
||||
|
||||
final NamespaceEntry e = _namespacePool;
|
||||
_namespacePool = e.next;
|
||||
|
||||
final NamespaceEntry current = _inScopeNamespaces[++prefixIndex];
|
||||
if (current == null) {
|
||||
e.declarationId = _declarationId;
|
||||
e.namespaceIndex = _currentInScope[prefixIndex] = ++namespaceIndex;
|
||||
e.next = null;
|
||||
|
||||
_inScopeNamespaces[prefixIndex] = e;
|
||||
} else if (current.declarationId < _declarationId) {
|
||||
e.declarationId = _declarationId;
|
||||
e.namespaceIndex = _currentInScope[prefixIndex] = ++namespaceIndex;
|
||||
e.next = current;
|
||||
|
||||
current.declarationId = 0;
|
||||
_inScopeNamespaces[prefixIndex] = e;
|
||||
} else {
|
||||
throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.duplicateNamespaceAttribute"));
|
||||
}
|
||||
}
|
||||
|
||||
public final void pushScopeWithPrefixEntry(String prefix, String namespaceName,
|
||||
int prefixIndex, int namespaceIndex) throws FastInfosetException {
|
||||
if (_namespacePool == null) {
|
||||
increaseNamespacePool(16);
|
||||
}
|
||||
if (_prefixPool == null) {
|
||||
increasePrefixPool(16);
|
||||
}
|
||||
|
||||
final NamespaceEntry e = _namespacePool;
|
||||
_namespacePool = e.next;
|
||||
|
||||
final NamespaceEntry current = _inScopeNamespaces[++prefixIndex];
|
||||
if (current == null) {
|
||||
e.declarationId = _declarationId;
|
||||
e.namespaceIndex = _currentInScope[prefixIndex] = ++namespaceIndex;
|
||||
e.next = null;
|
||||
|
||||
_inScopeNamespaces[prefixIndex] = e;
|
||||
} else if (current.declarationId < _declarationId) {
|
||||
e.declarationId = _declarationId;
|
||||
e.namespaceIndex = _currentInScope[prefixIndex] = ++namespaceIndex;
|
||||
e.next = current;
|
||||
|
||||
current.declarationId = 0;
|
||||
_inScopeNamespaces[prefixIndex] = e;
|
||||
} else {
|
||||
throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.duplicateNamespaceAttribute"));
|
||||
}
|
||||
|
||||
final PrefixEntry p = _prefixPool;
|
||||
_prefixPool = _prefixPool.next;
|
||||
p.prefixId = prefixIndex;
|
||||
|
||||
e.prefix = prefix;
|
||||
e.namespaceName = namespaceName;
|
||||
e.prefixEntryIndex = KeyIntMap.indexFor(KeyIntMap.hashHash(prefix.hashCode()), _prefixMap.length);
|
||||
|
||||
final PrefixEntry pCurrent = _prefixMap[e.prefixEntryIndex];
|
||||
p.next = pCurrent;
|
||||
_prefixMap[e.prefixEntryIndex] = p;
|
||||
}
|
||||
|
||||
public final void popScope(int prefixIndex) {
|
||||
final NamespaceEntry e = _inScopeNamespaces[++prefixIndex];
|
||||
_inScopeNamespaces[prefixIndex] = e.next;
|
||||
_currentInScope[prefixIndex] = (e.next != null) ? e.next.namespaceIndex : 0;
|
||||
|
||||
e.next = _namespacePool;
|
||||
_namespacePool = e;
|
||||
}
|
||||
|
||||
public final void popScopeWithPrefixEntry(int prefixIndex) {
|
||||
final NamespaceEntry e = _inScopeNamespaces[++prefixIndex];
|
||||
|
||||
_inScopeNamespaces[prefixIndex] = e.next;
|
||||
_currentInScope[prefixIndex] = (e.next != null) ? e.next.namespaceIndex : 0;
|
||||
|
||||
e.prefix = e.namespaceName = null;
|
||||
e.next = _namespacePool;
|
||||
_namespacePool = e;
|
||||
|
||||
PrefixEntry current = _prefixMap[e.prefixEntryIndex];
|
||||
if (current.prefixId == prefixIndex) {
|
||||
_prefixMap[e.prefixEntryIndex] = current.next;
|
||||
current.next = _prefixPool;
|
||||
_prefixPool = current;
|
||||
} else {
|
||||
PrefixEntry prev = current;
|
||||
current = current.next;
|
||||
while (current != null) {
|
||||
if (current.prefixId == prefixIndex) {
|
||||
prev.next = current.next;
|
||||
current.next = _prefixPool;
|
||||
_prefixPool = current;
|
||||
break;
|
||||
}
|
||||
prev = current;
|
||||
current = current.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final String getNamespaceFromPrefix(String prefix) {
|
||||
final int index = KeyIntMap.indexFor(KeyIntMap.hashHash(prefix.hashCode()), _prefixMap.length);
|
||||
PrefixEntry pe = _prefixMap[index];
|
||||
while (pe != null) {
|
||||
final NamespaceEntry ne = _inScopeNamespaces[pe.prefixId];
|
||||
if (prefix == ne.prefix || prefix.equals(ne.prefix)) {
|
||||
return ne.namespaceName;
|
||||
}
|
||||
pe = pe.next;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public final String getPrefixFromNamespace(String namespaceName) {
|
||||
int position = 0;
|
||||
while (++position < _size + 2) {
|
||||
final NamespaceEntry ne = _inScopeNamespaces[position];
|
||||
if (ne != null && namespaceName.equals(ne.namespaceName)) {
|
||||
return ne.prefix;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public final Iterator getPrefixes() {
|
||||
return new Iterator() {
|
||||
int _position = 1;
|
||||
NamespaceEntry _ne = _inScopeNamespaces[_position];
|
||||
|
||||
public boolean hasNext() {
|
||||
return _ne != null;
|
||||
}
|
||||
|
||||
public Object next() {
|
||||
if (_position == _size + 2) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
final String prefix = _ne.prefix;
|
||||
moveToNext();
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private final void moveToNext() {
|
||||
while (++_position < _size + 2) {
|
||||
_ne = _inScopeNamespaces[_position];
|
||||
if (_ne != null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
_ne = null;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public final Iterator getPrefixesFromNamespace(final String namespaceName) {
|
||||
return new Iterator() {
|
||||
String _namespaceName = namespaceName;
|
||||
int _position = 0;
|
||||
NamespaceEntry _ne;
|
||||
|
||||
{
|
||||
moveToNext();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return _ne != null;
|
||||
}
|
||||
|
||||
public Object next() {
|
||||
if (_position == _size + 2) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
final String prefix = _ne.prefix;
|
||||
moveToNext();
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private final void moveToNext() {
|
||||
while (++_position < _size + 2) {
|
||||
_ne = _inScopeNamespaces[_position];
|
||||
if (_ne != null && _namespaceName.equals(_ne.namespaceName)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
_ne = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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.util;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.QualifiedName;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class QualifiedNameArray extends ValueArray {
|
||||
|
||||
public QualifiedName[] _array;
|
||||
|
||||
private QualifiedNameArray _readOnlyArray;
|
||||
|
||||
public QualifiedNameArray(int initialCapacity, int maximumCapacity) {
|
||||
_array = new QualifiedName[initialCapacity];
|
||||
_maximumCapacity = maximumCapacity;
|
||||
}
|
||||
|
||||
public QualifiedNameArray() {
|
||||
this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY);
|
||||
}
|
||||
|
||||
public final void clear() {
|
||||
_size = _readOnlyArraySize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns cloned version of internal QualifiedName[].
|
||||
* @return cloned version of internal QualifiedName[].
|
||||
*/
|
||||
public final QualifiedName[] getArray() {
|
||||
if (_array == null) return null;
|
||||
|
||||
final QualifiedName[] clonedArray = new QualifiedName[_array.length];
|
||||
System.arraycopy(_array, 0, clonedArray, 0, _array.length);
|
||||
return clonedArray;
|
||||
}
|
||||
|
||||
public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) {
|
||||
if (!(readOnlyArray instanceof QualifiedNameArray)) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
|
||||
getString("message.illegalClass", new Object[]{readOnlyArray}));
|
||||
}
|
||||
|
||||
setReadOnlyArray((QualifiedNameArray)readOnlyArray, clear);
|
||||
}
|
||||
|
||||
public final void setReadOnlyArray(QualifiedNameArray readOnlyArray, boolean clear) {
|
||||
if (readOnlyArray != null) {
|
||||
_readOnlyArray = readOnlyArray;
|
||||
_readOnlyArraySize = readOnlyArray.getSize();
|
||||
|
||||
if (clear) {
|
||||
clear();
|
||||
}
|
||||
|
||||
_array = getCompleteArray();
|
||||
_size = _readOnlyArraySize;
|
||||
}
|
||||
}
|
||||
|
||||
public final QualifiedName[] getCompleteArray() {
|
||||
if (_readOnlyArray == null) {
|
||||
// Return cloned version of internal _array
|
||||
return getArray();
|
||||
// return _array;
|
||||
} else {
|
||||
final QualifiedName[] ra = _readOnlyArray.getCompleteArray();
|
||||
final QualifiedName[] a = new QualifiedName[_readOnlyArraySize + _array.length];
|
||||
System.arraycopy(ra, 0, a, 0, _readOnlyArraySize);
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
public final QualifiedName getNext() {
|
||||
return (_size == _array.length) ? null : _array[_size];
|
||||
}
|
||||
|
||||
public final void add(QualifiedName s) {
|
||||
if (_size == _array.length) {
|
||||
resize();
|
||||
}
|
||||
|
||||
_array[_size++] = s;
|
||||
}
|
||||
|
||||
protected final void resize() {
|
||||
if (_size == _maximumCapacity) {
|
||||
throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity"));
|
||||
}
|
||||
|
||||
int newSize = _size * 3 / 2 + 1;
|
||||
if (newSize > _maximumCapacity) {
|
||||
newSize = _maximumCapacity;
|
||||
}
|
||||
|
||||
final QualifiedName[] newArray = new QualifiedName[newSize];
|
||||
System.arraycopy(_array, 0, newArray, 0, _size);
|
||||
_array = newArray;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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.util;
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class StringArray extends ValueArray {
|
||||
|
||||
public String[] _array;
|
||||
|
||||
private StringArray _readOnlyArray;
|
||||
|
||||
private boolean _clear;
|
||||
|
||||
public StringArray(int initialCapacity, int maximumCapacity, boolean clear) {
|
||||
_array = new String[initialCapacity];
|
||||
_maximumCapacity = maximumCapacity;
|
||||
_clear = clear;
|
||||
}
|
||||
|
||||
public StringArray() {
|
||||
this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY, false);
|
||||
}
|
||||
|
||||
public final void clear() {
|
||||
if (_clear) for (int i = _readOnlyArraySize; i < _size; i++) {
|
||||
_array[i] = null;
|
||||
}
|
||||
_size = _readOnlyArraySize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns cloned version of internal String[].
|
||||
* @return cloned version of internal String[].
|
||||
*/
|
||||
public final String[] getArray() {
|
||||
if (_array == null) return null;
|
||||
|
||||
final String[] clonedArray = new String[_array.length];
|
||||
System.arraycopy(_array, 0, clonedArray, 0, _array.length);
|
||||
return clonedArray;
|
||||
}
|
||||
|
||||
public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) {
|
||||
if (!(readOnlyArray instanceof StringArray)) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
|
||||
getString("message.illegalClass", new Object[]{readOnlyArray}));
|
||||
}
|
||||
|
||||
setReadOnlyArray((StringArray)readOnlyArray, clear);
|
||||
}
|
||||
|
||||
public final void setReadOnlyArray(StringArray readOnlyArray, boolean clear) {
|
||||
if (readOnlyArray != null) {
|
||||
_readOnlyArray = readOnlyArray;
|
||||
_readOnlyArraySize = readOnlyArray.getSize();
|
||||
|
||||
if (clear) {
|
||||
clear();
|
||||
}
|
||||
|
||||
_array = getCompleteArray();
|
||||
_size = _readOnlyArraySize;
|
||||
}
|
||||
}
|
||||
|
||||
public final String[] getCompleteArray() {
|
||||
if (_readOnlyArray == null) {
|
||||
// Return cloned version of internal _array
|
||||
return getArray();
|
||||
// return _array;
|
||||
} else {
|
||||
final String[] ra = _readOnlyArray.getCompleteArray();
|
||||
final String[] a = new String[_readOnlyArraySize + _array.length];
|
||||
System.arraycopy(ra, 0, a, 0, _readOnlyArraySize);
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
public final String get(int i) {
|
||||
return _array[i];
|
||||
}
|
||||
|
||||
public final int add(String s) {
|
||||
if (_size == _array.length) {
|
||||
resize();
|
||||
}
|
||||
|
||||
_array[_size++] = s;
|
||||
return _size;
|
||||
}
|
||||
|
||||
protected final void resize() {
|
||||
if (_size == _maximumCapacity) {
|
||||
throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity"));
|
||||
}
|
||||
|
||||
int newSize = _size * 3 / 2 + 1;
|
||||
if (newSize > _maximumCapacity) {
|
||||
newSize = _maximumCapacity;
|
||||
}
|
||||
|
||||
final String[] newArray = new String[newSize];
|
||||
System.arraycopy(_array, 0, newArray, 0, _size);
|
||||
_array = newArray;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
|
||||
|
||||
public class StringIntMap extends KeyIntMap {
|
||||
protected static final Entry NULL_ENTRY = new Entry(null, 0, -1, null);
|
||||
|
||||
protected StringIntMap _readOnlyMap;
|
||||
|
||||
protected static class Entry extends BaseEntry {
|
||||
final String _key;
|
||||
Entry _next;
|
||||
|
||||
public Entry(String key, int hash, int value, Entry next) {
|
||||
super(hash, value);
|
||||
_key = key;
|
||||
_next = next;
|
||||
}
|
||||
}
|
||||
|
||||
protected Entry _lastEntry = NULL_ENTRY;
|
||||
|
||||
protected Entry[] _table;
|
||||
|
||||
protected int _index;
|
||||
|
||||
// Total character count of Map
|
||||
protected int _totalCharacterCount;
|
||||
|
||||
public StringIntMap(int initialCapacity, float loadFactor) {
|
||||
super(initialCapacity, loadFactor);
|
||||
|
||||
_table = new Entry[_capacity];
|
||||
}
|
||||
|
||||
public StringIntMap(int initialCapacity) {
|
||||
this(initialCapacity, DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
public StringIntMap() {
|
||||
this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
for (int i = 0; i < _table.length; i++) {
|
||||
_table[i] = null;
|
||||
}
|
||||
_lastEntry = NULL_ENTRY;
|
||||
_size = 0;
|
||||
_index = _readOnlyMapSize;
|
||||
_totalCharacterCount = 0;
|
||||
}
|
||||
|
||||
public void setReadOnlyMap(KeyIntMap readOnlyMap, boolean clear) {
|
||||
if (!(readOnlyMap instanceof StringIntMap)) {
|
||||
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
|
||||
getString("message.illegalClass", new Object[]{readOnlyMap}));
|
||||
}
|
||||
|
||||
setReadOnlyMap((StringIntMap)readOnlyMap, clear);
|
||||
}
|
||||
|
||||
public final void setReadOnlyMap(StringIntMap readOnlyMap, boolean clear) {
|
||||
_readOnlyMap = readOnlyMap;
|
||||
if (_readOnlyMap != null) {
|
||||
_readOnlyMapSize = _readOnlyMap.size();
|
||||
_index = _size + _readOnlyMapSize;
|
||||
|
||||
if (clear) {
|
||||
clear();
|
||||
}
|
||||
} else {
|
||||
_readOnlyMapSize = 0;
|
||||
_index = _size;
|
||||
}
|
||||
}
|
||||
|
||||
public final int getNextIndex() {
|
||||
return _index++;
|
||||
}
|
||||
|
||||
public final int getIndex() {
|
||||
return _index;
|
||||
}
|
||||
|
||||
public final int obtainIndex(String key) {
|
||||
final int hash = hashHash(key.hashCode());
|
||||
|
||||
if (_readOnlyMap != null) {
|
||||
final int index = _readOnlyMap.get(key, hash);
|
||||
if (index != -1) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
final int tableIndex = indexFor(hash, _table.length);
|
||||
for (Entry e = _table[tableIndex]; e != null; e = e._next) {
|
||||
if (e._hash == hash && eq(key, e._key)) {
|
||||
return e._value;
|
||||
}
|
||||
}
|
||||
|
||||
addEntry(key, hash, tableIndex);
|
||||
return NOT_PRESENT;
|
||||
}
|
||||
|
||||
public final void add(String key) {
|
||||
final int hash = hashHash(key.hashCode());
|
||||
final int tableIndex = indexFor(hash, _table.length);
|
||||
addEntry(key, hash, tableIndex);
|
||||
}
|
||||
|
||||
public final int get(String key) {
|
||||
if (key == _lastEntry._key)
|
||||
return _lastEntry._value;
|
||||
|
||||
return get(key, hashHash(key.hashCode()));
|
||||
}
|
||||
|
||||
public final int getTotalCharacterCount() {
|
||||
return _totalCharacterCount;
|
||||
}
|
||||
|
||||
private final int get(String key, int hash) {
|
||||
if (_readOnlyMap != null) {
|
||||
final int i = _readOnlyMap.get(key, hash);
|
||||
if (i != -1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
final int tableIndex = indexFor(hash, _table.length);
|
||||
for (Entry e = _table[tableIndex]; e != null; e = e._next) {
|
||||
if (e._hash == hash && eq(key, e._key)) {
|
||||
_lastEntry = e;
|
||||
return e._value;
|
||||
}
|
||||
}
|
||||
|
||||
return NOT_PRESENT;
|
||||
}
|
||||
|
||||
|
||||
private final void addEntry(String key, int hash, int bucketIndex) {
|
||||
Entry e = _table[bucketIndex];
|
||||
_table[bucketIndex] = new Entry(key, hash, _index++, e);
|
||||
_totalCharacterCount += key.length();
|
||||
if (_size++ >= _threshold) {
|
||||
resize(2 * _table.length);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void resize(int newCapacity) {
|
||||
_capacity = newCapacity;
|
||||
Entry[] oldTable = _table;
|
||||
int oldCapacity = oldTable.length;
|
||||
if (oldCapacity == MAXIMUM_CAPACITY) {
|
||||
_threshold = Integer.MAX_VALUE;
|
||||
return;
|
||||
}
|
||||
|
||||
Entry[] newTable = new Entry[_capacity];
|
||||
transfer(newTable);
|
||||
_table = newTable;
|
||||
_threshold = (int)(_capacity * _loadFactor);
|
||||
}
|
||||
|
||||
private final void transfer(Entry[] newTable) {
|
||||
Entry[] src = _table;
|
||||
int newCapacity = newTable.length;
|
||||
for (int j = 0; j < src.length; j++) {
|
||||
Entry e = src[j];
|
||||
if (e != null) {
|
||||
src[j] = null;
|
||||
do {
|
||||
Entry next = e._next;
|
||||
int i = indexFor(e._hash, newCapacity);
|
||||
e._next = newTable[i];
|
||||
newTable[i] = e;
|
||||
e = next;
|
||||
} while (e != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final boolean eq(String x, String y) {
|
||||
return x == y || x.equals(y);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
public abstract class ValueArray {
|
||||
public static final int DEFAULT_CAPACITY = 10;
|
||||
public static final int MAXIMUM_CAPACITY = Integer.MAX_VALUE;
|
||||
|
||||
protected int _size;
|
||||
|
||||
protected int _readOnlyArraySize;
|
||||
|
||||
protected int _maximumCapacity;
|
||||
|
||||
public int getSize() {
|
||||
return _size;
|
||||
}
|
||||
|
||||
public int getMaximumCapacity() {
|
||||
return _maximumCapacity;
|
||||
}
|
||||
|
||||
public void setMaximumCapacity(int maximumCapacity) {
|
||||
_maximumCapacity = maximumCapacity;
|
||||
}
|
||||
|
||||
public abstract void setReadOnlyArray(ValueArray array, boolean clear);
|
||||
|
||||
public abstract void clear();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
public class ValueArrayResourceException extends RuntimeException {
|
||||
|
||||
public ValueArrayResourceException() {
|
||||
}
|
||||
|
||||
public ValueArrayResourceException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* 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.vocab;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.EncodingConstants;
|
||||
import com.sun.xml.internal.fastinfoset.QualifiedName;
|
||||
import com.sun.xml.internal.fastinfoset.util.CharArray;
|
||||
import com.sun.xml.internal.fastinfoset.util.CharArrayArray;
|
||||
import com.sun.xml.internal.fastinfoset.util.ContiguousCharArrayArray;
|
||||
import com.sun.xml.internal.fastinfoset.util.DuplicateAttributeVerifier;
|
||||
import com.sun.xml.internal.fastinfoset.util.FixedEntryStringIntMap;
|
||||
import com.sun.xml.internal.fastinfoset.util.KeyIntMap;
|
||||
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.util.ValueArray;
|
||||
import java.util.Iterator;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
public class ParserVocabulary extends Vocabulary {
|
||||
public static final String IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY =
|
||||
"com.sun.xml.internal.fastinfoset.vocab.ParserVocabulary.IdentifyingStringTable.maximumItems";
|
||||
public static final String NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY =
|
||||
"com.sun.xml.internal.fastinfoset.vocab.ParserVocabulary.NonIdentifyingStringTable.maximumItems";
|
||||
public static final String NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS_PEOPERTY =
|
||||
"com.sun.xml.internal.fastinfoset.vocab.ParserVocabulary.NonIdentifyingStringTable.maximumCharacters";
|
||||
|
||||
protected static final int IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS =
|
||||
getIntegerValueFromProperty(IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY);
|
||||
protected static final int NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS =
|
||||
getIntegerValueFromProperty(NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS_PEOPERTY);
|
||||
protected static final int NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS =
|
||||
getIntegerValueFromProperty(NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS_PEOPERTY);
|
||||
|
||||
private static int getIntegerValueFromProperty(String property) {
|
||||
String value = System.getProperty(property);
|
||||
if (value == null) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
try {
|
||||
return Math.max(Integer.parseInt(value), ValueArray.DEFAULT_CAPACITY);
|
||||
} catch (NumberFormatException e) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
public final CharArrayArray restrictedAlphabet = new CharArrayArray(ValueArray.DEFAULT_CAPACITY, 256);
|
||||
public final StringArray encodingAlgorithm = new StringArray(ValueArray.DEFAULT_CAPACITY, 256, true);
|
||||
|
||||
public final StringArray namespaceName;
|
||||
public final PrefixArray prefix;
|
||||
public final StringArray localName;
|
||||
public final StringArray otherNCName ;
|
||||
public final StringArray otherURI;
|
||||
public final StringArray attributeValue;
|
||||
public final CharArrayArray otherString;
|
||||
|
||||
public final ContiguousCharArrayArray characterContentChunk;
|
||||
|
||||
public final QualifiedNameArray elementName;
|
||||
public final QualifiedNameArray attributeName;
|
||||
|
||||
public final ValueArray[] tables = new ValueArray[12];
|
||||
|
||||
protected SerializerVocabulary _readOnlyVocabulary;
|
||||
|
||||
/** Creates a new instance of ParserVocabulary */
|
||||
public ParserVocabulary() {
|
||||
namespaceName = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, false);
|
||||
prefix = new PrefixArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
|
||||
localName = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, false);
|
||||
otherNCName = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, false);
|
||||
otherURI = new StringArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, true);
|
||||
attributeValue = new StringArray(ValueArray.DEFAULT_CAPACITY, NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS, true);
|
||||
otherString = new CharArrayArray(ValueArray.DEFAULT_CAPACITY, NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
|
||||
|
||||
characterContentChunk = new ContiguousCharArrayArray(ValueArray.DEFAULT_CAPACITY,
|
||||
NON_IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS,
|
||||
ContiguousCharArrayArray.INITIAL_CHARACTER_SIZE,
|
||||
NON_IDENTIFYING_STRING_TABLE_MAXIMUM_CHARACTERS);
|
||||
|
||||
elementName = new QualifiedNameArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
|
||||
attributeName = new QualifiedNameArray(ValueArray.DEFAULT_CAPACITY, IDENTIFYING_STRING_TABLE_MAXIMUM_ITEMS);
|
||||
|
||||
tables[RESTRICTED_ALPHABET] = restrictedAlphabet;
|
||||
tables[ENCODING_ALGORITHM] = encodingAlgorithm;
|
||||
tables[PREFIX] = prefix;
|
||||
tables[NAMESPACE_NAME] = namespaceName;
|
||||
tables[LOCAL_NAME] = localName;
|
||||
tables[OTHER_NCNAME] = otherNCName;
|
||||
tables[OTHER_URI] = otherURI;
|
||||
tables[ATTRIBUTE_VALUE] = attributeValue;
|
||||
tables[OTHER_STRING] = otherString;
|
||||
tables[CHARACTER_CONTENT_CHUNK] = characterContentChunk;
|
||||
tables[ELEMENT_NAME] = elementName;
|
||||
tables[ATTRIBUTE_NAME] = attributeName;
|
||||
}
|
||||
|
||||
|
||||
public ParserVocabulary(com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary v) {
|
||||
this();
|
||||
|
||||
convertVocabulary(v);
|
||||
}
|
||||
|
||||
void setReadOnlyVocabulary(ParserVocabulary readOnlyVocabulary, boolean clear) {
|
||||
for (int i = 0; i < tables.length; i++) {
|
||||
tables[i].setReadOnlyArray(readOnlyVocabulary.tables[i], clear);
|
||||
}
|
||||
}
|
||||
|
||||
public void setInitialVocabulary(ParserVocabulary initialVocabulary, boolean clear) {
|
||||
setExternalVocabularyURI(null);
|
||||
setInitialReadOnlyVocabulary(true);
|
||||
setReadOnlyVocabulary(initialVocabulary, clear);
|
||||
}
|
||||
|
||||
public void setReferencedVocabulary(String referencedVocabularyURI, ParserVocabulary referencedVocabulary, boolean clear) {
|
||||
if (!referencedVocabularyURI.equals(getExternalVocabularyURI())) {
|
||||
setInitialReadOnlyVocabulary(false);
|
||||
setExternalVocabularyURI(referencedVocabularyURI);
|
||||
setReadOnlyVocabulary(referencedVocabulary, clear);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
for (int i = 0; i < tables.length; i++) {
|
||||
tables[i].clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void convertVocabulary(com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary v) {
|
||||
final StringIntMap prefixMap = new FixedEntryStringIntMap(
|
||||
EncodingConstants.XML_NAMESPACE_PREFIX, 8);
|
||||
final StringIntMap namespaceNameMap = new FixedEntryStringIntMap(
|
||||
EncodingConstants.XML_NAMESPACE_NAME, 8);
|
||||
final StringIntMap localNameMap = new StringIntMap();
|
||||
|
||||
addToTable(v.restrictedAlphabets.iterator(), restrictedAlphabet);
|
||||
addToTable(v.encodingAlgorithms.iterator(), encodingAlgorithm);
|
||||
addToTable(v.prefixes.iterator(), prefix, prefixMap);
|
||||
addToTable(v.namespaceNames.iterator(), namespaceName, namespaceNameMap);
|
||||
addToTable(v.localNames.iterator(), localName, localNameMap);
|
||||
addToTable(v.otherNCNames.iterator(), otherNCName);
|
||||
addToTable(v.otherURIs.iterator(), otherURI);
|
||||
addToTable(v.attributeValues.iterator(), attributeValue);
|
||||
addToTable(v.otherStrings.iterator(), otherString);
|
||||
addToTable(v.characterContentChunks.iterator(), characterContentChunk);
|
||||
addToTable(v.elements.iterator(), elementName, false,
|
||||
prefixMap, namespaceNameMap, localNameMap);
|
||||
addToTable(v.attributes.iterator(), attributeName, true,
|
||||
prefixMap, namespaceNameMap, localNameMap);
|
||||
}
|
||||
|
||||
private void addToTable(Iterator i, StringArray a) {
|
||||
while (i.hasNext()) {
|
||||
addToTable((String)i.next(), a, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void addToTable(Iterator i, StringArray a, StringIntMap m) {
|
||||
while (i.hasNext()) {
|
||||
addToTable((String)i.next(), a, m);
|
||||
}
|
||||
}
|
||||
|
||||
private void addToTable(String s, StringArray a, StringIntMap m) {
|
||||
if (s.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m != null) m.obtainIndex(s);
|
||||
a.add(s);
|
||||
}
|
||||
|
||||
private void addToTable(Iterator i, PrefixArray a, StringIntMap m) {
|
||||
while (i.hasNext()) {
|
||||
addToTable((String)i.next(), a, m);
|
||||
}
|
||||
}
|
||||
|
||||
private void addToTable(String s, PrefixArray a, StringIntMap m) {
|
||||
if (s.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m != null) m.obtainIndex(s);
|
||||
a.add(s);
|
||||
}
|
||||
|
||||
private void addToTable(Iterator i, ContiguousCharArrayArray a) {
|
||||
while (i.hasNext()) {
|
||||
addToTable((String)i.next(), a);
|
||||
}
|
||||
}
|
||||
|
||||
private void addToTable(String s, ContiguousCharArrayArray a) {
|
||||
if (s.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
char[] c = s.toCharArray();
|
||||
a.add(c, c.length);
|
||||
}
|
||||
|
||||
private void addToTable(Iterator i, CharArrayArray a) {
|
||||
while (i.hasNext()) {
|
||||
addToTable((String)i.next(), a);
|
||||
}
|
||||
}
|
||||
|
||||
private void addToTable(String s, CharArrayArray a) {
|
||||
if (s.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
char[] c = s.toCharArray();
|
||||
a.add(new CharArray(c, 0, c.length, false));
|
||||
}
|
||||
|
||||
private void addToTable(Iterator i, QualifiedNameArray a,
|
||||
boolean isAttribute,
|
||||
StringIntMap prefixMap, StringIntMap namespaceNameMap,
|
||||
StringIntMap localNameMap) {
|
||||
while (i.hasNext()) {
|
||||
addToNameTable((QName)i.next(), a, isAttribute,
|
||||
prefixMap, namespaceNameMap, localNameMap);
|
||||
}
|
||||
}
|
||||
|
||||
private void addToNameTable(QName n, QualifiedNameArray a,
|
||||
boolean isAttribute,
|
||||
StringIntMap prefixMap, StringIntMap namespaceNameMap,
|
||||
StringIntMap localNameMap) {
|
||||
int namespaceURIIndex = -1;
|
||||
int prefixIndex = -1;
|
||||
if (n.getNamespaceURI().length() > 0) {
|
||||
namespaceURIIndex = namespaceNameMap.obtainIndex(n.getNamespaceURI());
|
||||
if (namespaceURIIndex == KeyIntMap.NOT_PRESENT) {
|
||||
namespaceURIIndex = namespaceName.getSize();
|
||||
namespaceName.add(n.getNamespaceURI());
|
||||
}
|
||||
|
||||
if (n.getPrefix().length() > 0) {
|
||||
prefixIndex = prefixMap.obtainIndex(n.getPrefix());
|
||||
if (prefixIndex == KeyIntMap.NOT_PRESENT) {
|
||||
prefixIndex = prefix.getSize();
|
||||
prefix.add(n.getPrefix());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int localNameIndex = localNameMap.obtainIndex(n.getLocalPart());
|
||||
if (localNameIndex == KeyIntMap.NOT_PRESENT) {
|
||||
localNameIndex = localName.getSize();
|
||||
localName.add(n.getLocalPart());
|
||||
}
|
||||
|
||||
QualifiedName name = new QualifiedName(n.getPrefix(), n.getNamespaceURI(), n.getLocalPart(),
|
||||
a.getSize(),
|
||||
prefixIndex, namespaceURIIndex, localNameIndex);
|
||||
if (isAttribute) {
|
||||
name.createAttributeValues(DuplicateAttributeVerifier.MAP_SIZE);
|
||||
}
|
||||
a.add(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* 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.vocab;
|
||||
|
||||
import com.sun.xml.internal.fastinfoset.EncodingConstants;
|
||||
import com.sun.xml.internal.fastinfoset.QualifiedName;
|
||||
import com.sun.xml.internal.fastinfoset.util.CharArrayIntMap;
|
||||
import com.sun.xml.internal.fastinfoset.util.FixedEntryStringIntMap;
|
||||
import com.sun.xml.internal.fastinfoset.util.KeyIntMap;
|
||||
import com.sun.xml.internal.fastinfoset.util.LocalNameQualifiedNamesMap;
|
||||
import com.sun.xml.internal.fastinfoset.util.StringIntMap;
|
||||
import java.util.Iterator;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
public class SerializerVocabulary extends Vocabulary {
|
||||
public final StringIntMap restrictedAlphabet;
|
||||
public final StringIntMap encodingAlgorithm;
|
||||
|
||||
public final StringIntMap namespaceName;
|
||||
public final StringIntMap prefix;
|
||||
public final StringIntMap localName;
|
||||
public final StringIntMap otherNCName;
|
||||
public final StringIntMap otherURI;
|
||||
public final StringIntMap attributeValue;
|
||||
public final CharArrayIntMap otherString;
|
||||
|
||||
public final CharArrayIntMap characterContentChunk;
|
||||
|
||||
public final LocalNameQualifiedNamesMap elementName;
|
||||
public final LocalNameQualifiedNamesMap attributeName;
|
||||
|
||||
public final KeyIntMap[] tables = new KeyIntMap[12];
|
||||
|
||||
protected boolean _useLocalNameAsKey;
|
||||
|
||||
protected SerializerVocabulary _readOnlyVocabulary;
|
||||
|
||||
public SerializerVocabulary() {
|
||||
tables[RESTRICTED_ALPHABET] = restrictedAlphabet = new StringIntMap(4);
|
||||
tables[ENCODING_ALGORITHM] = encodingAlgorithm = new StringIntMap(4);
|
||||
tables[PREFIX] = prefix = new FixedEntryStringIntMap(EncodingConstants.XML_NAMESPACE_PREFIX, 8);
|
||||
tables[NAMESPACE_NAME] = namespaceName = new FixedEntryStringIntMap(EncodingConstants.XML_NAMESPACE_NAME, 8);
|
||||
tables[LOCAL_NAME] = localName = new StringIntMap();
|
||||
tables[OTHER_NCNAME] = otherNCName = new StringIntMap(4);
|
||||
tables[OTHER_URI] = otherURI = new StringIntMap(4);
|
||||
tables[ATTRIBUTE_VALUE] = attributeValue = new StringIntMap();
|
||||
tables[OTHER_STRING] = otherString = new CharArrayIntMap(4);
|
||||
tables[CHARACTER_CONTENT_CHUNK] = characterContentChunk = new CharArrayIntMap();
|
||||
tables[ELEMENT_NAME] = elementName = new LocalNameQualifiedNamesMap();
|
||||
tables[ATTRIBUTE_NAME] = attributeName = new LocalNameQualifiedNamesMap();
|
||||
}
|
||||
|
||||
public SerializerVocabulary(com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary v,
|
||||
boolean useLocalNameAsKey) {
|
||||
this();
|
||||
|
||||
_useLocalNameAsKey = useLocalNameAsKey;
|
||||
convertVocabulary(v);
|
||||
}
|
||||
|
||||
public SerializerVocabulary getReadOnlyVocabulary() {
|
||||
return _readOnlyVocabulary;
|
||||
}
|
||||
|
||||
protected void setReadOnlyVocabulary(SerializerVocabulary readOnlyVocabulary,
|
||||
boolean clear) {
|
||||
for (int i = 0; i < tables.length; i++) {
|
||||
tables[i].setReadOnlyMap(readOnlyVocabulary.tables[i], clear);
|
||||
}
|
||||
}
|
||||
|
||||
public void setInitialVocabulary(SerializerVocabulary initialVocabulary,
|
||||
boolean clear) {
|
||||
setExternalVocabularyURI(null);
|
||||
setInitialReadOnlyVocabulary(true);
|
||||
setReadOnlyVocabulary(initialVocabulary, clear);
|
||||
}
|
||||
|
||||
public void setExternalVocabulary(String externalVocabularyURI,
|
||||
SerializerVocabulary externalVocabulary, boolean clear) {
|
||||
setInitialReadOnlyVocabulary(false);
|
||||
setExternalVocabularyURI(externalVocabularyURI);
|
||||
setReadOnlyVocabulary(externalVocabulary, clear);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
for (int i = 0; i < tables.length; i++) {
|
||||
tables[i].clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void convertVocabulary(com.sun.xml.internal.org.jvnet.fastinfoset.Vocabulary v) {
|
||||
addToTable(v.restrictedAlphabets.iterator(), restrictedAlphabet);
|
||||
addToTable(v.encodingAlgorithms.iterator(), encodingAlgorithm);
|
||||
addToTable(v.prefixes.iterator(), prefix);
|
||||
addToTable(v.namespaceNames.iterator(), namespaceName);
|
||||
addToTable(v.localNames.iterator(), localName);
|
||||
addToTable(v.otherNCNames.iterator(), otherNCName);
|
||||
addToTable(v.otherURIs.iterator(), otherURI);
|
||||
addToTable(v.attributeValues.iterator(), attributeValue);
|
||||
addToTable(v.otherStrings.iterator(), otherString);
|
||||
addToTable(v.characterContentChunks.iterator(), characterContentChunk);
|
||||
addToTable(v.elements.iterator(), elementName);
|
||||
addToTable(v.attributes.iterator(), attributeName);
|
||||
}
|
||||
|
||||
private void addToTable(Iterator i, StringIntMap m) {
|
||||
while (i.hasNext()) {
|
||||
addToTable((String)i.next(), m);
|
||||
}
|
||||
}
|
||||
|
||||
private void addToTable(String s, StringIntMap m) {
|
||||
if (s.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
m.obtainIndex(s);
|
||||
}
|
||||
|
||||
private void addToTable(Iterator i, CharArrayIntMap m) {
|
||||
while (i.hasNext()) {
|
||||
addToTable((String)i.next(), m);
|
||||
}
|
||||
}
|
||||
|
||||
private void addToTable(String s, CharArrayIntMap m) {
|
||||
if (s.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
char[] c = s.toCharArray();
|
||||
m.obtainIndex(c, 0, c.length, false);
|
||||
}
|
||||
|
||||
private void addToTable(Iterator i, LocalNameQualifiedNamesMap m) {
|
||||
while (i.hasNext()) {
|
||||
addToNameTable((QName)i.next(), m);
|
||||
}
|
||||
}
|
||||
|
||||
private void addToNameTable(QName n, LocalNameQualifiedNamesMap m) {
|
||||
int namespaceURIIndex = -1;
|
||||
int prefixIndex = -1;
|
||||
if (n.getNamespaceURI().length() > 0) {
|
||||
namespaceURIIndex = namespaceName.obtainIndex(n.getNamespaceURI());
|
||||
if (namespaceURIIndex == KeyIntMap.NOT_PRESENT) {
|
||||
namespaceURIIndex = namespaceName.get(n.getNamespaceURI());
|
||||
}
|
||||
|
||||
if (n.getPrefix().length() > 0) {
|
||||
prefixIndex = prefix.obtainIndex(n.getPrefix());
|
||||
if (prefixIndex == KeyIntMap.NOT_PRESENT) {
|
||||
prefixIndex = prefix.get(n.getPrefix());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int localNameIndex = localName.obtainIndex(n.getLocalPart());
|
||||
if (localNameIndex == KeyIntMap.NOT_PRESENT) {
|
||||
localNameIndex = localName.get(n.getLocalPart());
|
||||
}
|
||||
|
||||
QualifiedName name = new QualifiedName(n.getPrefix(), n.getNamespaceURI(), n.getLocalPart(),
|
||||
m.getNextIndex(),
|
||||
prefixIndex, namespaceURIIndex, localNameIndex);
|
||||
|
||||
LocalNameQualifiedNamesMap.Entry entry = null;
|
||||
if (_useLocalNameAsKey) {
|
||||
entry = m.obtainEntry(n.getLocalPart());
|
||||
} else {
|
||||
String qName = (prefixIndex == -1)
|
||||
? n.getLocalPart()
|
||||
: n.getPrefix() + ":" + n.getLocalPart();
|
||||
entry = m.obtainEntry(qName);
|
||||
}
|
||||
|
||||
entry.addQualifiedName(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.vocab;
|
||||
|
||||
|
||||
public abstract class Vocabulary {
|
||||
public static final int RESTRICTED_ALPHABET = 0;
|
||||
public static final int ENCODING_ALGORITHM = 1;
|
||||
public static final int PREFIX = 2;
|
||||
public static final int NAMESPACE_NAME = 3;
|
||||
public static final int LOCAL_NAME = 4;
|
||||
public static final int OTHER_NCNAME = 5;
|
||||
public static final int OTHER_URI = 6;
|
||||
public static final int ATTRIBUTE_VALUE = 7;
|
||||
public static final int OTHER_STRING = 8;
|
||||
public static final int CHARACTER_CONTENT_CHUNK = 9;
|
||||
public static final int ELEMENT_NAME = 10;
|
||||
public static final int ATTRIBUTE_NAME = 11;
|
||||
|
||||
protected boolean _hasInitialReadOnlyVocabulary;
|
||||
|
||||
protected String _referencedVocabularyURI;
|
||||
|
||||
public boolean hasInitialVocabulary() {
|
||||
return _hasInitialReadOnlyVocabulary;
|
||||
}
|
||||
|
||||
protected void setInitialReadOnlyVocabulary(boolean hasInitialReadOnlyVocabulary) {
|
||||
_hasInitialReadOnlyVocabulary = hasInitialReadOnlyVocabulary;
|
||||
}
|
||||
|
||||
public boolean hasExternalVocabulary() {
|
||||
return _referencedVocabularyURI != null;
|
||||
}
|
||||
|
||||
public String getExternalVocabularyURI() {
|
||||
return _referencedVocabularyURI;
|
||||
}
|
||||
|
||||
protected void setExternalVocabularyURI(String referencedVocabularyURI) {
|
||||
_referencedVocabularyURI = referencedVocabularyURI;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user