001 package javax.xml.stream;
002
003 import javax.xml.transform.Result;
004
005 /**
006 * Defines an abstract implementation of a factory for
007 * getting XMLEventWriters and XMLStreamWriters.
008 *
009 * The following table defines the standard properties of this specification.
010 * Each property varies in the level of support required by each implementation.
011 * The level of support required is described in the 'Required' column.
012 *
013 * <table border="2" rules="all" cellpadding="4">
014 * <thead>
015 * <tr>
016 * <th align="center" colspan="2">
017 * Configuration parameters
018 * </th>
019 * </tr>
020 * </thead>
021 * <tbody>
022 * <tr>
023 * <th>Property Name</th>
024 * <th>Behavior</th>
025 * <th>Return type</th>
026 * <th>Default Value</th>
027 * <th>Required</th>
028 * </tr>
029 * <tr><td>javax.xml.stream.isRepairingNamespaces</td><td>defaults prefixes on the output side</td><td>Boolean</td><td>False</td><td>Yes</td></tr>
030 * </tbody>
031 * </table>
032 *
033 * <p>The following paragraphs describe the namespace and prefix repair algorithm:</p>
034 *
035 * <p>The property can be set with the following code line:
036 * <code>setProperty("javax.xml.stream.isRepairingNamespaces",new Boolean(true|false));</code></p>
037 *
038 * <p>This property specifies that the writer default namespace prefix declarations.
039 * The default value is false. </p>
040 *
041 * <p>If a writer isRepairingNamespaces it will create a namespace declaration
042 * on the current StartElement for
043 * any attribute that does not
044 * currently have a namespace declaration in scope. If the StartElement
045 * has a uri but no prefix specified a prefix will be assigned, if the prefix
046 * has not been declared in a parent of the current StartElement it will be declared
047 * on the current StartElement. If the defaultNamespace is bound and in scope
048 * and the default namespace matches the URI of the attribute or StartElement
049 * QName no prefix will be assigned.</p>
050 *
051 * <p>If an element or attribute name has a prefix, but is not
052 * bound to any namespace URI, then the prefix will be removed
053 * during serialization.</p>
054 *
055 * <p>If element and/or attribute names in the same start or
056 * empty-element tag are bound to different namespace URIs and
057 * are using the same prefix then the element or the first
058 * occurring attribute retains the original prefix and the
059 * following attributes have their prefixes replaced with a
060 * new prefix that is bound to the namespace URIs of those
061 * attributes. </p>
062 *
063 * <p>If an element or attribute name uses a prefix that is
064 * bound to a different URI than that inherited from the
065 * namespace context of the parent of that element and there
066 * is no namespace declaration in the context of the current
067 * element then such a namespace declaration is added. </p>
068 *
069 * <p>If an element or attribute name is bound to a prefix and
070 * there is a namespace declaration that binds that prefix
071 * to a different URI then that namespace declaration is
072 * either removed if the correct mapping is inherited from
073 * the parent context of that element, or changed to the
074 * namespace URI of the element or attribute using that prefix.</p>
075 *
076 * @version 1.0
077 * @author Copyright (c) 2003 by BEA Systems. All Rights Reserved.
078 * @see XMLInputFactory
079 * @see XMLEventWriter
080 * @see XMLStreamWriter
081 * @since 1.6
082 */
083 public abstract class XMLOutputFactory {
084 /**
085 * Property used to set prefix defaulting on the output side
086 */
087 public static final String IS_REPAIRING_NAMESPACES = "javax.xml.stream.isRepairingNamespaces";
088
089 protected XMLOutputFactory() {
090 }
091
092 /**
093 * Create a new instance of the factory.
094 * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
095 */
096 public static XMLOutputFactory newInstance()
097 throws FactoryConfigurationError {
098 return (XMLOutputFactory) FactoryFinder.find(
099 "javax.xml.stream.XMLOutputFactory",
100 "com.sun.xml.internal.stream.XMLOutputFactoryImpl");
101 }
102
103 /**
104 * Create a new instance of the factory.
105 *
106 * @param factoryId Name of the factory to find, same as
107 * a property name
108 * @param classLoader classLoader to use
109 * @return the factory implementation
110 * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
111 */
112 public static XMLInputFactory newInstance(String factoryId,
113 ClassLoader classLoader) throws FactoryConfigurationError {
114 try {
115 //do not fallback if given classloader can't find the class, throw exception
116 return (XMLInputFactory) FactoryFinder.newInstance(
117 factoryId, classLoader, false);
118 } catch (FactoryFinder.ConfigurationError e) {
119 throw new FactoryConfigurationError(e.getException(), e
120 .getMessage());
121 }
122 }
123
124 /**
125 * Create a new XMLStreamWriter that writes to a writer
126 * @param stream the writer to write to
127 * @throws XMLStreamException
128 */
129 public abstract XMLStreamWriter createXMLStreamWriter(
130 java.io.Writer stream) throws XMLStreamException;
131
132 /**
133 * Create a new XMLStreamWriter that writes to a stream
134 * @param stream the stream to write to
135 * @throws XMLStreamException
136 */
137 public abstract XMLStreamWriter createXMLStreamWriter(
138 java.io.OutputStream stream) throws XMLStreamException;
139
140 /**
141 * Create a new XMLStreamWriter that writes to a stream
142 * @param stream the stream to write to
143 * @param encoding the encoding to use
144 * @throws XMLStreamException
145 */
146 public abstract XMLStreamWriter createXMLStreamWriter(
147 java.io.OutputStream stream, String encoding)
148 throws XMLStreamException;
149
150 /**
151 * Create a new XMLStreamWriter that writes to a JAXP result. This method is optional.
152 * @param result the result to write to
153 * @throws UnsupportedOperationException if this method is not
154 * supported by this XMLOutputFactory
155 * @throws XMLStreamException
156 */
157 public abstract XMLStreamWriter createXMLStreamWriter(Result result)
158 throws XMLStreamException;
159
160 /**
161 * Create a new XMLEventWriter that writes to a JAXP result. This method is optional.
162 * @param result the result to write to
163 * @throws UnsupportedOperationException if this method is not
164 * supported by this XMLOutputFactory
165 * @throws XMLStreamException
166 */
167 public abstract XMLEventWriter createXMLEventWriter(Result result)
168 throws XMLStreamException;
169
170 /**
171 * Create a new XMLEventWriter that writes to a stream
172 * @param stream the stream to write to
173 * @throws XMLStreamException
174 */
175 public abstract XMLEventWriter createXMLEventWriter(
176 java.io.OutputStream stream) throws XMLStreamException;
177
178 /**
179 * Create a new XMLEventWriter that writes to a stream
180 * @param stream the stream to write to
181 * @param encoding the encoding to use
182 * @throws XMLStreamException
183 */
184 public abstract XMLEventWriter createXMLEventWriter(
185 java.io.OutputStream stream, String encoding)
186 throws XMLStreamException;
187
188 /**
189 * Create a new XMLEventWriter that writes to a writer
190 * @param stream the stream to write to
191 * @throws XMLStreamException
192 */
193 public abstract XMLEventWriter createXMLEventWriter(
194 java.io.Writer stream) throws XMLStreamException;
195
196 /**
197 * Allows the user to set specific features/properties on the underlying implementation.
198 * @param name The name of the property
199 * @param value The value of the property
200 * @throws java.lang.IllegalArgumentException if the property is not supported
201 */
202 public abstract void setProperty(java.lang.String name, Object value)
203 throws IllegalArgumentException;
204
205 /**
206 * Get a feature/property on the underlying implementation
207 * @param name The name of the property
208 * @return The value of the property
209 * @throws java.lang.IllegalArgumentException if the property is not supported
210 */
211 public abstract Object getProperty(java.lang.String name)
212 throws IllegalArgumentException;
213
214 /**
215 * Query the set of properties that this factory supports.
216 *
217 * @param name The name of the property (may not be null)
218 * @return true if the property is supported and false otherwise
219 */
220 public abstract boolean isPropertySupported(String name);
221 }
|