Examples of TMLContext


Examples of de.innovationgate.wgpublisher.webtml.utils.TMLContext

        // Find initial values for items
        Map<String,Object> itemDefaultValues = new HashMap<String, Object>();
        for (Element item : (List<Element>) modelNode.elements("item")) {
            String itemName = item.attributeValue("name");
            String defaultValueExpr = item.attributeValue("default");
            TMLContext context = new TMLContext(parent, _core, null, null);
            ExpressionResult result = ExpressionEngineFactory.getTMLScriptEngine().evaluateExpression(defaultValueExpr, context, ExpressionEngine.TYPE_EXPRESSION, null);
            if (!result.isError()) {
                itemDefaultValues.put(itemName, result.getResult());
            }
            else {
View Full Code Here

Examples of de.innovationgate.wgpublisher.webtml.utils.TMLContext

            }
            else if (condition.getName().equals("param")) {
               
                String paramName = condition.attributeValue("name");
                String paramExpression = condition.getTextTrim();
                TMLContext context = new TMLContext(content, _core, null, null);
                ExpressionResult result = ExpressionEngineFactory.getTMLScriptEngine().evaluateExpression(paramExpression, context, ExpressionEngine.TYPE_EXPRESSION, null);
                if (!result.isError()) {
                    params.put(paramName, result.getResult());
                }
                else {
View Full Code Here

Examples of de.innovationgate.wgpublisher.webtml.utils.TMLContext

        if (!(args[0] instanceof Function)) {
            Context.reportError("The first argument for synchronizedFunction() must be a Function object");
        }

        if (args.length == 1) {
            TMLContext context = fetchInitialContext(cx);
            return new SynchronizedFunction((Function) args[0], context.getwgacore());
        }
        else {
            return new SynchronizedFunction((Function) args[0], args[1]);
        }
View Full Code Here

Examples of de.innovationgate.wgpublisher.webtml.utils.TMLContext

        else if (toBeFormatted instanceof Scriptable) {
            toBeFormatted = ((Scriptable) toBeFormatted).getDefaultValue(null);
        }

        // Fetch locale to use
        TMLContext context = fetchInitialContext(cx);
        Locale locale = null;
        if (context != null) {
            locale = context.getPreferredLanguageLocale();
            if (locale == null) {
                locale = Locale.getDefault();
            }
        }

        if (toBeFormatted instanceof Number) {
            Number number = (Number) toBeFormatted;
            NumberFormat numFormat = context.getNumberFormat(formatString);
            return numFormat.format(number.doubleValue());
        }
        else if (toBeFormatted instanceof Date) {
            Date date = (Date) toBeFormatted;
            DateFormat dateFormat = context.getDateFormat(formatString);
            return dateFormat.format(date);
        }
        else {
            return null;
        }
View Full Code Here

Examples of de.innovationgate.wgpublisher.webtml.utils.TMLContext

    public static Object callAction(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) throws JavaScriptException {

        VarArgParser.Arguments parsedArgs = _callActionVarargs.parse(args);

        // Determine action id and action context
        TMLContext context = (TMLContext) parsedArgs.get("context");
        if (context == null) {
            context = fetchInitialContext(cx);
        }

        String actionID = (String) parsedArgs.get("id");
        List actionArgs = new ArrayList(parsedArgs.getOverflowArgs());

        // Get the current action, to be able to expand local name and search
        // the action to perform in it's database
        TMLAction.Locator actionLocator = determineActionLocator(cx, thisObj, context, actionID);

        TMLAction action = context.getActionByID(actionLocator.getId(), actionLocator.getDbkey());
        if (action == null) {
            throw new EvaluatorException("Could not retrieve action for ID '" + actionID + "'");
        }

        TMLScriptRootScope rootScope = fetchRootScope(cx);

        // Call action
        Object actionResult;
        try {
            actionResult = context.callCustomAction(action, actionArgs, rootScope.getData().getUnwrappedGlobalScopeObjects());
        }
        catch (WGAPIException e) {
            throw Context.throwAsScriptRuntimeEx(e);
        }
View Full Code Here

Examples of de.innovationgate.wgpublisher.webtml.utils.TMLContext

    public static Function loadObjectDefinition(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) throws JavaScriptException {

        VarArgParser.Arguments parsedArgs = _loadObjectDefVarags.parse(args);

        TMLContext context = fetchInitialContext(cx);
        String actionID = (String) parsedArgs.get("id");
        NativeObject currentObject = (NativeObject) parsedArgs.get("currentObject");

        // Get the function def (might need to expand local name by the name of
        // the current action)
        TMLAction.Locator actionLocator = determineActionLocator(cx, currentObject, context, actionID);

        TMLAction action;
        try {
            action = context.getModuleActionByID(actionLocator.getId(), actionLocator.getDbkey());
        }
        catch (TMLActionException e) {
            throw new EvaluatorException("Could not retrieve TMLScript module '" + args[0] + "': " + e.getMessage());
        }
        if (action == null) {
View Full Code Here

Examples of de.innovationgate.wgpublisher.webtml.utils.TMLContext

    public static TMLContext fetchInitialContext(Context cx) throws JavaScriptException {
        Object obj = cx.getThreadLocal(RhinoExpressionEngine.TL_INITIALCONTEXT);
        if (!(obj instanceof TMLContext)) {
            throw new EvaluatorException("Initial context not available");
        }
        TMLContext context = (TMLContext) obj;
        return context;
    }
View Full Code Here

Examples of de.innovationgate.wgpublisher.webtml.utils.TMLContext

        return obj;
    }

    public static void logException(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) {

        TMLContext context = fetchInitialContext(cx);

        // Determine parameters
        String msg = null;
        Object error = null;

        if (args.length == 0) {
            context.getlog().error("Unloggable TMLScript error because of too few arguments for logException");
            return;
        }
        else if (args.length == 1) {
            msg = "Error in TMLScript";
            error = args[0];
        }
        else {
            msg = (String) args[0];
            error = args[1];
        }

        // Determine throwable to log and/or additional message to put out
        Throwable throwable = null;
        String additionalMsg = null;

        if (error instanceof Throwable) {
            throwable = (Throwable) error;
        }
        else if (error instanceof Scriptable) {
            Scriptable nativeError = (Scriptable) error;
            if (nativeError.has("rhinoException", nativeError)) {
                throwable = (RhinoException) ((NativeJavaObject) nativeError.get("rhinoException", nativeError)).unwrap();
            }
            else if (nativeError.has("javaException", nativeError)) {
                throwable = (Throwable) ((NativeJavaObject) nativeError.get("javaException", nativeError)).unwrap();
            }
            else if (nativeError.has("message", nativeError)) {
                additionalMsg = (String) nativeError.get("message", nativeError);
            }
            else {
                additionalMsg = "(scriptable error object without further information: " + nativeError.getClass().getName() + ")";
            }

            if (nativeError.has("lineNumber", nativeError) && !(throwable instanceof RhinoException)) {
                additionalMsg += ". Line number: " + (Integer) nativeError.get("lineNumber", nativeError);
            }
        }
        else {
            additionalMsg = "(error object of invalid type: " + error.getClass().getName() + ")";
        }
       
        // Try to find job context. If available use the job log to put out error
        Logger theLog = context.getlog();
        JobContext jobContext = null;
        Object jcObj = thisObj.get("jobContext", thisObj);
        if (jcObj != null && jcObj instanceof NativeJavaObject) {
            jcObj = ((NativeJavaObject) jcObj).unwrap();
            if (jcObj instanceof JobContext) {
                jobContext = (JobContext) jcObj;
                theLog = jobContext.getLog();
            }
        }

        // Put out
        if (additionalMsg != null) {
            msg += ": " + additionalMsg;
        }

        if (throwable != null) {

            if (throwable instanceof RhinoException) {
                RhinoException rhinoEx = (RhinoException) throwable;
                if (rhinoEx.lineNumber() != 0) {
                    msg += ". Line Number " + rhinoEx.lineNumber();
                }

                if (rhinoEx.lineSource() != null) {
                    msg += ". Line source: " + rhinoEx.lineSource();
                }
            }

            theLog.error(msg, throwable);
           
            context.addwarning(msg + ". Exception message: " + throwable.getMessage() + ". Exception type: " + throwable.getClass().getName());
        }
        else {
            theLog.error(msg);
            context.addwarning(msg);
        }

    }
View Full Code Here

Examples of de.innovationgate.wgpublisher.webtml.utils.TMLContext

        }
       
        obj = ((NativeJavaObject) obj).unwrap();
       
        try {
            TMLContext context = fetchInitialContext(cx);
            String xml = XStreamUtils.XSTREAM_CLONING.toXML(obj);
            byte[] zipped = Zipper.zip(xml);
            String encrypted = context.getwgacore().getDesEncrypter().encrypt(zipped);
            return encrypted;
        }
        catch (UnsupportedEncodingException e) {
            throw Context.throwAsScriptRuntimeEx(e);
        }       
View Full Code Here

Examples of de.innovationgate.wgpublisher.webtml.utils.TMLContext

       
    }
   
    public static Object deserializeObject(Context cx, Scriptable thisObj, java.lang.Object[] args, Function funObj) {

        TMLContext context = fetchInitialContext(cx);
        String encrypted  = String.valueOf(args[0]);
        byte[] zipped = context.getwgacore().getDesEncrypter().decrypt(encrypted);
        String xml = Zipper.unzip(zipped);
        Object obj = XStreamUtils.XSTREAM_CLONING.fromXML(xml);
        return obj;
       
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.