001/* 002 Licensed to the Apache Software Foundation (ASF) under one 003 or more contributor license agreements. See the NOTICE file 004 distributed with this work for additional information 005 regarding copyright ownership. The ASF licenses this file 006 to you under the Apache License, Version 2.0 (the 007 "License"); you may not use this file except in compliance 008 with the License. You may obtain a copy of the License at 009 010 http://www.apache.org/licenses/LICENSE-2.0 011 012 Unless required by applicable law or agreed to in writing, 013 software distributed under the License is distributed on an 014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 KIND, either express or implied. See the License for the 016 specific language governing permissions and limitations 017 under the License. 018*/ 019package org.apache.wiki.htmltowiki; 020 021import org.jdom2.Element; 022import org.jdom2.JDOMException; 023import org.jdom2.Text; 024 025import java.io.PrintWriter; 026import java.util.Map; 027import java.util.Stack; 028 029 030/** 031 * Decorates Xhtml elements with wiki syntax 032 */ 033public interface SyntaxDecorator { 034 035 /** 036 * Prepares the syntax decorator. 037 * 038 * @param out writer that will hold the resulting wiki markup. 039 * @param liStack stack containing the amount of nested {@code li}s. 040 * @param preStack stack containing the amount of nested {@code pre}s. 041 * @param outTrimmer writer capable of trimming whitespaces and of checking if it's currently writing a line start. 042 * @param config xhtml to wiki configuration object. 043 * @param chain chain (in the chain of responsabilities pattern) that is expected to be called by the different xhtml decorations. 044 */ 045 void init( PrintWriter out, Stack< String > liStack, Stack< String > preStack, WhitespaceTrimWriter outTrimmer, XHtmlToWikiConfig config, XHtmlElementToWikiTranslator chain ); 046 047 /** 048 * Decorates an {@code a} element. 049 * 050 * @param e XHTML element being translated. 051 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 052 */ 053 void a( Element e ) throws JDOMException; 054 055 /** 056 * Decorates a {@code br} element. 057 * 058 * @param base parent of the XHTML element being translated. 059 * @param e XHTML element being translated. 060 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 061 */ 062 void br( Element base, Element e ) throws JDOMException; 063 064 /** 065 * Decorates a {@code code} ot {@code tt} element. 066 * 067 * @param e XHTML element being translated. 068 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 069 */ 070 void code( Element e ) throws JDOMException; 071 072 /** 073 * Decorates a {@code dd} element. 074 * 075 * @param e XHTML element being translated. 076 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 077 */ 078 void dd( Element e ) throws JDOMException; 079 080 /** 081 * Decorates a {@code dl} element. 082 * 083 * @param e XHTML element being translated. 084 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 085 */ 086 void dl( Element e ) throws JDOMException; 087 088 /** 089 * Decorates a {@code dt} element. 090 * 091 * @param e XHTML element being translated. 092 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 093 */ 094 void dt( Element e ) throws JDOMException; 095 096 /** 097 * Decorates an {@code em}, {@code i} or {@code address} element. 098 * 099 * @param e XHTML element being translated. 100 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 101 */ 102 void em( Element e ) throws JDOMException; 103 104 /** 105 * Decorates a {@code form} element. 106 * 107 * @param e XHTML element being translated. 108 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 109 */ 110 void form( Element e ) throws JDOMException; 111 112 /** 113 * Decorates an {@code hr} element. 114 * 115 * @param e XHTML element being translated. 116 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 117 */ 118 void hr( Element e ) throws JDOMException; 119 120 /** 121 * Decorates an {@code h1} element. 122 * 123 * @param e XHTML element being translated. 124 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 125 */ 126 void h1( Element e ) throws JDOMException; 127 128 /** 129 * Decorates an {@code h2} element. 130 * 131 * @param e XHTML element being translated. 132 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 133 */ 134 void h2( Element e ) throws JDOMException; 135 136 /** 137 * Decorates an {@code h3} element. 138 * 139 * @param e XHTML element being translated. 140 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 141 */ 142 void h3( Element e ) throws JDOMException; 143 144 /** 145 * Decorates an {@code h4} element. 146 * 147 * @param e XHTML element being translated. 148 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 149 */ 150 void h4( Element e ) throws JDOMException; 151 152 /** 153 * Decorates an image element. This is a terminal operation, that is, chain is not expected to be called by this method. 154 * 155 * @param src image source 156 * @param imageAttrs image attributes 157 */ 158 void image( String src, Map< String, Object > imageAttrs ); 159 160 /** 161 * Decorates an image element. This is a terminal operation, that is, chain is not expected to be called by this method. 162 * 163 * @param e XHTML element being translated. 164 */ 165 void img( Element e ); 166 167 /** 168 * Decorates an {@code input} element. 169 * 170 * @param e XHTML element being translated. 171 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 172 */ 173 void input( Element e ) throws JDOMException; 174 175 /** 176 * Decorates a {@code li} element. 177 * 178 * @param base parent of the XHTML element being translated. 179 * @param e XHTML element being translated. 180 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 181 */ 182 void li( Element base, Element e ) throws JDOMException; 183 184 /** 185 * Decorates an {@code ol} element. 186 * 187 * @param e XHTML element being translated. 188 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 189 */ 190 void ol( Element e ) throws JDOMException; 191 192 /** 193 * Decorates an {@code option} element. 194 * 195 * @param base parent of the XHTML element being translated. 196 * @param e XHTML element being translated. 197 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 198 */ 199 void option( Element base, Element e ) throws JDOMException; 200 201 /** 202 * Decorates a {@code p} element. 203 * 204 * @param e XHTML element being translated. 205 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 206 */ 207 void p( Element e ) throws JDOMException; 208 209 /** 210 * Decorates a text paragraph. 211 * 212 * @param dto XHTML element being translated. 213 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 214 */ 215 void paragraph( XHtmlElementToWikiTranslator.ElementDecoratorData dto ) throws JDOMException; 216 217 /** 218 * Decorates a {@code pre} element. 219 * 220 * @param e XHTML element being translated. 221 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 222 */ 223 void pre( Element e ) throws JDOMException; 224 225 /** 226 * Decorates a {@code strong} or {@code b} element. 227 * 228 * @param e XHTML element being translated. 229 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 230 */ 231 void strong( Element e ) throws JDOMException; 232 233 /** 234 * Decorates a {@code table} element. 235 * 236 * @param e XHTML element being translated. 237 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 238 */ 239 void table( Element e ) throws JDOMException; 240 241 /** 242 * Decorates an {@code td} element. 243 * 244 * @param e XHTML element being translated. 245 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 246 */ 247 void td( Element e ) throws JDOMException; 248 249 /** 250 * Decorates a text element. This is a terminal operation, that is, chain is not expected to be called by this method. 251 * 252 * @param e XHTML element being translated. 253 */ 254 void text( Text e ); 255 256 /** 257 * Decorates a {@code textarea} element. 258 * 259 * @param e XHTML element being translated. 260 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 261 */ 262 void textarea( Element e ) throws JDOMException; 263 264 /** 265 * Decorates a {@code th} element. 266 * 267 * @param e XHTML element being translated. 268 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 269 */ 270 void th( Element e ) throws JDOMException; 271 272 /** 273 * Decorates a {@code tr} element. 274 * 275 * @param e XHTML element being translated. 276 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 277 */ 278 void tr( Element e ) throws JDOMException; 279 280 /** 281 * Decorates a {@code select} element. 282 * 283 * @param e XHTML element being translated. 284 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 285 */ 286 void select( Element e ) throws JDOMException; 287 288 /** 289 * Decorates a {@code strike} element. 290 * 291 * @param e XHTML element being translated. 292 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 293 */ 294 void strike( Element e ) throws JDOMException; 295 296 /** 297 * Decorates a {@code sub} element. 298 * 299 * @param e XHTML element being translated. 300 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 301 */ 302 void sub( Element e ) throws JDOMException; 303 304 /** 305 * Decorates an {@code sup} element. 306 * 307 * @param e XHTML element being translated. 308 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 309 */ 310 void sup( Element e ) throws JDOMException; 311 312 /** 313 * Decorates an {@code ul} element. 314 * 315 * @param e XHTML element being translated. 316 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 317 */ 318 void ul( Element e ) throws JDOMException; 319 320 /** 321 * Decorates an {@code underline} element. 322 * 323 * @param e XHTML element being translated. 324 * @throws JDOMException if an error has ocurred parsing the xhtml chain. 325 */ 326 void underline( Element e ) throws JDOMException; 327 328}