/*
Get the value of an element. If no value type is specified, then white space is trimmed out
of the value. If it contains multiple value elements they are added as strings before being
converted to any specified type. @param node
540776
private Object value(Object obj, XmlParser.Node node) throws NoSuchMethodException,
            ClassNotFoundException, InvocationTargetException, IllegalAccessException
    {
        Object value = null;

        // Get the type
        String type = node.getAttribute("type");

        // Try a ref lookup
        String ref = node.getAttribute("ref");
        if (ref != null)
        {
            value = _idMap.get(ref);
        }
        else
        {
            // handle trivial case
            if (node.size() == 0)
            {
                if ("String".equals(type)) return "";
                return null;
            }

            // Trim values
            int first = 0;
            int last = node.size() - 1;

            // Handle default trim type
            if (type == null || !"String".equals(type))
            {
                // Skip leading white
                Object item = null;
                while (first <= last)
                {
                    item = node.get(first);
                    if (!(item instanceof String)) break;
                    item = ((String) item).trim();
                    if (((String) item).length() > 0) break;
                    first++;
                }

                // Skip trailing white
                while (first < last)
                {
                    item = node.get(last);
                    if (!(item instanceof String)) break;
                    item = ((String) item).trim();
                    if (((String) item).length() > 0) break;
                    last--;
                }

                // All white, so return null
                if (first > last) return null;
            }

            if (first == last)
                //  Single Item value
                value = itemValue(obj, node.get(first));
            else
            {
                // Get the multiple items as a single string
                StringBuffer buf = new StringBuffer();
                synchronized (buf)
                {
                    for (int i = first; i <= last; i++)
                    {
                        Object item = node.get(i);
                        buf.append(itemValue(obj, item));
                    }
                    value = buf.toString();
                }
            }
        }

        // Untyped or unknown
        if (value == null)
        {
            if ("String".equals(type)) return "";
            return null;
        }

        // Try to type the object
        if (type == null)
        {
            if (value != null && value instanceof String) return ((String) value).trim();
            return value;
        }

        if ("String".equals(type) || "java.lang.String".equals(type)) return value.toString();

        Class pClass = TypeUtil.fromName(type);
        if (pClass != null) return TypeUtil.valueOf(pClass, value.toString());

        if ("URL".equals(type) || "java.net.URL".equals(type))
        {
            if (value instanceof URL) return value;
            try
            {
                return new URL(value.toString());
            }
            catch (MalformedURLException e)
            {
                throw new InvocationTargetException(e);
            }
        }

        if ("InetAddress".equals(type) || "java.net.InetAddress".equals(type))
        {
            if (value instanceof InetAddress) return value;
            try
            {
                return InetAddress.getByName(value.toString());
            }
            catch (UnknownHostException e)
            {
                throw new InvocationTargetException(e);
            }
        }

        if ("InetAddrPort".equals(type) || "org.browsermob.proxy.jetty.util.InetAddrPort".equals(type))
        {
            if (value instanceof InetAddrPort) return value;
            try
            {
                return new InetAddrPort(value.toString());
            }
            catch (UnknownHostException e)
            {
                throw new InvocationTargetException(e);
            }
        }

        throw new IllegalStateException("Unknown type " + type);
    }
1300063
public static String getElementNodeValue(Node node) {
        StringWriter sw = new StringWriter(2000);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            NodeList all = node.getChildNodes();
            for (int i = 0; i < all.getLength(); i++) {
                if (all.item(i).getNodeType() == Node.TEXT_NODE ||
                    all.item(i).getNodeType() == Node.CDATA_SECTION_NODE) {
                    // TODO: Check if we exceed the limit for getNodeValue
                    sw.append(all.item(i).getNodeValue());
                }
            }
        }
        return sw.toString();
    }
602297
private void assignValue(SimpleNode node, RelationQueryNode queryNode) {
        if (node.getId() == JJTSTRINGLITERAL) {
            queryNode.setStringValue(unescapeQuotes(node.getValue()));
        } else if (node.getId() == JJTDECIMALLITERAL) {
            queryNode.setDoubleValue(Double.parseDouble(node.getValue()));
        } else if (node.getId() == JJTDOUBLELITERAL) {
            queryNode.setDoubleValue(Double.parseDouble(node.getValue()));
        } else if (node.getId() == JJTINTEGERLITERAL) {
            // if this is an expression that contains position() do not change
            // the type.
            if (queryNode.getValueType() == QueryConstants.TYPE_POSITION) {
                queryNode.setPositionValue(Integer.parseInt(node.getValue()));
            } else {
                queryNode.setLongValue(Long.parseLong(node.getValue()));
            }
        } else {
            exceptions.add(new InvalidQueryException("Unsupported literal type:" + node.toString()));
        }
    }
1074790
public Node<T> getPrevious(Node<T> node) {
    	if (node.left != null) {
    		node = node.left;
    		while (node.right != null) node = node.right;
    		return node;
    	}
    	// nothing at left, it may be the parent node if the node is at the right
    	if (node == first) return null;
    	return getPrevious(root, node.value);
    }
501290
private String getStringValue(Node node) {
        switch (node.getNodeType()) {
            case Node.ATTRIBUTE_NODE:
            case Node.TEXT_NODE:
                return node.getNodeValue();
            default: {
                try {
                    Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
                    StringWriter buffer = new StringWriter();
                    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                    transformer.transform(new DOMSource(node), new StreamResult(buffer));
                    return buffer.toString();
                } catch (Exception e) {
                }
                return null;
            }
        }
    }
407835
function(node, name) {
                var value = this.getStyle(node.getType() + "-" + name, node);
                return value !== null ? value : this.getStyle(name, node);
            }
254992
static String getAttributeValue(Element element, String name) {
        Attr attribute = element.getAttributeNode(name);
        if (attribute == null) {
            return null;
        } else {
            return attribute.getValue();
        }
    }
779780
public static String getStringValue(Node n) {
    // TODO(user): regex literals as well.
    switch (n.getToken()) {
      case STRING:
      case STRING_KEY:
        return n.getString();

      case TEMPLATELIT:
        // Only convert a template literal if all its expressions can be converted.
        String string = "";
        for (Node child = n.getFirstChild(); child != null; child = child.getNext()) {
          Node expression = child;
          if (child.isTemplateLitSub()) {
            expression = child.getFirstChild();
          }
          String expressionString = getStringValue(expression);
          if (expressionString == null) {
            // Cannot convert.
            return null;
          }
          string = string + expressionString;
        }
        return string;

      case TEMPLATELIT_STRING:
        return n.getCookedString();

      case NAME:
        String name = n.getString();
        if ("undefined".equals(name)
            || "Infinity".equals(name)
            || "NaN".equals(name)) {
          return name;
        }
        break;

      case NUMBER:
        return DToA.numberToString(n.getDouble());

      case FALSE:
        return "false";

      case TRUE:
        return "true";

      case NULL:
        return "null";

      case VOID:
        return "undefined";

      case NOT:
        TernaryValue child = getPureBooleanValue(n.getFirstChild());
        if (child != TernaryValue.UNKNOWN) {
          return child.toBoolean(true) ? "false" : "true"; // reversed.
        }
        break;

      case ARRAYLIT:
        return arrayToString(n);

      case OBJECTLIT:
        return "[object Object]";
      default:
        break;
    }
    return null;
  }
390046
function (value) {
            var elem = this[0] || {},
                i = 0;
            if (arguments.length > 0) {
                for (; ( elem = this[i] ) != null; i++) {
                    if (elem.nodeType === 1 || elem.nodeType === 11 || elem.nodeType === 9) {
                        // Remove any remaining nodes
                        elem.textContent = value;
                    }
                }
            }

            var node = this[0];
            if ( node.nodeType === 1 || node.nodeType === 9 || node.nodeType === 11 ) {

                // Use textContent for elements
                return node.textContent;
            } else if ( node.nodeType === 3 || node.nodeType === 4 ) {
                return node.nodeValue;
            }
            return '';
        }
1260886
function (node) {
            if (isText(node)) {
                return node.nodeValue.length;
            }

            if (node) {
                return node.childNodes.length;
            }

            return 0;

        }
1251081
public boolean isWhitespace(int nodeHandle)
  {
  	int type = getNodeType(nodeHandle);
    Node node = getNode(nodeHandle);
  	if(TEXT_NODE == type || CDATA_SECTION_NODE == type)
    {
      // If this is a DTM text node, it may be made of multiple DOM text
      // nodes -- including navigating into Entity References. DOM2DTM
      // records the first node in the sequence and requires that we
      // pick up the others when we retrieve the DTM node's value.
      //
      // %REVIEW% DOM Level 3 is expected to add a "whole text"
      // retrieval method which performs this function for us.
      FastStringBuffer buf = StringBufferPool.get();
      while(node!=null)
      {
        buf.append(node.getNodeValue());
        node=logicalNextDOMTextNode(node);
      }
     boolean b = buf.isWhitespace(0, buf.length());
      StringBufferPool.free(buf);
     return b;
    }
    return false;
  }
1240913
protected int getColor(Node node)
	{
		if (!colors.containsKey(node))
		{
			// Absence of color is interpreted as white
			return WHITE;
		}
		else
		{
			return colors.get(node);
		}
	}
912310
private Object getObjectValue(Node node, String fieldName) {
        // we have to take into account the fact that fieldName will be in the lower case
        if (node != null) {
            String name = node.getLocalName();
            switch (node.getNodeType()) {
                case Node.ATTRIBUTE_NODE:
                    return name.equalsIgnoreCase(fieldName) ? node : null;
                case Node.ELEMENT_NODE: {
                    if (name.equalsIgnoreCase(fieldName)) {
                        return new NodeArray(node.getChildNodes());
                    } else {
                        NamedNodeMap namedNodeMap = node.getAttributes();
                        for (int attributeIndex = 0; attributeIndex < namedNodeMap.getLength(); ++attributeIndex) {
                            Node attribute = namedNodeMap.item(attributeIndex);
                            if (attribute.getLocalName().equalsIgnoreCase(fieldName)) {
                                return attribute;
                            }
                        }
                        return null;
                    }
                }
                default:
                    return null;
            }
        }
        return null;
    }
618996
public static <T> T asValue(JsonNode node, Class<T> clazz) {
        return node != null ? ValueUtils.convertValue(node, clazz) : null;
    }
93130
protected function getVNodeValue($node)
    {
        // for cell types having a "v" tag containing the value.
        // if not, the returned value should be empty string.
        $vNode = $node->getElementsByTagName(self::XML_NODE_VALUE)->item(0);
        return ($vNode !== null) ? $vNode->nodeValue : '';
    }
817329
public static String getValue(Element element) {
        if (element != null) {
            Node dataNode = element.getFirstChild();
            if (dataNode != null) {
                return ((Text) dataNode).getData();
            }
        }
        return null;
    }
793650
function (xmlNode) {
            if (!xmlNode) {
                return;
            }
            var node = {};
            for (var i = 0; i < xmlNode.childNodes.length; i++) {
                var currNode = xmlNode.childNodes[i];

                // if it's a text node or a CDATA section use the nodeValue directly
                if (currNode.nodeType != 3 && currNode.nodeType != 4) {
                    var name = currNode.nodeName;
                    var count = 0;
                    for (var j = 0; j < xmlNode.childNodes.length; j++) {
                        if (xmlNode.childNodes[j].nodeName == name) {
                            if (++count == 2) {
                                break;
                            }
                        }
                    }
                    var el = this.__parseXmlNode(currNode);
                    if (count == 2) {
                        if (node[name] == null) {
                            node[name] = [];
                        }
                        node[name].push(el);
                    } else {
                        node[name] = el;
                    }

                } else if (xmlNode.childNodes.length == 1) {
                    node = currNode.nodeValue;
                }
            }
            return node;
        }