Package com.google.gwt.xml.client

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


  if (nodes == null || (length = nodes.getLength()) == 0) {
      return EMPTY_LIST;
  }
  final ArrayList<IPacket> selected = new ArrayList<IPacket>();
  for (int index = 0; index < length; index++) {
      final Node node = nodes.item(index);
      if (node.getNodeType() == Node.ELEMENT_NODE) {
    selected.add(new GWTPacket((Element) node));
      } else if (node.getNodeType() == Node.TEXT_NODE) {
      }
  }
  return selected;
    }
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

   
    Document response = XMLParser.parse(serviceDataXmlString);
   
    NodeList namespaces = response.getElementsByTagName("namespace");   
    for (int i = 0; i < namespaces.getLength(); i++) {
      Node namespace = namespaces.item(i);
      if (namespace.hasChildNodes()) {
        String namespaceString = namespace.getFirstChild().getNodeValue();
        if ((!otherNamespaces.contains(namespaceString)) &&
            (!namespaceString.equals(WadlXml.xmlns_xsd)) &&
            (!namespaceString.equals(WadlXml.xmlns_xsi))) {
          otherNamespaces.add(namespaceString);
        }
      }
    }
   
    NodeList requests = response.getElementsByTagName("requestData");   
    for (int i = 0; i < requests.getLength(); i++) {
      Node request = requests.item(i);           
      NodeList requestChildren = request.getChildNodes();     
      for (int j = 0; j < requestChildren.getLength(); j++) {
        Node requestChild = requestChildren.item(j);
        if (requestChild.getNodeName().equals("validRequest")) {         
          treatValidRequests(requestChild);
        }
        else if (requestChild.getNodeName().equals("erroneousRequests")) {
          treatErroneousRequests(requestChild);
        }
      }     
    }   
    show();   
View Full Code Here

   * @param validRequest
   */
  private static void treatValidRequests(Node validRequest) {   
    NodeList children = validRequest.getChildNodes();
    for(int i = 0; i < children.getLength(); i++) {
      Node node = children.item(i);
      if (node.getNodeType() != Node.ELEMENT_NODE) {
        continue;
      }
      if (node.getNodeName().equals("schemaLocation")) {       
        if (node.hasChildNodes() &&           
            !schemaLocations.contains(node.getFirstChild().getNodeValue())) {
          schemaLocations.add(node.getFirstChild().getNodeValue());         
        }   
      }
      else if (node.getNodeName().equals("defaultNamespace")) {       
        if (node.hasChildNodes() &&
            !defaultNamespace.contains(node.getFirstChild().getNodeValue())) {
          defaultNamespace.add(node.getFirstChild().getNodeValue());         
        }   
      }
    }   
  }
View Full Code Here

   * @param erroneousRequests
   */
  private static void treatErroneousRequests(Node erroneousRequestChildren) {   
    NodeList erroneousRequests = erroneousRequestChildren.getChildNodes();   
    for (int i = 0; i < erroneousRequests.getLength(); i++) {     
      Node erroneousRequest = erroneousRequests.item(i);
      if (erroneousRequest.getNodeType() != Node.ELEMENT_NODE) {
        continue;     
      }
      String status = erroneousRequest.getAttributes().getNamedItem("status").getNodeValue();     
      if (!errorStatuses.contains(status) && (!status.equals("200"))) {       
        errorStatuses.add(status);       
      }   
      NodeList children = erroneousRequest.getChildNodes();
      for(int j = 0; j < children.getLength(); j++) {
        Node node = children.item(j);       
        if (node.getNodeType() != Node.ELEMENT_NODE) {
          continue;
        }
        if (node.getNodeName().equals("schemaLocation")) {         
          if (node.hasChildNodes() &&
              !schemaLocations.contains(node.getFirstChild().getNodeValue())) {           
            schemaLocations.add(node.getFirstChild().getNodeValue());         
          }   
        }
        else if (node.getNodeName().equals("defaultNamespace")) {         
          if (node.hasChildNodes() &&
              !defaultNamespace.contains(node.getFirstChild().getNodeValue())) {
            defaultNamespace.add(node.getFirstChild().getNodeValue());         
          }   
        }
      }           
    }   
  }
View Full Code Here

   */
  private boolean startParsing(Document wadl) {
    // the first node must be an application node with namespace attributes
    NodeList wadlChildren = wadl.getChildNodes();
    for (int i = 0; i < wadlChildren.getLength(); i++) {
      Node wadlChild = wadlChildren.item(i);
      if (wadlChild.getNodeType() == ELEMENT_NODE) {
        applicationElement = wadlChild;
        break;
      }
    }
    if (applicationElement.getNodeName().equals(WadlXml.applicationNode)) {       
      // allowed children are only doc, grammars, resources, resource_type, method, representation, param, fault     
      if (containsOnlyAllowedChildren(applicationElement, WadlXml.applicationChildren)) {
        if ((applicationElement.getAttributes().getNamedItem(WadlXml.application_xmlns) != null) &&
            (applicationElement.getAttributes().getNamedItem(WadlXml.application_xmlns_xsd) != null) &&
            (applicationElement.getAttributes().getNamedItem(WadlXml.application_xmlns_xsi) != null) &&
            (applicationElement.getAttributes().getNamedItem(WadlXml.application_xsi_schemaLocation) != null)) {
          Analyzer analyzer = new Analyzer("");       
          application = new ApplicationNode(analyzer);       
          analyzer.setApplication(application);
         
          NamedNodeMap attributes = applicationElement.getAttributes();
          for (int i = 0; i < attributes.getLength(); i++) {
            Node attribute = attributes.item(i);
            if ((attribute.getNodeName().equals(WadlXml.application_xmlns)) ||
                (attribute.getNodeName().equals(WadlXml.application_xmlns_xsd)) ||
                (attribute.getNodeName().equals(WadlXml.application_xmlns_xsi)) ||
                (attribute.getNodeName().equals(WadlXml.application_xsi_schemaLocation))) {
              continue;
            }
            NamespaceAttribute namespace = new NamespaceAttribute(attribute.getNodeName(), attribute.getNodeValue());
            application.addNamespace(namespace);           
          }
         
          // applicationChildren = {resourcesNode, grammarsNode, resourceTypeNode, methodNode, representationNode, faultNode, docNode}
          NodeList applicationChildren = applicationElement.getChildNodes();
View Full Code Here

   * @param parentNode
   * @return
   */
  private boolean parseDocNode(Node docElement, GenericNode parentNode) {   
    if (containsOnlyAllowedAttributes(docElement, WadlXml.docAttributes)) {     
      Node langNode = docElement.getAttributes().getNamedItem(WadlXml.doc_xml_lang);
      String lang = "";
      if (langNode != null) {
        lang = encodeDangerousContents(langNode.getNodeValue());
      }
      else {
        lang = "en";
      }
     
      Node titleNode = docElement.getAttributes().getNamedItem(WadlXml.doc_title);
      String title = "";
      if (titleNode != null) {       
        title = encodeDangerousContents(titleNode.getNodeValue());
      }
           
      String text = "";     
      if (docElement.getFirstChild() != null) {       
        text = docElement.getChildNodes().toString();
View Full Code Here

   * @return
   */
  private boolean parseResourceTypeNode(Node resourceTypeElement, ApplicationNode application) {
    if (containsOnlyAllowedChildren(resourceTypeElement, WadlXml.resource_typeChildren)) {
      if  (containsOnlyAllowedAttributes(resourceTypeElement, WadlXml.resource_typeAttributes)) {
        Node idNode = resourceTypeElement.getAttributes().getNamedItem(WadlXml.resource_type_id);
        String id = "";
        if (idNode != null) {
          id = idNode.getNodeValue();
        }
        ResourceTypeNode resourceType = new ResourceTypeNode(id, application);
        application.addResourceType(resourceType);       
       
        // resource_typeChildren = {paramNode, methodNode, docNode}
View Full Code Here

   *
   */
  private boolean parseResourcesNode(Node resourcesElement, ApplicationNode application) {
    if (containsOnlyAllowedChildren(resourcesElement, WadlXml.resourcesChildren)) {
      if  (containsOnlyAllowedAttributes(resourcesElement, WadlXml.resourcesAttributes)) {
        Node baseNode = resourcesElement.getAttributes().getNamedItem(WadlXml.resources_base);
        String base = "";
        if (baseNode != null) {
          base = baseNode.getNodeValue();
        }
        ResourcesNode resources = new ResourcesNode(base, application);
        application.addResources(resources);
       
        // resourcesChildren = {resourceNode, docNode}
View Full Code Here

   * @param isReferenced
   */
  private boolean parseResourceNode(Node resourceElement, Object parentNode, boolean isReferenced) {       
    if (containsOnlyAllowedChildren(resourceElement, WadlXml.resourceChildren)) {
      if (containsOnlyAllowedAttributes(resourceElement, WadlXml.resourceAttributes)) {       
        Node hrefNode = resourceElement.getAttributes().getNamedItem(WadlXml.resource_href);
        if (hrefNode != null) {         
          getElementByIdThenParse(applicationElement, hrefNode.getNodeValue(), parentNode);
        }
        else {       
          Node pathAttribute = resourceElement.getAttributes().getNamedItem(WadlXml.resource_path);
          if (pathAttribute != null) {
            ResourceNode resource = null;
            if (!isReferenced) { 
              resource = new ResourceNode(pathAttribute.getNodeValue(), (GenericNode) parentNode, ((GenericNode) parentNode).getApplication());                           
             
              // resourceChildren = {paramNode, methodNode, resourceNode, docNode}
              NodeList childNodes = resourceElement.getChildNodes();
              for (int i = 0; i < childNodes.getLength(); i++) {           
                if (childNodes.item(i).getNodeName().equals(WadlXml.paramNode)) {
                  if (!parseParamNode(childNodes.item(i), resource, false)) {
                    return false;
                  }
                }
                else if (childNodes.item(i).getNodeName().equals(WadlXml.methodNode)) {
                  if (!parseMethodNode(childNodes.item(i), resource, false)) {
                    return false;
                  }
                }
                else if (childNodes.item(i).getNodeName().equals(WadlXml.resourceNode)) {                 
                  if (!parseResourceNode(childNodes.item(i), resource, false)) {
                    return false;
                  }
                }
                else if (childNodes.item(i).getNodeName().equals(WadlXml.docNode)) {
                  if (!parseDocNode(childNodes.item(i), resource)) {
                    return false;
                  }               
                }
              }
              Node idNode = resourceElement.getAttributes().getNamedItem(WadlXml.resource_id);
              if (idNode != null) {
                resource.setId(idNode.getNodeValue());
              }
            }
            else {
              Node idNode = resourceElement.getAttributes().getNamedItem(WadlXml.resource_id);
              resource = new ResourceNode(idNode.getNodeValue(), true, (GenericNode) parentNode, ((GenericNode) parentNode).getApplication());
            }
            // attach to parent
            if (parentNode instanceof ResourcesNode) {
              ((ResourcesNode) parentNode).addResource(resource);
            }
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.