void writeformattedItem(XdmItem item, ProcessContext context, OutputStream out) throws TransformerFactoryConfigurationError, TransformerException, IOException { if (item.isAtomicValue()) { out.write(item.getStringValue().getBytes(UTF8)); } else { // item is an XdmNode XdmNode node = (XdmNode) item; switch (node.getNodeKind()) { case DOCUMENT: case ELEMENT: Transformer transformer = TransformerFactory.newInstance().newTransformer(); final Properties props = getTransformerProperties(context); transformer.setOutputProperties(props); transformer.transform(node.asSource(), new StreamResult(out)); break; default: out.write(node.getStringValue().getBytes(UTF8)); } } }
/** * Get the underlying implementation object representing the value. This method allows * access to lower-level Saxon functionality, including classes and methods that offer * no guarantee of stability across releases. * * @return the underlying implementation object representing the value * @since 9.8 (previously inherited from XdmValue which returns a Sequence) */ @Override public NodeInfo getUnderlyingValue() { return (NodeInfo) super.getUnderlyingValue(); }
/** * Construct an XdmItem as a wrapper around an existing Saxon Item object * * @param item the Item object to be wrapped. This can be retrieved using the * {@link #getUnderlyingValue} method. * @throws NullPointerException if item is null * @since 9.5 (previously a protected constructor) */ public XdmItem(Item<?> item) { super(); setValue(item); }
@Override protected String makeResult(List<XdmItem> list) { return list.get(0).getStringValue(); } };
/** * Get an ItemType representing the type of a supplied XdmItem. If the supplied item is * an atomic value, the returned ItemType will reflect the most specific atomic type of the * item. If the supplied item is a node, the returned item type will reflect the node kind, * and if the node has a name, then its name. It will not reflect the type annotation. * * @param item the supplied item whose type is required * @return the type of the supplied item */ public ItemType getItemType(XdmItem item) { if (item.isAtomicValue()) { AtomicValue value = (AtomicValue) item.getUnderlyingValue(); AtomicType type = value.getItemType(); return new ConstructedItemType(type, processor); } else { NodeInfo node = (NodeInfo) item.getUnderlyingValue(); int kind = node.getNodeKind(); if (node.getLocalPart().isEmpty()) { return new ConstructedItemType(NodeKindTest.makeNodeKindTest(kind), processor); } else { return new ConstructedItemType(new SameNameTest(node), processor); } } }
protected void addResult(NamedList<Object> xpathResults, XdmItem item) throws SaxonApiException { if (item.isAtomicValue()) {
@Override public void collect(int docId) throws IOException { Document doc = this.context.reader().document(docId); BytesRef binaryValue = doc.getBinaryValue(LUX_XML_FIELD_NAME); if (binaryValue != null) { byte[] bytes = binaryValue.bytes; // Assuming the lux_xml field is configured to use the Lux TinyBinary xml format in the // Lux update chain if (bytes.length > 4 && bytes[0] == 'T' && bytes[1] == 'I' && bytes[2] == 'N') { TinyBinary tb = new TinyBinary(bytes, TinyBinaryField.UTF8); XdmNode node = new XdmNode(tb.getTinyDocument(config)); try { selector.setContextItem(node); XdmItem result = selector.evaluateSingle(); if (result != null && result.size() > 0 && !(result.isAtomicValue() && !((XdmAtomicValue) result).getBooleanValue())) { super.collect(docId); } } catch (SaxonApiException e) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Unable to evaluate xpath: " + xpath, e); } } } } }
/** * Get the context item used for evaluating the XPath expression. * This may be either a node or an atomic value. Most commonly it will be a document node, * which might be constructed using the Build method of the DocumentBuilder object. * * @return The context item for evaluating the expression, or null if no context item * has been set. */ public XdmItem getContextItem() { return XdmItem.wrapItem(dynamicContext.getContextItem()); }
/** * Factory method to construct an "external object". This is an XDM value that wraps a Java * object. Such values can be passed as parameters to stylesheets or queries, for use in conjunction * with external (extension) functions. * <p>Changed in Saxon 9.5 to return XdmItem rather than XdmAtomicValue, since wrapped * external objects are now modelled as a separate type of item, rather than as an atomic value.</p> * * @param object the value to be wrapped as an external object. Must not be null. * @return the object, wrapped as an XdmItem */ public XdmItem getExternalObject(Object object) { return (XdmItem) XdmItem.wrap(new ObjectValue<>(object)); }
/** * Obtain a predicate that tests whether the result of applying the XPath string() function to an item * is equal to a given string * * @param value the string being tested * @return a Predicate which returns true if the string value of the item being tested * is equal to the given string under Java comparison rules for comparing strings. */ public static Predicate<XdmItem> eq(String value) { return item -> item.getStringValue().equals(value); }
/** * Get an ItemType representing the type of a supplied XdmItem. If the supplied item is * an atomic value, the returned ItemType will reflect the most specific atomic type of the * item. If the supplied item is a node, the returned item type will reflect the node kind, * and if the node has a name, then its name. It will not reflect the type annotation. * * @param item the supplied item whose type is required * @return the type of the supplied item */ public ItemType getItemType(XdmItem item) { if (item.isAtomicValue()) { AtomicValue value = (AtomicValue) item.getUnderlyingValue(); AtomicType type = value.getItemType(); return new ConstructedItemType(type, processor); } else { NodeInfo node = (NodeInfo) item.getUnderlyingValue(); int kind = node.getNodeKind(); if (node.getLocalPart().isEmpty()) { return new ConstructedItemType(NodeKindTest.makeNodeKindTest(kind), processor); } else { return new ConstructedItemType(new SameNameTest(node), processor); } } }
continue; if (count == 1 && !xpathResult.isAtomicValue()) { net.sf.saxon.s9api.QName name = ((XdmNode)xpathResult).getNodeName(); if (name != null && name.getNamespaceURI().equals(EXPATH_HTTP_NS) &&
/** * Get the context item used for evaluating the XPath expression. * This may be either a node or an atomic value. Most commonly it will be a document node, * which might be constructed using the Build method of the DocumentBuilder object. * * @return The context item for evaluating the expression, or null if no context item * has been set. */ public XdmItem getContextItem() { return XdmItem.wrapItem(dynamicContext.getContextItem()); }
/** * Factory method to construct an "external object". This is an XDM value that wraps a Java * object. Such values can be passed as parameters to stylesheets or queries, for use in conjunction * with external (extension) functions. * <p>Changed in Saxon 9.5 to return XdmItem rather than XdmAtomicValue, since wrapped * external objects are now modelled as a separate type of item, rather than as an atomic value.</p> * * @param object the value to be wrapped as an external object. Must not be null. * @return the object, wrapped as an XdmItem */ public XdmItem getExternalObject(Object object) { return (XdmItem) XdmItem.wrap(new ObjectValue<>(object)); }
/** * Writes the content of an XdmValue sequence to a string. Each item in the * sequence is either an atomic value or a node. * * @param value A value in the XDM data model. * @return A String representing the content of the sequence. * * @see * <a target="_blank" href="http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/XdmValue.html">Saxon * API: XdmValue</a> * @see * <a target="_blank" href="http://www.w3.org/TR/xpath-datamodel/">XQuery * 1.0 and XPath 2.0 Data Model (XDM) (Second Edition)</a> */ public static String writeXdmValueToString(XdmValue value) { StringBuilder str = new StringBuilder(); for (XdmItem item : value) { if (item.isAtomicValue()) { str.append(item.getStringValue()); } else { XdmNode node = (XdmNode) item; str.append(node.getNodeName()).append(": "); str.append(node.getStringValue()); } str.append('\n'); } return str.toString(); }
@Override protected String makeResult(List<XdmItem> list) { return list.get(0).getStringValue(); } };
if (LOG.isTraceEnabled()) { LOG.trace("XQuery result sequence item #{} is of class: {} with value: {}", new Object[] { i, item.getUnderlyingValue().getClass().getName(), item }); if (item.isAtomicValue()) { LOG.debug("Ignoring atomic value in result sequence: {}", item); continue;
/** * Get the underlying implementation object representing the value. This method allows * access to lower-level Saxon functionality, including classes and methods that offer * no guarantee of stability across releases. * * @return the underlying implementation object representing the value * @since 9.8 (previously inherited from XdmValue which returns a Sequence) */ @Override public AtomicValue getUnderlyingValue() { return (AtomicValue)super.getUnderlyingValue(); }
if (xdmItem.isAtomicValue()) { itemType = getItemType(xdmItem, cachedProcessor); if (itemType == null) {
/** * Get the context item used for evaluating the XPath expression. * This may be either a node or an atomic value. Most commonly it will be a document node, * which might be constructed using the Build method of the DocumentBuilder object. * * @return The context item for evaluating the expression, or null if no context item * has been set. */ public XdmItem getContextItem() { return XdmItem.wrapItem(dynamicContext.getContextItem()); }