/** * Converts the given string value to upper case using an optional Locale * * @param strArg the value which gets converted to a String * @param locale the Locale to use for the conversion or null if * English should be used * @param nav the Navigator to use */ public static String evaluate(Object strArg, Locale locale, Navigator nav) { String str = StringFunction.evaluate( strArg, nav ); // it might be possible to use the xml:lang attribute to // pick a default locale if (locale == null) locale = Locale.ENGLISH; return str.toUpperCase(locale); } }
/** * Converts the given string value to lower case using an optional Locale * * @param strArg the value which gets converted to a String * @param locale the Locale to use for the conversion or null * English should be used * @param nav the Navigator to use */ public static String evaluate(Object strArg, Locale locale, Navigator nav) { String str = StringFunction.evaluate( strArg, nav ); // it might be possible to use the xml:lang attribute to // pick a default locale if (locale == null) locale = Locale.ENGLISH; return str.toLowerCase(locale); } }
/** * Returns true if the string-value of <code>strArg</code> * starts with the string-value of <code>matchArg</code>. * Otherwise it returns false. * * @param strArg the object whose string-value searched for the prefix * @param matchArg the object whose string-value becomes the prefix string to compare against * @param nav the navigator used to calculate the string-values of the arguments * * @return <code>Boolean.TRUE</code> if the string-value of <code>strArg</code> * starts with the string-value of <code>matchArg</code>; * otherwise <code>Boolean.FALSE</code> * */ public static Boolean evaluate(Object strArg, Object matchArg, Navigator nav) { String str = StringFunction.evaluate( strArg, nav ); String match = StringFunction.evaluate( matchArg, nav ); return ( str.startsWith(match) ? Boolean.TRUE : Boolean.FALSE ); }
/** * <p>Returns true if the first string contains the second string; false otherwise. * If necessary one or both arguments are converted to a string as if by the XPath * <code>string()</code> function. * </p> * * @param strArg the containing string * @param matchArg the contained string * @param nav used to calculate the string-values of the first two arguments * * @return <code>Boolean.TRUE</code> if true if the first string contains * the second string; <code>Boolean.FALSE</code> otherwise. */ public static Boolean evaluate(Object strArg, Object matchArg, Navigator nav) { String str = StringFunction.evaluate( strArg, nav ); String match = StringFunction.evaluate( matchArg, nav ); return ( ( str.indexOf(match) >= 0) ? Boolean.TRUE : Boolean.FALSE ); } }
private static Boolean evaluate(List contextNodes, Object lang, Navigator nav) throws UnsupportedAxisException { return evaluate(contextNodes.get(0), StringFunction.evaluate(lang, nav), nav) ? Boolean.TRUE : Boolean.FALSE; }
/** * Converts each item in the list to a string and returns the * concatenation of these strings. * If necessary, each item is first converted to a <code>String</code> * as if by the XPath <code>string()</code> function. * * @param list the items to be concatenated * @param nav ignored * * @return the concatenation of the arguments */ public static String evaluate(List list, Navigator nav) { StringBuffer result = new StringBuffer(); Iterator argIter = list.iterator(); while ( argIter.hasNext() ) { result.append( StringFunction.evaluate( argIter.next(), nav ) ); } return result.toString(); } }
public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 1) { Navigator nav = context.getNavigator(); String url = StringFunction.evaluate( args.get( 0 ), nav ); return evaluate( url, nav ); } throw new FunctionCallException( "document() requires one argument." ); }
Iterator iter = ((List)arg).iterator(); while (iter.hasNext()) { String id = StringFunction.evaluate(iter.next(), nav); nodes.addAll( evaluate( contextNodes, id, nav ) ); String ids = StringFunction.evaluate(arg, nav); StringTokenizer tok = new StringTokenizer(ids, " \t\n\r"); while (tok.hasMoreTokens()) {
String text = StringFunction.evaluate( value, navigator ); if (text != null && text.length() > 0)
/** * Returns the string-value of <code>args.get(0)</code> * or of the context node if <code>args</code> is empty. * * @param context the context at the point in the * expression where the function is called * @param args list with zero or one element * * @return a <code>String</code> * * @throws FunctionCallException if <code>args</code> has more than one item */ public Object call(Context context, List args) throws FunctionCallException { int size = args.size(); if ( size == 0 ) { return evaluate( context.getNodeSet(), context.getNavigator() ); } else if ( size == 1 ) { return evaluate( args.get(0), context.getNavigator() ); } throw new FunctionCallException( "string() takes at most argument." ); }
String str = StringFunction.evaluate( obj, nav );
Navigator nav) String str = StringFunction.evaluate( strArg, nav );
/** Retrieves the string-value of the result of * evaluating this XPath expression when evaluated * against the specified context. * * <p> * The string-value of the expression is determined per * the <code>string(..)</code> core function defined * in the XPath specification. This means that an expression * that selects zero nodes will return the empty string, * while an expression that selects one-or-more nodes will * return the string-value of the first node. * </p> * * @param node the node, node-set or Context object for evaluation. This value can be null. * * @return the string-value of the result of evaluating this expression with the specified context node * @throws JaxenException if an XPath error occurs during expression evaluation */ public String stringValueOf(Object node) throws JaxenException { Context context = getContext( node ); Object result = selectSingleNodeForContext( context ); if ( result == null ) { return ""; } return StringFunction.evaluate( result, context.getNavigator() ); }
private boolean evaluateObjectObject( Object lhs, Object rhs, Navigator nav ) { if( eitherIsBoolean( lhs, rhs ) ) { return evaluateObjectObject( BooleanFunction.evaluate( lhs, nav ), BooleanFunction.evaluate( rhs, nav ) ); } else if( eitherIsNumber( lhs, rhs ) ) { return evaluateObjectObject( NumberFunction.evaluate( lhs, nav ), NumberFunction.evaluate( rhs, nav ) ); } else { return evaluateObjectObject( StringFunction.evaluate( lhs, nav ), StringFunction.evaluate( rhs, nav ) ); } }
public static List evaluate (Context context, Object arg) throws FunctionCallException { List contextNodes = context.getNodeSet(); if (contextNodes.size() == 0) return Collections.EMPTY_LIST; Navigator nav = context.getNavigator(); String xpathString; if ( arg instanceof String ) xpathString = (String)arg; else xpathString = StringFunction.evaluate(arg, nav); try { XPath xpath = nav.parseXPath(xpathString); ContextSupport support = context.getContextSupport(); xpath.setVariableContext( support.getVariableContext() ); xpath.setFunctionContext( support.getFunctionContext() ); xpath.setNamespaceContext( support.getNamespaceContext() ); return xpath.selectNodes( context.duplicate() ); } catch ( org.jaxen.saxpath.SAXPathException e ) { throw new FunctionCallException(e.toString()); } } }