net.sf.saxon.expr.XPathContext Java Examples
The following examples show how to use
net.sf.saxon.expr.XPathContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MyConcatExtensionFunctionDefinition.java From kite with Apache License 2.0 | 6 votes |
@Override public ExtensionFunctionCall makeCallExpression() { return new ExtensionFunctionCall() { @Override public Sequence call(XPathContext ctx, Sequence[] secs) throws XPathException { if (secs.length == 0) { throw new XPathException("Missing argument"); } else { StringBuilder buf = new StringBuilder(); for (Sequence seq : secs) { SequenceIterator<? extends Item> iter = seq.iterate(); while (iter.next() != null) { buf.append(iter.current().getStringValue()); } } return new StringValue(buf.toString()); } } }; }
Example #2
Source File: SaxonTraceListener.java From intellij-xquery with Apache License 2.0 | 6 votes |
@Override public void enter(InstructionInfo instructionInfo, XPathContext xPathContext) { log("enter [" + myToString(instructionInfo) + "]" + instructionInfo.toString() + " line: " + instructionInfo.getLineNumber() + " constructType: " + instructionInfo.getConstructType()); if (instructionInfo instanceof ClauseInfo) { log("entering clause info of clause: " + ((ClauseInfo) instructionInfo).getClause()); return; } if (is(instructionInfo, StandardNames.XSL_FUNCTION)) { log("exiting enter as this is a bit faulty frame"); return; } if (debugger.getStatus() != Status.BREAK) { DebugFrame currentFrame = debugger.getCurrentFrame(); logPreviousFrame(currentFrame); String currentFunctionName = functionNames.size() > 0 ? functionNames.peekLast() : null; if (isUserFunctionCall(instructionInfo)) { addNewFunctionNameToStack(instructionInfo); logFunctionNames(); } debugger.enter(new SaxonDebugFrame(instructionInfo, xPathContext, currentFunctionName, debugger.getMainModule())); } }
Example #3
Source File: TECore.java From teamengine with Apache License 2.0 | 6 votes |
public int execute_test(String testName, List<String> params, XdmNode contextNode) throws Exception { if (LOGR.isLoggable( FINE)) { String logMsg = String.format( "Preparing test %s for execution, using params:%n %s", testName, params); LOGR.fine(logMsg); } TestEntry test = index.getTest(testName); if (test == null) { throw new Exception("Error: Test " + testName + " not found."); } XdmNode paramsNode = engine.getBuilder().build( new StreamSource(new StringReader(getParamsXML(params)))); if (contextNode == null && test.usesContext()) { String contextNodeXML = "<context><value>" + test.getContext() + "</value></context>"; contextNode = engine.getBuilder().build( new StreamSource(new StringReader(contextNodeXML))); } XPathContext context = getXPathContext(test, opts.getSourcesName(), contextNode); return executeTest(test, paramsNode, context); }
Example #4
Source File: SaxonDebugFrame.java From intellij-xquery with Apache License 2.0 | 5 votes |
public SaxonDebugFrame(InstructionInfo instructionInfo, XPathContext xPathContext, String functionName, QueryModule mainModule) { final String uri = instructionInfo.getSystemId(); this.xPathContext = xPathContext; this.uri = uri != null ? uri.replaceAll(" ", "%20=") : null; this.functionName = functionName; this.evaluator = new SaxonExpressionEvaluator(xPathContext, mainModule, uri); lineNumber = instructionInfo.getLineNumber(); log("uri=" + uri + " lineNumber=" + lineNumber + " xpathcontext=" + xPathContext); }
Example #5
Source File: TEXSLFunctionCall.java From teamengine with Apache License 2.0 | 5 votes |
public static String getType(Expression expr, XPathContext context) throws XPathException { ValueRepresentation vr = ExpressionTool.lazyEvaluate(expr, context, 1); ItemType it = Value.asValue(vr).getItemType( context.getConfiguration().getTypeHierarchy()); if (it instanceof SchemaType) { return "xs:" + ((SchemaType) it).getName(); } return "xs:any"; }
Example #6
Source File: GetTypeFunctionCall.java From teamengine with Apache License 2.0 | 5 votes |
public SequenceIterator iterate(XPathContext context) throws XPathException { Expression[] argExpressions = getArguments(); ValueRepresentation vr = ExpressionTool.lazyEvaluate(argExpressions[0], context, 1); ItemType it = Value.asValue(vr).getItemType( context.getConfiguration().getTypeHierarchy()); String type = getTypeName(it); Value v = Value.convertJavaObjectToXPath(type, SequenceType.SINGLE_STRING, context); return v.iterate(); }
Example #7
Source File: TECore.java From teamengine with Apache License 2.0 | 5 votes |
public NodeInfo executeXSLFunction(XPathContext context, FunctionEntry fe, NodeInfo params) throws Exception { String oldFnPath = fnPath; CRC32 crc = new CRC32(); crc.update((fe.getPrefix() + fe.getId()).getBytes()); fnPath += Long.toHexString(crc.getValue()) + "/"; XdmNode n = executeTemplate(fe, S9APIUtils.makeNode(params), context); fnPath = oldFnPath; if (n == null) { return null; } return n.getUnderlyingNode(); }
Example #8
Source File: TECore.java From teamengine with Apache License 2.0 | 5 votes |
public XdmNode executeTemplate(TemplateEntry template, XdmNode params, XPathContext context) throws Exception { if (stop) { throw new Exception("Execution was stopped by the user."); } XsltExecutable executable = engine.loadExecutable(template, opts.getSourcesName()); XsltTransformer xt = executable.load(); XdmDestination dest = new XdmDestination(); xt.setDestination(dest); if (template.usesContext() && context != null) { xt.setSource((NodeInfo) context.getContextItem()); } else { xt.setSource(new StreamSource(new StringReader("<nil/>"))); } xt.setParameter(TECORE_QNAME, new ObjValue(this)); if (params != null) { xt.setParameter(TEPARAMS_QNAME, params); } // test may set global verdict, e.g. by calling ctl:fail if (LOGR.isLoggable( FINE)) { LOGR.log( FINE, "Executing TemplateEntry {0}" + template.getQName()); } xt.transform(); XdmNode ret = dest.getXdmNode(); if (ret != null && LOGR.isLoggable( FINE)) { LOGR.log( FINE, "Output:\n" + ret.toString()); } return ret; }
Example #9
Source File: TECore.java From teamengine with Apache License 2.0 | 5 votes |
XPathContext getXPathContext(TestEntry test, String sourcesName, XdmNode contextNode) throws Exception { XPathContext context = null; if (test.usesContext()) { XsltExecutable xe = engine.loadExecutable(test, sourcesName); Executable ex = xe.getUnderlyingCompiledStylesheet() .getExecutable(); context = new XPathContextMajor(contextNode.getUnderlyingNode(), ex); } return context; }
Example #10
Source File: TECore.java From teamengine with Apache License 2.0 | 4 votes |
/** * Runs a subtest as directed by a <ctl:call-test> instruction. * * @param context * The context in which the subtest is executed. * @param localName * The [local name] of the subtest. * @param namespaceURI * The [namespace name] of the subtest. * @param params * A NodeInfo object containing test parameters. * @param callId * A node identifier used to build a file path reference for the * test results. * @throws Exception * If an error occcurs while executing the test. */ public synchronized void callTest(XPathContext context, String localName, String namespaceURI, NodeInfo params, String callId) throws Exception { String key = "{" + namespaceURI + "}" + localName; TestEntry test = index.getTest(key); if (logger != null) { logger.println("<testcall path=\"" + testPath + "/" + callId + "\"/>"); logger.flush(); } if (opts.getMode() == Test.RESUME_MODE) { Document doc = LogUtils.readLog(opts.getLogDir(), testPath + "/" + callId); int result = LogUtils.getResultFromLog(doc); // TODO revise the following if (result >= 0) { out.println(indent + "Test " + test.getName() + " " + getResultDescription(result)); if (result == WARNING) { warning(); } else if (result == CONTINUE) { throw new IllegalStateException( "Error: 'continue' is not allowed when a test is called using 'call-test' instruction"); } else if (result != PASS) { inheritedFailure(); } return; } } String oldTestPath = testPath; testPath += "/" + callId; try{ this.verdict = executeTest(test, S9APIUtils.makeNode(params), context); } catch(Exception e){ } finally { testPath = oldTestPath; } if (this.verdict == CONTINUE) { throw new IllegalStateException( "Error: 'continue' is not allowed when a test is called using 'call-test' instruction"); } updateParentTestResult(test); testStack.pop(); }
Example #11
Source File: TECore.java From teamengine with Apache License 2.0 | 4 votes |
public void repeatTest(XPathContext context, String localName, String NamespaceURI, NodeInfo params, String callId, int count, int pause) throws Exception { String key = "{" + NamespaceURI + "}" + localName; TestEntry test = index.getTest(key); if (logger != null) { logger.println("<testcall path=\"" + testPath + "/" + callId + "\"/>"); logger.flush(); } if (opts.getMode() == Test.RESUME_MODE) { Document doc = LogUtils.readLog(opts.getLogDir(), testPath + "/" + callId); int result = LogUtils.getResultFromLog(doc); if (result >= 0) { out.println(indent + "Test " + test.getName() + " " + getResultDescription(result)); if (result == WARNING) { warning(); } else if (result != PASS) { inheritedFailure(); } return; } } int oldResult = verdict; String oldTestPath = testPath; testPath += "/" + callId; for (int i = 0; i < count; i++) { executeTest(test, S9APIUtils.makeNode(params), context); testPath = oldTestPath; if (verdict == FAIL && oldResult != FAIL) { // If the child result was FAIL and parent hasn't directly // failed, // set parent result to INHERITED_FAILURE verdict = INHERITED_FAILURE; return; } else if (verdict == CONTINUE) { // System.out.println("Pausing for..."+pause); if (pause > 0 && i < count - 1) { try { Thread.sleep(pause); } catch (Exception e) { e.printStackTrace(); } } } else if (verdict <= oldResult) { // Restore parent result if the child results aren't worse verdict = oldResult; return; } } verdict = FAIL; if (oldResult != FAIL) { // If the child result was FAIL and parent hasn't directly failed, // set parent result to INHERITED_FAILURE verdict = INHERITED_FAILURE; } }
Example #12
Source File: SaxonExpressionEvaluator.java From intellij-xquery with Apache License 2.0 | 4 votes |
@Override public XPathContext makeEarlyEvaluationContext() { return original.makeEarlyEvaluationContext(); }
Example #13
Source File: SaxonExpressionEvaluator.java From intellij-xquery with Apache License 2.0 | 4 votes |
public SaxonExpressionEvaluator(XPathContext xPathContext, QueryModule mainModule, String uri) { this.xPathContext = xPathContext; this.mainModule = mainModule; this.uri = uri; }
Example #14
Source File: MonitorServlet.java From teamengine with Apache License 2.0 | 4 votes |
static public String createMonitor(XPathContext context, String url, String localName, String namespaceURI, NodeInfo params, String callId, TECore core) throws Exception { return createMonitor(context, url, localName, namespaceURI, params, null, "", callId, core); }
Example #15
Source File: MonitorCall.java From teamengine with Apache License 2.0 | 4 votes |
public XPathContext getContext() { return context; }
Example #16
Source File: MonitorCall.java From teamengine with Apache License 2.0 | 4 votes |
public void setContext(XPathContext context) { this.context = context; }
Example #17
Source File: StrictRelativeResolvingStrategy.java From validator with Apache License 2.0 | 4 votes |
@Override public ResourceCollection findCollection(final XPathContext context, final String collectionURI) throws XPathException { throw new IllegalStateException(MESSAGE); }