📄 droflo.py
字号:
## Copyright (c) 2005, John Mettraux, OpenWFE.org# All rights reserved.# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met:# # . Redistributions of source code must retain the above copyright notice, this# list of conditions and the following disclaimer. # # . Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution.# # . Neither the name of the "OpenWFE" nor the names of its contributors may be# used to endorse or promote products derived from this software without# specific prior written permission.# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE.## $Id: droflo.py,v 1.63 2005/07/07 07:39:47 jmettraux Exp $#""" jython classes for rendering and editing expressions for DroFlo This code is made for running with Jython only. $Id: droflo.py,v 1.63 2005/07/07 07:39:47 jmettraux Exp $"""import syssys.add_package('java.net')sys.add_package('java.lang')sys.add_package('java.util')sys.add_package('org.apache.log4j')sys.add_package('openwfe.org.misc')sys.add_package('openwfe.org.engine')sys.add_package('openwfe.org.engine.launch')sys.add_package('openwfe.org.engine.expressions')sys.add_package('openwfe.org.engine.expressions.raw')sys.add_package('openwfe.org.engine.expressions.sync')#print 'sys.path : %s' % sys.pathfrom java.net import URLfrom java.lang import Stringfrom java.util import HashMapfrom org.apache.log4j import Loggerfrom openwfe.org.misc import WebUtilsfrom openwfe.org.engine import expressions## log4j's loggerlog = Logger.getLogger('droflo.py')## CONSTANTSEMPTY_STRING = String()def _img (req, s, width=None, height=None): s = '/images/%s' % s if req: s = req.contextPath + s if width: width = 'width=%s' % width else: width = '' if height: height = ' height=%s' % height else: height = '' return '<img src="%s" border=0 %s%s>' % (s, width, height)IMG_ARROW = 'arrow.png'IMG_ARROW_TO_LEFT = 'arrow-to-left.png'IMG_ARROW_TO_RIGHT = 'arrow-to-right.png'IMG_DOWN_TO_LEFT = 'down-to-left.png'IMG_DOWN_TO_RIGHT = 'down-to-right.png'IMG_PARTICIPANT = 'participant.png'IMG_SUBPROCESS = 'subprocess.png'IMG_BRANCH = 'branch.png'IMG_CONCURRENCE = 'concurrence.png'IMG_ITERATOR = 'iterator.png'IMG_START = 'start.png'IMG_END = 'end.png'IMG_PLUS = 'plus.png'IMG_MINUS = 'minus.png'IMG_UP = 'up.png'IMG_DOWN = 'down.png'IMG_EDIT = 'edit.png'IMG_OK = 'ok.png'SCOPE_PREFIX = 'scope__'BTN_TOGGLE_HELP = '<p align=left><a href=droflo.action?action=togglehelp title="Show help pane">show help</a></p>'BTN_HIDE_HELP = '<p align=left><a href=droflo.action?action=togglehelp title="Hide help pane">hide help</a></p>'FORM_JSCRIPT = """<script language=\"javascript\"> function submitForm (formName, actionTarget) { document.forms[formName].action=actionTarget; document.forms[formName].method=\"POST\"; document.forms[formName].submit(); }</script>"""P_EXP_NAME = 'expName'P_EXP_ID = 'expId'GENERIC_HELP_FILE = 'help.jsp'RENDERER_MAP = {}ROOT_FORM_NAME = 'rootForm'EDIT_FORM_NAME = 'editForm'NEW_EXP_NAME = 'newExpName'UPDATE_ACTION = 'droflo.action?action=updateexpression'UPDATE_FLOW_NAME_ACTION = 'droflo.action?action=updateflowname'ADD_EXPRESSION_ACTION = 'droflo.action?action=addexpression'UPDATE_SUBPROCESS_NAME_ACTION = 'droflo.action?action=updatesubprocessname'CREATE_SUBPROCESS_ACTION = 'droflo.action?action=createsubprocess'REMOVE_SUBPROCESS_ACTION = 'droflo.action?action=removesubprocess'OPTIONS = [ 'field', 'variable' ]VALUE = 'value'FIELD_VALUE = 'field-value'VARIABLE_VALUE = 'variable-value'FUNCTION_VALUE = 'function-value'VALUE_OPTIONS = [ VALUE, FIELD_VALUE, VARIABLE_VALUE, FUNCTION_VALUE ]#OTHER_OPTIONS = [ 'other-value', 'other-field-value', 'other-variable-value' ]OTHER_OPTIONS = [ 'other-%s' % val for val in VALUE_OPTIONS ]REF = 'ref'FIELD_REF = 'field-ref'VARIABLE_REF = 'variable-ref'DEFAULT_REF = 'default-ref'ELSE_REF = 'else-ref'REFS = [ REF, FIELD_REF, VARIABLE_REF, DEFAULT_REF, ELSE_REF ]P_ADD_PARAM = 'add param'P_REMOVE = 'remove'BUTTON = 'button'FLOW_NAME_FORM = 'flowNameForm'P_FLOW_NAME = 'flowName'P_FLOW_REVISION = 'flowRevision'SUBPROCESS_NAME_FORM = 'subProcessNameForm'P_SUBPROCESS_NAME = 'subProcessName'P_OLD_SUBPROCESS_NAME = 'old_%s' % P_SUBPROCESS_NAME#P_SUBPROCESS_PATH = 'subProcessPath'P_SUBPROCESS_EXP = 'subProcessExp'TO_VARIABLE = 'to-variable'FROM_VARIABLE = 'from-variable'## some help methodsdef _isList (o): return type(o) == type([])def _isTuple (o): return type(o) == type((1, ))def _getKeyWithPrefix (expression, prefix): for k in expression.attributes.keySet(): if k.startswith(prefix): return k return Nonedef _neutralize (s): if not s: return 'None' s = s.replace('>', '>') s = s.replace('<', '<') return s## THE 'MAIN' METHODSdef renderFlow (session, out, req): """ this method is called from java DrofloHelper """ if session.isInEditMode(): out.println(FORM_JSCRIPT) out.println('<table border=0 cellpadding=2 cellspacing=1>') # the table holding the flow table and the help display out.println('<tr><td valign=top>') # # render the main flow _renderDefinition(session, out, req, session.flowDefinition) # # show help button if session.isInEditMode() and not session.isHelpVisible(): out.println(BTN_TOGGLE_HELP) # end of flow cell out.println('</td>') if session.isInEditMode() and session.isHelpVisible(): out.println('<td valign=top>') # display editor help if any if session.expressionToEdit != None: renderer = _getRenderer(session.expressionToEdit) helpFileName = renderer.getHelpFileName() if helpFileName != None: #WebUtils.include(out, session.applicationContext.applicationDirectory+helpFileName) u = URL(session.webappUrl+helpFileName) WebUtils.include(out, u) out.println('<br>\n<hr>') # display generic help #WebUtils.include(out, session.applicationContext.applicationDirectory+GENERIC_HELP_FILE) u = URL(session.webappUrl+GENERIC_HELP_FILE) WebUtils.include(out, u) out.println(BTN_HIDE_HELP) out.println('</td>') # # end of the flow & help table out.println('</tr></table>')def parseRequest (session, req): #log.debug('parseRequest()') if not session.expressionToEdit: return renderer = _getRenderer(session.expressionToEdit) renderer.parseRequest(session, session.expressionToEdit, req) ## OTHER METHODSdef _getRenderer (expression): log.debug\ ('_getRenderer() expression.class is %s' % expression.getClass().name) rendererClassName = RENDERER_MAP.get(expression.class) if rendererClassName == None: log.debug('_getRenderer() returning DefaultExpressionRenderer') return DefaultExpressionRenderer() return rendererClassName()def _isEditable (expression): renderer = _getRenderer(expression) return isinstance(renderer, Editable)def _displayRemoveSubDefinitionButton (req, out, defineExpressionId): href = "%s&%s=%s" % (REMOVE_SUBPROCESS_ACTION, P_SUBPROCESS_EXP, defineExpressionId.expressionName) _displaySimpleButton(out, href, _img(req, IMG_MINUS))def _renderDefinition (session, out, req, definition, defExpression=None): isWorkflowDefinition = (defExpression == None) if not defExpression: defExpression = definition.getSelf() log.debug("_renderDefinition() defExpression is %s" % defExpression.id) subDefName = defExpression.attributes.get('name') out.println('<table border=1 cellpadding=2 cellspacing=1>') # the table containing the flow if isWorkflowDefinition: # # it's a workflow out.println('<tr>'); out.print('<td align=right>'); out.print('flow<br>\nrevision'); out.println('</td>'); out.print('<td align=left>'); if session.isInEditMode(): out.print('<form name=%s>' % FLOW_NAME_FORM) out.println('<input type=text name=%s value="%s"><br>' % (P_FLOW_NAME, definition.id.workflowDefinitionName)) out.print('<input type=text name=%s value="%s"> ' % (P_FLOW_REVISION, definition.id.workflowDefinitionRevision)) _displayOkButton(req, out, FLOW_NAME_FORM, action=UPDATE_FLOW_NAME_ACTION) out.print('</form>') else: out.print(definition.id.workflowDefinitionName); out.println('<br>') out.print(definition.id.workflowDefinitionRevision); out.println('</td>'); out.println('</tr>'); out.println('<tr>'); out.print('<td align=right colspan=2>'); out.print('<a href=%s>' % definition.id.workflowDefinitionUrl); out.print(_neutralize(definition.id.workflowDefinitionUrl)) out.print('</a>'); out.println('</td>'); out.println('</tr>'); else: # # it's a subprocess definition out.println('<tr>') out.print('<td align=center>') out.print(_img(req, IMG_SUBPROCESS)) out.print('<br>\nsubprocess') out.println('</td>') out.print('<td valign=bottom>') expId = defExpression.id.expressionId if session.isInEditMode(): subProcessNameForm = '%s::%s' % (SUBPROCESS_NAME_FORM, expId) out.print('<form name=%s>' % subProcessNameForm) out.println('<input type=hidden name=%s value="%s">' % (P_SUBPROCESS_EXP, expId)) out.print('<input type=text name=%s value="%s"> ' % (P_SUBPROCESS_NAME, subDefName)) _displayOkButton(req, out, subProcessNameForm, action=UPDATE_SUBPROCESS_NAME_ACTION) out.print('</form>') out.print(' ') _displayRemoveSubDefinitionButton(req, out, defExpression.id) else: out.print(_neutralize(subDefName)) out.println('</td>') out.println('</tr>') out.println('<tr><td align=center colspan=2>') out.println('<br>') # # render the body of the flow out.print(_img(req, IMG_START)) out.println('<br>') bodyExpression = definition.getBody(defExpression) if bodyExpression: _renderExpression(session, out, req, definition, bodyExpression) else: if session.isInEditMode() and not session.expressionToEdit: _displayAddButton(req, session, out, defExpression.id, "add root expression<br>\n") out.println('<br>') out.println(_img(req, IMG_END)) # # render each subflow #if definition.subDefinitions and len(definition.subDefinitions) > 0: out.println('<br>') for subDef in definition.getSubDefinitions(defExpression): out.println('<br>') _renderDefinition(session, out, req, definition, subDef) if session.isInEditMode(): out.print('<br>\n<p align=right><a href=%s&%s=%s&%s=%s title="Create a subprocess">subprocess %s</a></p>' % (CREATE_SUBPROCESS_ACTION, P_SUBPROCESS_EXP, defExpression.id.expressionId, P_SUBPROCESS_NAME, 'new-subprocess', _img(req, IMG_PLUS))) out.println('</td></tr></table>') # the end of the flow table
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -