Author: ltheussl Date: Sat Sep 1 21:54:10 2007 New Revision: 571924 URL: http://svn.apache.org/viewvc?rev=571924&view=rev Log: Write out default head and body to make it usable stand-alone. Add a simpler constructor to the sink, the renderingContext shouldn't be required. Add the identity test.
Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlIdentityTest.java (with props) Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java?rev=571924&r1=571923&r2=571924&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java Sat Sep 1 21:54:10 2007 @@ -64,8 +64,6 @@ private PrintWriter writer; - //private StringsMap directives; - private RenderingContext renderingContext; private int[] cellJustif; @@ -76,8 +74,28 @@ /** * @param writer + */ + public XhtmlSink( Writer writer ) + { + this( writer, null ); + } + + /** + * @param writer + * @param renderingContext + */ + public XhtmlSink( Writer writer, RenderingContext renderingContext ) + { + this.writer = new PrintWriter( writer ); + + this.renderingContext = renderingContext; + } + + /** + * @param writer * @param renderingContext * @param directives + * @todo directives Map is not used */ public XhtmlSink( Writer writer, RenderingContext renderingContext, Map directives ) { @@ -129,12 +147,14 @@ /** [EMAIL PROTECTED] */ public void head() { - // Not used overridden in site renderer - // directive( "head()" ); - resetState(); headFlag = true; + + write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" ); + write( "<html xmlns=\"http://www.w3.org/1999/xhtml\">" ); + + writeStartTag( Tag.HEAD ); } /** [EMAIL PROTECTED] */ @@ -142,8 +162,7 @@ { headFlag = false; - // Not used overridden in site renderer - //directive( "head_()" ); + writeEndTag( Tag.HEAD ); } /** @@ -207,18 +226,14 @@ /** [EMAIL PROTECTED] */ public void body() { - // Not used overridden in site renderer - //String body = directiveValue( "body()" ); - //write( body ); + writeStartTag( Tag.BODY ); } /** [EMAIL PROTECTED] */ public void body_() { - // Not used overridden in site renderer - //String body = directiveValue( "body_()" ); - //write( body ); - //resetState(); + writeEndTag( Tag.BODY ); + writeEndTag( Tag.HTML ); } // ---------------------------------------------------------------------- @@ -1190,15 +1205,19 @@ /** [EMAIL PROTECTED] */ protected void write( String text ) { - String relativePathToBasedir = renderingContext.getRelativePath(); - - if ( relativePathToBasedir != null ) + // TODO: this doesn't belong here + if ( renderingContext != null ) { - text = StringUtils.replace( text, "$relativePath", relativePathToBasedir ); - } - else - { - text = StringUtils.replace( text, "$relativePath", "." ); + String relativePathToBasedir = renderingContext.getRelativePath(); + + if ( relativePathToBasedir == null ) + { + text = StringUtils.replace( text, "$relativePath", "." ); + } + else + { + text = StringUtils.replace( text, "$relativePath", relativePathToBasedir ); + } } writer.write( text ); Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlIdentityTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlIdentityTest.java?rev=571924&view=auto ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlIdentityTest.java (added) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlIdentityTest.java Sat Sep 1 21:54:10 2007 @@ -0,0 +1,51 @@ +package org.apache.maven.doxia.module.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 java.io.File; +import java.io.Writer; + +import java.util.HashMap; + +import org.apache.maven.doxia.module.AbstractIdentityTest; +import org.apache.maven.doxia.module.xhtml.decoration.render.RenderingContext; +import org.apache.maven.doxia.parser.Parser; +import org.apache.maven.doxia.sink.Sink; + + +/** + * Check that piping a full model through an XhtmlParser and an XhtmlSink + * leaves the model unchanged. + */ +public class XhtmlIdentityTest extends AbstractIdentityTest +{ + /** [EMAIL PROTECTED] */ + protected Sink createSink( Writer writer ) + { + return new XhtmlSink( writer ); + } + + /** [EMAIL PROTECTED] */ + protected Parser createParser() + { + return new XhtmlParser(); + } + +} Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlIdentityTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlIdentityTest.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java?rev=571924&r1=571923&r2=571924&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java Sat Sep 1 21:54:10 2007 @@ -44,15 +44,7 @@ /** [EMAIL PROTECTED] */ protected Sink createSink( Writer writer ) { - String apt = "test.apt"; - - RenderingContext renderingContext = - new RenderingContext( getBasedirFile(), new File( getBasedirFile(), apt ).getPath(), "apt" ); - - //PLXAPI: This horrible fake map is being used because someone neutered the directives approach in the - // site renderer so that it half worked. Put it back and make it work properly. - - return new XhtmlSink( writer, renderingContext, new FakeMap() ); + return new XhtmlSink( writer ); } public void testLinks() @@ -92,13 +84,13 @@ /** [EMAIL PROTECTED] */ protected String getHeadBlock() { - return ""; + return "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head>"; } /** [EMAIL PROTECTED] */ protected String getBodyBlock() { - return ""; + return "<body></body></html>"; } /** [EMAIL PROTECTED] */ @@ -247,14 +239,4 @@ return text; } - - class FakeMap - extends HashMap - { - /** [EMAIL PROTECTED] */ - public Object get( Object key ) - { - return "fake"; - } - } }