net.sf.saxon.om.SequenceIterator Java Examples
The following examples show how to use
net.sf.saxon.om.SequenceIterator.
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: SaxonExpressionEvaluator.java From intellij-xquery with Apache License 2.0 | 6 votes |
public Optional<Variable> eval(String expressionString) { QueryModule evaluatedModule = getModule(); StaticContext wrappingContext = wrapContext(evaluatedModule); if (wrappingContext != null) { try { Expression expression = ExpressionTool.make(expressionString, wrappingContext, 0, Token.EOF, null); final ExpressionVisitor visitor = ExpressionVisitor.make(wrappingContext); expression = expression.typeCheck(visitor, new ContextItemStaticInfo(Type.ITEM_TYPE, true)); SlotManager stackFrameMap = xPathContext.getStackFrame().getStackFrameMap(); final int variables = stackFrameMap.getNumberOfVariables(); ExpressionTool.allocateSlots(expression, variables, stackFrameMap); final SequenceIterator it = expression.iterate(xPathContext); String[] sequenceValue = SaxonItemConverter.getSequenceValue(it); if (sequenceValue != null) { return Optional.of(new Variable("evalResult", sequenceValue[1], sequenceValue[0])); } else { return Optional.empty(); } } catch (AssertionError | Exception e) { System.err.println("Unable to evaluate: '" + expressionString + "'"); e.printStackTrace(); return Optional.empty(); } } return Optional.empty(); }
Example #2
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 #3
Source File: SaxonItemConverter.java From intellij-xquery with Apache License 2.0 | 5 votes |
public static String[] getSequenceValue(SequenceIterator iterator) { String type = "item()"; try { List<String> sequenceItems = new ArrayList<>(); Item next = iterator.next(); if (next != null && next instanceof AtomicValue) { type = ((AtomicValue) next).getPrimitiveType().getPrimitiveItemType().toString(); } else if (next != null && next instanceof HashTrieMap) { type = "map(*)"; } while (next != null) { sequenceItems.add(itemToString(next)); next = iterator.next(); } StringBuilder sb = new StringBuilder(); int numberOfSequenceItems = sequenceItems.size(); if (numberOfSequenceItems > 1) { sb.append("("); } for (int i = 0; i < numberOfSequenceItems; i++) { sb.append(sequenceItems.get(i)); if (i < numberOfSequenceItems - 1) { sb.append(", "); } } if (numberOfSequenceItems > 1) { sb.append(")"); type = type + "*"; } return new String[]{sb.toString(), type}; } catch (XPathException e) { return null; } }
Example #4
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(); }