/** * Returns a <code>Source</code> ready to use by a <code>Transformer</code> from the previously produced result. * * @return a <code>Source</code> ready to use by a <code>Transformer</code>. * * @throws IllegalStateException If this method is invoked before results have been produced. */ public Source getSource() throws IllegalStateException { if (this.writer == null) throw new IllegalStateException("The templates have not been produced."); StreamSource source = new StreamSource(new StringReader(this.writer.toString())); // source.setSystemId( this.systemId); source.setPublicId("compiled:" + this.systemId); return source; }
private XMLStreamReader createXMLStreamReader(InputSource source) throws UnmarshalException { StreamSource streamSource = new StreamSource(); streamSource.setSystemId(source.getSystemId()); streamSource.setPublicId(source.getPublicId()); streamSource.setInputStream(source.getByteStream()); streamSource.setReader(source.getCharacterStream()); XMLStreamReader streamReader = createXMLStreamReader(streamSource); return streamReader; }
public static XMLStreamReader createXMLStreamReader(InputSource src) { String sysId = src.getSystemId() == null ? null : src.getSystemId(); String pubId = src.getPublicId() == null ? null : src.getPublicId(); if (src.getByteStream() != null) { if (src.getEncoding() == null) { StreamSource ss = new StreamSource(src.getByteStream(), sysId); ss.setPublicId(pubId); return createXMLStreamReader(ss); } return createXMLStreamReader(src.getByteStream(), src.getEncoding()); } else if (src.getCharacterStream() != null) { StreamSource ss = new StreamSource(src.getCharacterStream(), sysId); ss.setPublicId(pubId); return createXMLStreamReader(ss); } else { try { URL url = new URL(sysId); StreamSource ss = new StreamSource(url.openStream(), sysId); ss.setPublicId(pubId); return createXMLStreamReader(ss); } catch (Exception ex) { //ignore - not a valid URL } } throw new IllegalArgumentException("InputSource must have a ByteStream or CharacterStream"); } /**
public static XMLStreamReader createXMLStreamReader(InputSource src) { String sysId = src.getSystemId() == null ? null : src.getSystemId(); String pubId = src.getPublicId() == null ? null : src.getPublicId(); if (src.getByteStream() != null) { if (src.getEncoding() == null) { StreamSource ss = new StreamSource(src.getByteStream(), sysId); ss.setPublicId(pubId); return createXMLStreamReader(ss); } return createXMLStreamReader(src.getByteStream(), src.getEncoding()); } else if (src.getCharacterStream() != null) { StreamSource ss = new StreamSource(src.getCharacterStream(), sysId); ss.setPublicId(pubId); return createXMLStreamReader(ss); } else { try { URL url = new URL(sysId); StreamSource ss = new StreamSource(url.openStream(), sysId); ss.setPublicId(pubId); return createXMLStreamReader(ss); } catch (Exception ex) { //ignore - not a valid URL } } throw new IllegalArgumentException("InputSource must have a ByteStream or CharacterStream"); } /**
public static XMLStreamReader createXMLStreamReader(InputSource src) { String sysId = src.getSystemId() == null ? null : new String(src.getSystemId()); String pubId = src.getPublicId() == null ? null : new String(src.getPublicId()); if (src.getByteStream() != null) { if (src.getEncoding() == null) { StreamSource ss = new StreamSource(src.getByteStream(), sysId); ss.setPublicId(pubId); return createXMLStreamReader(ss); } return createXMLStreamReader(src.getByteStream(), src.getEncoding()); } else if (src.getCharacterStream() != null) { StreamSource ss = new StreamSource(src.getCharacterStream(), sysId); ss.setPublicId(pubId); return createXMLStreamReader(ss); } else { try { URL url = new URL(sysId); StreamSource ss = new StreamSource(url.openStream(), sysId); ss.setPublicId(pubId); return createXMLStreamReader(ss); } catch (Exception ex) { //ignore - not a valid URL } } throw new IllegalArgumentException("InputSource must have a ByteStream or CharacterStream"); } /**
private XMLStreamReader createXMLStreamReader(InputSource source) throws UnmarshalException { StreamSource streamSource = new StreamSource(); streamSource.setSystemId(source.getSystemId()); streamSource.setPublicId(source.getPublicId()); streamSource.setInputStream(source.getByteStream()); streamSource.setReader(source.getCharacterStream()); XMLStreamReader streamReader = createXMLStreamReader(streamSource); return streamReader; }
public static XMLStreamReader createXMLStreamReader(InputSource src) { String sysId = src.getSystemId() == null ? null : new String(src.getSystemId()); String pubId = src.getPublicId() == null ? null : new String(src.getPublicId()); if (src.getByteStream() != null) { if (src.getEncoding() == null) { StreamSource ss = new StreamSource(src.getByteStream(), sysId); ss.setPublicId(pubId); return createXMLStreamReader(ss); } return createXMLStreamReader(src.getByteStream(), src.getEncoding()); } else if (src.getCharacterStream() != null) { StreamSource ss = new StreamSource(src.getCharacterStream(), sysId); ss.setPublicId(pubId); return createXMLStreamReader(ss); } else { try { URL url = new URL(sysId); StreamSource ss = new StreamSource(url.openStream(), sysId); ss.setPublicId(pubId); return createXMLStreamReader(ss); } catch (Exception ex) { //ignore - not a valid URL } } throw new IllegalArgumentException("InputSource must have a ByteStream or CharacterStream"); } /**
public static XMLStreamReader createXMLStreamReader(InputSource src) { String sysId = src.getSystemId() == null ? null : new String(src.getSystemId()); String pubId = src.getPublicId() == null ? null : new String(src.getPublicId()); if (src.getByteStream() != null) { if (src.getEncoding() == null) { StreamSource ss = new StreamSource(src.getByteStream(), sysId); ss.setPublicId(pubId); return createXMLStreamReader(ss); } return createXMLStreamReader(src.getByteStream(), src.getEncoding()); } else if (src.getCharacterStream() != null) { StreamSource ss = new StreamSource(src.getCharacterStream(), sysId); ss.setPublicId(pubId); return createXMLStreamReader(ss); } else { try { URL url = new URL(sysId); StreamSource ss = new StreamSource(url.openStream(), sysId); ss.setPublicId(pubId); return createXMLStreamReader(ss); } catch (Exception ex) { //ignore - not a valid URL } } throw new IllegalArgumentException("InputSource must have a ByteStream or CharacterStream"); } /**
source.setPublicId(href); return getMainSchemaSource();
source.setPublicId("-//Berlioz//Service/XML/"+service.group()+"/"+service.id());
private static StreamSource forkStreamSource(final StreamSource source) throws IOException { final StreamSource result; if (source.getInputStream() != null) { final InputStreamForker streamForker = new InputStreamForker(source.getInputStream()); // let's replace the input stream with a fork source.setInputStream(streamForker.fork()); // and return another stream for the fork result = new StreamSource(streamForker.fork()); } else if (source.getReader() != null) { final InputStreamForker streamForker = new InputStreamForker(new ReaderInputStream(source.getReader())); // let's replace the input stream with a fork source.setReader(new InputStreamReader(streamForker.fork())); // and return another stream for the fork result = new StreamSource(streamForker.fork()); } else { // it's not a stream but a systemId must have been set (for example by StreamSource(File)). result = new StreamSource(source.getSystemId()); } result.setPublicId(source.getPublicId()); return result; }