Source Home >> Java Source 1.6.0 >> javax.xml.transform.stream.StreamResult V 0.09
  • 001/*
  • 002 * The contents of this file are subject to the terms
  • 003 * of the Common Development and Distribution License
  • 004 * (the "License"). You may not use this file except
  • 005 * in compliance with the License.
  • 006 *
  • 007 * You can obtain a copy of the license at
  • 008 * https://jaxp.dev.java.net/CDDLv1.0.html.
  • 009 * See the License for the specific language governing
  • 010 * permissions and limitations under the License.
  • 011 *
  • 012 * When distributing Covered Code, include this CDDL
  • 013 * HEADER in each file and include the License file at
  • 014 * https://jaxp.dev.java.net/CDDLv1.0.html
  • 015 * If applicable add the following below this CDDL HEADER
  • 016 * with the fields enclosed by brackets "[]" replaced with
  • 017 * your own identifying information: Portions Copyright
  • 018 * [year] [name of copyright owner]
  • 019 */
  • 020
  • 021/*
  • 022 * $Id: StreamResult.java,v 1.4 2005/11/03 19:34:27 jeffsuttor Exp $
  • 023 * @(#)StreamResult.java 1.24 05/11/30
  • 024 *
  • 025 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
  • 026 */
  • 027
  • 028package javax.xml.transform.stream;
  • 029
  • 030import javax.xml.transform.Result;
  • 031
  • 032import java.io.File;
  • 033import java.io.OutputStream;
  • 034import java.io.Writer;
  • 035import java.net.MalformedURLException;
  • 036
  • 037/**
  • 038 * <p>Acts as an holder for a transformation result,
  • 039 * which may be XML, plain Text, HTML, or some other form of markup.</p>
  • 040 *
  • 041 * @author <a href="Jeff.Suttor@Sun.com">Jeff Suttor</a>
  • 042 */
  • 043public class StreamResult implements Result {
  • 044
  • 045 /** If {@link javax.xml.transform.TransformerFactory#getFeature}
  • 046 * returns true when passed this value as an argument,
  • 047 * the Transformer supports Result output of this type.
  • 048 */
  • 049 public static final String FEATURE =
  • 050 "http://javax.xml.transform.stream.StreamResult/feature";
  • 051
  • 052 /**
  • 053 * Zero-argument default constructor.
  • 054 */
  • 055 public StreamResult() {
  • 056 }
  • 057
  • 058 /**
  • 059 * Construct a StreamResult from a byte stream. Normally,
  • 060 * a stream should be used rather than a reader, so that
  • 061 * the transformer may use instructions contained in the
  • 062 * transformation instructions to control the encoding.
  • 063 *
  • 064 * @param outputStream A valid OutputStream reference.
  • 065 */
  • 066 public StreamResult(OutputStream outputStream) {
  • 067 setOutputStream(outputStream);
  • 068 }
  • 069
  • 070 /**
  • 071 * Construct a StreamResult from a character stream. Normally,
  • 072 * a stream should be used rather than a reader, so that
  • 073 * the transformer may use instructions contained in the
  • 074 * transformation instructions to control the encoding. However,
  • 075 * there are times when it is useful to write to a character
  • 076 * stream, such as when using a StringWriter.
  • 077 *
  • 078 * @param writer A valid Writer reference.
  • 079 */
  • 080 public StreamResult(Writer writer) {
  • 081 setWriter(writer);
  • 082 }
  • 083
  • 084 /**
  • 085 * Construct a StreamResult from a URL.
  • 086 *
  • 087 * @param systemId Must be a String that conforms to the URI syntax.
  • 088 */
  • 089 public StreamResult(String systemId) {
  • 090 this.systemId = systemId;
  • 091 }
  • 092
  • 093 /**
  • 094 * Construct a StreamResult from a File.
  • 095 *
  • 096 * @param f Must a non-null File reference.
  • 097 */
  • 098 public StreamResult(File f) {
  • 099 //convert file to appropriate URI, f.toURI().toASCIIString()
  • 100 //converts the URI to string as per rule specified in
  • 101 //RFC 2396,
  • 102 setSystemId(f.toURI().toASCIIString());
  • 103 }
  • 104
  • 105 /**
  • 106 * Set the ByteStream that is to be written to. Normally,
  • 107 * a stream should be used rather than a reader, so that
  • 108 * the transformer may use instructions contained in the
  • 109 * transformation instructions to control the encoding.
  • 110 *
  • 111 * @param outputStream A valid OutputStream reference.
  • 112 */
  • 113 public void setOutputStream(OutputStream outputStream) {
  • 114 this.outputStream = outputStream;
  • 115 }
  • 116
  • 117 /**
  • 118 * Get the byte stream that was set with setOutputStream.
  • 119 *
  • 120 * @return The byte stream that was set with setOutputStream, or null
  • 121 * if setOutputStream or the ByteStream constructor was not called.
  • 122 */
  • 123 public OutputStream getOutputStream() {
  • 124 return outputStream;
  • 125 }
  • 126
  • 127 /**
  • 128 * Set the writer that is to receive the result. Normally,
  • 129 * a stream should be used rather than a writer, so that
  • 130 * the transformer may use instructions contained in the
  • 131 * transformation instructions to control the encoding. However,
  • 132 * there are times when it is useful to write to a writer,
  • 133 * such as when using a StringWriter.
  • 134 *
  • 135 * @param writer A valid Writer reference.
  • 136 */
  • 137 public void setWriter(Writer writer) {
  • 138 this.writer = writer;
  • 139 }
  • 140
  • 141 /**
  • 142 * Get the character stream that was set with setWriter.
  • 143 *
  • 144 * @return The character stream that was set with setWriter, or null
  • 145 * if setWriter or the Writer constructor was not called.
  • 146 */
  • 147 public Writer getWriter() {
  • 148 return writer;
  • 149 }
  • 150
  • 151 /**
  • 152 * Set the systemID that may be used in association
  • 153 * with the byte or character stream, or, if neither is set, use
  • 154 * this value as a writeable URI (probably a file name).
  • 155 *
  • 156 * @param systemId The system identifier as a URI string.
  • 157 */
  • 158 public void setSystemId(String systemId) {
  • 159 this.systemId = systemId;
  • 160 }
  • 161
  • 162 /**
  • 163 * <p>Set the system ID from a <code>File</code> reference.</p>
  • 164 *
  • 165 *
  • 166 * @param f Must a non-null File reference.
  • 167 */
  • 168 public void setSystemId(File f) {
  • 169 //convert file to appropriate URI, f.toURI().toASCIIString()
  • 170 //converts the URI to string as per rule specified in
  • 171 //RFC 2396,
  • 172 this.systemId = f.toURI().toASCIIString();
  • 173 }
  • 174
  • 175 /**
  • 176 * Get the system identifier that was set with setSystemId.
  • 177 *
  • 178 * @return The system identifier that was set with setSystemId, or null
  • 179 * if setSystemId was not called.
  • 180 */
  • 181 public String getSystemId() {
  • 182 return systemId;
  • 183 }
  • 184
  • 185 //////////////////////////////////////////////////////////////////////
  • 186 // Internal state.
  • 187 //////////////////////////////////////////////////////////////////////
  • 188
  • 189 /**
  • 190 * The systemID that may be used in association
  • 191 * with the byte or character stream, or, if neither is set, use
  • 192 * this value as a writeable URI (probably a file name).
  • 193 */
  • 194 private String systemId;
  • 195
  • 196 /**
  • 197 * The byte stream that is to be written to.
  • 198 */
  • 199 private OutputStream outputStream;
  • 200
  • 201 /**
  • 202 * The character stream that is to be written to.
  • 203 */
  • 204 private Writer writer;
  • 205}

文件:StreamResult.java
包名:javax.xml.transform.stream
类名:StreamResult
继承:
接口:[Result]