public static ArrayList<String> getUsedFqnFromHits(String xmlResultInString) {
    ArrayList<String> usedFqns = new ArrayList<String>();

    Document doc = XMLParser.parse(xmlResultInString);
    NodeList _arrs = doc.getElementsByTagName("arr");

    for (int i = 0; i < _arrs.getLength(); i++) {
      Node _arr = _arrs.item(i);
      NamedNodeMap _nnm = _arr.getAttributes();
      if (_nnm != null) {
        Node _nameNode = _nnm.getNamedItem("name");
        if (_nameNode != null) {
          String _nodeType = _nameNode.getNodeValue();
          if (_nodeType.equals("lib_use_fqn_full")
              || _nodeType.equals("jdk_use_fqn_full")
              || _nodeType.equals("local_use_fqn_full")) {
            NodeList _fqns = _arr.getChildNodes();
            for (int j = 0; j < _fqns.getLength(); j++) {
              Node _fqn = _fqns.item(j);
              if (_fqn.getNodeName().equals("str")) {
                String _usedFqn = _fqn.getFirstChild().getNodeValue();
                usedFqns.add(_usedFqn);
              }
            }
          }
        }
      }
    }
    return usedFqns;
  }
  public static ArrayList<String> getHitEidsFromHits(String xmlResultInString) {
    ArrayList<String> _hitEids = new ArrayList<String>();
    Document doc = XMLParser.parse(xmlResultInString);
    NodeList hits = doc.getElementsByTagName("doc");

    for (int i = 0; i < hits.getLength(); i++) {
      Node hit = hits.item(i);

      NodeList hitDocChildNodes = hit.getChildNodes();

      String entity_id = "";

      for (int j = 0; j < hitDocChildNodes.getLength(); j++) {
        Node hitDocChildNode = hitDocChildNodes.item(j);

        NamedNodeMap attrs = hitDocChildNode.getAttributes();
        Node _attributeNode = null;
        _attributeNode = attrs.getNamedItem("name");

        if (_attributeNode != null) {
          if (_attributeNode.getNodeValue().equals("entity_id")) {
            entity_id = hitDocChildNode.getFirstChild().getNodeValue();
          }
        }
      }

      _hitEids.add(entity_id);
    }

    return _hitEids;
  }
示例#3
0
 private Element getXMLDoc() {
   Document d = XMLParser.createDocument();
   Element root = d.createElement("PedEx");
   PelicanPerson[] people = getAllPeople();
   for (int i = 0; i < people.length; i++) {
     root.appendChild(people[i].save());
   }
   return root;
 }
示例#4
0
  /**
   * Converts a form definition object to XHTML.
   *
   * @param formDef the form definition object.
   * @return the xhtml.
   */
  public static String fromFormDef2Xhtml(FormDef formDef) {
    Document doc = fromFormDef2XhtmlDoc(formDef);
    formDef.setDoc(doc);
    formDef.setXformsNode(doc.getDocumentElement());

    if (FormUtil.isJavaRosaSaveFormat()) ItextBuilder.build(formDef);

    return XmlUtil.fromDoc2String(doc);
  }
示例#5
0
        public void onResponseReceived(Request request, Response response) {
          String text = response.getText();
          String url = null;
          Document document = null;

          String bpath = "<" + TAG_BLOBSTORE_PATH + ">";
          String sbpath = "</" + TAG_BLOBSTORE_PATH + ">";
          if (text.contains(bpath)) {
            try {
              document = XMLParser.parse(text);
              url = Utils.getXmlNodeValue(document, TAG_BLOBSTORE_PATH);
            } catch (Exception e) {
              cancelUpload(
                  i18nStrs.uploaderBlobstoreError() + "\n>>>\n" + e.getMessage() + "\n>>>>\n" + e);
              return;
            }
            if (url == null) {
              url =
                  text.replaceAll("[\r\n]+", "")
                      .replaceAll("^.*" + bpath + "\\s*", "")
                      .replaceAll("\\s*" + sbpath + ".*$", "");
            }
          }
          if (url != null && url.length() > 0 && !"null".equalsIgnoreCase(url)) {
            if (session.getServletPath().startsWith("http")) {
              url = session.getServletPath().replaceFirst("(https?://[^/]+).*", "$1") + url;
            }
            uploadForm.setAction(url);
          } else {
            uploadForm.setAction(session.getServletPath());
          }
          removeHiddens();
          if (document != null) {
            String name = Utils.getXmlNodeValue(document, TAG_BLOBSTORE_NAME);
            if (name != null) {
              fileInput.setName(name);
            }
            NodeList list = document.getElementsByTagName(TAG_BLOBSTORE_PARAM);
            for (int i = 0; i < list.getLength(); i++) {
              Node node = list.item(i);
              String value = Utils.getXmlNodeValue(node);
              if (value != null) {
                Node attribute = node.getAttributes().getNamedItem(ATTR_BLOBSTORE_PARAM_NAME);
                if (attribute != null) {
                  String paramName = attribute.getNodeValue();
                  if (paramName != null) {
                    addHidden(paramName, value);
                  }
                }
              }
            }
          }
          receivedBlobPath = true;
          uploadForm.submit();
        }
  public static Payload parseMessage(String message) {
    final Payload payload = new Payload();

    Document messageDom = XMLParser.parse(message);
    NodeList statements = messageDom.getElementsByTagName("com.freedomotic.reactions.Statement");
    for (int i = 0; i < statements.getLength(); i++) {
      Element statement = (Element) statements.item(i);
      payload.enqueueStatement(parseStatement(statement));
    }
    return payload;
  }
  public void loadQueryDef(String xml) {
    Document doc = XMLParser.parse(xml);
    Element rootNode = doc.getDocumentElement();
    if (!rootNode.getNodeName().equalsIgnoreCase(XmlBuilder.NODE_NAME_QUERYDEF)) return;

    HashMap<String, DisplayColumnWidget> displayCols = new HashMap<String, DisplayColumnWidget>();

    NodeList nodes = rootNode.getElementsByTagName(XmlBuilder.NODE_NAME_DISPLAY_FIELDS);
    if (nodes != null && nodes.getLength() > 0)
      loadDisplayFields((Element) nodes.item(0), displayCols);

    nodes = rootNode.getElementsByTagName(XmlBuilder.NODE_NAME_SORT_FIELDS);
    if (nodes != null && nodes.getLength() > 0)
      loadSortFields((Element) nodes.item(0), displayCols);
  }
示例#8
0
  /**
   * Converts a form definition object to an XHTML document object.
   *
   * @param formDef the form definition object.
   * @return the xhtml document object.
   */
  public static Document fromFormDef2XhtmlDoc(FormDef formDef) {
    Document prevdoc = formDef.getDoc();

    Document doc = XMLParser.createDocument();
    doc.appendChild(doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));

    Element htmlNode = doc.createElement("h:html");
    // formDef.setXformsNode(htmlNode);

    htmlNode.setAttribute("xmlns:h", "http://www.w3.org/1999/xhtml");
    htmlNode.setAttribute("xmlns:jr", "http://openrosa.org/javarosa");
    htmlNode.setAttribute(
        XformConstants
            .XML_NAMESPACE /*XformConstants.XML_NAMESPACE_PREFIX+XformConstants.PREFIX_XFORMS*/,
        XformConstants.NAMESPACE_XFORMS);
    htmlNode.setAttribute(
        XformConstants.XML_NAMESPACE_PREFIX + XformConstants.PREFIX_XML_SCHEMA,
        XformConstants.NAMESPACE_XML_SCHEMA);

    doc.appendChild(htmlNode);

    // add head
    Element headNode = doc.createElement("h:head");
    htmlNode.appendChild(headNode);

    // add title
    Element titleNode = doc.createElement("h:title");
    titleNode.appendChild(doc.createTextNode(formDef.getName()));
    headNode.appendChild(titleNode);

    // add body
    Element bodyNode = doc.createElement("h:body");
    htmlNode.appendChild(bodyNode);

    // add model
    Element modelNode = doc.createElement(XformConstants.NODE_NAME_MODEL);
    headNode.appendChild(modelNode);

    // we do not want to lose anything that the model could have had which we do not build when
    // creating an xform from scratch
    XformBuilder.buildXform(formDef, doc, bodyNode, modelNode);

    XformUtil.copyModel(prevdoc, doc);

    return doc;
  }
示例#9
0
  /**
   * This is used to create the user interface for a question
   *
   * @param doc
   * @param UINode
   * @return
   */
  private Element writeToXmlUi(Document doc, Element UINode) {
    // create an item element
    Element itemNode = doc.createElement(XformConstants.NODE_NAME_ITEM);
    // now attach the item to the UI node
    UINode.appendChild(itemNode);

    // now add the label
    Element labelNode = doc.createElement(XformConstants.NODE_NAME_LABEL_MINUS_PREFIX);
    labelNode.setAttribute(XformConstants.ATTRIBUTE_NAME_REF, "jr:itext('" + getBinding() + "')");
    itemNode.appendChild(labelNode);

    // now add the value
    Element valueNode = doc.createElement(XformConstants.NODE_NAME_VALUE);
    valueNode.appendChild(doc.createTextNode(getDefaultValue()));
    itemNode.appendChild(valueNode);
    return UINode;
  }
示例#10
0
  public static List<HitFqnEntityId> getUsedApisFromFacetedHits(
      String xmlResultInString, EntityCategory c) {

    //		if (c.equals(EntityCategory.LOCAL))
    //			throw new IllegalArgumentException("only jdk or lib");

    List<HitFqnEntityId> apis = new LinkedList<HitFqnEntityId>();

    Document doc = XMLParser.parse(xmlResultInString);
    NodeList apisNodes = doc.getElementsByTagName("lst");

    String nodeName;

    if (c.equals(EntityCategory.JDK)) nodeName = "jdk_use_fqn_full";
    else if (c.equals(EntityCategory.LIB)) nodeName = "lib_use_fqn_full";
    else return apis;

    for (int i = 0; i < apisNodes.getLength(); i++) {
      Node apiNode = apisNodes.item(i);
      NamedNodeMap attrs = apiNode.getAttributes();
      Node _attributeNode = null;
      _attributeNode = attrs.getNamedItem("name");

      if (_attributeNode != null) {
        if (_attributeNode.getNodeValue().equals(nodeName)) {
          // iterate through int nodes
          NodeList fqnNodes = apiNode.getChildNodes();

          for (int j = 0; j < fqnNodes.getLength(); j++) {
            Node fqnNode = fqnNodes.item(j);
            if (fqnNode.getNodeName().equals("int")) {
              String fqn = getAttributeValue(fqnNode, "name");
              if (fqn != null) {
                String count = fqnNode.getFirstChild().getNodeValue();

                HitFqnEntityId _apiFqn = new HitFqnEntityId(fqn, "-1", count);
                apis.add(_apiFqn);
              }
            }
          }
        }
      }
    }

    return apis;
  }
示例#11
0
  private void parseXml(String messageXml) {
    try {
      Document messageDom = XMLParser.parse(messageXml);

      Node customerNode = messageDom.getElementsByTagName("customer").item(0);
      String id = ((Element) customerNode).getAttribute("id");
      idField.setText(id);

      String name =
          messageDom.getElementsByTagName("fullname").item(0).getFirstChild().getNodeValue();
      nameField.setText(name);

      String street =
          messageDom.getElementsByTagName("street").item(0).getFirstChild().getNodeValue();
      streetField.setText(street);

      String city = messageDom.getElementsByTagName("city").item(0).getFirstChild().getNodeValue();
      cityField.setText(city);

      String state =
          messageDom.getElementsByTagName("state").item(0).getFirstChild().getNodeValue();
      stateField.setText(state);

      String zip = messageDom.getElementsByTagName("zip").item(0).getFirstChild().getNodeValue();
      zipField.setText(zip);
    } catch (DOMException e) {
      Window.alert("Could not parse XML document.");
    }
  }
示例#12
0
 /**
  * Used to write the instance data
  *
  * @param doc
  * @param instanceNode
  */
 private Element writeToXmlInstance(Document doc, Element instanceNode) {
   // create a node for this question
   Element repeatNode = doc.createElement(getBinding());
   repeatNode.setAttribute(XformConstants.ATTRIBUTE_NAME_JR_TEMPLATE, "");
   // add this to the parent node
   instanceNode.appendChild(repeatNode);
   // return the parent
   return repeatNode;
 }
示例#13
0
 protected void readModel(Model aModel) throws Exception {
   Element el =
       DATAMODEL_TAG_NAME.equals(doc.getDocumentElement().getNodeName())
           ? doc.getDocumentElement()
           : Utils.getElementByTagName(doc.getDocumentElement(), DATAMODEL_TAG_NAME);
   if (el != null && aModel != null) {
     model = aModel;
     try {
       currentTag = el;
       NodeList nl = currentTag.getChildNodes();
       if (nl != null && nl.getLength() > 0) {
         Element lcurrentTag = currentTag;
         try {
           for (int i = 0; i < nl.getLength(); i++) {
             if (ENTITY_TAG_NAME.equals(nl.item(i).getNodeName())) {
               currentTag = (Element) nl.item(i);
               Entity entity = new Entity();
               entity.accept(this);
             } else if (RELATION_TAG_NAME.equals(nl.item(i).getNodeName())) {
               currentTag = (Element) nl.item(i);
               Relation relation = new Relation();
               relation.accept(this);
             } else if (REFERENCE_RELATION_TAG_NAME.equals(nl.item(i).getNodeName())) {
               currentTag = (Element) nl.item(i);
               Relation relation = new ReferenceRelation();
               relation.accept(this);
             }
           }
         } finally {
           currentTag = lcurrentTag;
         }
       }
       model.validateQueries();
       for (Runnable resolver : relationsResolvers) {
         resolver.run();
       }
       model.checkRelationsIntegrity();
     } finally {
       relationsResolvers = null;
       model = null;
     }
   }
 }
示例#14
0
  private static Node getResponseNode(String xmlResultInString) {

    Document doc = XMLParser.parse(xmlResultInString);
    NodeList results = doc.getElementsByTagName("result");

    for (int i = 0; i < results.getLength(); i++) {
      Node result = results.item(i);
      NamedNodeMap attrs = result.getAttributes();
      Node _attributeNode = null;
      _attributeNode = attrs.getNamedItem("name");

      if (_attributeNode != null) {
        if (_attributeNode.getNodeValue().equals("response")) {

          return result;
        }
      }
    }

    return null;
  }
示例#15
0
  /**
   * This is used to create the user interface for a question
   *
   * @param doc
   * @param UINode
   * @return
   */
  protected Element writeToXmlUi(Document doc, Element UINode) {

    UINode = super.writeToXmlUi(doc, UINode);
    // create the group element
    Element repeatUiNode = doc.createElement(XformConstants.NODE_NAME_REPEAT);
    // set the ID for reference purposes
    repeatUiNode.setAttribute(XformConstants.ATTRIBUTE_NAME_NODESET, getPath());
    // add the group node to the UINode
    UINode.appendChild(repeatUiNode);

    return repeatUiNode;
  }
示例#16
0
 /**
  * This will flesh out the iText
  *
  * @param doc
  * @param iTextNode
  */
 private void writeToXmliText(Document doc, List<Element> iTextNodes) {
   // we're assuming that all languages have already been fleshed out in the
   // itext node
   // the mapping of binds to language strings
   HashMap<String, ItextModel> itextMap = getFormDef().getITextMap();
   // loop the itext children, which should be translation elements
   for (Element translationNode : iTextNodes) {
     // get the language name
     String languageName = translationNode.getAttribute(XformConstants.ATTRIBUTE_NAME_LANG);
     // make sure it's not null
     if (languageName == null) {
       continue;
     }
     // get the ItextModel for this question
     ItextModel itext = itextMap.get(getBinding());
     // if there's nothing there, then this is probably a hidden question
     if (itext == null) {
       continue;
     }
     // get the string
     String text = itext.get(languageName);
     // make sure it's not null
     if (text == null) {
       continue;
     }
     // add it to the translation node
     // create the text for the form title
     Element titleTextNode = doc.createElement(XformConstants.NODE_NAME_TEXT);
     // set the id
     titleTextNode.setAttribute(XformConstants.ATTRIBUTE_NAME_ID, getBinding());
     // create the value node for the form title
     Element titleValueNode = doc.createElement(XformConstants.NODE_NAME_VALUE);
     // set the text itself
     titleValueNode.appendChild(doc.createTextNode(text));
     // now add the value node to the text node
     titleTextNode.appendChild(titleValueNode);
     // add the text node to the translation node
     translationNode.appendChild(titleTextNode);
   }
 }
示例#17
0
文件: Feed.java 项目: CzarnyPeter/cxf
    private void parseEntries(@Nonnull final Document document) {
      NodeList entryNodes = document.getElementsByTagName(ENTRY_TAG);

      if (entryNodes != null) {
        Node entryNode;
        for (int i = 0; i < entryNodes.getLength(); i++) {
          entryNode = entryNodes.item(i);
          assert entryNode != null;

          if (entryNode.getNodeType() == ELEMENT_NODE) {
            entries.add(new Entry(entryNodes.item(i)));
          }
        }
        Collections.reverse(entries);
      }
    }
示例#18
0
    /** return the text content of a tag in a xml document. */
    public static String getXmlNodeValue(Document doc, String tag) {
      if (doc == null) return null;

      NodeList list = doc.getElementsByTagName(tag);
      if (list.getLength() == 0) return null;

      Node node = list.item(0);
      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();
      }
      return ret.length() == 0 ? null : ret;
    }
示例#19
0
  public void setState(String state) {
    // read in this pedigree from the xml
    Vector<PelicanPerson> newPedigree = new Vector<PelicanPerson>();
    int pedSize = 0;
    Vector<Integer> pidList = new Vector<Integer>();
    Vector<Integer> midList = new Vector<Integer>();
    HashMap<Integer, Integer> idMap = new HashMap<Integer, Integer>();

    Document doc = XMLParser.parse(state);
    NodeList people = doc.getDocumentElement().getChildNodes();
    for (int i = 0; i < people.getLength(); i++) {
      Element e = (Element) people.item(i);
      if (e.getTagName().equals("Person")) {
        int id = Integer.parseInt(e.getAttribute("Id"));
        int sex = Integer.parseInt(e.getAttribute("Sex"));
        int affection = Integer.parseInt(e.getAttribute("Affection"));

        String[] genotype = new String[2];
        genotype[0] = "?";
        genotype[1] = "?";

        PelicanPerson person =
            new PelicanPerson(this, id, null, null, sex, affection, "", 0, genotype);
        newPedigree.add(person);

        int father = Integer.parseInt(e.getAttribute("Father"));
        pidList.add(new Integer(father));
        int mother = Integer.parseInt(e.getAttribute("Mother"));
        midList.add(new Integer(mother));

        idMap.put(new Integer(id), new Integer(pedSize++));
      }
    }

    for (int i = 0; i < newPedigree.size(); i++) {
      PelicanPerson person = (PelicanPerson) newPedigree.elementAt(i);
      // gww	    if (((Integer)pidList.elementAt(i)).intValue()!=PelicanPerson.unknown) {
      if ((Integer) pidList.elementAt(i) != PelicanPerson.unknownID) {
        if (!idMap.containsKey(pidList.elementAt(i)))
          // gww		    throw(new Error("Father of subject "+String.valueOf(person.id)+" is
          // missing"));
          throw (new Error("Father of subject " + person.id + " is missing"));
        person.father =
            (PelicanPerson)
                newPedigree.elementAt(((Integer) idMap.get(pidList.elementAt(i))).intValue());
      }
      // gww	    if (((Integer)midList.elementAt(i)).intValue()!=PelicanPerson.unknown) {
      if ((Integer) midList.elementAt(i) != PelicanPerson.unknownID) {
        if (!idMap.containsKey(midList.elementAt(i)))
          // gww		    throw(new Error("Mother of subject "+String.valueOf(person.id)+" is
          // missing"));
          throw (new Error("Mother of subject " + person.id + " is missing"));
        person.mother =
            (PelicanPerson)
                newPedigree.elementAt(((Integer) idMap.get(midList.elementAt(i))).intValue());
      }
    }

    // figure out the generations
    ((PelicanPerson) newPedigree.elementAt(0)).laidOut = true;
    boolean someChange = true;
    int nperson = newPedigree.size();
    // repeatedly pass through the pedigree all subjects laid out
    while (someChange) {
      someChange = false;
      for (int i = 0; i < nperson; i++) {
        PelicanPerson p = (PelicanPerson) newPedigree.elementAt(i);
        if (!p.laidOut) {
          // try to get it from the parents
          for (int j = 0; j < nperson; j++) {
            PelicanPerson parent = (PelicanPerson) newPedigree.elementAt(j);
            if (parent == p.father && parent.laidOut) {
              p.generation = parent.generation + 1;
              p.laidOut = true;
              someChange = true;
            }
            if (parent == p.mother && parent.laidOut) {
              p.generation = parent.generation + 1;
              p.laidOut = true;
              someChange = true;
            }
          }
        }
        if (p.laidOut) {
          // assign parents generation
          for (int j = 0; j < nperson; j++) {
            PelicanPerson parent = (PelicanPerson) newPedigree.elementAt(j);
            if (parent == p.father && !parent.laidOut) {
              parent.generation = p.generation - 1;
              parent.laidOut = true;
              someChange = true;
            }
            if (parent == p.mother && !parent.laidOut) {
              parent.generation = p.generation - 1;
              parent.laidOut = true;
              someChange = true;
            }
          }
        }
      }
    }

    if (!checkIntegrity(newPedigree).equals("")) {
      return;
    }

    // end
    clear();
    currentId = 0;
    for (int i = 0; i < nperson; i++) {
      PelicanPerson p = (PelicanPerson) newPedigree.elementAt(i);
      add(p);
      // gww need to add in check for valid integer ID else ignore updating of currentId
      if (p.id > 0) {
        // gww           if (i==0 || p.id>currentId) currentId=p.id;
        if (i == 0 || p.id > currentId) currentId = p.id;
      }
    }
    currentId++;
    newPedigree.removeAllElements();
    updateDisplay();
  }
示例#20
0
  public String getGrade() {
    Document d = XMLParser.createDocument();
    Element root = d.createElement("Grade");

    // first, some specifications of the pedigree
    int numMales = 0;
    int numFemales = 0;
    int numAffectedMales = 0;
    int numAffectedFemales = 0;
    PelicanPerson[] people = getAllPeople();
    for (int i = 0; i < people.length; i++) {
      PelicanPerson p = people[i];
      if (p.sex == PelicanPerson.male) {
        numMales++;
        if (p.affection == PelicanPerson.affected) {
          numAffectedMales++;
        }
      } else {
        numFemales++;
        if (p.affection == PelicanPerson.affected) {
          numAffectedFemales++;
        }
      }
    }
    Element e = d.createElement("Counts");

    Element M = d.createElement("M");
    M.appendChild(d.createTextNode(String.valueOf(numMales)));
    e.appendChild(M);

    Element F = d.createElement("F");
    F.appendChild(d.createTextNode(String.valueOf(numFemales)));
    e.appendChild(F);

    Element aM = d.createElement("aM");
    aM.appendChild(d.createTextNode(String.valueOf(numAffectedMales)));
    e.appendChild(aM);

    Element aF = d.createElement("aF");
    aF.appendChild(d.createTextNode(String.valueOf(numAffectedFemales)));
    e.appendChild(aF);

    root.appendChild(e);

    // now, the analysis results
    renumberAll();
    updateDisplay();

    String integrity = checkIntegrity(history.lastElement());
    if (integrity.equals("")) {
      PedigreeSolver ps = new PedigreeSolver(getAllPeople(), getMatingList());
      PedigreeSolution sol = ps.solve();
      e = d.createElement("Analysis");

      GenotypeSet[] results = sol.getResults();

      Element AR = d.createElement("AR");
      if (results[0].getAll().size() > 0) {
        AR.appendChild(d.createTextNode("Y"));
      } else {
        AR.appendChild(d.createTextNode("N"));
      }
      e.appendChild(AR);

      Element AD = d.createElement("AD");
      if (results[1].getAll().size() > 0) {
        AD.appendChild(d.createTextNode("Y"));
      } else {
        AD.appendChild(d.createTextNode("N"));
      }
      e.appendChild(AD);

      Element SR = d.createElement("SR");
      if (results[2].getAll().size() > 0) {
        SR.appendChild(d.createTextNode("Y"));
      } else {
        SR.appendChild(d.createTextNode("N"));
      }
      e.appendChild(SR);

      Element SD = d.createElement("SD");
      if (results[3].getAll().size() > 0) {
        SD.appendChild(d.createTextNode("Y"));
      } else {
        SD.appendChild(d.createTextNode("N"));
      }
      e.appendChild(SD);
    }
    root.appendChild(e);

    return root.toString();
  }
示例#21
0
 /** return the text content of a tag in the position idx inside a xml document */
 public static String getXmlNodeValue(Document doc, String tag, int idx) {
   if (doc == null) {
     return null;
   }
   return getXmlNodeValue(doc.getElementsByTagName(tag), tag, idx);
 }
示例#22
0
  private void parseAjaxResponse(String responseTxt) {
    if (responseTxt == null) {
      return;
    }

    String error = null;
    Document doc = null;
    try {
      doc = XMLParser.parse(responseTxt);
      error = Utils.getXmlNodeValue(doc, "error");
      if (error == null) {
        // Response brings uploaded files info in either:
        // POST response or FINISHED status
        String msg = Utils.getXmlNodeValue(doc, TAG_MESSAGE);
        serverMessage.setMessage(msg);
        String fld = Utils.getXmlNodeValue(doc, TAG_FIELD);
        NodeList list = doc.getElementsByTagName(TAG_FILE);
        for (int i = 0, l = list.getLength(); i < l; i++) {
          UploadedInfo info = new UploadedInfo();
          info.setField(getInputName() + "-" + i);
          info.setName(Utils.getXmlNodeValue(doc, TAG_NAME, i));
          info.setCtype(Utils.getXmlNodeValue(doc, TAG_CTYPE, i));
          // TODO: test
          info.setKey(Utils.getXmlNodeValue(doc, TAG_KEY, i));
          // TODO: remove
          info.message = msg;
          String url = session.composeURL(PARAM_SHOW + "=" + info.getField());
          if (info.getKey() != null) {
            url += "&" + PARAM_BLOBKEY + "=" + info.getKey();
          }
          info.setFileUrl(url);

          String size = Utils.getXmlNodeValue(doc, TAG_SIZE, i);
          if (size != null) {
            info.setSize(Integer.parseInt(size));
          }
          serverMessage.getUploadedInfos().add(info);
        }
      }
    } catch (Exception e) {
      if (responseTxt.toLowerCase().matches("error")) {
        error =
            i18nStrs.uploaderServerError()
                + "\nAction: "
                + getServletPath()
                + "\nException: "
                + e.getMessage()
                + responseTxt;
      }
    }

    if (error != null) {
      successful = false;
      cancelUpload(error);
      return;
    } else if (Utils.getXmlNodeValue(doc, TAG_WAIT) != null) {
      if (serverRawResponse != null) {
        log(
            "server response received, cancelling the upload "
                + getFileNames()
                + " "
                + serverRawResponse,
            null);
        successful = true;
        uploadFinished();
      }
    } else if (Utils.getXmlNodeValue(doc, TAG_CANCELED) != null) {
      log("server response is: canceled " + getFileNames(), null);
      successful = false;
      canceled = true;
      uploadFinished();
      return;
    } else if (Utils.getXmlNodeValue(doc, TAG_FINISHED) != null) {
      log("server response is: finished " + serverMessage.getUploadedFileNames(), null);
      successful = true;
      if (onSubmitComplete) {
        log("POST response from server has been received", null);
        uploadFinished();
      }
      return;
    } else if (Utils.getXmlNodeValue(doc, TAG_PERCENT) != null) {
      lastData = now();
      long transferredKB = Long.valueOf(Utils.getXmlNodeValue(doc, TAG_CURRENT_BYTES)) / 1024;
      long totalKB = Long.valueOf(Utils.getXmlNodeValue(doc, TAG_TOTAL_BYTES)) / 1024;
      statusWidget.setProgress(transferredKB, totalKB);
      log(
          "server response transferred  " + transferredKB + "/" + totalKB + " " + getFileNames(),
          null);
      if (onSubmitComplete) {
        successful = true; // why suppose an error here in this case ?
        String msg = i18nStrs.uploaderBadServerResponse() + "\n" + serverRawResponse;
        if (blobstore) {
          msg += "\n" + i18nStrs.uploaderBlobstoreBilling();
        } else {
          msg += "\n" + i18nStrs.uploaderBadParsing();
        }
        msg += "\n\n" + responseTxt;
        log(msg, null); // keep log message anyway
        //        statusWidget.setError(msg); // disable the user visible error message
        uploadFinished();
      }
      return;
    } else {
      log("incorrect response: " + getFileNames() + " " + responseTxt, null);
    }

    if (uploadTimeout > 0 && now() - lastData > uploadTimeout) {
      successful = false;
      cancelUpload(i18nStrs.uploaderTimeout());
      try {
        sendAjaxRequestToCancelCurrentUpload();
      } catch (Exception e) {
      }
    }
  }
 @Override
 public JSONValue encode(Document value) throws EncodingException {
   return (value == null) ? getNullType() : new JSONString(value.toString());
 }
示例#24
0
 public Method xml(Document data) {
   defaultContentType(Resource.CONTENT_TYPE_XML);
   builder.setRequestData(data.toString());
   return this;
 }