@SuppressWarnings({ "unchecked", "rawtypes" }) public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { try { String path = ((AtomicSequence) arguments[0]) .getStringValue(); boolean result = (path.isEmpty()) ? true : new File(path) .exists(); return new BooleanValue(result, BuiltInAtomicType.BOOLEAN); } catch (Exception e) { throw new XPathException("pf:file-exists failed", e); } } };
/** * Return a hash code to support the equals() function */ public int computeHashCode() { if (value instanceof AtomicSequence) { return ((AtomicSequence) value).getSchemaComparable().hashCode(); } else { return super.computeHashCode(); } }
public AtomicValue next() throws XPathException { while (true) { if (results != null) { if (atomicPosition < results.getLength()) { return results.itemAt(atomicPosition++); } else { results = null; continue; } } AtomicSequence atomized = base.nextAtomizedValue(); if (atomized == null) { results = null; return null; } if (atomized instanceof AtomicValue) { // common case (the atomized value of the node is a single atomic value) results = null; return (AtomicValue) atomized; } else { results = atomized; atomicPosition = 0; // continue } } }
/** * Convert a string to the target type of this converter. * * @param input the string to be converted * @return either an {@link net.sf.saxon.value.AtomicValue} of the appropriate type for this converter (if conversion * succeeded), or a {@link net.sf.saxon.type.ValidationFailure} if conversion failed. */ @Override public ConversionResult convertString( CharSequence input) { try { return targetType.getTypedValue(input, null, rules).head(); } catch (ValidationException err) { return err.getValidationFailure(); } } }
final AtomicIterator v1 = n1.atomize().iterate(); final AtomicIterator v2 = n2.atomize().iterate(); return deepEqual(v1, v2, comparer, config.getConversionContext(), flags); ar = deepEqual(n1.atomize().iterate(), n2.atomize().iterate(), comparer, config.getConversionContext(), 0); } else { ar = comparer.comparesEqual( boolean vr = comparer.comparesEqual((AtomicValue) n1.atomize(), (AtomicValue) n2.atomize()); if (!vr && ((flags & WARNING_IF_FALSE) != 0)) { String v1 = n1.atomize().getStringValue(); String v2 = n2.atomize().getStringValue(); String message = ""; if (v1.length() != v2.length()) {
/** * Evaluate the expression */ /*@NotNull*/ //@Override public SequenceIterator<AtomicValue> iterate(XPathContext c) throws XPathException { GroupIterator gi = c.getCurrentMergeGroupIterator(); if (gi == null) { throw new XPathException("There is no current merge key", "XTDE3510"); } return gi.getCurrentGroupingKey().iterate(); }
/** * Ask whether an element is an ID element. (The represents the * is-id property in the data model) * * @param nr the element node whose is-id property is required * @return true if the node has the is-id property */ public boolean isIdElement(int nr) { try { return getSchemaType(nr).isIdType() && getTypedValueOfElement(nr).getLength() == 1; } catch (XPathException e) { return false; } }
/** * Convert a string to the target type of this converter. * * @param input the string to be converted * @return either an {@link net.sf.saxon.value.AtomicValue} of the appropriate type for this converter (if conversion * succeeded), or a {@link net.sf.saxon.type.ValidationFailure} if conversion failed. */ @Override public ConversionResult convertString( CharSequence input) { try { return targetType.getTypedValue(input, null, rules).head(); } catch (ValidationException err) { return err.getValidationFailure(); } } }
final AtomicIterator v1 = n1.atomize().iterate(); final AtomicIterator v2 = n2.atomize().iterate(); return deepEqual(v1, v2, comparer, config.getConversionContext(), flags); ar = deepEqual(n1.atomize().iterate(), n2.atomize().iterate(), comparer, config.getConversionContext(), 0); } else { ar = comparer.comparesEqual( boolean vr = comparer.comparesEqual((AtomicValue) n1.atomize(), (AtomicValue) n2.atomize()); if (!vr && ((flags & WARNING_IF_FALSE) != 0)) { String v1 = n1.atomize().getStringValue(); String v2 = n2.atomize().getStringValue(); String message = ""; if (v1.length() != v2.length()) {
public AtomicValue next() throws XPathException { while (true) { if (results != null) { if (atomicPosition < results.getLength()) { return results.itemAt(atomicPosition++); } else { results = null; continue; } } AtomicSequence atomized = base.nextAtomizedValue(); if (atomized == null) { results = null; return null; } if (atomized instanceof AtomicValue) { // common case (the atomized value of the node is a single atomic value) results = null; return (AtomicValue) atomized; } else { results = atomized; atomicPosition = 0; // continue } } }
/** * Evaluate the expression */ /*@NotNull*/ //@Override public SequenceIterator<AtomicValue> iterate(XPathContext c) throws XPathException { GroupIterator gi = c.getCurrentMergeGroupIterator(); if (gi == null) { throw new XPathException("There is no current merge key", "XTDE3510"); } return gi.getCurrentGroupingKey().iterate(); }
/** * Ask whether an element is an ID element. (The represents the * is-id property in the data model) * * @param nr the element node whose is-id property is required * @return true if the node has the is-id property */ public boolean isIdElement(int nr) { try { return getSchemaType(nr).isIdType() && getTypedValueOfElement(nr).getLength() == 1; } catch (XPathException e) { return false; } }
public static List<Object> itemToList(ArrayItem ai) throws XPathException { List<Object> result = new ArrayList<>(ai.arrayLength()); for (Sequence sq: ai) { result.add(itemToObject(sq.head().atomize().head())); } return result; }
public AtomicValue next() throws XPathException { while (true) { if (currentValue != null) { if (currentValuePosition < currentValueSize) { return currentValue.itemAt(currentValuePosition++); } else { currentValue = null; } } Item nextSource = base.next(); if (nextSource != null) { AtomicSequence v = nextSource.atomize(); if (v instanceof AtomicValue) { return (AtomicValue) v; } else { currentValue = v; currentValuePosition = 0; currentValueSize = currentValue.getLength(); // now go round the loop to get the first item from the atomized value } } else { currentValue = null; return null; } } }
/** * The typed value of a list-valued node is obtained by tokenizing the string value and * applying a mapping function to the sequence of tokens. * This method implements the mapping function. It is for internal use only. * For details see {@link net.sf.saxon.expr.MappingFunction} */ public AtomicIterator map(StringValue item) throws XPathException { try { return atomicType.getTypedValue(item.getStringValueCS(), resolver, rules).iterate(); } catch (ValidationException err) { throw new XPathException(err); } } }
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { try { Query query = query(((AtomicSequence)arguments[0]).getStringValue()); String[] text = sequenceToArray(arguments[1]); Hyphenator hyphenator; try { hyphenator = hyphenators.get(query).iterator().next(); } catch (NoSuchElementException e) { throw new RuntimeException("Could not find a hyphenator for query: " + query); } return arrayToSequence(hyphenator.asFullHyphenator().transform(text));} catch (Exception e) { throw new XPathException("louis:hyphenate failed", XProcException.javaError(e, 0)); } } };
/** * Return a hash code to support the equals() function */ public int computeHashCode() { if (value instanceof AtomicSequence) { return ((AtomicSequence) value).getSchemaComparable().hashCode(); } else { return super.computeHashCode(); } }
@Override public GroundedValue evaluate(Item item, XPathContext context) throws XPathException { SystemFunction f = SystemFunction.makeFunction(getDetails().name.getLocalPart(), getRetainedStaticContext(), 1); AtomicSequence val = item.atomize(); switch (val.getLength()) { case 0: return DoubleValue.NaN; case 1: return f.call(context, new Sequence[]{val.head()}).materialize(); default: XPathException err = new XPathException( "When number() is called with no arguments, the atomized value of the context node must " + "not be a sequence of several atomic values", "XPTY0004"); err.setIsTypeError(true); throw err; } }