commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From morg...@apache.org
Subject cvs commit: jakarta-commons/latka/src/java/org/apache/commons/latka XMLReporter.java
Date Tue, 15 Oct 2002 18:38:02 GMT
morgand     2002/10/15 11:38:02

  Modified:    latka/src/java/org/apache/commons/latka XMLReporter.java
  Log:
  converted XMLReporter from JDOM to dom4j
  
  Revision  Changes    Path
  1.22      +55 -46    jakarta-commons/latka/src/java/org/apache/commons/latka/XMLReporter.java
  
  Index: XMLReporter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/XMLReporter.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- XMLReporter.java	11 Oct 2002 18:38:10 -0000	1.21
  +++ XMLReporter.java	15 Oct 2002 18:38:02 -0000	1.22
  @@ -73,10 +73,12 @@
   import org.apache.commons.latka.event.RequestFailedEvent;
   import org.apache.commons.latka.event.SuiteEvent;
   import org.apache.commons.latka.http.Request;
  -// jdom imports
  -import org.jdom.Document;
  -import org.jdom.Element;
  -import org.jdom.output.XMLOutputter;
  +// dom4j imports
  +import org.dom4j.Document;
  +import org.dom4j.DocumentFactory;
  +import org.dom4j.Element;
  +import org.dom4j.io.OutputFormat;
  +import org.dom4j.io.XMLWriter;
   
   /**
    * This LatkaEventListener will generate an XML report
  @@ -92,49 +94,51 @@
    * @version $Id$
    */
   public class XMLReporter extends AbstractReporter implements LatkaEventListener {
  -    /** JDOM document produced as output */
  +    /** dom4j document produced as output */
       protected Document _doc         = null;
  -    /** top level element of JDOM document, a <report> element*/
  +    /** top level element of dom4j document, a <report> element*/
       protected Element  _rootElement = null;
       /** used for output as tests run */                   
       protected PrintWriter _printWriter = new PrintWriter(System.out);
   
       protected boolean _didSuiteSucceed = true;
   
  +    protected DocumentFactory _factory = new DocumentFactory();
  +
       /**
        * Create an XML Reporter, initialising document property, as a new empty
        * report with an unsuccessful suite
        */
       public XMLReporter() {
  -        _rootElement = new Element("report");
  +        _rootElement = _factory.createElement("report");
           //defaults to false, until a SuiteSuccess event occurs
  -        _doc = new Document(_rootElement);
  -        _rootElement.setAttribute("suiteSuccess", "false");
  +        _doc = _factory.createDocument(_rootElement);
  +        _rootElement.addAttribute("suiteSuccess", "false");
       }
   
       /**
        * Returns the XML Document produced by this listener
        *
  -     * @return JDOM representation of the test report
  +     * @return dom4j representation of the test report
        */
       public Document getDocument() {
           return _doc;
       }
   
       /**
  -     * Returns the test report converted from JDOM to a
  +     * Returns the test report converted from dom4j to a
        * text string.
        *
        * @return the test report as an XML string
  -     * @throws IOException if the XML formatter cannot convert the JDOM object
  +     * @throws IOException if the XML formatter cannot convert the dom4j object
        *                     to text
        */
       public String getDocumentAsString() throws IOException {
           // get the xml string from the listener
  -        XMLOutputter outputter = new XMLOutputter("  ", true);
           StringWriter writer = new StringWriter();
  +        XMLWriter outputter = new XMLWriter(writer, new OutputFormat("  ", true));
         
  -        outputter.output(getDocument(), writer);
  +        outputter.write(getDocument());
   
           String xmlDocument = writer.toString();
   
  @@ -154,11 +158,14 @@
           RequestErrorEvent errorEvent = (RequestErrorEvent) event;
           // <root><request><requestError><label>errortext</label>
           // </requestError></request></root>
  -        Element label = new Element("label")
  -                            .addContent(errorEvent.getError().toString());
  -        Element requestError = new Element("requestError").addContent(label);
  -        _rootElement.addContent(createRequestElement(event)
  -                                .addContent(requestError));
  +        Element label = _factory.createElement("label")
  +                            .addText(errorEvent.getError().toString());
  +        Element requestError = _factory.createElement("requestError");
  +        requestError.add(label);
  +
  +        Element requestElement = createRequestElement(event);
  +        requestElement.add(requestError);
  +        _rootElement.add(requestElement);
   
       }
   
  @@ -171,9 +178,9 @@
           _printWriter.print(".");
           _printWriter.flush();
       
  -        _rootElement.addContent(createRequestElement(event)
  -                                .addContent(new Element("requestSuccess"))
  -                               );
  +        Element requestElement = createRequestElement(event);
  +        requestElement.add(_factory.createElement("requestSuccess"));
  +        _rootElement.add(requestElement);
       }
   
       /**
  @@ -190,18 +197,19 @@
   
           // <root><request><requestFailure responseId="xxx"><label>XXX</label>
           // </requestFailure></request></root>
  -        Element label = new Element("label")
  -                            .addContent(failedEvent.getValidationException()
  +        Element label = _factory.createElement("label")
  +                            .addText(failedEvent.getValidationException()
                                                      .getMessage()
                                                      .toString());
  -        Element requestFailure = new Element("requestFailure")
  -                                    .setAttribute("responseId",
  +        Element requestFailure = _factory.createElement("requestFailure")
  +                                    .addAttribute("responseId",
                                                     event.getResponse().toString()
  -                                                 )
  -                                    .addContent(label);
  +                                                 );
  +        requestFailure.add(label);
   
  -        _rootElement.addContent(createRequestElement(event)
  -                                .addContent(requestFailure));
  +        Element requestElement = createRequestElement(event);
  +        requestElement.add(requestFailure);
  +        _rootElement.add(requestElement);
     }
   
       /**
  @@ -216,8 +224,9 @@
       
           Request request = event.getRequest();
           // <root><request><requestSkipped/></request></root>
  -        _rootElement.addContent(createRequestElement(event)
  -                                .addContent(new Element("requestSkipped")));
  +        Element requestElement = createRequestElement(event);
  +        requestElement.add(_factory.createElement("requestSkipped"));
  +        _rootElement.add(requestElement);
   
       }
   
  @@ -228,9 +237,9 @@
        * @param event a {@link ReportMessageEvent}
        */
       public void reportMessage(ReportMessageEvent event) {
  -        Element messageElement = new Element("reportMessage")
  -          .setAttribute("message", event.getMessage());
  -        _rootElement.addContent(messageElement);
  +        Element messageElement = _factory.createElement("reportMessage")
  +          .addAttribute("message", event.getMessage());
  +        _rootElement.add(messageElement);
       }
   
       /**
  @@ -238,29 +247,29 @@
        * @param event the event detailing the completing Suite
        */
       public void suiteCompleted(SuiteEvent event) {
  -        _rootElement.getAttribute("suiteSuccess").setValue(
  +        _rootElement.addAttribute("suiteSuccess",
               String.valueOf(_didSuiteSucceed));
       }
   
       /**
        * Utility method that converts a RequestEvent object to its
  -     * corresponding element in the JDOM object.
  +     * corresponding element in the dom4j object.
        *
        * @param event the request event sent to the listener
  -     * @return the JDOM Element equivalent
  +     * @return the dom4j Element equivalent
        */
       protected Element createRequestElement(RequestEvent event) {
           // the request object
           Request request = event.getRequest();
   
  -        Element requestElement = new Element("request")
  -            .setAttribute("requestTime",
  +        Element requestElement = _factory.createElement("request")
  +            .addAttribute("requestTime",
                             String.valueOf(request.getRequestTiming()))
  -            .setAttribute("url", request.getURL().toString());
  +            .addAttribute("url", request.getURL().toString());
   
           String label = request.getLabel();
           if (label != null) {
  -            requestElement.setAttribute("label", label);
  +            requestElement.addAttribute("label", label);
           }
   
           return requestElement;
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message