Esempio n. 1
0
 /**
  * Display the response as text or as rendered HTML. Change the text on the button appropriate to
  * the current display.
  *
  * @param e the ActionEvent being processed
  */
 @Override
 public void actionPerformed(ActionEvent e) {
   String command = e.getActionCommand();
   if ((sampleResult != null) && (XPATH_TESTER_COMMAND.equals(command))) {
     String response = xmlDataField.getText();
     XPathExtractor extractor = new XPathExtractor();
     xmlConfPanel.modifyTestElement(extractor);
     extractor.setFragment(getFragment.isSelected());
     executeAndShowXPathTester(response, extractor);
   }
 }
Esempio n. 2
0
  /**
   * Converts (X)HTML response to DOM object Tree. This version cares of charset of response.
   *
   * @param unicodeData
   * @return
   */
  private Document parseResponse(String unicodeData, XPathExtractor extractor)
      throws UnsupportedEncodingException, IOException, ParserConfigurationException, SAXException,
          TidyException {
    // TODO: validate contentType for reasonable types?

    // NOTE: responseData encoding is server specific
    //       Therefore we do byte -> unicode -> byte conversion
    //       to ensure UTF-8 encoding as required by XPathUtil
    // convert unicode String -> UTF-8 bytes
    byte[] utf8data = unicodeData.getBytes("UTF-8"); // $NON-NLS-1$
    ByteArrayInputStream in = new ByteArrayInputStream(utf8data);
    boolean isXML = JOrphanUtils.isXML(utf8data);
    // this method assumes UTF-8 input data
    return XPathUtil.makeDocument(
        in,
        false,
        false,
        extractor.useNameSpace(),
        extractor.isTolerant(),
        extractor.isQuiet(),
        extractor.showWarnings(),
        extractor.reportErrors(),
        isXML,
        extractor.isDownloadDTDs());
  }
Esempio n. 3
0
 private String process(String textToParse, XPathExtractor extractor) {
   try {
     Document doc = parseResponse(textToParse, extractor);
     List<String> matchStrings = new ArrayList<String>();
     XPathUtil.putValuesForXPathInList(
         doc, xpathExpressionField.getText(), matchStrings, extractor.getFragment());
     StringBuilder builder = new StringBuilder();
     int nbFound = matchStrings.size();
     builder.append("Match count: ").append(nbFound).append("\n");
     for (int i = 0; i < nbFound; i++) {
       builder
           .append("Match[")
           .append(i + 1)
           .append("]=")
           .append(matchStrings.get(i))
           .append("\n");
     }
     return builder.toString();
   } catch (Exception e) {
     return "Exception:" + ExceptionUtils.getStackTrace(e);
   }
 }