001package org.apache.maven.doxia.module.apt; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.Writer; 023 024import org.apache.maven.doxia.markup.Markup; 025import org.apache.maven.doxia.sink.Sink; 026import org.apache.maven.doxia.sink.impl.AbstractSinkTest; 027import org.codehaus.plexus.util.StringUtils; 028 029/** 030 * Test the <code>AptSink</code> class 031 * 032 * @see AptSink 033 */ 034public class AptSinkTest extends AbstractSinkTest 035{ 036 /** {@inheritDoc} */ 037 protected String outputExtension() 038 { 039 return "apt"; 040 } 041 042 /** {@inheritDoc} */ 043 protected Sink createSink( Writer writer ) 044 { 045 return new AptSink( writer ); 046 } 047 048 /** {@inheritDoc} */ 049 protected boolean isXmlSink() 050 { 051 return false; 052 } 053 054 /** {@inheritDoc} */ 055 protected String getTitleBlock( String title ) 056 { 057 return title; 058 } 059 060 /** {@inheritDoc} */ 061 protected String getAuthorBlock( String author ) 062 { 063 return author; 064 } 065 066 /** {@inheritDoc} */ 067 protected String getDateBlock( String date ) 068 { 069 return date; 070 } 071 072 /** {@inheritDoc} */ 073 protected String getHeadBlock() 074 { 075 return AptMarkup.HEADER_START_MARKUP + EOL + AptMarkup.HEADER_START_MARKUP + EOL + AptMarkup.HEADER_START_MARKUP 076 + EOL + AptMarkup.HEADER_START_MARKUP + EOL; 077 } 078 079 /** {@inheritDoc} */ 080 protected String getBodyBlock() 081 { 082 return ""; 083 } 084 085 /** {@inheritDoc} */ 086 protected String getSectionTitleBlock( String title ) 087 { 088 return title; 089 } 090 091 /** {@inheritDoc} */ 092 protected String getSection1Block( String title ) 093 { 094 return EOL + title + EOL + EOL + EOL; 095 } 096 097 /** {@inheritDoc} */ 098 protected String getSection2Block( String title ) 099 { 100 return EOL + AptMarkup.SECTION_TITLE_START_MARKUP + title + EOL + EOL + EOL; 101 } 102 103 /** {@inheritDoc} */ 104 protected String getSection3Block( String title ) 105 { 106 return EOL + StringUtils.repeat( String.valueOf( AptMarkup.SECTION_TITLE_START_MARKUP ), 2 ) 107 + title + EOL + EOL + EOL; 108 } 109 110 /** {@inheritDoc} */ 111 protected String getSection4Block( String title ) 112 { 113 return EOL + StringUtils.repeat( String.valueOf( AptMarkup.SECTION_TITLE_START_MARKUP ), 3 ) 114 + title + EOL + EOL + EOL; 115 } 116 117 /** {@inheritDoc} */ 118 protected String getSection5Block( String title ) 119 { 120 return EOL + StringUtils.repeat( String.valueOf( AptMarkup.SECTION_TITLE_START_MARKUP ), 4 ) 121 + title + EOL + EOL + EOL; 122 } 123 124 /** {@inheritDoc} */ 125 protected String getListBlock( String item ) 126 { 127 return EOL + EOL + Markup.SPACE + "" + AptMarkup.LIST_START_MARKUP + "" + Markup.SPACE + item + EOL + EOL 128 + Markup.SPACE + "" + AptMarkup.LIST_END_MARKUP + EOL; 129 } 130 131 /** {@inheritDoc} */ 132 protected String getNumberedListBlock( String item ) 133 { 134 return EOL + EOL + Markup.SPACE + "" + Markup.LEFT_SQUARE_BRACKET + "" 135 + Markup.LEFT_SQUARE_BRACKET + AptMarkup.NUMBERING_LOWER_ROMAN_CHAR + "" 136 + Markup.RIGHT_SQUARE_BRACKET + "" + Markup.RIGHT_SQUARE_BRACKET 137 + Markup.SPACE + item + EOL + EOL + Markup.SPACE + "" + AptMarkup.LIST_END_MARKUP + EOL; 138 } 139 140 /** {@inheritDoc} */ 141 protected String getDefinitionListBlock( String definum, String definition ) 142 { 143 return EOL + EOL + Markup.SPACE + "" + Markup.LEFT_SQUARE_BRACKET + definum 144 + Markup.RIGHT_SQUARE_BRACKET + "" + Markup.SPACE + definition + EOL + EOL 145 + Markup.SPACE + "" + AptMarkup.LIST_END_MARKUP + EOL; 146 } 147 148 /** {@inheritDoc} */ 149 protected String getFigureBlock( String source, String caption ) 150 { 151 String figureBlock = EOL + Markup.LEFT_SQUARE_BRACKET + source + Markup.RIGHT_SQUARE_BRACKET + Markup.SPACE; 152 if( caption != null ) 153 { 154 figureBlock += caption + EOL; 155 } 156 return figureBlock; 157 } 158 159 /** {@inheritDoc} */ 160 protected String getTableBlock( String cell, String caption ) 161 { 162 return EOL + AptMarkup.TABLE_ROW_START_MARKUP + AptMarkup.TABLE_COL_CENTERED_ALIGNED_MARKUP + EOL + cell 163 + AptMarkup.TABLE_ROW_SEPARATOR_MARKUP + EOL + AptMarkup.TABLE_ROW_START_MARKUP 164 + AptMarkup.TABLE_COL_CENTERED_ALIGNED_MARKUP + EOL + caption + EOL; 165 } 166 167 /** {@inheritDoc} */ 168 protected String getParagraphBlock( String text ) 169 { 170 return EOL + Markup.SPACE + text + EOL + EOL; 171 } 172 173 /** {@inheritDoc} */ 174 protected String getVerbatimBlock( String text ) 175 { 176 return EOL + EOL + AptMarkup.BOXED_VERBATIM_START_MARKUP + EOL + text + EOL 177 + AptMarkup.BOXED_VERBATIM_START_MARKUP + EOL; 178 } 179 180 /** {@inheritDoc} */ 181 protected String getHorizontalRuleBlock() 182 { 183 return EOL + AptMarkup.HORIZONTAL_RULE_MARKUP + EOL; 184 } 185 186 /** {@inheritDoc} */ 187 protected String getPageBreakBlock() 188 { 189 return EOL + AptMarkup.PAGE_BREAK_MARKUP + EOL; 190 } 191 192 /** {@inheritDoc} */ 193 protected String getAnchorBlock( String anchor ) 194 { 195 return AptMarkup.ANCHOR_START_MARKUP + anchor + AptMarkup.ANCHOR_END_MARKUP; 196 } 197 198 /** {@inheritDoc} */ 199 protected String getLinkBlock( String link, String text ) 200 { 201 String lnk = link.startsWith( "#" ) ? link.substring( 1 ) : link; 202 return AptMarkup.LINK_START_1_MARKUP + lnk + AptMarkup.LINK_START_2_MARKUP + text + AptMarkup.LINK_END_MARKUP; 203 } 204 205 /** {@inheritDoc} */ 206 protected String getItalicBlock( String text ) 207 { 208 return AptMarkup.ITALIC_START_MARKUP + text + AptMarkup.ITALIC_END_MARKUP; 209 } 210 211 /** {@inheritDoc} */ 212 protected String getBoldBlock( String text ) 213 { 214 return AptMarkup.BOLD_START_MARKUP + text + AptMarkup.BOLD_END_MARKUP; 215 } 216 217 /** {@inheritDoc} */ 218 protected String getMonospacedBlock( String text ) 219 { 220 return AptMarkup.MONOSPACED_START_MARKUP + text + AptMarkup.MONOSPACED_END_MARKUP; 221 } 222 223 /** {@inheritDoc} */ 224 protected String getLineBreakBlock() 225 { 226 return String.valueOf( AptMarkup.BACKSLASH ) + EOL; 227 } 228 229 /** {@inheritDoc} */ 230 protected String getNonBreakingSpaceBlock() 231 { 232 return AptMarkup.NON_BREAKING_SPACE_MARKUP; 233 } 234 235 /** {@inheritDoc} */ 236 protected String getTextBlock( String text ) 237 { 238 // "\\~, \\=, \\-, \\+, \\*, \\[, \\], \\<, \\>, \\{, \\}, \\\\" 239 StringBuilder sb = new StringBuilder(); 240 sb.append( getSpecialCharacters( AptMarkup.COMMENT ) ).append( ",_" ); 241 sb.append( getSpecialCharacters( Markup.EQUAL ) ).append( ",_" ); 242 sb.append( getSpecialCharacters( Markup.MINUS ) ).append( ",_" ); 243 sb.append( getSpecialCharacters( Markup.PLUS ) ).append( ",_" ); 244 sb.append( getSpecialCharacters( Markup.STAR ) ).append( ",_" ); 245 sb.append( getSpecialCharacters( Markup.LEFT_SQUARE_BRACKET ) ).append( ",_" ); 246 sb.append( getSpecialCharacters( Markup.RIGHT_SQUARE_BRACKET ) ).append( ",_" ); 247 sb.append( getSpecialCharacters( Markup.LESS_THAN ) ).append( ",_" ); 248 sb.append( getSpecialCharacters( Markup.GREATER_THAN ) ).append( ",_" ); 249 sb.append( getSpecialCharacters( Markup.LEFT_CURLY_BRACKET ) ).append( ",_" ); 250 sb.append( getSpecialCharacters( Markup.RIGHT_CURLY_BRACKET ) ).append( ",_" ); 251 sb.append( getSpecialCharacters( AptMarkup.BACKSLASH ) ); 252 253 return sb.toString(); 254 } 255 256 /** {@inheritDoc} */ 257 protected String getRawTextBlock( String text ) 258 { 259 return text; 260 } 261 262 /** 263 * Add a backslash for a special markup character 264 * 265 * @param c 266 * @return the character with a backslash before 267 */ 268 private static String getSpecialCharacters( char c ) 269 { 270 return AptMarkup.BACKSLASH + "" + c; 271 } 272 273 /** {@inheritDoc} */ 274 protected String getCommentBlock( String text ) 275 { 276 return "~~" + text; 277 } 278}