1
package org.apache.maven.doxia.sink;
4
* Licensed to the Apache Software Foundation (ASF) under one
5
* or more contributor license agreements. See the NOTICE file
6
* distributed with this work for additional information
7
* regarding copyright ownership. The ASF licenses this file
8
* to you under the Apache License, Version 2.0 (the
9
* "License"); you may not use this file except in compliance
10
* with the License. You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* Unless required by applicable law or agreed to in writing,
15
* software distributed under the License is distributed on an
16
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
* KIND, either express or implied. See the License for the
18
* specific language governing permissions and limitations
22
import java.util.LinkedList;
23
import java.util.List;
24
import java.util.Stack;
28
* This sink is used for testing purposes in order to check wether
29
* the input of some parser is well-formed.
31
* @author <a href="mailto:lars@trieloff.net">Lars Trieloff</a>
32
* @version $Id: WellformednessCheckingSink.java 661711 2008-05-30 13:30:24Z ltheussl $
34
public class WellformednessCheckingSink
37
private Stack elements = new Stack();
39
private List errors = new LinkedList();
43
startElement( "head" );
48
checkWellformedness( "head" );
53
startElement( "body" );
58
checkWellformedness( "body" );
61
public void section1()
63
startElement( "section1" );
66
public void section1_()
68
checkWellformedness( "section1" );
71
public void section2()
73
startElement( "section2" );
76
public void section2_()
78
checkWellformedness( "section2" );
81
public void section3()
83
startElement( "section3" );
86
public void section3_()
88
checkWellformedness( "section3" );
91
public void section4()
93
startElement( "section4" );
96
public void section4_()
98
checkWellformedness( "section4" );
101
public void section5()
103
startElement( "section5" );
106
public void section5_()
108
checkWellformedness( "section5" );
113
startElement( "list" );
118
checkWellformedness( "list" );
121
public void listItem()
123
startElement( "listItem" );
126
public void listItem_()
128
checkWellformedness( "listItem" );
131
public void numberedList( int numbering )
133
startElement( "numberedList" );
136
public void numberedList_()
138
checkWellformedness( "numberedList" );
141
public void numberedListItem()
143
startElement( "numberedListItem" );
146
public void numberedListItem_()
148
checkWellformedness( "numberedListItem" );
151
public void definitionList()
153
startElement( "definitionList" );
156
public void definitionList_()
158
checkWellformedness( "definitionList" );
161
public void definitionListItem()
163
startElement( "definitionListItem" );
166
public void definitionListItem_()
168
checkWellformedness( "definitionListItem" );
171
public void definition()
173
startElement( "definition" );
176
public void definition_()
178
checkWellformedness( "definition" );
183
startElement( "figure" );
186
public void figure_()
188
checkWellformedness( "figure" );
193
startElement( "table" );
198
checkWellformedness( "table" );
201
public void tableRows( int[] justification, boolean grid )
203
startElement( "tableRows" );
206
public void tableRows_()
208
checkWellformedness( "tableRows" );
211
public void tableRow()
213
startElement( "tableRow" );
216
public void tableRow_()
218
checkWellformedness( "tableRow" );
223
startElement( "title" );
228
checkWellformedness( "title" );
233
startElement( "author" );
236
public void author_()
238
checkWellformedness( "author" );
243
startElement( "date" );
248
checkWellformedness( "date" );
251
public void sectionTitle()
253
startElement( "sectionTitle" );
256
public void sectionTitle_()
258
checkWellformedness( "sectionTitle" );
261
public void sectionTitle1()
263
startElement( "sectionTitle1" );
266
public void sectionTitle1_()
268
checkWellformedness( "sectionTitle1" );
271
public void sectionTitle2()
273
startElement( "sectionTitle2" );
276
public void sectionTitle2_()
278
checkWellformedness( "sectionTitle2" );
281
public void sectionTitle3()
283
startElement( "sectionTitle3" );
286
public void sectionTitle3_()
288
checkWellformedness( "sectionTitle3" );
291
public void sectionTitle4()
293
startElement( "sectionTitle4" );
296
public void sectionTitle4_()
298
checkWellformedness( "sectionTitle4" );
301
public void sectionTitle5()
303
startElement( "sectionTitle5" );
306
public void sectionTitle5_()
308
checkWellformedness( "sectionTitle5" );
311
public void paragraph()
313
startElement( "paragraph" );
316
public void paragraph_()
318
checkWellformedness( "paragraph" );
321
public void verbatim( boolean boxed )
323
startElement( "verbatim" );
326
public void verbatim_()
328
checkWellformedness( "verbatim" );
331
public void definedTerm()
333
startElement( "definedTerm" );
336
public void definedTerm_()
338
checkWellformedness( "definedTerm" );
341
public void figureCaption()
343
startElement( "figureCaption" );
346
public void figureCaption_()
348
checkWellformedness( "figureCaption" );
351
public void tableCell()
353
startElement( "tableCell" );
356
public void tableCell( String width )
358
startElement( "tableCell" );
361
public void tableCell_()
363
checkWellformedness( "tableCell" );
366
public void tableHeaderCell()
368
startElement( "tableHeaderCell" );
371
public void tableHeaderCell( String width )
373
startElement( "tableHeaderCell" );
376
public void tableHeaderCell_()
378
checkWellformedness( "tableHeaderCell" );
381
public void tableCaption()
383
startElement( "tableCaption" );
386
public void tableCaption_()
388
checkWellformedness( "tableCaption" );
391
public void figureGraphics( String name )
395
public void horizontalRule()
399
public void pageBreak()
403
public void anchor( String name )
405
startElement( "anchor" );
408
public void anchor_()
410
checkWellformedness( "anchor" );
413
public void link( String name )
415
startElement( "link" );
420
checkWellformedness( "link" );
425
startElement( "italic" );
428
public void italic_()
430
checkWellformedness( "italic" );
435
startElement( "bold" );
440
checkWellformedness( "bold" );
443
public void monospaced()
445
startElement( "monospaced" );
448
public void monospaced_()
450
checkWellformedness( "monospaced" );
453
public void lineBreak()
457
public void nonBreakingSpace()
461
public void text( String text )
465
public void rawText( String text )
470
public void comment( String comment )
483
* Finds out wether the wellformedness-contraints of the model have been
486
* @return false for non-wellformed models
488
public boolean isWellformed()
490
return errors.size() == 0;
494
* Gets the offending element that breaks the wellformedness as well
495
* as the exepected element.
497
* @return the expected and acual elements
499
public String getOffender()
501
if ( isWellformed() )
506
return (String) errors.get( errors.size() - 1 );
510
* Gets the list of errors found during wellformedness-check
512
* @return a list of String of error messages
514
public List getOffenders()
520
* Checks wether a newly encountered end-tag breaks the wellformedness
523
* @param actual the local-name of the encountered element
525
private void checkWellformedness( String actual )
527
String expected = (String) elements.pop();
529
if ( !expected.equals( actual ) )
531
errors.add( "Encountered closing: " + actual + ", expected " + expected );
536
* Starts a new element and puts it on the stack in order to calculate
537
* wellformedness of the model at a later point of time.
539
* @param string the local-name of the start-tag
541
private void startElement( String string )
543
elements.push( string );
547
public void head( SinkEventAttributes attributes )
553
public void title( SinkEventAttributes attributes )
559
public void author( SinkEventAttributes attributes )
565
public void date( SinkEventAttributes attributes )
571
public void body( SinkEventAttributes attributes )
577
public void section( int level, SinkEventAttributes attributes )
579
startElement( "section" + level );
583
public void section_( int level )
585
checkWellformedness( "section" + level );
589
public void sectionTitle( int level, SinkEventAttributes attributes )
591
startElement( "sectionTitle" + level );
595
public void sectionTitle_( int level )
597
checkWellformedness( "sectionTitle" + level );
601
public void list( SinkEventAttributes attributes )
607
public void listItem( SinkEventAttributes attributes )
613
public void numberedList( int numbering, SinkEventAttributes attributes )
615
numberedList( numbering );
619
public void numberedListItem( SinkEventAttributes attributes )
625
public void definitionList( SinkEventAttributes attributes )
631
public void definitionListItem( SinkEventAttributes attributes )
633
definitionListItem();
637
public void definition( SinkEventAttributes attributes )
643
public void definedTerm( SinkEventAttributes attributes )
649
public void figure( SinkEventAttributes attributes )
655
public void figureCaption( SinkEventAttributes attributes )
661
public void figureGraphics( String src, SinkEventAttributes attributes )
663
figureGraphics( src );
667
public void table( SinkEventAttributes attributes )
673
public void tableRow( SinkEventAttributes attributes )
679
public void tableCell( SinkEventAttributes attributes )
685
public void tableHeaderCell( SinkEventAttributes attributes )
691
public void tableCaption( SinkEventAttributes attributes )
697
public void paragraph( SinkEventAttributes attributes )
703
public void verbatim( SinkEventAttributes attributes )
709
public void horizontalRule( SinkEventAttributes attributes )
715
public void anchor( String name, SinkEventAttributes attributes )
721
public void link( String name, SinkEventAttributes attributes )
727
public void lineBreak( SinkEventAttributes attributes )
733
public void text( String text, SinkEventAttributes attributes )
739
public void unknown( String name, Object[] requiredParams, SinkEventAttributes attributes )