|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Listener | Line # 50 | 0 | - | 0 | 0 | - |
-1.0
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| No Tests | |||
| 1 | /* | |
| 2 | * See the NOTICE file distributed with this work for additional | |
| 3 | * information regarding copyright ownership. | |
| 4 | * | |
| 5 | * This is free software; you can redistribute it and/or modify it | |
| 6 | * under the terms of the GNU Lesser General Public License as | |
| 7 | * published by the Free Software Foundation; either version 2.1 of | |
| 8 | * the License, or (at your option) any later version. | |
| 9 | * | |
| 10 | * This software is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | * Lesser General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU Lesser General Public | |
| 16 | * License along with this software; if not, write to the Free | |
| 17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
| 18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
| 19 | */ | |
| 20 | package org.xwiki.rendering.listener; | |
| 21 | ||
| 22 | import java.util.Collections; | |
| 23 | import java.util.Map; | |
| 24 | ||
| 25 | import org.xwiki.rendering.syntax.Syntax; | |
| 26 | ||
| 27 | /** | |
| 28 | * Contains callback events called when a document has been parsed and when it needs to be modified or rendered. More | |
| 29 | * specifically when a document is parsed it generates an {@link org.xwiki.rendering.block.XDOM} object. That object has | |
| 30 | * a {@link org.xwiki.rendering.block.XDOM#traverse(Listener)} method that accepts a {@link Listener} object. For each | |
| 31 | * {@link org.xwiki.rendering.block.Block} element found in the document its | |
| 32 | * {@link org.xwiki.rendering.block.Block#traverse} method is called leading to the generation of events from this | |
| 33 | * interface. | |
| 34 | * <p> | |
| 35 | * Here's an example of usage: | |
| 36 | * </p> | |
| 37 | * | |
| 38 | * <pre> | |
| 39 | * <code> | |
| 40 | * XDOM dom = parser.parse(source); | |
| 41 | * MyListener listener = new MyListener(...); | |
| 42 | * dom.traverse(listener); | |
| 43 | * // At this stage all events have been sent to MyListener. | |
| 44 | * </code> | |
| 45 | * </pre> | |
| 46 | * | |
| 47 | * @version $Id$ | |
| 48 | * @since 1.5M2 | |
| 49 | */ | |
| 50 | public interface Listener extends LinkListener, ImageListener | |
| 51 | { | |
| 52 | /** | |
| 53 | * To use when there is no parameters. | |
| 54 | */ | |
| 55 | Map<String, String> EMPTY_PARAMETERS = Collections.emptyMap(); | |
| 56 | ||
| 57 | /** | |
| 58 | * Start of the document. | |
| 59 | * | |
| 60 | * @param metaData the meta data to associate to the following events, see {@link MetaData} | |
| 61 | * @since 3.0M2 | |
| 62 | */ | |
| 63 | void beginDocument(MetaData metaData); | |
| 64 | ||
| 65 | /** | |
| 66 | * End of the document. | |
| 67 | * | |
| 68 | * @param metaData the meta data associated with the previous events, see {@link MetaData} | |
| 69 | * @since 3.0M2 | |
| 70 | */ | |
| 71 | void endDocument(MetaData metaData); | |
| 72 | ||
| 73 | /** | |
| 74 | * Start of MetaData (eg saving source from where the content is coming from). | |
| 75 | * | |
| 76 | * @param metadata the metadata | |
| 77 | * @since 3.0M2 | |
| 78 | */ | |
| 79 | void beginMetaData(MetaData metadata); | |
| 80 | ||
| 81 | /** | |
| 82 | * End of MetaData. | |
| 83 | * | |
| 84 | * @param metadata the metadata | |
| 85 | * @since 3.0M2 | |
| 86 | */ | |
| 87 | void endMetaData(MetaData metadata); | |
| 88 | ||
| 89 | /** | |
| 90 | * Start a group of elements. Groups are used to allow using standalone elements in list items, table cells, etc. | |
| 91 | * They can also be used to set parameters on a group of standalone elements. | |
| 92 | * | |
| 93 | * @param parameters a generic list of parameters. Example: style="background-color: blue" | |
| 94 | * @since 1.8.3 | |
| 95 | */ | |
| 96 | void beginGroup(Map<String, String> parameters); | |
| 97 | ||
| 98 | /** | |
| 99 | * End of the group. | |
| 100 | * | |
| 101 | * @param parameters a generic list of parameters. Example: style="background-color: blue" | |
| 102 | * @since 1.8.3 | |
| 103 | */ | |
| 104 | void endGroup(Map<String, String> parameters); | |
| 105 | ||
| 106 | /** | |
| 107 | * End of a text formatting block. | |
| 108 | * | |
| 109 | * @param format the formatting type (bold, italic, etc) | |
| 110 | * @param parameters a generic list of parameters. Example: style="background-color: blue" | |
| 111 | * @see Format | |
| 112 | */ | |
| 113 | void beginFormat(Format format, Map<String, String> parameters); | |
| 114 | ||
| 115 | /** | |
| 116 | * End of a text formatting block. | |
| 117 | * | |
| 118 | * @param format the formatting type (bold, italic, etc) | |
| 119 | * @param parameters a generic list of parameters. Example: style="background-color: blue" | |
| 120 | * @see Format | |
| 121 | */ | |
| 122 | void endFormat(Format format, Map<String, String> parameters); | |
| 123 | ||
| 124 | /** | |
| 125 | * Start of a paragraph. | |
| 126 | * | |
| 127 | * @param parameters a generic list of parameters. Example: style="background-color: blue" | |
| 128 | */ | |
| 129 | void beginParagraph(Map<String, String> parameters); | |
| 130 | ||
| 131 | /** | |
| 132 | * End of a paragraph. | |
| 133 | * | |
| 134 | * @param parameters a generic list of parameters. Example: style="background-color: blue" | |
| 135 | */ | |
| 136 | void endParagraph(Map<String, String> parameters); | |
| 137 | ||
| 138 | /** | |
| 139 | * Start of a list. | |
| 140 | * | |
| 141 | * @param listType the type of list (bulleted, numbered, etc) | |
| 142 | * @param parameters a generic list of parameters for the list. Example: "style"/"background-color: blue" | |
| 143 | * @see ListType | |
| 144 | */ | |
| 145 | void beginList(ListType listType, Map<String, String> parameters); | |
| 146 | ||
| 147 | /** | |
| 148 | * Start of a definition list. For example in HTML this is the equivalent of <dl>. | |
| 149 | * | |
| 150 | * @param parameters a generic list of parameters for the list. Example: "style"/"background-color: blue" | |
| 151 | * @since 2.0RC1 | |
| 152 | */ | |
| 153 | void beginDefinitionList(Map<String, String> parameters); | |
| 154 | ||
| 155 | /** | |
| 156 | * End of a list. | |
| 157 | * | |
| 158 | * @param listType the type of list (bulleted, numbered, etc) | |
| 159 | * @param parameters a generic list of parameters for the list. Example: "style"/"background-color: blue" | |
| 160 | * @see ListType | |
| 161 | */ | |
| 162 | void endList(ListType listType, Map<String, String> parameters); | |
| 163 | ||
| 164 | /** | |
| 165 | * End of a definition list. For example in HTML this is the equivalent of </dl>. | |
| 166 | * | |
| 167 | * @param parameters a generic list of parameters for the list. Example: "style"/"background-color: blue" | |
| 168 | * @since 2.0RC1 | |
| 169 | */ | |
| 170 | void endDefinitionList(Map<String, String> parameters); | |
| 171 | ||
| 172 | /** | |
| 173 | * Start of a list item. | |
| 174 | */ | |
| 175 | void beginListItem(); | |
| 176 | ||
| 177 | /** | |
| 178 | * Start of a definition list term. For example in HTML this is the equivalent of <dt>. | |
| 179 | * | |
| 180 | * @since 1.6M2 | |
| 181 | */ | |
| 182 | void beginDefinitionTerm(); | |
| 183 | ||
| 184 | /** | |
| 185 | * Start of a definition list description. For example in HTML this is the equivalent of <dd>. | |
| 186 | * | |
| 187 | * @since 1.6M2 | |
| 188 | */ | |
| 189 | void beginDefinitionDescription(); | |
| 190 | ||
| 191 | /** | |
| 192 | * End of a list item. | |
| 193 | */ | |
| 194 | void endListItem(); | |
| 195 | ||
| 196 | /** | |
| 197 | * End of a definition list term. For example in HTML this is the equivalent of </dt>. | |
| 198 | * | |
| 199 | * @since 1.6M2 | |
| 200 | */ | |
| 201 | void endDefinitionTerm(); | |
| 202 | ||
| 203 | /** | |
| 204 | * End of a definition list description. For example in HTML this is the equivalent of </dd>. | |
| 205 | * | |
| 206 | * @since 1.6M2 | |
| 207 | */ | |
| 208 | void endDefinitionDescription(); | |
| 209 | ||
| 210 | /** | |
| 211 | * Start of a table. | |
| 212 | * | |
| 213 | * @param parameters a generic list of parameters for the table. | |
| 214 | * @since 1.6M2 | |
| 215 | */ | |
| 216 | void beginTable(Map<String, String> parameters); | |
| 217 | ||
| 218 | /** | |
| 219 | * Start of a table row. | |
| 220 | * | |
| 221 | * @param parameters a generic list of parameters for the table row. | |
| 222 | * @since 1.6M2 | |
| 223 | */ | |
| 224 | void beginTableRow(Map<String, String> parameters); | |
| 225 | ||
| 226 | /** | |
| 227 | * Start of a table cell. | |
| 228 | * | |
| 229 | * @param parameters a generic list of parameters for the table cell. | |
| 230 | * @since 1.6M2 | |
| 231 | */ | |
| 232 | void beginTableCell(Map<String, String> parameters); | |
| 233 | ||
| 234 | /** | |
| 235 | * Start of a table head cell. | |
| 236 | * | |
| 237 | * @param parameters a generic list of parameters for the table head cell. | |
| 238 | * @since 1.6M2 | |
| 239 | */ | |
| 240 | void beginTableHeadCell(Map<String, String> parameters); | |
| 241 | ||
| 242 | /** | |
| 243 | * End of a table. | |
| 244 | * | |
| 245 | * @param parameters a generic list of parameters for the table. | |
| 246 | * @since 1.6M2 | |
| 247 | */ | |
| 248 | void endTable(Map<String, String> parameters); | |
| 249 | ||
| 250 | /** | |
| 251 | * End of a table row. | |
| 252 | * | |
| 253 | * @param parameters a generic list of parameters for the table row. | |
| 254 | * @since 1.6M2 | |
| 255 | */ | |
| 256 | void endTableRow(Map<String, String> parameters); | |
| 257 | ||
| 258 | /** | |
| 259 | * End of a table cell. | |
| 260 | * | |
| 261 | * @param parameters a generic list of parameters for the table cell. | |
| 262 | * @since 1.6M2 | |
| 263 | */ | |
| 264 | void endTableCell(Map<String, String> parameters); | |
| 265 | ||
| 266 | /** | |
| 267 | * End of a table head cell. | |
| 268 | * | |
| 269 | * @param parameters a generic list of parameters for the table head cell. | |
| 270 | * @since 1.6M2 | |
| 271 | */ | |
| 272 | void endTableHeadCell(Map<String, String> parameters); | |
| 273 | ||
| 274 | /** | |
| 275 | * Start of a section. | |
| 276 | * | |
| 277 | * @param parameters a generic list of parameters. Example: style="background-color: blue" | |
| 278 | * @see org.xwiki.rendering.listener.HeaderLevel | |
| 279 | */ | |
| 280 | void beginSection(Map<String, String> parameters); | |
| 281 | ||
| 282 | /** | |
| 283 | * End of a section. | |
| 284 | * | |
| 285 | * @param parameters a generic list of parameters. Example: style="background-color: blue" | |
| 286 | * @see org.xwiki.rendering.listener.HeaderLevel | |
| 287 | */ | |
| 288 | void endSection(Map<String, String> parameters); | |
| 289 | ||
| 290 | /** | |
| 291 | * Start of a header. | |
| 292 | * | |
| 293 | * @param level the header level (1, 2, 3, etc) | |
| 294 | * @param id the header unique identifier | |
| 295 | * @param parameters a generic list of parameters. Example: style="background-color: blue" | |
| 296 | * @see org.xwiki.rendering.listener.HeaderLevel | |
| 297 | * @since 1.9M1 | |
| 298 | */ | |
| 299 | void beginHeader(HeaderLevel level, String id, Map<String, String> parameters); | |
| 300 | ||
| 301 | /** | |
| 302 | * End of a header. | |
| 303 | * | |
| 304 | * @param level the header level (1, 2, 3, etc) | |
| 305 | * @param id the header unique identifier | |
| 306 | * @param parameters a generic list of parameters. Example: style="background-color: blue" | |
| 307 | * @see org.xwiki.rendering.listener.HeaderLevel | |
| 308 | * @since 1.9M1 | |
| 309 | */ | |
| 310 | void endHeader(HeaderLevel level, String id, Map<String, String> parameters); | |
| 311 | ||
| 312 | /** | |
| 313 | * Start of marker containing a macro definition. This is a special that Macro Blocks emits when they are executed | |
| 314 | * so that it's possible to reconstruct the initial macro syntax even after Macros have been executed. This is used | |
| 315 | * for exemple by the WYSIWYG editor to let use see the result of executing a macro and still let them modify the | |
| 316 | * macro definition. | |
| 317 | * | |
| 318 | * @param name the macro name | |
| 319 | * @param macroParameters the macro parameters | |
| 320 | * @param content the macro content | |
| 321 | * @param isInline if true the macro is located in a inline content (like paragraph, etc.) | |
| 322 | * @see #onMacro(String, java.util.Map, String, boolean) | |
| 323 | */ | |
| 324 | void beginMacroMarker(String name, Map<String, String> macroParameters, String content, boolean isInline); | |
| 325 | ||
| 326 | /** | |
| 327 | * End of marker containing a macro definition. | |
| 328 | * | |
| 329 | * @param name the macro name | |
| 330 | * @param macroParameters the macro parameters | |
| 331 | * @param content the macro content | |
| 332 | * @param isInline if true the macro is located in a inline content (like paragraph, etc.) | |
| 333 | * @see #beginMacroMarker(String, java.util.Map, String, boolean) | |
| 334 | */ | |
| 335 | void endMacroMarker(String name, Map<String, String> macroParameters, String content, boolean isInline); | |
| 336 | ||
| 337 | /** | |
| 338 | * Start of a quotation. There are one or several quotation lines inside a quotation block. | |
| 339 | * | |
| 340 | * @param parameters a generic list of parameters for the quotation. Example: "style"/"background-color: blue" | |
| 341 | */ | |
| 342 | void beginQuotation(Map<String, String> parameters); | |
| 343 | ||
| 344 | /** | |
| 345 | * End of a quotation. | |
| 346 | * | |
| 347 | * @param parameters a generic list of parameters for the quotation. Example: "style"/"background-color: blue" | |
| 348 | */ | |
| 349 | void endQuotation(Map<String, String> parameters); | |
| 350 | ||
| 351 | /** | |
| 352 | * Start of a quotation line. There can be several quotation lines in a quotation block. | |
| 353 | */ | |
| 354 | void beginQuotationLine(); | |
| 355 | ||
| 356 | /** | |
| 357 | * End of a quotation line. | |
| 358 | */ | |
| 359 | void endQuotationLine(); | |
| 360 | ||
| 361 | /** | |
| 362 | * A new line or line break (it's up to the renderers to decide if it should be outputted as a new line or as a line | |
| 363 | * break in the given syntax). | |
| 364 | */ | |
| 365 | void onNewLine(); | |
| 366 | ||
| 367 | /** | |
| 368 | * A Macro. | |
| 369 | * | |
| 370 | * @param id the macro id (eg "toc" for the TOC macro) | |
| 371 | * @param macroParameters the macro parameters | |
| 372 | * @param content the macro content | |
| 373 | * @param isInline if true the macro is located in a inline content (like paragraph, etc.) | |
| 374 | * @since 1.6M2 | |
| 375 | */ | |
| 376 | void onMacro(String id, Map<String, String> macroParameters, String content, boolean isInline); | |
| 377 | ||
| 378 | /** | |
| 379 | * A word. Note that sentences ar broken into different events: word events, special symbols events, space events, | |
| 380 | * etc. This allows fine-grained actions for listeners. | |
| 381 | * | |
| 382 | * @param word the word encountered | |
| 383 | */ | |
| 384 | void onWord(String word); | |
| 385 | ||
| 386 | /** | |
| 387 | * A space. | |
| 388 | */ | |
| 389 | void onSpace(); | |
| 390 | ||
| 391 | /** | |
| 392 | * A special symbol ("*", "<", ">", "=", quote, etc). Any non alpha numeric character is a special symbol. | |
| 393 | * | |
| 394 | * @param symbol the symbol encountered | |
| 395 | */ | |
| 396 | void onSpecialSymbol(char symbol); | |
| 397 | ||
| 398 | /** | |
| 399 | * A reference/location in a page. In HTML for example this is called an Anchor. It allows pointing to that | |
| 400 | * location, for example in links. Note that there is no wiki syntax for this in general and it's often generated by | |
| 401 | * Macros (such as the TOC Macro). | |
| 402 | * | |
| 403 | * @param name the location name. | |
| 404 | * @since 1.6M1 | |
| 405 | */ | |
| 406 | void onId(String name); | |
| 407 | ||
| 408 | /** | |
| 409 | * Represents an horizontal line. | |
| 410 | * | |
| 411 | * @param parameters a generic list of parameters. Example: style="background-color: blue" | |
| 412 | * @since 1.6M1 | |
| 413 | */ | |
| 414 | void onHorizontalLine(Map<String, String> parameters); | |
| 415 | ||
| 416 | /** | |
| 417 | * Represents an empty line between 2 standalone Blocks. A standalone block is block that is not included in another | |
| 418 | * block. Standalone blocks are Paragraph, Standalone Macro, Lists, Table, etc. | |
| 419 | * | |
| 420 | * @param count the number of empty lines between 2 standalone Blocks | |
| 421 | */ | |
| 422 | void onEmptyLines(int count); | |
| 423 | ||
| 424 | /** | |
| 425 | * A portion of text. | |
| 426 | * | |
| 427 | * @param protectedString the string to protected from rendering | |
| 428 | * @param isInline if true the text content is located in a inline content (like paragraph, etc.) | |
| 429 | * @param parameters a generic list of parameters. Example: style="background-color: blue" | |
| 430 | */ | |
| 431 | void onVerbatim(String protectedString, boolean isInline, Map<String, String> parameters); | |
| 432 | ||
| 433 | /** | |
| 434 | * Some text to inject directly into the listener output without parsing it. For example a HTML macro could inject | |
| 435 | * directly some HTML entered by the user into the rendered HTML output. Note that it's not recommended to use this | |
| 436 | * event in most cases since it can lead to invalid content being generated and in addition most listener | |
| 437 | * implementations will not understand the injected text and will just ignore it. | |
| 438 | * | |
| 439 | * @param rawContent the text to inject | |
| 440 | * @param syntax the syntax in which the text is written. This is useful so that listener implementations can decide | |
| 441 | * whether they can handle direct inject for that syntax | |
| 442 | */ | |
| 443 | void onRawText(String rawContent, Syntax syntax); | |
| 444 | } | |
|
||||||||||||