List of usage examples for org.w3c.dom Element getElementsByTagNameNS
public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException;
NodeList
of all the descendant Elements
with a given local name and namespace URI in document order. From source file:org.wso2.carbon.bpel.b4p.extension.PeopleActivity.java
/** * Process the <attachmentPropagation/> element defined under peopleActivity * * @param peopleActivityElement peopleActivity (parent element) where the <attachmentPropagation/> resides * @throws FaultException can be raised if there are more than one <attachmentPropagation/> elements defined * or the namespace for the <attachmentPropagation/> element is not defined correctly *//*w w w .ja v a 2 s . c o m*/ private void processAttachmentPropagationElement(Element peopleActivityElement) throws FaultException { NodeList attachmentElementList = peopleActivityElement.getElementsByTagNameNS( BPEL4PeopleConstants.B4P_NAMESPACE, BPEL4PeopleConstants.ATTACHMENT_PROPAGATION_ACTIVITY); if (attachmentElementList.getLength() > 1) { throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "More than one elements defined for:" + BPEL4PeopleConstants.ATTACHMENT_PROPAGATION_ACTIVITY + " inside " + BPEL4PeopleConstants.PEOPLE_ACTIVITY); } else if (attachmentElementList.getLength() == 1) { // <attachmentPropagation/> element processing logic Node attachmentPropagationElement = attachmentElementList.item(0); this.attachmentPropagation = new AttachmentPropagation((Element) attachmentPropagationElement); } else if (attachmentElementList.getLength() == 0) { //As the BPEL4PeopleConstants.ATTACHMENT_PROPAGATION_ACTIVITY is not declared. So handling the default // behavior if (log.isDebugEnabled()) { log.debug("No " + BPEL4PeopleConstants.ATTACHMENT_PROPAGATION_ACTIVITY + " " + "activities found. Hence " + "assuming the default values defined by specification."); } this.attachmentPropagation = new AttachmentPropagation(); } else { if (peopleActivityElement.getElementsByTagName(BPEL4PeopleConstants.ATTACHMENT_PROPAGATION_ACTIVITY) .getLength() > 0) { throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Namespace defined for :" + BPEL4PeopleConstants.ATTACHMENT_PROPAGATION_ACTIVITY + " inside " + BPEL4PeopleConstants.PEOPLE_ACTIVITY + " is wrong."); } } }
From source file:org.wso2.carbon.humantask.core.api.rendering.HTRenderingApiImpl.java
public SetTaskOutputResponse setTaskOutput(URI taskIdentifier, SetOutputValuesType values) throws SetTaskOutputFaultException { //Retrieve task information TaskDAO htTaskDAO;/*from www . j a v a 2 s . c o m*/ try { htTaskDAO = getTaskDAO(taskIdentifier); } catch (Exception e) { log.error("Error occurred while retrieving task data", e); throw new SetTaskOutputFaultException(e); } QName taskName = QName.valueOf(htTaskDAO.getName()); //Check hash map for output message template Element outputMsgTemplate = outputTemplates.get(taskName); if (outputMsgTemplate == null) { //Output message template not available try { //generate output message template int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId(); HumanTaskBaseConfiguration htConf = HumanTaskServiceComponent.getHumanTaskServer() .getTaskStoreManager().getHumanTaskStore(tenantID).getTaskConfiguration(taskName); TaskConfiguration taskConf = (TaskConfiguration) htConf; //retrieve response binding Service callbackService = (Service) taskConf.getResponseWSDL().getServices() .get(taskConf.getCallbackServiceName()); Port callbackPort = (Port) callbackService.getPorts().get(taskConf.getCallbackPortName()); String callbackBinding = callbackPort.getBinding().getQName().getLocalPart(); outputMsgTemplate = createSoapTemplate(taskConf.getResponseWSDL().getDocumentBaseURI(), taskConf.getResponsePortType().getLocalPart(), taskConf.getResponseOperation(), callbackBinding); } catch (Exception e) { log.error("Error occurred while output message template generation", e); throw new SetTaskOutputFaultException("Unable to generate output message", e); } //add to the template HashMap if (outputMsgTemplate != null) { outputTemplates.put(taskName, outputMsgTemplate); } else { log.error("Unable to create output message template"); throw new SetTaskOutputFaultException("Unable to generate output message"); } } //update template with new values try { //TODO improve this section with caching QName renderingType = new QName(htRenderingNS, "output", "wso2"); String outputRenderings = (String) taskOps.getRendering(taskIdentifier, renderingType); SetOutputvalueType[] valueSet = values.getValue(); if (outputRenderings != null && valueSet.length > 0) { Element outputRenderingsElement = DOMUtils.stringToDOM(outputRenderings); //update elements in the template to create output xml for (int i = 0; i < valueSet.length; i++) { Element outElement = getOutputElementById(valueSet[i].getId(), outputRenderingsElement); if (outElement != null) { outputMsgTemplate = updateXmlByXpath(outputMsgTemplate, outElement.getElementsByTagNameNS(htRenderingNS, "xpath").item(0).getTextContent(), valueSet[i].getString(), outputRenderingsElement.getOwnerDocument()); } } } else { log.error("Retrieving output renderings failed"); throw new SetTaskOutputFaultException("Retrieving output renderings failed"); } //TODO what is this NCName? taskOps.setOutput(taskIdentifier, new NCName("message"), DOMUtils.domToString(outputMsgTemplate)); } catch (IllegalArgumentFault illegalArgumentFault) { //Error occurred while retrieving HT renderings and set output message throw new SetTaskOutputFaultException(illegalArgumentFault); } catch (SAXException e) { log.error("Error occured while parsing output renderings", e); throw new SetTaskOutputFaultException("Response message generation failed"); } catch (XPathExpressionException e) { //Error occured while updating elements in the template to create output xml log.error("XPath evaluation failed", e); throw new SetTaskOutputFaultException("Internal Error Occurred"); } catch (Exception e) { //Error occurred while updating template with new values log.error("Error occurred while updating template with new values", e); throw new SetTaskOutputFaultException("Internal Error Occurred"); } SetTaskOutputResponse response = new SetTaskOutputResponse(); response.setSuccess(true); return response; }
From source file:org.wso2.carbon.humantask.core.api.rendering.HTRenderingApiImpl.java
/** * @param taskIdentifier : interested task identifier * @return set of input renderings wrapped within InputType * @throws IllegalArgumentFault : error occured while retrieving renderings from task definition * @throws IOException If an error occurred while reading from the input source * @throws SAXException If the content in the input source is invalid *///from w ww . j a v a 2 s. c o m private InputType getRenderingInputElements(URI taskIdentifier) throws IllegalArgumentFault, IOException, SAXException, IllegalOperationFault, IllegalAccessFault, IllegalStateFault, XPathExpressionException { //TODO Chaching : check cache against task id for input renderings QName renderingType = new QName(htRenderingNS, "input", "wso2"); String inputRenderings = (String) taskOps.getRendering(taskIdentifier, renderingType); //Create input element InputType renderingInputs = null; //check availability of input renderings if (inputRenderings != null && inputRenderings.length() > 0) { //parse input renderings Element inputRenderingsElement = DOMUtils.stringToDOM(inputRenderings); //retrieve input elements NodeList inputElementList = inputRenderingsElement.getElementsByTagNameNS(htRenderingNS, "element"); Element taskInputMsgElement = DOMUtils.stringToDOM((String) taskOps.getInput(taskIdentifier, null)); if (inputElementList != null && inputElementList.getLength() > 0) { int inputElementNum = inputElementList.getLength();//hold number of input element InputElementType[] inputElements = new InputElementType[inputElementNum]; for (int i = 0; i < inputElementNum; i++) { Element tempElement = (Element) inputElementList.item(i); String label = tempElement.getElementsByTagNameNS(htRenderingNS, "label").item(0) .getTextContent(); String value = tempElement.getElementsByTagNameNS(htRenderingNS, "value").item(0) .getTextContent(); //check if the value is xpath or not //if the value starts with '/' then considered as an xpath and evaluate over received Input Message if (value.startsWith("/") && taskInputMsgElement != null) { //value represents xpath. evaluate against the input message String xpathValue = evaluateXPath(value, taskInputMsgElement, inputRenderingsElement.getOwnerDocument()); if (xpathValue != null) { value = xpathValue; } } inputElements[i] = new InputElementType(); inputElements[i].setLabel(label); inputElements[i].setValue(value); } renderingInputs = new InputType(); renderingInputs.setElement(inputElements); //TODO cache renderingInputs against task instance id } } //NOTE : //HT without input renderings is valid scennario in such scennario return zero length input renderings will be returned return renderingInputs; }
From source file:org.wso2.carbon.humantask.core.api.rendering.HTRenderingApiImpl.java
/** * Function to retrieve output rendering elements * * @param taskIdentifier interested task identifier * @return set of output renderings wrapped within OutputType * @throws IllegalArgumentFault error occured while retrieving renderings from task definition * @throws IOException If an error occurred while reading from the input source * @throws SAXException If the xml content in the input source is invalid * @throws IllegalOperationFault// w ww . ja v a 2s. c o m * @throws IllegalAccessFault * @throws IllegalStateFault * @throws XPathExpressionException If error occurred while xpath evaluation * @throws GetRenderingsFaultException If unable to find unique id for the wso2:output rendering element */ private OutputType getRenderingOutputElements(URI taskIdentifier) throws IllegalArgumentFault, IOException, SAXException, IllegalOperationFault, IllegalAccessFault, IllegalStateFault, XPathExpressionException, GetRenderingsFaultException { QName renderingType = new QName(htRenderingNS, "output", "wso2"); String outputRenderings = (String) taskOps.getRendering(taskIdentifier, renderingType); //create output element OutputType renderingOutputs = null; //HT without output renderings is valid scenario //check availability of output renderings if (outputRenderings != null && outputRenderings.length() > 0) { //parse output renderings Element outputRenderingsElement = DOMUtils.stringToDOM(outputRenderings); //retrieve output rendering elements NodeList outputElementList = outputRenderingsElement.getElementsByTagNameNS(htRenderingNS, "element"); if (outputElementList != null && outputElementList.getLength() > 0) { int outputElementNum = outputElementList.getLength(); OutputElementType[] outputElements = new OutputElementType[outputElementNum]; //TODO get task output message from the cache // (if not in the cache) retrieve saved output using HumanTaskClientAPI String savedOutputMsg = (String) taskOps.getOutput(taskIdentifier, null); //Element to hold parsed saved output message Element savedOutputElement = null; if (savedOutputMsg != null && savedOutputMsg.length() > 0) { savedOutputElement = DOMUtils.stringToDOM(savedOutputMsg); } for (int i = 0; i < outputElementNum; i++) { Element tempElement = (Element) outputElementList.item(i); if (tempElement.hasAttribute("id")) { //Retrieve element data String elementID = tempElement.getAttribute("id"); String label = tempElement.getElementsByTagNameNS(htRenderingNS, "label").item(0) .getTextContent(); String xpath = tempElement.getElementsByTagNameNS(htRenderingNS, "xpath").item(0) .getTextContent(); String defaultValue = tempElement.getElementsByTagNameNS(htRenderingNS, "default").item(0) .getTextContent(); //set the readOnly attribute if Exists, default false String readOnly = "false"; if (tempElement.hasAttribute("readOnly")) { readOnly = tempElement.getAttribute("readOnly"); } //set element data in the response message outputElements[i] = new OutputElementType(); //set ID outputElements[i].setId(elementID); //set label outputElements[i].setLabel(label); //set xpath outputElements[i].setXpath(xpath); //set value Element valueElement = (Element) tempElement.getElementsByTagNameNS(htRenderingNS, "value") .item(0); outputElements[i].setValue(createOutRenderElementValue(valueElement)); if (readOnly.equals("true")) { outputElements[i].setReadOnly(true); } else { outputElements[i].setReadOnly(false); } if (savedOutputElement != null) { //resolve default value String savedOutMessageValue = evaluateXPath(xpath, savedOutputElement, outputRenderingsElement.getOwnerDocument()); if (savedOutMessageValue == null) { outputElements[i].set_default(defaultValue); } else { outputElements[i].set_default(savedOutMessageValue); } } else { //add default value specified in the HT rendering definition outputElements[i].set_default(defaultValue); } } else { //no unique id for the element log.error("Unable to find unique id for the wso2:output rendering element"); throw new GetRenderingsFaultException( "Unable to find unique id for the wso2:output rendering element"); } } renderingOutputs = new OutputType(); renderingOutputs.setElement(outputElements); } } //NOTE : //HT without output renderings is valid scennario in such scennario return zero length output renderings will be returned return renderingOutputs; }
From source file:org.wso2.carbon.humantask.core.api.rendering.HTRenderingApiImpl.java
/** * Function to retrieve output rendering element with matching id * * @param id output rendering element id * @param outputRendering DOMElement representing output renderings in the HT definition * @return DOM Element if matching element found, otherwise return null *///from w w w . j a v a 2 s . c o m private static Element getOutputElementById(String id, Element outputRendering) { NodeList nodes = outputRendering.getElementsByTagNameNS(htRenderingNS, "element"); for (int i = 0; i < nodes.getLength(); i++) { Element tempElement = (Element) nodes.item(i); if (tempElement.getAttribute("id").equals(id)) { return tempElement; } } return null; }
From source file:org.wso2.carbon.humantask.core.api.rendering.HTRenderingApiImpl.java
/** * Function to create response message template * * @param SrcWsdl source wsld : wsdl file path or url * @param portType callback port type/* w w w . ja va 2s.com*/ * @param operation callback operation name * @param binding callback binding * @return DOM element of response message template * @throws IOException If error occurred while parsing string xml to Dom element * @throws SAXException If error occurred while parsing string xml to Dom element */ private static Element createSoapTemplate(String SrcWsdl, String portType, String operation, String binding) throws IOException, SAXException { WSDLParser parser = new WSDLParser(); //BPS-677 int fileLocationPrefixIndex = SrcWsdl.indexOf(HumanTaskConstants.FILE_LOCATION_FILE_PREFIX); if (SrcWsdl.indexOf(HumanTaskConstants.FILE_LOCATION_FILE_PREFIX) != -1) { SrcWsdl = SrcWsdl .substring(fileLocationPrefixIndex + HumanTaskConstants.FILE_LOCATION_FILE_PREFIX.length()); } Definitions wsdl = parser.parse(SrcWsdl); StringWriter writer = new StringWriter(); //SOAPRequestCreator constructor: SOARequestCreator(Definitions, Creator, MarkupBuilder) SOARequestCreator creator = new SOARequestCreator(wsdl, new RequestTemplateCreator(), new MarkupBuilder(writer)); //creator.createRequest(PortType name, Operation name, Binding name); creator.createRequest(portType, operation, binding); Element outGenMessageDom = DOMUtils.stringToDOM(writer.toString()); Element outMsgElement = null; NodeList nodes = outGenMessageDom.getElementsByTagNameNS(outGenMessageDom.getNamespaceURI(), "Body").item(0) .getChildNodes(); if (nodes != null) { for (int i = 0; i < nodes.getLength(); i++) { if (nodes.item(i).getNodeType() == Node.ELEMENT_NODE) { outMsgElement = (Element) nodes.item(i); break; } } } if (outMsgElement != null) { //convert element to string and back to element to remove Owner Document return DOMUtils.stringToDOM(DOMUtils.domToString(outMsgElement)); } return null; }
From source file:org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.provider.LiteralBasedOrgEntityProvider.java
public List<OrganizationalEntityDAO> getOrganizationalEntities(PeopleQueryEvaluator peopleQueryEvaluator, TFrom tFrom, EvaluationContext evaluationContext) { TLiteral literal = tFrom.getLiteral(); List<OrganizationalEntityDAO> orgEntityList = new ArrayList<OrganizationalEntityDAO>(); Element domNode = (Element) literal.getDomNode(); if (domNode != null) { NodeList orgEntityNodes = domNode.getElementsByTagNameNS( HumanTaskConstants.organizationalEntityQname.getNamespaceURI(), HumanTaskConstants.organizationalEntityQname.getLocalPart()); // There should be only one organizational Entity if (orgEntityNodes.getLength() == 1) { Node orgEntityNode = orgEntityNodes.item(0); addOrgEntitiesForOrganizationEntityNode(orgEntityNode, peopleQueryEvaluator, orgEntityList); } else {/* w ww . ja va 2s. c om*/ NodeList elements = domNode.getElementsByTagNameNS(HumanTaskConstants.userQname.getNamespaceURI(), HumanTaskConstants.userQname.getLocalPart()); if (elements.getLength() == 1) { // There should only be one user element CommonTaskUtil.addOrgEntityForUserNode(elements.item(0), peopleQueryEvaluator, orgEntityList); } } } return orgEntityList; }
From source file:org.wso2.carbon.humantask.core.dao.TaskCreationContext.java
/** * Extract the header content related to attachment-ids and create a list from of those attachment-ids * * @return list of attachment-ids//from ww w .j a va2s . c o m */ public List<String> getAttachmentIDs() { List<String> attachmentIDs = new ArrayList<String>(); final String NAMESPACE = Constants.ATTACHMENT_ID_NAMESPACE; final String NAMESPACE_PREFIX = Constants.ATTACHMENT_ID_NAMESPACE_PREFIX; final String PARENT_ELEMENT_NAME = Constants.ATTACHMENT_ID_PARENT_ELEMENT_NAME; final String CHILD_ELEMENT_NAME = Constants.ATTACHMENT_ID_CHILD_ELEMENT_NAME; Element attachmentElement = this.messageHeaderParts.get(PARENT_ELEMENT_NAME); if (attachmentElement != null && NAMESPACE.equals(attachmentElement.getNamespaceURI())) { NodeList childElementList = attachmentElement.getElementsByTagNameNS(NAMESPACE, CHILD_ELEMENT_NAME); int size = childElementList.getLength(); for (int i = 0; i < size; i++) { Element child = (Element) childElementList.item(i); attachmentIDs.add(child.getTextContent()); } } else { if (log.isDebugEnabled()) { log.debug("No header elements found with :" + PARENT_ELEMENT_NAME); } } return attachmentIDs; }
From source file:org.wso2.carbon.humantask.core.engine.util.CommonTaskUtil.java
public static void setTaskOverrideContextAttributes(TaskDAO task, Map<String, Element> headerElements) { //TODO fix this for remaining properties. try {//from w w w . ja v a 2 s . co m if (headerElements != null) { Element contextRequest = headerElements.get(HumanTaskConstants.HT_CONTEXT_REQUEST); if (contextRequest != null) { if (!TaskType.NOTIFICATION.equals(task.getType())) { // Notification can't be skipped. NodeList nodeList = contextRequest.getElementsByTagNameNS( HumanTaskConstants.HT_CONTEXT_NAMESPACE, HumanTaskConstants.HT_CONTEXT_IS_SKIPABLE); if (nodeList != null && nodeList.getLength() > 0) { Node isSkipable = nodeList.item(0); task.setSkipable(Boolean.parseBoolean(isSkipable.getTextContent())); } } NodeList nodeList = contextRequest.getElementsByTagNameNS( HumanTaskConstants.HT_CONTEXT_NAMESPACE, HumanTaskConstants.HT_CONTEXT_PRIORITY); if (nodeList != null && nodeList.getLength() > 0) { Node priority = nodeList.item(0); task.setPriority(Integer.parseInt(priority.getTextContent())); } } } } catch (Exception e) { log.error("Error while setting override attributes to task", e); } }
From source file:org.wso2.carbon.humantask.core.scheduler.NotificationScheduler.java
/** * Publish SMS notifications by extracting the information from the incoming message rendering tags * <htd:renderings>//ww w . j av a2 s .c o m * <htd:rendering type="wso2:email" xmlns:wso2="http://wso2.org/ht/schema/renderings/"> * <wso2:to name="to" type="xsd:string">wso2bpsemail@wso2.com</wso2:to> * <wso2:subject name="subject" type="xsd:string">email subject to user</wso2:subject> * <wso2:body name="body" type="xsd:string">Hi email notifications</wso2:body> * </htd:rendering> * <htd:rendering type="wso2:sms" xmlns:wso2="http://wso2.org/ht/schema/renderings/"> * <wso2:receiver name="receiver" type="xsd:string">94777459299</wso2:receiver> * <wso2:body name="body" type="xsd:string">Hi $firstname$</wso2:body> * </htd:rendering> * </htd:renderings> * @param task Task Dao Object for this notification task * @param taskConfiguration task Configuration for this notification task instance */ public void publishSMSNotifications(TaskDAO task, HumanTaskBaseConfiguration taskConfiguration) throws IOException, SAXException, ParserConfigurationException { String renderingSMS = CommonTaskUtil.getRendering(task, taskConfiguration, new QName(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.RENDERING_TYPE_SMS)); if (renderingSMS != null) { Map<String, String> dynamicPropertiesForSms = new HashMap<String, String>(); Element rootSMS = DOMUtils.stringToDOM(renderingSMS); if (rootSMS != null) { String smsReceiver = null; String smsBody = null; if (log.isDebugEnabled()) { log.debug("Parsing SMS notification rendering element 'receiver' for notification id " + task.getId()); } NodeList smsReceiverList = rootSMS.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.SMS_RECEIVER_TAG); if (smsReceiverList != null && smsReceiverList.getLength() > 0) { smsReceiver = smsReceiverList.item(0).getTextContent(); } else { log.warn("SMS notification rendering element 'receiver' not specified for notification with id " + task.getId()); } NodeList smsBodyList = rootSMS.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_OR_SMS_BODY_TAG); if (log.isDebugEnabled()) { log.debug("Parsing SMS notification rendering element 'body' for notification id " + task.getId()); } if (smsBodyList != null && smsBodyList.getLength() > 0) { smsBody = smsBodyList.item(0).getTextContent(); } else { log.warn("SMS notification rendering element 'body' not specified for notification with id " + task.getId()); } dynamicPropertiesForSms.put(HumanTaskConstants.ARRAY_SMS_NO, smsReceiver); String adaptorName = getAdaptorName(task.getName(), HumanTaskConstants.RENDERING_TYPE_SMS); if (!smsAdapterNames.contains(adaptorName)) { OutputEventAdapterConfiguration outputEventAdapterConfiguration = createOutputEventAdapterConfiguration( adaptorName, HumanTaskConstants.RENDERING_TYPE_SMS, HumanTaskConstants.SMS_MESSAGE_FORMAT); try { HumanTaskServiceComponent.getOutputEventAdapterService() .create(outputEventAdapterConfiguration); smsAdapterNames.add(adaptorName); } catch (OutputEventAdapterException e) { log.error("Unable to create Output Event Adapter : " + adaptorName, e); } } HumanTaskServiceComponent.getOutputEventAdapterService().publish(adaptorName, dynamicPropertiesForSms, smsBody); //smsAdapter.publish(smsBody, dynamicPropertiesForSms); } } else { log.warn("SMS Rendering type not found for task definition with task id " + task.getId()); } }