public Object getDocument(String url) throws FunctionCallException { try { SAXBuilder builder = new SAXBuilder(); return builder.build( url ); } catch (Exception e) { throw new FunctionCallException( e.getMessage() ); } } }
/** * <p> * Returns the number of nodes in the specified node-set. * </p> * * @param obj a <code>List</code> of nodes * @return the integral number of items in the list * @throws FunctionCallException if obj is not a <code>List</code> */ public static Double evaluate(Object obj) throws FunctionCallException { if (obj instanceof List) { return new Double( ((List) obj).size() ); } throw new FunctionCallException("count() function can only be used for node-sets"); }
public Object getDocument(String uri) throws FunctionCallException { try { return getSAXReader().read( uri ); } catch (DocumentException e) { throw new FunctionCallException("Failed to parse document for URI: " + uri, e); } }
public Object call( Context context, List args ) throws FunctionCallException { if ( args.size() == 1 ) { return evaluate( context, args.get(0)); } throw new FunctionCallException( "evaluate() requires one argument" ); }
public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 2) { return evaluate( args.get(0), args.get(1), context.getNavigator() ); } throw new FunctionCallException( "ends-with() requires two arguments." ); }
/** Returns <code>Boolean.TRUE</code> * * @param context ignored * @param args an empty list * * @return <code>Boolean.TRUE</code> * * @throws FunctionCallException if <code>args</code> is not empty */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 0) { return evaluate(); } throw new FunctionCallException( "true() requires no arguments." ); }
/** Returns <code>Boolean.FALSE</code> * * @param context the context at the point in the * expression when the function is called * @param args an empty list * * @return <code>Boolean.FALSE</code> * * @throws FunctionCallException if <code>args</code> is not empty */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 0) { return evaluate(); } throw new FunctionCallException( "false() requires no arguments." ); }
/** * <p> * Returns the number of nodes in the specified node-set. * </p> * @param context ignored * @param args the function arguments * * @return a <code>Double</code> giving the integral number of items in the first argument * * @throws FunctionCallException if args does not have exactly one * item; or that item is not a <code>List</code> */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 1) { return evaluate( args.get(0) ); } throw new FunctionCallException( "count() requires one argument." ); }
/** * Returns the position of the context node in the context node-set. * * @param context the context at the point in the * expression where the function is called * @param args an empty list * * @return a <code>Double</code> containing the context position * * @throws FunctionCallException if <code>args</code> is not empty * * @see Context#getSize() */ public Object call(Context context, List args) throws FunctionCallException { if ( args.size() == 0 ) { return evaluate( context ); } throw new FunctionCallException( "position() does not take any arguments." ); }
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." ); }
/** Returns the smallest integer greater than or equal to a number. * * @param context the context at the point in the * expression when the function is called * @param args a list with exactly one item which will be converted to a * <code>Double</code> as if by the XPath <code>number()</code> function * * @return a <code>Double</code> containing the smallest integer greater than or equal * <code>args.get(0)</code> * * @throws FunctionCallException if <code>args</code> has more or less than one item */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 1) { return evaluate( args.get(0), context.getNavigator() ); } throw new FunctionCallException("ceiling() requires one argument."); }
/** Convert the argument to a <code>Boolean</code> * * @param context the context at the point in the * expression when the function is called * @param args a list with exactly one item which will be converted to a * <code>Boolean</code> * * @return the result of evaluating the function; * <code>Boolean.TRUE</code> or <code>Boolean.FALSE</code> * * @throws FunctionCallException if <code>args</code> has more or less than one item */ public Object call(Context context, List args) throws FunctionCallException { if ( args.size() == 1 ) { return evaluate( args.get(0), context.getNavigator() ); } throw new FunctionCallException("boolean() requires one argument"); }
/** Returns the sum of its arguments. * * @param context the context at the point in the * expression when the function is called * @param args a list that contains exactly one item, also a <code>List</code> * * @return a <code>Double</code> containing the sum of the items in <code>args.get(0)</code> * * @throws FunctionCallException if <code>args</code> has more or less than one item; * or if the first argument is not a <code>List</code> */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 1) { return evaluate( args.get(0), context.getNavigator() ); } throw new FunctionCallException( "sum() requires one argument." ); }
/** Returns the nearest integer to the number. * * @param context the context at the point in the * expression when the function is called * @param args a list with exactly one item which will be converted to a * <code>Double</code> as if by the XPath <code>number()</code> function * * @return a <code>Double</code> containing the integer nearest to * <code>args.get(0)</code> * * @throws FunctionCallException if <code>args</code> has more or less than one item */ public Object call(Context context, List args) throws FunctionCallException { if (args.size() == 1) { return evaluate( args.get(0), context.getNavigator() ); } throw new FunctionCallException( "round() requires one argument." ); }
public Object call(Context context, List args) throws FunctionCallException { Navigator navigator = context.getNavigator(); int size = args.size(); if (size > 0) { Object text = args.get(0); Locale locale = null; if (size > 1) { locale = getLocale( args.get(1), navigator ); } return evaluate( text, locale, navigator ); } throw new FunctionCallException( "upper-case() requires at least one argument." ); }
public Object call(Context context, List args) throws FunctionCallException { Navigator navigator = context.getNavigator(); int size = args.size(); if (size > 0) { Object text = args.get(0); Locale locale = null; if (size > 1) { locale = getLocale( args.get(1), navigator ); } return evaluate( text, locale, navigator ); } throw new FunctionCallException( "lower-case() requires at least one argument." ); }
/** * Concatenates the arguments and returns the resulting string. * Non-string items are first converted to strings as if by the * XPath <code>string()<code> function. * * @param context the context at the point in the * expression when the function is called * @param args the list of strings to be concatenated * * @return a <code>String</code> containing the concatenation of the items * of <code>args</code> * * @throws FunctionCallException if <code>args</code> has less than two items */ public Object call(Context context, List args) throws FunctionCallException { if ( args.size() >= 2 ) { return evaluate( args, context.getNavigator() ); } throw new FunctionCallException("concat() requires at least two arguments"); }
/** * Returns a list of the nodes with the specified IDs. * * @param context the context at the point in the * expression when the function is called * @param args a list with exactly one item which is either a string * a node-set * * @return a <code>List</code> containing the first node in document * with each of the specified IDs; or * an empty list if there are no such nodes * * @throws FunctionCallException if <code>args</code> has more or less than one item */ public Object call(Context context, List args) throws FunctionCallException { if ( args.size() == 1 ) { return evaluate( context.getNodeSet(), args.get(0), context.getNavigator() ); } throw new FunctionCallException( "id() requires one argument" ); }
@Override public Object getDocument(String uri) throws FunctionCallException { try { Template raw = getTemplate(uri); Document doc = (Document) FM_DOM_NAVIAGOTOR_CACHED_DOM.get(raw); if (doc == null) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); FmEntityResolver er = new FmEntityResolver(); builder.setEntityResolver(er); doc = builder.parse(createInputSource(null, raw)); // If the entity resolver got called 0 times, the document // is standalone, so we can safely cache it if (er.getCallCount() == 0) { FM_DOM_NAVIAGOTOR_CACHED_DOM.set(doc, raw); } } return doc; } catch (Exception e) { throw new FunctionCallException("Failed to parse document for URI: " + uri, e); } } };
public Object getDocument(String s) throws FunctionCallException { try { return new Builder(new NodeFactory()).build(s); } catch (Exception pe) { throw new FunctionCallException(pe); } }