List of usage examples for org.w3c.dom Element hasAttribute
public boolean hasAttribute(String name);
true
when an attribute with a given name is specified on this element or has a default value, false
otherwise. From source file:org.wso2.developerstudio.eclipse.esb.mediators.impl.CalloutMediatorImpl.java
/** * {@inheritDoc}/*w w w. java 2 s.c o m*/ */ protected void doLoad(Element self) throws Exception { // Service URL. if (self.hasAttribute("serviceURL")) { setServiceURL(self.getAttribute("serviceURL")); setEndpointType(CallOutMediatorEndpointType.ANONYMOUS); } else if (self.hasAttribute("endpointKey")) { setEndpointType(CallOutMediatorEndpointType.REGISTRY_REFERENCE); RegistryKeyProperty endPointKey = getEsbFactory().createRegistryKeyProperty(); endPointKey.setKeyValue(self.getAttribute("endpointKey")); endPointKey.setPrettyName("Endpoint Key"); endPointKey.setKeyName("endpointKey"); setEndpointKey(endPointKey); } else { throw new Exception("Expected service url."); } // Soap action. setSoapAction(self.getAttribute("action")); // Configuration. Element configElem = getChildElement(self, "configuration"); if (null != configElem) { setPathToAxis2xml(configElem.getAttribute("axis2xml")); setPathToAxis2Repository(configElem.getAttribute("repository")); } // Pass Headers if (self.hasAttribute("passHeaders")) { setPassHeaders(self.getAttribute("passHeaders").equals("true") ? true : false); } else { setPassHeaders(false); } // Use Server Config if (self.hasAttribute("useServerConfig")) { setUseServerConfig(self.getAttribute("useServerConfig").equals("true") ? true : false); } else { setUseServerConfig(false); } // Payload. Element sourceElem = getChildElement(self, "source"); if (null != sourceElem) { if (sourceElem.hasAttribute("xpath")) { setPayloadType(CalloutPayloadType.MESSAGE_ELEMENT); getPayloadMessageXpath().load(sourceElem); } else if (sourceElem.hasAttribute("key")) { setPayloadType(CalloutPayloadType.REGISTRY_ENTRY); getPayloadRegistryKey().load(sourceElem); } else { throw new Exception("Expected either payload xpath or payload registry key."); } } else { throw new Exception("Expected payload configuration."); } // Result. Element targetElem = getChildElement(self, "target"); if (null != targetElem) { if (targetElem.hasAttribute("xpath")) { setResultType(CalloutResultType.MESSAGE_ELEMENT); getResultMessageXpath().load(targetElem); } else if (targetElem.hasAttribute("key")) { setResultType(CalloutResultType.CONTEXT_PROPERTY); setResultContextProperty(targetElem.getAttribute("key")); } else { throw new Exception("Expected result xpath or result context property name."); } } else { throw new Exception("Expected result configuration."); } super.doLoad(self); }
From source file:org.wso2.developerstudio.eclipse.esb.mediators.impl.CloneTargetImpl.java
/** * {@inheritDoc}/* www . ja v a2 s.com*/ */ protected void doLoad(Element self) throws Exception { // Soap action. if (self.hasAttribute("soapAction")) { setSoapAction(self.getAttribute("soapAction")); } // To address. if (self.hasAttribute("to")) { setToAddress(self.getAttribute("to")); } // Delegate. super.doLoad(self); }
From source file:org.wso2.developerstudio.eclipse.esb.mediators.impl.HeaderMediatorImpl.java
/** * {@inheritDoc}/*from ww w .j av a 2 s.c o m*/ */ protected void doLoad(Element self) throws Exception { String headerNamePrefix = null; if (self.hasAttribute("name")) { getHeaderName().load(self); // Extract header name and the corresponding namespace. String headerNameWithPrefix = getHeaderName().getPropertyValue(); String headerName = null; String headerNameNamespaceURI = null; int colon = headerNameWithPrefix.indexOf(':'); if (colon > 0) { headerNamePrefix = headerNameWithPrefix.substring(0, colon); headerName = headerNameWithPrefix.substring(colon + 1); headerNameNamespaceURI = getHeaderName().getNamespaces().get(headerNamePrefix); if (headerNameNamespaceURI == null) { Map<String, String> nsMap = new HashMap<String, String>(); NamedNodeMap nsList = self.getOwnerDocument().getChildNodes().item(0).getAttributes(); if (nsList.getLength() > 0) { for (int i = 0; i < nsList.getLength(); i++) { Node item = nsList.item(i); if (null != item.getPrefix() && "xmlns".equals(item.getPrefix())) { nsMap.put(item.getLocalName(), item.getNodeValue()); } } } headerNameNamespaceURI = (String) nsMap.get(headerNamePrefix); } } // Clear all other namespaces. getHeaderName().getNamespaces().clear(); // Set the extracted header name. if (!StringUtils.isBlank(headerName)) { getHeaderName().setPropertyValue(headerName); } // Add the namespace corresponding to header name. if (!StringUtils.isBlank(headerNamePrefix) && (!StringUtils.isBlank(headerNameNamespaceURI))) { getHeaderName().getNamespaces().put(headerNamePrefix, headerNameNamespaceURI); } } else { throw new Exception("Expected header name."); } // Header action. HeaderAction action = HeaderAction.get(self.getAttribute("action")); if (null != action) { setHeaderAction(action); } // removed exception throwing due to optionality of action // Header value. if (getHeaderAction().equals(HeaderAction.SET)) { if (self.hasAttribute("value")) { setValueType(HeaderValueType.LITERAL); setValueLiteral(self.getAttribute("value")); } else if (self.hasAttribute("expression")) { setValueType(HeaderValueType.EXPRESSION); getValueExpression().load(self); // Remove the namespace corresponding to header name. if (!StringUtils.isBlank(headerNamePrefix)) { getValueExpression().getNamespaces().remove(headerNamePrefix); } } else { throw new Exception("Expected either a header value or an expression."); } } super.doLoad(self); }
From source file:org.wso2.developerstudio.eclipse.esb.mediators.impl.MessageBuilderImpl.java
/** * {@inheritDoc}//from w ww .j a v a 2 s . c o m */ protected void doLoad(Element self) throws Exception { // Content type. if (self.hasAttribute("contentType")) { setContentType(self.getAttribute("contentType")); } else { throw new Exception("Missing message builder content type."); } // Builder class. if (self.hasAttribute("class")) { setBuilderClass(self.getAttribute("class")); } else { throw new Exception("Missing message builder class."); } // Formatter class. if (self.hasAttribute("formatterClass")) { setFormatterClass(self.getAttribute("formatterClass")); } else { setFormatterClass(null); } }
From source file:org.wso2.developerstudio.eclipse.esb.mediators.impl.PropertyMediatorImpl.java
/** * {@inheritDoc}/* w w w . java2s . c o m*/ */ protected void doLoad(Element self) throws Exception { // Property name. if (self.hasAttribute("name")) { setPropertyName(self.getAttribute("name")); } else { throw new Exception("Expected property name."); } // Property action. PropertyAction action = PropertyAction.get(self.getAttribute("action")); if (null == action) { action = PropertyAction.SET; } setPropertyAction(action); if (getPropertyAction().equals(PropertyAction.SET)) { // Property data type. PropertyDataType dataType = PropertyDataType.get(self.getAttribute("type")); if (null != dataType) { setPropertyDataType(dataType); } // Property value. if (self.hasAttribute("expression")) { setValueType(PropertyValueType.EXPRESSION); getValueExpression().load(self); } else { setValueType(PropertyValueType.LITERAL); if (self.hasAttribute("value")) { setValueLiteral(self.getAttribute("value")); } else if (getPropertyDataType().equals(PropertyDataType.OM)) { List<Element> childElems = getChildElements(self); if (!childElems.isEmpty()) { // Question: Is it possible there will be multiple child // elements? setValueOM(EsbUtils.renderElement(childElems.get(0), true)); } } else { throw new Exception("Unknown property value definition."); } } // String properties have additional pattern and group parameters. if (getPropertyDataType().equals(PropertyDataType.STRING)) { // Pattern. if (self.hasAttribute("pattern")) { setValueStringPattern(self.getAttribute("pattern")); } // Capturing group. if (self.hasAttribute("group")) { setValueStringCapturingGroup(Integer.parseInt(self.getAttribute("group"))); } } } // Property scope. PropertyScope scope = PropertyScope.get(self.getAttribute("scope")); if (null != scope) { setPropertyScope(scope); } super.doLoad(self); }
From source file:org.wso2.developerstudio.eclipse.esb.mediators.impl.RouterRouteImpl.java
/** * {@inheritDoc}//from w w w .j av a 2s.c o m */ protected void doLoad(Element self) throws Exception { if (self.hasAttribute("match")) { setRoutePattern(self.getAttribute("match")); } if (self.hasAttribute("breakRouter")) { setBreakAfterRoute(self.getAttribute("breakRouter").equals("true") ? true : false); } else { setBreakAfterRoute(false); } if (self.hasAttribute("expression")) { getRouteExpression().load(self); } loadObjects(self, "target", RouteTarget.class, new ObjectHandler<RouteTarget>() { public void handle(RouteTarget object) { setTarget(object); } }); super.doLoad(self); }
From source file:org.wso2.developerstudio.eclipse.esb.mediators.impl.ScriptMediatorImpl.java
/** * {@inheritDoc}/* w w w. j a v a 2 s . c o m*/ */ protected void doLoad(Element self) throws Exception { // Script language. ScriptLanguage language = ScriptLanguage.get(self.getAttribute("language")); if (null != language) { setScriptLanguage(language); } // Script type. if (self.hasAttribute("key")) { setScriptType(ScriptType.REGISTRY_REFERENCE); getScriptKey().load(self); // Script function. if (self.hasAttribute("function")) { setMediateFunction(self.getAttribute("function")); } } else { setScriptType(ScriptType.INLINE); CDATASection cdata = getChildCDATASection(self); if (null != cdata) { setScriptBody(cdata.getTextContent()); } } super.doLoad(self); }
From source file:org.wso2.developerstudio.eclipse.esb.mediators.impl.URLRewriteMediatorImpl.java
/** * {@inheritDoc}/* w w w . j ava 2s . co m*/ */ protected void doLoad(Element self) throws Exception { //Load In Property if (self.hasAttribute("inProperty")) { String inPropertyValue = self.getAttribute("inProperty"); if (inPropertyValue == null) { inPropertyValue = ""; } inPropertyValue = inPropertyValue.trim(); setInProperty(inPropertyValue); } else { setInProperty(""); } //Load Out Property if (self.hasAttribute("outProperty")) { String outPropertyValue = self.getAttribute("outProperty"); if (outPropertyValue == null) { outPropertyValue = ""; } outPropertyValue = outPropertyValue.trim(); setOutProperty(outPropertyValue); } else { setOutProperty(""); } loadObjects(self, "rewriterule", URLRewriteRule.class, new ObjectHandler<URLRewriteRule>() { public void handle(URLRewriteRule object) { getUrlRewriteRules().add(object); } }); super.doLoad(self); }
From source file:org.wso2.developerstudio.eclipse.esb.mediators.impl.XQueryMediatorImpl.java
/** * {@inheritDoc}// ww w . j a va 2 s .co m */ protected void doLoad(Element self) throws Exception { switch (getCurrentEsbVersion()) { case ESB301: // Query key. if (self.hasAttribute("key")) { getQueryKey().load(self); } else { throw new Exception("An xquery mediator must have a query key property."); } // Target XPath. if (self.hasAttribute("target")) { getTargetXPath().load(self); } // Variables. loadObjects(self, "variable", XQueryVariable.class, new ObjectHandler<XQueryVariable>() { public void handle(XQueryVariable object) { getVariables().add(object); } }); break; case ESB400: // XQuery script key. if (self.hasAttribute("key")) { String scriptKeyValue = self.getAttribute("key"); if (scriptKeyValue == null) { scriptKeyValue = ""; } scriptKeyValue = scriptKeyValue.trim(); if (scriptKeyValue.startsWith("{") && scriptKeyValue.endsWith("}")) { setScriptKeyType(getScriptKeyType().DYNAMIC); scriptKeyValue = scriptKeyValue.substring(1, scriptKeyValue.length() - 2); getDynamicScriptKey().setPropertyValue(scriptKeyValue); } else { setScriptKeyType(getScriptKeyType().STATIC); getStaticScriptKey().setKeyValue(scriptKeyValue); } } else { setScriptKeyType(getScriptKeyType().STATIC); //throw new Exception( // "An xquery mediator must have a query key property."); } // Target XPath. if (self.hasAttribute("target")) { getTargetXPath().load(self); } // Variables. loadObjects(self, "variable", XQueryVariable.class, new ObjectHandler<XQueryVariable>() { public void handle(XQueryVariable object) { getVariables().add(object); } }); break; } super.doLoad(self); }
From source file:org.wso2.developerstudio.eclipse.esb.mediators.impl.XQueryVariableImpl.java
/** * {@inheritDoc}// w ww. j a va2 s .c o m */ protected void doLoad(Element self) throws Exception { // Variable name. if (self.hasAttribute("name")) { setVariableName(self.getAttribute("name")); } else { throw new Exception("An xquery variable must have a name."); } // Variable type. XQueryVariableType variableType = null; if (self.hasAttribute("type")) { variableType = XQueryVariableType.get(self.getAttribute("type")); } if (null != variableType) { setVariableType(variableType); } else { throw new Exception("Missing or un-known variable type."); } // Variable value. if (self.hasAttribute("value")) { setValueType(XQueryVariableValueType.LITERAL); setValueLiteral(self.getAttribute("value")); } else { setValueType(XQueryVariableValueType.EXPRESSION); if (self.hasAttribute("expression")) { getValueExpression().load(self); } if (self.hasAttribute("key")) { getValueKey().load(self); } } super.doLoad(self); }