private CustomFunctionsLibrary() { this.converterLibrary = new FunctionLibrary(); }
public void addConverterFunctions(Functions functions) { this.converterLibrary.addFunctions(functions); } }
/** * Returns a set containing all namespaces used by the aggregated * Functions. * @return Set<String> */ public Set getUsedNamespaces() { if (byNamespace == null) { prepareCache(); } return byNamespace.keySet(); }
/** * Create root jxpath configuration */ public JXPathHelperConfiguration(Configuration config) throws ConfigurationException { this.lenient = config.getChild("lenient").getValueAsBoolean(true); this.library = new FunctionLibrary(); setup(config); // the following is necessary to be able to use methods on objects without // explicitely registering extension functions (see PackageFunctions javadoc) this.library.addFunctions(new PackageFunctions("", null)); }
/** * Create child jxpath configuration */ public JXPathHelperConfiguration(JXPathHelperConfiguration global, Configuration config) throws ConfigurationException { this.lenient = global.lenient; this.library = new FunctionLibrary(); this.library.addFunctions(global.getLibrary()); if (global.getNamespaces() != null) { this.namespaces = new HashMap(global.getNamespaces()); } setup(config); }
/** access the jxpath context object for this object (lazily initialized) * @modified NWW - renamed, to avoid using 'get*' naming convention - otherwise * is accessed when traversing the tree, which leads to recursion and out of memory errors.*/ public final synchronized JXPathContext accessJXPathContext() { if (cxt == null) { this.cxt = JXPathContext.newContext(this); this.cxt.setLenient(true); FunctionLibrary lib = new FunctionLibrary(); this.cxt.setFunctions(lib); lib.addFunctions(new ClassFunctions(BaseBean.Fns.class,"fn")); } return cxt; } /** add a new funciton library to the xpath interpreter */
/** add a new funciton library to the xpath interpreter */ public final void addFunctions(Functions fn) { ((FunctionLibrary)accessJXPathContext().getFunctions()).addFunctions(fn); } /** execute an xpath query, using thiis object as the root of an object graph
Object[] parameters) { if (byNamespace == null) { prepareCache();
@Override public FunctionLibrary getScriptFunctions(IScriptEvalProvider factory) { FunctionLibrary library = new FunctionLibrary(); for (String propertyKey : this.properties.keySet()) { FunctionblockModel fbm = this.properties.get(propertyKey); if (fbm.getStereotype("functions").isPresent()) { Stereotype functionsStereoType = fbm.getStereotype("functions").get(); IScriptEvaluator evaluator = factory.createEvaluator(propertyKey.toLowerCase()); functionsStereoType.getAttributes().keySet().stream() .filter(functionName -> !functionName.equalsIgnoreCase("_namespace")).forEach( functionName -> evaluator.addScriptFunction(new ScriptClassFunction(functionName, functionsStereoType.getAttributes().get(functionName)))); library.addFunctions(evaluator.getFunctions()); } } return library; } }
public void addConverterFunction(IFunction function) { this.converterLibrary .addFunctions(new ClassFunctions(function.getFunctionClass(), function.getNamespace())); }
private void setXpathFunctions(JXPathContext xpathContext) { Functions existing = xpathContext.getFunctions(); final FunctionLibrary funcLib; if (existing == null) { funcLib = new FunctionLibrary(); } else if (existing instanceof FunctionLibrary) { funcLib = (FunctionLibrary) existing; } else { funcLib = new FunctionLibrary(); funcLib.addFunctions(existing); } for (ITagLibrary lib : getPaxml().getParser().getTagLibraries()) { for (String name : lib.getUtilFunctionsFactoryNames()) { Class<? extends IUtilFunctionsFactory> clazz = lib.getUtilFunctionsFactory(name); Class<?> xpathFunClass = ReflectUtils.createObject(clazz).getXpathUtilFunctions(this); if (xpathFunClass == null) { // skip this one continue; } Util util = ReflectUtils.getAnnotation(clazz, Util.class); if (util == null) { throw new PaxmlRuntimeException("Internal error: util function factory is not annotated: " + clazz.getName()); } funcLib.addFunctions(new ClassFunctions(xpathFunClass, util.value())); } } xpathContext.setFunctions(funcLib); }
/** * Register all extension functions listed in the configuration * through <code><function name="fully.qualified.Class" * prefix="prefix"/></code> in the given FunctionLibrary. * * @param conf a <code>Configuration</code> value */ private void getFunctions(Configuration conf) { Configuration[] children = conf.getChildren("function"); int i = children.length; while (i-- > 0) { String clazzName = children[i].getAttribute("name", null); String prefix = children[i].getAttribute("prefix", null); if (clazzName != null && prefix != null) { try { Class clazz = Class.forName(clazzName); this.library.addFunctions(new ClassFunctions(clazz, prefix)); } catch (ClassNotFoundException cnf) { // ignore } } } }
private void setXpathFunctions(JXPathContext xpathContext) { Functions existing = xpathContext.getFunctions(); final FunctionLibrary funcLib; if (existing == null) { funcLib = new FunctionLibrary(); } else if (existing instanceof FunctionLibrary) { funcLib = (FunctionLibrary) existing; } else { funcLib = new FunctionLibrary(); funcLib.addFunctions(existing); } for (ITagLibrary lib : getPaxml().getParser().getTagLibraries()) { for (String name : lib.getUtilFunctionsFactoryNames()) { Class<? extends IUtilFunctionsFactory> clazz = lib.getUtilFunctionsFactory(name); Class<?> xpathFunClass = ReflectUtils.createObject(clazz).getXpathUtilFunctions(this); if (xpathFunClass == null) { // skip this one continue; } Util util = ReflectUtils.getAnnotation(clazz, Util.class); if (util == null) { throw new PaxmlRuntimeException("Internal error: util function factory is not annotated: " + clazz.getName()); } funcLib.addFunctions(new ClassFunctions(xpathFunClass, util.value())); } } xpathContext.setFunctions(funcLib); }
/** * Register all extension packages listed in the configuration * through <code><package name="fully.qualified.package" * prefix="prefix"/></code> in the given FunctionLibrary. * * @param conf a <code>Configuration</code> value */ private void getPackages(Configuration conf) { Configuration[] children = conf.getChildren("package"); int i = children.length; while (i-- > 0) { String packageName = children[i].getAttribute("name", null); String prefix = children[i].getAttribute("prefix", null); if (packageName != null && prefix != null) { this.library.addFunctions(new PackageFunctions(packageName, prefix)); } } }