Author: vsiveton Date: Sat Jan 31 14:39:03 2009 New Revision: 739565 URL: http://svn.apache.org/viewvc?rev=739565&view=rev Log: DOXIA-277: Specify the language identification
o handle languageId in xml sinks o added methods in the xml factories o added test cases Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkWithLanguageIdTest.java (with props) maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkWithLanguageIdTest.java (with props) Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractXmlSinkFactory.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/main/java/org/apache/maven/doxia/module/docbook/DocBookSink.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/main/java/org/apache/maven/doxia/module/docbook/DocbookSinkFactory.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSinkFactory.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSinkFactory.java 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/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkFactory.java Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractXmlSinkFactory.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractXmlSinkFactory.java?rev=739565&r1=739564&r2=739565&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractXmlSinkFactory.java (original) +++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractXmlSinkFactory.java Sat Jan 31 14:39:03 2009 @@ -19,6 +19,8 @@ * under the License. */ +import java.io.Writer; + /** * An abstract <code>SinkFactory</code> for XML markup syntax. <code>UTF-8</code> is used * when no encoding is specified. @@ -29,5 +31,16 @@ public abstract class AbstractXmlSinkFactory extends AbstractTextSinkFactory { - // nop + /** + * Create a text Sink for a given encoding and for a given language identifier. + * + * @param writer The writer for the sink output, never <code>null</code>. + * @param encoding The character encoding used by the writer. + * @param languageId language identifier for the root element as defined by + * <a href="ftp://ftp.isi.edu/in-notes/bcp/bcp47.txt">IETF BCP 47</a>, Tags for the Identification of Languages; + * in addition, the empty string may be specified. + * @return a Sink for XML output in the given encoding. + * @see <a href="http://www.w3.org/TR/REC-xml/#sec-lang-tag">http://www.w3.org/TR/REC-xml/#sec-lang-tag</a> + */ + protected abstract Sink createSink( Writer writer, String encoding, String languageId ); } Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/main/java/org/apache/maven/doxia/module/docbook/DocBookSink.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/main/java/org/apache/maven/doxia/module/docbook/DocBookSink.java?rev=739565&r1=739564&r2=739565&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/main/java/org/apache/maven/doxia/module/docbook/DocBookSink.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/main/java/org/apache/maven/doxia/module/docbook/DocBookSink.java Sat Jan 31 14:39:03 2009 @@ -178,6 +178,23 @@ } /** + * Constructor, initialize the Writer and tells which encoding and languageId are used. + * + * @param writer not null writer to write the result. + * @param encoding the encoding used, that should be written to the generated HTML content + * if not <code>null</code>. + * @param languageId language identifier for the root element as defined by + * <a href="ftp://ftp.isi.edu/in-notes/bcp/bcp47.txt">IETF BCP 47</a>, Tags for the Identification of Languages; + * in addition, the empty string may be specified. + */ + protected DocBookSink( Writer writer, String encoding, String languageId ) + { + this( writer, encoding ); + + this.lang = languageId; + } + + /** * @param text The text to escape. * @param xmlMode xmlMode. * @return The escaped text. @@ -612,7 +629,7 @@ MutableAttributeSet att = new SimpleAttributeSet(); if ( lang != null ) { - att.addAttribute( Attribute.LANG, lang ); + att.addAttribute( Attribute.LANG.toString(), lang ); } return att; } Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/main/java/org/apache/maven/doxia/module/docbook/DocbookSinkFactory.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/main/java/org/apache/maven/doxia/module/docbook/DocbookSinkFactory.java?rev=739565&r1=739564&r2=739565&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/main/java/org/apache/maven/doxia/module/docbook/DocbookSinkFactory.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/main/java/org/apache/maven/doxia/module/docbook/DocbookSinkFactory.java Sat Jan 31 14:39:03 2009 @@ -40,4 +40,10 @@ { return new DocBookSink( writer, encoding ); } + + /** {...@inheritdoc} */ + protected Sink createSink( Writer writer, String encoding, String languageId ) + { + return new DocBookSink( writer, encoding, languageId ); + } } Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java?rev=739565&r1=739564&r2=739565&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java Sat Jan 31 14:39:03 2009 @@ -29,6 +29,7 @@ import org.apache.maven.doxia.sink.AbstractXmlSink; import org.apache.maven.doxia.sink.Sink; +import org.apache.maven.doxia.sink.SinkEventAttributeSet; import org.apache.maven.doxia.sink.SinkEventAttributes; import org.apache.maven.doxia.util.DoxiaUtils; import org.apache.maven.doxia.util.HtmlTools; @@ -79,6 +80,8 @@ private String encoding; + private String languageId; + /** * Constructor, initialize the Writer. * @@ -106,6 +109,23 @@ setNameSpace( "fo" ); } + /** + * Constructor, initialize the Writer and tells which encoding and languageId are used. + * + * @param writer not null writer to write the result. + * @param encoding the encoding used, that should be written to the generated HTML content + * if not <code>null</code>. + * @param languageId language identifier for the root element as defined by + * <a href="ftp://ftp.isi.edu/in-notes/bcp/bcp47.txt">IETF BCP 47</a>, Tags for the Identification of Languages; + * in addition, the empty string may be specified. + */ + protected FoSink( Writer writer, String encoding, String languageId ) + { + this( writer, encoding ); + + this.languageId = languageId; + } + // TODO add FOP compliance mode? /** {...@inheritdoc} */ @@ -996,8 +1016,17 @@ write( " encoding=\"" + encoding + "\"" ); } write( "?>" ); + writeEOL(); + + MutableAttributeSet atts = new SinkEventAttributeSet(); + atts.addAttribute( "xmlns:" + getNameSpace(), FO_NAMESPACE ); + + if ( languageId != null ) + { + atts.addAttribute( "language", languageId ); + } - writeStartTag( ROOT_TAG, "xmlns:" + getNameSpace(), FO_NAMESPACE ); + writeStartTag( ROOT_TAG, atts ); writeStartTag( LAYOUT_MASTER_SET_TAG, "" ); Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSinkFactory.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSinkFactory.java?rev=739565&r1=739564&r2=739565&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSinkFactory.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSinkFactory.java Sat Jan 31 14:39:03 2009 @@ -40,4 +40,10 @@ { return new FoSink( writer, encoding ); } + + /** {...@inheritdoc} */ + protected Sink createSink( Writer writer, String encoding, String languageId ) + { + return new FoSink( writer, encoding, languageId ); + } } Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java?rev=739565&r1=739564&r2=739565&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java Sat Jan 31 14:39:03 2009 @@ -54,6 +54,8 @@ private String encoding; + private String languageId; + // ---------------------------------------------------------------------- // Constructors // ---------------------------------------------------------------------- @@ -82,6 +84,23 @@ this.encoding = encoding; } + /** + * Constructor, initialize the Writer and tells which encoding and languageId are used. + * + * @param writer not null writer to write the result. + * @param encoding the encoding used, that should be written to the generated HTML content + * if not <code>null</code>. + * @param languageId language identifier for the root element as defined by + * <a href="ftp://ftp.isi.edu/in-notes/bcp/bcp47.txt">IETF BCP 47</a>, Tags for the Identification of Languages; + * in addition, the empty string may be specified. + */ + protected XdocSink( Writer writer, String encoding, String languageId ) + { + this( writer, encoding ); + + this.languageId = languageId; + } + // ---------------------------------------------------------------------- // Public protected methods // ---------------------------------------------------------------------- @@ -118,6 +137,12 @@ atts.addAttribute( "xmlns:xsi", XML_NAMESPACE ); atts.addAttribute( "xsi:schemaLocation", XDOC_NAMESPACE + " " + XDOC_SYSTEM_ID ); + if ( languageId != null ) + { + atts.addAttribute( Attribute.LANG.toString(), languageId ); + atts.addAttribute( "xml:lang", languageId ); + } + writeStartTag( DOCUMENT_TAG, atts ); writeStartTag( PROPERTIES_TAG ); Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSinkFactory.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSinkFactory.java?rev=739565&r1=739564&r2=739565&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSinkFactory.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSinkFactory.java Sat Jan 31 14:39:03 2009 @@ -40,4 +40,10 @@ { return new XdocSink( writer, encoding ); } + + /** {...@inheritdoc} */ + protected Sink createSink( Writer writer, String encoding, String languageId ) + { + return new XdocSink( writer, encoding, languageId ); + } } Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkWithLanguageIdTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkWithLanguageIdTest.java?rev=739565&view=auto ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkWithLanguageIdTest.java (added) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkWithLanguageIdTest.java Sat Jan 31 14:39:03 2009 @@ -0,0 +1,49 @@ +package org.apache.maven.doxia.module.xdoc; + +/* + * 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.Writer; +import java.util.Locale; + +import org.apache.maven.doxia.sink.Sink; + +/** + * @author <a href="mailto:vincent.sive...@gmail.com">Vincent Siveton</a> + * @version $Id$ + */ +public class XdocSinkWithLanguageIdTest + extends XdocSinkTest +{ + /** {...@inheritdoc} */ + protected Sink createSink( Writer writer ) + { + return new XdocSink( writer, "UTF-8", Locale.US.getLanguage() ); + } + + /** {...@inheritdoc} */ + protected String getHeadBlock() + { + return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + + "<document xmlns=\"http://maven.apache.org/XDOC/2.0\" " + + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + + "xsi:schemaLocation=\"http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd\" " + + "lang=\"en\" xml:lang=\"en\">" + "<properties></properties>"; + } +} Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkWithLanguageIdTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkWithLanguageIdTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision 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=739565&r1=739564&r2=739565&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 Jan 31 14:39:03 2009 @@ -49,6 +49,8 @@ private String encoding; + private String languageId; + /** An indication on if we're inside a head title. */ private boolean headTitleFlag; @@ -80,6 +82,23 @@ this.encoding = encoding; } + /** + * Constructor, initialize the Writer and tells which encoding and languageId are used. + * + * @param writer not null writer to write the result. + * @param encoding the encoding used, that should be written to the generated HTML content + * if not <code>null</code>. + * @param languageId language identifier for the root element as defined by + * <a href="ftp://ftp.isi.edu/in-notes/bcp/bcp47.txt">IETF BCP 47</a>, Tags for the Identification of Languages; + * in addition, the empty string may be specified. + */ + protected XhtmlSink( Writer writer, String encoding, String languageId ) + { + this( writer, encoding ); + + this.languageId = languageId; + } + /** {...@inheritdoc} */ public void head() { @@ -93,6 +112,12 @@ MutableAttributeSet atts = new SinkEventAttributeSet(); atts.addAttribute( "xmlns", XHTML_NAMESPACE ); + if ( languageId != null ) + { + atts.addAttribute( Attribute.LANG.toString(), languageId ); + atts.addAttribute( "xml:lang", languageId ); + } + writeStartTag( Tag.HTML, atts ); writeStartTag( Tag.HEAD ); Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkFactory.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/XhtmlSinkFactory.java?rev=739565&r1=739564&r2=739565&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkFactory.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkFactory.java Sat Jan 31 14:39:03 2009 @@ -40,4 +40,10 @@ { return new XhtmlSink( writer, encoding ); } + + /** {...@inheritdoc} */ + protected Sink createSink( Writer writer, String encoding, String languageId ) + { + return new XhtmlSink( writer, encoding, languageId ); + } } Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkWithLanguageIdTest.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/XhtmlSinkWithLanguageIdTest.java?rev=739565&view=auto ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkWithLanguageIdTest.java (added) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkWithLanguageIdTest.java Sat Jan 31 14:39:03 2009 @@ -0,0 +1,48 @@ +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.Writer; +import java.util.Locale; + +import org.apache.maven.doxia.sink.Sink; + +/** + * @author <a href="mailto:vincent.sive...@gmail.com">Vincent Siveton</a> + * @version $Id$ + */ +public class XhtmlSinkWithLanguageIdTest + extends XhtmlSinkTest +{ + /** {...@inheritdoc} */ + protected Sink createSink( Writer writer ) + { + return new XhtmlSink( writer, "UTF-8", Locale.US.getLanguage() ); + } + + /** {...@inheritdoc} */ + protected String getHeadBlock() + { + 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\" lang=\"en\" xml:lang=\"en\">" + + "<head><title></title>" + + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/></head>"; + } +} Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkWithLanguageIdTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkWithLanguageIdTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision