Get the first node of the MathML-Content annotations within a MathML document.

@param mathml full MathML document
@return first node of the MathML-Content annotations within a MathML document
503043
public static Node getFirstNode(String mathml) {
        try {
            // get the apply node of the ContentMathML root
            return getFirstNode(new CMMLInfo(mathml));
        } catch (Exception e) {
            logger.error("failed to get apply node", e);
            return null;
        }
    }
708244
public T removeFirst() {
        if ( this.firstNode == null ) {
            return null;
        }
        final T node = this.firstNode;
        this.firstNode = node.getNext();
        node.setNext( null );
        if ( this.firstNode != null ) {
            this.firstNode.setPrevious( null );
        } else {
            this.lastNode = null;
        }
        this.size--;
        return node;
    }
1356249
private int readXMLComment(final Line firstLine, final int start)
    {
        Line line = firstLine;
        if (start + 3 < line.value.length())
        {
            if (line.value.charAt(2) == '-' && line.value.charAt(3) == '-')
            {
                int pos = start + 4;
                while (line != null)
                {
                    while (pos < line.value.length() && line.value.charAt(pos) != '-')
                    {
                        pos++;
                    }
                    if (pos == line.value.length())
                    {
                        line = line.next;
                        pos = 0;
                    }
                    else
                    {
                        if (pos + 2 < line.value.length())
                        {
                            if (line.value.charAt(pos + 1) == '-' && line.value.charAt(pos + 2) == '>')
                            {
                                this.xmlEndLine = line;
                                return pos + 3;
                            }
                        }
                        pos++;
                    }
                }
            }
        }
        return -1;
    }
620755
@SuppressWarnings("rawtypes")
    private Map.Entry getMapEntry(Node node) {
        Object value = null;
        String keyName = node.getLocalName();
        XmlMapEntry xmlMapEntry = this.mapSpecification.get(keyName);
        switch (node.getNodeType()) {
            case Node.ATTRIBUTE_NODE:
                value = node.getNodeValue();
                break;
            case Node.ELEMENT_NODE: {
                if (xmlMapEntry == null) {
                    value = new NodeArray(node.getChildNodes());
                } else {
                    XmlMapFacet valueFacet = xmlMapEntry.getValue();
                    switch (valueFacet.getType()) {
                        case ELEMENT:
                            value = keyName;
                            break;
                        case CONTENT: {
                            NodeList nodeList = node.getChildNodes();
                            if (nodeList.getLength() > 0) {
                                value = new NodeArray(nodeList);
                            }
                        }
                            break;
                        case ATTRIBUTE: {
                            NamedNodeMap attributes = node.getAttributes();
                            Node attribute = attributes.getNamedItem(valueFacet.getName());
                            if (attribute != null) {
                                value = attribute.getNodeValue();
                            }
                        }
                            break;
                        default:
                            throw new IllegalStateException();
                    }
                    XmlMapFacet keyFacet = xmlMapEntry.getKey();
                    switch (keyFacet.getType()) {
                        case ELEMENT:
                            break;
                        case CONTENT: {
                            NodeList nodeList = node.getChildNodes();
                            if (nodeList.getLength() > 0) {
                                keyName = getStringValue((Node) nodeList.item(0));
                            } else {
                                keyName = null;
                            }
                        }
                            break;
                        case ATTRIBUTE: {
                            NamedNodeMap attributes = node.getAttributes();
                            Node attribute = attributes.getNamedItem(keyFacet.getName());
                            if (attribute != null) {
                                keyName = attribute.getNodeValue();
                            } else {
                                keyName = null;
                            }
                            break;
                        }
                        default:
                            throw new IllegalStateException();
                    }
                }
            }
        }
        if (keyName == null) {
            return null;
        } else {
            final Object _key = keyName;
            final Object _value = value;
            return new Map.Entry() {

                @Override
                public Object getKey() {
                    return _key;
                }

                @Override
                public Object getValue() {
                    return _value;
                }

                @Override
                public Object setValue(Object object) {
                    return null;
                }

            };
        }
    }
930530
@SuppressWarnings("JavaDoc")
    public static Multiset<String> getIdentifiersFrom(String mathml) {
        Multiset<String> list = HashMultiset.create();
        Pattern p = Pattern.compile("<((m:)?[mc][ion])(.*?)>(.{1,4}?)</\\1>", Pattern.DOTALL);
        Matcher m = p.matcher(mathml);
        while (m.find()) {
            String identifier = m.group(4);
            list.add(identifier);
        }
        return list;
    }
1191684
public Node getDOM()
    {
        Object root = m_message.getRawData();
        try {
            String strSOAPPackage = (String)((TrxMessageHeader)this.getMessage().getMessageHeader()).get(SOAPMessageTransport.SOAP_PACKAGE);

            Node node = null;            
            DocumentBuilder db = Util.getDocumentBuilder();
            Document doc = db.newDocument();            
            
            Marshaller m = JaxbContexts.getJAXBContexts().getMarshaller(strSOAPPackage);
            if (m == null)
                return null;
            synchronized(m)
            {   // Since the marshaller is shared (may want to tweek this for multi-cpu implementations)
                m.marshal( root, doc );
            }
            node = doc.getDocumentElement();

            if (node != null)
                return node;
        } catch (JAXBException ex)   {
            ex.printStackTrace();
        } catch (java.lang.IllegalArgumentException ex)   {
            ex.printStackTrace();
        }
        return super.getDOM();
    }
150134
private String getNodeValue(Node node) {
        if (node.getNodeType() == Node.ELEMENT_NODE && node.getFirstChild() != null) {
            return node.getFirstChild().getNodeValue();
        } else {
            return node.getNodeValue();
        }
    }
273406
public static int findFirstNonAnnotationLine(ASTNode node, SourceCode sourceCode) {
        if (node instanceof AnnotatedNode && !((AnnotatedNode) node).getAnnotations().isEmpty()) {

            // HACK: Groovy line numbers are broken when annotations have a parameter :(
            // so we must look at the lineNumber, not the lastLineNumber
            AnnotationNode lastAnnotation = null;
            for (AnnotationNode annotation : ((AnnotatedNode) node).getAnnotations()) {
                if (lastAnnotation == null) lastAnnotation = annotation;
                else if (lastAnnotation.getLineNumber() < annotation.getLineNumber()) lastAnnotation = annotation;
            }

            String rawLine = getRawLine(sourceCode, lastAnnotation.getLastLineNumber()-1);

            if(rawLine == null) {
                return node.getLineNumber();
            }

            // is the annotation the last thing on the line?
            if (rawLine.length() > lastAnnotation.getLastColumnNumber()) {
                // no it is not
                return lastAnnotation.getLastLineNumber();
            }
            // yes it is the last thing, return the next thing
            return lastAnnotation.getLastLineNumber() + 1;
        }
        return node.getLineNumber();
    }
953714
public Node getNamedItem(String name)
  {

    for (int n = dtm.getFirstAttribute(element); n != DTM.NULL;
            n = dtm.getNextAttribute(n))
    {
      if (dtm.getNodeName(n).equals(name))
        return dtm.getNode(n);
    }

    return null;
  }
1312625
static public String getRootNodeName(String xml)
    {
        String rootNodeName = null;
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setExpandEntityReferences(false);
            DocumentBuilder dBuilder = dbf.newDocumentBuilder();
            InputSource inputSource = new InputSource(new StringReader(xml));
            Document doc = dBuilder.parse(inputSource);
            doc.getDocumentElement().normalize();
            rootNodeName = doc.getDocumentElement().getNodeName();
        } catch (SAXException e) {
            System.out.println("SAX exception: " + e);
        } catch (IOException e) {
            System.out.println("IO exception: " + e);
        } catch (ParserConfigurationException e) {
            System.out.println("ParserConfiguration exception: " + e);
        }
        return rootNodeName;
    }
820451
public static MathNode generateMathNode(Node applyRoot) {
        Objects.requireNonNull(applyRoot, "apply element is missing");

        MathNode mathNode = createMathNode(applyRoot, 0);
        // compute the maximum depth at least once after creation to define it for each branch.
        if (mathNode != null) {
            mathNode.getMaxDepth();
        }
        return mathNode;
    }
964966
public static XdmNode getParamsFromLog(
            net.sf.saxon.s9api.DocumentBuilder builder, Document log)
            throws Exception {
        Element starttest = (Element) log.getElementsByTagName("starttest")
                .item(0);
        NodeList nl = starttest.getElementsByTagName("params");
        if (nl == null || nl.getLength() == 0) {
            return null;
        } else {
            Document doc = DomUtils.createDocument(nl.item(0));
            return builder.build(new DOMSource(doc));
        }
    }
1007220
private Node getNode(Node nodeStart, String key, CreateMode createMode, boolean bReturnTextNode)
    {
        if (key.indexOf('/') != -1)
        {
            String strKeyParent = key.substring(0, key.indexOf('/'));
            CreateMode createModeParent = createMode;
            if (createModeParent == CreateMode.CREATE_NEW_NODE)
                createModeParent = CreateMode.CREATE_IF_NOT_FOUND;  // Only create a duplicate node at the leaf level.
            nodeStart = this.getNode(nodeStart, strKeyParent, createModeParent, false);
            if (nodeStart == null)
                return null;
            key = key.substring(key.indexOf('/') + 1);
            return this.getNode(nodeStart, key, createMode, bReturnTextNode);
        }
        if (nodeStart == null)
            nodeStart = this.getNode(true);

        int iIndex = Integer.MAX_VALUE;
        if (key.indexOf('[') != -1)
        {
            iIndex = Integer.parseInt(key.substring(key.indexOf('[') + 1, key.indexOf(']')));
            key = key.substring(0, key.indexOf('['));
        }
        key = Util.fixDOMElementName(key);
        Node node = null;
        NodeList nodeList = ((Element)nodeStart).getElementsByTagName(key);
        if (nodeList != null)
        {
            for (int i = 0; i < nodeList.getLength(); i++)
            {
                if (nodeList.item(i).getParentNode() == nodeStart)
                {
                    node = nodeList.item(i);    // Get the last child.
                    if (iIndex != Integer.MAX_VALUE)
                    {
                        if (--iIndex == 0)
                            break;  // This is the correct node
                        node = null;    // If you are looking for a specific node, and it doesn't exist, return null.
                    }
                }
            }
        }
        if (((node == null) && (createMode != CreateMode.DONT_CREATE))
                || (createMode == CreateMode.CREATE_NEW_NODE))
        {
        	Document doc = null;
        	if (m_data instanceof Document)
        		doc = (Document)m_data;
        	if (doc == null)
        		doc = ((Node)m_data).getOwnerDocument();
            node = doc.createElement(key);
            if (bReturnTextNode)
            {
                if (createMode != CreateMode.CREATE_CDATA_NODE)
                    node.appendChild(doc.createTextNode(Constant.BLANK));
                else
                    node.appendChild(doc.createCDATASection(Constant.BLANK));
            }
            nodeStart.appendChild(node);
        }
        if (node != null)
            if (bReturnTextNode)
                node = node.getFirstChild();
        return node;    // Return new node or null.
    }
527213
private int _readXMLComment (final Line firstLine, final int start)
  {
    Line line = firstLine;
    if (start + 3 < line.m_sValue.length ())
    {
      if (line.m_sValue.charAt (2) == '-' && line.m_sValue.charAt (3) == '-')
      {
        int pos = start + 4;
        while (line != null)
        {
          while (pos < line.m_sValue.length () && line.m_sValue.charAt (pos) != '-')
          {
            pos++;
          }
          if (pos == line.m_sValue.length ())
          {
            line = line.m_aNext;
            pos = 0;
          }
          else
          {
            if (pos + 2 < line.m_sValue.length ())
            {
              if (line.m_sValue.charAt (pos + 1) == '-' && line.m_sValue.charAt (pos + 2) == '>')
              {
                m_aXmlEndLine = line;
                return pos + 3;
              }
            }
            pos++;
          }
        }
      }
    }
    return -1;
  }
142057
public N getPartitionSuperNode(N node) {
    checkNotNull(colorToNodeMap, "No coloring founded. color() should be called first.");
    Color color = graph.getNode(node).getAnnotation();
    N headNode = colorToNodeMap[color.value];
    if (headNode == null) {
      colorToNodeMap[color.value] = node;
      return node;
    } else {
      return headNode;
    }
  }
627439
public XMLString getStringValue(int nodeHandle)
  {

    int type = getNodeType(nodeHandle);
    Node node = getNode(nodeHandle);
    // %TBD% If an element only has one text node, we should just use it 
    // directly.
    if(DTM.ELEMENT_NODE == type || DTM.DOCUMENT_NODE == type 
    || DTM.DOCUMENT_FRAGMENT_NODE == type)
    {
      FastStringBuffer buf = StringBufferPool.get();
      String s;
  
      try
      {
        getNodeData(node, buf);
  
        s = (buf.length() > 0) ? buf.toString() : "";
      }
      finally
      {
        StringBufferPool.free(buf);
      }
  
      return m_xstrf.newstr( s );
    }
    else 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);
      }
      String s=(buf.length() > 0) ? buf.toString() : "";
      StringBufferPool.free(buf);
      return m_xstrf.newstr( s );
    }
    else
      return m_xstrf.newstr( node.getNodeValue() );
  }
717847
LimitPlanNode limitPlanNodeFromXml(VoltXMLElement limitXml, VoltXMLElement offsetXml) {

        if (limitXml == null && offsetXml == null) {
            return null;
        }

        String node;
        long limitParameterId = -1;
        long offsetParameterId = -1;
        long limit = -1;
        long offset = 0;
        if (limitXml != null) {
            // Parse limit
            if ((node = limitXml.attributes.get("limit_paramid")) != null) {
                limitParameterId = Long.parseLong(node);
            }
            else {
                assert(limitXml.children.size() == 1);
                VoltXMLElement valueNode = limitXml.children.get(0);
                String isParam = valueNode.attributes.get("isparam");
                if ((isParam != null) && (isParam.equalsIgnoreCase("true"))) {
                    limitParameterId = Long.parseLong(valueNode.attributes.get("id"));
                }
                else {
                    node = limitXml.attributes.get("limit");
                    assert(node != null);
                    limit = Long.parseLong(node);
                }
            }
        }
        if (offsetXml != null) {
            // Parse offset
            if ((node = offsetXml.attributes.get("offset_paramid")) != null) {
                offsetParameterId = Long.parseLong(node);
            }
            else {
                if (offsetXml.children.size() == 1) {
                    VoltXMLElement valueNode = offsetXml.children.get(0);
                    String isParam = valueNode.attributes.get("isparam");
                    if ((isParam != null) && (isParam.equalsIgnoreCase("true"))) {
                        offsetParameterId = Long.parseLong(valueNode.attributes.get("id"));
                    }
                    else {
                        node = offsetXml.attributes.get("offset");
                        assert(node != null);
                        offset = Long.parseLong(node);
                    }
                }
            }
        }

        // limit and offset can't have both value and parameter
        if (limit != -1) assert limitParameterId == -1 : "Parsed value and param. limit.";
        if (offset != 0) assert offsetParameterId == -1 : "Parsed value and param. offset.";

        LimitPlanNode limitPlanNode = new LimitPlanNode();
        limitPlanNode.setLimit((int) limit);
        limitPlanNode.setOffset((int) offset);
        limitPlanNode.setLimitParameterIndex(parameterCountIndexById(limitParameterId));
        limitPlanNode.setOffsetParameterIndex(parameterCountIndexById(offsetParameterId));
        return limitPlanNode;
    }