@Override public void writeTo(Source source, Class<?> t, Type gt, Annotation[] as, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { try { if (source instanceof StreamSource) { StreamSource stream = (StreamSource) source; InputSource inputStream = new InputSource(stream.getInputStream()); inputStream.setCharacterStream(inputStream.getCharacterStream()); inputStream.setPublicId(stream.getPublicId()); inputStream.setSystemId(source.getSystemId()); source = new SAXSource(saxParserFactory.get().newSAXParser().getXMLReader(), inputStream); } StreamResult sr = new StreamResult(entityStream); transformerFactory.get().newTransformer().transform(source, sr); } catch (SAXException ex) { throw new InternalServerErrorException(ex); } catch (ParserConfigurationException ex) { throw new InternalServerErrorException(ex); } catch (TransformerException ex) { throw new InternalServerErrorException(ex); } } }
@Override public void writeTo(Source source, Class<?> t, Type gt, Annotation[] as, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { try { if (source instanceof StreamSource) { StreamSource stream = (StreamSource) source; InputSource inputStream = new InputSource(stream.getInputStream()); inputStream.setCharacterStream(inputStream.getCharacterStream()); inputStream.setPublicId(stream.getPublicId()); inputStream.setSystemId(source.getSystemId()); source = new SAXSource(saxParserFactory.get().newSAXParser().getXMLReader(), inputStream); } StreamResult sr = new StreamResult(entityStream); transformerFactory.get().newTransformer().transform(source, sr); } catch (SAXException ex) { throw new InternalServerErrorException(ex); } catch (ParserConfigurationException ex) { throw new InternalServerErrorException(ex); } catch (TransformerException ex) { throw new InternalServerErrorException(ex); } } }
/** * 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; } } }
inputStream.setPublicId(stream.getPublicId()); inputStream.setSystemId(source.getSystemId()); source = new SAXSource(SAXParserFactory.newInstance().newSAXParser().getXMLReader(), inputStream);
private static WstxInputSource sourceFromSS(WstxInputSource parent, ReaderConfig cfg, String refName, int xmlVersion, StreamSource ssrc) throws IOException, XMLStreamException { InputBootstrapper bs; Reader r = ssrc.getReader(); String pubId = ssrc.getPublicId(); String sysId0 = ssrc.getSystemId(); URL ctxt = (parent == null) ? null : parent.getSource(); URL url = (sysId0 == null || sysId0.length() == 0) ? null : URLUtil.urlFromSystemId(sysId0, ctxt); final SystemId systemId = SystemId.construct(sysId0, (url == null) ? ctxt : url); if (r == null) { InputStream in = ssrc.getInputStream(); if (in == null) { // Need to try just resolving the system id then if (url == null) { throw new IllegalArgumentException("Can not create Stax reader for a StreamSource -- neither reader, input stream nor system id was set."); } in = URLUtil.inputStreamFromURL(url); } bs = StreamBootstrapper.getInstance(pubId, systemId, in); } else { bs = ReaderBootstrapper.getInstance(pubId, systemId, r, null); } Reader r2 = bs.bootstrapInput(cfg, false, xmlVersion); return InputSourceFactory.constructEntitySource (cfg, parent, refName, bs, pubId, systemId, xmlVersion, r2); }
public String getPublicId() { return input.getPublicId(); }
public String getPublicId() { return input.getPublicId(); }
public String getPublicId() { return input.getPublicId(); }
StreamSource ss = (StreamSource) src; sysId = ss.getSystemId(); pubId = ss.getPublicId(); in = ss.getInputStream(); if (in == null) {
private static InputSource toInputSource(StreamSource source) { InputSource is = new InputSource(); is.setByteStream(source.getInputStream()); is.setCharacterStream(source.getReader()); is.setPublicId(source.getPublicId()); is.setSystemId(source.getSystemId()); return is; }
private static InputSource toInputSource(StreamSource src) { InputSource is = new InputSource(); is.setByteStream(src.getInputStream()); is.setCharacterStream(src.getReader()); is.setPublicId(src.getPublicId()); is.setSystemId(src.getSystemId()); return is; }
private static InputSource toInputSource(StreamSource src) { InputSource is = new InputSource(); is.setByteStream(src.getInputStream()); is.setCharacterStream(src.getReader()); is.setPublicId(src.getPublicId()); is.setSystemId(src.getSystemId()); return is; }
private static InputSource toInputSource(StreamSource src) { InputSource is = new InputSource(); is.setByteStream(src.getInputStream()); is.setCharacterStream(src.getReader()); is.setPublicId(src.getPublicId()); is.setSystemId(src.getSystemId()); return is; }
private static InputSource toInputSource(StreamSource source) { InputSource is = new InputSource(); is.setByteStream(source.getInputStream()); is.setCharacterStream(source.getReader()); is.setPublicId(source.getPublicId()); is.setSystemId(source.getSystemId()); return is; }
private org.iso_relax.verifier.Schema compileSchema(Source s) throws IOException, VerifierConfigurationException, SAXException, TransformerException { if( s instanceof StreamSource ) { StreamSource ss = (StreamSource)s; InputSource is = new InputSource(); is.setByteStream(ss.getInputStream()); is.setCharacterStream(ss.getReader()); is.setSystemId(ss.getSystemId()); is.setPublicId(ss.getPublicId()); return core.compileSchema(is); } // we can't directly parse SAX and DOM into JARV, // so turn it into stream first. StringWriter w = new StringWriter(); Transformer t = TransformerFactory.newInstance().newTransformer(); t.transform(s,new StreamResult(w)); return compileSchema(new StreamSource(new StringReader(w.toString()))); }
public static InputSource toInputSource(final Source source) throws TransformerException { if (source instanceof SAXSource) { return ((SAXSource) source).getInputSource(); } if (source instanceof StreamSource) { final InputSource inputSource = new InputSource(); inputSource.setPublicId(((StreamSource) source).getPublicId()); inputSource.setSystemId(source.getSystemId()); inputSource.setCharacterStream(((StreamSource) source).getReader()); inputSource.setByteStream(((StreamSource) source).getInputStream()); return inputSource; } final InputSource inputSource = new InputSource(toInputStream(source)); inputSource.setSystemId(source.getSystemId()); return inputSource; }
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()); }
/** * 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() ); }
/** * 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() ); }
/** * 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() ); }