Package com.google.gwt.xml.client

Examples of com.google.gwt.xml.client.Node


  {
    List<Node> result = new ArrayList<Node>();

    for(int i=0; i<childNodes.getLength(); i++)
    {
      Node n = childNodes.item(i);
      if(n.getNodeType()!=Node.ELEMENT_NODE) // skip #text
        continue;
      else
        result.add(n);
    }
    return result;
View Full Code Here


    Document doc = XMLParser.parse((String) data);

    NodeList list = doc.getElementsByTagName(modelType.getRecordName());
    ArrayList<ModelData> records = new ArrayList<ModelData>();
    for (int i = 0; i < list.getLength(); i++) {
      Node node = list.item(i);
      Element elem = (Element) node;
      ModelData model = newModelInstance();
      for (int j = 0; j < modelType.getFieldCount(); j++) {
        DataField field = modelType.getField(j);
        Class type = field.getType();
        String name = field.getName();
        String map = field.getMap() != null ? field.getMap() : field.getName();
        String v = getValue(elem, map);
        if (v == null) continue;
        if (type != null) {
          if (type.equals(Boolean.class)) {
            model.set(name, Boolean.parseBoolean(v));
          } else if (type.equals(Integer.class)) {
            model.set(name, Integer.parseInt(v));
          } else if (type.equals(Long.class)) {
            model.set(name, Long.parseLong(v));
          } else if (type.equals(Float.class)) {
            model.set(name, Float.parseFloat(v));
          } else if (type.equals(Double.class)) {
            model.set(name, Double.parseDouble(v));
          } else if (type.equals(Date.class)) {
            if ("timestamp".equals(field.getFormat())) {
              Date d = new Date(Long.parseLong(v) * 1000);
              model.set(name, d);
            } else {
              DateTimeFormat format = DateTimeFormat.getFormat(field.getFormat());
              Date d = format.parse(v);
              model.set(name, d);
            }
          }
        } else {
          model.set(field.getName(), v);
        }

      }
      records.add(model);
    }

    int totalCount = records.size();
    Node root = doc.getElementsByTagName(modelType.getRoot()).item(0);
    if (root != null && modelType.getTotalName() != null) {
      String tot = getValue((Element) root, modelType.getTotalName());
      if (tot != null) {
        totalCount = Integer.parseInt(tot);
      }
View Full Code Here

    public static Node getFirstChildElement(Node parent) {
        NodeList children = parent.getChildNodes();

        for(int i=0; i<children.getLength(); i++)
        {
            Node child = children.item(i);
            if(child.getNodeType() == Node.ELEMENT_NODE)
                return child;
        }

        return null;
    }
View Full Code Here

    @Override
    public DMRMapping fromXML(Node node) {

        DMRMapping mapping = new DMRMapping();
        Node address = node.getAttributes().getNamedItem("address");
        if(address !=null)
        {
            mapping.setAddress(address.getNodeValue());
        }

        NodeList children = node.getChildNodes();
        List<String> attributes = new LinkedList<String>();
        List<String> objects = new LinkedList<String>();
        for(int i=0; i<children.getLength(); i++)
        {
            Node child = children.item(i);
            if(!( Node.ELEMENT_NODE == child.getNodeType()))
                continue;

            if(child.getNodeName().equals("attribute"))
            {
                attributes.add(child.getAttributes().getNamedItem("name").getNodeValue());
            }
            else if(child.getNodeName().equals("object"))
            {
                objects.add(child.getAttributes().getNamedItem("name").getNodeValue());
            }
        }
        mapping.addAttributes(attributes);
        mapping.addObjects(objects);
        return mapping;
View Full Code Here

            NodeList children = root.getChildNodes();

            for(int i=0; i<children.getLength(); i++)
            {

                Node child = children.item(i);

                // skip anything except elements
                if(! (Node.ELEMENT_NODE == child.getNodeType()))
                    continue;

                if(child.hasChildNodes())
                {
                    dfsElement(builder, child);
                }
                else
                {
                    ElementAdapter childAdapter = getAdapter(child.getNodeName());
                    if(DMRMapping.class==childAdapter.getType())
                        builder.mappedBy((DMRMapping)childAdapter.fromXML(child));
                    else if(InteractionUnit.class==childAdapter.getType())
                        builder.add((InteractionUnit)childAdapter.fromXML(child));
                }
View Full Code Here

        }

        @Override
        public void endVisit(Container container) {
            if(stack.size()>1){
                Node el = stack.pop();
                stack.peek().appendChild(el);
            }
            else if(stack.size()==1)
            {
                Node root = stack.pop();

                Element dialogEl = DOMUtils.createElementNS(document, dialog.getId().getNamespaceURI(), "dialog");
                dialogEl.setAttribute("id", dialog.getId().getLocalPart());
                dialogEl.appendChild(root);
                document.appendChild(dialogEl);
View Full Code Here

    Document doc = XMLParser.parse((String) data);

    NodeList list = doc.getElementsByTagName(modelType.recordName);
    ArrayList<ModelData> records = new ArrayList<ModelData>();
    for (int i = 0; i < list.getLength(); i++) {
      Node node = list.item(i);
      Element elem = (Element) node;
      ModelData model = newModelInstance();
      for (int j = 0; j < modelType.getFieldCount(); j++) {
        DataField field = modelType.getField(j);
        String map = field.map != null ? field.map : field.name;
        String v = getValue(elem, map);
        model.set(field.name, v);
      }
      records.add(model);
    }

    int totalCount = records.size();

    Node root = doc.getElementsByTagName(modelType.root).item(0);
    if (root != null && modelType.totalName != null) {
      Node totalNode = root.getAttributes().getNamedItem(modelType.totalName);
      if (totalNode != null) {
        String sTot = totalNode.getNodeValue();
        totalCount = Integer.parseInt(sTot);
      }
    }
    ListLoadResult result = newLoadResult(loadConfig, records);
    if (result instanceof PagingLoadResult) {
View Full Code Here

  public static String getXmlNodeValue(NodeList list, String tagName, int idx) {
    if (list == null || list.getLength() <= idx) {
      return null;
    }
    Node node = list.item(idx);
    if (node.getNodeType() != Node.ELEMENT_NODE) {
      return null;
    }
    String ret = "";
    NodeList textNodes = node.getChildNodes();
    for (int i = 0; i < textNodes.getLength(); i++) {
      Node n = textNodes.item(i);
      if (n.getNodeType() == Node.TEXT_NODE && n.getNodeValue().replaceAll("[ \\n\\t\\r]", "").length() > 0) {
        ret += n.getNodeValue();
      } else if (n.getNodeType() == Node.CDATA_SECTION_NODE) {
        ret += n.getNodeValue();
      }
    return getXmlNodeValue(list.item(0));
    }
    return ret.length() == 0 ? null : ret.replaceAll("^\\s+", "").replaceAll("\\s+$", "");
  }
View Full Code Here

        return null;
      }
      String ret = "";
      NodeList textNodes = node.getChildNodes();
      for (int i = 0; i < textNodes.getLength(); i++) {
        Node n = textNodes.item(i);
        if (n.getNodeType() == Node.TEXT_NODE && n.getNodeValue().replaceAll("[ \\n\\t\\r]", "").length() > 0) {
          ret += n.getNodeValue();
        } else if (n.getNodeType() == Node.CDATA_SECTION_NODE) {
          ret += n.getNodeValue();
        }
      }
      return ret.length() == 0 ? null : ret.replaceAll("^\\s+", "").replaceAll("\\s+$", "");
  }
View Full Code Here

        processNodes(doc.getChildNodes());
    }

    private void processNodes(NodeList node) throws ParseException {
        for (int i = 0; i < node.getLength(); i++) {
            Node nd = node.item(i);
            switch (nd.getNodeType()) {
                case Node.ELEMENT_NODE:
                    HashMap<String, String> attr = new HashMap<String, String>();
                    NamedNodeMap nnm = nd.getAttributes();
                    for (int j = 0; j < nnm.getLength(); j++) {
                        Node nm = nnm.item(j);
                        attr.put(nm.getNodeName(), nm.getNodeValue());
                    }
                    handler.onNodeStart(nd.getNodeName(), attr, nd.getNamespaceURI());
                    processNodes(nd.getChildNodes());
                    handler.onNodeEnd(nd.getNodeName());
                    break;
View Full Code Here

TOP

Related Classes of com.google.gwt.xml.client.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.