maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ltheu...@apache.org
Subject svn commit: r634666 - in /maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src: main/java/org/apache/maven/doxia/siterenderer/sink/ test/java/org/apache/maven/doxia/siterenderer/ test/site/xdoc/
Date Fri, 07 Mar 2008 13:30:48 GMT
Author: ltheussl
Date: Fri Mar  7 05:30:47 2008
New Revision: 634666

URL: http://svn.apache.org/viewvc?rev=634666&view=rev
Log:
Use new Sink attributes. Add tests for table and figure events, DOXIA-78 and DOXIA-227.

Added:
    maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/site/xdoc/attributes.xml
  (with props)
Modified:
    maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/SiteRendererSink.java
    maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/DefaultSiteRendererTest.java

Modified: maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/SiteRendererSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/SiteRendererSink.java?rev=634666&r1=634665&r2=634666&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/SiteRendererSink.java
(original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/SiteRendererSink.java
Fri Mar  7 05:30:47 2008
@@ -19,11 +19,6 @@
  * under the License.
  */
 
-import org.apache.maven.doxia.module.xhtml.XhtmlSink;
-import org.apache.maven.doxia.module.xhtml.decoration.render.RenderingContext;
-import org.apache.maven.doxia.sink.Sink;
-import org.apache.maven.doxia.util.HtmlTools;
-
 import java.io.StringWriter;
 import java.io.Writer;
 import java.util.ArrayList;
@@ -31,6 +26,12 @@
 
 import javax.swing.text.html.HTML.Tag;
 
+import org.apache.maven.doxia.module.xhtml.XhtmlSink;
+import org.apache.maven.doxia.module.xhtml.decoration.render.RenderingContext;
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.sink.SinkEventAttributes;
+import org.apache.maven.doxia.util.HtmlTools;
+
 /**
  * Sink for site renderering.
  *
@@ -163,6 +164,48 @@
         setHeadFlag( true );
     }
 
+
+    /** {@inheritDoc} */
+    public void sectionTitle( int level, SinkEventAttributes attributes )
+    {
+        if ( level == SECTION_LEVEL_1 || level == SECTION_LEVEL_2 )
+        {
+            setHeadFlag( true );
+        }
+        else
+        {
+            super.sectionTitle( level, attributes );
+        }
+    }
+
+    /** {@inheritDoc} */
+    public void sectionTitle_( int level )
+    {
+        if ( level == SECTION_LEVEL_1 || level == SECTION_LEVEL_2 )
+        {
+            String sectionTitle = "";
+
+            if ( getBuffer().length() > 0 )
+            {
+                sectionTitle = getBuffer().toString();
+            }
+
+            resetBuffer();
+
+            setHeadFlag( false );
+
+            writeStartTag( level == SECTION_LEVEL_1 ? Tag.H2 : Tag.H3  );
+            anchor( HtmlTools.encodeId( sectionTitle ) );
+            anchor_();
+            text( sectionTitle );
+            writeEndTag( level == SECTION_LEVEL_1 ? Tag.H2 : Tag.H3 );
+        }
+        else
+        {
+            super.sectionTitle_( level );
+        }
+    }
+
     /**
      * Sets the head flag to true so the title text is buffered until the closing tag.
      *
@@ -170,7 +213,7 @@
      */
     public void sectionTitle1()
     {
-        setHeadFlag( true );
+        sectionTitle( SECTION_LEVEL_1, null );
     }
 
     /**
@@ -181,22 +224,7 @@
      */
     public void sectionTitle1_()
     {
-        String sectionTitle = "";
-
-        if ( getBuffer().length() > 0 )
-        {
-            sectionTitle = getBuffer().toString();
-        }
-
-        resetBuffer();
-
-        setHeadFlag( false );
-
-        writeStartTag( Tag.H2 );
-        anchor( HtmlTools.encodeId( sectionTitle ) );
-        anchor_();
-        text( sectionTitle );
-        writeEndTag( Tag.H2 );
+        sectionTitle_( SECTION_LEVEL_1 );
     }
 
     /**
@@ -206,7 +234,7 @@
      */
     public void sectionTitle2()
     {
-        setHeadFlag( true );
+        sectionTitle( SECTION_LEVEL_2, null );
     }
 
     /**
@@ -217,21 +245,6 @@
      */
     public void sectionTitle2_()
     {
-        String sectionTitle = "";
-
-        if ( getBuffer().length() > 0 )
-        {
-            sectionTitle = getBuffer().toString();
-        }
-
-        resetBuffer();
-
-        setHeadFlag( false );
-
-        writeStartTag( Tag.H3 );
-        anchor( HtmlTools.encodeId( sectionTitle ) );
-        anchor_();
-        text( sectionTitle );
-        writeEndTag( Tag.H3 );
+        sectionTitle_( SECTION_LEVEL_2 );
     }
 }

Modified: maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/DefaultSiteRendererTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/DefaultSiteRendererTest.java?rev=634666&r1=634665&r2=634666&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/DefaultSiteRendererTest.java
(original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/DefaultSiteRendererTest.java
Fri Mar  7 05:30:47 2008
@@ -29,6 +29,7 @@
 import com.gargoylesoftware.htmlunit.html.HtmlElement;
 import com.gargoylesoftware.htmlunit.html.HtmlHeader2;
 import com.gargoylesoftware.htmlunit.html.HtmlHeader4;
+import com.gargoylesoftware.htmlunit.html.HtmlImage;
 import com.gargoylesoftware.htmlunit.html.HtmlListItem;
 import com.gargoylesoftware.htmlunit.html.HtmlOrderedList;
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
@@ -36,6 +37,7 @@
 import com.gargoylesoftware.htmlunit.html.HtmlPreformattedText;
 import com.gargoylesoftware.htmlunit.html.HtmlScript;
 import com.gargoylesoftware.htmlunit.html.HtmlTable;
+import com.gargoylesoftware.htmlunit.html.HtmlTableHeaderCell;
 import com.gargoylesoftware.htmlunit.html.HtmlTableDataCell;
 import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
 import com.gargoylesoftware.htmlunit.html.HtmlUnorderedList;
@@ -126,6 +128,7 @@
         verifyEntitiesPage();
         verifyJavascriptPage();
         verifyFaqPage();
+        verifyAttributes();
     }
 
     /**
@@ -839,5 +842,87 @@
         assertEquals( a.asText().trim(), "[top]" );
 
         assertFalse( elementIterator.hasNext() );
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void verifyAttributes()
+        throws Exception
+    {
+        File attributes = getTestFile( "target/output/attributes.html" );
+        assertNotNull( attributes );
+        assertTrue( attributes.exists() );
+
+        // HtmlUnit
+        WebClient webClient = new WebClient();
+        HtmlPage page = (HtmlPage) webClient.getPage( attributes.toURL() );
+        assertNotNull( page );
+
+        HtmlElement element = page.getHtmlElementById( "contentBox" );
+        assertNotNull( element );
+        HtmlDivision division = (HtmlDivision) element;
+        assertNotNull( division );
+
+        Iterator elementIterator = division.getAllHtmlChildElements();
+
+        // ----------------------------------------------------------------------
+        //
+        // ----------------------------------------------------------------------
+
+        HtmlDivision div = (HtmlDivision) elementIterator.next();
+        assertEquals( "section", div.getAttributeValue( "class" ) );
+
+        HtmlHeader2 h2 = (HtmlHeader2) elementIterator.next();
+        assertNotNull( h2 );
+        assertEquals( "section", h2.asText().trim() );
+
+        HtmlAnchor a = (HtmlAnchor) elementIterator.next();
+        assertNotNull( a );
+        assertEquals( "section", a.getAttributeValue( "name" ) );
+
+        HtmlParagraph p = (HtmlParagraph) elementIterator.next();
+        assertNotNull( p );
+
+        assertEquals( "ID",  p.getAttributeValue( "id" ) );
+        assertEquals( "CLASS", p.getAttributeValue( "class" ) );
+        assertEquals( "TITLE", p.getAttributeValue( "title" ) );
+        assertEquals( "STYLE", p.getAttributeValue( "style" ) );
+        assertEquals( "LANG", p.getAttributeValue( "lang" ) );
+
+        HtmlImage img = (HtmlImage) elementIterator.next();
+        assertNotNull( img );
+
+        assertEquals( "project.png", img.getAttributeValue( "src" ) );
+        assertEquals( "150", img.getAttributeValue( "width" ) );
+        assertEquals( "93", img.getAttributeValue( "height" ) );
+        assertEquals( "border: 1px solid silver", img.getAttributeValue( "style" ) );
+        assertEquals( "Project", img.getAttributeValue( "alt" ) );
+
+        // test object identity to distinguish the case ATTRIBUTE_VALUE_EMPTY
+        assertTrue( img.getAttributeValue( "dummy" ) == HtmlElement.ATTRIBUTE_NOT_DEFINED
);
+
+        HtmlTable table = (HtmlTable) elementIterator.next();
+        assertEquals( "1", table.getAttributeValue( "border" ) );
+        assertEquals( "none", table.getAttributeValue( "class" ) );
+
+        element = (HtmlElement) elementIterator.next();
+        // this is a htmlunit bug
+        assertEquals( "tbody", element.getTagName() );
+
+        HtmlTableRow tr = (HtmlTableRow) elementIterator.next();
+        HtmlTableHeaderCell th = (HtmlTableHeaderCell) elementIterator.next();
+
+        th = (HtmlTableHeaderCell) elementIterator.next();
+        assertEquals( "center", th.getAttributeValue( "align" ) );
+        assertEquals( "2", th.getAttributeValue( "colspan" ) );
+        assertEquals( "50%", th.getAttributeValue( "width" ) );
+
+        tr = (HtmlTableRow) elementIterator.next();
+
+        th = (HtmlTableHeaderCell) elementIterator.next();
+        assertEquals( "left", th.getAttributeValue( "align" ) );
+        assertEquals( "2", th.getAttributeValue( "rowspan" ) );
+        assertEquals( "middle", th.getAttributeValue( "valign" ) );
     }
 }

Added: maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/site/xdoc/attributes.xml
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/site/xdoc/attributes.xml?rev=634666&view=auto
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/site/xdoc/attributes.xml
(added)
+++ maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/site/xdoc/attributes.xml
Fri Mar  7 05:30:47 2008
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+
+<document>
+  <body>
+    <section name="section">
+      <p id="ID" class="CLASS" title="TITLE" lang="LANG" style="STYLE">
+        <!-- DOXIA-227 -->
+        <img src="project.png" dummy="" width="150" height="93" style="border: 1px solid
silver" alt="Project" />
+      </p>
+      <!-- DOXIA-78 -->
+      <table border="1" class="none">
+        <tr>
+          <th>Name</th>
+          <th colspan="2" align="center" width="50%">Telephone</th>
+        </tr>
+        <tr>
+          <th rowspan="2" valign="middle">Telephone</th>
+          <td align="right">555 77 854</td>
+          <td align="right">555 77 855</td>
+        </tr>
+        <tr>
+          <td valign="top">555 77 854</td>
+          <td valign="bottom">555 77 855</td>
+        </tr>
+      </table>
+    </section>
+  </body>
+</document>

Propchange: maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/site/xdoc/attributes.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/site/xdoc/attributes.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message