47 import java.util.Random;
48 import java.util.Set;
49 import javax.xml.XMLConstants;
50 import javax.xml.namespace.NamespaceContext;
51 import javax.xml.stream.XMLOutputFactory;
52 import javax.xml.stream.XMLStreamConstants;
53 import javax.xml.stream.XMLStreamException;
54 import javax.xml.transform.stream.StreamResult;
55 import jdk.xml.internal.SecuritySupport;
56
57 /**
58 * This class implements a StAX XMLStreamWriter. It extends
59 * <code>AbstractMap</code> in order to support a getter for
60 * implementation-specific properties. For example, you can get
61 * the underlying <code>OutputStream</code> by casting an instance
62 * of this class to <code>Map</code> and calling
63 * <code>getProperty(OUTPUTSTREAM_PROPERTY)</code>.
64 *
65 * @author Neeraj Bajaj
66 * @author K.Venugopal
67 * @author Santiago.Pericas-Geertsen@sun.com
68 * @author Sunitha.Reddy@sun.com
69 */
70 public final class XMLStreamWriterImpl extends AbstractMap<Object, Object>
71 implements XMLStreamWriterBase {
72
73 public static final String START_COMMENT = "<!--";
74 public static final String END_COMMENT = "-->";
75 public static final String DEFAULT_ENCODING = " encoding=\"utf-8\"";
76 public static final String DEFAULT_XMLDECL = "<?xml version=\"1.0\" ?>";
77 public static final String DEFAULT_XML_VERSION = "1.0";
78 public static final char CLOSE_START_TAG = '>';
79 public static final char OPEN_START_TAG = '<';
80 public static final String OPEN_END_TAG = "</";
81 public static final char CLOSE_END_TAG = '>';
82 public static final String START_CDATA = "<![CDATA[";
83 public static final String END_CDATA = "]]>";
84 public static final String CLOSE_EMPTY_ELEMENT = "/>";
85 public static final String SPACE = " ";
86 public static final String UTF_8 = "UTF-8";
87
88 public static final String OUTPUTSTREAM_PROPERTY = "sjsxp-outputstream";
2024 * the specified QName.
2025 * <p>
2026 * <strong>Note:</strong> The object returned is <em>not</em>
2027 * orphaned to the caller. Therefore, the caller should consider
2028 * the object to be read-only.
2029 */
2030 public ElementState pop() {
2031 return fElements[--fDepth];
2032 }
2033
2034 /** Clears the stack without throwing away existing QName objects. */
2035 public void clear() {
2036 fDepth = 0;
2037 }
2038
2039 /**
2040 * This function is as a result of optimization done for endElement --
2041 * we dont need to set the value for every end element we encouter.
2042 * For Well formedness checks we can have the same QName object that was pushed.
2043 * the values will be set only if application need to know about the endElement
2044 * -- neeraj.bajaj@sun.com
2045 */
2046 public ElementState peek() {
2047 return fElements[fDepth - 1];
2048 }
2049
2050 /**
2051 *
2052 * @return
2053 */
2054 public boolean empty() {
2055 return (fDepth > 0) ? false : true;
2056 }
2057 }
2058
2059 /**
2060 * Maintains element state . localName for now.
2061 */
2062 class ElementState extends QName {
2063 public boolean isEmpty = false;
2064
|
47 import java.util.Random;
48 import java.util.Set;
49 import javax.xml.XMLConstants;
50 import javax.xml.namespace.NamespaceContext;
51 import javax.xml.stream.XMLOutputFactory;
52 import javax.xml.stream.XMLStreamConstants;
53 import javax.xml.stream.XMLStreamException;
54 import javax.xml.transform.stream.StreamResult;
55 import jdk.xml.internal.SecuritySupport;
56
57 /**
58 * This class implements a StAX XMLStreamWriter. It extends
59 * <code>AbstractMap</code> in order to support a getter for
60 * implementation-specific properties. For example, you can get
61 * the underlying <code>OutputStream</code> by casting an instance
62 * of this class to <code>Map</code> and calling
63 * <code>getProperty(OUTPUTSTREAM_PROPERTY)</code>.
64 *
65 * @author Neeraj Bajaj
66 * @author K.Venugopal
67 * @author Santiago Pericas-Geertsen
68 * @author Sunitha Reddy
69 */
70 public final class XMLStreamWriterImpl extends AbstractMap<Object, Object>
71 implements XMLStreamWriterBase {
72
73 public static final String START_COMMENT = "<!--";
74 public static final String END_COMMENT = "-->";
75 public static final String DEFAULT_ENCODING = " encoding=\"utf-8\"";
76 public static final String DEFAULT_XMLDECL = "<?xml version=\"1.0\" ?>";
77 public static final String DEFAULT_XML_VERSION = "1.0";
78 public static final char CLOSE_START_TAG = '>';
79 public static final char OPEN_START_TAG = '<';
80 public static final String OPEN_END_TAG = "</";
81 public static final char CLOSE_END_TAG = '>';
82 public static final String START_CDATA = "<![CDATA[";
83 public static final String END_CDATA = "]]>";
84 public static final String CLOSE_EMPTY_ELEMENT = "/>";
85 public static final String SPACE = " ";
86 public static final String UTF_8 = "UTF-8";
87
88 public static final String OUTPUTSTREAM_PROPERTY = "sjsxp-outputstream";
2024 * the specified QName.
2025 * <p>
2026 * <strong>Note:</strong> The object returned is <em>not</em>
2027 * orphaned to the caller. Therefore, the caller should consider
2028 * the object to be read-only.
2029 */
2030 public ElementState pop() {
2031 return fElements[--fDepth];
2032 }
2033
2034 /** Clears the stack without throwing away existing QName objects. */
2035 public void clear() {
2036 fDepth = 0;
2037 }
2038
2039 /**
2040 * This function is as a result of optimization done for endElement --
2041 * we dont need to set the value for every end element we encouter.
2042 * For Well formedness checks we can have the same QName object that was pushed.
2043 * the values will be set only if application need to know about the endElement
2044 */
2045 public ElementState peek() {
2046 return fElements[fDepth - 1];
2047 }
2048
2049 /**
2050 *
2051 * @return
2052 */
2053 public boolean empty() {
2054 return (fDepth > 0) ? false : true;
2055 }
2056 }
2057
2058 /**
2059 * Maintains element state . localName for now.
2060 */
2061 class ElementState extends QName {
2062 public boolean isEmpty = false;
2063
|