jstrachan    2003/10/01 03:43:03

  Modified:    html2xdoc/src/test/org/apache/maven/html2xdoc
                        TestHtml2Xdoc.java
               html2xdoc/src/main/org/apache/maven/html2xdoc
                        Html2XdocBean.java
               html2xdoc plugin.jelly .cvsignore
  Added:       html2xdoc/src/test/org/apache/maven/html2xdoc h2h4.html
                        h2h3.html codeinpara.html codeinpara.xml
  Log:
  Various fixes for the HTML plugin.

* recreate the converter bean for each file to avoid multiple files causing wierdness 
to occur on the handling of headings etc

* added more test cases which used to highlight some issues, such as a nested <code> 
element inside some text markup
  
  Revision  Changes    Path
  1.3       +23 -16    
maven-plugins/html2xdoc/src/test/org/apache/maven/html2xdoc/TestHtml2Xdoc.java
  
  Index: TestHtml2Xdoc.java
  ===================================================================
  RCS file: 
/home/cvs/maven-plugins/html2xdoc/src/test/org/apache/maven/html2xdoc/TestHtml2Xdoc.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestHtml2Xdoc.java        4 Aug 2003 14:12:58 -0000       1.2
  +++ TestHtml2Xdoc.java        1 Oct 2003 10:43:03 -0000       1.3
  @@ -65,26 +65,18 @@
   import java.io.IOException;
   import java.io.StringWriter;
   import java.net.URL;
  -import java.util.Iterator;
  -import java.util.LinkedList;
  -import java.util.List;
  -
  -import org.dom4j.CharacterData;
  -import org.dom4j.Document;
  -import org.dom4j.DocumentFactory;
  -import org.dom4j.Element;
  -import org.dom4j.Node;
  -import org.dom4j.io.OutputFormat;
  -import org.dom4j.io.SAXReader;
  -import org.dom4j.io.XMLWriter;
  -
  -import org.cyberneko.html.parsers.SAXParser;
   
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   import junit.textui.TestRunner;
   
  +import org.cyberneko.html.parsers.SAXParser;
  +import org.dom4j.Document;
  +import org.dom4j.io.OutputFormat;
  +import org.dom4j.io.SAXReader;
  +import org.dom4j.io.XMLWriter;
  +
   /**
    * A test harness for the HTML to XDOC converter 
    * 
  @@ -92,6 +84,8 @@
    */
   public class TestHtml2Xdoc extends TestCase {
       
  +    protected boolean verbose = false;
  +    
       public static void main( String[] args ) {
           TestRunner.run( suite() );
       }
  @@ -107,11 +101,14 @@
       // Test cases
       //-------------------------------------------------------------------------
       public void testOne() throws Exception {
  +        assertConversion("codeinpara.html", "codeinpara.xml");
                assertConversion("input1.html", "output1.xml");
                assertConversion("h1h2.html", "h1h2.xml");
  -             assertConversion("h3h4.html", "h1h2.xml");
  +        assertConversion("h2h3.html", "h1h2.xml");
  +        assertConversion("h2h4.html", "h1h2.xml");
  +        assertConversion("h3h4.html", "h1h2.xml");
                assertConversion("link.html", "link.xml");
  -             assertConversion("comment.html", "comment.xml");
  +        assertConversion("comment.html", "comment.xml");
       }
       
       // Implementation methods
  @@ -119,9 +116,19 @@
       protected void assertConversion(String input, String output) throws Exception {
           Html2XdocBean converter = createConverter();
           Document inputDoc = parseHtml(input);
  +        
  +        
           Document expectedDoc = parse(output);
           
           Document actualDoc = converter.convert(inputDoc);
  +
  +        if (verbose) {        
  +            System.out.println("Comparing: " + input + " to: " + output);
  +            System.out.println("Parsed: " + inputDoc.asXML());
  +            System.out.println("Generated: " + actualDoc.asXML());
  +            System.out.println();
  +            System.out.println();
  +        }
           
           assertEqual("Output for: " + input + " does not match: " + output, 
expectedDoc, actualDoc);
       }
  
  
  
  1.1                  
maven-plugins/html2xdoc/src/test/org/apache/maven/html2xdoc/h2h4.html
  
  Index: h2h4.html
  ===================================================================
  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    <title>A title</title>
  </head>
  <body>
        
  <h2>A section title</h2>
  
  Some text
  <br/>
  More text
  
  <h4>a subsection</h4>
  
  This is a subsection. It only has this.
  
  </body>
  </html>
  
  
  
  1.1                  
maven-plugins/html2xdoc/src/test/org/apache/maven/html2xdoc/h2h3.html
  
  Index: h2h3.html
  ===================================================================
  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    <title>A title</title>
  </head>
  <body>
        
  <h2>A section title</h2>
  
  Some text
  <br/>
  More text
  
  <h3>a subsection</h3>
  
  This is a subsection. It only has this.
  
  </body>
  </html>
  
  
  
  1.1                  
maven-plugins/html2xdoc/src/test/org/apache/maven/html2xdoc/codeinpara.html
  
  Index: codeinpara.html
  ===================================================================
  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    <title>A title</title>
  </head>
  <body>
  
  <h3>Title</h3>
  Some text <code>some code</code> more text
  </body>
  </html>
  
  
  
  1.1                  
maven-plugins/html2xdoc/src/test/org/apache/maven/html2xdoc/codeinpara.xml
  
  Index: codeinpara.xml
  ===================================================================
  <document>
    <properties>
      <title>A title</title>
    </properties>
    <body>
      <section name="Title">
        <p>Some text <code>some code</code> more text
        </p>
      </section>
    </body>
  </document>
  
  
  
  1.3       +16 -2     
maven-plugins/html2xdoc/src/main/org/apache/maven/html2xdoc/Html2XdocBean.java
  
  Index: Html2XdocBean.java
  ===================================================================
  RCS file: 
/home/cvs/maven-plugins/html2xdoc/src/main/org/apache/maven/html2xdoc/Html2XdocBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Html2XdocBean.java        4 Aug 2003 14:12:58 -0000       1.2
  +++ Html2XdocBean.java        1 Oct 2003 10:43:03 -0000       1.3
  @@ -295,8 +295,22 @@
        * @param node the node to add
        */
       private void addNode(Node node) {
  -        currentNode.add(cloneNode(node));
  -        currentParaNode = null;
  +        if (currentParaNode != null && ! shouldBreakPara(node)) {
  +            currentParaNode.add(cloneNode(node));
  +        }
  +        else {
  +            currentNode.add(cloneNode(node));
  +            currentParaNode = null;
  +        }
  +    }
  +
  +    /**
  +     * @return true if the paragraph should be split, such as for a br or p
  +     * tag
  +     */
  +    protected boolean shouldBreakPara(Node node) {
  +        String name = node.getName();
  +        return name.equals("p") || name.equals("br");
       }
   
       /**
  
  
  
  1.9       +3 -3      maven-plugins/html2xdoc/plugin.jelly
  
  Index: plugin.jelly
  ===================================================================
  RCS file: /home/cvs/maven-plugins/html2xdoc/plugin.jelly,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- plugin.jelly      19 Sep 2003 07:35:23 -0000      1.8
  +++ plugin.jelly      1 Oct 2003 10:43:03 -0000       1.9
  @@ -24,9 +24,6 @@
       
       <j:set var="outputencoding" value="${maven.docs.outputencoding}"/>
   
  -    <!-- tool for converting HTML into XDoc -->
  -    <j:useBean class="org.apache.maven.html2xdoc.Html2XdocBean" var="htmlTool"/>
  -
       <!-- mapper for determining output file name -->
       <j:new var="mapper" 
className="org.apache.maven.util.CaseInsensitiveGlobPatternMapper"/>
   
  @@ -55,6 +52,9 @@
       </ant:fileScanner>
   
       <j:forEach var="file" items="${docFiles.iterator()}">
  +
  +      <!-- tool for converting HTML into XDoc -->
  +      <j:useBean class="org.apache.maven.html2xdoc.Html2XdocBean" var="htmlTool"/>
   
         <util:replace var="inDirForward" oldChar="\" newChar="/" 
value="${file.parent}"/>
         <j:set var="outDir" value="${dirMapper.mapFileName(inDirForward).0}"/>
  
  
  
  1.3       +2 -0      maven-plugins/html2xdoc/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  RCS file: /home/cvs/maven-plugins/html2xdoc/.cvsignore,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- .cvsignore        17 Mar 2003 08:57:17 -0000      1.2
  +++ .cvsignore        1 Oct 2003 10:43:03 -0000       1.3
  @@ -1,3 +1,5 @@
   target
   maven.log
   velocity.log
  +bin
  +.classpath
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to