Package helma.scripting

Examples of helma.scripting.ScriptingEngine


            repositories.add(repository);
            props.addResource(repository.getResource("type.properties"));
            props.addResource(repository.getResource(name + ".properties"));
            if (update) {
                RequestEvaluator eval = app.getCurrentRequestEvaluator();
                ScriptingEngine engine = eval == null ? null : eval.scriptingEngine;
                Iterator it = repository.getAllResources().iterator();
                while (it.hasNext()) {
                    checkResource((Resource) it.next(), engine);
                }
            }
View Full Code Here


                throw new MacroException("Macro not allowed in sandbox: " + name);
            }

            Object handler = null;
            Object value = null;
            ScriptingEngine engine = cx.reval.scriptingEngine;

            if (handlerType != HANDLER_GLOBAL) {
                handler = cx.resolveHandler(path[0], handlerType);
                handler = resolvePath(handler, cx.reval);
            }

            if (handlerType == HANDLER_GLOBAL || handler != null) {
                // check if a function called name_macro is defined.
                // if so, the macro evaluates to the function. Otherwise,
                // a property/field with the name is used, if defined.
                String propName = path[path.length - 1];
                String funcName = resolveFunctionName(handler, propName + "_macro", engine);

                // remember length of response buffer before calling macro
                StringBuffer buffer = cx.reval.getResponse().getBuffer();
                int bufLength = buffer.length();

                if (funcName != null) {

                    Object[] arguments = prepareArguments(0, cx);
                    // get reference to rendered named params for after invocation
                    Map params = (Map) arguments[0];
                    value = cx.reval.invokeDirectFunction(handler,
                            funcName,
                            arguments);

                    // update StandardParams to override defaults in case the macro changed anything
                    if (stdParams != null) stdParams.readFrom(params);

                    // if macro has a filter chain and didn't return anything, use output
                    // as filter argument.
                    if (asObject && value == null && buffer.length() > bufLength) {
                        value = buffer.substring(bufLength);
                        buffer.setLength(bufLength);
                    }

                    return filter(value, cx);
                } else {
                    if (handlerType == HANDLER_RESPONSE) {
                        // some special handling for response handler
                        if ("message".equals(propName))
                            value = cx.reval.getResponse().getMessage();
                        else if ("error".equals(propName))
                            value = cx.reval.getResponse().getErrorMessage();
                        if (value != null)
                            return filter(value, cx);
                    }
                    // display error message unless onUnhandledMacro is defined or silent failmode is on
                    if (!engine.hasProperty(handler, propName)) {
                        if (engine.hasFunction(handler, "onUnhandledMacro", false)) {
                            Object[] arguments = prepareArguments(1, cx);
                            arguments[0] = propName;
                            value = cx.reval.invokeDirectFunction(handler,  "onUnhandledMacro", arguments);
                            // if macro has a filter chain and didn't return anything, use output
                            // as filter argument.
                            if (asObject && value == null && buffer.length() > bufLength) {
                                value = buffer.substring(bufLength);
                                buffer.setLength(bufLength);
                            }
                        } else if (standardParams.verboseFailmode(handler, engine)) {
                            throw new MacroException("Unhandled macro: " + name);
                        }
                    } else {
                        value = engine.getProperty(handler, propName);
                    }
                    return filter(value, cx);
                }
            } else if (standardParams.verboseFailmode(handler, engine)) {
                throw new MacroException("Unhandled macro: " + name);
View Full Code Here

TOP

Related Classes of helma.scripting.ScriptingEngine

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.