View Javadoc
1   package org.apache.maven.doxia.sink;
2   
3   /*
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
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
22  import java.io.StringWriter;
23  import java.io.Writer;
24  
25  import javax.swing.text.html.HTML.Attribute;
26  
27  import junit.framework.TestCase;
28  
29  import org.apache.maven.doxia.markup.Markup;
30  
31  /**
32   * Test for XhtmlBaseSink.
33   *
34   * @author ltheussl
35   * @version $Id: XhtmlBaseSinkTest.java 1465348 2013-04-07 09:15:29Z rfscholte $
36   * @since 1.1
37   */
38  public class XhtmlBaseSinkTest
39      extends TestCase
40  {
41      protected static final String LS = Markup.EOL;
42      private final SinkEventAttributes attributes = SinkEventAttributeSet.BOLD;
43      private XhtmlBaseSink sink;
44      private Writer writer;
45  
46      /**
47       * Set up the writer.
48       *
49       * @throws java.lang.Exception if any.
50       */
51      @Override
52      protected void setUp()
53              throws Exception
54      {
55          super.setUp();
56          writer =  new StringWriter();
57      }
58  
59      /** @throws Exception */
60      public void testSpaceAfterClosingTag()
61          throws Exception
62      {
63          // DOXIA-189
64          try
65          {
66              sink = new XhtmlBaseSink( writer );
67  
68              sink.paragraph();
69              sink.text( "There should be no space before the " );
70              sink.italic();
71              sink.text( "period" );
72              sink.italic_();
73              sink.text( "." );
74              sink.paragraph_();
75          }
76          finally
77          {
78              if ( sink != null )
79              {
80                  sink.close();
81              }
82          }
83  
84          String actual = writer.toString();
85          String expected = "<p>There should be no space before the <i>period</i>.</p>";
86  
87          assertEquals( expected, actual );
88      }
89  
90      /**
91       * @throws Exception if any
92       */
93      public void testNestedTables()
94          throws Exception
95      {
96          // DOXIA-177
97          try
98          {
99              sink = new XhtmlBaseSink( writer );
100 
101             sink.table();
102             sink.tableRows( new int[] { Sink.JUSTIFY_CENTER }, false );
103             sink.tableRow();
104             sink.tableCell();
105             sink.text( "cell11" );
106             sink.tableCell_();
107             sink.tableCell();
108             sink.text( "cell12" );
109             sink.tableCell_();
110             sink.tableRow_();
111 
112             sink.tableRow();
113             sink.tableCell();
114             sink.table( SinkEventAttributeSet.LEFT );
115             sink.tableRows( new int[] { Sink.JUSTIFY_LEFT }, false );
116             sink.tableRow();
117             sink.tableCell();
118             sink.text( "nestedTable1Cell11" );
119             sink.tableCell_();
120             sink.tableCell();
121             sink.text( "nestedTable1Cell12" );
122             sink.tableCell_();
123             sink.tableRow_();
124             sink.tableRow();
125             sink.tableCell();
126 
127             sink.table( SinkEventAttributeSet.RIGHT );
128             sink.tableRows( new int[] { Sink.JUSTIFY_RIGHT }, false );
129             sink.tableRow();
130             sink.tableCell();
131             sink.text( "nestedTable2Cell11" );
132             sink.tableCell_();
133             sink.tableCell();
134             sink.text( "nestedTable2Cell12" );
135             sink.tableCell_();
136             sink.tableRow_();
137             sink.tableRow();
138             sink.tableCell();
139             sink.text( "nestedTable2Cell21" );
140             sink.tableCell_();
141             sink.tableCell();
142             sink.text( "nestedTable2Cell22" );
143             sink.tableCell_();
144             sink.tableRow_();
145             sink.tableRows_();
146             sink.tableCaption();
147             sink.text( "caption3" );
148             sink.tableCaption_();
149             sink.table_();
150 
151             sink.tableCell_();
152             sink.tableCell();
153             sink.text( "nestedTable1Cell22" );
154             sink.tableCell_();
155             sink.tableRow_();
156             sink.tableRows_();
157             sink.tableCaption();
158             sink.text( "caption2" );
159             sink.tableCaption_();
160             sink.table_();
161 
162             sink.tableCell_();
163             sink.tableCell();
164             sink.text( "cell22" );
165             sink.tableCell_();
166             sink.tableRow_();
167             sink.tableRows_();
168             sink.tableCaption();
169             sink.text( "caption1" );
170             sink.tableCaption_();
171             sink.table_();
172         }
173         finally
174         {
175             sink.close();
176         }
177 
178         String actual = writer.toString();
179         assertTrue( actual.indexOf( "<table align=\"center\" border=\"0\" class=\"bodyTable\">"
180             + "<caption>caption1</caption>" ) != 1 );
181         assertTrue( actual.indexOf( "<table border=\"0\" class=\"bodyTable\" align=\"left\">"
182             + "<caption>caption2</caption>" ) != 1 );
183         assertTrue( actual.indexOf( "<table align=\"center\" border=\"0\" class=\"bodyTable\">"
184             + "<caption>caption3</caption>" ) != 1 );
185 
186         assertTrue( actual.indexOf( "<td align=\"center\">cell11</td>" ) != 1 );
187         assertTrue( actual.indexOf( "<td align=\"left\">nestedTable1Cell11</td>" ) != 1 );
188         assertTrue( actual.indexOf( "<td align=\"right\">nestedTable2Cell11</td>" ) != 1 );
189         assertTrue( actual.indexOf( "<td align=\"left\">nestedTable1Cell22</td>" ) != 1 );
190         assertTrue( actual.indexOf( "<td align=\"center\">cell22</td>" ) != 1 );
191     }
192 
193     /**
194      * Test of section method, of class XhtmlBaseSink.
195      */
196     public void testSection()
197     {
198         final int level = XhtmlBaseSink.SECTION_LEVEL_1;
199 
200         try
201         {
202             sink = new XhtmlBaseSink( writer );
203 
204             sink.section( level, attributes );
205             sink.sectionTitle( level, attributes );
206             sink.sectionTitle_( level );
207             sink.section_( level );
208         }
209         finally
210         {
211             sink.close();
212         }
213 
214         assertEquals( "<div class=\"section\" style=\"bold\">" + LS + "<h2 style=\"bold\"></h2></div>", writer.toString() );
215     }
216 
217     /**
218      * Test of section method, of class XhtmlBaseSink.
219      */
220     public void testSectionAttributes()
221     {
222         final int level = XhtmlBaseSink.SECTION_LEVEL_1;
223         final SinkEventAttributeSet set = new SinkEventAttributeSet(
224             new String[] {"name", "section name", "class", "foo", "id", "bar"} );
225 
226         try
227         {
228             sink = new XhtmlBaseSink( writer );
229 
230             sink.section( level, set );
231             sink.sectionTitle( level, null );
232             sink.sectionTitle_( level );
233             sink.section_( level );
234         }
235         finally
236         {
237             sink.close();
238         }
239 
240         assertEquals( "<div class=\"foo\" id=\"bar\">" + LS + "<h2></h2></div>", writer.toString() );
241     }
242 
243     /**
244      * Test of section1 method, of class XhtmlBaseSink.
245      */
246     public void testSection1()
247     {
248 
249         try
250         {
251             sink = new XhtmlBaseSink( writer );
252 
253             sink.section1();
254             sink.sectionTitle1();
255             sink.sectionTitle1_();
256             sink.section1_();
257         }
258         finally
259         {
260             sink.close();
261         }
262 
263         assertEquals( "<div class=\"section\">" + LS + "<h2></h2></div>", writer.toString() );
264     }
265 
266     /**
267      * Test of section2 method, of class XhtmlBaseSink.
268      */
269     public void testSection2()
270     {
271 
272         try
273         {
274             sink = new XhtmlBaseSink( writer );
275 
276             sink.section2();
277             sink.sectionTitle2();
278             sink.sectionTitle2_();
279             sink.section2_();
280         }
281         finally
282         {
283             sink.close();
284         }
285 
286         assertEquals( "<div class=\"section\">" + LS + "<h3></h3></div>", writer.toString() );
287     }
288 
289     /**
290      * Test of section3 method, of class XhtmlBaseSink.
291      */
292     public void testSection3()
293     {
294 
295         try
296         {
297             sink = new XhtmlBaseSink( writer );
298 
299             sink.section3();
300             sink.sectionTitle3();
301             sink.sectionTitle3_();
302             sink.section3_();
303         }
304         finally
305         {
306             sink.close();
307         }
308 
309         assertEquals( "<div class=\"section\">" + LS + "<h4></h4></div>", writer.toString() );
310     }
311 
312     /**
313      * Test of section4 method, of class XhtmlBaseSink.
314      */
315     public void testSection4()
316     {
317         try
318         {
319             sink = new XhtmlBaseSink( writer );
320 
321             sink.section4();
322             sink.sectionTitle4();
323             sink.sectionTitle4_();
324             sink.section4_();
325         }
326         finally
327         {
328             sink.close();
329         }
330 
331         assertEquals( "<div class=\"section\">" + LS + "<h5></h5></div>", writer.toString() );
332     }
333 
334     /**
335      * Test of section5 method, of class XhtmlBaseSink.
336      */
337     public void testSection5()
338     {
339         try
340         {
341             sink = new XhtmlBaseSink( writer );
342 
343             sink.section5();
344             sink.sectionTitle5();
345             sink.sectionTitle5_();
346             sink.section5_();
347         }
348         finally
349         {
350             sink.close();
351         }
352 
353         assertEquals( "<div class=\"section\">" + LS + "<h6></h6></div>", writer.toString() );
354     }
355 
356     /**
357      * Test of list method, of class XhtmlBaseSink.
358      * @throws java.lang.Exception if any.
359      */
360     public void testList()
361             throws Exception
362     {
363         try
364         {
365             sink = new XhtmlBaseSink( writer );
366 
367             sink.list();
368             sink.listItem();
369             sink.listItem_();
370             sink.list_();
371         }
372         finally
373         {
374             sink.close();
375         }
376 
377         assertEquals( "<ul>" + LS + "<li></li></ul>", writer.toString() );
378 
379         writer =  new StringWriter();
380 
381         try
382         {
383             sink = new XhtmlBaseSink( writer );
384 
385             sink.list( attributes );
386             sink.listItem( attributes );
387             sink.listItem_();
388             sink.list_();
389         }
390         finally
391         {
392             sink.close();
393         }
394 
395         assertEquals( "<ul style=\"bold\">" + LS + "<li style=\"bold\"></li></ul>", writer.toString() );
396     }
397 
398     /**
399      * Test of numberedList method, of class XhtmlBaseSink.
400      */
401     public void testNumberedList()
402     {
403         final int numbering = XhtmlBaseSink.NUMBERING_DECIMAL;
404 
405         try
406         {
407             sink = new XhtmlBaseSink( writer );
408 
409             sink.numberedList( numbering );
410             sink.numberedListItem();
411             sink.numberedListItem_();
412             sink.numberedList_();
413         }
414         finally
415         {
416             sink.close();
417         }
418 
419         assertEquals( "<ol style=\"list-style-type: decimal\">" + LS + "<li></li></ol>", writer.toString() );
420 
421         writer =  new StringWriter();
422 
423         try
424         {
425             sink = new XhtmlBaseSink( writer );
426 
427             sink.numberedList( numbering, attributes );
428             sink.numberedListItem( attributes );
429             sink.numberedListItem_();
430             sink.numberedList_();
431         }
432         finally
433         {
434             sink.close();
435         }
436 
437         assertEquals( "<ol style=\"list-style-type: decimal\">" + LS + "<li style=\"bold\"></li></ol>", writer.toString() );
438     }
439 
440     /**
441      * Test of definitionList method, of class XhtmlBaseSink.
442      */
443     public void testDefinitionList()
444     {
445         try
446         {
447             sink = new XhtmlBaseSink( writer );
448 
449             sink.definitionList();
450             sink.definedTerm();
451             sink.definedTerm_();
452             sink.definition();
453             sink.definition_();
454             sink.definitionList_();
455         }
456         finally
457         {
458             sink.close();
459         }
460 
461         assertEquals( "<dl>" + LS + "<dt></dt>" + LS + "<dd></dd></dl>", writer.toString() );
462 
463         writer =  new StringWriter();
464 
465         try
466         {
467             sink = new XhtmlBaseSink( writer );
468 
469             sink.definitionList( attributes );
470             sink.definedTerm( attributes );
471             sink.definedTerm_();
472             sink.definition( attributes );
473             sink.definition_();
474             sink.definitionList_();
475         }
476         finally
477         {
478             sink.close();
479         }
480 
481         assertEquals( "<dl style=\"bold\">" + LS + "<dt style=\"bold\"></dt>" + LS + "<dd style=\"bold\"></dd></dl>", writer.toString() );
482     }
483 
484     /**
485      * Test of figure method, of class XhtmlBaseSink.
486      */
487     public void testFigure()
488     {
489         final String src = "src.jpg";
490 
491         try
492         {
493             sink = new XhtmlBaseSink( writer );
494 
495             sink.figure( attributes );
496             sink.figureGraphics( src, attributes );
497             sink.figureCaption( attributes );
498             sink.figureCaption_();
499             sink.figure_();
500         }
501         finally
502         {
503             sink.close();
504         }
505 
506         assertEquals( "<div style=\"bold\" class=\"figure\">"
507                 + "" + LS + "<p align=\"center\"><img src=\"src.jpg\" style=\"bold\" alt=\"\" /></p>"
508                 + "" + LS + "<p align=\"center\" style=\"bold\"><i></i></p></div>", writer.toString() );
509     }
510 
511     /**
512      * Test of figureGraphics method, of class XhtmlBaseSink.
513      */
514     public void testFigureGraphics()
515     {
516         String src = "source.png";
517 
518         try
519         {
520             sink = new XhtmlBaseSink( writer );
521             sink.figureGraphics( src, attributes );
522         }
523         finally
524         {
525             sink.close();
526         }
527 
528         assertEquals( "<img src=\"source.png\" style=\"bold\" alt=\"\" />", writer.toString() );
529     }
530 
531     /**
532      * Test of paragraph method, of class XhtmlBaseSink.
533      */
534     public void testParagraph()
535     {
536         try
537         {
538             sink = new XhtmlBaseSink( writer );
539 
540             sink.paragraph();
541             sink.paragraph_();
542         }
543         finally
544         {
545             sink.close();
546         }
547 
548         assertEquals( "<p></p>", writer.toString() );
549 
550         writer =  new StringWriter();
551 
552         try
553         {
554             sink = new XhtmlBaseSink( writer );
555 
556             sink.paragraph( attributes );
557             sink.paragraph_();
558         }
559         finally
560         {
561             sink.close();
562         }
563 
564         assertEquals( "<p style=\"bold\"></p>", writer.toString() );
565     }
566 
567     /**
568      * Test of verbatim method, of class XhtmlBaseSink.
569      */
570     public void testVerbatim()
571     {
572         try
573         {
574             sink = new XhtmlBaseSink( writer );
575 
576             sink.verbatim( true );
577             sink.verbatim_();
578         }
579         finally
580         {
581             sink.close();
582         }
583 
584         assertEquals( "<div class=\"source\">" + LS + "<pre></pre></div>", writer.toString() );
585 
586         checkVerbatimAttributes( attributes, "<div>" + LS + "<pre style=\"bold\"></pre></div>" );
587 
588         final SinkEventAttributes att =
589             new SinkEventAttributeSet( new String[] {SinkEventAttributes.ID, "id"} );
590         checkVerbatimAttributes( att, "<div>" + LS + "<pre id=\"id\"></pre></div>" );
591 
592         att.addAttribute( Attribute.CLASS, "class" );
593         checkVerbatimAttributes( att, "<div>" + LS + "<pre id=\"id\" class=\"class\"></pre></div>" );
594 
595         att.addAttribute( SinkEventAttributes.DECORATION, "boxed" );
596         checkVerbatimAttributes( att, "<div class=\"source\">" + LS + "<pre id=\"id\" class=\"class\"></pre></div>" );
597 
598         att.removeAttribute( Attribute.CLASS.toString() );
599         checkVerbatimAttributes( att, "<div class=\"source\">" + LS + "<pre id=\"id\"></pre></div>" );
600     }
601 
602     private void checkVerbatimAttributes( final SinkEventAttributes att, final String expected )
603     {
604 
605         writer =  new StringWriter();
606 
607         try
608         {
609             sink = new XhtmlBaseSink( writer );
610 
611             sink.verbatim( att );
612             sink.verbatim_();
613         }
614         finally
615         {
616             sink.close();
617         }
618 
619         assertEquals( expected, writer.toString() );
620     }
621 
622     /**
623      * Test of horizontalRule method, of class XhtmlBaseSink.
624      */
625     public void testHorizontalRule()
626     {
627         try
628         {
629             sink = new XhtmlBaseSink( writer );
630 
631             sink.horizontalRule();
632             sink.horizontalRule( attributes );
633         }
634         finally
635         {
636             sink.close();
637         }
638 
639         assertEquals( "<hr /><hr style=\"bold\" />", writer.toString() );
640     }
641 
642     /**
643      * Test of table method, of class XhtmlBaseSink.
644      */
645     public void testTable()
646     {
647         try
648         {
649             sink = new XhtmlBaseSink( writer );
650 
651             sink.table( attributes );
652             sink.table_();
653         }
654         finally
655         {
656             sink.close();
657         }
658 
659         assertEquals( "</table>", writer.toString() );
660     }
661 
662     /**
663      * Test of tableRows method, of class XhtmlBaseSink.
664      */
665     public void testTableRows()
666     {
667         final int[] justification = null;
668         final boolean grid = false;
669 
670         try
671         {
672             sink = new XhtmlBaseSink( writer );
673 
674             sink.tableRows( justification, grid );
675             sink.tableRows_();
676         }
677         finally
678         {
679             sink.close();
680         }
681 
682         assertEquals( "<table border=\"0\" class=\"bodyTable\">", writer.toString() );
683     }
684 
685     /**
686      * Test of tableRow method, of class XhtmlBaseSink.
687      */
688     public void testTableRow()
689     {
690         try
691         {
692             sink = new XhtmlBaseSink( writer );
693 
694             sink.tableRow( attributes );
695             sink.tableRow_();
696         }
697         finally
698         {
699             sink.close();
700         }
701 
702         assertEquals( "<tr class=\"a\" style=\"bold\"></tr>", writer.toString() );
703     }
704 
705     /**
706      * Test of tableCell method, of class XhtmlBaseSink.
707      */
708     public void testTableCell()
709     {
710         try
711         {
712             sink = new XhtmlBaseSink( writer );
713 
714             sink.tableCell( attributes );
715             sink.tableCell_();
716         }
717         finally
718         {
719             sink.close();
720         }
721 
722         assertEquals( "<td style=\"bold\"></td>", writer.toString() );
723     }
724 
725     /**
726      * Test of tableHeaderCell method, of class XhtmlBaseSink.
727      */
728     public void testTableHeaderCell()
729     {
730         try
731         {
732             sink = new XhtmlBaseSink( writer );
733 
734             sink.tableHeaderCell( attributes );
735             sink.tableHeaderCell_();
736         }
737         finally
738         {
739             sink.close();
740         }
741 
742         assertEquals( "<th style=\"bold\"></th>", writer.toString() );
743     }
744 
745     /**
746      * Test of tableCaption method, of class XhtmlBaseSink.
747      */
748     public void testTableCaption()
749     {
750         try
751         {
752             sink = new XhtmlBaseSink( writer );
753 
754             sink.table();
755             sink.tableRows( null, false );
756             sink.tableCaption( attributes );
757             sink.text( "caption" );
758             sink.tableCaption_();
759             sink.tableRows_();
760             sink.table_();
761         }
762         finally
763         {
764             sink.close();
765         }
766 
767         assertEquals( "<table border=\"0\" class=\"bodyTable\">" +
768                 "<caption style=\"bold\">caption</caption></table>", writer.toString() );
769     }
770 
771     /**
772      * Test of anchor method, of class XhtmlBaseSink.
773      */
774     public void testAnchor()
775     {
776         String name = "anchor";
777 
778         try
779         {
780             sink = new XhtmlBaseSink( writer );
781             sink.anchor( name, attributes );
782             sink.anchor_();
783         }
784         finally
785         {
786             sink.close();
787         }
788 
789         assertEquals( "<a name=\"anchor\" style=\"bold\"></a>", writer.toString() );
790     }
791 
792     /**
793      * Test of link method, of class XhtmlBaseSink.
794      */
795     public void testLink()
796     {
797         final String name = "link.html";
798 
799         try
800         {
801             sink = new XhtmlBaseSink( writer );
802             sink.link( name, attributes );
803             sink.link_();
804         }
805         finally
806         {
807             sink.close();
808         }
809 
810         assertEquals( "<a href=\"link.html\" style=\"bold\"></a>", writer.toString() );
811     }
812 
813     /**
814      * Test of italic/bold/monospaced method, of class XhtmlBaseSink.
815      */
816     public void testItalic()
817     {
818         try
819         {
820             sink = new XhtmlBaseSink( writer );
821             sink.italic();
822             sink.italic_();
823             sink.bold();
824             sink.bold_();
825             sink.monospaced();
826             sink.monospaced_();
827         }
828         finally
829         {
830             sink.close();
831         }
832 
833         assertEquals( "<i></i><b></b><tt></tt>", writer.toString() );
834     }
835 
836     /**
837      * Test of lineBreak/pageBreak/nonBreakingSpace method, of class XhtmlBaseSink.
838      */
839     public void testLineBreak()
840     {
841         try
842         {
843             sink = new XhtmlBaseSink( writer );
844             sink.lineBreak( attributes );
845             sink.pageBreak();
846             sink.nonBreakingSpace();
847         }
848         finally
849         {
850             sink.close();
851         }
852 
853         assertEquals( "<br style=\"bold\" /><!-- PB -->&#160;", writer.toString() );
854     }
855 
856     /**
857      * Test of text method, of class XhtmlBaseSink.
858      */
859     public void testText()
860     {
861         String text = "a text & \u00c6";
862 
863         try
864         {
865             sink = new XhtmlBaseSink( writer );
866             sink.text( text );
867         }
868         finally
869         {
870             sink.close();
871         }
872 
873         assertEquals( "a text &amp; &#xc6;", writer.toString() );
874 
875         writer =  new StringWriter();
876 
877         try
878         {
879             sink = new XhtmlBaseSink( writer );
880             sink.text( text, attributes );
881         }
882         finally
883         {
884             sink.close();
885         }
886 
887         assertEquals( "a text &amp; &#xc6;", writer.toString() );
888     }
889 
890     /**
891      * Test of rawText method, of class XhtmlBaseSink.
892      */
893     public void testRawText()
894     {
895         String text = "raw text";
896 
897         try
898         {
899             sink = new XhtmlBaseSink( writer );
900             sink.rawText( text );
901         }
902         finally
903         {
904             sink.close();
905         }
906 
907         assertEquals( "raw text", writer.toString() );
908     }
909 
910     /**
911      * Test of comment method, of class XhtmlBaseSink.
912      */
913     public void testComment()
914     {
915         try
916         {
917             sink = new XhtmlBaseSink( writer );
918             sink.comment( "a comment" );
919         }
920         finally
921         {
922             sink.close();
923         }
924 
925         assertEquals( "<!-- a comment -->", writer.toString() );
926     }
927 
928     /**
929      * Test of unknown method, of class XhtmlBaseSink.
930      */
931     public void testUnknown()
932     {
933         final String name = "unknown";
934         final Object[] requiredParams = null;
935 
936         try
937         {
938             sink = new XhtmlBaseSink( writer );
939             sink.unknown( name, requiredParams, attributes );
940         }
941         finally
942         {
943             sink.close();
944         }
945 
946         assertEquals( "", writer.toString() );
947     }
948 
949     /**
950      * Test entities in attribute values.
951      */
952     public void testAttributeEntities()
953     {
954         final Object[] startTag = new Object[] { new Integer( XhtmlBaseSink.TAG_TYPE_START ) };
955         final Object[] endTag = new Object[] { new Integer( XhtmlBaseSink.TAG_TYPE_END ) };
956         final String script = XhtmlBaseSink.SCRIPT.toString();
957         final SinkEventAttributes src = new SinkEventAttributeSet(
958                 new String[] {SinkEventAttributes.SRC.toString(), "http://ex.com/ex.js?v=l&l=e"} );
959 
960         try
961         {
962             sink = new XhtmlBaseSink( writer );
963 
964             sink.unknown( script, startTag, src );
965             sink.unknown( script, endTag, null );
966 
967             sink.figureGraphics( "http://ex.com/ex.jpg?v=l&l=e", src );
968         }
969         finally
970         {
971             sink.close();
972         }
973 
974         String result = writer.toString();
975 
976         assertTrue( result.contains( "ex.js?v=l&amp;l=e" ) );
977         assertTrue( result.contains( "ex.jpg?v=l&amp;l=e" ) );
978     }
979 
980     /**
981      * Test of entity.
982      */
983     public void testEntity()
984     {
985         // DOXIA-314
986         String text = "a text '&#x1d7ed;'";
987 
988         try
989         {
990             sink = new XhtmlBaseSink( writer );
991             sink.text( text );
992         }
993         finally
994         {
995             sink.close();
996         }
997 
998         assertEquals( "a text '&#x1d7ed;'", writer.toString() );
999     }
1000 
1001     /**
1002      * Test unicode chracters in tables. DOXIA-433.
1003      */
1004     public void testSpecialCharacters()
1005     {
1006         try
1007         {
1008             sink = new XhtmlBaseSink( writer );
1009             sink.table( null );
1010             sink.tableRows( null, true );
1011             sink.tableRow( null );
1012             sink.tableCell();
1013             sink.text( "\u2713", null );
1014             sink.tableCell_();
1015             sink.tableRow_();
1016             sink.tableRows_();
1017             sink.table_();
1018         }
1019         finally
1020         {
1021             sink.close();
1022         }
1023 
1024         final String result = writer.toString();
1025 
1026         assertTrue( result.contains( "&#x2713;" ) );
1027     }
1028 }