📄 codec.py
字号:
launchables = [] l = getChildrenByTagName(elt, LAUNCHABLE) for e in l: launchable = Launchable() launchable.engineId = e.getAttribute(ENGINE_ID) launchable.url = e.getAttribute(URL) launchables.append(launchable) return launchablesdef parseExpressions (elt): expressions = [] l = getChildrenByTagName(elt, EXPRESSION) for e in l: exp = Expression() exp.id = parseFlowExpressionId \ (getChildrenByTagName(e, FLOW_EXPRESSION_ID)[0]) exp.applyTime = e.getAttribute(APPLY_TIME) exp.frozenTime = e.getAttribute(FROZEN_TIME) expressions.append(exp) return expressionsdef parseHistory (elt): history = [] l = getChildrenByTagName(elt, HISTORY_ITEM) for iElt in l: item = HistoryItem() item.author = iElt.getAttribute(AUTHOR) #print 'DATE >>>>>>>>>>>> >%s<' % iElt.getAttribute(DATE) item.date = iElt.getAttribute(DATE) item.host = iElt.getAttribute(HOST) item.text = str(iElt.firstChild.data) item.workflowDefinitionName = \ iElt.getAttribute(WORKFLOW_DEFINITION_NAME) item.workflowDefinitionRevision = \ iElt.getAttribute(WORKFLOW_DEFINITION_REVISION) #item.workflowInstanceId = \ # long(iElt.getAttribute(WORKFLOW_INSTANCE_ID)) item.workflowInstanceId = \ iElt.getAttribute(WORKFLOW_INSTANCE_ID) item.expressionId = \ iElt.getAttribute(EXPRESSION_ID) history.append(item) return historydef parseFlowExpressionId (elt): fei = FlowExpressionId() fei.engineId = elt.getAttribute(ENGINE_ID) fei.initialEngineId = elt.getAttribute(INITIAL_ENGINE_ID) fei.workflowDefinitionUrl = elt.getAttribute(WORKFLOW_DEFINITION_URL) fei.workflowDefinitionName = elt.getAttribute(WORKFLOW_DEFINITION_NAME) fei.workflowDefinitionRevision = elt.getAttribute(WORKFLOW_DEFINITION_REVISION) #fei.workflowInstanceId = long(elt.getAttribute(WORKFLOW_INSTANCE_ID)) fei.workflowInstanceId = elt.getAttribute(WORKFLOW_INSTANCE_ID) fei.expressionName = elt.getAttribute(EXPRESSION_NAME) #fei.expressionId = int(elt.getAttribute(EXPRESSION_ID)) fei.expressionId = elt.getAttribute(EXPRESSION_ID) return feidef parseFilterEntryList (elt): l = getChildrenByTagName(elt, FIELD) entries = [] for e in l: entry = FilterEntry() entry.fieldRegex = e.getAttribute(REGEX) entry.permissions = e.getAttribute(PERMISSIONS) entry.attributeClassName = e.getAttribute(TYPE) entries.append(entry) return entries def parseFilter (elt): filter = Filter() filter.name = elt.getAttribute(NAME) filter.addAllowed = (elt.getAttribute(ADD_ALLOWED).strip() == 'true') filter.removeAllowed = (elt.getAttribute(REMOVE_ALLOWED).strip() == 'true') filter.entryList = parseFilterEntryList(elt) return filter## ENCODING#def encode (object): doc = Document() if isinstance(object, Header): encodeHeader(doc, object) elif isinstance(object, InFlowWorkitem): encodeInFlowWorkitem(doc, object) elif isinstance(object, Cancelitem): encodeCancelitem(doc, object) elif isinstance(object, Launchitem): encodeLaunchitem(doc, object) elif isinstance(object, StringMapAttribute): e = encodeAttribute(doc, object) doc.appendChild(e) elif isinstance(object, FlowExpressionId): e = encodeFlowExpressionId(doc, object) doc.appendChild(e) else: raise ValueError, \ "No encoder for objects of class '%s'" % object.__class__ #return doc.toprettyxml(indent=' ', newl='\n', encoding=getEncoding()) result = doc.toprettyxml(indent=' ', newl='\n', encoding=ENCODING) # # DEBUG OUT #print '\n%s\n' % result return resultdef encodeFlowExpressionId (doc, flowExpressionId): e = doc.createElement(FLOW_EXPRESSION_ID) e.setAttribute \ (ENGINE_ID, flowExpressionId.engineId) e.setAttribute \ (INITIAL_ENGINE_ID, flowExpressionId.initialEngineId) e.setAttribute \ (WORKFLOW_DEFINITION_URL, flowExpressionId.workflowDefinitionUrl) e.setAttribute \ (WORKFLOW_DEFINITION_NAME, flowExpressionId.workflowDefinitionName) e.setAttribute \ (WORKFLOW_DEFINITION_REVISION, flowExpressionId.workflowDefinitionRevision) #e.setAttribute \ # (WORKFLOW_INSTANCE_ID, str(flowExpressionId.workflowInstanceId)) e.setAttribute \ (WORKFLOW_INSTANCE_ID, flowExpressionId.workflowInstanceId) e.setAttribute \ (EXPRESSION_NAME, flowExpressionId.expressionName) e.setAttribute \ (EXPRESSION_ID, flowExpressionId.expressionId) return edef encodeHeader (doc, header): e = doc.createElement(HEADER) e.appendChild(encodeFlowExpressionId(doc, header.flowExpressionId)) e.setAttribute(LAST_MODIFIED, header.lastModified) locked = 'false' if (header.locked): locked = 'true' e.setAttribute(LOCKED, locked) attributes = doc.createElement(ATTRIBUTES) attributes.appendChild(encodeAttribute(doc, header.attributes)) e.appendChild(attributes) doc.appendChild(e)#def _encodeFlowStack (doc, flowStack):## e = doc.createElement(FLOW_STACK)## for fei in flowStack:# e.appendChild(encodeFlowExpressionId(doc, fei))## return edef _encodeWorkitem (element, workitem): if workitem.lastModified != None: element.setAttribute(LAST_MODIFIED, workitem.lastModified) #element.appendChild \ # (_encodeFlowStack(element.ownerDocument, workitem.flowStack)) attributes = element.ownerDocument.createElement(ATTRIBUTES) attributes.appendChild \ (encodeAttribute(element.ownerDocument, workitem.attributes)) element.appendChild(attributes)def _encodeCancelitem (element, workitem): _encodeWorkitem(element, workitem) element.setAttribute \ (PARTICIPANT_NAME, workitem.participantName) lei = element.ownerDocument.createElement(LAST_EXPRESSION_ID) lei.appendChild(encodeFlowExpressionId \ (element.ownerDocument, workitem.lastExpressionId)) element.appendChild(lei)def encodeCancelitem (doc, workitem): element = doc.createElement(CANCELITEM) _encodeCancelitem (element, workitem) doc.appendChild(element)def encodeLaunchitem (doc, launchitem): element = doc.createElement(LAUNCHITEM) _encodeWorkitem(element, launchitem) element.setAttribute \ (WORKFLOW_DEFINITION_URL, launchitem.workflowDefinitionUrl) if launchitem.descriptionMap != None: for k in launchitem.descriptionMap.keys(): de = doc.createElement(DESCRIPTION) de.setAttribute(LANGUAGE, k) te = doc.createTextNode(launchitem.descriptionMap[k]) de.appendChild(te) element.appendChild(de) doc.appendChild(element)def encodeInFlowWorkitem (doc, workitem): element = doc.createElement(WORKITEM) _encodeCancelitem(element, workitem) element.setAttribute \ (DISPATCH_TIME, workitem.dispatchTime) _encodeFilter(element, workitem.filter) _encodeHistory(element, workitem.history) doc.appendChild(element)def _encodeFilter (elt, filter): if filter == None: return tag = CLOSED_FILTER if filter.isOpen(): tag = OPEN_FILTER eFilter = elt.ownerDocument.createElement(tag) #eFilter.setAttribute(NAME, filter.name) sAddAllowed = 'false' if filter.addAllowed: sAddAllowed = 'true' eFilter.setAttribute(ADD_ALLOWED, sAddAllowed) sRemoveAllowed = 'false' if filter.removeAllowed: sRemoveAllowed = 'true' eFilter.setAttribute(REMOVE_ALLOWED, sRemoveAllowed) _encodeFilterList(eFilter, filter.entryList) elt.appendChild(eFilter)def _encodeHistory (elt, history): if history == None: return eHistory = elt.ownerDocument.createElement(HISTORY) for item in history: eItem = eHistory.ownerDocument.createElement(HISTORY_ITEM) eItem.setAttribute(AUTHOR, item.author) eItem.setAttribute(HOST, item.host) eItem.setAttribute(DATE, item.date) eItem.setAttribute \ (WORKFLOW_DEFINITION_NAME, item.workflowDefinitionName) eItem.setAttribute \ (WORKFLOW_DEFINITION_REVISION, item.workflowDefinitionRevision) #eItem.setAttribute \ # (WORKFLOW_INSTANCE_ID, str(item.workflowInstanceId)) eItem.setAttribute \ (WORKFLOW_INSTANCE_ID, item.workflowInstanceId) eItem.setAttribute \ (EXPRESSION_ID, str(item.expressionId)) tn = eItem.ownerDocument.createTextNode(item.text) eItem.appendChild(tn) eHistory.appendChild(eItem) elt.appendChild(eHistory)def _encodeFilterList (elt, list): if list == None or len(list) < 1: return for entry in list: eField = elt.ownerDocument.createElement(FIELD) eField.setAttribute(REGEX, entry.fieldRegex) eField.setAttribute(PERMISSIONS, entry.permissions) if (entry.attributeClassName != None): eField.setAttribute(TYPE, entry.attributeClassName) elt.appendChild(eField)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -