Java Code Examples for org.apache.xpath.objects.XObject#str()
The following examples show how to use
org.apache.xpath.objects.XObject#str() .
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: XalanXPathExecuter.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Object selectObject(Node contextNode, String expression) throws JRException { try { Object value; XObject object = xpathAPI.eval(contextNode, expression); switch (object.getType()) { case XObject.CLASS_NODESET: value = object.nodeset().nextNode(); break; case XObject.CLASS_BOOLEAN: value = object.bool(); break; case XObject.CLASS_NUMBER: value = object.num(); break; default: value = object.str(); break; } return value; } catch (TransformerException e) { throw new JRException( EXCEPTION_MESSAGE_KEY_XPATH_SELECTION_FAILURE, new Object[]{expression}, e); } }
Example 2
Source File: XalanNsAwareXPathExecuter.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Object selectObject(Node contextNode, String expression) throws JRException { try { createNamespaceElement(contextNode, expression); Object value; XObject object = null; if (namespaceElement != null) { object = xpathAPI.eval(contextNode, expression, namespaceElement); } else { object = xpathAPI.eval(contextNode, expression); } switch (object.getType()) { case XObject.CLASS_NODESET: value = object.nodeset().nextNode(); break; case XObject.CLASS_BOOLEAN: value = object.bool(); break; case XObject.CLASS_NUMBER: value = object.num(); break; default: value = object.str(); break; } return value; } catch (TransformerException e) { throw new JRException( EXCEPTION_MESSAGE_KEY_XPATH_SELECTION_FAILURE, new Object[]{expression}, e); } }
Example 3
Source File: XPathImpl.java From j2objc with Apache License 2.0 | 5 votes |
private Object getResultAsType( XObject resultObject, QName returnType ) throws javax.xml.transform.TransformerException { // XPathConstants.STRING if ( returnType.equals( XPathConstants.STRING ) ) { return resultObject.str(); } // XPathConstants.NUMBER if ( returnType.equals( XPathConstants.NUMBER ) ) { return new Double ( resultObject.num()); } // XPathConstants.BOOLEAN if ( returnType.equals( XPathConstants.BOOLEAN ) ) { return new Boolean( resultObject.bool()); } // XPathConstants.NODESET ---ORdered, UNOrdered??? if ( returnType.equals( XPathConstants.NODESET ) ) { return resultObject.nodelist(); } // XPathConstants.NODE if ( returnType.equals( XPathConstants.NODE ) ) { NodeIterator ni = resultObject.nodeset(); //Return the first node, or null return ni.nextNode(); } String fmsg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE, new Object[] { returnType.toString()}); throw new IllegalArgumentException( fmsg ); }
Example 4
Source File: XPathExpressionImpl.java From j2objc with Apache License 2.0 | 5 votes |
private Object getResultAsType( XObject resultObject, QName returnType ) throws javax.xml.transform.TransformerException { // XPathConstants.STRING if ( returnType.equals( XPathConstants.STRING ) ) { return resultObject.str(); } // XPathConstants.NUMBER if ( returnType.equals( XPathConstants.NUMBER ) ) { return new Double ( resultObject.num()); } // XPathConstants.BOOLEAN if ( returnType.equals( XPathConstants.BOOLEAN ) ) { return new Boolean( resultObject.bool()); } // XPathConstants.NODESET ---ORdered, UNOrdered??? if ( returnType.equals( XPathConstants.NODESET ) ) { return resultObject.nodelist(); } // XPathConstants.NODE if ( returnType.equals( XPathConstants.NODE ) ) { NodeIterator ni = resultObject.nodeset(); //Return the first node, or null return ni.nextNode(); } // If isSupported check is already done then the execution path // shouldn't come here. Being defensive String fmsg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE, new Object[] { returnType.toString()}); throw new IllegalArgumentException ( fmsg ); }
Example 5
Source File: ElemCopyOf.java From j2objc with Apache License 2.0 | 4 votes |
/** * The xsl:copy-of element can be used to insert a result tree * fragment into the result tree, without first converting it to * a string as xsl:value-of does (see [7.6.1 Generating Text with * xsl:value-of]). * * @param transformer non-null reference to the the current transform-time state. * * @throws TransformerException */ public void execute( TransformerImpl transformer) throws TransformerException { try { XPathContext xctxt = transformer.getXPathContext(); int sourceNode = xctxt.getCurrentNode(); XObject value = m_selectExpression.execute(xctxt, sourceNode, this); SerializationHandler handler = transformer.getSerializationHandler(); if (null != value) { int type = value.getType(); String s; switch (type) { case XObject.CLASS_BOOLEAN : case XObject.CLASS_NUMBER : case XObject.CLASS_STRING : s = value.str(); handler.characters(s.toCharArray(), 0, s.length()); break; case XObject.CLASS_NODESET : // System.out.println(value); DTMIterator nl = value.iter(); // Copy the tree. DTMTreeWalker tw = new TreeWalker2Result(transformer, handler); int pos; while (DTM.NULL != (pos = nl.nextNode())) { DTM dtm = xctxt.getDTMManager().getDTM(pos); short t = dtm.getNodeType(pos); // If we just copy the whole document, a startDoc and endDoc get // generated, so we need to only walk the child nodes. if (t == DTM.DOCUMENT_NODE) { for (int child = dtm.getFirstChild(pos); child != DTM.NULL; child = dtm.getNextSibling(child)) { tw.traverse(child); } } else if (t == DTM.ATTRIBUTE_NODE) { SerializerUtils.addAttribute(handler, pos); } else { tw.traverse(pos); } } // nl.detach(); break; case XObject.CLASS_RTREEFRAG : SerializerUtils.outputResultTreeFragment( handler, value, transformer.getXPathContext()); break; default : s = value.str(); handler.characters(s.toCharArray(), 0, s.length()); break; } } // I don't think we want this. -sb // if (transformer.getDebug()) // transformer.getTraceManager().fireSelectedEvent(sourceNode, this, // "endSelect", m_selectExpression, value); } catch(org.xml.sax.SAXException se) { throw new TransformerException(se); } }