List of usage examples for org.w3c.dom Element normalize
public void normalize();
Text
nodes in the full depth of the sub-tree underneath this Node
, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text
nodes, i.e., there are neither adjacent Text
nodes nor empty Text
nodes. From source file:net.wastl.webmail.xml.XMLCommon.java
/** * @deprecated use getXPath instead!//from w w w . ja v a2 s . c om */ @Deprecated public static String getElementTextValue(Element e) { e.normalize(); NodeList nl = e.getChildNodes(); if (nl.getLength() <= 0) { log.error("Elements: " + nl.getLength()); // Should we not throw here so us developers will see and // fix the problem? - blaine return ""; } else { String s = ""; for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i) instanceof CharacterData) { s += nl.item(i).getNodeValue(); } } return s.trim(); } }
From source file:net.wastl.webmail.xml.XMLSystemData.java
public WebMailVirtualDomain getVirtualDomain(String domname) { // Check if virtual domains are disabled if (getVirtuals() == false) { // No, default to localhost return new WebMailVirtualDomain() { public String getDomainName() { return "localhost"; }/*from ww w . j a v a 2 s . com*/ public void setDomainName(String name) throws Exception { log.error("Ignoring DefaultDomain.setDomainName(). " + "Should not call this method."); } public String getDefaultServer() { return "localhost"; } public void setDefaultServer(String name) { log.error("Ignoring DefaultDomain.setDomainServer(). " + "Should not call this method."); } public String getAuthenticationHost() { return "localhost"; } public void setAuthenticationHost(String name) { log.error("Ignoring DefaultDomain.setAuthenticationHost(). " + "Should not call this method."); } public boolean isAllowedHost(String host) { return true; } public void setAllowedHosts(String hosts) { log.error("Ignoring DefaultDomain.setAllowedHosts(). " + "Should not call this method."); } public Enumeration<String> getAllowedHosts() { return new Enumeration<String>() { int i = 0; public boolean hasMoreElements() { return i < 1; } public String nextElement() { i++; return "localhost"; } }; } public void setHostsRestricted(boolean b) { log.error("Ignoring DefaultDomain.setHostsRestricted(). " + "Should not call this method."); } public boolean getHostsRestricted() { return false; } public String getImapBasedir() { return null; } }; } // Virtual domains are allowed, get that wanted one NodeList nodel = sysdata.getElementsByTagName("DOMAIN"); Element elem = null; int j; for (j = 0; j < nodel.getLength(); j++) { elem = (Element) nodel.item(j); elem.normalize(); NodeList namel = elem.getElementsByTagName("NAME"); if (namel.getLength() > 0) { if (XMLCommon.getElementTextValue((Element) namel.item(0)).equals(domname)) { break; } } } if (j < nodel.getLength() && elem != null) { final Element domain = elem; return new WebMailVirtualDomain() { public String getDomainName() { String value = XMLCommon.getTagValue(domain, "NAME"); return value == null ? "unknown" : value; } public void setDomainName(String name) throws Exception { XMLCommon.setTagValue(domain, "NAME", name, true, "Virtual Domain names must be unique!"); } public String getDefaultServer() { String value = XMLCommon.getTagValue(domain, "DEFAULT_HOST"); return value == null ? "unknown" : value; } /* Override the IMAP base directory for this domain, * for imap and imaps protocols */ public String getImapBaseDir() { String value = XMLCommon.getTagValue(domain, "IMAP_BASEDIR"); return value == null ? "unknown" : value; } public void setDefaultServer(String name) { XMLCommon.setTagValue(domain, "DEFAULT_HOST", name); } public String getAuthenticationHost() { String value = XMLCommon.getTagValue(domain, "AUTHENTICATION_HOST"); return value == null ? "unknown" : value; } public void setAuthenticationHost(String name) { XMLCommon.setTagValue(domain, "AUTHENTICATION_HOST", name); } public boolean isAllowedHost(String host) { if (getHostsRestricted()) { Vector<String> v = new Vector<String>(); v.addElement(getDefaultServer()); Enumeration<String> e = getAllowedHosts(); while (e.hasMoreElements()) { v.addElement(e.nextElement()); } Enumeration<String> enumVar = v.elements(); while (enumVar.hasMoreElements()) { String next = enumVar.nextElement(); if (host.toUpperCase().endsWith(next.toUpperCase())) { return true; } } return false; } else { return true; } } public void setAllowedHosts(String hosts) { NodeList nl = domain.getElementsByTagName("ALLOWED_HOST"); for (int i = 0; i < nl.getLength(); i++) { domain.removeChild(nl.item(i)); } StringTokenizer tok = new StringTokenizer(hosts, ", "); while (tok.hasMoreElements()) { Element ahost = root.createElement("ALLOWED_HOST"); XMLCommon.setElementTextValue(ahost, tok.nextToken()); domain.appendChild(ahost); } } public Enumeration<String> getAllowedHosts() { final NodeList nl = domain.getElementsByTagName("ALLOWED_HOST"); return new Enumeration<String>() { int i = 0; public boolean hasMoreElements() { return i < nl.getLength(); } public String nextElement() { String value = XMLCommon.getElementTextValue((Element) nl.item(i++)); return value == null ? "error" : value; } }; } public void setHostsRestricted(boolean b) { NodeList nl = domain.getElementsByTagName("RESTRICTED"); for (int i = 0; i < nl.getLength(); i++) { domain.removeChild(nl.item(i)); } if (b) { domain.appendChild(root.createElement("RESTRICTED")); } } public boolean getHostsRestricted() { NodeList nl = domain.getElementsByTagName("RESTRICTED"); return nl.getLength() > 0; } public String getImapBasedir() { NodeList nl = domain.getElementsByTagName("IMAP_BASEDIR"); return ((nl.getLength() > 0) ? XMLCommon.getElementTextValue((Element) nl.item(0)) : null); } }; } else { return null; } }
From source file:org.apache.hadoop.mapreduce.v2.app.rm.HostGroupLabelsFileReader.java
private static void readXMLFileToMap(String labelsFile, Map<String, Set<String>> hostGroupLabelsMap) throws IOException { try {/* ww w .j ava2 s . com*/ URL url = Thread.currentThread().getContextClassLoader().getResource(labelsFile); if (url == null) { LOG.fatal("Host group labels file " + labelsFile + " not found"); throw new RuntimeException("Host group labels file " + labelsFile + " not found"); } DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbFactory.newDocumentBuilder(); Document doc = docBuilder.parse(url.toString()); if (doc == null) { LOG.fatal("Error parsing host group labels file " + labelsFile); throw new RuntimeException("Error parsing host group labels file " + labelsFile); } Element root = doc.getDocumentElement(); root.normalize(); if (!"CBD-NodeGroups".equalsIgnoreCase(root.getTagName())) { LOG.fatal("Bad node group labels file " + labelsFile); throw new RuntimeException("Bad node group labels file " + labelsFile); } NodeList nodeGroupLabelsList = root.getChildNodes(); for (int i = 0; i < nodeGroupLabelsList.getLength(); i++) { Node nodeGroupLabelNode = nodeGroupLabelsList.item(i); if (!(nodeGroupLabelNode instanceof Element)) continue; Element nodeGroupLabel = (Element) nodeGroupLabelNode; if (!"NodeGroupLabel".equalsIgnoreCase(nodeGroupLabel.getTagName())) { throw new RuntimeException("Bad CBD NodeGroups labels file - no NodeGroupLabel"); } String nodeGroupLabelAttr = nodeGroupLabel.getAttribute("label"); NodeList nodeList = nodeGroupLabel.getChildNodes(); Set<String> nodeSet = new HashSet<String>(); for (int j = 0; j < nodeList.getLength(); j++) { Node nodeNode = nodeList.item(j); if (!(nodeNode instanceof Element)) continue; Element nodeElem = (Element) nodeNode; if ("Node".equalsIgnoreCase(nodeElem.getTagName())) { nodeSet.add(nodeElem.getTextContent().trim()); } } hostGroupLabelsMap.put(nodeGroupLabelAttr.toLowerCase(), nodeSet); } } catch (SAXException e) { LOG.fatal("error parsing conf file: " + e); throw new RuntimeException(e); } catch (ParserConfigurationException e) { LOG.fatal("error parsing conf file: " + e); throw new RuntimeException(e); } }
From source file:org.apache.ode.bpel.rtrep.v1.ASSIGN.java
/** * Get the r-value. There are several possibilities: * <ul>/* www . j a v a 2 s .c o m*/ * <li>a message is selected - an element representing the whole message is * returned.</li> * <li>a (element) message part is selected - the element is returned. * </li> * <li>a (typed) message part is select - a wrapper element is returned. * </li> * <li>an attribute is selected - an attribute node is returned. </li> * <li>a text node/string expression is selected - a text node is returned. * </li> * </ul> * * @param from * * @return Either {@link Element}, {@link org.w3c.dom.Text}, or * {@link org.w3c.dom.Attr} node representing the r-value. * * @throws FaultException * DOCUMENTME * @throws UnsupportedOperationException * DOCUMENTME * @throws IllegalStateException * DOCUMENTME */ private Node evalRValue(OAssign.RValue from) throws FaultException, ExternalVariableModuleException { if (__log.isDebugEnabled()) __log.debug("Evaluating FROM expression \"" + from + "\"."); Node retVal; if (from instanceof DirectRef) { OAssign.DirectRef dref = (OAssign.DirectRef) from; sendVariableReadEvent(_scopeFrame.resolve(dref.variable)); Node data = fetchVariableData(_scopeFrame.resolve(dref.variable), false); retVal = DOMUtils.findChildByName((Element) data, dref.elName); } else if (from instanceof OAssign.VariableRef) { OAssign.VariableRef varRef = (OAssign.VariableRef) from; sendVariableReadEvent(_scopeFrame.resolve(varRef.variable)); Node data = fetchVariableData(_scopeFrame.resolve(varRef.variable), false); retVal = evalQuery(data, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location, getEvaluationContext()); } else if (from instanceof OAssign.PropertyRef) { OAssign.PropertyRef propRef = (OAssign.PropertyRef) from; sendVariableReadEvent(_scopeFrame.resolve(propRef.variable)); Node data = fetchVariableData(_scopeFrame.resolve(propRef.variable), false); retVal = evalQuery(data, propRef.propertyAlias.part, propRef.propertyAlias.location, getEvaluationContext()); } else if (from instanceof OAssign.PartnerLinkRef) { OAssign.PartnerLinkRef pLinkRef = (OAssign.PartnerLinkRef) from; PartnerLinkInstance pLink = _scopeFrame.resolve(pLinkRef.partnerLink); Node tempVal = pLinkRef.isMyEndpointReference ? getBpelRuntime().fetchMyRoleEndpointReferenceData(pLink) : getBpelRuntime().fetchPartnerRoleEndpointReferenceData(pLink); if (__log.isDebugEnabled()) __log.debug("RValue is a partner link, corresponding endpoint " + tempVal.getClass().getName() + " has value " + DOMUtils.domToString(tempVal)); retVal = tempVal; } else if (from instanceof OAssign.Expression) { OExpression expr = ((OAssign.Expression) from).expression; List<Node> l = getBpelRuntime().getExpLangRuntime().evaluate(expr, getEvaluationContext()); if (l.size() == 0) { String msg = __msgs.msgRValueNoNodesSelected(expr.toString()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg, new Throwable("ignoreMissingFromData")); } else if (l.size() > 1) { String msg = __msgs.msgRValueMultipleNodesSelected(expr.toString()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } retVal = (Node) l.get(0); } else if (from instanceof OAssign.Literal) { Element literalRoot = ((OAssign.Literal) from).getXmlLiteral().getDocumentElement(); assert literalRoot.getLocalName().equals("literal"); // We'd like a single text node... literalRoot.normalize(); retVal = literalRoot.getFirstChild(); // Adjust for whitespace before an element. if (retVal != null && retVal.getNodeType() == Node.TEXT_NODE && retVal.getTextContent().trim().length() == 0 && retVal.getNextSibling() != null) { retVal = retVal.getNextSibling(); } if (retVal == null) { // Special case, no children --> empty TII retVal = literalRoot.getOwnerDocument().createTextNode(""); } else if (retVal.getNodeType() == Node.ELEMENT_NODE) { // Make sure there is no more elements. Node x = retVal.getNextSibling(); while (x != null) { if (x.getNodeType() == Node.ELEMENT_NODE) { String msg = __msgs.msgLiteralContainsMultipleEIIs(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } x = x.getNextSibling(); } } else if (retVal.getNodeType() == Node.TEXT_NODE) { // Make sure there are no elements following this text node. Node x = retVal.getNextSibling(); while (x != null) { if (x.getNodeType() == Node.ELEMENT_NODE) { String msg = __msgs.msgLiteralContainsMixedContent(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } x = x.getNextSibling(); } } if (retVal == null) { String msg = __msgs.msgLiteralMustContainTIIorEII(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } } else { String msg = __msgs.msgInternalError("Unknown RVALUE type: " + from); if (__log.isErrorEnabled()) __log.error(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } // Now verify we got something. if (retVal == null) { String msg = __msgs.msgEmptyRValue(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } // Now check that we got the right thing. switch (retVal.getNodeType()) { case Node.TEXT_NODE: case Node.ATTRIBUTE_NODE: case Node.ELEMENT_NODE: case Node.CDATA_SECTION_NODE: break; default: String msg = __msgs.msgInvalidRValue(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } return retVal; }
From source file:org.apache.ode.bpel.rtrep.v2.ASSIGN.java
/** * Get the r-value. There are several possibilities: * <ul>/* w w w. j ava 2 s .com*/ * <li>a message is selected - an element representing the whole message is * returned.</li> * <li>a (element) message part is selected - the element is returned. * </li> * <li>a (typed) message part is select - a wrapper element is returned. * </li> * <li>an attribute is selected - an attribute node is returned. </li> * <li>a text node/string expression is selected - a text node is returned. * </li> * </ul> * * @param from * * @return Either {@link Element}, {@link org.w3c.dom.Text}, or * {@link org.w3c.dom.Attr} node representing the r-value. * * @throws FaultException * DOCUMENTME * @throws UnsupportedOperationException * DOCUMENTME * @throws IllegalStateException * DOCUMENTME */ private Node evalRValue(OAssign.RValue from) throws FaultException, ExternalVariableModuleException { if (__log.isDebugEnabled()) __log.debug("Evaluating FROM expression \"" + from + "\"."); Node retVal; if (from instanceof OAssign.DirectRef) { OAssign.DirectRef dref = (OAssign.DirectRef) from; sendVariableReadEvent(_scopeFrame.resolve(dref.variable)); Node data = fetchVariableData(_scopeFrame.resolve(dref.variable), false); retVal = DOMUtils.findChildByName((Element) data, dref.elName); } else if (from instanceof OAssign.VariableRef) { OAssign.VariableRef varRef = (OAssign.VariableRef) from; sendVariableReadEvent(_scopeFrame.resolve(varRef.variable)); Node data = fetchVariableData(_scopeFrame.resolve(varRef.variable), false); retVal = evalQuery(data, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location, getEvaluationContext()); } else if (from instanceof OAssign.PropertyRef) { OAssign.PropertyRef propRef = (OAssign.PropertyRef) from; sendVariableReadEvent(_scopeFrame.resolve(propRef.variable)); Node data = fetchVariableData(_scopeFrame.resolve(propRef.variable), false); retVal = evalQuery(data, propRef.propertyAlias.part, propRef.propertyAlias.location, getEvaluationContext()); } else if (from instanceof OAssign.PartnerLinkRef) { OAssign.PartnerLinkRef pLinkRef = (OAssign.PartnerLinkRef) from; PartnerLinkInstance pLink = _scopeFrame.resolve(pLinkRef.partnerLink); Node tempVal = pLinkRef.isMyEndpointReference ? getBpelRuntime().fetchMyRoleEndpointReferenceData(pLink) : getBpelRuntime().fetchPartnerRoleEndpointReferenceData(pLink); if (__log.isDebugEnabled()) __log.debug("RValue is a partner link, corresponding endpoint " + tempVal.getClass().getName() + " has value " + DOMUtils.domToString(tempVal)); retVal = tempVal; } else if (from instanceof OAssign.Expression) { OExpression expr = ((OAssign.Expression) from).expression; List<Node> l = getBpelRuntime().getExpLangRuntime().evaluate(expr, getEvaluationContext()); if (l.size() == 0) { String msg = __msgs.msgRValueNoNodesSelected(expr.toString()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg, new Throwable("ignoreMissingFromData")); } else if (l.size() > 1) { String msg = __msgs.msgRValueMultipleNodesSelected(expr.toString()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } retVal = l.get(0); } else if (from instanceof OAssign.Literal) { Element literalRoot = ((OAssign.Literal) from).getXmlLiteral().getDocumentElement(); assert literalRoot.getLocalName().equals("literal"); // We'd like a single text node... literalRoot.normalize(); retVal = literalRoot.getFirstChild(); // Adjust for whitespace before an element. if (retVal != null && retVal.getNodeType() == Node.TEXT_NODE && retVal.getTextContent().trim().length() == 0 && retVal.getNextSibling() != null) { retVal = retVal.getNextSibling(); } if (retVal == null) { // Special case, no children --> empty TII retVal = literalRoot.getOwnerDocument().createTextNode(""); } else if (retVal.getNodeType() == Node.ELEMENT_NODE) { // Make sure there is no more elements. Node x = retVal.getNextSibling(); while (x != null) { if (x.getNodeType() == Node.ELEMENT_NODE) { String msg = __msgs.msgLiteralContainsMultipleEIIs(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } x = x.getNextSibling(); } } else if (retVal.getNodeType() == Node.TEXT_NODE) { // Make sure there are no elements following this text node. Node x = retVal.getNextSibling(); while (x != null) { if (x.getNodeType() == Node.ELEMENT_NODE) { String msg = __msgs.msgLiteralContainsMixedContent(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } x = x.getNextSibling(); } } if (retVal == null) { String msg = __msgs.msgLiteralMustContainTIIorEII(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } } else { String msg = __msgs.msgInternalError("Unknown RVALUE type: " + from); if (__log.isErrorEnabled()) __log.error(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } // Now verify we got something. if (retVal == null) { String msg = __msgs.msgEmptyRValue(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } // Now check that we got the right thing. switch (retVal.getNodeType()) { case Node.TEXT_NODE: case Node.ATTRIBUTE_NODE: case Node.ELEMENT_NODE: case Node.CDATA_SECTION_NODE: break; default: String msg = __msgs.msgInvalidRValue(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } return retVal; }
From source file:org.apache.ode.bpel.rtrep.v2.AssignHelper.java
/** * Get the r-value. There are several possibilities: * <ul>/* w ww. j a va 2 s. co m*/ * <li>a message is selected - an element representing the whole message is * returned.</li> * <li>a (element) message part is selected - the element is returned. * </li> * <li>a (typed) message part is select - a wrapper element is returned. * </li> * <li>an attribute is selected - an attribute node is returned. </li> * <li>a text node/string expression is selected - a text node is returned. * </li> * </ul> * (madars.vitolins _at gmail.com - 2009.04.17 - moved from ASSIGN here) * @param from * * @return Either {@link Element}, {@link org.w3c.dom.Text}, or * {@link org.w3c.dom.Attr} node representing the r-value. * * @throws FaultException * DOCUMENTME * @throws UnsupportedOperationException * DOCUMENTME * @throws IllegalStateException * DOCUMENTME */ public Node evalRValue(OAssign.RValue from) throws FaultException, ExternalVariableModuleException { if (__log.isDebugEnabled()) __log.debug("Evaluating FROM expression \"" + from + "\"."); Node retVal; if (from instanceof OAssign.DirectRef) { OAssign.DirectRef dref = (OAssign.DirectRef) from; sendVariableReadEvent(_scopeFrame.resolve(dref.variable)); Node data = fetchVariableData(_scopeFrame.resolve(dref.variable), false); retVal = DOMUtils.findChildByName((Element) data, dref.elName); } else if (from instanceof OAssign.VariableRef) { OAssign.VariableRef varRef = (OAssign.VariableRef) from; sendVariableReadEvent(_scopeFrame.resolve(varRef.variable)); Node data = fetchVariableData(_scopeFrame.resolve(varRef.variable), false); retVal = evalQuery(data, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location, getEvaluationContext()); } else if (from instanceof OAssign.PropertyRef) { OAssign.PropertyRef propRef = (OAssign.PropertyRef) from; sendVariableReadEvent(_scopeFrame.resolve(propRef.variable)); Node data = fetchVariableData(_scopeFrame.resolve(propRef.variable), false); retVal = evalQuery(data, propRef.propertyAlias.part, propRef.propertyAlias.location, getEvaluationContext()); } else if (from instanceof OAssign.PartnerLinkRef) { OAssign.PartnerLinkRef pLinkRef = (OAssign.PartnerLinkRef) from; PartnerLinkInstance pLink = _scopeFrame.resolve(pLinkRef.partnerLink); Node tempVal = pLinkRef.isMyEndpointReference ? getBpelRuntime().fetchMyRoleEndpointReferenceData(pLink) : getBpelRuntime().fetchPartnerRoleEndpointReferenceData(pLink); if (__log.isDebugEnabled()) __log.debug("RValue is a partner link, corresponding endpoint " + tempVal.getClass().getName() + " has value " + DOMUtils.domToString(tempVal)); retVal = tempVal; } else if (from instanceof OAssign.ContextRef) { OAssign.ContextRef ctxRef = (OAssign.ContextRef) from; ContextData cdata = getBpelRuntime().fetchContextData(_scopeFrame.resolve(ctxRef.partnerLink)); retVal = evalQuery(cdata.toXML(ctxRef.contexts), null, ctxRef.location, getEvaluationContext()); } else if (from instanceof OAssign.Expression) { OExpression expr = ((OAssign.Expression) from).expression; List<Node> l = getBpelRuntime().getExpLangRuntime().evaluate(expr, getEvaluationContext()); if (l.size() == 0) { String msg = __msgs.msgRValueNoNodesSelected(expr.toString()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg, new Throwable("ignoreMissingFromData")); } else if (l.size() > 1) { String msg = __msgs.msgRValueMultipleNodesSelected(expr.toString()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } retVal = l.get(0); } else if (from instanceof OAssign.Literal) { Element literalRoot = ((OAssign.Literal) from).getXmlLiteral().getDocumentElement(); assert literalRoot.getLocalName().equals("literal"); // We'd like a single text node... literalRoot.normalize(); retVal = literalRoot.getFirstChild(); // Adjust for whitespace before an element. if (retVal != null && retVal.getNodeType() == Node.TEXT_NODE && retVal.getTextContent().trim().length() == 0 && retVal.getNextSibling() != null) { retVal = retVal.getNextSibling(); } if (retVal == null) { // Special case, no children --> empty TII retVal = literalRoot.getOwnerDocument().createTextNode(""); } else if (retVal.getNodeType() == Node.ELEMENT_NODE) { // Make sure there is no more elements. Node x = retVal.getNextSibling(); while (x != null) { if (x.getNodeType() == Node.ELEMENT_NODE) { String msg = __msgs.msgLiteralContainsMultipleEIIs(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } x = x.getNextSibling(); } } else if (retVal.getNodeType() == Node.TEXT_NODE) { // Make sure there are no elements following this text node. Node x = retVal.getNextSibling(); while (x != null) { if (x.getNodeType() == Node.ELEMENT_NODE) { String msg = __msgs.msgLiteralContainsMixedContent(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } x = x.getNextSibling(); } } if (retVal == null) { String msg = __msgs.msgLiteralMustContainTIIorEII(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } } else { String msg = __msgs.msgInternalError("Unknown RVALUE type: " + from); if (__log.isErrorEnabled()) __log.error(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } // Now verify we got something. if (retVal == null) { String msg = __msgs.msgEmptyRValue(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } // Now check that we got the right thing. switch (retVal.getNodeType()) { case Node.TEXT_NODE: case Node.ATTRIBUTE_NODE: case Node.ELEMENT_NODE: case Node.CDATA_SECTION_NODE: break; default: String msg = __msgs.msgInvalidRValue(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } return retVal; }
From source file:org.apache.ode.bpel.runtime.ASSIGN.java
/** * Get the r-value. There are several possibilities: * <ul>//w w w. j a va2s. c o m * <li>a message is selected - an element representing the whole message is * returned.</li> * <li>a (element) message part is selected - the element is returned. * </li> * <li>a (typed) message part is select - a wrapper element is returned. * </li> * <li>an attribute is selected - an attribute node is returned. </li> * <li>a text node/string expression is selected - a text node is returned. * </li> * </ul> * * @param from * * @return Either {@link Element}, {@link org.w3c.dom.Text}, or * {@link org.w3c.dom.Attr} node representing the r-value. * * @throws FaultException * DOCUMENTME * @throws UnsupportedOperationException * DOCUMENTME * @throws IllegalStateException * DOCUMENTME */ private Node evalRValue(OAssign.RValue from) throws FaultException, ExternalVariableModuleException { if (__log.isDebugEnabled()) __log.debug("Evaluating FROM expression \"" + from + "\"."); Node retVal; if (from instanceof DirectRef) { OAssign.DirectRef dref = (OAssign.DirectRef) from; sendVariableReadEvent(_scopeFrame.resolve(dref.variable)); Node data = fetchVariableData(_scopeFrame.resolve(dref.variable), false); retVal = DOMUtils.findChildByName((Element) data, dref.elName); } else if (from instanceof OAssign.VariableRef) { OAssign.VariableRef varRef = (OAssign.VariableRef) from; sendVariableReadEvent(_scopeFrame.resolve(varRef.variable)); Node data = fetchVariableData(_scopeFrame.resolve(varRef.variable), false); retVal = evalQuery(data, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location, getEvaluationContext()); } else if (from instanceof OAssign.PropertyRef) { OAssign.PropertyRef propRef = (OAssign.PropertyRef) from; sendVariableReadEvent(_scopeFrame.resolve(propRef.variable)); Node data = fetchVariableData(_scopeFrame.resolve(propRef.variable), false); retVal = evalQuery(data, propRef.propertyAlias.part, propRef.propertyAlias.location, getEvaluationContext()); } else if (from instanceof OAssign.PartnerLinkRef) { OAssign.PartnerLinkRef pLinkRef = (OAssign.PartnerLinkRef) from; PartnerLinkInstance pLink = _scopeFrame.resolve(pLinkRef.partnerLink); Node tempVal = pLinkRef.isMyEndpointReference ? getBpelRuntimeContext().fetchMyRoleEndpointReferenceData(pLink) : getBpelRuntimeContext().fetchPartnerRoleEndpointReferenceData(pLink); if (__log.isDebugEnabled()) __log.debug("RValue is a partner link, corresponding endpoint " + tempVal.getClass().getName() + " has value " + DOMUtils.domToString(tempVal)); retVal = tempVal; } else if (from instanceof OAssign.Expression) { List<Node> l; OExpression expr = ((OAssign.Expression) from).expression; try { l = getBpelRuntimeContext().getExpLangRuntime().evaluate(expr, getEvaluationContext()); if (l.size() == 0 || l.get(0) == null || !(l.get(0) instanceof Element)) { if (__log.isTraceEnabled()) { __log.trace("evalRValue: OAssign.Expression: eval reult not Element or node=null"); } } else { Element element = (Element) l.get(0); for (Map.Entry<String, String> entry : DOMUtils.getMyNSContext(element).toMap().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (entry.getKey() == null || entry.getKey().length() == 0) { element.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns", value); } else { element.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + key, value); } } } } catch (EvaluationException e) { String msg = __msgs.msgEvalException(from.toString(), e.getMessage()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); if (e.getCause() instanceof FaultException) throw (FaultException) e.getCause(); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } if (l.size() == 0) { String msg = __msgs.msgRValueNoNodesSelected(expr.toString()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg, new Throwable("ignoreMissingFromData")); } else if (l.size() > 1) { String msg = __msgs.msgRValueMultipleNodesSelected(expr.toString()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } retVal = (Node) l.get(0); } else if (from instanceof OAssign.Literal) { String literal = ((OAssign.Literal) from).getXmlLiteral(); Element literalRoot; try { literalRoot = DOMUtils.stringToDOM(literal); } catch (Exception e) { throw new RuntimeException("XML literal parsing failed " + literal, e); } assert literalRoot.getLocalName().equals("literal"); // We'd like a single text node... literalRoot.normalize(); retVal = literalRoot.getFirstChild(); // Adjust for whitespace before an element. if (retVal != null && retVal.getNodeType() == Node.TEXT_NODE && retVal.getTextContent().trim().length() == 0 && retVal.getNextSibling() != null) { retVal = retVal.getNextSibling(); } if (retVal == null) { // Special case, no children --> empty TII retVal = literalRoot.getOwnerDocument().createTextNode(""); } else if (retVal.getNodeType() == Node.ELEMENT_NODE) { // Make sure there is no more elements. Node x = retVal.getNextSibling(); while (x != null) { if (x.getNodeType() == Node.ELEMENT_NODE) { String msg = __msgs.msgLiteralContainsMultipleEIIs(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } x = x.getNextSibling(); } } else if (retVal.getNodeType() == Node.TEXT_NODE) { // Make sure there are no elements following this text node. Node x = retVal.getNextSibling(); while (x != null) { if (x.getNodeType() == Node.ELEMENT_NODE) { String msg = __msgs.msgLiteralContainsMixedContent(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } x = x.getNextSibling(); } } if (retVal == null) { String msg = __msgs.msgLiteralMustContainTIIorEII(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } } else { String msg = __msgs.msgInternalError("Unknown RVALUE type: " + from); if (__log.isErrorEnabled()) __log.error(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } // Now verify we got something. if (retVal == null) { String msg = __msgs.msgEmptyRValue(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } // Now check that we got the right thing. switch (retVal.getNodeType()) { case Node.TEXT_NODE: case Node.ATTRIBUTE_NODE: case Node.ELEMENT_NODE: case Node.CDATA_SECTION_NODE: break; default: String msg = __msgs.msgInvalidRValue(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } return retVal; }
From source file:org.apache.ode.bpel.runtime.AssignHelper.java
/** * Get the r-value. There are several possibilities: * <ul>//from w w w . j ava 2 s . com * <li>a message is selected - an element representing the whole message is * returned.</li> * <li>a (element) message part is selected - the element is returned. * </li> * <li>a (typed) message part is select - a wrapper element is returned. * </li> * <li>an attribute is selected - an attribute node is returned. </li> * <li>a text node/string expression is selected - a text node is returned. * </li> * </ul> * * @param from * * @return Either {@link Element}, {@link org.w3c.dom.Text}, or * {@link org.w3c.dom.Attr} node representing the r-value. * * @throws FaultException * DOCUMENTME * @throws UnsupportedOperationException * DOCUMENTME * @throws IllegalStateException * DOCUMENTME */ private Node evalRValue(OAssign.RValue from) throws FaultException, ExternalVariableModuleException { if (__log.isDebugEnabled()) __log.debug("Evaluating FROM expression \"" + from + "\"."); Node retVal; if (from instanceof DirectRef) { OAssign.DirectRef dref = (OAssign.DirectRef) from; sendVariableReadEvent(_scopeFrame.resolve(dref.variable)); Node data = fetchVariableData(_scopeFrame.resolve(dref.variable), false); retVal = DOMUtils.findChildByName((Element) data, dref.elName); } else if (from instanceof OAssign.VariableRef) { OAssign.VariableRef varRef = (OAssign.VariableRef) from; sendVariableReadEvent(_scopeFrame.resolve(varRef.variable)); Node data = fetchVariableData(_scopeFrame.resolve(varRef.variable), false); retVal = evalQuery(data, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location, getEvaluationContext()); } else if (from instanceof OAssign.PropertyRef) { OAssign.PropertyRef propRef = (OAssign.PropertyRef) from; sendVariableReadEvent(_scopeFrame.resolve(propRef.variable)); Node data = fetchVariableData(_scopeFrame.resolve(propRef.variable), false); retVal = evalQuery(data, propRef.propertyAlias.part, propRef.propertyAlias.location, getEvaluationContext()); } else if (from instanceof OAssign.PartnerLinkRef) { OAssign.PartnerLinkRef pLinkRef = (OAssign.PartnerLinkRef) from; PartnerLinkInstance pLink = _scopeFrame.resolve(pLinkRef.partnerLink); Node tempVal = pLinkRef.isMyEndpointReference ? getBpelRuntimeContext().fetchMyRoleEndpointReferenceData(pLink) : getBpelRuntimeContext().fetchPartnerRoleEndpointReferenceData(pLink); if (__log.isDebugEnabled()) __log.debug("RValue is a partner link, corresponding endpoint " + tempVal.getClass().getName() + " has value " + DOMUtils.domToString(tempVal)); retVal = tempVal; } else if (from instanceof OAssign.Expression) { List<Node> l; OExpression expr = ((OAssign.Expression) from).expression; try { l = getBpelRuntimeContext().getExpLangRuntime().evaluate(expr, getEvaluationContext()); } catch (EvaluationException e) { String msg = __msgs.msgEvalException(from.toString(), e.getMessage()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); if (e.getCause() instanceof FaultException) throw (FaultException) e.getCause(); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } if (l.size() == 0) { String msg = __msgs.msgRValueNoNodesSelected(expr.toString()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg, new Throwable("ignoreMissingFromData")); } else if (l.size() > 1) { String msg = __msgs.msgRValueMultipleNodesSelected(expr.toString()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } retVal = (Node) l.get(0); } else if (from instanceof OAssign.Literal) { String literal = ((OAssign.Literal) from).getXmlLiteral(); Element literalRoot; try { literalRoot = DOMUtils.stringToDOM(literal); } catch (Exception e) { throw new RuntimeException("XML literal parsing failed " + literal, e); } assert literalRoot.getLocalName().equals("literal"); // We'd like a single text node... literalRoot.normalize(); retVal = literalRoot.getFirstChild(); // Adjust for whitespace before an element. if (retVal != null && retVal.getNodeType() == Node.TEXT_NODE && retVal.getTextContent().trim().length() == 0 && retVal.getNextSibling() != null) { retVal = retVal.getNextSibling(); } if (retVal == null) { // Special case, no children --> empty TII retVal = literalRoot.getOwnerDocument().createTextNode(""); } else if (retVal.getNodeType() == Node.ELEMENT_NODE) { // Make sure there is no more elements. Node x = retVal.getNextSibling(); while (x != null) { if (x.getNodeType() == Node.ELEMENT_NODE) { String msg = __msgs.msgLiteralContainsMultipleEIIs(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } x = x.getNextSibling(); } } else if (retVal.getNodeType() == Node.TEXT_NODE) { // Make sure there are no elements following this text node. Node x = retVal.getNextSibling(); while (x != null) { if (x.getNodeType() == Node.ELEMENT_NODE) { String msg = __msgs.msgLiteralContainsMixedContent(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } x = x.getNextSibling(); } } if (retVal == null) { String msg = __msgs.msgLiteralMustContainTIIorEII(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } } else { String msg = __msgs.msgInternalError("Unknown RVALUE type: " + from); if (__log.isErrorEnabled()) __log.error(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } // Now verify we got something. if (retVal == null) { String msg = __msgs.msgEmptyRValue(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } // Now check that we got the right thing. switch (retVal.getNodeType()) { case Node.TEXT_NODE: case Node.ATTRIBUTE_NODE: case Node.ELEMENT_NODE: case Node.CDATA_SECTION_NODE: break; default: String msg = __msgs.msgInvalidRValue(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } return retVal; }
From source file:org.apache.ws.security.processor.X509Util.java
protected static SecretKey getSharedKey(Element keyInfoElem, String algorithm, CallbackHandler cb) throws WSSecurityException { String keyName = null;/*from w w w . j a va 2 s .com*/ Element keyNmElem = (Element) WSSecurityUtil.getDirectChild(keyInfoElem, "KeyName", WSConstants.SIG_NS); if (keyNmElem != null) { keyNmElem.normalize(); Node tmpN = keyNmElem.getFirstChild(); if (tmpN != null && tmpN.getNodeType() == Node.TEXT_NODE) { keyName = tmpN.getNodeValue(); } } if (keyName == null) { throw new WSSecurityException(WSSecurityException.INVALID_SECURITY, "noKeyname"); } WSPasswordCallback pwCb = new WSPasswordCallback(keyName, WSPasswordCallback.KEY_NAME); Callback[] callbacks = new Callback[1]; callbacks[0] = pwCb; try { cb.handle(callbacks); } catch (IOException e) { throw new WSSecurityException(WSSecurityException.FAILURE, "noPassword", new Object[] { keyName }, e); } catch (UnsupportedCallbackException e) { throw new WSSecurityException(WSSecurityException.FAILURE, "noPassword", new Object[] { keyName }, e); } byte[] decryptedData = pwCb.getKey(); if (decryptedData == null) { throw new WSSecurityException(WSSecurityException.FAILURE, "noPassword", new Object[] { keyName }); } return WSSecurityUtil.prepareSecretKey(algorithm, decryptedData); }
From source file:org.apereo.portal.groups.ldap.LDAPGroupStore.java
protected void init(Document config) { this.groups = new HashMap(); this.contexts = new SmartCache(120); config.normalize();// w w w. j ava 2s . co m int refreshminutes = 120; Element root = config.getDocumentElement(); NodeList nl = root.getElementsByTagName("config"); if (nl.getLength() == 1) { Element conf = (Element) nl.item(0); Node cc = conf.getFirstChild(); //NodeList cl= conf.getF.getChildNodes(); //for(int i=0; i<cl.getLength(); i++){ while (cc != null) { if (cc.getNodeType() == ELEMENT_NODE) { Element c = (Element) cc; c.normalize(); Node t = c.getFirstChild(); if (t != null && t.getNodeType() == Node.TEXT_NODE) { String name = c.getNodeName(); String text = ((Text) t).getData(); //System.out.println(name+" = "+text); if (name.equals("url")) { url = text; } else if (name.equals("logonid")) { logonid = text; } else if (name.equals("logonpassword")) { logonpassword = text; } else if (name.equals("keyfield")) { keyfield = text; } else if (name.equals("namefield")) { namefield = text; } else if (name.equals("usercontext")) { usercontext = text; } else if (name.equals("refresh-minutes")) { try { refreshminutes = Integer.parseInt(text); } catch (Exception e) { } } } } cc = cc.getNextSibling(); } } else { throw new RuntimeException("LDAPGroupStore: config file must contain one config element"); } this.personkeys = new SmartCache(refreshminutes * 60); NodeList gl = root.getChildNodes(); for (int j = 0; j < gl.getLength(); j++) { if (gl.item(j).getNodeType() == ELEMENT_NODE) { Element g = (Element) gl.item(j); if (g.getNodeName().equals("group")) { GroupShadow shadow = processXmlGroupRecursive(g); groups.put(shadow.key, shadow); } } } }