Package net.sourceforge.temply.base.rules

Examples of net.sourceforge.temply.base.rules.TemplyFunction


        if (src.exists()) {
            add(src);
        }
       
        for (XMLFunction XMLFunction : _xmlFunctions.values()) {
            TemplyFunction function = new TemplyFunction(XMLFunction.getName(), XMLFunction.getContent());
            _functions.put(function.getName(), function);
        }
       
        for (TemplyFunction function : BuiltinFunctions.getInstance().getFunctions()) {
            _functions.put(function.getName(), function);
        }
       
        for (XMLRule xmlRule : _xmlRules.values()) {
            getRule(xmlRule);
        }
View Full Code Here


     * @param in
     * @return null if some function returned null (it means invalidate)
     */
    String resolveFunctions(String in) {
        for (TemplyFunctionExpression functionExp : _functionFinder.find(in)) {
            TemplyFunction function = _project.getRepository().getFunction(functionExp.getName());
            if (function == null) {
                throw new RuntimeException("Cannot find function \"" + functionExp.getName() + "\".");
            }
            Object result = function.evaluate(_project, functionExp.getArguments());
            if (result == null) {
                return null;
            }
            in = _functionFinder.replace(in, functionExp, result.toString());
        }
View Full Code Here

//        }
//        return in;
//    }
   
    Object runFunction(String name, Object[] args) {
        TemplyFunction function = _project.getRepository().getFunction(name);
        if (function == null) {
            throw new IllegalArgumentException("Cannot find function \"" + name + "\".");
        }
        return function.evaluate(_project, args);
    }
View Full Code Here

    private Collection<TemplyFunction> _functions;
   
    public Collection<TemplyFunction> getFunctions() {
        if (_functions == null) {
            _functions = new ArrayList<TemplyFunction>();
            _functions.add(new TemplyFunction("equals", "return args[0] == args[1]"));
            _functions.add(new TemplyFunction("property", "return properties[args[0]]"));
            _functions.add(new TemplyFunction("in",
                    "def separator = (args.length == 2 ? \"\\\\|\" : args[2])\n" +
                    "for (String s : args[1].split(separator)) {\n" +
                            "    if (s == args[0]) {return true}\n" +
                    "}\n" +
                    "return false"));
View Full Code Here

TOP

Related Classes of net.sourceforge.temply.base.rules.TemplyFunction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.