List of usage examples for org.w3c.dom Element getNamespaceURI
public String getNamespaceURI();
null
if it is unspecified (see ). From source file:iristk.flow.FlowCompiler.java
protected void printAction(Object action, Object parent, String exprContext) throws FlowCompilerException { if (action instanceof JAXBElement<?>) action = ((JAXBElement<?>) action).getValue(); printLocation(action);//from w w w. jav a 2 s . co m if (action instanceof iristk.xml.flow.Goto) { iristk.xml.flow.Goto gotoAction = (iristk.xml.flow.Goto) action; if (exprContext != null) throw new FlowCompilerException("<goto> not allowed in expression", gotoAction.sourceLocation().getLineNumber()); String stateVar = ""; if (gotoAction.getState() != null) { if (!stateExists(gotoAction.getState())) throw new FlowCompilerException("State " + gotoAction.getState() + " does not exist", gotoAction.sourceLocation().getLineNumber()); stateVar = varname("state"); code.println(stateClass(gotoAction.getState()) + " " + stateVar + " = " + newState(gotoAction.getState()) + ";"); printSetStateParameters(stateVar, getParameters(gotoAction.getOtherAttributes(), gotoAction.getContent(), gotoAction)); } else if (gotoAction.getExpr() != null) { stateVar = gotoAction.getExpr(); } else { throw new FlowCompilerException("Goto must either have a 'state' or 'expr' attribute", gotoAction.sourceLocation().getLineNumber()); } code.println( "flowThread.gotoState(" + stateVar + ", currentState, new FlowEventInfo(currentState, event, " + location(flowXml.getLocation(action)) + "));"); code.println("eventResult = EVENT_ABORTED;"); code.println("break EXECUTION;"); } else if (action instanceof iristk.xml.flow.Run) { iristk.xml.flow.Run runAction = (iristk.xml.flow.Run) action; if (exprContext != null) throw new FlowCompilerException("<run> not allowed in expression", runAction.sourceLocation().getLineNumber()); String stateVar = varname("state"); code.println(stateClass(runAction.getState()) + " " + stateVar + " = " + newState(runAction.getState()) + ";"); printSetStateParameters(stateVar, getParameters(runAction.getOtherAttributes(), runAction.getContent(), runAction)); code.println("FlowRunner.FlowThread " + stateVar + "Thread = flowThread.runState(" + stateVar + ", new FlowEventInfo(currentState, event, " + location(flowXml.getLocation(action)) + "));"); } else if (action instanceof iristk.xml.flow.Call) { iristk.xml.flow.Call callAction = (iristk.xml.flow.Call) action; if (exprContext != null) throw new FlowCompilerException("<call> not allowed in expression", callAction.sourceLocation().getLineNumber()); String stateVar = varname("state"); code.println(stateClass(callAction.getState()) + " " + stateVar + " = " + newState(callAction.getState()) + ";"); printSetStateParameters(stateVar, getParameters(callAction.getOtherAttributes(), callAction.getContent(), callAction)); code.println("if (!flowThread.callState(" + stateVar + ", new FlowEventInfo(currentState, event, " + location(flowXml.getLocation(action)) + "))) {"); code.println("eventResult = EVENT_ABORTED;"); code.println("break EXECUTION;"); code.println("}"); } else if (action instanceof iristk.xml.flow.Return) { iristk.xml.flow.Return returnAction = (iristk.xml.flow.Return) action; if (exprContext != null) throw new FlowCompilerException("<return> not allowed in expression", returnAction.sourceLocation().getLineNumber()); if (returnAction.getEvent() != null || returnAction.getCopy() != null) { String returnEvent = varname("returnEvent"); printInitEvent(returnEvent, returnAction.getCopy(), returnAction.getEvent(), getParameters(returnAction.getOtherAttributes(), returnAction.getContent(), returnAction)); //code.println("flowThread.raiseEvent(" + returnEvent + ", new FlowEventInfo(currentState, event, " + locationConstructor(flowReader.getLocation(action)) + ");"); code.println("flowThread.returnFromCall(this, " + returnEvent + ", new FlowEventInfo(currentState, event, " + location(flowXml.getLocation(action)) + "));"); } else { code.println("flowThread.returnFromCall(this, null, new FlowEventInfo(currentState, event, " + location(flowXml.getLocation(action)) + "));"); } code.println("eventResult = EVENT_ABORTED;"); code.println("break EXECUTION;"); } else if (action instanceof Reentry) { //code.println("flowThread.raiseEvent(new EntryEvent(), new FlowEventInfo(currentState, event, " + locationConstructor(flowReader.getLocation(action)) + ");"); Reentry reentryAction = (Reentry) action; if (exprContext != null) throw new FlowCompilerException("<reentry> not allowed in expression", reentryAction.sourceLocation().getLineNumber()); code.println("flowThread.reentryState(this, new FlowEventInfo(currentState, event, " + location(flowXml.getLocation(action)) + "));"); code.println("eventResult = EVENT_ABORTED;"); code.println("break EXECUTION;"); } else if (action instanceof iristk.xml.flow.Block) { //System.out.println("BLOCK " + currentLineNumber); iristk.xml.flow.Block blockAction = (iristk.xml.flow.Block) action; String cond = ""; if (blockAction.getCond() != null) { cond = "if (" + formatCondExpr(blockAction.getCond()) + ") "; } code.println(cond + "{"); printActions(blockAction.getContent(), action, exprContext); code.println("}"); } else if (action instanceof iristk.xml.flow.Wait) { iristk.xml.flow.Wait waitAction = (iristk.xml.flow.Wait) action; if (exprContext != null) throw new FlowCompilerException("<wait> not allowed in expression", waitAction.sourceLocation().getLineNumber()); String waitvar = varname("waitState"); code.println(DialogFlow.class.getName() + ".wait " + waitvar + " = new " + DialogFlow.class.getName() + ".wait();"); code.println(waitvar + ".setMsec(" + waitAction.getMsec() + ");"); code.println("if (!flowThread.callState(" + waitvar + ", new FlowEventInfo(currentState, event, " + location(flowXml.getLocation(action)) + "))) {"); code.println("eventResult = EVENT_ABORTED;"); code.println("break EXECUTION;"); code.println("}"); } else if (action instanceof Random) { Random randomAction = (Random) action; if (randomAction.getList() != null) { if (exprContext == null) { throw new FlowCompilerException("<random list=\"...\"/> only allowed in expressions", randomAction.sourceLocation().getLineNumber()); } code.println(exprContext + ".append(randstr(" + randomAction.getList() + "));"); } else { int tot = 0; for (Object child : randomAction.getAny()) { int inc = 1; if (child instanceof JAXBElement) child = ((JAXBElement) child).getValue(); if (child instanceof Block && ((Block) child).getWeight() != null) inc = ((Block) child).getWeight(); tot += inc; } int n = 0; int lastn = 0; String chosenVar = varname("chosen"); String matchingVar = varname("matching"); code.println("boolean " + chosenVar + " = false;"); code.println("boolean " + matchingVar + " = true;"); code.println("while (!" + chosenVar + " && " + matchingVar + ") {"); String randVar = varname("rand"); String model = "iristk.util.RandomList.RandomModel." + randomAction.getModel().toUpperCase(); code.println("int " + randVar + " = random(" + randomAction.hashCode() + ", " + tot + ", " + model + ");"); code.println(matchingVar + " = false;"); for (Object child : randomAction.getAny()) { if (n > 0) code.println("}"); int inc = 1; String cond = "true"; List<Object> actions = new ArrayList<>(); if (child instanceof JAXBElement) child = ((JAXBElement) child).getValue(); if (child instanceof Block) { Block block = (Block) child; if (block.getWeight() != null) inc = block.getWeight(); if (block.getCond() != null) cond = formatCondExpr(block.getCond()); actions.addAll(block.getContent()); } else { actions.add(child); } n += inc; code.println("if (" + cond + ") {"); code.println(matchingVar + " = true;"); code.println("if (" + randVar + " >= " + lastn + " && " + randVar + " < " + n + ") {"); code.println(chosenVar + " = true;"); printActions(actions, randomAction, exprContext); code.println("}"); lastn = n; } code.println("}"); code.println("}"); } } else if (action instanceof Select) { Select select = (Select) action; String label = varname("SELECTION"); code.println(label + ":"); code.println("{"); for (Object child : select.getAny()) { String cond = ""; List<Object> actions = new ArrayList<>(); if (child instanceof JAXBElement) child = ((JAXBElement) child).getValue(); if (child instanceof Block) { Block block = (Block) child; if (block.getCond() != null) cond = "if (" + formatCondExpr(block.getCond()) + ") "; actions.addAll(block.getContent()); } else { actions.add(child); } code.println(cond + "{"); printActions(actions, select, exprContext); code.println("break " + label + ";"); code.println("}"); if (cond.equals("")) break; } code.println("}"); } else if (action instanceof iristk.xml.flow.Raise) { iristk.xml.flow.Raise raiseAction = (iristk.xml.flow.Raise) action; if (exprContext != null) throw new FlowCompilerException("<raise> not allowed in expression", raiseAction.sourceLocation().getLineNumber()); String raiseEvent = varname("raiseEvent"); printInitEvent(raiseEvent, raiseAction.getCopy(), raiseAction.getEvent(), getParameters(raiseAction.getOtherAttributes(), raiseAction.getContent(), raiseAction)); if (raiseAction.getDelay() != null) { String delayedEvent = "flowThread.raiseEvent(" + raiseEvent + ", " + formatAttrExpr(raiseAction.getDelay()) + ", new FlowEventInfo(currentState, event, " + location(flowXml.getLocation(action)) + "))"; if (raiseAction.isForgetOnExit()) { code.println("forgetOnExit(" + delayedEvent + ");"); } else { code.println(delayedEvent + ";"); } } else { code.println("if (flowThread.raiseEvent(" + raiseEvent + ", new FlowEventInfo(currentState, event, " + location(flowXml.getLocation(action)) + ")) == State.EVENT_ABORTED) {"); code.println("eventResult = EVENT_ABORTED;"); code.println("break EXECUTION;"); code.println("}"); } } else if (action instanceof iristk.xml.flow.Send) { iristk.xml.flow.Send sendAction = (iristk.xml.flow.Send) action; if (exprContext != null) throw new FlowCompilerException("<send> not allowed in expression", sendAction.sourceLocation().getLineNumber()); String sendEvent = varname("sendEvent"); printInitEvent(sendEvent, sendAction.getCopy(), sendAction.getEvent(), getParameters(sendAction.getOtherAttributes(), sendAction.getContent(), sendAction)); if (sendAction.getDelay() != null) code.println("flowRunner.sendEvent(" + sendEvent + ", " + formatAttrExpr(sendAction.getDelay()) + ", new FlowEventInfo(currentState, event, " + location(flowXml.getLocation(action)) + "));"); else code.println("flowRunner.sendEvent(" + sendEvent + ", new FlowEventInfo(currentState, event, " + location(flowXml.getLocation(action)) + "));"); if (sendAction.getBindId() != null) { code.println(sendAction.getBindId() + " = " + sendEvent + ".getId();"); } } else if (action instanceof iristk.xml.flow.If) { iristk.xml.flow.If ifAction = (iristk.xml.flow.If) action; code.println("if (" + formatCondExpr(ifAction.getCond()) + ") {"); printActions(ifAction.getContent(), ifAction, exprContext); code.println("}"); } else if (action instanceof iristk.xml.flow.Else) { code.println("} else {"); } else if (action instanceof iristk.xml.flow.Elseif) { iristk.xml.flow.Elseif eifAction = (iristk.xml.flow.Elseif) action; code.println("} else if (" + formatCondExpr(eifAction.getCond()) + ") {"); } else if (action instanceof iristk.xml.flow.Propagate) { iristk.xml.flow.Propagate propagateAction = (iristk.xml.flow.Propagate) action; if (exprContext != null) throw new FlowCompilerException("<propagate> not allowed in expression", propagateAction.sourceLocation().getLineNumber()); code.println("eventResult = EVENT_IGNORED;"); code.println("break EXECUTION;"); } else if (action instanceof Repeat) { Repeat repeat = (Repeat) action; String handler = repeat.getHandler(); if (handler == null) { handler = varname("handler"); } code.println("{"); if (repeat.getTimes() != null) { code.println("RepeatHandler " + handler + " = new RepeatHandler(" + formatAttrExpr(repeat.getTimes()) + ");"); code.println("while (" + handler + ".getPosition() < " + handler + ".getLength()) {"); } else if (repeat.getWhile() != null) { code.println("RepeatHandler " + handler + " = new RepeatHandler();"); code.println("while (" + formatAttrExpr(repeat.getWhile()) + ") {"); } else if (repeat.getList() != null) { code.println("RepeatHandler " + handler + " = new RepeatHandler(" + formatAttrExpr(repeat.getList()) + ");"); code.println("while (" + handler + ".getPosition() < " + handler + ".getLength()) {"); } printActions(repeat.getContent(), repeat, exprContext); code.println(handler + ".next();"); code.println("}"); code.println("}"); } else if (action instanceof Var) { Var varAction = (Var) action; if (exprContext != null) throw new FlowCompilerException("<var> not allowed in expression", varAction.sourceLocation().getLineNumber()); code.println(variable((Var) action)); } else if (action instanceof iristk.xml.flow.Exec) { code.println(formatExec(((iristk.xml.flow.Exec) action).getValue().trim())); } else if (action instanceof iristk.xml.flow.Log) { code.println("log(" + createExpression(((iristk.xml.flow.Log) action).getContent(), action) + ");"); } else if (action instanceof iristk.xml.flow.Expr) { if (exprContext == null) { throw new FlowCompilerException("<expr> not allowed", currentLineNumber); } else { code.println(exprContext + ".append(" + formatExpr(((Expr) action).getValue()) + ");"); } } else if (action instanceof Element) {//perhaps implement variable name here Element elem = (Element) action; if (exprContext == null) { if (elem.getNamespaceURI().equals("iristk.flow") || elem.getPrefix() == null) { throw new FlowCompilerException("Bad element: <" + elem.getLocalName() + ">", currentLineNumber); } String stateVar = varname("state"); code.println(stateClass(elem) + " " + stateVar + " = " + newState(elem) + ";"); printSetStateParameters(stateVar, getParameters(elem)); code.println("if (!flowThread.callState(" + stateVar + ", new FlowEventInfo(currentState, event, " + location(flowXml.getLocation(parent)) + "))) {"); code.println("eventResult = EVENT_ABORTED;"); code.println("break EXECUTION;"); code.println("}"); } else { try { Object o = flowXml.unmarshal(elem); printAction(o, parent, exprContext); } catch (FlowCompilerException e) { code.println(exprContext + ".append(" + createExpression(elem) + ");"); } } } else if (action instanceof Text) { printAction(((Text) action).getTextContent(), parent, exprContext); } else if (action instanceof String) { String str = action.toString().trim(); if (str.length() > 0) { if (exprContext == null) { throw new FlowCompilerException("Text node not allowed: " + str, currentLineNumber); } else { code.println(exprContext + ".append(\"" + str.replaceAll("\\n", " ") + "\");"); } } } else { throw new FlowCompilerException("Could not parse " + action, currentLineNumber); } }
From source file:iristk.flow.FlowCompiler.java
private String newState(Element elem) { if (elem.getPrefix().equals("this")) { return "new " + elem.getLocalName() + "()"; }/*from w w w. jav a2s .com*/ for (Var var : flowXml.getVariables()) { if (var.getName().equals(elem.getPrefix())) return elem.getPrefix() + ".new " + elem.getLocalName() + "()"; } for (Param param : flowXml.getParameters()) { if (param.getName().equals(elem.getPrefix())) return elem.getPrefix() + ".new " + elem.getLocalName() + "()"; } return "new " + elem.getNamespaceURI() + "." + elem.getLocalName() + "()"; }
From source file:org.jdal.beans.TableBeanDefinitionParser.java
/** * {@inheritDoc}/*from w ww .j a v a 2 s . com*/ */ @SuppressWarnings("rawtypes") public BeanDefinition parse(Element element, ParserContext parserContext) { // Defaults String entity = null; if (element.hasAttribute(ENTITY)) entity = element.getAttribute(ENTITY); String name = StringUtils.uncapitalize(StringUtils.substringAfterLast(entity, ".")); if (element.hasAttribute(ID)) name = element.getAttribute(ID); parserContext.pushContainingComponent( new CompositeComponentDefinition(name, parserContext.extractSource(element))); // Bean names String tableModelBeanName = name + LIST_TABLE_MODEL_SUFFIX; String tablePanelBeanName = name + TABLE_PANEL_SUFFIX; String pageableTableBeanName = name + PAGEABLE_TABLE_SUFFIX; String dataSource = name + SERVICE_SUFFIX; String paginator = PAGINATOR_VIEW; String editor = name + EDITOR_SUFFIX; String actions = DefaultsBeanDefinitionParser.DEFAULT_TABLE_ACTIONS; String guiFactory = DefaultsBeanDefinitionParser.DEFAULT_GUI_FACTORY; String scope = BeanDefinition.SCOPE_PROTOTYPE; if (element.hasAttribute(SERVICE_ATTRIBUTE)) dataSource = element.getAttribute(SERVICE_ATTRIBUTE); if (element.hasAttribute(PAGINATOR)) paginator = element.getAttribute(PAGINATOR); if (element.hasAttribute(ACTIONS)) actions = element.getAttribute(ACTIONS); if (element.hasAttribute(GUI_FACTORY)) guiFactory = element.getAttribute(GUI_FACTORY); if (element.hasAttribute(EDITOR)) editor = element.getAttribute(EDITOR); if (element.hasAttribute(SCOPE)) scope = element.getAttribute(SCOPE); // create ListTableModel BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(ListTableModel.class); bdb.setScope(scope); bdb.addPropertyValue("modelClass", entity); NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), COLUMNS); if (nl.getLength() > 0) { List columns = parserContext.getDelegate().parseListElement((Element) nl.item(0), bdb.getRawBeanDefinition()); bdb.addPropertyValue(COLUMNS, columns); } registerBeanDefinition(element, parserContext, tableModelBeanName, bdb); // create PageableTable bdb = BeanDefinitionBuilder.genericBeanDefinition(PageableTable.class); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); bdb.addPropertyReference(DATA_SOURCE, dataSource); bdb.addPropertyReference(PAGINATOR_VIEW, paginator); bdb.addPropertyReference(TABLE_MODEL, tableModelBeanName); bdb.addPropertyValue(NAME, pageableTableBeanName); if (element.hasAttribute(TABLE_SERVICE)) bdb.addPropertyReference(Conventions.attributeNameToPropertyName(TABLE_SERVICE), element.getAttribute(TABLE_SERVICE)); if (element.hasAttribute(FILTER)) bdb.addPropertyReference(FILTER, element.getAttribute(FILTER)); if (element.hasAttribute(SHOW_MENU)) bdb.addPropertyValue(Conventions.attributeNameToPropertyName(SHOW_MENU), element.getAttribute(SHOW_MENU)); if (element.hasAttribute(MESSAGE_SOURCE)) bdb.addPropertyReference(MESSAGE_SOURCE, element.getAttribute(MESSAGE_SOURCE)); registerBeanDefinition(element, parserContext, pageableTableBeanName, bdb); // create TablePanel String tablePanelClassName = "org.jdal.swing.table.TablePanel"; if (element.hasAttribute(TABLE_PANEL_CLASS)) tablePanelClassName = element.getAttribute(TABLE_PANEL_CLASS); bdb = BeanDefinitionBuilder.genericBeanDefinition(tablePanelClassName); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); bdb.addPropertyReference(TABLE, pageableTableBeanName); bdb.addPropertyReference(GUI_FACTORY, guiFactory); bdb.addPropertyValue(EDITOR_NAME, editor); bdb.addPropertyReference(PERSISTENT_SERVICE, dataSource); if (element.hasAttribute(FILTER_VIEW)) bdb.addPropertyReference(Conventions.attributeNameToPropertyName(FILTER_VIEW), element.getAttribute(FILTER_VIEW)); if (!element.hasAttribute(USE_ACTIONS) || "true".equals(element.getAttribute(USE_ACTIONS))) bdb.addPropertyReference(ACTIONS, actions); registerBeanDefinition(element, parserContext, tablePanelBeanName, bdb); parserContext.popAndRegisterContainingComponent(); return null; }
From source file:eu.europa.esig.dss.xades.validation.XAdESSignature.java
/** * This method sets the namespace which will determinate the {@code XPathQueryHolder} to use. The content of the Transform element is ignored. * * @param element/*from ww w. ja va 2s .c o m*/ */ public void recursiveNamespaceBrowser(final Element element) { for (int ii = 0; ii < element.getChildNodes().getLength(); ii++) { final Node node = element.getChildNodes().item(ii); if (node.getNodeType() == Node.ELEMENT_NODE) { final Element childElement = (Element) node; final String namespaceURI = childElement.getNamespaceURI(); // final String tagName = childElement.getTagName(); final String localName = childElement.getLocalName(); // final String nodeName = childElement.getNodeName(); // System.out.println(tagName + "-->" + namespaceURI); if (XPathQueryHolder.XMLE_TRANSFORM.equals(localName) && javax.xml.crypto.dsig.XMLSignature.XMLNS.equals(namespaceURI)) { continue; } else if (XPathQueryHolder.XMLE_QUALIFYING_PROPERTIES.equals(localName)) { setXPathQueryHolder(namespaceURI); return; } recursiveNamespaceBrowser(childElement); } } }
From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java
private void addElement(SOAPMessage responseMessage, SOAPEnvelope soapEnvelope, Context context, Element elementToAdd, SOAPElement soapElement) throws SOAPException { SOAPElement soapMethodResponseElement = (SOAPElement) soapEnvelope.getBody().getFirstChild(); String targetNamespace = soapMethodResponseElement.getNamespaceURI(); String prefix = soapMethodResponseElement.getPrefix(); String nodeType = elementToAdd.getAttribute("type"); SOAPElement childSoapElement = soapElement; boolean elementAdded = true; boolean bTable = false; if (nodeType.equals("table")) { bTable = true;//from w w w.j a va 2 s . com /*childSoapElement = soapElement.addChildElement("ArrayOf" + context.transactionName + "_" + tableName + "_Row", ""); if (!context.httpServletRequest.getServletPath().endsWith(".wsl")) { childSoapElement.addAttribute(soapEnvelope.createName("xsi:type"), "soapenc:Array"); }*/ childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName()); } else if (nodeType.equals("row")) { /*String elementType = context.transactionName + "_" + tableName + "_Row"; childSoapElement = soapElement.addChildElement(elementType, "");*/ childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName()); } else if (nodeType.equals("attachment")) { childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName()); if (context.requestedObject instanceof AbstractHttpTransaction) { AttachmentDetails attachment = AttachmentManager.getAttachment(elementToAdd); if (attachment != null) { byte[] raw = attachment.getData(); if (raw != null) childSoapElement.addTextNode(Base64.encodeBase64String(raw)); } /* DON'T WORK YET *\ AttachmentPart ap = responseMessage.createAttachmentPart(new ByteArrayInputStream(raw), elementToAdd.getAttribute("content-type")); ap.setContentId(key); ap.setContentLocation(elementToAdd.getAttribute("url")); responseMessage.addAttachmentPart(ap); \* DON'T WORK YET */ } } else { String elementNodeName = elementToAdd.getNodeName(); String elementNodeNsUri = elementToAdd.getNamespaceURI(); String elementNodePrefix = getPrefix(context.projectName, elementNodeNsUri); XmlSchemaElement xmlSchemaElement = getXmlSchemaElementByName(context.projectName, elementNodeName); boolean isGlobal = xmlSchemaElement != null; if (isGlobal) { elementNodeNsUri = xmlSchemaElement.getQName().getNamespaceURI(); elementNodePrefix = getPrefix(context.projectName, elementNodeNsUri); } // ignore original SOAP message response elements // if ((elementNodeName.toUpperCase().indexOf("SOAP-ENV:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("SOAP-ENV:") != -1)) || // (elementNodeName.toUpperCase().indexOf("SOAPENV:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("SOAPENV:") != -1)) || // (elementNodeName.toUpperCase().indexOf("NS0:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1))) { // elementAdded = false; // } if ("http://schemas.xmlsoap.org/soap/envelope/".equals(elementToAdd.getNamespaceURI()) || "http://schemas.xmlsoap.org/soap/envelope/" .equals(elementToAdd.getParentNode().getNamespaceURI()) || elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1 || elementNodeName.toUpperCase().indexOf("NS0:") != -1) { elementAdded = false; } else { if (XsdForm.qualified == context.project.getSchemaElementForm() || isGlobal) { if (elementNodePrefix == null) { childSoapElement = soapElement .addChildElement(soapEnvelope.createName(elementNodeName, prefix, targetNamespace)); } else { childSoapElement = soapElement.addChildElement( soapEnvelope.createName(elementNodeName, elementNodePrefix, elementNodeNsUri)); } } else { childSoapElement = soapElement.addChildElement(elementNodeName); } } } if (elementAdded && elementToAdd.hasAttributes()) { addAttributes(responseMessage, soapEnvelope, context, elementToAdd.getAttributes(), childSoapElement); } if (elementToAdd.hasChildNodes()) { NodeList childNodes = elementToAdd.getChildNodes(); int len = childNodes.getLength(); if (bTable) { /*if (!context.httpServletRequest.getServletPath().endsWith(".wsl")) { childSoapElement.addAttribute(soapEnvelope.createName("soapenc:arrayType"), context.projectName+"_ns:" + context.transactionName + "_" + tableName + "_Row[" + (len - 1) + "]"); }*/ } org.w3c.dom.Node node; Element childElement; for (int i = 0; i < len; i++) { node = childNodes.item(i); switch (node.getNodeType()) { case org.w3c.dom.Node.ELEMENT_NODE: childElement = (Element) node; addElement(responseMessage, soapEnvelope, context, childElement, childSoapElement); break; case org.w3c.dom.Node.CDATA_SECTION_NODE: case org.w3c.dom.Node.TEXT_NODE: String text = node.getNodeValue(); text = (text == null) ? "" : text; childSoapElement.addTextNode(text); break; default: break; } } /*org.w3c.dom.Node node; Element childElement; for (int i = 0 ; i < len ; i++) { node = childNodes.item(i); if (node instanceof Element) { childElement = (Element) node; addElement(responseMessage, soapEnvelope, context, childElement, childSoapElement); } else if (node instanceof CDATASection) { Node textNode = XMLUtils.findChildNode(elementToAdd, org.w3c.dom.Node.CDATA_SECTION_NODE); String text = textNode.getNodeValue(); if (text == null) { text = ""; } childSoapElement.addTextNode(text); } else { Node textNode = XMLUtils.findChildNode(elementToAdd, org.w3c.dom.Node.TEXT_NODE); if (textNode != null) { String text = textNode.getNodeValue(); if (text == null) { text = ""; } childSoapElement.addTextNode(text); } } }*/ } }
From source file:org.jdal.vaadin.beans.TableBeanDefinitionParser.java
/** * {@inheritDoc}//from w ww.j ava 2 s .c om */ @SuppressWarnings("rawtypes") public BeanDefinition parse(Element element, ParserContext parserContext) { // Defaults String entity = null; if (element.hasAttribute(ENTITY)) entity = element.getAttribute(ENTITY); String name = StringUtils.uncapitalize(StringUtils.substringAfterLast(entity, ".")); if (element.hasAttribute(ID)) name = element.getAttribute(ID); parserContext.pushContainingComponent( new CompositeComponentDefinition(name, parserContext.extractSource(element))); // Bean names String pageableTableBeanName = name + PAGEABLE_TABLE_SUFFIX; String tableBeanName = name + TABLE_SUFFIX; String dataSource = name + SERVICE_SUFFIX; String paginator = PAGINATOR_VIEW; String editor = name + EDITOR_SUFFIX; String actions = DefaultsBeanDefinitionParser.DEFAULT_TABLE_ACTIONS; String guiFactory = DefaultsBeanDefinitionParser.DEFAULT_GUI_FACTORY; String scope = BeanDefinition.SCOPE_PROTOTYPE; String pageableTableClass = DEFAULT_PAGEABLE_TABLE_CLASS; String tableClass = DEFAULT_TABLE_CLASS; if (element.hasAttribute(DATA_SOURCE)) dataSource = element.getAttribute(DATA_SOURCE); if (element.hasAttribute(PAGINATOR)) paginator = element.getAttribute(PAGINATOR); if (element.hasAttribute(ACTIONS)) actions = element.getAttribute(ACTIONS); if (element.hasAttribute(GUI_FACTORY)) guiFactory = element.getAttribute(GUI_FACTORY); if (element.hasAttribute(EDITOR)) editor = element.getAttribute(EDITOR); if (element.hasAttribute(SCOPE)) scope = element.getAttribute(SCOPE); if (element.hasAttribute(PAGEABLE_TABLE_CLASS)) pageableTableClass = element.getAttribute(PAGEABLE_TABLE_CLASS); if (element.hasAttribute(TABLE_CLASS)) tableClass = element.getAttribute(TABLE_CLASS); // create PageableTable BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(pageableTableClass); bdb.setScope(scope); bdb.addPropertyReference(DATA_SOURCE, dataSource); bdb.addPropertyReference(PAGINATOR_VIEW, paginator); bdb.addPropertyValue(NAME, pageableTableBeanName); bdb.addPropertyReference(TABLE, tableBeanName); bdb.addPropertyReference(GUI_FACTORY, guiFactory); bdb.addPropertyValue(EDITOR_NAME, editor); bdb.addPropertyValue(ENTITY_CLASS, entity); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, TABLE_SERVICE); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FILTER); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, MESSAGE_SOURCE); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FILTER_FORM); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, SORT_PROPERTY); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, ORDER); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, PAGE_SIZE); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, NATIVE_BUTTONS); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, PROPAGATE_SERVICE); if (!element.hasAttribute(USE_ACTIONS) || "true".equals(element.getAttribute(USE_ACTIONS))) bdb.addPropertyReference(ACTIONS, actions); parserContext.getDelegate().parseBeanDefinitionAttributes(element, pageableTableBeanName, null, bdb.getBeanDefinition()); BeanDefinitionHolder holder = new BeanDefinitionHolder(bdb.getBeanDefinition(), pageableTableBeanName); // Test Decorators like aop:scoped-proxy NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node n = childNodes.item(i); if (Node.ELEMENT_NODE != n.getNodeType() || COLUMNS.equals(n.getLocalName())) continue; NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver() .resolve(n.getNamespaceURI()); if (handler != null) { holder = handler.decorate(n, holder, parserContext); } } parserContext.registerBeanComponent(new BeanComponentDefinition(holder)); // create ConfigurableTable bdb = BeanDefinitionBuilder.genericBeanDefinition(tableClass); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FIELD_FACTORY); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, MULTISELECT); if (element.hasAttribute(SELECTABLE)) { bdb.addPropertyValue(SELECTABLE, element.getAttribute(SELECTABLE)); } else { // set selectable by default bdb.addPropertyValue(SELECTABLE, true); } // parse columns NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), COLUMNS); if (nl.getLength() > 0) { List columns = parserContext.getDelegate().parseListElement((Element) nl.item(0), bdb.getRawBeanDefinition()); bdb.addPropertyValue(COLUMNS, columns); } registerBeanDefinition(element, parserContext, tableBeanName, bdb); parserContext.popAndRegisterContainingComponent(); return null; }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainReachAgent.java
/** * Parse a content.//from ww w .j a v a 2s .com * @param xml content's raw XML. * @param jid optional reply-to XMPP address. * @return content. * @throws Exception parsing problem, most likely invalid XML. */ private CapptainReachContent parseContent(String xml, String jid) throws Exception { /* Check root element, drop it if invalid XML or invalid namespace */ Element root = XmlUtil.parseContent(xml); String rootNS = root.getNamespaceURI(); if (!REACH_NAMESPACE.equals(rootNS)) throw new IllegalArgumentException("Unknown namespace: " + rootNS); /* If this is an announcement */ String rootTagName = root.getLocalName(); if ("announcement".equals(rootTagName)) /* Parse the announcement */ return new CapptainAnnouncement(jid, xml, root, mInjectedParams); /* If this is a poll */ else if ("poll".equals(rootTagName)) /* Parse the poll */ return new CapptainPoll(jid, xml, root); /* If this is a notification announcement */ else if ("notifAnnouncement".equals(rootTagName)) /* Parse the notification announcement */ return new CapptainNotifAnnouncement(jid, xml, root, mInjectedParams); /* If this is a data push */ else if ("datapush".equals(rootTagName)) /* Parse the datapush */ return new CapptainDataPush(jid, xml, root, mInjectedParams); /* XML/Namespace valid but content is not recognized */ throw new IllegalArgumentException("Unknown root tag: " + rootTagName); }
From source file:nl.b3p.ogc.utils.OgcWfsClient.java
/** Haal de elementen uit de describefeaturetype request *///from www . j a v a2 s. c om public static ArrayList getDescribeFeatureElements(Element el) throws Exception { //Haal eerst de complexTypes type elementen op en de prefix. String namespaceUri = el.getNamespaceURI(); NodeList childs = el.getChildNodes(); String prefix = ""; for (int i = 0; i < childs.getLength() && prefix.length() == 0; i++) { Node n = childs.item(i); if (n instanceof DeferredElementNSImpl) { Element e = (Element) n; if (e.getLocalName().equalsIgnoreCase("element")) { if (e.getAttribute("type") != null && e.getAttribute("type").contains(":")) { prefix = e.getAttribute("type").split(":")[0]; } } } } String featureNameSpace = null; if (prefix.length() > 0) { featureNameSpace = el.getAttribute("xmlns:" + prefix); } String s = elementToString(el); if (el == null) { return null; } NodeList nlist = el.getElementsByTagNameNS(namespaceUri, "complexType"); if (!(nlist.getLength() > 0)) { log.error("no complexType element found"); return null; } ArrayList returnValue = new ArrayList(); for (int i = 0; i < nlist.getLength(); i++) { Element e = (Element) nlist.item(i); NodeList nl = e.getElementsByTagNameNS(namespaceUri, "element"); for (int b = 0; b < nl.getLength(); b++) { Element element = (Element) nl.item(b); if (featureNameSpace != null && featureNameSpace.length() > 0) { element.setAttribute("name", "{" + featureNameSpace + "}" + element.getAttribute("name")); } returnValue.add(element); } } return returnValue; }
From source file:org.alfresco.repo.template.XSLTProcessor.java
/** * Adds the specified parameters to the xsl template as variables within the alfresco namespace. * //from w ww .j a v a2 s . c o m * @param xsltModel * the variables to place within the xsl template * @param xslTemplate * the xsl template */ protected void addParameters(final XSLTemplateModel xsltModel, final Document xslTemplate) { final Element docEl = xslTemplate.getDocumentElement(); final String XSL_NS = docEl.getNamespaceURI(); final String XSL_NS_PREFIX = docEl.getPrefix(); for (Map.Entry<QName, Object> e : xsltModel.entrySet()) { if (ROOT_NAMESPACE.equals(e.getKey())) { continue; } final Element el = xslTemplate.createElementNS(XSL_NS, XSL_NS_PREFIX + ":variable"); el.setAttribute("name", e.getKey().toPrefixString()); final Object o = e.getValue(); if (o instanceof String || o instanceof Number || o instanceof Boolean) { el.appendChild(xslTemplate.createTextNode(o.toString())); // ALF-15413. Add the variables at the end of the list of children docEl.insertBefore(el, null); } } }
From source file:org.alfresco.web.forms.xforms.Schema2XForms.java
@SuppressWarnings("unchecked") public static void rebuildInstance(final Node prototypeNode, final Node oldInstanceNode, final Node newInstanceNode, final HashMap<String, String> schemaNamespaces) { final JXPathContext prototypeContext = JXPathContext.newContext(prototypeNode); prototypeContext.registerNamespace(NamespaceService.ALFRESCO_PREFIX, NamespaceService.ALFRESCO_URI); final JXPathContext instanceContext = JXPathContext.newContext(oldInstanceNode); instanceContext.registerNamespace(NamespaceService.ALFRESCO_PREFIX, NamespaceService.ALFRESCO_URI); for (final String prefix : schemaNamespaces.keySet()) { prototypeContext.registerNamespace(prefix, schemaNamespaces.get(prefix)); instanceContext.registerNamespace(prefix, schemaNamespaces.get(prefix)); }/*from w w w . j av a2 s .c om*/ // Evaluate non-recursive XPaths for all prototype elements at this level final Iterator<Pointer> it = prototypeContext.iteratePointers("*"); while (it.hasNext()) { final Pointer p = it.next(); Element proto = (Element) p.getNode(); String path = p.asPath(); // check if this is a prototype element with the attribute set boolean isPrototype = proto.hasAttributeNS(NamespaceService.ALFRESCO_URI, "prototype") && proto.getAttributeNS(NamespaceService.ALFRESCO_URI, "prototype").equals("true"); // We shouldn't locate a repeatable child with a fixed path if (isPrototype) { path = path.replaceAll("\\[(\\d+)\\]", "[position() >= $1]"); if (LOGGER.isDebugEnabled()) { LOGGER.debug("[rebuildInstance] evaluating prototyped nodes " + path); } } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("[rebuildInstance] evaluating child node with positional path " + path); } } Document newInstanceDocument = newInstanceNode.getOwnerDocument(); // Locate the corresponding nodes in the instance document List<Node> l = (List<Node>) instanceContext.selectNodes(path); // If the prototype node isn't a prototype element, copy it in as a missing node, complete with all its children. We won't need to recurse on this node if (l.isEmpty()) { if (!isPrototype) { LOGGER.debug("[rebuildInstance] copying in missing node " + proto.getNodeName() + " to " + XMLUtil.buildXPath(newInstanceNode, newInstanceDocument.getDocumentElement())); // Clone the prototype node and all its children Element clone = (Element) proto.cloneNode(true); newInstanceNode.appendChild(clone); if (oldInstanceNode instanceof Document) { // add XMLSchema instance NS addNamespace(clone, NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX, NamespaceConstants.XMLSCHEMA_INSTANCE_NS); } } } else { // Otherwise, append the matches from the old instance document in order for (Node old : l) { Element oldEl = (Element) old; // Copy the old instance element rather than cloning it, so we don't copy over attributes Element clone = null; String nSUri = oldEl.getNamespaceURI(); if (nSUri == null) { clone = newInstanceDocument.createElement(oldEl.getTagName()); } else { clone = newInstanceDocument.createElementNS(nSUri, oldEl.getTagName()); } newInstanceNode.appendChild(clone); if (oldInstanceNode instanceof Document) { // add XMLSchema instance NS addNamespace(clone, NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX, NamespaceConstants.XMLSCHEMA_INSTANCE_NS); } // Copy over child text if this is not a complex type boolean isEmpty = true; for (Node n = old.getFirstChild(); n != null; n = n.getNextSibling()) { if (n instanceof Text) { clone.appendChild(newInstanceDocument.importNode(n, false)); isEmpty = false; } else if (n instanceof Element) { break; } } // Populate the nil attribute. It may be true or false if (proto.hasAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS, "nil")) { clone.setAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS, NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX + ":nil", String.valueOf(isEmpty)); } // Copy over attributes present in the prototype NamedNodeMap attributes = proto.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attribute = (Attr) attributes.item(i); String localName = attribute.getLocalName(); if (localName == null) { String name = attribute.getName(); if (oldEl.hasAttribute(name)) { clone.setAttributeNode( (Attr) newInstanceDocument.importNode(oldEl.getAttributeNode(name), false)); } else { LOGGER.debug("[rebuildInstance] copying in missing attribute " + attribute.getNodeName() + " to " + XMLUtil.buildXPath(clone, newInstanceDocument.getDocumentElement())); clone.setAttributeNode((Attr) attribute.cloneNode(false)); } } else { String namespace = attribute.getNamespaceURI(); if (!((!isEmpty && (namespace.equals(NamespaceConstants.XMLSCHEMA_INSTANCE_NS) && localName.equals("nil")) || (namespace.equals(NamespaceService.ALFRESCO_URI) && localName.equals("prototype"))))) { if (oldEl.hasAttributeNS(namespace, localName)) { clone.setAttributeNodeNS((Attr) newInstanceDocument .importNode(oldEl.getAttributeNodeNS(namespace, localName), false)); } else { LOGGER.debug("[rebuildInstance] copying in missing attribute " + attribute.getNodeName() + " to " + XMLUtil.buildXPath(clone, newInstanceDocument.getDocumentElement())); clone.setAttributeNodeNS((Attr) attribute.cloneNode(false)); } } } } // recurse on children rebuildInstance(proto, oldEl, clone, schemaNamespaces); } } // Now add in a new copy of the prototype if (isPrototype) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("[rebuildInstance] appending " + proto.getNodeName() + " to " + XMLUtil.buildXPath(newInstanceNode, newInstanceDocument.getDocumentElement())); } newInstanceNode.appendChild(proto.cloneNode(true)); } } }