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