axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/utils XMLUtils.java
Date Tue, 09 Jul 2002 19:45:24 GMT
dims        2002/07/09 12:45:24

  Modified:    java/src/org/apache/axis SOAPPart.java
               java/src/org/apache/axis/utils XMLUtils.java
  Added:       java/src/javax/xml/transform/dom DOMSource.java
               java/src/javax/xml/transform/sax SAXSource.java
               java/src/javax/xml/transform/stream StreamSource.java
  Log:
  Adding support for JAXP's DOMSource, StreamSource and SAXSource.
  
  Revision  Changes    Path
  1.1                  xml-axis/java/src/javax/xml/transform/dom/DOMSource.java
  
  Index: DOMSource.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The name "Apache Software Foundation" must not be used to endorse or
   *    promote products derived from this software without prior written
   *    permission. For written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package javax.xml.transform.dom;
  
  import javax.xml.transform.*;
  
  import java.lang.String;
  
  import java.io.OutputStream;
  import java.io.Writer;
  
  import org.w3c.dom.Node;
  
  
  /**
   * Acts as a holder for a transformation Source tree in the
   * form of a Document Object Model (DOM) tree.
   *
   * @see <a href="http://www.w3.org/TR/DOM-Level-2">Document Object Model (DOM) Level
2 Specification</a>
   */
  public class DOMSource implements Source {
  
      /** If {@link javax.xml.transform.TransformerFactory#getFeature}
       * returns true when passed this value as an argument,
       * the Transformer supports Source input of this type.
       */
      public static final String FEATURE =
          "http://javax.xml.transform.dom.DOMSource/feature";
  
      /**
       * Zero-argument default constructor.  If this is used, and
       * no DOM source is set, then the Transformer will
       * create an empty source Document using
       * {@link javax.xml.parsers.DocumentBuilder#newDocument}.
       */
      public DOMSource() {}
  
      /**
       * Create a new input source with a DOM node.  The operation
       * will be applied to the subtree rooted at this node.  In XSLT,
       * a "/" pattern still means the root of the tree (not the subtree),
       * and the evaluation of global variables and parameters is done
       * from the root node also.
       *
       * @param n The DOM node that will contain the Source tree.
       */
      public DOMSource(Node n) {
          setNode(n);
      }
  
      /**
       * Create a new input source with a DOM node, and with the
       * system ID also passed in as the base URI.
       *
       * @param node The DOM node that will contain the Source tree.
       * @param systemID Specifies the base URI associated with node.
       */
      public DOMSource(Node node, String systemID) {
          setNode(node);
          setSystemId(systemID);
      }
  
      /**
       * Set the node that will represents a Source DOM tree.
       *
       * @param node The node that is to be transformed.
       */
      public void setNode(Node node) {
          this.node = node;
      }
  
      /**
       * Get the node that represents a Source DOM tree.
       *
       * @return The node that is to be transformed.
       */
      public Node getNode() {
          return node;
      }
  
      /**
       * Set the base ID (URL or system ID) from where URLs
       * will be resolved.
       *
       * @param baseID Base URL for this DOM tree.
       */
      public void setSystemId(String baseID) {
          this.baseID = baseID;
      }
  
      /**
       * Get the base ID (URL or system ID) from where URLs
       * will be resolved.
       *
       * @return Base URL for this DOM tree.
       */
      public String getSystemId() {
          return this.baseID;
      }
  
      //////////////////////////////////////////////////////////////////////
      // Internal state.
      //////////////////////////////////////////////////////////////////////
  
      /**
       * Field node
       */
      private Node node;
  
      /**
       * The base ID (URL or system ID) from where URLs
       * will be resolved.
       */
      String baseID;
  }
  
  
  
  1.1                  xml-axis/java/src/javax/xml/transform/sax/SAXSource.java
  
  Index: SAXSource.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The name "Apache Software Foundation" must not be used to endorse or
   *    promote products derived from this software without prior written
   *    permission. For written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package javax.xml.transform.sax;
  
  import javax.xml.transform.Source;
  import javax.xml.transform.stream.StreamSource;
  
  import java.lang.String;
  
  import java.io.OutputStream;
  import java.io.Writer;
  
  import org.xml.sax.XMLReader;
  import org.xml.sax.ext.DeclHandler;
  import org.xml.sax.ext.LexicalHandler;
  import org.xml.sax.InputSource;
  
  
  /**
   * Acts as an holder for SAX-style Source.
   */
  public class SAXSource implements Source {
  
      /**
       * If {@link javax.xml.transform.TransformerFactory#getFeature}
       * returns true when passed this value as an argument,
       * the Transformer supports Source input of this type.
       */
      public static final String FEATURE =
          "http://javax.xml.transform.sax.SAXSource/feature";
  
      /**
       * Zero-argument default constructor.  If this constructor
       * is used, and no other method is called, the
       * {@link javax.xml.transform.Transformer}
       * assumes an empty input tree, with a default root node.
       */
      public SAXSource() {}
  
      /**
       * Create a <code>SAXSource</code>, using an {@link org.xml.sax.XMLReader}
       * and a SAX InputSource. The {@link javax.xml.transform.Transformer}
       * or {@link javax.xml.transform.sax.SAXTransformerFactory} will set itself
       * to be the reader's {@link org.xml.sax.ContentHandler}, and then will call
       * reader.parse(inputSource).
       *
       * @param reader An XMLReader to be used for the parse.
       * @param inputSource A SAX input source reference that must be non-null
       * and that will be passed to the reader parse method.
       */
      public SAXSource(XMLReader reader, InputSource inputSource) {
          this.reader      = reader;
          this.inputSource = inputSource;
      }
  
      /**
       * Create a <code>SAXSource</code>, using a SAX <code>InputSource</code>.
       * The {@link javax.xml.transform.Transformer} or
       * {@link javax.xml.transform.sax.SAXTransformerFactory} creates a
       * reader via {@link org.xml.sax.helpers.XMLReaderFactory}
       * (if setXMLReader is not used), sets itself as
       * the reader's {@link org.xml.sax.ContentHandler}, and calls
       * reader.parse(inputSource).
       *
       * @param inputSource An input source reference that must be non-null
       * and that will be passed to the parse method of the reader.
       */
      public SAXSource(InputSource inputSource) {
          this.inputSource = inputSource;
      }
  
      /**
       * Set the XMLReader to be used for the Source.
       *
       * @param reader A valid XMLReader or XMLFilter reference.
       */
      public void setXMLReader(XMLReader reader) {
          this.reader = reader;
      }
  
      /**
       * Get the XMLReader to be used for the Source.
       *
       * @return A valid XMLReader or XMLFilter reference, or null.
       */
      public XMLReader getXMLReader() {
          return reader;
      }
  
      /**
       * Set the SAX InputSource to be used for the Source.
       *
       * @param inputSource A valid InputSource reference.
       */
      public void setInputSource(InputSource inputSource) {
          this.inputSource = inputSource;
      }
  
      /**
       * Get the SAX InputSource to be used for the Source.
       *
       * @return A valid InputSource reference, or null.
       */
      public InputSource getInputSource() {
          return inputSource;
      }
  
      /**
       * Set the system identifier for this Source.  If an input source
       * has already been set, it will set the system ID or that
       * input source, otherwise it will create a new input source.
       *
       * <p>The system identifier is optional if there is a byte stream
       * or a character stream, but it is still useful to provide one,
       * since the application can use it to resolve relative URIs
       * and can include it in error messages and warnings (the parser
       * will attempt to open a connection to the URI only if
       * no byte stream or character stream is specified).</p>
       *
       * @param systemId The system identifier as a URI string.
       */
      public void setSystemId(String systemId) {
  
          if (null == inputSource) {
              inputSource = new InputSource(systemId);
          } else {
              inputSource.setSystemId(systemId);
          }
      }
  
      /**
       * Get the base ID (URI or system ID) from where URIs
       * will be resolved.
       *
       * @return Base URL for the Source, or null.
       */
      public String getSystemId() {
  
          return (null != inputSource)
                 ? inputSource.getSystemId()
                 : null;
      }
  
      /** The XMLReader to be used for the source tree input. May be null.        */
      private XMLReader reader;
  
      /** The SAX InputSource to be used for the source tree input.  Should not be null. */
      private InputSource inputSource;
  
      /**
       * Attempt to obtain a SAX InputSource object from a TrAX Source
       * object.
       *
       * @param source Must be a non-null Source reference.
       *
       * @return An InputSource, or null if Source can not be converted.
       */
      public static InputSource sourceToInputSource(Source source) {
  
          if (source instanceof SAXSource) {
              return ((SAXSource) source).getInputSource();
          } else if (source instanceof StreamSource) {
              StreamSource ss      = (StreamSource) source;
              InputSource  isource = new InputSource(ss.getSystemId());
  
              isource.setByteStream(ss.getInputStream());
              isource.setCharacterStream(ss.getReader());
              isource.setPublicId(ss.getPublicId());
  
              return isource;
          } else {
              return null;
          }
      }
  }
  
  
  
  
  1.36      +4 -1      xml-axis/java/src/org/apache/axis/SOAPPart.java
  
  Index: SOAPPart.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/SOAPPart.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- SOAPPart.java	9 Jul 2002 16:31:15 -0000	1.35
  +++ SOAPPart.java	9 Jul 2002 19:45:24 -0000	1.36
  @@ -568,7 +568,10 @@
        * @see #getContent() getContent()
        */
       public void setContent(Source source) throws SOAPException {
  -        InputSource in = org.apache.axis.utils.XMLUtils.getInputSourceFromURI(source.getSystemId());
  +        if(source == null)
  +            throw new SOAPException(JavaUtils.getMessage("illegalArgumentException00"));
  +
  +        InputSource in = org.apache.axis.utils.XMLUtils.sourceToInputSource(source);
           setCurrentMessage(in.getByteStream(), FORM_INPUTSTREAM);
       }
   
  
  
  
  1.1                  xml-axis/java/src/javax/xml/transform/stream/StreamSource.java
  
  Index: StreamSource.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The name "Apache Software Foundation" must not be used to endorse or
   *    promote products derived from this software without prior written
   *    permission. For written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package javax.xml.transform.stream;
  
  import javax.xml.transform.Source;
  
  import java.io.InputStream;
  import java.io.Reader;
  import java.io.File;
  
  
  /**
   * Acts as an holder for a transformation Source in the form
   * of a stream of XML markup.
   *
   */
  public class StreamSource implements Source {
  
      /** If {@link javax.xml.transform.TransformerFactory#getFeature}
       * returns true when passed this value as an argument,
       * the Transformer supports Source input of this type.
       */
      public static final String FEATURE =
          "http://javax.xml.transform.stream.StreamSource/feature";
  
      /**
       * Zero-argument default constructor. If this constructor
       * is used, and no other method is called, the transformer
       * will assume an empty input tree, with a default root node.
       */
      public StreamSource() {}
  
      /**
       * Construct a StreamSource from a byte stream.  Normally,
       * a stream should be used rather than a reader, so
       * the XML parser can resolve character encoding specified
       * by the XML declaration.
       *
       * <p>If this constructor is used to process a stylesheet, normally
       * setSystemId should also be called, so that relative URI references
       * can be resolved.</p>
       *
       * @param inputStream A valid InputStream reference to an XML stream.
       */
      public StreamSource(InputStream inputStream) {
          setInputStream(inputStream);
      }
  
      /**
       * Construct a StreamSource from a byte stream.  Normally,
       * a stream should be used rather than a reader, so that
       * the XML parser can resolve character encoding specified
       * by the XML declaration.
       *
       * <p>This constructor allows the systemID to be set in addition
       * to the input stream, which allows relative URIs
       * to be processed.</p>
       *
       * @param inputStream A valid InputStream reference to an XML stream.
       * @param systemId Must be a String that conforms to the URI syntax.
       */
      public StreamSource(InputStream inputStream, String systemId) {
          setInputStream(inputStream);
          setSystemId(systemId);
      }
  
      /**
       * Construct a StreamSource from a character reader.  Normally,
       * a stream should be used rather than a reader, so that
       * the XML parser can resolve character encoding specified
       * by the XML declaration.  However, in many cases the encoding
       * of the input stream is already resolved, as in the case of
       * reading XML from a StringReader.
       *
       * @param reader A valid Reader reference to an XML character stream.
       */
      public StreamSource(Reader reader) {
          setReader(reader);
      }
  
      /**
       * Construct a StreamSource from a character reader.  Normally,
       * a stream should be used rather than a reader, so that
       * the XML parser may resolve character encoding specified
       * by the XML declaration.  However, in many cases the encoding
       * of the input stream is already resolved, as in the case of
       * reading XML from a StringReader.
       *
       * @param reader A valid Reader reference to an XML character stream.
       * @param systemId Must be a String that conforms to the URI syntax.
       */
      public StreamSource(Reader reader, String systemId) {
          setReader(reader);
          setSystemId(systemId);
      }
  
      /**
       * Construct a StreamSource from a URL.
       *
       * @param systemId Must be a String that conforms to the URI syntax.
       */
      public StreamSource(String systemId) {
          this.systemId = systemId;
      }
  
      /**
       * Construct a StreamSource from a File.
       *
       * @param f Must a non-null File reference.
       */
      public StreamSource(File f) {
          setSystemId(f);
      }
  
      /**
       * Set the byte stream to be used as input.  Normally,
       * a stream should be used rather than a reader, so that
       * the XML parser can resolve character encoding specified
       * by the XML declaration.
       *
       * <p>If this Source object is used to process a stylesheet, normally
       * setSystemId should also be called, so that relative URL references
       * can be resolved.</p>
       *
       * @param inputStream A valid InputStream reference to an XML stream.
       */
      public void setInputStream(InputStream inputStream) {
          this.inputStream = inputStream;
      }
  
      /**
       * Get the byte stream that was set with setByteStream.
       *
       * @return The byte stream that was set with setByteStream, or null
       * if setByteStream or the ByteStream constructor was not called.
       */
      public InputStream getInputStream() {
          return inputStream;
      }
  
      /**
       * Set the input to be a character reader.  Normally,
       * a stream should be used rather than a reader, so that
       * the XML parser can resolve character encoding specified
       * by the XML declaration.  However, in many cases the encoding
       * of the input stream is already resolved, as in the case of
       * reading XML from a StringReader.
       *
       * @param reader A valid Reader reference to an XML CharacterStream.
       */
      public void setReader(Reader reader) {
          this.reader = reader;
      }
  
      /**
       * Get the character stream that was set with setReader.
       *
       * @return The character stream that was set with setReader, or null
       * if setReader or the Reader constructor was not called.
       */
      public Reader getReader() {
          return reader;
      }
  
      /**
       * Set the public identifier for this Source.
       *
       * <p>The public identifier is always optional: if the application
       * writer includes one, it will be provided as part of the
       * location information.</p>
       *
       * @param publicId The public identifier as a string.
       */
      public void setPublicId(String publicId) {
          this.publicId = publicId;
      }
  
      /**
       * Get the public identifier that was set with setPublicId.
       *
       * @return The public identifier that was set with setPublicId, or null
       * if setPublicId was not called.
       */
      public String getPublicId() {
          return publicId;
      }
  
      /**
       * Set the system identifier for this Source.
       *
       * <p>The system identifier is optional if there is a byte stream
       * or a character stream, but it is still useful to provide one,
       * since the application can use it to resolve relative URIs
       * and can include it in error messages and warnings (the parser
       * will attempt to open a connection to the URI only if
       * there is no byte stream or character stream specified).</p>
       *
       * @param systemId The system identifier as a URL string.
       */
      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.
       */
      public String getSystemId() {
          return systemId;
      }
  
      /**
       * Set the system ID from a File reference.
       *
       * @param f Must a non-null File reference.
       */
      public void setSystemId(File f) {
  	String fpath=f.getAbsolutePath();
  	if (File.separatorChar != '/') {
  	    fpath = fpath.replace(File.separatorChar, '/');
  	}
          if( fpath.startsWith("/"))
  	  this.systemId= "file://" + fpath;
  	else
  	  this.systemId = "file:///" + fpath;
      }
  
      //////////////////////////////////////////////////////////////////////
      // Internal state.
      //////////////////////////////////////////////////////////////////////
  
      /**
       * The public identifier for this input source, or null.
       */
      private String publicId;
  
      /**
       * The system identifier as a URL string, or null.
       */
      private String systemId;
  
      /**
       * The byte stream for this Source, or null.
       */
      private InputStream inputStream;
  
      /**
       * The character stream for this Source, or null.
       */
      private Reader reader;
  }
  
  
  
  1.59      +33 -0     xml-axis/java/src/org/apache/axis/utils/XMLUtils.java
  
  Index: XMLUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/XMLUtils.java,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- XMLUtils.java	3 Jul 2002 17:50:35 -0000	1.58
  +++ XMLUtils.java	9 Jul 2002 19:45:24 -0000	1.59
  @@ -80,10 +80,16 @@
   import javax.xml.parsers.ParserConfigurationException;
   import javax.xml.parsers.SAXParser;
   import javax.xml.parsers.SAXParserFactory;
  +import javax.xml.transform.Source;
  +import javax.xml.transform.dom.DOMSource;
  +import javax.xml.transform.stream.StreamSource;
  +import javax.xml.transform.sax.SAXSource;
   import java.io.InputStream;
   import java.io.OutputStream;
   import java.io.OutputStreamWriter;
   import java.io.Writer;
  +import java.io.ByteArrayOutputStream;
  +import java.io.ByteArrayInputStream;
   import java.net.HttpURLConnection;
   import java.net.MalformedURLException;
   import java.net.URL;
  @@ -518,6 +524,33 @@
        */
       public static InputSource getInputSourceFromURI(String uri){
           return getInputSourceFromURI(uri);
  +    }
  +
  +    /**
  +     * Utility to get the bytes uri
  +     *
  +     * @param uri the resource to get
  +     */
  +    public static InputSource sourceToInputSource(Source source) {
  +        if (source instanceof SAXSource) {
  +            return ((SAXSource) source).getInputSource();
  +        } else if (source instanceof DOMSource) {
  +            ByteArrayOutputStream baos = new ByteArrayOutputStream();
  +            Element domElement = (Element)((DOMSource)source).getNode();
  +            PrettyElementToStream(domElement, baos);
  +            InputSource  isource = new InputSource(source.getSystemId());
  +            isource.setByteStream(new ByteArrayInputStream(baos.toByteArray()));
  +            return isource;
  +        } else if (source instanceof StreamSource) {
  +            StreamSource ss      = (StreamSource) source;
  +            InputSource  isource = new InputSource(ss.getSystemId());
  +            isource.setByteStream(ss.getInputStream());
  +            isource.setCharacterStream(ss.getReader());
  +            isource.setPublicId(ss.getPublicId());
  +            return isource;
  +        } else {
  +            return getInputSourceFromURI(source.getSystemId());
  +        }
       }
   
       /**
  
  
  

Mime
View raw message