void writeformattedItem(XdmItem item, ProcessContext context, OutputStream out) throws TransformerFactoryConfigurationError, TransformerException, IOException { if (item.isAtomicValue()) { out.write(item.getStringValue().getBytes(UTF8)); } else { // item is an XdmNode XdmNode node = (XdmNode) item; switch (node.getNodeKind()) { case DOCUMENT: case ELEMENT: Transformer transformer = TransformerFactory.newInstance().newTransformer(); final Properties props = getTransformerProperties(context); transformer.setOutputProperties(props); transformer.transform(node.asSource(), new StreamResult(out)); break; default: out.write(node.getStringValue().getBytes(UTF8)); } } }
return getDocument(path).asSource();
void writeformattedItem(XdmItem item, ProcessContext context, OutputStream out) throws TransformerFactoryConfigurationError, TransformerException, IOException { if (item.isAtomicValue()) { out.write(item.getStringValue().getBytes(UTF8)); } else { // item is an XdmNode XdmNode node = (XdmNode) item; switch (node.getNodeKind()) { case DOCUMENT: case ELEMENT: Transformer transformer = TransformerFactory.newInstance().newTransformer(); final Properties props = getTransformerProperties(context); transformer.setOutputProperties(props); transformer.transform(node.asSource(), new StreamResult(out)); break; default: out.write(node.getStringValue().getBytes(UTF8)); } } }
return cache.get(uri).asSource();
return cache.get(uri).asSource();
public void genericTransform(XdmNode input, Map<String, Object> parameters, Destination dest) throws SaxonApiException { if (parameters != null) { for (Map.Entry<String, Object> param : parameters.entrySet()) { this.transformer.setParameter(new QName(null, param.getKey()), new XdmAtomicValue(param.getValue().toString())); } } this.transformer.setSource(input.asSource()); this.transformer.setDestination(dest); this.transformer.transform(); if (parameters != null) { //cancel the parameters for (Map.Entry<String, Object> param : parameters.entrySet()) { this.transformer.setParameter(new QName(null, param.getKey()), null); } } }
uri.toASCIIString()); else return doc.asSource(); }}} catch (URISyntaxException e) { e.printStackTrace();
config2.addSchemaSource(schema.asSource()); __log.debug("schema contents: " + schema);
result = new DOMResult(NodeOverNodeInfo.wrap(nodeInfo)); } else { result = generateTextResult(results.getXdmNode().asSource());
public void run() throws SaxonApiException { super.run(); XsltCompiler compiler = runtime.getProcessor().newXsltCompiler(); XsltExecutable exec = compiler.compile(prettyPrint.asSource()); XsltTransformer transformer = exec.load(); transformer.setInitialContextNode(source.read()); ByteArrayOutputStream stream = new ByteArrayOutputStream(); Serializer serializer = runtime.getProcessor().newSerializer(); serializer.setOutputProperty(Serializer.Property.ENCODING, "utf-8"); serializer.setOutputProperty(Serializer.Property.INDENT, "yes"); serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes"); serializer.setOutputProperty(Serializer.Property.METHOD, "xml"); serializer.setOutputStream(stream); transformer.setDestination(serializer); transformer.transform(); XdmNode output = runtime.parse(new InputSource(new ByteArrayInputStream(stream.toByteArray()))); result.write(output); } }
public void run() throws SaxonApiException { super.run(); XsltCompiler compiler = runtime.getProcessor().newXsltCompiler(); XsltExecutable exec = compiler.compile(prettyPrint.asSource()); XsltTransformer transformer = exec.load(); transformer.setInitialContextNode(source.read()); ByteArrayOutputStream stream = new ByteArrayOutputStream(); Serializer serializer = runtime.getProcessor().newSerializer(); serializer.setOutputProperty(Serializer.Property.ENCODING, "utf-8"); serializer.setOutputProperty(Serializer.Property.INDENT, "yes"); serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes"); serializer.setOutputProperty(Serializer.Property.METHOD, "xml"); serializer.setOutputStream(stream); transformer.setDestination(serializer); transformer.transform(); XdmNode output = runtime.parse(new InputSource(new ByteArrayInputStream(stream.toByteArray()))); result.write(output); } }
System.setErr(console); XsltExecutable compiledStylesheet = compiler.compile(chainResult.getXdmNode().asSource()); return compiledStylesheet;
Source style = compiler.getAssociatedStylesheet(sourceDoc.asSource(), null, null, null); XsltExecutable sheet = compiler.compile(style);
Source style = compiler.getAssociatedStylesheet(sourceDoc.asSource(), null, null, null); XsltExecutable sheet = compiler.compile(style);
"Validating: " + doc.getBaseURI().toASCIIString())); validator.validate(doc.asSource()); if (validationException != null) { throw (SaxonApiException) validationException;
public void run() throws SaxonApiException { Processor processor = new Processor(true); SchemaManager manager = processor.getSchemaManager(); // No resolver here, there isn't one. DocumentBuilder builder = processor.newDocumentBuilder(); SAXSource source = new SAXSource(new InputSource("http://tests.xproc.org/tests/doc/compoundEntity.xml")); XdmNode document = builder.build(source); source = new SAXSource(new InputSource("http://tests.xproc.org/tests/doc/document.xsd")); XdmNode schema = builder.build(source); manager.load(schema.asSource()); XdmDestination destination = new XdmDestination(); Controller controller = new Controller(processor.getUnderlyingConfiguration()); Receiver receiver = destination.getReceiver(controller.getConfiguration()); PipelineConfiguration pipe = controller.makePipelineConfiguration(); pipe.setRecoverFromValidationErrors(false); receiver.setPipelineConfiguration(pipe); SchemaValidator validator = manager.newSchemaValidator(); validator.setDestination(destination); dumpTree(document, "Input"); validator.validate(document.asSource()); XdmNode valid = destination.getXdmNode(); dumpTree(valid, "Output"); }
protected String serialize(XdmNode doc, MediaType type) { XProcRuntime runtime = getGlobalRuntime(); String format = "text"; if (MediaType.TEXT_HTML.equals(type)) { format = "html"; } else if (MediaType.APPLICATION_XML.equals(type)) { format = "xml"; } else if (MediaType.APPLICATION_JSON.equals(type)) { format = "json"; } if (xsl() != null) { XdmDestination result = null; try { XsltCompiler compiler = runtime.getProcessor().newXsltCompiler(); XsltExecutable exec = compiler.compile(xsl().asSource()); XsltTransformer transformer = exec.load(); transformer.setParameter(_format, new XdmAtomicValue(format)); transformer.setInitialContextNode(doc); result = new XdmDestination(); transformer.setDestination(result); transformer.transform(); } catch (SaxonApiException e) { throw new XProcException(e); } doc = result.getXdmNode(); } return doc.toString(); }
exec = compiler.compile(compiledSchema.asSource()); transformer = exec.load(); for (QName name : params.keySet()) {
exec = compiler.compile(compiledSchema.asSource()); transformer = exec.load(); for (QName name : params.keySet()) {
protected String serialize(XdmNode doc, MediaType type) { XProcRuntime runtime = getGlobalRuntime(); String format = "text"; if (MediaType.TEXT_HTML.equals(type)) { format = "html"; } else if (MediaType.APPLICATION_XML.equals(type)) { format = "xml"; } else if (MediaType.APPLICATION_JSON.equals(type)) { format = "json"; } if (xsl() != null) { XdmDestination result = null; try { XsltCompiler compiler = runtime.getProcessor().newXsltCompiler(); XsltExecutable exec = compiler.compile(xsl().asSource()); XsltTransformer transformer = exec.load(); transformer.setParameter(_format, new XdmAtomicValue(format)); transformer.setInitialContextNode(doc); result = new XdmDestination(); transformer.setDestination(result); transformer.transform(); } catch (SaxonApiException e) { throw new XProcException(e); } doc = result.getXdmNode(); } return doc.toString(); }