예제 #1
0
 /**
  * Writes data out in XML format.
  *
  * @return A flag indicating the success of the operation.
  */
 private boolean writeXMLFile() {
   File selectedFile = model.getFile();
   try {
     FileOutputStream ow = new FileOutputStream(selectedFile);
     DriveTrainEncoder.encode(ow, model);
     ow.close();
     model.reset();
     return true;
   } catch (IOException iox) {
     JOptionPane.showMessageDialog(
         this,
         Messages.format("Main.15", iox.getLocalizedMessage()), // $NON-NLS-1$
         Messages.getString("Main.16"),
         JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$
     return false;
   } catch (ParserConfigurationException iox) {
     JOptionPane.showMessageDialog(
         this,
         Messages.format("ParserConfigurationException", iox.getLocalizedMessage()), // $NON-NLS-1$
         Messages.getString("Main.16"),
         JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$
     return false;
   } catch (TransformerException iox) {
     JOptionPane.showMessageDialog(
         this,
         Messages.format("TransformerException", iox.getLocalizedMessage()), // $NON-NLS-1$
         Messages.getString("Main.16"),
         JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$
     return false;
   }
 }
예제 #2
0
  /**
   * Test whether an XPath is valid. It seems the Xalan has no easy way to check, so this creates a
   * dummy test document, then tries to evaluate the xpath against it.
   *
   * @param xpathString XPath String to validate
   * @param showDialog weather to show a dialog
   * @return returns true if valid, valse otherwise.
   */
  public static boolean validXPath(String xpathString, boolean showDialog) {
    String ret = null;
    boolean success = true;
    Document testDoc = null;
    try {
      testDoc = XPathUtil.makeDocumentBuilder(false, false, false, false).newDocument();
      Element el = testDoc.createElement("root"); // $NON-NLS-1$
      testDoc.appendChild(el);
      XPathUtil.validateXPath(testDoc, xpathString);
    } catch (IllegalArgumentException e) {
      log.warn(e.getLocalizedMessage());
      success = false;
      ret = e.getLocalizedMessage();
    } catch (ParserConfigurationException e) {
      success = false;
      ret = e.getLocalizedMessage();
    } catch (TransformerException e) {
      success = false;
      ret = e.getLocalizedMessage();
    }

    if (showDialog) {
      JOptionPane.showMessageDialog(
          null,
          (success) ? JMeterUtils.getResString("xpath_assertion_valid") : ret, // $NON-NLS-1$
          (success)
              ? JMeterUtils.getResString("xpath_assertion_valid")
              : JMeterUtils //$NON-NLS-1$
                  .getResString("xpath_assertion_failed"),
          (success)
              ? JOptionPane.INFORMATION_MESSAGE // $NON-NLS-1$
              : JOptionPane.ERROR_MESSAGE);
    }
    return success;
  }