17
17
import java .io .IOException ;
18
18
import java .io .InputStreamReader ;
19
19
import java .net .URL ;
20
- import java .nio .channels .Selector ;
21
20
import java .text .MessageFormat ;
22
21
import java .util .HashMap ;
23
22
@@ -165,7 +164,7 @@ protected Locator createLocator(final Token t) {
165
164
* @return a new string with the escaped values
166
165
*/
167
166
protected String addEscapes (final String str ) {
168
- StringBuilder sb = new StringBuilder ();
167
+ final StringBuilder sb = new StringBuilder ();
169
168
char ch ;
170
169
for (int i = 0 ; i < str .length (); i ++) {
171
170
ch = str .charAt (i );
@@ -210,6 +209,12 @@ protected String addEscapes(final String str) {
210
209
return sb .toString ();
211
210
}
212
211
212
+ /**
213
+ *
214
+ * @param key the message lookup key
215
+ * @param e the parse exception
216
+ * @return a new CSSParseException
217
+ */
213
218
protected CSSParseException toCSSParseException (final String key , final ParseException e ) {
214
219
final String messagePattern1 = getParserMessage ("invalidExpectingOne" );
215
220
final String messagePattern2 = getParserMessage ("invalidExpectingMore" );
@@ -450,83 +455,220 @@ private CharStream getCharStream(final InputSource source) throws IOException {
450
455
451
456
@ Override
452
457
public abstract String getParserVersion ();
453
- protected abstract String getGrammarUri ();
458
+
459
+ /**
460
+ * Re intit the stream.
461
+ * @param charStream the stream
462
+ */
454
463
protected abstract void ReInit (CharStream charStream );
464
+
465
+ /**
466
+ * Process a style sheet.
467
+ *
468
+ * @throws CSSParseException in case of error
469
+ * @throws ParseException in case of error
470
+ */
455
471
protected abstract void styleSheet () throws CSSParseException , ParseException ;
472
+
473
+ /**
474
+ * Process a style sheet declaration.
475
+ *
476
+ * @throws ParseException in case of error
477
+ */
456
478
protected abstract void styleDeclaration () throws ParseException ;
479
+
480
+ /**
481
+ * Process a style sheet rule.
482
+ *
483
+ * @throws ParseException in case of error
484
+ */
457
485
protected abstract void styleSheetRuleSingle () throws ParseException ;
486
+
487
+ /**
488
+ * Process a selector list.
489
+ *
490
+ * @return the selector list
491
+ * @throws ParseException in case of error
492
+ */
458
493
protected abstract SelectorList parseSelectorsInternal () throws ParseException ;
459
- protected abstract SelectorList selectorList () throws ParseException ;
494
+
495
+ /**
496
+ * Process an expression.
497
+ *
498
+ * @return the lexical unit
499
+ * @throws ParseException in case of error
500
+ */
460
501
protected abstract LexicalUnit expr () throws ParseException ;
502
+
503
+ /**
504
+ * Process a prio.
505
+ *
506
+ * @return true or false
507
+ * @throws ParseException in case of error
508
+ */
461
509
protected abstract boolean prio () throws ParseException ;
510
+
511
+ /**
512
+ * Process a media list.
513
+ *
514
+ * @param ml the media list
515
+ * @throws ParseException in case of error
516
+ */
462
517
protected abstract void mediaList (MediaQueryList ml ) throws ParseException ;
463
518
519
+ /**
520
+ * start document handler.
521
+ */
464
522
protected void handleStartDocument () {
465
523
getDocumentHandler ().startDocument (getInputSource ());
466
524
}
467
525
526
+ /**
527
+ * end document handler.
528
+ */
468
529
protected void handleEndDocument () {
469
530
getDocumentHandler ().endDocument (getInputSource ());
470
531
}
471
532
533
+ /**
534
+ * ignorable at rule handler.
535
+ *
536
+ * @param s the rule
537
+ * @param locator the locator
538
+ */
472
539
protected void handleIgnorableAtRule (final String s , final Locator locator ) {
473
540
getDocumentHandler ().ignorableAtRule (s , locator );
474
541
}
475
542
543
+ /**
544
+ * charset handler.
545
+ *
546
+ * @param characterEncoding the encoding
547
+ * @param locator the locator
548
+ */
476
549
protected void handleCharset (final String characterEncoding , final Locator locator ) {
477
550
getDocumentHandler ().charset (characterEncoding , locator );
478
551
}
479
552
553
+ /**
554
+ * import style handler.
555
+ *
556
+ * @param uri the uri
557
+ * @param media the media query list
558
+ * @param defaultNamespaceURI the namespace uri
559
+ * @param locator the locator
560
+ */
480
561
protected void handleImportStyle (final String uri , final MediaQueryList media ,
481
562
final String defaultNamespaceURI , final Locator locator ) {
482
563
getDocumentHandler ().importStyle (uri , media , defaultNamespaceURI , locator );
483
564
}
484
565
566
+ /**
567
+ * start media handler.
568
+ *
569
+ * @param media the media query list
570
+ * @param locator the locator
571
+ */
485
572
protected void handleStartMedia (final MediaQueryList media , final Locator locator ) {
486
573
getDocumentHandler ().startMedia (media , locator );
487
574
}
488
575
576
+ /**
577
+ * medium handler.
578
+ *
579
+ * @param medium the medium
580
+ * @param locator the locator
581
+ */
489
582
protected void handleMedium (final String medium , final Locator locator ) {
490
583
// empty default impl
491
584
}
492
585
586
+ /**
587
+ * end media handler.
588
+ *
589
+ * @param media the media query list
590
+ */
493
591
protected void handleEndMedia (final MediaQueryList media ) {
494
592
getDocumentHandler ().endMedia (media );
495
593
}
496
594
595
+ /**
596
+ * start page handler.
597
+ *
598
+ * @param name the name
599
+ * @param pseudoPage the pseudo page
600
+ * @param locator the locator
601
+ */
497
602
protected void handleStartPage (final String name , final String pseudoPage , final Locator locator ) {
498
603
getDocumentHandler ().startPage (name , pseudoPage , locator );
499
604
}
500
605
606
+ /**
607
+ * end page handler.
608
+ *
609
+ * @param name the name
610
+ * @param pseudoPage the pseudo page
611
+ */
501
612
protected void handleEndPage (final String name , final String pseudoPage ) {
502
613
getDocumentHandler ().endPage (name , pseudoPage );
503
614
}
504
615
616
+ /**
617
+ * start font face handler.
618
+ *
619
+ * @param locator the locator
620
+ */
505
621
protected void handleStartFontFace (final Locator locator ) {
506
622
getDocumentHandler ().startFontFace (locator );
507
623
}
508
624
625
+ /**
626
+ * end font face handler.
627
+ */
509
628
protected void handleEndFontFace () {
510
629
getDocumentHandler ().endFontFace ();
511
630
}
512
631
513
- protected void handleSelector (final Selector selector ) {
514
- // empty default impl
515
- }
516
-
632
+ /**
633
+ * selector start handler.
634
+ *
635
+ * @param selectors the selector list
636
+ * @param locator the locator
637
+ */
517
638
protected void handleStartSelector (final SelectorList selectors , final Locator locator ) {
518
639
getDocumentHandler ().startSelector (selectors , locator );
519
640
}
520
641
642
+ /**
643
+ * selector end handler.
644
+ *
645
+ * @param selectors the selector list
646
+ */
521
647
protected void handleEndSelector (final SelectorList selectors ) {
522
648
getDocumentHandler ().endSelector (selectors );
523
649
}
524
650
651
+ /**
652
+ * property handler.
653
+ *
654
+ * @param name the name
655
+ * @param value the value
656
+ * @param important important flag
657
+ * @param locator the locator
658
+ */
525
659
protected void handleProperty (final String name , final LexicalUnit value ,
526
660
final boolean important , final Locator locator ) {
527
661
getDocumentHandler ().property (name , value , important , locator );
528
662
}
529
663
664
+ /**
665
+ * Process a function decl.
666
+ *
667
+ * @param prev the previous lexical unit
668
+ * @param funct the function
669
+ * @param params the params
670
+ * @return a lexical unit
671
+ */
530
672
protected LexicalUnit functionInternal (final LexicalUnit prev , final String funct ,
531
673
final LexicalUnit params ) {
532
674
@@ -551,6 +693,13 @@ else if ("rgb(".equalsIgnoreCase(funct)) {
551
693
params );
552
694
}
553
695
696
+ /**
697
+ * Processes a hexadecimal color definition.
698
+ *
699
+ * @param prev the previous lexical unit
700
+ * @param t the token
701
+ * @return a new lexical unit
702
+ */
554
703
protected LexicalUnit hexcolorInternal (final LexicalUnit prev , final Token t ) {
555
704
// Step past the hash at the beginning
556
705
final int i = 1 ;
@@ -598,6 +747,13 @@ else if (len == 6) {
598
747
}
599
748
}
600
749
750
+ /**
751
+ * Parses the sting into an integer.
752
+ *
753
+ * @param op the sign char
754
+ * @param s the string to parse
755
+ * @return the int value
756
+ */
601
757
protected int intValue (final char op , final String s ) {
602
758
final int result = Integer .parseInt (s );
603
759
if (op == '-' ) {
@@ -606,6 +762,13 @@ protected int intValue(final char op, final String s) {
606
762
return result ;
607
763
}
608
764
765
+ /**
766
+ * Parses the sting into an double.
767
+ *
768
+ * @param op the sign char
769
+ * @param s the string to parse
770
+ * @return the double value
771
+ */
609
772
protected double doubleValue (final char op , final String s ) {
610
773
final double result = Double .parseDouble (s );
611
774
if (op == '-' ) {
@@ -614,6 +777,12 @@ protected double doubleValue(final char op, final String s) {
614
777
return result ;
615
778
}
616
779
780
+ /**
781
+ * Returns the pos of the last numeric char in the given string.
782
+ *
783
+ * @param s the string to parse
784
+ * @return the pos
785
+ */
617
786
protected int getLastNumPos (final String s ) {
618
787
int i = 0 ;
619
788
for ( ; i < s .length (); i ++) {
0 commit comments