本文整理汇总了Java中net.sf.saxon.trans.XPathException类的典型用法代码示例。如果您正苦于以下问题:Java XPathException类的具体用法?Java XPathException怎么用?Java XPathException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XPathException类属于net.sf.saxon.trans包,在下文中一共展示了XPathException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testQueryElementNotImplementedAxis
import net.sf.saxon.trans.XPathException; //导入依赖的package包/类
@Test
public void testQueryElementNotImplementedAxis() throws Exception {
final String xpath = "/CLASS_DEF//following-sibling::METHOD_DEF";
final RootNode rootNode = getRootNode("InputXpathMapperAst.java");
try {
getXpathItems(xpath, rootNode);
fail("Exception is excepted");
}
catch (XPathException ex) {
assertEquals("Invalid number of nodes", "Operation is not supported", ex.getMessage());
}
}
示例2: getItems
import net.sf.saxon.trans.XPathException; //导入依赖的package包/类
/**
* Returns list of nodes matching xpath expression given event.
* @param event {@code TreeWalkerAuditEvent} object
* @return list of nodes matching xpath expression given event
*/
private List<Item> getItems(TreeWalkerAuditEvent event) {
final RootNode rootNode;
if (event.getRootAst() == null) {
rootNode = null;
}
else {
rootNode = new RootNode(event.getRootAst());
}
final List<Item> items;
try {
final XPathDynamicContext xpathDynamicContext =
xpathExpression.createDynamicContext(rootNode);
items = xpathExpression.evaluate(xpathDynamicContext);
}
catch (XPathException ex) {
throw new IllegalStateException("Cannot initialize context and evaluate query: "
+ xpathQuery, ex);
}
return items;
}
示例3: close
import net.sf.saxon.trans.XPathException; //导入依赖的package包/类
@Override
public void close() throws XPathException {
String fileName = getParameter(FileAppenderStep.FILE_NAME).toString();
String value = getParameter(FileAppenderStep.VALUE).toString();
String lineSeparator = FileAppenderStep.getLineSeparator(getParameter(FileAppenderStep.LINE_SEPARATOR));
Charset encoding = FileAppenderStep.getCharset(getParameter(FileAppenderStep.ENCODING));
File f = new File(fileName);
try {
FileOutputStream fos = new FileOutputStream(f, true);
try (OutputStreamWriter osw = new OutputStreamWriter(fos, encoding)) {
osw.append(value);
osw.append(lineSeparator);
osw.flush();
}
} catch(IOException ex) {
LOGGER.error("while writting to "+fileName,ex);
}
}
示例4: close
import net.sf.saxon.trans.XPathException; //导入依赖的package包/类
@Override
public void close() throws XPathException {
super.close();
String fileName = getParameter(FILE_NAME).toString();
String value = getParameter(VALUE).toString();
String lineSeparator = getLineSeparator(getParameter(LINE_SEPARATOR));
Charset encoding = getCharset(getParameter(ENCODING));
File f = new File(fileName);
try {
FileOutputStream fos = new FileOutputStream(f, true);
try (OutputStreamWriter osw = new OutputStreamWriter(fos, encoding)) {
osw.append(value);
osw.append(lineSeparator);
osw.flush();
}
} catch(IOException ex) {
LOGGER.error("while writting to "+fileName,ex);
}
}
示例5: createVariableValue
import net.sf.saxon.trans.XPathException; //导入依赖的package包/类
private Value createVariableValue(ValueFacade facade) {
try {
return createValue(facade);
} catch (XPathException e) {
return new ErrorValue(e.getMessage(), facade);
}
}
示例6: iterate
import net.sf.saxon.trans.XPathException; //导入依赖的package包/类
public SequenceIterator iterate(XPathContext context) throws XPathException {
final SequenceIterator iterator = myVariable.iterate(context);
if (iterator instanceof EmptyIterator) {
final ValueRepresentation value = myVariable.evaluateVariable(context);
if (value instanceof Item) {
return SingletonIterator.makeIterator((Item)value);
} else if (value instanceof net.sf.saxon.value.Value) {
return ((net.sf.saxon.value.Value)value).iterate();
} else {
return iterator;
}
} else {
return iterator;
}
}
示例7: init
import net.sf.saxon.trans.XPathException; //导入依赖的package包/类
public static boolean init(Transformer transformer, final LocalDebugger dbg) {
if (transformer instanceof Controller) {
System.out.println("SAXON 9");
final Controller controller = (Controller)transformer;
((Saxon9TraceListener)controller.getConfiguration().getTraceListener()).setDebugger(dbg);
controller.getConfiguration().setLineNumbering(true);
controller.getConfiguration().setCompileWithTracing(true);
controller.getConfiguration().setMultiThreading(false);
controller.getConfiguration().setSerializerFactory(new SerializerFactory(controller.getConfiguration()) {
@Override
protected Receiver createXMLSerializer(Emitter emitter,
Properties props,
PipelineConfiguration pipe,
CharacterMapExpander characterMapExpander,
ProxyReceiver normalizer) throws XPathException {
return super.createXMLSerializer(emitter, props, pipe, characterMapExpander, normalizer);
}
@Override
protected Emitter newXMLEmitter() {
return new TracingOutputter(dbg.getEventQueue(), super.newXMLEmitter());
}
});
controller.getConfiguration().setDebugger(new Debugger() {
public SlotManager makeSlotManager() {
return new SlotManager() {
@Override
public int allocateSlotNumber(StructuredQName qName) {
System.out.println("qName = " + qName);
return super.allocateSlotNumber(qName);
}
};
}
});
return true;
}
return false;
}
示例8: makeCallExpression
import net.sf.saxon.trans.XPathException; //导入依赖的package包/类
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
private static final long serialVersionUID = 1L;
@Override
public Sequence call(XPathContext xPathContext, Sequence[] arguments) throws XPathException {
// 1st argument (mandatory, index 0)
StringValue arg1 = (StringValue) arguments[0].iterate().next();
String arg1Str = arg1.getStringValue();
// 2nd argument (optional, index 1)
String arg2Str = "";
if (arguments.length > 1) {
StringValue arg2 = (StringValue) arguments[1].iterate().next();
arg2Str = arg2.getStringValue();
}
// Functionality goes here
String resultStr = arg1Str + arg2Str;
Item result = new StringValue(resultStr);
return SequenceTool.toLazySequence(SingletonIterator.makeIterator(result));
}
};
}
示例9: makeCallExpression
import net.sf.saxon.trans.XPathException; //导入依赖的package包/类
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
private static final long serialVersionUID = 1L;
@Override
public Sequence call(XPathContext xPathContext, Sequence[] arguments) throws XPathException {
// 1st argument (mandatory, index 0)
Int64Value arg1 = (Int64Value) arguments[0].iterate().next();
int arg1Int = arg1.getDecimalValue().toBigInteger().intValue();
// 2nd argument (mandatory, index 1)
Int64Value arg2 = (Int64Value) arguments[1].iterate().next();
int arg2Int = arg2.getDecimalValue().toBigInteger().intValue();
// Functionality goes here
int resultInt = arg1Int + arg2Int;
Item result = new Int64Value(resultInt);
return SequenceTool.toLazySequence(SingletonIterator.makeIterator(result));
}
};
}
示例10: makeCallExpression
import net.sf.saxon.trans.XPathException; //导入依赖的package包/类
@Override
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
private static final long serialVersionUID = 1L;
@Override
public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
// get value of first arg passed to the function
Item arg1 = sequences[0].head();
String arg1Val = arg1.getStringValue();
// return a altered version of the first arg
return new StringValue("arg1[" + arg1Val + "]");
}
};
}
示例11: xslt
import net.sf.saxon.trans.XPathException; //导入依赖的package包/类
public static String xslt(String xmlInput, Controller controller) throws Exception {
String strResult = "";
try {
Source sourceInput = new StreamSource(new StringReader(xmlInput));
StringWriter outWriter = new StringWriter();
javax.xml.transform.Result result = new StreamResult(outWriter);
try {
controller.transform(sourceInput, result);
strResult = outWriter.getBuffer().toString();
} catch (XPathException err) {
if (!err.hasBeenReported()) {
err.printStackTrace();
}
throw new XPathException("Run-time errors were reported");
}
} catch (Exception e) {
throw e;
}
return strResult;
}
示例12: getStringValueOrNull
import net.sf.saxon.trans.XPathException; //导入依赖的package包/类
static String getStringValueOrNull(Sequence[] pArguments, int pIndex, String pFunctionName, boolean pStrict)
throws XPathException {
String lResult = null;
if(pArguments.length > pIndex) {
Item lItem = pArguments[pIndex].head();
if(!(lItem instanceof StringValue) && pStrict) {
throw new ExInternal("Argument " + (pIndex+1) + " to " + pFunctionName + " function must be a string.");
}
if(lItem != null) {
lResult = lItem.getStringValue();
}
}
return lResult;
}
示例13: serialize
import net.sf.saxon.trans.XPathException; //导入依赖的package包/类
@Override
public void serialize(OutputStream out, Properties params) throws HttpClientException {
// TODO: childs can be childs of http:body. Even if the 'http' prefix is
// in @exclude-result-prefixes, its namespace declaration is serialized
// in the output (I guess because http:body is still the parent of
// childs, so ns normalization requires it. How to do?
// TODO: Look for what Norm uses in Calabash. I know I saw a post from
// him on the Saxon mailing list on that subject...
Configuration config = myCtxt.getConfiguration();
try {
QueryResult.serializeSequence(myIt, config, out, params);
} catch (XPathException ex) {
throw new HttpClientException("Error serializing the single part body", ex);
}
}
示例14: call
import net.sf.saxon.trans.XPathException; //导入依赖的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());
}
}
示例15: resolveToString
import net.sf.saxon.trans.XPathException; //导入依赖的package包/类
public String resolveToString(List<Parameter> frameworkParameters) throws XPathException, TempContextException {
//logger.info("resolveToString: " + getScriptName());
final NodeInfo resolvedNode = resolve(frameworkParameters);
final String resolvedString = SaxonNodeWrapper.serializeNode(resolvedNode);
//logger.info(resolvedString);
return resolvedString;
}