Author: ltheussl Date: Fri Jul 17 10:46:21 2009 New Revision: 795033 URL: http://svn.apache.org/viewvc?rev=795033&view=rev Log: Implement all methods with SinkEventAttributes
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-latex/src/main/java/org/apache/maven/doxia/module/latex/LatexSink.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-latex/src/test/java/org/apache/maven/doxia/module/latex/LatexSinkTest.java Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-latex/src/main/java/org/apache/maven/doxia/module/latex/LatexSink.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-latex/src/main/java/org/apache/maven/doxia/module/latex/LatexSink.java?rev=795033&r1=795032&r2=795033&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-latex/src/main/java/org/apache/maven/doxia/module/latex/LatexSink.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-latex/src/main/java/org/apache/maven/doxia/module/latex/LatexSink.java Fri Jul 17 10:46:21 2009 @@ -22,6 +22,7 @@ import org.apache.maven.doxia.sink.AbstractTextSink; import org.apache.maven.doxia.sink.Sink; import org.apache.maven.doxia.sink.SinkEventAttributes; +import org.apache.maven.doxia.sink.SinkEventAttributeSet; import org.apache.maven.doxia.util.DoxiaUtils; import org.apache.maven.doxia.util.LineBreaker; @@ -65,8 +66,6 @@ private boolean verbatimFlag; - private boolean boxFlag; - private boolean figureFlag; private boolean tableFlag; @@ -172,10 +171,15 @@ */ public void head() { + head( null ); + } + + /** {...@inheritdoc} */ + public void head( SinkEventAttributes attributes ) + { titleFlag = false; numberedListNesting = 0; verbatimFlag = false; - boxFlag = false; figureFlag = false; tableFlag = false; gridFlag = false; @@ -199,6 +203,12 @@ */ public void body() { + body( null ); + } + + /** {...@inheritdoc} */ + public void body( SinkEventAttributes attributes ) + { if ( titleFlag ) { if ( fragmentDocument ) @@ -231,6 +241,12 @@ */ public void title() { + title( null ); + } + + /** {...@inheritdoc} */ + public void title( SinkEventAttributes attributes ) + { if ( !fragmentDocument ) { titleFlag = true; @@ -262,6 +278,12 @@ */ public void author() { + author( null ); + } + + /** {...@inheritdoc} */ + public void author( SinkEventAttributes attributes ) + { if ( !fragmentDocument ) { markup( "\\author{" ); @@ -292,6 +314,12 @@ */ public void date() { + date( null ); + } + + /** {...@inheritdoc} */ + public void date( SinkEventAttributes attributes ) + { if ( !fragmentDocument ) { markup( "\\date{" ); @@ -317,6 +345,47 @@ } } + /** {...@inheritdoc} */ + public void sectionTitle( int level, SinkEventAttributes attributes ) + { + isTitle = true; + } + + /** {...@inheritdoc} */ + public void sectionTitle_( int level ) + { + String command = ""; + switch ( level ) + { + case SECTION_LEVEL_1: + command = "section"; + break; + case SECTION_LEVEL_2: + command = "subsection"; + break; + case SECTION_LEVEL_3: + command = "subsubsection"; + break; + case SECTION_LEVEL_4: + command = "paragraph"; + break; + case SECTION_LEVEL_5: + command = "subparagraph"; + break; + default: + throw new IllegalArgumentException( "Not a section level: " + level ); + } + + isTitle = false; + + if ( StringUtils.isNotEmpty( title ) ) + { + markup( EOL + "\\" + command + "{" + title + "}" + EOL ); + + title = null; + } + } + // ---------------------------------------------------------------------- // Section Title 1 // ---------------------------------------------------------------------- @@ -326,7 +395,7 @@ */ public void sectionTitle1() { - isTitle = true; + sectionTitle( SECTION_LEVEL_1, null ); } /** @@ -334,14 +403,7 @@ */ public void sectionTitle1_() { - isTitle = false; - - if ( StringUtils.isNotEmpty( title ) ) - { - markup( EOL + "\\section{" + title + "}" + EOL ); - - title = null; - } + sectionTitle_( SECTION_LEVEL_1 ); } // ---------------------------------------------------------------------- @@ -353,7 +415,7 @@ */ public void sectionTitle2() { - isTitle = true; + sectionTitle( SECTION_LEVEL_2, null ); } /** @@ -361,14 +423,7 @@ */ public void sectionTitle2_() { - isTitle = false; - - if ( StringUtils.isNotEmpty( title ) ) - { - markup( EOL + "\\subsection{" + title + "}" + EOL ); - - title = null; - } + sectionTitle_( SECTION_LEVEL_2 ); } // ---------------------------------------------------------------------- @@ -380,7 +435,7 @@ */ public void sectionTitle3() { - isTitle = true; + sectionTitle( SECTION_LEVEL_3, null ); } /** @@ -388,14 +443,7 @@ */ public void sectionTitle3_() { - isTitle = false; - - if ( StringUtils.isNotEmpty( title ) ) - { - markup( EOL + "\\subsubsection{" + title + "}" + EOL ); - - title = null; - } + sectionTitle_( SECTION_LEVEL_3 ); } // ---------------------------------------------------------------------- @@ -407,7 +455,7 @@ */ public void sectionTitle4() { - isTitle = true; + sectionTitle( SECTION_LEVEL_4, null ); } /** @@ -415,14 +463,7 @@ */ public void sectionTitle4_() { - isTitle = false; - - if ( StringUtils.isNotEmpty( title ) ) - { - markup( EOL + "\\paragraph{" + title + "}" + EOL ); - - title = null; - } + sectionTitle_( SECTION_LEVEL_4 ); } // ---------------------------------------------------------------------- @@ -434,7 +475,7 @@ */ public void sectionTitle5() { - isTitle = true; + sectionTitle( SECTION_LEVEL_5, null ); } /** @@ -442,14 +483,7 @@ */ public void sectionTitle5_() { - isTitle = false; - - if ( StringUtils.isNotEmpty( title ) ) - { - markup( EOL + "\\subparagraph{" + title + "}" + EOL ); - - title = null; - } + sectionTitle_( SECTION_LEVEL_5 ); } // ---------------------------------------------------------------------- @@ -461,6 +495,12 @@ */ public void list() { + list( null ); + } + + /** {...@inheritdoc} */ + public void list( SinkEventAttributes attributes ) + { markup( EOL + "\\begin{itemize}" ); } @@ -477,6 +517,12 @@ */ public void listItem() { + listItem( null ); + } + + /** {...@inheritdoc} */ + public void listItem( SinkEventAttributes attributes ) + { markup( EOL + "\\item " ); } @@ -485,6 +531,12 @@ */ public void numberedList( int numbering ) { + numberedList( numbering, null ); + } + + /** {...@inheritdoc} */ + public void numberedList( int numbering, SinkEventAttributes attributes ) + { ++numberedListNesting; String counter; @@ -542,6 +594,12 @@ */ public void numberedListItem() { + numberedListItem( null ); + } + + /** {...@inheritdoc} */ + public void numberedListItem( SinkEventAttributes attributes ) + { markup( "\\item " ); } @@ -550,6 +608,12 @@ */ public void definitionList() { + definitionList( null ); + } + + /** {...@inheritdoc} */ + public void definitionList( SinkEventAttributes attributes ) + { markup( EOL + "\\begin{description}" ); } @@ -566,6 +630,12 @@ */ public void definedTerm() { + definedTerm( null ); + } + + /** {...@inheritdoc} */ + public void definedTerm( SinkEventAttributes attributes ) + { markup( EOL + "\\item[\\mbox{" ); } @@ -577,6 +647,42 @@ markup( "}] " ); } + /** {...@inheritdoc} */ + public void definitionListItem() + { + definitionListItem( null ); + } + + /** {...@inheritdoc} */ + public void definitionListItem( SinkEventAttributes attributes ) + { + // nop + } + + /** {...@inheritdoc} */ + public void definitionListItem_() + { + // nop + } + + /** {...@inheritdoc} */ + public void definition() + { + definition( null ); + } + + /** {...@inheritdoc} */ + public void definition( SinkEventAttributes attributes ) + { + // nop + } + + /** {...@inheritdoc} */ + public void definition_() + { + // nop + } + // ---------------------------------------------------------------------- // Figure // ---------------------------------------------------------------------- @@ -586,6 +692,12 @@ */ public void figure() { + figure( null ); + } + + /** {...@inheritdoc} */ + public void figure( SinkEventAttributes attributes ) + { figureFlag = true; markup( EOL + "\\begin{figure}[htb]" + EOL ); } @@ -604,13 +716,19 @@ */ public void figureGraphics( String name ) { - if ( !name.toLowerCase( Locale.ENGLISH ).endsWith( ".eps" ) ) + figureGraphics( name, null ); + } + + /** {...@inheritdoc} */ + public void figureGraphics( String src, SinkEventAttributes attributes ) + { + if ( !src.toLowerCase( Locale.ENGLISH ).endsWith( ".eps" ) ) { getLog().warn( "[Latex Sink] Found non-eps figure graphics!" ); } markup( "\\begin{center}" + EOL ); - markup( "\\includegraphics{" + name + "}" + EOL ); + markup( "\\includegraphics{" + src + "}" + EOL ); markup( "\\end{center}" + EOL ); } @@ -619,6 +737,12 @@ */ public void figureCaption() { + figureCaption( null ); + } + + /** {...@inheritdoc} */ + public void figureCaption( SinkEventAttributes attributes ) + { markup( "\\caption{" ); } @@ -639,6 +763,12 @@ */ public void table() { + table( null ); + } + + /** {...@inheritdoc} */ + public void table( SinkEventAttributes attributes ) + { tableFlag = true; markup( EOL + "\\begin{table}[htp]" + EOL ); } @@ -712,6 +842,12 @@ */ public void tableRow() { + tableRow( null ); + } + + /** {...@inheritdoc} */ + public void tableRow( SinkEventAttributes attributes ) + { cellCount = 0; } @@ -734,6 +870,21 @@ */ public void tableCell() { + tableCell( (SinkEventAttributes) null ); + } + + /** {...@inheritdoc} */ + public void tableCell( String width ) + { + SinkEventAttributeSet att = new SinkEventAttributeSet(); + att.addAttribute( javax.swing.text.html.HTML.Attribute.WIDTH, width ); + + tableCell( att ); + } + + /** {...@inheritdoc} */ + public void tableCell( SinkEventAttributes attributes ) + { tableCell( false ); } @@ -742,7 +893,8 @@ */ public void tableCell_() { - tableCell_( false ); + markup( "\\end{tabular}" ); + ++cellCount; } /** @@ -750,6 +902,21 @@ */ public void tableHeaderCell() { + tableCell( (SinkEventAttributes) null ); + } + + /** {...@inheritdoc} */ + public void tableHeaderCell( String width ) + { + SinkEventAttributeSet att = new SinkEventAttributeSet(); + att.addAttribute( javax.swing.text.html.HTML.Attribute.WIDTH, width ); + + tableHeaderCell( att ); + } + + /** {...@inheritdoc} */ + public void tableHeaderCell( SinkEventAttributes attributes ) + { tableCell( true ); } @@ -758,7 +925,7 @@ */ public void tableHeaderCell_() { - tableCell_( true ); + tableCell_(); } private boolean lastCellWasHeader = false; @@ -795,20 +962,15 @@ } /** - * Ends a table cell. - * - * @param header True if this is a header cell. + * {...@inheritdoc} */ - private void tableCell_( boolean header ) + public void tableCaption() { - markup( "\\end{tabular}" ); - ++cellCount; + tableCaption( null ); } - /** - * {...@inheritdoc} - */ - public void tableCaption() + /** {...@inheritdoc} */ + public void tableCaption( SinkEventAttributes attributes ) { markup( "\\caption{" ); } @@ -826,6 +988,12 @@ */ public void paragraph() { + paragraph( null ); + } + + /** {...@inheritdoc} */ + public void paragraph( SinkEventAttributes attributes ) + { markup( EOL + EOL ); } @@ -842,6 +1010,20 @@ */ public void verbatim( boolean boxed ) { + verbatim( boxed ? SinkEventAttributeSet.BOXED : null ); + } + + /** {...@inheritdoc} */ + public void verbatim( SinkEventAttributes attributes ) + { + boolean boxed = false; + + if ( attributes != null && attributes.isDefined( SinkEventAttributes.DECORATION ) ) + { + boxed = "boxed".equals( + (String) attributes.getAttribute( SinkEventAttributes.DECORATION ) ); + } + markup( EOL + "\\begin{small}" + EOL ); if ( boxed ) @@ -854,7 +1036,6 @@ } verbatimFlag = true; - boxFlag = boxed; } /** @@ -866,7 +1047,6 @@ markup( "\\end{small}" + EOL ); verbatimFlag = false; - boxFlag = false; } /** @@ -874,6 +1054,12 @@ */ public void horizontalRule() { + horizontalRule( null ); + } + + /** {...@inheritdoc} */ + public void horizontalRule( SinkEventAttributes attributes ) + { markup( EOL + "\\begin{center}\\rule[0.5ex]{\\linewidth}{1pt}\\end{center}" + EOL ); } @@ -890,6 +1076,12 @@ */ public void anchor( String name ) { + anchor( name, null ); + } + + /** {...@inheritdoc} */ + public void anchor( String name, SinkEventAttributes attributes ) + { markup( "\\hypertarget{" + name + "}{" ); } @@ -906,6 +1098,12 @@ */ public void link( String name ) { + link( name, null ); + } + + /** {...@inheritdoc} */ + public void link( String name, SinkEventAttributes attributes ) + { // TODO: use \\url for simple links if ( DoxiaUtils.isExternalLink( name ) ) { @@ -978,6 +1176,12 @@ */ public void lineBreak() { + lineBreak( null ); + } + + /** {...@inheritdoc} */ + public void lineBreak( SinkEventAttributes attributes ) + { markup( ( figureFlag || tableFlag || titleFlag || verbatimFlag ) ? EOL : "\\newline" + EOL ); } @@ -994,6 +1198,12 @@ */ public void text( String text ) { + text( text, null ); + } + + /** {...@inheritdoc} */ + public void text( String text, SinkEventAttributes attributes ) + { if ( ignoreText ) { return; @@ -1012,6 +1222,18 @@ } } + /** {...@inheritdoc} */ + public void rawText( String text ) + { + verbatimContent( text ); + } + + /** {...@inheritdoc} */ + public void comment( String comment ) + { + rawText( EOL + "% " + comment ); + } + /** * {...@inheritdoc} * @@ -1211,5 +1433,4 @@ return ""; } } - } Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-latex/src/test/java/org/apache/maven/doxia/module/latex/LatexSinkTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-latex/src/test/java/org/apache/maven/doxia/module/latex/LatexSinkTest.java?rev=795033&r1=795032&r2=795033&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-latex/src/test/java/org/apache/maven/doxia/module/latex/LatexSinkTest.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-latex/src/test/java/org/apache/maven/doxia/module/latex/LatexSinkTest.java Fri Jul 17 10:46:21 2009 @@ -70,9 +70,9 @@ /** {...@inheritdoc} */ protected String getHeadBlock() { - return ((LatexSink) getSink()).defaultSinkCommands() + return ( (LatexSink) getSink() ).defaultSinkCommands() + "\\documentclass[a4paper]{article}" + EOL + EOL - + ((LatexSink) getSink()).defaultPreamble() + + ( (LatexSink) getSink() ).defaultPreamble() + "\\begin{document}" + EOL + EOL; } @@ -134,7 +134,8 @@ /** {...@inheritdoc} */ protected String getDefinitionListBlock( String definum, String definition ) { - return EOL + "\\begin{description}" + EOL + "\\item[\\mbox{" + definum + "}] " + definition + EOL + "\\end{description}" + EOL; + return EOL + "\\begin{description}" + EOL + "\\item[\\mbox{" + definum + "}] " + + definition + EOL + "\\end{description}" + EOL; } /** {...@inheritdoc} */ @@ -223,19 +224,19 @@ protected String getTextBlock( String text ) { // TODO: how to retrieve those outside the sink? - return "\\textasciitilde" + EOL + ",\\_=,\\_\\symbol{45},\\_+,\\_*,\\_[,\\_],\\_\\symbol{60},\\_\\symbol{62},\\_\\{,\\_\\},\\_\\textbackslash"; + return "\\textasciitilde" + EOL + ",\\_=,\\_\\symbol{45},\\_+,\\_*,\\_[,\\_]," + + "\\_\\symbol{60},\\_\\symbol{62},\\_\\{,\\_\\},\\_\\textbackslash"; } /** {...@inheritdoc} */ protected String getRawTextBlock( String text ) { - // TODO: not implemented - return ""; + return "~,_=,_-,_+,_*,_[,_],_<,_>,_{,_},_\\"; } /** {...@inheritdoc} */ protected String getCommentBlock( String text ) { - return ""; + return EOL + "% Simple comment with ----"; } }