Package de.innovationgate.wgpublisher.expressions

Examples of de.innovationgate.wgpublisher.expressions.ExpressionResult


            }

            // Eval cache key
            if (!currentCacheby.equals("")) {
                ExpressionEngine engine = ExpressionEngineFactory.getEngine(this.getExprlanguage());
                ExpressionResult result = engine.evaluateExpression(currentCacheby, this.getTMLContext(), ExpressionEngine.TYPE_EXPRESSION, null);
                if (result.isError()) {
                    addExpressionWarning(currentCacheby, result);
                    return;
                }
                status._currentCacheKey = String.valueOf(result.getResult());
            }
            else {
                status._currentCacheKey = "";
            }
           
View Full Code Here


            throw new TMLActionException("Could not find action for key " + actionLink.getActionKey());
          }
          actionContext.callCustomAction(tmlAction, params);
          if (actionLink.getPortletmode() != null && actionContext.getportlet() != null) {
              if (getTMLContext().isdefined("actionresult")) {
                      ExpressionResult expressionResult = (ExpressionResult) getTMLContext().item("actionresult");
                      if (!expressionResult.isError() && (expressionResult.getResult() == null || expressionResult.getResult() instanceof String || !expressionResult.isFalse())) {
                          actionContext.getportlet().setmode(actionLink.getPortletmode());         
                      }
                  }
          }
                applyPortletContext(actionLink, actionContext);
View Full Code Here

                scope = new TMLScriptRootScope(scopePrototype, _tmlContext);
                rcx.setErrorReporter(scope);
                rcx.putThreadLocal(TL_ROOTSCOPE, scope);
            }
            catch (RhinoException exc) {
                return new ExpressionResult(null, false, true, new de.innovationgate.webgate.api.WGExpressionException("Error creating tmlscript context", exc.getLocalizedMessage()));
            }
           
            // Put custom additional objects into scope
            if (_additionalObjects != null) {
                Iterator objectNames = _additionalObjects.keySet().iterator();
                String objectName;
                Object object;
                while (objectNames.hasNext()) {
                    objectName = (String) objectNames.next();
                    object = _additionalObjects.get(objectName);
                    if (objectName.startsWith("$")) {
                        if (objectName.equals(PARAM_SCRIPTTIMEOUT)) {
                            rcx.scriptTimeout = ((Number) object).intValue();
                        }
                        else if (objectName.equals(PARAM_ACTIONDEFINITION)) {
                            rcx.putThreadLocal(TL_ACTIONDEFINITION, object);
                        }
                        else if (objectName.equals(PARAM_ACTIONLOCATOR)) {
                            rcx.putThreadLocal(TL_ACTIONLOCATOR, object);
                        }
                        else if (objectName.equals(RhinoExpressionEngine.PARAM_SCRIPTNAME)) {
                            rcx.putThreadLocal(TL_SCRIPTNAME, object);
                        }
                    }
                    else {
                        scope.getData().putScopeObject(objectName, Context.javaToJS(object, scope));
                    }
                }
            }
           
            // Default scope objects that may not be overwritten with custom scope objects
            scope.getData().putScopeObject(SCOPEOBJECT_RUNTIME, Context.javaToJS(RhinoExpressionEngineImpl.this, scope));
           
            try {
                // Eventually disable TMLScript optimization, so Script stack traces are generated
                rcx.setOptimizationLevel(RhinoContextFactory.defaultOptimizationLevel);
                rcx.setGeneratingDebug(false);
                if (_tmlContext.hasVariable(RhinoExpressionEngine.SESSIONVAR_ENABLE_SCRIPTSTACKTRACE)) {
                    Boolean tmlscriptOptimizationDisabled = (Boolean) _tmlContext.item(RhinoExpressionEngine.SESSIONVAR_ENABLE_SCRIPTSTACKTRACE);
                    if (tmlscriptOptimizationDisabled != null && tmlscriptOptimizationDisabled.booleanValue() == true) {
                        if (rcx.getOptimizationLevel() > 0) {
                            rcx.setOptimizationLevel(0);
                        }
                        rcx.setGeneratingDebug(true);
                    }
                }

                // Set new main TMLContext for this thread
                _tmlContext.makeThreadMainContext();
               
                // Execute
                Object result = null;
                try {
                    if (_function != null) {
                        result = executeFunction(_function, _overrideFunctionScope, _functionParams, rcx, scope);
                    }
                    else if (_type == ExpressionEngine.TYPE_SCRIPT) {
                        result = executeScript(_expression, rcx, scope);
                    }
                    else {
                        result = executeExpression(_expression, rcx, scope);
                    }
                }
               
                // Some syntax error
                catch (EcmaError exc) {
                    String exceptionMessage = exc.getName() + " executing tmlscript: " + exc.getMessage() + "\n" + buildExceptionDetails(exc);
                    WGExpressionException expressionException;
                    String scriptStackTrace = filterScriptStackTrace(exc.getScriptStackTrace(TMLSCRIPT_NAME_FILTER));
                    Throwable cause = (WGUtils.isEmpty(scriptStackTrace) ? exc : null);
                    expressionException = new de.innovationgate.webgate.api.WGExpressionException(exceptionMessage, exc.lineSource(), cause, scriptStackTrace);
                    return new ExpressionResult(null, false, true, expressionException);
                }
               
                // A script timeout (deprecated, works only in debug mode)
                catch (TimeoutError err) {
                    return new ExpressionResult(null, false, true, new de.innovationgate.webgate.api.WGExpressionException("Script execution timed out after " + err.getTimeout() + " milliseconds.",
                            _expression));
                }
               
                // Some java script error explicitly thrown by the code: Converted to TMLScriptException so the class can be better used outside
                catch (JavaScriptException exc) {
                    String exceptionMessage = "JavaScript exception executing tmlscript: " + exc.getMessage()  + " (Exception value: " + exc.getValue() + ")\n" + buildExceptionDetails(exc);
                    de.innovationgate.webgate.api.WGExpressionException expressionException = new de.innovationgate.webgate.api.WGExpressionException(exceptionMessage, exc.lineSource(), convertToTMLScriptException(exc), filterScriptStackTrace(exc.getScriptStackTrace()));
                    return new ExpressionResult(null, false, true, expressionException);
                }
               
                // Everything else: Wrapped java exceptions, internal rhino malfunctionings etc.
                catch (RhinoException exc) {
                   
                    Throwable cause = exc;
                    if (cause instanceof WrappedException) {
                        cause = ((WrappedException) exc).getCause();
                    }
                   
                    return new ExpressionResult(null, false, true, new de.innovationgate.webgate.api.WGExpressionException("Exception executing tmlscript: " + cause.getMessage() + ".\n"
                            + buildExceptionDetails(exc), exc.lineSource(), cause, exc.getScriptStackTrace()));
                }
                finally {
                   
                    /// Remove thread main context
                    _tmlContext.removeThreadMainContext();
                   
                    // Restore preserved ThreadLocal values
                    preserver.restore();
                }

                // Evaluate and return result;
                if (result instanceof NativeJavaObject) {
                    result = ((NativeJavaObject) result).unwrap();
                }
                else if (result instanceof NativeArray) {
                    result = new ArrayList(Arrays.asList(rcx.getElements((NativeArray) result)));
                }
                else if (result instanceof Undefined) {
                    result = "";
                }

                if (result instanceof Boolean) {
                    Boolean bolResult = (Boolean) result;
                    return new ExpressionResult(result, bolResult.booleanValue(), !bolResult.booleanValue(), null);
                }
                else {
                    return new ExpressionResult(result, false, isJSFalse(result), null);
                }

            }
            catch (Exception e) {
                Logger.getLogger("wga").error("Error in TMLScript processing", e);
                return new ExpressionResult(null, false, true, new de.innovationgate.webgate.api.WGExpressionException("Unexpected exception: " + e.getClass().getName() + ": " + e.getMessage(),
                        "(No source available)"));
            }
        }
View Full Code Here

                    persDB.openSession();
                    persDB.getSessionContext().setTask(taskDescr);
                }
   
                RhinoContextAction contextAction = new RhinoContextAction(_context, _function, _overrideFunctionScope, _params);
                ExpressionResult result = (ExpressionResult) ContextFactory.getGlobal().call(contextAction);
               
                if (result.isError()) {
                    WGExpressionException exc = result.getException();
                    _context.getlog().error(
                            "Error executing anonymous TMLScript Master Function",
                            result.getException());
                            
                }
               
                _returnValue = result.getResult();               
   
        }
        catch (Exception e) {
          _context.getwgacore().getLog().error("Error creating TML Context for master function", e);
        }
View Full Code Here

        try {
            WGCSSJSModule mod = db.getCSSJSModule(script, WGScriptModule.CODETYPE_TMLSCRIPT);
            if (mod != null) {
                _log.info("Running connection script of '" + db.getDbReference() + "'");
                TMLContext context = new TMLContext(db.getDummyContent(null), _core, null, null);
                ExpressionResult result = ExpressionEngineFactory.getTMLScriptEngine().evaluateExpression(mod.getCode(), context, ExpressionEngine.TYPE_SCRIPT, null);
                if (result.isError()) {
                    _log.error("Error running connection script '" + csConfig.getConnectionScript() + "' of '" + db.getDbReference() + "'", result.getException());
                }
            }
            else {
                _log.error("Connection script '" + csConfig.getConnectionScript() + "' not found in design of '" + db.getDbReference() + "'");
            }
View Full Code Here

           
            WGCSSJSModule mod = db.getCSSJSModule(script, WGScriptModule.CODETYPE_TMLSCRIPT);
            if (mod != null) {
                _log.info("Running disconnection script of '" + db.getDbReference() + "'");
                TMLContext context = new TMLContext(db.getDummyContent(null), _core, null, null);
                ExpressionResult result = ExpressionEngineFactory.getTMLScriptEngine().evaluateExpression(mod.getCode(), context, ExpressionEngine.TYPE_SCRIPT, null);
                if (result.isError()) {
                    _log.error("Error running disconnection script '" + script + "' of '" + db.getDbReference() + "'", result.getException());
                }
            }
            else {
                _log.error("Disconnection script '" + script + "' not found in design of '" + db.getDbReference() + "'");
            }
View Full Code Here

   
    String expr = getExpression();
    Object result;
        if (expr != null) {
            RhinoExpressionEngine engine = ExpressionEngineFactory.getTMLScriptEngine();
            ExpressionResult exprResult = engine.evaluateExpression(expr, getTMLContext(), RhinoExpressionEngine.TYPE_EXPRESSION, null);
            if (!exprResult.isError()) {
                result = exprResult.getResult();
            }
            else {
                addWarning("Error evaluation param expression: " + exprResult.getException().getClass() + exprResult.getException().getMessage(), true);
                return;
            }
        }
        else {
            result = getResultString();
View Full Code Here

                            try {
                                WGCSSJSModule mod = _db.getCSSJSModule(_info.getCsConfig().getInitScript(), WGScriptModule.CODETYPE_TMLSCRIPT);
                                if (mod != null) {
                                    _log.info("Running initialisation script of database '" + _db.getDbReference() + "'");
                                    TMLContext context = new TMLContext(_db.getDummyContent(null), _core, null, null);
                                    ExpressionResult result = ExpressionEngineFactory.getTMLScriptEngine().evaluateExpression(mod.getCode(), context, ExpressionEngine.TYPE_SCRIPT, null);
                                    if (result.isError()) {
                                        _log.error("Error running initialisation script '" + _info.getCsConfig().getInitScript() + "' of db '" + _db.getDbReference() + "'", result.getException());
                                    }
                                }
                                else {
                                    _log.error("Initialisiation script '" + _info.getCsConfig().getInitScript() + "' not found in database '" + _db.getDbReference() + "'");
                                }
View Full Code Here

        }
       
       
        Map objects = new HashMap();
        objects.put(RhinoExpressionEngine.PARAM_SCRIPTNAME, "Condition on " + getTagDescription());
        ExpressionResult result = engine.evaluateExpression(attValue, this.getTMLContext(), ExpressionEngine.TYPE_EXPRESSION, objects);
        if (result.isError()) {
            addExpressionWarning(attValue,result);
          return false;
        }
        else if (result.isFalse()) {
          return false;
        }
      }
   
      attValue = this.getIsselected();
View Full Code Here

            childEntry = (WGStructEntry) childEntries.next();
            childContent = childEntry.getReleasedContent(language);
            if (childContent != null) {
               
                if (role == null || childContent.isVisibleFor(role)) {
                    ExpressionResult result = engine.evaluateExpression(expr, getTMLContextForDocument(childContent), ExpressionEngine.TYPE_EXPRESSION, null);
                    if (result.isTrue()) {
                        results.add(childContent.getContentKey());
                        if (maxDocs != 0 && results.size() >= maxDocs) {
                            break;
                        }
                    }
                   
                    if (result.isError()) {
                        addWarning("Error executing expression: " + result.getException().getClass().getName() + " - " + result.getException().getMessage());
                    }
                }
            }

            if (deep) {
View Full Code Here

TOP

Related Classes of de.innovationgate.wgpublisher.expressions.ExpressionResult

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.