XML11OutputFactory.java
001 /*
002  *  XML11OutputFactory.java
003  *
004  *  Copyright (c) 1995-2015, The University of Sheffield. See the file
005  *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
006  *
007  *  This file is part of GATE (see http://gate.ac.uk/), and is free
008  *  software, licenced under the GNU Library General Public License,
009  *  Version 2, June 1991 (in the distribution as file licence.html,
010  *  and also available at http://gate.ac.uk/gate/licence.html).
011  *
012  *  Ian Roberts, 04/Jun/2015
013  *
014  *  $Id: XML11OutputFactory.java 18753 2015-06-04 13:20:25Z ian_roberts $
015  */
016 package gate.util.xml;
017 
018 import java.io.OutputStream;
019 import java.io.Writer;
020 
021 import javax.xml.stream.XMLEventWriter;
022 import javax.xml.stream.XMLOutputFactory;
023 import javax.xml.stream.XMLStreamException;
024 import javax.xml.stream.XMLStreamWriter;
025 import javax.xml.transform.Result;
026 
027 /**
028  * Simple delegating XMLOutputFactory that produces stream writers whose
029  <code>startDocument()</code> method delegates to
030  <code>startDocument("1.1")</code>, thus producing XML 1.1 instead of
031  * 1.0 by default.
032  */
033 public class XML11OutputFactory extends XMLOutputFactory {
034 
035   private XMLOutputFactory delegate;
036   
037   /**
038    * Create an output factory that generates stream writers that
039    * prefer XML 1.1 instead of 1.0 by default.  The underlying
040    * writers are created from the given delegate output factory.
041    */
042   public XML11OutputFactory(XMLOutputFactory delegate) {
043     this.delegate = delegate;
044   }
045 
046   /**
047    * Wrap the supplied writer in a wrapper that prefers XML 1.1 over 1.0
048    */
049   protected XMLStreamWriter wrap(XMLStreamWriter writer)
050           throws XMLStreamException {
051     return new XML11StreamWriter(writer);
052   }
053 
054   public XMLStreamWriter createXMLStreamWriter(Writer stream)
055           throws XMLStreamException {
056     return wrap(delegate.createXMLStreamWriter(stream));
057   }
058 
059   public XMLStreamWriter createXMLStreamWriter(OutputStream stream)
060           throws XMLStreamException {
061     return wrap(delegate.createXMLStreamWriter(stream));
062   }
063 
064   public XMLStreamWriter createXMLStreamWriter(OutputStream stream,
065           String encodingthrows XMLStreamException {
066     return wrap(delegate.createXMLStreamWriter(stream, encoding));
067   }
068 
069   public XMLStreamWriter createXMLStreamWriter(Result result)
070           throws XMLStreamException {
071     return wrap(delegate.createXMLStreamWriter(result));
072   }
073 
074   public XMLEventWriter createXMLEventWriter(Result result)
075           throws XMLStreamException {
076     return delegate.createXMLEventWriter(result);
077   }
078 
079   public XMLEventWriter createXMLEventWriter(OutputStream stream)
080           throws XMLStreamException {
081     return delegate.createXMLEventWriter(stream);
082   }
083 
084   public XMLEventWriter createXMLEventWriter(OutputStream stream,
085           String encodingthrows XMLStreamException {
086     return delegate.createXMLEventWriter(stream, encoding);
087   }
088 
089   public XMLEventWriter createXMLEventWriter(Writer stream)
090           throws XMLStreamException {
091     return delegate.createXMLEventWriter(stream);
092   }
093 
094   public void setProperty(String name, Object value)
095           throws IllegalArgumentException {
096     delegate.setProperty(name, value);
097   }
098 
099   public Object getProperty(String namethrows IllegalArgumentException {
100     return delegate.getProperty(name);
101   }
102 
103   public boolean isPropertySupported(String name) {
104     return delegate.isPropertySupported(name);
105   }
106 }