本文整理了Java中javax.xml.transform.Source
类的一些代码示例,展示了Source
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Source
类的具体详情如下:
包路径:javax.xml.transform.Source
类名称:Source
[英]An object that implements this interface contains the information needed to act as source input (XML source or transformation instructions).
[中]实现此接口的对象包含用作源输入(XML源或转换指令)所需的信息。
代码示例来源:origin: plutext/docx4j
in = ((StreamSource) source).getInputStream();
if (in == null && source.getSystemId() != null) {
in = new java.net.URL(source.getSystemId()).openStream();
InputSource src = new InputSource(in);
src.setSystemId(source.getSystemId());
reader = new FontReader(src);
} else {
reader = new FontReader(new InputSource(
new URL(metricsFileName).openStream()));
代码示例来源:origin: robovm/robovm
if ((source instanceof StreamSource && source.getSystemId()==null &&
((StreamSource)source).getInputStream()==null &&
((StreamSource)source).getReader()==null)||
(source instanceof SAXSource &&
((SAXSource)source).getInputSource()==null &&
((SAXSource)source).getXMLReader()==null )||
(source instanceof DOMSource && ((DOMSource)source).getNode()==null)){
try {
DocumentBuilderFactory builderF = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = builderF.newDocumentBuilder();
String systemID = source.getSystemId();
source = new DOMSource(builder.newDocument());
source.setSystemId(systemID);
m_systemID = dsource.getSystemId();
Node dNode = dsource.getNode();
InputSource xmlSource = SAXSource.sourceToInputSource(source);
if (null != xmlSource.getSystemId())
m_systemID = xmlSource.getSystemId();
reader.setContentHandler(inputHandler);
reader.setDTDHandler((org.xml.sax.DTDHandler) inputHandler);
代码示例来源:origin: xalan/xalan
/**
* This class wraps an ErrorListener into a MessageHandler in order to
* capture messages reported via xsl:message.
*/
static class MessageHandler
extends org.apache.xalan.xsltc.runtime.MessageHandler
{
private ErrorListener _errorListener;
public MessageHandler(ErrorListener errorListener) {
_errorListener = errorListener;
}
public void displayMessage(String msg) {
if(_errorListener == null) {
System.err.println(msg);
}
else {
try {
_errorListener.warning(new TransformerException(msg));
}
catch (TransformerException e) {
// ignored
}
}
}
}
代码示例来源:origin: stackoverflow.com
String sourceUrlString = "http://some url";
Source source = new Source(new URL(sourceUrlString));
Element INFORM = source.getElementById("main").getAllElementsByClass("game").get(i-1);
String response = INFORM.replaceAll("\\s",""); // ! Use another name here !
sendResponse(resp, respone); // or use '+' - not shure if 1 or 2 args
代码示例来源:origin: plutext/docx4j
in = ((StreamSource) source).getInputStream();
if (in == null && source.getSystemId() != null) {
in = new java.net.URL(source.getSystemId()).openStream();
in = new URL(uri).openStream();
代码示例来源:origin: xalan/xalan
String systemId = source.getSystemId();
if (systemId != null) {
File file = new File(systemId);
URL url = null;
try {
url = new URL(systemId);
if ("file".equals(url.getProtocol()))
return url.getFile();
else
return null;
代码示例来源:origin: com.sun.xml.ws/jaxws-rt
void addSchema(Source schema) {
assert schema.getSystemId() != null;
String systemId = schema.getSystemId();
try {
XMLStreamBufferResult xsbr = XmlUtil.identityTransform(schema, new XMLStreamBufferResult());
SDDocumentSource sds = SDDocumentSource.create(new URL(systemId), xsbr.getXMLStreamBuffer());
SDDocument sdoc = SDDocumentImpl.create(sds, new QName(""), new QName(""));
docs.put(systemId, sdoc);
nsMapping.put(((SDDocument.Schema)sdoc).getTargetNamespace(), sdoc);
} catch(Exception ex) {
LOGGER.log(Level.WARNING, "Exception in adding schemas to resolver", ex);
}
}
代码示例来源:origin: stackoverflow.com
import javax.xml.XMLConstants;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.*;
...
URL schemaFile = new URL("http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd");
Source xmlFile = new StreamSource(new File("web.xml"));
SchemaFactory schemaFactory = SchemaFactory
.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
try {
validator.validate(xmlFile);
System.out.println(xmlFile.getSystemId() + " is valid");
} catch (SAXException e) {
System.out.println(xmlFile.getSystemId() + " is NOT valid");
System.out.println("Reason: " + e.getLocalizedMessage());
}
代码示例来源:origin: org.apache.openejb.patch/openejb-jstl
Source getSource(Reader reader, String systemId)
throws JspTagException {
try {
XMLReader xr = XMLReaderFactory.createXMLReader();
xr.setEntityResolver(new ParseSupport.JstlEntityResolver(pageContext));
xr.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
InputSource s = new InputSource(reader);
s.setSystemId(wrapSystemId(systemId));
Source result = new SAXSource(xr, s);
result.setSystemId(wrapSystemId(systemId));
return result;
} catch (SAXException e) {
throw new JspTagException(e);
}
}
代码示例来源:origin: org.apache.xmlgraphics/xmlgraphics-commons
/** {@inheritDoc} */
public Resource getResource(URI uri) throws IOException {
try {
Source src = resolver.resolve(uri.toASCIIString(), null);
InputStream resourceStream = XmlSourceUtil.getInputStream(src);
if (resourceStream == null) {
URL url = new URL(src.getSystemId());
resourceStream = url.openStream();
}
return new Resource(resourceStream);
} catch (TransformerException e) {
throw new IOException(e.getMessage());
}
}
代码示例来源:origin: org.apache.xmlgraphics/xmlgraphics-commons
/** {@inheritDoc} */
public OutputStream getOutputStream(URI uri) throws IOException {
try {
Source src = resolver.resolve(uri.toASCIIString(), null);
return new URL(src.getSystemId()).openConnection().getOutputStream();
} catch (TransformerException te) {
throw new IOException(te.getMessage());
}
}
}
代码示例来源:origin: org.daisy.pipeline.modules/css-speech
@Override
public InputStream fetch(URL url) throws IOException {
try {
if (url != null) {
Source resolved = resolver.resolve(url.toString(), "");
if (resolved != null) {
if (resolved instanceof StreamSource)
return ((StreamSource)resolved).getInputStream();
else
url = new URL(resolved.getSystemId());
}
}
} catch (TransformerException e) {
} catch (MalformedURLException e) {
}
return super.fetch(url);
}
};
代码示例来源:origin: org.apache.ws.security/wss4j
/**
* Utility to get the bytes uri
*
* @param source 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();
Node node = ((DOMSource) source).getNode();
if (node instanceof Document) {
node = ((Document) node).getDocumentElement();
}
Element domElement = (Element) node;
ElementToStream(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());
}
}
代码示例来源:origin: jersey/jersey
@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);
}
}
}
代码示例来源:origin: org.wamblee/wamblee-support-general
public XSLTransformation(URI aUri) throws XMLException {
try {
factory = TransformerFactory.newInstance();
Source source = new StreamSource(aUri.toURL().openStream());
source.setSystemId(aUri.toString());
systemId = aUri.toString();
transformer = factory.newTransformer(source);
} catch (MalformedURLException e) {
throw new XMLException(e.getMessage(), e);
} catch (TransformerConfigurationException e) {
throw new XMLException(e.getMessage(), e);
} catch (TransformerFactoryConfigurationError e) {
throw new XMLException(e.getMessage(), e);
} catch (IOException e) {
throw new XMLException(e.getMessage(), e);
}
}
代码示例来源:origin: xalan/xalan
_sourceSystemId = source.getSystemId();
final InputStream streamInput = stream.getInputStream();
final Reader streamReader = stream.getReader();
final XMLReader reader = _readerManager.getXMLReader();
reader.setProperty(LEXICAL_HANDLER_PROPERTY, handler);
reader.setContentHandler(handler);
input = new InputSource(streamInput);
input.setSystemId(_sourceSystemId);
input = new InputSource(streamReader);
input.setSystemId(_sourceSystemId);
reader.parse(input);
} finally {
_readerManager.releaseXMLReader(reader);
XMLReader reader = sax.getXMLReader();
final InputSource input = sax.getInputSource();
boolean userReader = true;
new DOM2TO(domsrc.getNode(), handler).parse();
} else if (source instanceof XSLTCSource) {
final DOM dom = ((XSLTCSource) source).getDOM(null, _translet);
代码示例来源:origin: org.apache.ant/ant
private Source getSource(final InputStream is, final Resource resource)
throws ParserConfigurationException, SAXException {
// todo: is this comment still relevant ??
// FIXME: need to use a SAXSource as the source for the transform
// so we can plug in our own entity resolver
Source src = null;
if (entityResolver != null) {
if (getFactory().getFeature(SAXSource.FEATURE)) {
final SAXParserFactory spFactory = SAXParserFactory.newInstance();
spFactory.setNamespaceAware(true);
final XMLReader reader = spFactory.newSAXParser().getXMLReader();
reader.setEntityResolver(entityResolver);
src = new SAXSource(reader, new InputSource(is));
} else {
throw new IllegalStateException("xcatalog specified, but "
+ "parser doesn't support SAX");
}
} else {
// WARN: Don't use the StreamSource(File) ctor. It won't work with
// xalan prior to 2.2 because of systemid bugs.
src = new StreamSource(is);
}
// The line below is a hack: the system id must an URI, but it is not
// cleat to get the URI of an resource, so just set the name of the
// resource as a system id
src.setSystemId(resourceToURI(resource));
return src;
}
代码示例来源:origin: com.caucho/resin
StreamSource stream = (StreamSource) source;
InputSource in = new InputSource();
in.setSystemId(stream.getSystemId());
in.setByteStream(stream.getInputStream());
in.setCharacterStream(stream.getReader());
Node node = ((DOMSource) source).getNode();
return parseStringDocument(string, source.getSystemId());
else
return new QDocument();
SAXSource saxSource = (SAXSource) source;
XMLReader reader = saxSource.getXMLReader();
InputSource inputSource = saxSource.getInputSource();
reader.setContentHandler(builder);
reader.parse(inputSource);
代码示例来源:origin: com.componentcorp.xml.validation/jxvc
if (source instanceof SAXSource){
SAXSource saxSource = (SAXSource) source;
inputSource=saxSource.getInputSource();
inputSource=new InputSource(streamSource.getInputStream());
inputSource.setSystemId(source.getSystemId());
inputSource.setPublicId(streamSource.getPublicId());
xmlReader.setEntityResolver(new LSResourceResolverWrapper(resourceResolver));
xmlReader.setErrorHandler(new MonitoringErrorHandler(errorHandler));
xmlReader.parse(inputSource);
} catch (ParserConfigurationException ex) {
throw new SAXException(ex);
代码示例来源:origin: xalan/xalan
String systemId = source.getSystemId();
input = sax.getInputSource();
XMLReader reader = sax.getXMLReader();
reader.setFeature
("http://xml.org/sax/features/namespaces",true);
reader.setFeature
("http://xml.org/sax/features/namespace-prefixes",false);
final Document dom = (Document)domsrc.getNode();
final DOM2SAX dom2sax = new DOM2SAX(dom);
xsltc.setXMLReader(dom2sax);
input = SAXSource.sourceToInputSource(source);
if (input == null){
input = new InputSource(domsrc.getSystemId());
final InputStream istream = stream.getInputStream();
final Reader reader = stream.getReader();
input = new InputSource(istream);
input = new InputSource(reader);
内容来源于网络,如有侵权,请联系作者删除!