Java Code Examples for javax.xml.transform.stream.StreamSource#getSystemId()

The following examples show how to use javax.xml.transform.stream.StreamSource#getSystemId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLInputFactoryImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
XMLInputSource jaxpSourcetoXMLInputSource(Source source){
     if(source instanceof StreamSource){
         StreamSource stSource = (StreamSource)source;
         String systemId = stSource.getSystemId();
         String publicId = stSource.getPublicId();
         InputStream istream = stSource.getInputStream();
         Reader reader = stSource.getReader();

         if(istream != null){
             return new XMLInputSource(publicId, systemId, null, istream, null);
         }
         else if(reader != null){
             return new XMLInputSource(publicId, systemId,null, reader, null);
         }else{
             return new XMLInputSource(publicId, systemId, null);
         }
     }

     throw new UnsupportedOperationException("Cannot create " +
            "XMLStreamReader or XMLEventReader from a " +
            source.getClass().getName());
}
 
Example 2
Source File: SAXSource.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Attempt to obtain a SAX InputSource object from a 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;
    }
}
 
Example 3
Source File: XMLInputFactoryImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
XMLInputSource jaxpSourcetoXMLInputSource(Source source){
     if(source instanceof StreamSource){
         StreamSource stSource = (StreamSource)source;
         String systemId = stSource.getSystemId();
         String publicId = stSource.getPublicId();
         InputStream istream = stSource.getInputStream();
         Reader reader = stSource.getReader();

         if(istream != null){
             return new XMLInputSource(publicId, systemId, null, istream, null);
         }
         else if(reader != null){
             return new XMLInputSource(publicId, systemId,null, reader, null);
         }else{
             return new XMLInputSource(publicId, systemId, null);
         }
     }

     throw new UnsupportedOperationException("Cannot create " +
            "XMLStreamReader or XMLEventReader from a " +
            source.getClass().getName());
}
 
Example 4
Source File: SAXSource.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Attempt to obtain a SAX InputSource object from a 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;
    }
}
 
Example 5
Source File: XMLInputFactoryImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
XMLInputSource jaxpSourcetoXMLInputSource(Source source){
     if(source instanceof StreamSource){
         StreamSource stSource = (StreamSource)source;
         String systemId = stSource.getSystemId();
         String publicId = stSource.getPublicId();
         InputStream istream = stSource.getInputStream();
         Reader reader = stSource.getReader();

         if(istream != null){
             return new XMLInputSource(publicId, systemId, null, istream, null);
         }
         else if(reader != null){
             return new XMLInputSource(publicId, systemId,null, reader, null);
         }else{
             return new XMLInputSource(publicId, systemId, null);
         }
     }

     throw new UnsupportedOperationException("Cannot create " +
            "XMLStreamReader or XMLEventReader from a " +
            source.getClass().getName());
}
 
Example 6
Source File: XMLInputFactoryImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
XMLInputSource jaxpSourcetoXMLInputSource(Source source){
     if(source instanceof StreamSource){
         StreamSource stSource = (StreamSource)source;
         String systemId = stSource.getSystemId();
         String publicId = stSource.getPublicId();
         InputStream istream = stSource.getInputStream();
         Reader reader = stSource.getReader();

         if(istream != null){
             return new XMLInputSource(publicId, systemId, null, istream, null);
         }
         else if(reader != null){
             return new XMLInputSource(publicId, systemId,null, reader, null);
         }else{
             return new XMLInputSource(publicId, systemId, null);
         }
     }

     throw new UnsupportedOperationException("Cannot create " +
            "XMLStreamReader or XMLEventReader from a " +
            source.getClass().getName());
}
 
Example 7
Source File: SAXSource.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Attempt to obtain a SAX InputSource object from a 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;
    }
}
 
Example 8
Source File: SAXSource.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Attempt to obtain a SAX InputSource object from a 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;
    }
}
 
Example 9
Source File: Util.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a proper {@link XMLInputSource} from a {@link StreamSource}.
 *
 * @return always return non-null valid object.
 */
public static final XMLInputSource toXMLInputSource( StreamSource in ) {
    if( in.getReader()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getReader(), null );
    if( in.getInputStream()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getInputStream(), null );

    return new XMLInputSource(
    in.getPublicId(), in.getSystemId(), in.getSystemId(), false );
}
 
Example 10
Source File: AbstractSchematronResource.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Nullable
protected NodeAndBaseURI getAsNode (@Nonnull final IHasInputStream aXMLResource) throws Exception
{
  final StreamSource aStreamSrc = TransformSourceFactory.create (aXMLResource);
  InputStream aIS = null;
  try
  {
    aIS = aStreamSrc.getInputStream ();
  }
  catch (final IllegalStateException ex)
  {
    // Fall through
    // Happens e.g. for ResourceStreamSource with non-existing resources
  }
  if (aIS == null)
  {
    // Resource not found
    LOGGER.warn ("XML resource " + aXMLResource + " does not exist!");
    return null;
  }
  final Document aDoc = DOMReader.readXMLDOM (aIS, internalCreateDOMReaderSettings ());
  if (aDoc == null)
    throw new IllegalArgumentException ("Failed to read resource " + aXMLResource + " as XML");

  LOGGER.info ("Read XML resource " + aXMLResource);
  return new NodeAndBaseURI (aDoc, aStreamSrc.getSystemId ());
}
 
Example 11
Source File: Util.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a proper {@link XMLInputSource} from a {@link StreamSource}.
 *
 * @return always return non-null valid object.
 */
public static final XMLInputSource toXMLInputSource( StreamSource in ) {
    if( in.getReader()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getReader(), null );
    if( in.getInputStream()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getInputStream(), null );

    return new XMLInputSource(
    in.getPublicId(), in.getSystemId(), in.getSystemId() );
}
 
Example 12
Source File: Util.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a proper {@link XMLInputSource} from a {@link StreamSource}.
 *
 * @return always return non-null valid object.
 */
public static final XMLInputSource toXMLInputSource( StreamSource in ) {
    if( in.getReader()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getReader(), null );
    if( in.getInputStream()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getInputStream(), null );

    return new XMLInputSource(
    in.getPublicId(), in.getSystemId(), in.getSystemId() );
}
 
Example 13
Source File: Util.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a proper {@link XMLInputSource} from a {@link StreamSource}.
 *
 * @return always return non-null valid object.
 */
public static final XMLInputSource toXMLInputSource( StreamSource in ) {
    if( in.getReader()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getReader(), null );
    if( in.getInputStream()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getInputStream(), null );

    return new XMLInputSource(
    in.getPublicId(), in.getSystemId(), in.getSystemId(), false );
}
 
Example 14
Source File: Util.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a proper {@link XMLInputSource} from a {@link StreamSource}.
 *
 * @return always return non-null valid object.
 */
public static final XMLInputSource toXMLInputSource( StreamSource in ) {
    if( in.getReader()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getReader(), null );
    if( in.getInputStream()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getInputStream(), null );

    return new XMLInputSource(
    in.getPublicId(), in.getSystemId(), in.getSystemId() );
}
 
Example 15
Source File: Util.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a proper {@link XMLInputSource} from a {@link StreamSource}.
 *
 * @return always return non-null valid object.
 */
public static final XMLInputSource toXMLInputSource( StreamSource in ) {
    if( in.getReader()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getReader(), null );
    if( in.getInputStream()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getInputStream(), null );

    return new XMLInputSource(
    in.getPublicId(), in.getSystemId(), in.getSystemId() );
}
 
Example 16
Source File: Util.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a proper {@link XMLInputSource} from a {@link StreamSource}.
 *
 * @return always return non-null valid object.
 */
public static final XMLInputSource toXMLInputSource( StreamSource in ) {
    if( in.getReader()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getReader(), null );
    if( in.getInputStream()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getInputStream(), null );

    return new XMLInputSource(
    in.getPublicId(), in.getSystemId(), in.getSystemId() );
}
 
Example 17
Source File: EfficientStreamingTransformer.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private InputStream getInputStreamFromSource(StreamSource s)
    throws TransformerException {

    InputStream stream = s.getInputStream();
    if (stream != null)
        return stream;

    if (s.getReader() != null)
        return null;

    String systemId = s.getSystemId();
    if (systemId != null) {
        try {
            String fileURL = systemId;

            if (systemId.startsWith("file:///"))
            {
                /*
                 systemId is:
                 file:///<drive>:/some/path/file.xml
                 or
                 file:///some/path/file.xml
                */

                String absolutePath = systemId.substring(7);
                /*
                 /<drive>:/some/path/file.xml
                 or
                 /some/path/file.xml
                */

                boolean hasDriveDesignator = absolutePath.indexOf(":") > 0;
                if (hasDriveDesignator) {
                  String driveDesignatedPath = absolutePath.substring(1);
                  /*
                  <drive>:/some/path/file.xml */
                  fileURL = driveDesignatedPath;
                }
                else {
                  /*
                  /some/path/file.xml */
                  fileURL = absolutePath;
                }
            }
            //return new FileInputStream(fileURL);
            try {
                return new FileInputStream(new File(new URI(fileURL)));
            } catch (URISyntaxException ex) {
                throw new TransformerException(ex);
            }
        } catch (IOException e) {
            throw new TransformerException(e.toString());
        }
    }

    throw new TransformerException("Unexpected StreamSource object");
}
 
Example 18
Source File: EfficientStreamingTransformer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private InputStream getInputStreamFromSource(StreamSource s)
    throws TransformerException {

    InputStream stream = s.getInputStream();
    if (stream != null)
        return stream;

    if (s.getReader() != null)
        return null;

    String systemId = s.getSystemId();
    if (systemId != null) {
        try {
            String fileURL = systemId;

            if (systemId.startsWith("file:///"))
            {
                /*
                 systemId is:
                 file:///<drive>:/some/path/file.xml
                 or
                 file:///some/path/file.xml
                */

                String absolutePath = systemId.substring(7);
                /*
                 /<drive>:/some/path/file.xml
                 or
                 /some/path/file.xml
                */

                boolean hasDriveDesignator = absolutePath.indexOf(":") > 0;
                if (hasDriveDesignator) {
                  String driveDesignatedPath = absolutePath.substring(1);
                  /*
                  <drive>:/some/path/file.xml */
                  fileURL = driveDesignatedPath;
                }
                else {
                  /*
                  /some/path/file.xml */
                  fileURL = absolutePath;
                }
            }
            //return new FileInputStream(fileURL);
            try {
                return new FileInputStream(new File(new URI(fileURL)));
            } catch (URISyntaxException ex) {
                throw new TransformerException(ex);
            }
        } catch (IOException e) {
            throw new TransformerException(e.toString());
        }
    }

    throw new TransformerException("Unexpected StreamSource object");
}
 
Example 19
Source File: EfficientStreamingTransformer.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private InputStream getInputStreamFromSource(StreamSource s)
    throws TransformerException {

    InputStream stream = s.getInputStream();
    if (stream != null)
        return stream;

    if (s.getReader() != null)
        return null;

    String systemId = s.getSystemId();
    if (systemId != null) {
        try {
            String fileURL = systemId;

            if (systemId.startsWith("file:///"))
            {
                /*
                 systemId is:
                 file:///<drive>:/some/path/file.xml
                 or
                 file:///some/path/file.xml
                */

                String absolutePath = systemId.substring(7);
                /*
                 /<drive>:/some/path/file.xml
                 or
                 /some/path/file.xml
                */

                boolean hasDriveDesignator = absolutePath.indexOf(":") > 0;
                if (hasDriveDesignator) {
                  String driveDesignatedPath = absolutePath.substring(1);
                  /*
                  <drive>:/some/path/file.xml */
                  fileURL = driveDesignatedPath;
                }
                else {
                  /*
                  /some/path/file.xml */
                  fileURL = absolutePath;
                }
            }
            //return new FileInputStream(fileURL);
            try {
                return new FileInputStream(new File(new URI(fileURL)));
            } catch (URISyntaxException ex) {
                throw new TransformerException(ex);
            }
        } catch (IOException e) {
            throw new TransformerException(e.toString());
        }
    }

    throw new TransformerException("Unexpected StreamSource object");
}
 
Example 20
Source File: EfficientStreamingTransformer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private InputStream getInputStreamFromSource(StreamSource s)
    throws TransformerException {

    InputStream stream = s.getInputStream();
    if (stream != null)
        return stream;

    if (s.getReader() != null)
        return null;

    String systemId = s.getSystemId();
    if (systemId != null) {
        try {
            String fileURL = systemId;

            if (systemId.startsWith("file:///"))
            {
                /*
                 systemId is:
                 file:///<drive>:/some/path/file.xml
                 or
                 file:///some/path/file.xml
                */

                String absolutePath = systemId.substring(7);
                /*
                 /<drive>:/some/path/file.xml
                 or
                 /some/path/file.xml
                */

                boolean hasDriveDesignator = absolutePath.indexOf(":") > 0;
                if (hasDriveDesignator) {
                  String driveDesignatedPath = absolutePath.substring(1);
                  /*
                  <drive>:/some/path/file.xml */
                  fileURL = driveDesignatedPath;
                }
                else {
                  /*
                  /some/path/file.xml */
                  fileURL = absolutePath;
                }
            }
            //return new FileInputStream(fileURL);
            try {
                return new FileInputStream(new File(new URI(fileURL)));
            } catch (URISyntaxException ex) {
                throw new TransformerException(ex);
            }
        } catch (IOException e) {
            throw new TransformerException(e.toString());
        }
    }

    throw new TransformerException("Unexpected StreamSource object");
}