droflosession.java

来自「OpenWFE是一个开放源码的Java工作流引擎。它是一个完整的业务处理管理套件」· Java 代码 · 共 582 行 · 第 1/2 页

JAVA
582
字号
                 "__new_flow",                 "1.0");        }        catch (final BuildException be)        {            log                ("newFlowDefinition() Failed to build new flow definition !",                  be);        }    }    public ProcessDefinition getFlowDefinition ()    {        return this.flowDefinition;    }    public void setException (Throwable t)    {        this.exception = t;    }    public Throwable getException ()    {        return this.exception;    }    public void clearException ()    {        this.exception = null;    }    public ApplicationContext getApplicationContext ()    {        return this.applicationContext;    }    /*     *     * RENDER FLOW     *     */    public void renderFlow         (final PrintWriter out,         final HttpServletRequest req,         final HttpServletResponse res)    throws         RenderingException    {        try        {            final long drofloLinkCounter =                 Long.parseLong(req.getParameter("dlc"));            this.workitem = (InFlowWorkItem)ApplicationContext                .lookupSharedContext().lookup("workitem"+drofloLinkCounter);        }        catch (NumberFormatException nfe)        {            this.workitem = null;        }        log("renderFlow() this.workitem == null : "+(this.workitem == null));        DrofloHelper.getInstance(req).renderFlow(this, out, req, res);    }    public void updateExpression (final HttpServletRequest req)        throws RenderingException    {        DrofloHelper.getInstance(req).parseRequest(this, req);    }    public void loadExpressionToEdit (final String expId)    {        this.expressionToEdit = this.flowDefinition.getExpression(expId);    }    public void unloadExpressionToEdit ()    {        this.expressionToEdit = null;        this.editInXml = false;    }    public FlowExpression getExpressionToEdit ()    {        return this.expressionToEdit;    }    public String getExpressionToEditName ()    {        return getExpressionName(this.expressionToEdit);    }    public void outputDefinitionAsXml (final PrintWriter out)        throws Exception    {        out.println(this.flowDefinition.outputAsXmlString());    }    /**     * Returns the expressionMap OpenWFE service that this session uses     */    public ExpressionMap getExpressionMap ()    {        return Definitions.getExpressionMap(this.applicationContext);    }    /**     * Given a expression, returns the corresponding short name     * (found in the XML process definition as a tag)     */    public String getExpressionName (Object expression)    {        if (expression == null) return "--null-expression--";        return getExpressionMap().getName(expression.getClass());    }    //    // undo methods    public boolean canUndo ()    {        return this.undoStack.size() > 0;    }    public void stackForUndo ()    {        if (this.flowDefinition == null) return;        try        {            this.undoStack.add(0, this.flowDefinition.outputAsXmlString());            while (this.undoStack.size() > UNDO_LEVELS)                this.undoStack.remove(UNDO_LEVELS);        }        catch (Exception e)        {            log("stackForUndo() stacking failed", e);        }    }    public void popForUndo ()    {        try        {            final String sFlowDefinition = (String)this.undoStack.get(0);            this.flowDefinition = getLauncher()                .loadProcessDefinitionFromString(sFlowDefinition);        }        catch (Exception e)        {            log("popForUndo() popping failed", e);        }        this.undoStack.remove(0);    }    public void substituteBranch         (final FlowExpressionId fei, final String newXml)    throws         BuildException    {        String sDefinition = this.flowDefinition.doReplaceXml(fei, newXml);        this.flowDefinition = getLauncher()            .loadProcessDefinitionFromString(sDefinition);    }    //    // STATIC METHODS    public static DrofloSession getSession (final HttpServletRequest req)    {        HttpSession httpSession = req.getSession(true);        return (DrofloSession)httpSession.getAttribute(DROFLO_SESSION);    }    public static boolean inEditMode (final HttpServletRequest req)    {        Object o = req.getAttribute(IN_EDIT_MODE);        if (o == null || ! (o instanceof Boolean)) return false;        return ((Boolean)o).booleanValue();    }    private static String isolateUrl (final HttpServletRequest req)    {        final StringBuffer rawUrl = req.getRequestURL();        WebUtils.log(req, "isolateUrl() for >"+rawUrl+"<");        int i = rawUrl.indexOf("/servlet");        if (i < 0) i = rawUrl.lastIndexOf("/");        String result = rawUrl.substring(0, i);         //result += "/";        WebUtils.log(req, "isolateUrl() result is >"+result+"<");        return result;    }    public static DrofloSession getOrCreateSession         (final HttpServletRequest req)    {        HttpSession httpSession = req.getSession(true);        WebUtils.log            (req, "getOrCreateSession() req is "+req.getRequestURL().toString());        WebUtils.log            (req, "getOrCreateSession() httpSession is "+httpSession);        final String dsKey =             req.getContextPath() + DrofloSession.DROFLO_SESSION;        WebUtils.log(req, "getOrCreateSession() dsKey is >"+dsKey+"<");        DrofloSession result = (DrofloSession)httpSession.getAttribute(dsKey);        WebUtils.log            (req, "getOrCreateSession() is result null ? "+(result == null));        final String sEdit = req.getParameter("edit");        //log("getOrCreateSession() sEdit is >"+sEdit+"<");        if (result != null)        {            //result.setInEditMode("true".equals(sEdit));            if ("true".equals(sEdit)) result.setInEditMode(true);            return result;        }        WebUtils.log            (req, "getOrCreateSession() building ApplicationContext...");        //        // build ApplicationContext                ApplicationContext applicationContext = null;        try        {            ServletContext servletContext = httpSession.getServletContext();            String configFileName = servletContext                .getInitParameter(APPLICATION_CONFIGURATION);            configFileName = servletContext.getRealPath(configFileName);            WebUtils.log                (req, "getOrCreateSession() configFileName : "+configFileName);            openwfe.org.app.XmlApplicationContextBuilder builder =                 (openwfe.org.app.XmlApplicationContextBuilder)                    openwfe.org.app.XmlApplicationContextBuilder.class                        .newInstance();            applicationContext = builder                .build(configFileName, servletContext.getRealPath("/"));        }        catch (final Throwable t)        {            WebUtils.log                (req,                 "getOrCreateSession() "+                 "Problem with parameter '"+APPLICATION_CONFIGURATION+"'",                  t);            throw new IllegalArgumentException                ("Parameter '"+APPLICATION_CONFIGURATION+                 "' is missing in WEB-INF/web.xml "+                 "or this configuration file is corrupt.");        }        //        // build DrofloSession        result = new DrofloSession            (isolateUrl(req),              req.getSession().getServletContext(),             applicationContext,              "true".equalsIgnoreCase(sEdit));        httpSession.setAttribute            (req.getContextPath()+DrofloSession.DROFLO_SESSION, result);        return result;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?