content: /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
   * obtain a copy of the License at
   * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
   * or packager/legal/LICENSE.txt.  See the License for the specific
   * language governing permissions and limitations under the License.
   *
   * When distributing the software, include this License Header Notice in each
   * file and include the License file at packager/legal/LICENSE.txt.
   *
   * GPL Classpath Exception:
   * Oracle designates this particular file as subject to the "Classpath"
   * exception as provided by Oracle in the GPL Version 2 section of the License
   * file that accompanied this code.
   *
   * Modifications:
   * If applicable, add the following below the License Header, with the fields
   * enclosed by brackets [] replaced by your own identifying information:
   * "Portions Copyright [year] [name of copyright owner]"
   *
   * Contributor(s):
   * If you wish your version of this file to be governed by only the CDDL or
   * only the GPL Version 2, indicate your decision by adding "[Contributor]
   * elects to include this software in this distribution under the [CDDL or GPL
   * Version 2] license."  If you don't indicate a single choice of license, a
   * recipient has the option to distribute your version of this file under
   * either the CDDL, the GPL Version 2 or to extend the choice of license to
   * its licensees as provided above.  However, if you add GPL Version 2 code
   * and therefore, elected the GPL Version 2 license, then the option applies
   * only if the new code is made subject to such option by the copyright
   * holder.
   */
  
  /*
   * $Id: StreamResult.java,v 1.7 2010-11-01 04:36:13 joehw Exp $
   * %W% %E%
   */
  package mf.javax.xml.transform.stream;
  
  import java.io.File;
  import java.io.OutputStream;
  import java.io.Writer;
  
  import mf.javax.xml.transform.Result;
  
  /**
   * <p>Acts as an holder for a transformation result,
   * which may be XML, plain Text, HTML, or some other form of markup.</p>
   *
   * @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
   */
  public class StreamResult implements Result {
  
      /**
       * If {@link javax.xml.transform.TransformerFactory#getFeature}
       * returns true when passed this value as an argument,
       * the Transformer supports Result output of this type.
       */
      public static final String FEATURE =
              "http://javax.xml.transform.stream.StreamResult/feature";
      /**
       * The systemID that may be used in association
       * with the byte or character stream, or, if neither is set, use
       * this value as a writeable URI (probably a file name).
       */
      private String systemId;
      /**
       * The byte stream that is to be written to.
       */
      private OutputStream outputStream;
      /**
       * The character stream that is to be written to.
       */
      private Writer writer;
  
      /**
       * Zero-argument default constructor.
       */
      public StreamResult() {
      }
  
      /**
       * Construct a StreamResult from a byte stream.  Normally,
       * a stream should be used rather than a reader, so that
       * the transformer may use instructions contained in the
       * transformation instructions to control the encoding.
       *
       * @param outputStream A valid OutputStream reference.
       */
      public StreamResult(OutputStream outputStream) {
          setOutputStream(outputStream);
      }
  
      /**
       * Construct a StreamResult from a character stream.  Normally,
       * a stream should be used rather than a reader, so that
       * the transformer may use instructions contained in the
       * transformation instructions to control the encoding.  However,
       * there are times when it is useful to write to a character
       * stream, such as when using a StringWriter.
       *
       * @param writer A valid Writer reference.
       */
      public StreamResult(Writer writer) {
          setWriter(writer);
      }
  
      /**
       * Construct a StreamResult from a URL.
       *
       * @param systemId Must be a String that conforms to the URI syntax.
       */
      public StreamResult(String systemId) {
          this.systemId = systemId;
      }
  
      /**
       * Construct a StreamResult from a File.
       *
       * @param f Must a non-null File reference.
       */
      public StreamResult(File f) {
          //convert file to appropriate URI, f.toURI().toASCIIString()
          //converts the URI to string as per rule specified in
          //RFC 2396,
          setSystemId(f.toURI().toASCIIString());
      }
  
      /**
       * Get the byte stream that was set with setOutputStream.
       *
       * @return The byte stream that was set with setOutputStream, or null
       * if setOutputStream or the ByteStream constructor was not called.
       */
      public OutputStream getOutputStream() {
          return outputStream;
      }
  
      /**
       * Set the ByteStream that is to be written to.  Normally,
       * a stream should be used rather than a reader, so that
       * the transformer may use instructions contained in the
       * transformation instructions to control the encoding.
       *
       * @param outputStream A valid OutputStream reference.
       */
      public void setOutputStream(OutputStream outputStream) {
          this.outputStream = outputStream;
      }
  
      /**
       * Get the character stream that was set with setWriter.
       *
       * @return The character stream that was set with setWriter, or null
       * if setWriter or the Writer constructor was not called.
       */
      public Writer getWriter() {
          return writer;
      }
  
      /**
       * Set the writer that is to receive the result.  Normally,
       * a stream should be used rather than a writer, so that
       * the transformer may use instructions contained in the
       * transformation instructions to control the encoding.  However,
       * there are times when it is useful to write to a writer,
       * such as when using a StringWriter.
       *
       * @param writer A valid Writer reference.
       */
      public void setWriter(Writer writer) {
          this.writer = writer;
      }
  
      //////////////////////////////////////////////////////////////////////
      // Internal state.
      //////////////////////////////////////////////////////////////////////
  
      /**
       * Set the systemID that may be used in association
       * with the byte or character stream, or, if neither is set, use
       * this value as a writeable URI (probably a file name).
       *
       * @param systemId The system identifier as a URI string.
       */
      @Override
      public void setSystemId(String systemId) {
          this.systemId = systemId;
      }
  
      /**
       * Get the system identifier that was set with setSystemId.
       *
       * @return The system identifier that was set with setSystemId, or null
       * if setSystemId was not called.
       */
      @Override
      public String getSystemId() {
          return systemId;
      }
  
      /**
       * <p>Set the system ID from a <code>File</code> reference.</p>
       *
       * @param f Must a non-null File reference.
       */
      public void setSystemId(File f) {
          //convert file to appropriate URI, f.toURI().toASCIIString()
          //converts the URI to string as per rule specified in
          //RFC 2396,
          this.systemId = f.toURI().toASCIIString();
      }
  }
  