jaxp/src/share/classes/javax/xml/stream/XMLOutputFactory.java
changeset 6 7f561c08de6b
equal deleted inserted replaced
0:fd16c54261b3 6:7f561c08de6b
       
     1 /*
       
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     3  *
       
     4  * This code is free software; you can redistribute it and/or modify it
       
     5  * under the terms of the GNU General Public License version 2 only, as
       
     6  * published by the Free Software Foundation.  Sun designates this
       
     7  * particular file as subject to the "Classpath" exception as provided
       
     8  * by Sun in the LICENSE file that accompanied this code.
       
     9  *
       
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    13  * version 2 for more details (a copy is included in the LICENSE file that
       
    14  * accompanied this code).
       
    15  *
       
    16  * You should have received a copy of the GNU General Public License version
       
    17  * 2 along with this work; if not, write to the Free Software Foundation,
       
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    19  *
       
    20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    21  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    22  * have any questions.
       
    23  */
       
    24 
       
    25 /*
       
    26  * Copyright (c) 2003 by BEA Systems, Inc. All Rights Reserved.
       
    27  */
       
    28 
       
    29 package javax.xml.stream;
       
    30 
       
    31 import javax.xml.transform.Result;
       
    32 
       
    33 /**
       
    34  * Defines an abstract implementation of a factory for
       
    35  * getting XMLEventWriters and XMLStreamWriters.
       
    36  *
       
    37  * The following table defines the standard properties of this specification.
       
    38  * Each property varies in the level of support required by each implementation.
       
    39  * The level of support required is described in the 'Required' column.
       
    40  *
       
    41  *     <table border="2" rules="all" cellpadding="4">
       
    42  *     <thead>
       
    43  *      <tr>
       
    44  *        <th align="center" colspan="2">
       
    45  *          Configuration parameters
       
    46  *        </th>
       
    47  *      </tr>
       
    48  *    </thead>
       
    49  *    <tbody>
       
    50  *      <tr>
       
    51  *        <th>Property Name</th>
       
    52  *        <th>Behavior</th>
       
    53  *        <th>Return type</th>
       
    54  *        <th>Default Value</th>
       
    55  *        <th>Required</th>
       
    56  *              </tr>
       
    57  *         <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>
       
    58  *      </tbody>
       
    59  *   </table>
       
    60  *
       
    61  * <p>The following paragraphs describe the namespace and prefix repair algorithm:</p>
       
    62  *
       
    63  * <p>The property can be set with the following code line:
       
    64  * <code>setProperty("javax.xml.stream.isRepairingNamespaces",new Boolean(true|false));</code></p>
       
    65  *
       
    66  * <p>This property specifies that the writer default namespace prefix declarations.
       
    67  * The default value is false. </p>
       
    68  *
       
    69  * <p>If a writer isRepairingNamespaces it will create a namespace declaration
       
    70  * on the current StartElement for
       
    71  * any attribute that does not
       
    72  * currently have a namespace declaration in scope.  If the StartElement
       
    73  * has a uri but no prefix specified a prefix will be assigned, if the prefix
       
    74  * has not been declared in a parent of the current StartElement it will be declared
       
    75  * on the current StartElement.  If the defaultNamespace is bound and in scope
       
    76  * and the default namespace matches the URI of the attribute or StartElement
       
    77  * QName no prefix will be assigned.</p>
       
    78  *
       
    79  * <p>If an element or attribute name has a prefix, but is not
       
    80  * bound to any namespace URI, then the prefix will be removed
       
    81  * during serialization.</p>
       
    82  *
       
    83  * <p>If element and/or attribute names in the same start or
       
    84  * empty-element tag are bound to different namespace URIs and
       
    85  * are using the same prefix then the element or the first
       
    86  * occurring attribute retains the original prefix and the
       
    87  * following attributes have their prefixes replaced with a
       
    88  * new prefix that is bound to the namespace URIs of those
       
    89  * attributes. </p>
       
    90  *
       
    91  * <p>If an element or attribute name uses a prefix that is
       
    92  * bound to a different URI than that inherited from the
       
    93  * namespace context of the parent of that element and there
       
    94  * is no namespace declaration in the context of the current
       
    95  * element then such a namespace declaration is added. </p>
       
    96  *
       
    97  * <p>If an element or attribute name is bound to a prefix and
       
    98  * there is a namespace declaration that binds that prefix
       
    99  * to a different URI then that namespace declaration is
       
   100  * either removed if the correct mapping is inherited from
       
   101  * the parent context of that element, or changed to the
       
   102  * namespace URI of the element or attribute using that prefix.</p>
       
   103  *
       
   104  * @author Copyright (c) 2003 by BEA Systems. All Rights Reserved.
       
   105  * @see XMLInputFactory
       
   106  * @see XMLEventWriter
       
   107  * @see XMLStreamWriter
       
   108  * @since 1.6
       
   109  */
       
   110 public abstract class XMLOutputFactory {
       
   111   /**
       
   112    * Property used to set prefix defaulting on the output side
       
   113    */
       
   114   public static final String IS_REPAIRING_NAMESPACES=
       
   115     "javax.xml.stream.isRepairingNamespaces";
       
   116 
       
   117   protected XMLOutputFactory(){}
       
   118 
       
   119   /**
       
   120    * Create a new instance of the factory.
       
   121    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
       
   122    */
       
   123   public static XMLOutputFactory newInstance()
       
   124     throws FactoryConfigurationError
       
   125   {
       
   126     return (XMLOutputFactory) FactoryFinder.find("javax.xml.stream.XMLOutputFactory",
       
   127                                                  "com.sun.xml.internal.stream.XMLOutputFactoryImpl");
       
   128   }
       
   129 
       
   130   /**
       
   131    * Create a new instance of the factory.
       
   132    *
       
   133    * @param factoryId             Name of the factory to find, same as
       
   134    *                              a property name
       
   135    * @param classLoader           classLoader to use
       
   136    * @return the factory implementation
       
   137    * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
       
   138    */
       
   139   public static XMLInputFactory newInstance(String factoryId,
       
   140           ClassLoader classLoader)
       
   141           throws FactoryConfigurationError {
       
   142       try {
       
   143           //do not fallback if given classloader can't find the class, throw exception
       
   144           return (XMLInputFactory) FactoryFinder.newInstance(factoryId, classLoader, false);
       
   145       } catch (FactoryFinder.ConfigurationError e) {
       
   146           throw new FactoryConfigurationError(e.getException(),
       
   147                   e.getMessage());
       
   148       }
       
   149   }
       
   150 
       
   151   /**
       
   152    * Create a new XMLStreamWriter that writes to a writer
       
   153    * @param stream the writer to write to
       
   154    * @throws XMLStreamException
       
   155    */
       
   156   public abstract XMLStreamWriter createXMLStreamWriter(java.io.Writer stream) throws XMLStreamException;
       
   157 
       
   158   /**
       
   159    * Create a new XMLStreamWriter that writes to a stream
       
   160    * @param stream the stream to write to
       
   161    * @throws XMLStreamException
       
   162    */
       
   163   public abstract XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream) throws XMLStreamException;
       
   164 
       
   165   /**
       
   166    * Create a new XMLStreamWriter that writes to a stream
       
   167    * @param stream the stream to write to
       
   168    * @param encoding the encoding to use
       
   169    * @throws XMLStreamException
       
   170    */
       
   171   public abstract XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream,
       
   172                                          String encoding) throws XMLStreamException;
       
   173 
       
   174   /**
       
   175    * Create a new XMLStreamWriter that writes to a JAXP result.  This method is optional.
       
   176    * @param result the result to write to
       
   177    * @throws UnsupportedOperationException if this method is not
       
   178    * supported by this XMLOutputFactory
       
   179    * @throws XMLStreamException
       
   180    */
       
   181   public abstract XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException;
       
   182 
       
   183 
       
   184   /**
       
   185    * Create a new XMLEventWriter that writes to a JAXP result.  This method is optional.
       
   186    * @param result the result to write to
       
   187    * @throws UnsupportedOperationException if this method is not
       
   188    * supported by this XMLOutputFactory
       
   189    * @throws XMLStreamException
       
   190    */
       
   191   public abstract XMLEventWriter createXMLEventWriter(Result result) throws XMLStreamException;
       
   192 
       
   193   /**
       
   194    * Create a new XMLEventWriter that writes to a stream
       
   195    * @param stream the stream to write to
       
   196    * @throws XMLStreamException
       
   197    */
       
   198   public abstract XMLEventWriter createXMLEventWriter(java.io.OutputStream stream) throws XMLStreamException;
       
   199 
       
   200 
       
   201 
       
   202   /**
       
   203    * Create a new XMLEventWriter that writes to a stream
       
   204    * @param stream the stream to write to
       
   205    * @param encoding the encoding to use
       
   206    * @throws XMLStreamException
       
   207    */
       
   208   public abstract XMLEventWriter createXMLEventWriter(java.io.OutputStream stream,
       
   209                                                      String encoding) throws XMLStreamException;
       
   210 
       
   211   /**
       
   212    * Create a new XMLEventWriter that writes to a writer
       
   213    * @param stream the stream to write to
       
   214    * @throws XMLStreamException
       
   215    */
       
   216   public abstract XMLEventWriter createXMLEventWriter(java.io.Writer stream) throws XMLStreamException;
       
   217 
       
   218   /**
       
   219    * Allows the user to set specific features/properties on the underlying implementation.
       
   220    * @param name The name of the property
       
   221    * @param value The value of the property
       
   222    * @throws java.lang.IllegalArgumentException if the property is not supported
       
   223    */
       
   224   public abstract void setProperty(java.lang.String name,
       
   225                                     Object value)
       
   226     throws IllegalArgumentException;
       
   227 
       
   228   /**
       
   229    * Get a feature/property on the underlying implementation
       
   230    * @param name The name of the property
       
   231    * @return The value of the property
       
   232    * @throws java.lang.IllegalArgumentException if the property is not supported
       
   233    */
       
   234   public abstract Object getProperty(java.lang.String name)
       
   235     throws IllegalArgumentException;
       
   236 
       
   237   /**
       
   238    * Query the set of properties that this factory supports.
       
   239    *
       
   240    * @param name The name of the property (may not be null)
       
   241    * @return true if the property is supported and false otherwise
       
   242    */
       
   243   public abstract boolean isPropertySupported(String name);
       
   244 }