本文整理汇总了Java中net.sf.saxon.s9api.SaxonApiException类的典型用法代码示例。如果您正苦于以下问题:Java SaxonApiException类的具体用法?Java SaxonApiException怎么用?Java SaxonApiException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SaxonApiException类属于net.sf.saxon.s9api包,在下文中一共展示了SaxonApiException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExpressionEvaluatorFactory
import net.sf.saxon.s9api.SaxonApiException; //导入依赖的package包/类
@Override
public ExpressionEvaluatorFactory<XdmItem> getExpressionEvaluatorFactory() {
return entry -> expression -> {
try {
XPathSelector selector = xpath.compile(expression).load();
selector.setContextItem(entry);
XdmItem value = selector.evaluateSingle();
if (value == null) {
return Optional.empty();
}
String result = autoNodeTextExtraction ? value.getStringValue() : value.toString();
return Optional.of(result);
} catch (SaxonApiException e) {
throw new RuntimeException(String.format(
"Error applying XPath expression [%s] to entry [%s]", entry, expression),
e);
}
};
}
示例2: validateComment
import net.sf.saxon.s9api.SaxonApiException; //导入依赖的package包/类
@Test
public void validateComment() throws ValidationException {
try {
GauloisPipe piper = new GauloisPipe(configFactory);
Config config = new ConfigUtil(configFactory.getConfiguration(),piper.getUriResolver(), "./src/test/resources/comment-xslt.xml").buildConfig(emptyInputParams);
config.verify();
Iterator<ParametrableStep> it = config.getPipe().getXslts();
int count=0;
while(it.hasNext()) {
it.next();
count++;
}
assertEquals(3, count);
} catch (InvalidSyntaxException | SaxonApiException ex) {
fail(ex.getMessage());
}
}
示例3: testXdmValueToXsl
import net.sf.saxon.s9api.SaxonApiException; //导入依赖的package包/类
@Test
public void testXdmValueToXsl() throws InvalidSyntaxException, SaxonApiException, URISyntaxException, IOException, ValidationException {
GauloisPipe piper = new GauloisPipe(configFactory);
ConfigUtil cu = new ConfigUtil(configFactory.getConfiguration(), piper.getUriResolver(), "./src/test/resources/paramDate.xml");
HashMap<QName,ParameterValue> params = new HashMap<>();
QName qnDate = new QName("date");
// to get a date XdmValue from saxon, we must be brilliants !
Processor proc = new Processor(configFactory.getConfiguration());
XQueryEvaluator ev = proc.newXQueryCompiler().compile("current-dateTime()").load();
XdmItem item = ev.evaluateSingle();
params.put(qnDate, new ParameterValue(qnDate, item, factory.getDatatype(new QName("xs","http://www.w3.org/2001/XMLSchema","dateTime"))));
Config config = cu.buildConfig(params);
config.verify();
piper.setConfig(config);
piper.setInstanceName("XDM_VALUE_TO_XSL");
piper.launch();
File expect = new File("target/generated-test-files/date-output.xml");
XdmNode document = proc.newDocumentBuilder().build(expect);
XPathExecutable exec = proc.newXPathCompiler().compile("/date");
XPathSelector selector = exec.load();
selector.setContextItem((XdmItem)document);
XdmValue result = selector.evaluate();
assertTrue(result.size()>0);
}
示例4: testStaticBaseUri
import net.sf.saxon.s9api.SaxonApiException; //导入依赖的package包/类
public void testStaticBaseUri() throws InvalidSyntaxException, SaxonApiException, URISyntaxException, IOException, ValidationException {
File expect = new File("target/generated-test-file/static-base-uri-ret.xml");
if(expect.exists()) expect.delete();
GauloisPipe piper = new GauloisPipe(configFactory);
ConfigUtil cu = new ConfigUtil(configFactory.getConfiguration(), piper.getUriResolver(), "./src/test/resources/static-base-uri.xml");
HashMap<QName,ParameterValue> params = new HashMap<>();
Config config = cu.buildConfig(params);
config.verify();
piper.setConfig(config);
piper.setInstanceName("STATIC-BASE-URI");
piper.launch();
assertTrue(expect.exists());
Processor proc = new Processor(configFactory.getConfiguration());
XdmNode document = proc.newDocumentBuilder().build(expect);
XPathExecutable exec = proc.newXPathCompiler().compile("/ret/*/text()");
XPathSelector selector = exec.load();
selector.setContextItem((XdmItem)document);
XdmValue result = selector.evaluate();
String staticBaseUri = result.itemAt(0).getStringValue();
String gpStaticBaseUri = result.itemAt(1).getStringValue();
assertTrue("gp:staticBaseUri does not ends with target/classes/xsl/static-base-uri-ret.xml", gpStaticBaseUri.endsWith("target/classes/xsl/static-base-uri-ret.xml"));
expect.delete();
}
示例5: testSourceFolderContent
import net.sf.saxon.s9api.SaxonApiException; //导入依赖的package包/类
@Test
public void testSourceFolderContent() throws InvalidSyntaxException, SaxonApiException, MalformedURLException {
GauloisPipe piper = new GauloisPipe(configFactory);
ConfigUtil cu = new ConfigUtil(configFactory.getConfiguration(), piper.getUriResolver(), "src/test/resources/folderContentRelative.xml");
Config config = cu.buildConfig(emptyInputParams);
assertTrue("relative path in source folder fails",config.getSources().getFiles().size()>=34);
cu = new ConfigUtil(configFactory.getConfiguration(), piper.getUriResolver(), "cp:/folderContentAbsUri.xml");
HashMap<QName, ParameterValue> params = new HashMap<>();
File currentPath = new File(System.getProperty("user.dir"));
// check if we are in the right directory
File test = new File(currentPath, "src/test/resources/folderContentAbsUri.xml");
if(!test.exists()) {
// probably, we are in parent folder
currentPath = new File(currentPath, "gaulois-pipe");
test = new File(currentPath, "src/test/resources/folderContentAbsUri.xml");
if(!test.exists()) {
fail("Unable to locate gaulois-pipe folder. Try moving to gaulois-pipe module folder.");
}
}
QName sourceQn = new QName("source");
params.put(sourceQn, new ParameterValue(sourceQn, currentPath.toURI().toURL().toExternalForm(), datatypeFactory.XS_STRING));
config = cu.buildConfig(params);
assertTrue("absolute URI in source folder fails", config.getSources().getFiles().size()>=34);
}
示例6: build
import net.sf.saxon.s9api.SaxonApiException; //导入依赖的package包/类
public FormattingXmlStreamWriter build() {
if (_indent) {
_serializer.setOutputProperty(Property.INDENT, "yes");
}
if (_lineLength != null) {
_serializer.setOutputProperty(Property.SAXON_LINE_LENGTH, _lineLength.toString());
}
StreamWriterToReceiver xmlStreamWriter;
try {
xmlStreamWriter = _serializer.getXMLStreamWriter();
} catch (SaxonApiException ex) {
throw Throwables.propagate(ex);
}
return new FormattingXmlStreamWriter(xmlStreamWriter, _flushable);
}
示例7: compile
import net.sf.saxon.s9api.SaxonApiException; //导入依赖的package包/类
public CrigttXsltExecutable compile(Source src, @Nullable ExtensionFunctionDefinition ... extFuncs) throws SaxonApiException {
CrigttProcessor proc = this.getProcessor();
CompilerInfo compilerInfo = this.getUnderlyingCompilerInfo();
if (!ArrayUtils.isEmpty(extFuncs)) {
IntegratedFunctionLibrary extFuncLib = new IntegratedFunctionLibrary();
Stream.of(extFuncs).forEach(extFuncLib::registerFunction);
compilerInfo.setExtensionFunctionLibrary(extFuncLib);
}
try {
PreparedStylesheet preparedStylesheet = Compilation.compileSingletonPackage(proc.getUnderlyingConfiguration(), compilerInfo, src);
return new CrigttXsltExecutable(proc, preparedStylesheet, compilerInfo);
} catch (XPathException e) {
throw new SaxonApiException(e);
}
}
示例8: setCustomParameters
import net.sf.saxon.s9api.SaxonApiException; //导入依赖的package包/类
private void setCustomParameters(XsltTransformer xsltTransformer) throws XPathException {
//logger.info("setCustomParameters()");
final URL scriptUrl = getScriptUrl();
final XsltExecutable xsltExecutable = xsltConrefCache.getTransformerCache().getExecutable(scriptUrl, xsltConrefCache.getUriResolver());
final List<String> attrNameList = node.getAttributeNamesOfNamespace(NAMESPACE_PARAMETER_URI);
for (String attrName : attrNameList) {
//logger.info("attribute: " + attrName);
final QName paramName = new QName(attrName.replaceAll("(^[^\\{\\}]*:)|(^\\{.*\\})", ""));
final String paramValue = node.getAttribute(attrName, NAMESPACE_PARAMETER_URI);
//logger.info("set custom parameter: " + paramName + " = '" + paramValue + "'");
if (paramValue != null) {
if (xsltExecutable.getGlobalParameters().containsKey(paramName)) {
try {
xsltTransformer.setParameter(paramName, new XdmAtomicValue(EmbeddedXPathResolver.resolve(paramValue, node), ItemType.UNTYPED_ATOMIC));
//logger.info("parameters set. ");
} catch (SaxonApiException e) {
logger.error(e, e);
}
} else {
//logger.error("Parameter '" + paramName + "' not defined in script.");
}
}
}
}
示例9: call
import net.sf.saxon.s9api.SaxonApiException; //导入依赖的package包/类
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
final Processor processor = new Processor(context.getConfiguration());
final DocumentBuilder builder = processor.newDocumentBuilder();
try {
BuildingStreamWriterImpl writer = builder.newBuildingStreamWriter();
writer.writeStartElement("test1");
writer.writeCharacters("text1");
writer.writeEndElement();
writer.writeStartElement("test2");
writer.writeCharacters("text2");
writer.writeEndElement();
return writer.getDocumentNode().getUnderlyingValue();
} catch (SaxonApiException | XMLStreamException e) {
logger.error(e, e);
throw new XPathException("Failed to create return value: " + e.getMessage());
}
}
示例10: getXPathExecutable
import net.sf.saxon.s9api.SaxonApiException; //导入依赖的package包/类
private XPathExecutable getXPathExecutable(String xPath, boolean schemaAware) throws XPathException {
final HashMap<String, XPathExecutable> xPathMap = (schemaAware) ? xPathMapSchemaAware: xPathMapNonSchemaAware;
XPathExecutable xPathExecutable = xPathMap.get(xPath);
if (xPathExecutable == null) {
try {
compiler.setSchemaAware(schemaAware);
xPathExecutable = compiler.compile(xPath);
xPathMap.put(xPath, xPathExecutable);
} catch (SaxonApiException e) {
logger.error(e.getMessage(), e);
throw new XPathException("XPath compilation error. (XPath Expression: '" + xPath + "'): " + e.getMessage());
}
}
return xPathExecutable;
}
示例11: compileXsl
import net.sf.saxon.s9api.SaxonApiException; //导入依赖的package包/类
/**
* Compiles an xsl file.
* @param inputStream the xsl file as {@link InputStream}
* @param processor the {@link Processor} that provides the compiler
* @return an {@link XsltExecutable} that will be used further in the xsl transformation process
* @throws SaxonApiException it is thrown if an exception occurs during the compilation
*/
public XsltExecutable compileXsl(final InputStream inputStream, final Processor processor) throws SaxonApiException {
XsltCompiler xsltCompiler = processor.newXsltCompiler();
Source xslSource = streamSourceFactory.createStreamSource(inputStream);
xsltCompiler.setErrorListener(errorListener);
XsltExecutable xsltExecutable = xsltCompiler.compile(xslSource);
return xsltExecutable;
}
示例12: testTransformShouldSetHistoryElementsAsParameter
import net.sf.saxon.s9api.SaxonApiException; //导入依赖的package包/类
@Test
public void testTransformShouldSetHistoryElementsAsParameter() throws SaxonApiException, SAXException {
//GIVEN
given(xslCompiler.compileXsl(xslInputStream, processor)).willReturn(xsltExecutable);
given(xsltExecutable.load()).willReturn(xsltTransformer);
given(xslOutputProvider.getOutput(xsltTransformer)).willReturn(outputStream);
givenParameter("request", requestName);
givenParameter("historyRequest", historyRequestName);
givenParameter("historyResponse", historyResponseName);
setTemplateMocks();
//WHEN
underTest.transform(xslInputStream, requestInputStream, templateInputStream, nameToXml);
//THEN
verify(xsltTransformer).setParameter(requestName, requestDocument);
verify(xsltTransformer).setParameter(historyRequestName, requestDocument);
verify(xsltTransformer).setParameter(historyResponseName, requestDocument);
}
示例13: evaluateXQuery
import net.sf.saxon.s9api.SaxonApiException; //导入依赖的package包/类
/**
* Executes a given XQuery expression on the given XML.
* @param xml is the XQuery data source
* @param query is the query expression
* @return with the query result as String
* @throws SaxonApiException was thrown when the XQuery execution is failed
*/
public String evaluateXQuery(final String xml, final String query) throws SaxonApiException {
Processor processor = processorFactory.createProcessor();
XQueryCompiler xqueryCompiler = processor.newXQueryCompiler();
xqueryCompiler.setErrorListener(errorListener);
XQueryExecutable xqueryExec = xqueryCompiler.compile(query);
XQueryEvaluator xqueryEval = xqueryExec.load();
xqueryEval.setErrorListener(errorListener);
SAXSource requestXml = saxSourceFactory.createSAXSource(inputSourceFactory.createInputSource(xml));
xqueryEval.setSource(requestXml);
ByteArrayOutputStream baos = byteArrayOutputStreamFactory.createByteArrayOutputStream();
Serializer ser = serializerFactory.createSerializer(baos);
xqueryEval.setDestination(ser);
xqueryEval.run();
return baos.toString();
}
示例14: checkCondition
import net.sf.saxon.s9api.SaxonApiException; //导入依赖的package包/类
@Override
public boolean checkCondition(final WilmaHttpRequest request, final ParameterList parameterList) {
List<Parameter> params = parameterList.getAllParameters();
boolean result = false;
if (params.size() == 1) {
String contentType = request.getHeader(CONTENT_TYPE_HEADER);
if (contentType != null && (contentType.contains(XML_CONTENT) || FASTINFOSET_CONTENT.equals(contentType))) {
try {
Parameter paramater = params.iterator().next();
String element = paramater.getName();
String value = paramater.getValue();
result = evaluateCondition(request.getBody(), element, value);
} catch (SaxonApiException e) {
throw new ConditionEvaluationFailedException("XQuery evaluation failed at request: " + request.getWilmaMessageLoggerId(), e);
}
}
} else {
throw new ConditionEvaluationFailedException("Please provide exactly one parameter!");
}
return result;
}
示例15: checkCondition
import net.sf.saxon.s9api.SaxonApiException; //导入依赖的package包/类
@Override
public boolean checkCondition(final WilmaHttpRequest request, final ParameterList parameterList) {
boolean result = false;
List<Parameter> params = parameterList.getAllParameters();
if (params.size() == 1) {
String contentType = request.getHeader(CONTENT_TYPE_HEADER);
if (contentType != null && (contentType.contains(XML_CONTENT) || FASTINFOSET_CONTENT.equals(contentType))) {
try {
Parameter paramater = params.iterator().next();
String element = paramater.getName();
String value = paramater.getValue();
result = evaluateCondition(request.getBody(), element, value);
} catch (SaxonApiException e) {
throw new ConditionEvaluationFailedException("XQuery evaluation failed at request: " + request.getWilmaMessageLoggerId(), e);
}
}
} else {
throw new ConditionEvaluationFailedException("Please provide exactly one parameter in Stub Configuration!");
}
return result;
}