You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by lt...@apache.org on 2007/09/05 22:53:10 UTC
svn commit: r573052 - in
/maven/sandbox/trunk/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer:
XHtmlBookRenderer.java xhtml/ xhtml/XhtmlBookSink.java
Author: ltheussl
Date: Wed Sep 5 13:53:09 2007
New Revision: 573052
URL: http://svn.apache.org/viewvc?rev=573052&view=rev
Log:
Fix xhtml book rendering
Added:
maven/sandbox/trunk/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xhtml/
maven/sandbox/trunk/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xhtml/XhtmlBookSink.java (with props)
Modified:
maven/sandbox/trunk/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XHtmlBookRenderer.java
Modified: maven/sandbox/trunk/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XHtmlBookRenderer.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XHtmlBookRenderer.java?rev=573052&r1=573051&r2=573052&view=diff
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XHtmlBookRenderer.java (original)
+++ maven/sandbox/trunk/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XHtmlBookRenderer.java Wed Sep 5 13:53:09 2007
@@ -25,12 +25,18 @@
import org.apache.maven.doxia.book.model.BookModel;
import org.apache.maven.doxia.book.model.Chapter;
import org.apache.maven.doxia.book.model.Section;
+import org.apache.maven.doxia.book.services.renderer.xhtml.XhtmlBookSink;
+import org.apache.maven.doxia.module.xhtml.decoration.render.RenderingContext;
+import org.apache.maven.doxia.parser.manager.ParserNotFoundException;
+import org.apache.maven.doxia.parser.ParseException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.Writer;
import java.util.Iterator;
/**
@@ -69,7 +75,7 @@
File bookFile = new File( context.getOutputDirectory(), book.getId() + ".xhtml" );
- FileWriter fileWriter;
+ Writer fileWriter;
try
{
@@ -80,22 +86,30 @@
throw new BookDoxiaException( "Error while opening file.", e );
}
- PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter( fileWriter );
- writer.writeText(
- "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">" );
- writer.startElement( "html" );
- writer.addAttribute( "xmlns", "http://www.w3.org/1999/xhtml" );
- writer.startElement( "body" );
+ XhtmlBookSink sink = new XhtmlBookSink( fileWriter,
+ new RenderingContext( context.getOutputDirectory(), bookFile.getAbsolutePath() ) );
+
+ sink.bookHead();
+ // TODO: book author, title?
+ sink.bookHead_();
+ sink.bookBody();
+
+ int chapterNumber = 1;
for ( Iterator it = book.getChapters().iterator(); it.hasNext(); )
{
Chapter chapter = (Chapter) it.next();
- renderChapter( writer, chapter, context );
+ sink.sectionTitle();
+ sink.text( Integer.toString( chapterNumber ) + ". " + chapter.getTitle() );
+ sink.sectionTitle_();
+
+ renderChapter( sink, chapter, context );
+
+ chapterNumber++;
}
- writer.endElement(); // body
- writer.endElement(); // html
+ sink.bookBody_();
try
{
@@ -114,42 +128,34 @@
/**
* Write a chapter.
*
- * @param writer the writer.
+ * @param sink the XhtmlBookSink.
* @param chapter the Chapter.
* @param context the BookContext.
* @throws BookDoxiaException if the chapter cannot be written.
*/
- private void renderChapter( PrettyPrintXMLWriter writer, Chapter chapter, BookContext context )
+ private void renderChapter( XhtmlBookSink sink, Chapter chapter, BookContext context )
throws BookDoxiaException
{
- writer.startElement( "chapter" );
-
for ( Iterator it = chapter.getSections().iterator(); it.hasNext(); )
{
Section section = (Section) it.next();
- renderSection( writer, section, context );
+ renderSection( sink, section, context );
}
-
- writer.endElement();
}
/**
* Write a section.
*
- * @param writer the writer.
+ * @param sink the XhtmlBookSink.
* @param section the Section.
* @param context the BookContext.
* @throws BookDoxiaException if the section cannot be written.
*/
- private void renderSection( PrettyPrintXMLWriter writer, Section section, BookContext context )
+ private void renderSection( XhtmlBookSink sink, Section section, BookContext context )
throws BookDoxiaException
{
- writer.startElement( "section" );
-
- // ----------------------------------------------------------------------
- //
- // ----------------------------------------------------------------------
+ sink.section2();
BookContext.BookFile bookFile = (BookContext.BookFile) context.getFiles().get( section.getId() );
@@ -158,33 +164,26 @@
throw new BookDoxiaException( "No document that matches section with id=" + section.getId() + "." );
}
- // ----------------------------------------------------------------------
- //
- // ----------------------------------------------------------------------
-
-// Sink sink = new XhtmlSink( writer,
-// new RenderingContext( context.getOutputDirectory(), bookFile.getFile().getAbsolutePath() ) );
-
-// try
-// {
-// doxia.parse( new FileReader( bookFile.getFile() ), bookFile.getParserId(), sink );
-// }
-// catch ( ParserNotFoundException e )
-// {
-// throw new BookDoxiaException( "Parser not found: "
-// + bookFile.getParserId() + ".", e );
-// }
-// catch ( ParseException e )
-// {
-// throw new BookDoxiaException( "Error while parsing document: "
-// + bookFile.getFile().getAbsolutePath() + ".", e );
-// }
-// catch ( FileNotFoundException e )
-// {
-// throw new BookDoxiaException( "Could not find document: "
-// + bookFile.getFile().getAbsolutePath() + ".", e );
-// }
+ try
+ {
+ doxia.parse( new FileReader( bookFile.getFile() ), bookFile.getParserId(), sink );
+ }
+ catch ( ParserNotFoundException e )
+ {
+ throw new BookDoxiaException( "Parser not found: "
+ + bookFile.getParserId() + ".", e );
+ }
+ catch ( ParseException e )
+ {
+ throw new BookDoxiaException( "Error while parsing document: "
+ + bookFile.getFile().getAbsolutePath() + ".", e );
+ }
+ catch ( FileNotFoundException e )
+ {
+ throw new BookDoxiaException( "Could not find document: "
+ + bookFile.getFile().getAbsolutePath() + ".", e );
+ }
- writer.endElement();
+ sink.section2_();
}
}
Added: maven/sandbox/trunk/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xhtml/XhtmlBookSink.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xhtml/XhtmlBookSink.java?rev=573052&view=auto
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xhtml/XhtmlBookSink.java (added)
+++ maven/sandbox/trunk/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xhtml/XhtmlBookSink.java Wed Sep 5 13:53:09 2007
@@ -0,0 +1,162 @@
+package org.apache.maven.doxia.book.services.renderer.xhtml;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.module.xhtml.XhtmlSink;
+import org.apache.maven.doxia.module.xhtml.decoration.render.RenderingContext;
+
+import java.io.Writer;
+
+import javax.swing.text.html.HTML.Tag;
+
+/**
+ * An Xhtml Sink that doesn't write out head or body elements.
+ *
+ * @author ltheussl
+ * @version $Id$
+ */
+public class XhtmlBookSink
+ extends XhtmlSink
+{
+ /**
+ * Construct a new XhtmlBookSink.
+ *
+ * @param out the writer for the sink.
+ * @param context the RenderingContext.
+ */
+ public XhtmlBookSink( Writer out, RenderingContext context )
+ {
+ super( out, context );
+ }
+
+ // ----------------------------------------------------------------------
+ //
+ // ----------------------------------------------------------------------
+
+ /** Does nothing. */
+ public void head()
+ {
+ resetState();
+
+ setHeadFlag( true );
+ }
+
+ /** Does nothing. */
+ public void head_()
+ {
+ setHeadFlag( false );
+ }
+
+ /** Does nothing. */
+ public void title()
+ {
+ // noop
+ }
+
+ /** Does nothing. */
+ public void title_()
+ {
+ resetBuffer();
+ }
+
+ /** Does nothing. */
+ public void author_()
+ {
+ resetBuffer();
+ }
+
+ /** Does nothing. */
+ public void date_()
+ {
+ resetBuffer();
+ }
+
+ /** Does nothing. */
+ public void body()
+ {
+ // noop
+ }
+
+ /** Does nothing. */
+ public void body_()
+ {
+ // noop
+ }
+
+ /** Calls super.head(). */
+ public void bookHead()
+ {
+ super.head();
+ }
+
+ /** Calls super.head_(). */
+ public void bookHead_()
+ {
+ super.head_();
+ }
+
+ /** Calls super.title(). */
+ public void bookTitle()
+ {
+ super.title();
+ }
+
+ /** Calls super.title_(). */
+ public void bookTitle_()
+ {
+ super.title_();
+ }
+
+ /** Calls super.head_(). */
+ public void bookAuthor_()
+ {
+ super.author_();
+ }
+
+ /** Calls super.head_(). */
+ public void bookDate_()
+ {
+ super.date_();
+ }
+
+ /** Calls super.body(). */
+ public void bookBody()
+ {
+ super.body();
+ }
+
+ /** Calls super.body_(). */
+ public void bookBody_()
+ {
+ super.body_();
+ }
+
+ /** {@inheritDoc} */
+ public void sectionTitle()
+ {
+ writeStartTag( Tag.H1 );
+ }
+
+ /** {@inheritDoc} */
+ public void sectionTitle_()
+ {
+ writeEndTag( Tag.H1 );
+ }
+}
Propchange: maven/sandbox/trunk/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xhtml/XhtmlBookSink.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/sandbox/trunk/doxia/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xhtml/XhtmlBookSink.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"