1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.util;
18
19 import java.util.BitSet;
20
21 import org.apache.commons.vfs2.provider.GenericURLFileName;
22
23
24
25
26
27
28
29
30
31 class URIBitSets {
32
33
34
35
36
37
38
39
40 protected static final BitSet percent = new BitSet(256);
41
42 static {
43 percent.set('%');
44 }
45
46
47
48
49
50
51
52
53
54 protected static final BitSet digit = new BitSet(256);
55
56 static {
57 for (int i = '0'; i <= '9'; i++) {
58 digit.set(i);
59 }
60 }
61
62
63
64
65
66
67
68
69 protected static final BitSet alpha = new BitSet(256);
70
71 static {
72 for (int i = 'a'; i <= 'z'; i++) {
73 alpha.set(i);
74 }
75 for (int i = 'A'; i <= 'Z'; i++) {
76 alpha.set(i);
77 }
78 }
79
80
81
82
83
84
85
86
87 protected static final BitSet alphanum = new BitSet(256);
88
89 static {
90 alphanum.or(alpha);
91 alphanum.or(digit);
92 }
93
94
95
96
97
98
99
100
101
102 protected static final BitSet hex = new BitSet(256);
103
104 static {
105 hex.or(digit);
106 for (int i = 'a'; i <= 'f'; i++) {
107 hex.set(i);
108 }
109 for (int i = 'A'; i <= 'F'; i++) {
110 hex.set(i);
111 }
112 }
113
114
115
116
117
118
119
120
121 protected static final BitSet escaped = new BitSet(256);
122
123 static {
124 escaped.or(percent);
125 escaped.or(hex);
126 }
127
128
129
130
131
132
133
134
135
136 protected static final BitSet mark = new BitSet(256);
137
138 static {
139 mark.set('-');
140 mark.set('_');
141 mark.set('.');
142 mark.set('!');
143 mark.set('~');
144 mark.set('*');
145 mark.set('\'');
146 mark.set('(');
147 mark.set(')');
148 }
149
150
151
152
153
154
155
156
157
158 protected static final BitSet unreserved = new BitSet(256);
159
160 static {
161 unreserved.or(alphanum);
162 unreserved.or(mark);
163 }
164
165
166
167
168
169
170
171
172
173 protected static final BitSet reserved = new BitSet(256);
174
175 static {
176 reserved.set(';');
177 reserved.set('/');
178 reserved.set('?');
179 reserved.set(':');
180 reserved.set('@');
181 reserved.set('&');
182 reserved.set('=');
183 reserved.set('+');
184 reserved.set('$');
185 reserved.set(',');
186 }
187
188
189
190
191
192
193
194
195 protected static final BitSet uric = new BitSet(256);
196
197 static {
198 uric.or(reserved);
199 uric.or(unreserved);
200 uric.or(escaped);
201 }
202
203
204
205
206
207
208
209
210 protected static final BitSet fragment = uric;
211
212
213
214
215
216
217
218
219 protected static final BitSet query = uric;
220
221
222
223
224
225
226
227
228
229 protected static final BitSet pchar = new BitSet(256);
230
231 static {
232 pchar.or(unreserved);
233 pchar.or(escaped);
234 pchar.set(':');
235 pchar.set('@');
236 pchar.set('&');
237 pchar.set('=');
238 pchar.set('+');
239 pchar.set('$');
240 pchar.set(',');
241 }
242
243
244
245
246
247
248
249
250 protected static final BitSet param = pchar;
251
252
253
254
255
256
257
258
259 protected static final BitSet segment = new BitSet(256);
260
261 static {
262 segment.or(pchar);
263 segment.set(';');
264 segment.or(param);
265 }
266
267
268
269
270
271
272
273
274 protected static final BitSet path_segments = new BitSet(256);
275
276 static {
277 path_segments.set('/');
278 path_segments.or(segment);
279 }
280
281
282
283
284
285
286
287
288 protected static final BitSet abs_path = new BitSet(256);
289
290 static {
291 abs_path.set('/');
292 abs_path.or(path_segments);
293 }
294
295
296
297
298
299
300
301
302
303 protected static final BitSet uric_no_slash = new BitSet(256);
304
305 static {
306 uric_no_slash.or(unreserved);
307 uric_no_slash.or(escaped);
308 uric_no_slash.set(';');
309 uric_no_slash.set('?');
310 uric_no_slash.set(';');
311 uric_no_slash.set('@');
312 uric_no_slash.set('&');
313 uric_no_slash.set('=');
314 uric_no_slash.set('+');
315 uric_no_slash.set('$');
316 uric_no_slash.set(',');
317 }
318
319
320
321
322
323
324
325
326 protected static final BitSet opaque_part = new BitSet(256);
327
328 static {
329
330 opaque_part.or(uric_no_slash);
331 opaque_part.or(uric);
332 }
333
334
335
336
337
338
339
340
341 protected static final BitSet path = new BitSet(256);
342
343 static {
344 path.or(abs_path);
345 path.or(opaque_part);
346 }
347
348
349
350
351
352 protected static final BitSet port = digit;
353
354
355
356
357
358
359
360
361 protected static final BitSet IPv4address = new BitSet(256);
362
363 static {
364 IPv4address.or(digit);
365 IPv4address.set('.');
366 }
367
368
369
370
371
372
373
374
375 protected static final BitSet IPv6address = new BitSet(256);
376
377 static {
378 IPv6address.or(hex);
379 IPv6address.set(':');
380 IPv6address.or(IPv4address);
381 }
382
383
384
385
386
387
388
389
390 protected static final BitSet IPv6reference = new BitSet(256);
391
392 static {
393 IPv6reference.set('[');
394 IPv6reference.or(IPv6address);
395 IPv6reference.set(']');
396 }
397
398
399
400
401
402
403
404
405 protected static final BitSet toplabel = new BitSet(256);
406
407 static {
408 toplabel.or(alphanum);
409 toplabel.set('-');
410 }
411
412
413
414
415
416
417
418
419 protected static final BitSet domainlabel = toplabel;
420
421
422
423
424
425
426
427
428 protected static final BitSet hostname = new BitSet(256);
429
430 static {
431 hostname.or(toplabel);
432
433 hostname.set('.');
434 }
435
436
437
438
439
440
441
442
443 protected static final BitSet host = new BitSet(256);
444
445 static {
446 host.or(hostname);
447
448 host.or(IPv6reference);
449 }
450
451
452
453
454
455
456
457
458 protected static final BitSet hostport = new BitSet(256);
459
460 static {
461 hostport.or(host);
462 hostport.set(':');
463 hostport.or(port);
464 }
465
466
467
468
469
470
471
472
473
474 protected static final BitSet userinfo = new BitSet(256);
475
476 static {
477 userinfo.or(unreserved);
478 userinfo.or(escaped);
479 userinfo.set(';');
480 userinfo.set(':');
481 userinfo.set('&');
482 userinfo.set('=');
483 userinfo.set('+');
484 userinfo.set('$');
485 userinfo.set(',');
486 }
487
488
489
490
491
492 public static final BitSet within_userinfo = new BitSet(256);
493
494 static {
495 within_userinfo.or(userinfo);
496 within_userinfo.clear(';');
497 within_userinfo.clear(':');
498 within_userinfo.clear('@');
499 within_userinfo.clear('?');
500 within_userinfo.clear('/');
501 }
502
503
504
505
506
507
508
509
510 protected static final BitSet server = new BitSet(256);
511
512 static {
513 server.or(userinfo);
514 server.set('@');
515 server.or(hostport);
516 }
517
518
519
520
521
522
523
524
525
526 protected static final BitSet reg_name = new BitSet(256);
527
528 static {
529 reg_name.or(unreserved);
530 reg_name.or(escaped);
531 reg_name.set('$');
532 reg_name.set(',');
533 reg_name.set(';');
534 reg_name.set(':');
535 reg_name.set('@');
536 reg_name.set('&');
537 reg_name.set('=');
538 reg_name.set('+');
539 }
540
541
542
543
544
545
546
547
548 protected static final BitSet authority = new BitSet(256);
549
550 static {
551 authority.or(server);
552 authority.or(reg_name);
553 }
554
555
556
557
558
559
560
561
562 protected static final BitSet scheme = new BitSet(256);
563
564 static {
565 scheme.or(alpha);
566 scheme.or(digit);
567 scheme.set('+');
568 scheme.set('-');
569 scheme.set('.');
570 }
571
572
573
574
575
576
577
578
579
580 protected static final BitSet rel_segment = new BitSet(256);
581
582 static {
583 rel_segment.or(unreserved);
584 rel_segment.or(escaped);
585 rel_segment.set(';');
586 rel_segment.set('@');
587 rel_segment.set('&');
588 rel_segment.set('=');
589 rel_segment.set('+');
590 rel_segment.set('$');
591 rel_segment.set(',');
592 }
593
594
595
596
597
598
599
600
601 protected static final BitSet rel_path = new BitSet(256);
602
603 static {
604 rel_path.or(rel_segment);
605 rel_path.or(abs_path);
606 }
607
608
609
610
611
612
613
614
615 protected static final BitSet net_path = new BitSet(256);
616
617 static {
618 net_path.set('/');
619 net_path.or(authority);
620 net_path.or(abs_path);
621 }
622
623
624
625
626
627
628
629
630 protected static final BitSet hier_part = new BitSet(256);
631
632 static {
633 hier_part.or(net_path);
634 hier_part.or(abs_path);
635
636 hier_part.or(query);
637 }
638
639
640
641
642
643
644
645
646 protected static final BitSet relativeURI = new BitSet(256);
647
648 static {
649 relativeURI.or(net_path);
650 relativeURI.or(abs_path);
651 relativeURI.or(rel_path);
652
653 relativeURI.or(query);
654 }
655
656
657
658
659
660
661
662
663 protected static final BitSet absoluteURI = new BitSet(256);
664
665 static {
666 absoluteURI.or(scheme);
667 absoluteURI.set(':');
668 absoluteURI.or(hier_part);
669 absoluteURI.or(opaque_part);
670 }
671
672
673
674
675
676
677
678
679 protected static final BitSet URI_reference = new BitSet(256);
680
681 static {
682 URI_reference.or(absoluteURI);
683 URI_reference.or(relativeURI);
684 URI_reference.set('#');
685 URI_reference.or(fragment);
686 }
687
688
689
690
691
692
693
694 public static final BitSet control = new BitSet(256);
695
696 static {
697 for (int i = 0; i <= 0x1F; i++) {
698 control.set(i);
699 }
700 control.set(0x7F);
701 }
702
703
704
705
706 public static final BitSet space = new BitSet(256);
707
708 static {
709 space.set(0x20);
710 }
711
712
713
714
715
716 public static final BitSet delims = new BitSet(256);
717
718 static {
719 delims.set('<');
720 delims.set('>');
721 delims.set('#');
722 delims.set('%');
723 delims.set('"');
724 }
725
726
727
728
729
730 public static final BitSet unwise = new BitSet(256);
731
732 static {
733 unwise.set('{');
734 unwise.set('}');
735 unwise.set('|');
736 unwise.set('\\');
737 unwise.set('^');
738 unwise.set('[');
739 unwise.set(']');
740 unwise.set('`');
741 }
742
743
744
745
746
747 public static final BitSet disallowed_rel_path = new BitSet(256);
748
749 static {
750 disallowed_rel_path.or(uric);
751 disallowed_rel_path.andNot(rel_path);
752 }
753
754
755
756
757
758 public static final BitSet disallowed_opaque_part = new BitSet(256);
759
760 static {
761 disallowed_opaque_part.or(uric);
762 disallowed_opaque_part.andNot(opaque_part);
763 }
764
765
766
767
768
769
770 public static final BitSet allowed_authority = new BitSet(256);
771
772 static {
773 allowed_authority.or(authority);
774 allowed_authority.clear('%');
775 }
776
777
778
779
780
781 public static final BitSet allowed_opaque_part = new BitSet(256);
782
783 static {
784 allowed_opaque_part.or(opaque_part);
785 allowed_opaque_part.clear('%');
786 }
787
788
789
790
791
792 public static final BitSet allowed_reg_name = new BitSet(256);
793
794 static {
795 allowed_reg_name.or(reg_name);
796
797 allowed_reg_name.clear('%');
798 }
799
800
801
802
803
804 public static final BitSet allowed_userinfo = new BitSet(256);
805
806 static {
807 allowed_userinfo.or(userinfo);
808
809 allowed_userinfo.clear('%');
810 }
811
812
813
814
815
816 public static final BitSet allowed_within_userinfo = new BitSet(256);
817
818 static {
819 allowed_within_userinfo.or(within_userinfo);
820 allowed_within_userinfo.clear('%');
821 }
822
823
824
825
826
827
828 public static final BitSet allowed_IPv6reference = new BitSet(256);
829
830 static {
831 allowed_IPv6reference.or(IPv6reference);
832
833 allowed_IPv6reference.clear('[');
834 allowed_IPv6reference.clear(']');
835 }
836
837
838
839
840
841
842 public static final BitSet allowed_host = new BitSet(256);
843
844 static {
845 allowed_host.or(hostname);
846 allowed_host.or(allowed_IPv6reference);
847 }
848
849
850
851
852
853 public static final BitSet allowed_within_authority = new BitSet(256);
854
855 static {
856 allowed_within_authority.or(server);
857 allowed_within_authority.or(reg_name);
858 allowed_within_authority.clear(';');
859 allowed_within_authority.clear(':');
860 allowed_within_authority.clear('@');
861 allowed_within_authority.clear('?');
862 allowed_within_authority.clear('/');
863 }
864
865
866
867
868
869 public static final BitSet allowed_abs_path = new BitSet(256);
870
871 static {
872 allowed_abs_path.or(abs_path);
873
874 allowed_abs_path.andNot(percent);
875 allowed_abs_path.clear('+');
876 }
877
878
879
880
881
882 public static final BitSet allowed_rel_path = new BitSet(256);
883
884 static {
885 allowed_rel_path.or(rel_path);
886 allowed_rel_path.clear('%');
887 allowed_rel_path.clear('+');
888 }
889
890
891
892
893
894 public static final BitSet allowed_within_path = new BitSet(256);
895
896 static {
897 allowed_within_path.or(abs_path);
898 allowed_within_path.clear('/');
899 allowed_within_path.clear(';');
900 allowed_within_path.clear('=');
901 allowed_within_path.clear('?');
902 }
903
904
905
906
907
908 public static final BitSet allowed_query = new BitSet(256);
909
910 static {
911 allowed_query.or(uric);
912 allowed_query.clear('%');
913 }
914
915
916
917
918
919 public static final BitSet allowed_within_query = new BitSet(256);
920
921 static {
922 allowed_within_query.or(allowed_query);
923 allowed_within_query.andNot(reserved);
924 }
925
926
927
928
929
930 public static final BitSet allowed_fragment = new BitSet(256);
931
932 static {
933 allowed_fragment.or(uric);
934 allowed_fragment.clear('%');
935 }
936
937 private URIBitSets() {
938 }
939
940 }