1 package org.apache.maven.doxia.sink.impl;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.ByteArrayOutputStream;
23 import java.io.File;
24 import java.io.FileOutputStream;
25 import java.io.IOException;
26 import java.io.OutputStream;
27 import java.util.ArrayList;
28 import java.util.List;
29
30 import org.apache.maven.doxia.logging.Log;
31 import org.apache.maven.doxia.sink.Sink;
32 import org.apache.maven.doxia.sink.SinkEventAttributes;
33 import org.apache.maven.doxia.sink.SinkFactory;
34
35
36
37
38
39
40
41
42
43
44 public class RandomAccessSink
45 implements Sink
46 {
47 private SinkFactory sinkFactory;
48
49 private String encoding;
50
51 private OutputStream coreOutputStream;
52
53 private Sink coreSink;
54
55 private List<Sink> sinks = new ArrayList<>();
56
57 private List<ByteArrayOutputStream> outputStreams = new ArrayList<>();
58
59 private Sink currentSink;
60
61
62
63
64
65
66
67
68 public RandomAccessSink( SinkFactory sinkFactory, OutputStream stream )
69 throws IOException
70 {
71 this.sinkFactory = sinkFactory;
72 this.coreOutputStream = stream;
73 this.currentSink = sinkFactory.createSink( stream );
74 this.coreSink = this.currentSink;
75 }
76
77
78
79
80
81
82
83
84
85 public RandomAccessSink( SinkFactory sinkFactory, OutputStream stream, String encoding )
86 throws IOException
87 {
88 this.sinkFactory = sinkFactory;
89 this.coreOutputStream = stream;
90 this.encoding = encoding;
91 this.currentSink = sinkFactory.createSink( stream, encoding );
92 this.coreSink = this.currentSink;
93 }
94
95
96
97
98
99
100
101
102
103 public RandomAccessSink( SinkFactory sinkFactory, File outputDirectory, String outputName )
104 throws IOException
105 {
106 this.sinkFactory = sinkFactory;
107 this.coreOutputStream = new FileOutputStream( new File( outputDirectory, outputName ) );
108 this.currentSink = sinkFactory.createSink( coreOutputStream );
109 this.coreSink = this.currentSink;
110 }
111
112
113
114
115
116
117
118
119
120
121 public RandomAccessSink( SinkFactory sinkFactory, File outputDirectory, String outputName, String encoding )
122 throws IOException
123 {
124 this.sinkFactory = sinkFactory;
125 this.coreOutputStream = new FileOutputStream( new File( outputDirectory, outputName ) );
126 this.encoding = encoding;
127 this.currentSink = sinkFactory.createSink( coreOutputStream, encoding );
128 this.coreSink = this.currentSink;
129 }
130
131
132 @Override
133 public void address()
134 {
135 currentSink.address();
136 }
137
138
139 @Override
140 public void address( SinkEventAttributes attributes )
141 {
142 currentSink.address( attributes );
143 }
144
145
146 @Override
147 public void address_()
148 {
149 currentSink.address_();
150 }
151
152
153
154
155
156
157
158 public Sink addSinkHook()
159 {
160 Sink subSink = null;
161 try
162 {
163 ByteArrayOutputStream subOut = new ByteArrayOutputStream();
164 ByteArrayOutputStream newOut = new ByteArrayOutputStream();
165
166 outputStreams.add( subOut );
167 outputStreams.add( newOut );
168
169 if ( encoding != null )
170 {
171 subSink = sinkFactory.createSink( subOut, encoding );
172 currentSink = sinkFactory.createSink( newOut, encoding );
173 }
174 else
175 {
176 subSink = sinkFactory.createSink( subOut );
177 currentSink = sinkFactory.createSink( newOut );
178 }
179 sinks.add( subSink );
180 sinks.add( currentSink );
181 }
182 catch ( IOException e )
183 {
184
185 }
186 return subSink;
187 }
188
189
190 @Override
191 public void anchor( String name )
192 {
193 currentSink.anchor( name );
194 }
195
196
197 @Override
198 public void anchor( String name, SinkEventAttributes attributes )
199 {
200 currentSink.anchor( name, attributes );
201 }
202
203
204 @Override
205 public void anchor_()
206 {
207 currentSink.anchor_();
208 }
209
210
211 @Override
212 public void article()
213 {
214 currentSink.article();
215 }
216
217
218 @Override
219 public void article( SinkEventAttributes attributes )
220 {
221 currentSink.article( attributes );
222 }
223
224
225 @Override
226 public void article_()
227 {
228 currentSink.article_();
229 }
230
231
232 @Override
233 public void author()
234 {
235 currentSink.author();
236 }
237
238
239 @Override
240 public void author( SinkEventAttributes attributes )
241 {
242 currentSink.author( attributes );
243 }
244
245
246 @Override
247 public void author_()
248 {
249 currentSink.author_();
250 }
251
252
253 @Override
254 public void blockquote()
255 {
256 currentSink.blockquote();
257 }
258
259
260 @Override
261 public void blockquote( SinkEventAttributes attributes )
262 {
263 currentSink.blockquote( attributes );
264 }
265
266
267 @Override
268 public void blockquote_()
269 {
270 currentSink.blockquote_();
271 }
272
273
274 @Override
275 public void body()
276 {
277 currentSink.body();
278 }
279
280
281 @Override
282 public void body( SinkEventAttributes attributes )
283 {
284 currentSink.body( attributes );
285 }
286
287
288 @Override
289 public void body_()
290 {
291 currentSink.body_();
292 }
293
294
295 @Override
296 public void bold()
297 {
298 currentSink.bold();
299 }
300
301
302 @Override
303 public void bold_()
304 {
305 currentSink.bold_();
306 }
307
308
309
310
311 public void close()
312 {
313 for ( Sink sink : sinks )
314 {
315
316 sink.close();
317 }
318 coreSink.close();
319 }
320
321
322 @Override
323 public void comment( String comment )
324 {
325 currentSink.comment( comment );
326 }
327
328
329 @Override
330 public void content()
331 {
332 currentSink.content();
333 }
334
335
336 @Override
337 public void content( SinkEventAttributes attributes )
338 {
339 currentSink.content( attributes );
340 }
341
342
343 @Override
344 public void content_()
345 {
346 currentSink.content_();
347 }
348
349
350 @Override
351 public void data( String value )
352 {
353 currentSink.data( value );
354 }
355
356
357 @Override
358 public void data( String value, SinkEventAttributes attributes )
359 {
360 currentSink.data( value, attributes );
361 }
362
363
364 @Override
365 public void data_()
366 {
367 currentSink.data_();
368 }
369
370
371 @Override
372 public void date()
373 {
374 currentSink.date();
375 }
376
377
378 @Override
379 public void date( SinkEventAttributes attributes )
380 {
381 currentSink.date( attributes );
382 }
383
384
385 @Override
386 public void date_()
387 {
388 currentSink.date_();
389 }
390
391
392 @Override
393 public void definedTerm()
394 {
395 currentSink.definedTerm();
396 }
397
398
399 @Override
400 public void definedTerm( SinkEventAttributes attributes )
401 {
402 currentSink.definedTerm( attributes );
403 }
404
405
406 @Override
407 public void definedTerm_()
408 {
409 currentSink.definedTerm_();
410 }
411
412
413 @Override
414 public void definition()
415 {
416 currentSink.definition();
417 }
418
419
420 @Override
421 public void definition( SinkEventAttributes attributes )
422 {
423 currentSink.definition( attributes );
424 }
425
426
427 @Override
428 public void definitionList()
429 {
430 currentSink.definitionList();
431 }
432
433
434 @Override
435 public void definitionList( SinkEventAttributes attributes )
436 {
437 currentSink.definitionList( attributes );
438 }
439
440
441 @Override
442 public void definitionListItem()
443 {
444 currentSink.definitionListItem();
445 }
446
447
448 @Override
449 public void definitionListItem( SinkEventAttributes attributes )
450 {
451 currentSink.definitionListItem( attributes );
452 }
453
454
455 @Override
456 public void definitionListItem_()
457 {
458 currentSink.definitionListItem_();
459 }
460
461
462 @Override
463 public void definitionList_()
464 {
465 currentSink.definitionList_();
466 }
467
468
469 @Override
470 public void definition_()
471 {
472 currentSink.definition_();
473 }
474
475
476 @Override
477 public void division()
478 {
479 currentSink.division();
480 }
481
482
483 @Override
484 public void division( SinkEventAttributes attributes )
485 {
486 currentSink.division( attributes );
487 }
488
489
490 @Override
491 public void division_()
492 {
493 currentSink.division_();
494 }
495
496
497 @Override
498 public void figure()
499 {
500 currentSink.figure();
501 }
502
503
504 @Override
505 public void figure( SinkEventAttributes attributes )
506 {
507 currentSink.figure( attributes );
508 }
509
510
511 @Override
512 public void figureCaption()
513 {
514 currentSink.figureCaption();
515 }
516
517
518 @Override
519 public void figureCaption( SinkEventAttributes attributes )
520 {
521 currentSink.figureCaption( attributes );
522 }
523
524
525 @Override
526 public void figureCaption_()
527 {
528 currentSink.figureCaption_();
529 }
530
531
532 @Override
533 public void figureGraphics( String name )
534 {
535 currentSink.figureGraphics( name );
536 }
537
538
539 @Override
540 public void figureGraphics( String src, SinkEventAttributes attributes )
541 {
542 currentSink.figureGraphics( src, attributes );
543 }
544
545
546 @Override
547 public void figure_()
548 {
549 currentSink.figure_();
550 }
551
552
553
554
555 public void flush()
556 {
557 for ( int i = 0; i < sinks.size(); i++ )
558 {
559
560
561 Sink sink = sinks.get( i );
562 sink.flush();
563
564 ByteArrayOutputStream stream = outputStreams.get( i );
565 try
566 {
567 coreOutputStream.write( stream.toByteArray() );
568 }
569 catch ( IOException e )
570 {
571
572 }
573 }
574 coreSink.flush();
575 }
576
577
578 @Override
579 public void footer()
580 {
581 currentSink.footer();
582 }
583
584
585 @Override
586 public void footer( SinkEventAttributes attributes )
587 {
588 currentSink.footer( attributes );
589 }
590
591
592 @Override
593 public void footer_()
594 {
595 currentSink.footer_();
596 }
597
598
599 @Override
600 public void head()
601 {
602 currentSink.head();
603 }
604
605
606 @Override
607 public void head( SinkEventAttributes attributes )
608 {
609 currentSink.head( attributes );
610 }
611
612
613 @Override
614 public void head_()
615 {
616 currentSink.head_();
617 }
618
619
620 @Override
621 public void header()
622 {
623 currentSink.header();
624 }
625
626
627 @Override
628 public void header( SinkEventAttributes attributes )
629 {
630 currentSink.header( attributes );
631 }
632
633
634 @Override
635 public void header_()
636 {
637 currentSink.header_();
638 }
639
640
641 @Override
642 public void horizontalRule()
643 {
644 currentSink.horizontalRule();
645 }
646
647
648 @Override
649 public void horizontalRule( SinkEventAttributes attributes )
650 {
651 currentSink.horizontalRule( attributes );
652 }
653
654
655 @Override
656 public void inline()
657 {
658 currentSink.inline();
659 }
660
661
662 @Override
663 public void inline( SinkEventAttributes attributes )
664 {
665 currentSink.inline( attributes );
666 }
667
668
669 @Override
670 public void inline_()
671 {
672 currentSink.inline_();
673 }
674
675
676 @Override
677 public void italic()
678 {
679 currentSink.italic();
680 }
681
682
683 @Override
684 public void italic_()
685 {
686 currentSink.italic_();
687 }
688
689
690 @Override
691 public void lineBreak()
692 {
693 currentSink.lineBreak();
694 }
695
696
697 @Override
698 public void lineBreak( SinkEventAttributes attributes )
699 {
700 currentSink.lineBreak( attributes );
701 }
702
703
704 @Override
705 public void lineBreakOpportunity()
706 {
707 currentSink.lineBreakOpportunity();
708 }
709
710
711 @Override
712 public void lineBreakOpportunity( SinkEventAttributes attributes )
713 {
714 currentSink.lineBreakOpportunity( attributes );
715 }
716
717
718 @Override
719 public void link( String name )
720 {
721 currentSink.link( name );
722 }
723
724
725 @Override
726 public void link( String name, SinkEventAttributes attributes )
727 {
728 currentSink.link( name, attributes );
729 }
730
731
732 @Override
733 public void link_()
734 {
735 currentSink.link_();
736 }
737
738
739 @Override
740 public void list()
741 {
742 currentSink.list();
743 }
744
745
746 @Override
747 public void list( SinkEventAttributes attributes )
748 {
749 currentSink.list( attributes );
750 }
751
752
753 @Override
754 public void listItem()
755 {
756 currentSink.listItem();
757 }
758
759
760 @Override
761 public void listItem( SinkEventAttributes attributes )
762 {
763 currentSink.listItem( attributes );
764 }
765
766
767 @Override
768 public void listItem_()
769 {
770 currentSink.listItem_();
771 }
772
773
774 @Override
775 public void list_()
776 {
777 currentSink.list_();
778 }
779
780
781 @Override
782 public void monospaced()
783 {
784 currentSink.monospaced();
785 }
786
787
788 @Override
789 public void monospaced_()
790 {
791 currentSink.monospaced_();
792 }
793
794
795 @Override
796 public void navigation()
797 {
798 currentSink.navigation();
799 }
800
801
802 @Override
803 public void navigation( SinkEventAttributes attributes )
804 {
805 currentSink.navigation( attributes );
806 }
807
808
809 @Override
810 public void navigation_()
811 {
812 currentSink.navigation_();
813 }
814
815
816 @Override
817 public void nonBreakingSpace()
818 {
819 currentSink.nonBreakingSpace();
820 }
821
822
823 @Override
824 public void numberedList( int numbering )
825 {
826 currentSink.numberedList( numbering );
827 }
828
829
830 @Override
831 public void numberedList( int numbering, SinkEventAttributes attributes )
832 {
833 currentSink.numberedList( numbering, attributes );
834 }
835
836
837 @Override
838 public void numberedListItem()
839 {
840 currentSink.numberedListItem();
841 }
842
843
844 @Override
845 public void numberedListItem( SinkEventAttributes attributes )
846 {
847 currentSink.numberedListItem( attributes );
848 }
849
850
851 @Override
852 public void numberedListItem_()
853 {
854 currentSink.numberedListItem_();
855 }
856
857
858 @Override
859 public void numberedList_()
860 {
861 currentSink.numberedList_();
862 }
863
864
865 @Override
866 public void pageBreak()
867 {
868 currentSink.pageBreak();
869 }
870
871
872 @Override
873 public void paragraph()
874 {
875 currentSink.paragraph();
876 }
877
878
879 @Override
880 public void paragraph( SinkEventAttributes attributes )
881 {
882 currentSink.paragraph( attributes );
883 }
884
885
886 @Override
887 public void paragraph_()
888 {
889 currentSink.paragraph_();
890 }
891
892
893 @Override
894 public void rawText( String text )
895 {
896 currentSink.rawText( text );
897 }
898
899
900 @Override
901 public void section( int level, SinkEventAttributes attributes )
902 {
903 currentSink.section( level, attributes );
904 }
905
906
907 @Override
908 public void section1()
909 {
910 currentSink.section1();
911 }
912
913
914 @Override
915 public void section1_()
916 {
917 currentSink.section1_();
918 }
919
920
921 @Override
922 public void section2()
923 {
924 currentSink.section2();
925 }
926
927
928 @Override
929 public void section2_()
930 {
931 currentSink.section2_();
932 }
933
934
935 @Override
936 public void section3()
937 {
938 currentSink.section3();
939 }
940
941
942 @Override
943 public void section3_()
944 {
945 currentSink.section3_();
946 }
947
948
949 @Override
950 public void section4()
951 {
952 currentSink.section4();
953 }
954
955
956 @Override
957 public void section4_()
958 {
959 currentSink.section4_();
960 }
961
962
963 @Override
964 public void section5()
965 {
966 currentSink.section5();
967 }
968
969
970 @Override
971 public void section5_()
972 {
973 currentSink.section5_();
974 }
975
976
977 @Override
978 public void section6()
979 {
980 currentSink.section5();
981 }
982
983
984 @Override
985 public void section6_()
986 {
987 currentSink.section5_();
988 }
989
990
991 @Override
992 public void sectionTitle()
993 {
994 currentSink.sectionTitle();
995 }
996
997
998 @Override
999 public void sectionTitle( int level, SinkEventAttributes attributes )
1000 {
1001 currentSink.sectionTitle( level, attributes );
1002 }
1003
1004
1005 @Override
1006 public void sectionTitle1()
1007 {
1008 currentSink.sectionTitle1();
1009 }
1010
1011
1012 @Override
1013 public void sectionTitle1_()
1014 {
1015 currentSink.sectionTitle1_();
1016 }
1017
1018
1019 @Override
1020 public void sectionTitle2()
1021 {
1022 currentSink.sectionTitle2();
1023 }
1024
1025
1026 @Override
1027 public void sectionTitle2_()
1028 {
1029 currentSink.sectionTitle2_();
1030 }
1031
1032
1033 @Override
1034 public void sectionTitle3()
1035 {
1036 currentSink.sectionTitle3();
1037 }
1038
1039
1040 @Override
1041 public void sectionTitle3_()
1042 {
1043 currentSink.sectionTitle3_();
1044 }
1045
1046
1047 @Override
1048 public void sectionTitle4()
1049 {
1050 currentSink.sectionTitle4();
1051 }
1052
1053
1054 @Override
1055 public void sectionTitle4_()
1056 {
1057 currentSink.sectionTitle4_();
1058 }
1059
1060
1061 @Override
1062 public void sectionTitle5()
1063 {
1064 currentSink.sectionTitle5();
1065 }
1066
1067
1068 @Override
1069 public void sectionTitle5_()
1070 {
1071 currentSink.sectionTitle5_();
1072 }
1073
1074
1075 @Override
1076 public void sectionTitle6()
1077 {
1078 currentSink.sectionTitle5();
1079 }
1080
1081
1082 @Override
1083 public void sectionTitle6_()
1084 {
1085 currentSink.sectionTitle5_();
1086 }
1087
1088
1089 @Override
1090 public void sectionTitle_()
1091 {
1092 currentSink.sectionTitle_();
1093 }
1094
1095
1096 @Override
1097 public void sectionTitle_( int level )
1098 {
1099 currentSink.sectionTitle_( level );
1100 }
1101
1102
1103 @Override
1104 public void section_( int level )
1105 {
1106 currentSink.section_( level );
1107 }
1108
1109
1110 @Override
1111 public void sidebar()
1112 {
1113 currentSink.sidebar();
1114 }
1115
1116
1117 @Override
1118 public void sidebar( SinkEventAttributes attributes )
1119 {
1120 currentSink.sidebar( attributes );
1121 }
1122
1123
1124 @Override
1125 public void sidebar_()
1126 {
1127 currentSink.sidebar_();
1128 }
1129
1130
1131 @Override
1132 public void table()
1133 {
1134 currentSink.table();
1135 }
1136
1137
1138 @Override
1139 public void table( SinkEventAttributes attributes )
1140 {
1141 currentSink.table( attributes );
1142 }
1143
1144
1145 @Override
1146 public void tableCaption()
1147 {
1148 currentSink.tableCaption();
1149 }
1150
1151
1152 @Override
1153 public void tableCaption( SinkEventAttributes attributes )
1154 {
1155 currentSink.tableCaption( attributes );
1156 }
1157
1158
1159 @Override
1160 public void tableCaption_()
1161 {
1162 currentSink.tableCaption_();
1163 }
1164
1165
1166 @Override
1167 public void tableCell()
1168 {
1169 currentSink.tableCell();
1170 }
1171
1172
1173 @Override
1174 public void tableCell( String width )
1175 {
1176 currentSink.tableCell( width );
1177 }
1178
1179
1180 @Override
1181 public void tableCell( SinkEventAttributes attributes )
1182 {
1183 currentSink.tableCell( attributes );
1184 }
1185
1186
1187 @Override
1188 public void tableCell_()
1189 {
1190 currentSink.tableCell_();
1191 }
1192
1193
1194 @Override
1195 public void tableHeaderCell()
1196 {
1197 currentSink.tableHeaderCell();
1198 }
1199
1200
1201 @Override
1202 public void tableHeaderCell( String width )
1203 {
1204 currentSink.tableHeaderCell( width );
1205 }
1206
1207
1208 @Override
1209 public void tableHeaderCell( SinkEventAttributes attributes )
1210 {
1211 currentSink.tableHeaderCell( attributes );
1212 }
1213
1214
1215 @Override
1216 public void tableHeaderCell_()
1217 {
1218 currentSink.tableHeaderCell_();
1219 }
1220
1221
1222 @Override
1223 public void tableRow()
1224 {
1225 currentSink.tableRow();
1226 }
1227
1228
1229 @Override
1230 public void tableRow( SinkEventAttributes attributes )
1231 {
1232 currentSink.tableRow( attributes );
1233 }
1234
1235
1236 @Override
1237 public void tableRow_()
1238 {
1239 currentSink.tableRow_();
1240 }
1241
1242
1243 @Override
1244 public void tableRows( int[] justification, boolean grid )
1245 {
1246 currentSink.tableRows( justification, grid );
1247 }
1248
1249
1250 @Override
1251 public void tableRows_()
1252 {
1253 currentSink.tableRows_();
1254 }
1255
1256
1257 @Override
1258 public void table_()
1259 {
1260 currentSink.table_();
1261 }
1262
1263
1264 @Override
1265 public void text( String text )
1266 {
1267 currentSink.text( text );
1268 }
1269
1270
1271 @Override
1272 public void text( String text, SinkEventAttributes attributes )
1273 {
1274 currentSink.text( text, attributes );
1275 }
1276
1277
1278 @Override
1279 public void time( String datetime )
1280 {
1281 currentSink.time( datetime );
1282 }
1283
1284
1285 @Override
1286 public void time( String datetime, SinkEventAttributes attributes )
1287 {
1288 currentSink.time( datetime, attributes );
1289 }
1290
1291
1292 @Override
1293 public void time_()
1294 {
1295 currentSink.time_();
1296 }
1297
1298
1299 @Override
1300 public void title()
1301 {
1302 currentSink.title();
1303 }
1304
1305
1306 @Override
1307 public void title( SinkEventAttributes attributes )
1308 {
1309 currentSink.title( attributes );
1310 }
1311
1312
1313 @Override
1314 public void title_()
1315 {
1316 currentSink.title_();
1317 }
1318
1319
1320 @Override
1321 public void unknown( String name, Object[] requiredParams, SinkEventAttributes attributes )
1322 {
1323 currentSink.unknown( name, requiredParams, attributes );
1324 }
1325
1326
1327 @Override
1328 public void verbatim( boolean boxed )
1329 {
1330 currentSink.verbatim( boxed );
1331 }
1332
1333
1334 @Override
1335 public void verbatim( SinkEventAttributes attributes )
1336 {
1337 currentSink.verbatim( attributes );
1338 }
1339
1340
1341 @Override
1342 public void verbatim_()
1343 {
1344 currentSink.verbatim_();
1345 }
1346
1347
1348 @Override
1349 public void enableLogging( Log log )
1350 {
1351 currentSink.enableLogging( log );
1352 }
1353 }