List of usage examples for org.w3c.dom Element getAttributes
public NamedNodeMap getAttributes();
NamedNodeMap
containing the attributes of this node (if it is an Element
) or null
otherwise. From source file:net.ymate.platform.commons.support.XMLConfigFileHandler.java
public XMLConfigFileHandler load(boolean sorted) { if (!__loaded) { __sorted = sorted;/*from www.j av a 2s . co m*/ // ???? if (sorted) { __categories = new LinkedHashMap<String, XMLCategory>(); __rootAttributes = new LinkedHashMap<String, XMLAttribute>(); } else { __categories = new HashMap<String, XMLCategory>(); __rootAttributes = new HashMap<String, XMLAttribute>(); } // if (!__rootElement.getNodeName().equals(TAG_NAME_ROOT)) { throw new RuntimeException("Configuration root element not valid."); } // NamedNodeMap __rootAttrNodes = __rootElement.getAttributes(); if (__rootAttrNodes != null && __rootAttrNodes.getLength() > 0) { // ???root for (int _attrIdx = 0; _attrIdx < __rootAttrNodes.getLength(); _attrIdx++) { String _attrKey = __rootAttrNodes.item(_attrIdx).getNodeName(); String _attrValue = __rootAttrNodes.item(_attrIdx).getNodeValue(); if (StringUtils.isNotBlank(_attrKey) && StringUtils.isNotBlank(_attrValue)) { __rootAttributes.put(_attrKey, new XMLAttribute(_attrKey, _attrValue)); } } } // NodeList _nodes = __rootElement.getElementsByTagName(TAG_NAME_CATEGORY); if (_nodes.getLength() > 0) { for (int _idx = 0; _idx < _nodes.getLength(); _idx++) { Element _categoryElement = (Element) _nodes.item(_idx); // ?category String _categoryNameAttr = null; List<XMLAttribute> _categoryAttrs = new ArrayList<XMLAttribute>(); NamedNodeMap _categoryAttrNodes = _categoryElement.getAttributes(); if (_categoryAttrNodes != null && _categoryAttrNodes.getLength() > 0) { // ???category for (int _attrIdx = 0; _attrIdx < _categoryAttrNodes.getLength(); _attrIdx++) { String _attrKey = _categoryAttrNodes.item(_attrIdx).getNodeName(); String _attrValue = _categoryAttrNodes.item(_attrIdx).getNodeValue(); if (StringUtils.isNotBlank(_attrKey) && StringUtils.isNotBlank(_attrValue)) { if (_attrKey.equals("name")) { _categoryNameAttr = _attrValue; } else { _categoryAttrs.add(new XMLAttribute(_attrKey, _attrValue)); } } } } if (_categoryNameAttr != null) { // ??categoryproperty List<XMLProperty> _properties = new ArrayList<XMLProperty>(); // NodeList _propertyNodes = _categoryElement.getElementsByTagName(TAG_NAME_PROPERTY); if (_propertyNodes.getLength() > 0) { for (int _idy = 0; _idy < _propertyNodes.getLength(); _idy++) { Element _node = (Element) _propertyNodes.item(_idy); NamedNodeMap _attrNodes = _node.getAttributes(); List<XMLAttribute> _attrs = new ArrayList<XMLAttribute>(); String _propertyNameValue = null; String _propertyContent = _node.getTextContent(); if (_attrNodes != null && _attrNodes.getLength() > 0) { // ???property for (int _attrIdx = 0; _attrIdx < _attrNodes.getLength(); _attrIdx++) { String _attrKey = _attrNodes.item(_attrIdx).getNodeName(); String _attrValue = _attrNodes.item(_attrIdx).getNodeValue(); if (StringUtils.isNotBlank(_attrKey) && StringUtils.isNotBlank(_attrValue)) { if (_attrKey.equals("name")) { _propertyNameValue = _attrValue; } else if (_attrKey.equals("value")) { _propertyContent = _attrValue; } else { _attrs.add(new XMLAttribute(_attrKey, _attrValue)); } } } // ?name???? if (_propertyNameValue != null && StringUtils.isNotBlank(_propertyContent)) { _properties .add(new XMLProperty(_propertyNameValue, _propertyContent, _attrs)); } } } } // __categories.put(_categoryNameAttr, new XMLCategory(_categoryNameAttr, _categoryAttrs, _properties, sorted)); } } } // ??DEFAULT_CATEGORY_NAME?? if (!__categories.containsKey(DEFAULT_CATEGORY_NAME)) { __categories.put(DEFAULT_CATEGORY_NAME, new XMLCategory(DEFAULT_CATEGORY_NAME, null, null, sorted)); } // this.__loaded = true; } return this; }
From source file:net.ymate.platform.configuration.support.XMLConfigFileHandler.java
protected PairObject<String, String> __doParseNodeAttributes(List<XMLAttribute> attributes, Element node, boolean collections, boolean textContent) { String _propertyName = null;/*from w w w. j a v a 2 s. c om*/ String _propertyContent = null; // NamedNodeMap _attrNodes = node.getAttributes(); if (_attrNodes != null && _attrNodes.getLength() > 0) { for (int _idy = 0; _idy < _attrNodes.getLength(); _idy++) { String _attrKey = _attrNodes.item(_idy).getNodeName(); String _attrValue = _attrNodes.item(_idy).getNodeValue(); if (collections) { if (_attrKey.equals("name")) { attributes.add(new XMLAttribute(_attrValue, node.getTextContent())); } } else { if (textContent && StringUtils.isNotBlank(_attrValue)) { _attrValue = node.getTextContent(); } if (_attrKey.equals("name")) { _propertyName = _attrValue; } else if (_attrKey.equals("value")) { _propertyContent = _attrValue; } else { attributes.add(new XMLAttribute(_attrKey, _attrValue)); } } } } if (!collections && StringUtils.isNotBlank(_propertyName)) { return new PairObject<String, String>(_propertyName, _propertyContent); } return null; }
From source file:nl.strohalm.cyclos.utils.conversion.HtmlConverter.java
private static void removeBadNodes(final Document document) { final NodeList elements = document.getElementsByTagName("*"); for (int i = 0; i < elements.getLength(); i++) { final Element element = (Element) elements.item(i); if (ArrayUtils.contains(BAD_TAGS, element.getTagName())) { element.getParentNode().removeChild(element); }//from w w w . ja va2 s. c o m final NamedNodeMap attributes = element.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { final Attr attr = (Attr) attributes.item(j); if (attr.getNodeName().startsWith("on")) { // This is an event handler: remove it element.removeAttributeNode(attr); } } } }
From source file:openblocks.yacodeblocks.BlockSaveFileTest.java
private void assertElementContainsOnlyAsciiCharacters(Element element) throws Exception { assertStringContainsOnlyAsciiCharacters(element.getNodeName(), "name", element); if (element.hasAttributes()) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { assertNodeContainsOnlyAsciiCharacters(attributes.item(i)); }/*from ww w .j a v a2s . co m*/ } if (element.hasChildNodes()) { NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { assertNodeContainsOnlyAsciiCharacters(childNodes.item(i)); } } }
From source file:org.alfresco.repo.rendition.StandardRenditionLocationResolverImpl.java
public static String buildNamespaceDeclaration(final Document xml) { final Element docEl = xml.getDocumentElement(); final NamedNodeMap attributes = docEl.getAttributes(); final StringBuilder result = new StringBuilder(); for (int i = 0; i < attributes.getLength(); i++) { final Node a = attributes.item(i); if (a.getNodeName().startsWith(XMLConstants.XMLNS_ATTRIBUTE)) { final String prefix = a.getNodeName().substring((XMLConstants.XMLNS_ATTRIBUTE + ":").length()); final String uri = a.getNodeValue(); if (result.length() != 0) { result.append(",\n"); }//from ww w . jav a2 s . c om result.append("\"").append(prefix).append("\":\"").append(uri).append("\""); } } return "<#ftl ns_prefixes={\n" + result.toString() + "}>\n"; }
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 . ja v a 2 s.co m*/ // 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)); } } }
From source file:org.apache.axis.encoding.SerializationContext.java
/** * Output a DOM representation to a SerializationContext * @param el is a DOM Element//from www . j a v a2s . co m */ public void writeDOMElement(Element el) throws IOException { if (startOfDocument && sendXMLDecl) { writeXMLDeclaration(); } // If el is a Text element, write the text and exit if (el instanceof org.apache.axis.message.Text) { writeSafeString(((Text) el).getData()); return; } AttributesImpl attributes = null; NamedNodeMap attrMap = el.getAttributes(); if (attrMap.getLength() > 0) { attributes = new AttributesImpl(); for (int i = 0; i < attrMap.getLength(); i++) { Attr attr = (Attr) attrMap.item(i); String tmp = attr.getNamespaceURI(); if (tmp != null && tmp.equals(Constants.NS_URI_XMLNS)) { String prefix = attr.getLocalName(); if (prefix != null) { if (prefix.equals("xmlns")) prefix = ""; String nsURI = attr.getValue(); registerPrefixForURI(prefix, nsURI); } continue; } attributes.addAttribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getName(), "CDATA", attr.getValue()); } } String namespaceURI = el.getNamespaceURI(); String localPart = el.getLocalName(); if (namespaceURI == null || namespaceURI.length() == 0) localPart = el.getNodeName(); QName qName = new QName(namespaceURI, localPart); startElement(qName, attributes); NodeList children = el.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { writeDOMElement((Element) child); } else if (child instanceof CDATASection) { writeString("<![CDATA["); writeString(((Text) child).getData()); writeString("]]>"); } else if (child instanceof Comment) { writeString("<!--"); writeString(((CharacterData) child).getData()); writeString("-->"); } else if (child instanceof Text) { writeSafeString(((Text) child).getData()); } } endElement(); }
From source file:org.apache.axis.encoding.SerializationContextImpl.java
/** * Output a DOM representation to a SerializationContext * @param el is a DOM Element//from w ww . j a v a 2s . c o m */ public void writeDOMElement(Element el) throws IOException { AttributesImpl attributes = null; NamedNodeMap attrMap = el.getAttributes(); if (attrMap.getLength() > 0) { attributes = new AttributesImpl(); for (int i = 0; i < attrMap.getLength(); i++) { Attr attr = (Attr)attrMap.item(i); String tmp = attr.getNamespaceURI(); if ( tmp != null && tmp.equals(Constants.NS_URI_XMLNS) ) { String prefix = attr.getLocalName(); if (prefix != null) { if (prefix.equals("xmlns")) prefix = ""; String nsURI = attr.getValue(); registerPrefixForURI(prefix, nsURI); } continue; } attributes.addAttribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getName(), "CDATA", attr.getValue()); } } String namespaceURI = el.getNamespaceURI(); String localPart = el.getLocalName(); if(namespaceURI == null || namespaceURI.length()==0) localPart = el.getNodeName(); QName qName = new QName(namespaceURI, localPart); startElement(qName, attributes); NodeList children = el.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { writeDOMElement((Element)child); } else if (child instanceof CDATASection) { writeString("<![CDATA["); writeString(((Text)child).getData()); writeString("]]>"); } else if (child instanceof Comment) { writeString("<!--"); writeString(((CharacterData)child).getData()); writeString("-->"); } else if (child instanceof Text) { writeSafeString(((Text)child).getData()); } } endElement(); }
From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java
/** * Get the Extensible elements form wsdl4jExtensibleElements * <code>Vector</code> if any and copy them to <code>Component</code> * <p/> Note - SOAP body extensible element will be processed differently * * @param wsdl4jExtensibleElements/*from www .j a va 2s . co m*/ * @param description where is the ext element (port , portype , biding) * @param wsdl4jDefinition * @param originOfExtensibilityElements - * this will indicate the place this extensibility element came * from. */ private void copyExtensibleElements(List wsdl4jExtensibleElements, Definition wsdl4jDefinition, AxisDescription description, String originOfExtensibilityElements) throws AxisFault { ExtensibilityElement wsdl4jExtensibilityElement; for (Iterator iterator = wsdl4jExtensibleElements.iterator(); iterator.hasNext();) { wsdl4jExtensibilityElement = (ExtensibilityElement) iterator.next(); if (wsdl4jExtensibilityElement instanceof UnknownExtensibilityElement) { UnknownExtensibilityElement unknown = (UnknownExtensibilityElement) (wsdl4jExtensibilityElement); QName type = unknown.getElementType(); // <wsp:Policy> if (WSDLConstants.WSDL11Constants.POLICY.equals(type)) { if (isTraceEnabled) { log.trace("copyExtensibleElements:: PolicyElement found " + unknown); } Policy policy = (Policy) PolicyUtil.getPolicyComponent(unknown.getElement()); description.getPolicySubject().attachPolicy(policy); // int attachmentScope = // getPolicyAttachmentPoint(description, originOfExtensibilityElements); // if (attachmentScope > -1) { // description.getPolicyInclude().addPolicyElement( // attachmentScope, policy); // } // <wsp:PolicyReference> } else if (WSDLConstants.WSDL11Constants.POLICY_REFERENCE.equals(type)) { if (isTraceEnabled) { log.trace("copyExtensibleElements:: PolicyReference found " + unknown); } PolicyReference policyReference = (PolicyReference) PolicyUtil .getPolicyComponent(unknown.getElement()); description.getPolicySubject().attachPolicyReference(policyReference); // int attachmentScope = // getPolicyAttachmentPoint(description, originOfExtensibilityElements); // if (attachmentScope > -1) { // description.getPolicyInclude().addPolicyRefElement( // attachmentScope, policyReference); // } } else if (AddressingConstants.Final.WSAW_USING_ADDRESSING.equals(type) || AddressingConstants.Submission.WSAW_USING_ADDRESSING.equals(unknown.getElementType())) { if (isTraceEnabled) { log.trace("copyExtensibleElements:: wsaw:UsingAddressing found " + unknown); } // FIXME We need to set this the appropriate Axis Description AxisEndpoint or // AxisBinding . if (originOfExtensibilityElements.equals(PORT) || originOfExtensibilityElements.equals(BINDING)) { if (Boolean.TRUE.equals(unknown.getRequired())) { AddressingHelper.setAddressingRequirementParemeterValue(axisService, AddressingConstants.ADDRESSING_REQUIRED); } else { AddressingHelper.setAddressingRequirementParemeterValue(axisService, AddressingConstants.ADDRESSING_OPTIONAL); } } } else if (wsdl4jExtensibilityElement.getElementType() != null && wsdl4jExtensibilityElement.getElementType().getNamespaceURI() .equals(org.apache.axis2.namespace.Constants.FORMAT_BINDING)) { Element typeMapping = unknown.getElement(); NodeList typeMaps = typeMapping .getElementsByTagNameNS(org.apache.axis2.namespace.Constants.FORMAT_BINDING, "typeMap"); int count = typeMaps.getLength(); HashMap typeMapper = new HashMap(); for (int index = 0; index < count; index++) { Node node = typeMaps.item(index); NamedNodeMap attributes = node.getAttributes(); Node typeName = attributes.getNamedItem("typeName"); if (typeName != null) { String prefix = getPrefix(typeName.getNodeValue()); if (prefix != null) { String ns = (String) wsdl4jDefinition.getNamespaces().get(prefix); if (ns != null) { Node formatType = attributes.getNamedItem("formatType"); typeMapper.put(new QName(ns, getTypeName(typeName.getNodeValue())), formatType.getNodeValue()); } } } } } else if (wsdl4jExtensibilityElement.getElementType() != null && wsdl4jExtensibilityElement .getElementType().getNamespaceURI().equals(org.apache.axis2.namespace.Constants.JAVA_NS)) { Element unknowJavaElement = unknown.getElement(); if (unknowJavaElement.getLocalName().equals("address")) { NamedNodeMap nameAttributes = unknowJavaElement.getAttributes(); Node node = nameAttributes.getNamedItem("className"); Parameter serviceClass = new Parameter(); serviceClass.setName("className"); serviceClass.setValue(node.getNodeValue()); axisService.addParameter(serviceClass); Parameter transportName = new Parameter(); transportName.setName("TRANSPORT_NAME"); transportName.setValue("java"); axisService.addParameter(transportName); } } else { // Ignore this element - it is a totally unknown element if (isTraceEnabled) { log.trace("copyExtensibleElements:: Unknown Extensibility Element found " + unknown); } } } else if (wsdl4jExtensibilityElement instanceof SOAP12Address) { SOAP12Address soapAddress = (SOAP12Address) wsdl4jExtensibilityElement; if (description instanceof AxisEndpoint) { setEndpointURL((AxisEndpoint) description, soapAddress.getLocationURI()); } } else if (wsdl4jExtensibilityElement instanceof SOAPAddress) { SOAPAddress soapAddress = (SOAPAddress) wsdl4jExtensibilityElement; if (description instanceof AxisEndpoint) { setEndpointURL((AxisEndpoint) description, soapAddress.getLocationURI()); } } else if (wsdl4jExtensibilityElement instanceof HTTPAddress) { HTTPAddress httpAddress = (HTTPAddress) wsdl4jExtensibilityElement; if (description instanceof AxisEndpoint) { setEndpointURL((AxisEndpoint) description, httpAddress.getLocationURI()); } } else if (wsdl4jExtensibilityElement instanceof Schema) { Schema schema = (Schema) wsdl4jExtensibilityElement; // just add this schema - no need to worry about the imported // ones axisService.addSchema(getXMLSchema(schema.getElement(), schema.getDocumentBaseURI())); } else if (wsdl4jExtensibilityElement instanceof SOAP12Operation) { SOAP12Operation soapOperation = (SOAP12Operation) wsdl4jExtensibilityElement; AxisBindingOperation axisBindingOperation = (AxisBindingOperation) description; String style = soapOperation.getStyle(); if (style != null) { axisBindingOperation.setProperty(WSDLConstants.WSDL_1_1_STYLE, style); } String soapActionURI = soapOperation.getSoapActionURI(); if (this.isCodegen && ((soapActionURI == null) || (soapActionURI.equals("")))) { soapActionURI = axisBindingOperation.getAxisOperation().getInputAction(); } if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) log.debug("WSDL Binding Operation: " + axisBindingOperation.getName() + ", SOAPAction: " + soapActionURI); if (soapActionURI != null && !soapActionURI.equals("")) { axisBindingOperation.setProperty(WSDL2Constants.ATTR_WSOAP_ACTION, soapActionURI); axisBindingOperation.getAxisOperation().setSoapAction(soapActionURI); if (!isServerSide) { axisBindingOperation.getAxisOperation().setOutputAction(soapActionURI); } axisService.mapActionToOperation(soapActionURI, axisBindingOperation.getAxisOperation()); } } else if (wsdl4jExtensibilityElement instanceof SOAPOperation) { SOAPOperation soapOperation = (SOAPOperation) wsdl4jExtensibilityElement; AxisBindingOperation axisBindingOperation = (AxisBindingOperation) description; String style = soapOperation.getStyle(); if (style != null) { axisBindingOperation.setProperty(WSDLConstants.WSDL_1_1_STYLE, style); } String soapAction = soapOperation.getSoapActionURI(); if (this.isCodegen && ((soapAction == null) || (soapAction.equals("")))) { soapAction = axisBindingOperation.getAxisOperation().getInputAction(); } if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) log.debug("WSDL Binding Operation: " + axisBindingOperation.getName() + ", SOAPAction: " + soapAction); if (soapAction != null) { axisBindingOperation.setProperty(WSDL2Constants.ATTR_WSOAP_ACTION, soapAction); axisBindingOperation.getAxisOperation().setSoapAction(soapAction); if (!isServerSide) { axisBindingOperation.getAxisOperation().setOutputAction(soapAction); } axisService.mapActionToOperation(soapAction, axisBindingOperation.getAxisOperation()); } } else if (wsdl4jExtensibilityElement instanceof HTTPOperation) { HTTPOperation httpOperation = (HTTPOperation) wsdl4jExtensibilityElement; AxisBindingOperation axisBindingOperation = (AxisBindingOperation) description; String httpLocation = httpOperation.getLocationURI(); if (httpLocation != null) { // change the template to make it same as WSDL 2 template httpLocation = httpLocation.replaceAll("\\(", "{"); httpLocation = httpLocation.replaceAll("\\)", "}"); axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, httpLocation); } axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_INPUT_SERIALIZATION, HTTPConstants.MEDIA_TYPE_TEXT_XML); } else if (wsdl4jExtensibilityElement instanceof SOAP12Header) { SOAP12Header soapHeader = (SOAP12Header) wsdl4jExtensibilityElement; SOAPHeaderMessage headerMessage = new SOAPHeaderMessage(); headerMessage.setNamespaceURI(soapHeader.getNamespaceURI()); headerMessage.setUse(soapHeader.getUse()); Boolean required = soapHeader.getRequired(); if (required != null) { headerMessage.setRequired(required.booleanValue()); } if (wsdl4jDefinition != null) { // find the relevant schema part from the messages Message msg = wsdl4jDefinition.getMessage(soapHeader.getMessage()); if (msg == null) { msg = getMessage(wsdl4jDefinition, soapHeader.getMessage(), new HashSet()); } if (msg == null) { // TODO i18n this throw new AxisFault("message " + soapHeader.getMessage() + " not found in the WSDL "); } Part msgPart = msg.getPart(soapHeader.getPart()); if (msgPart == null) { // TODO i18n this throw new AxisFault("message part " + soapHeader.getPart() + " not found in the WSDL "); } // see basic profile 4.4.2 Bindings and Faults header, fault and headerfaults // can only have elements headerMessage.setElement(msgPart.getElementName()); } headerMessage.setMessage(soapHeader.getMessage()); headerMessage.setPart(soapHeader.getPart()); if (description instanceof AxisBindingMessage) { AxisBindingMessage bindingMessage = (AxisBindingMessage) description; List soapHeaders = (List) bindingMessage.getProperty(WSDL2Constants.ATTR_WSOAP_HEADER); if (soapHeaders == null) { soapHeaders = new ArrayList(); bindingMessage.setProperty(WSDL2Constants.ATTR_WSOAP_HEADER, soapHeaders); } soapHeaders.add(headerMessage); } } else if (wsdl4jExtensibilityElement instanceof SOAPHeader) { SOAPHeader soapHeader = (SOAPHeader) wsdl4jExtensibilityElement; SOAPHeaderMessage headerMessage = new SOAPHeaderMessage(); headerMessage.setNamespaceURI(soapHeader.getNamespaceURI()); headerMessage.setUse(soapHeader.getUse()); Boolean required = soapHeader.getRequired(); if (null != required) { headerMessage.setRequired(required.booleanValue()); } if (null != wsdl4jDefinition) { // find the relevant schema part from the messages Message msg = wsdl4jDefinition.getMessage(soapHeader.getMessage()); if (msg == null) { msg = getMessage(wsdl4jDefinition, soapHeader.getMessage(), new HashSet()); } if (msg == null) { // todo i18n this throw new AxisFault("message " + soapHeader.getMessage() + " not found in the WSDL "); } Part msgPart = msg.getPart(soapHeader.getPart()); if (msgPart == null) { // todo i18n this throw new AxisFault("message part " + soapHeader.getPart() + " not found in the WSDL "); } headerMessage.setElement(msgPart.getElementName()); } headerMessage.setMessage(soapHeader.getMessage()); headerMessage.setPart(soapHeader.getPart()); if (description instanceof AxisBindingMessage) { AxisBindingMessage bindingMessage = (AxisBindingMessage) description; List soapHeaders = (List) bindingMessage.getProperty(WSDL2Constants.ATTR_WSOAP_HEADER); if (soapHeaders == null) { soapHeaders = new ArrayList(); bindingMessage.setProperty(WSDL2Constants.ATTR_WSOAP_HEADER, soapHeaders); } soapHeaders.add(headerMessage); } } else if (wsdl4jExtensibilityElement instanceof SOAPBinding) { SOAPBinding soapBinding = (SOAPBinding) wsdl4jExtensibilityElement; AxisBinding axisBinding = (AxisBinding) description; axisBinding.setType(soapBinding.getTransportURI()); axisBinding.setProperty(WSDL2Constants.ATTR_WSOAP_VERSION, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI); String style = soapBinding.getStyle(); if (style != null) { axisBinding.setProperty(WSDLConstants.WSDL_1_1_STYLE, style); } } else if (wsdl4jExtensibilityElement instanceof SOAP12Binding) { SOAP12Binding soapBinding = (SOAP12Binding) wsdl4jExtensibilityElement; AxisBinding axisBinding = (AxisBinding) description; axisBinding.setProperty(WSDL2Constants.ATTR_WSOAP_VERSION, SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI); String style = soapBinding.getStyle(); if (style != null) { axisBinding.setProperty(WSDLConstants.WSDL_1_1_STYLE, style); } String transportURI = soapBinding.getTransportURI(); axisBinding.setType(transportURI); } else if (wsdl4jExtensibilityElement instanceof HTTPBinding) { HTTPBinding httpBinding = (HTTPBinding) wsdl4jExtensibilityElement; AxisBinding axisBinding = (AxisBinding) description; // set the binding style same as the wsd2 to process smoothly axisBinding.setType(WSDL2Constants.URI_WSDL2_HTTP); axisBinding.setProperty(WSDL2Constants.ATTR_WHTTP_METHOD, httpBinding.getVerb()); } else if (wsdl4jExtensibilityElement instanceof MIMEContent) { if (description instanceof AxisBindingMessage) { MIMEContent mimeContent = (MIMEContent) wsdl4jExtensibilityElement; String messageSerialization = mimeContent.getType(); AxisBindingMessage bindingMessage = (AxisBindingMessage) description; setMessageSerialization((AxisBindingOperation) bindingMessage.getParent(), originOfExtensibilityElements, messageSerialization); } } else if (wsdl4jExtensibilityElement instanceof MIMEMimeXml) { if (description instanceof AxisBindingMessage) { AxisBindingMessage bindingMessage = (AxisBindingMessage) description; setMessageSerialization((AxisBindingOperation) bindingMessage.getParent(), originOfExtensibilityElements, HTTPConstants.MEDIA_TYPE_TEXT_XML); } } else if (wsdl4jExtensibilityElement instanceof HTTPUrlEncoded) { if (description instanceof AxisBindingMessage) { AxisBindingMessage bindingMessage = (AxisBindingMessage) description; setMessageSerialization((AxisBindingOperation) bindingMessage.getParent(), originOfExtensibilityElements, HTTPConstants.MEDIA_TYPE_X_WWW_FORM); } } } }
From source file:org.apache.axis2.jaxws.message.util.impl.XMLStreamReaderFromDOM.java
public List getNamespaceDeclarations() { Element element = null; if (cursor instanceof Element) { element = (Element) cursor; } else {//w w w .ja va 2 s .c o m return new ArrayList(); } if (element == cacheNDKey) { return cacheND; } cacheNDKey = element; cacheND = new ArrayList(); NamedNodeMap attrs = element.getAttributes(); if (attrs != null) { for (int i = 0; i < attrs.getLength(); i++) { Attr attr = (Attr) attrs.item(i); String name = attr.getNodeName(); if (name.startsWith("xmlns")) { String prefix = ""; if (name.startsWith("xmlns:")) { prefix = name.substring(6); } NamespaceDeclare nd = new NamespaceDeclare(prefix, attr.getNodeValue()); cacheND.add(nd); } } } return cacheND; }