home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / text / html / StyleSheet$CssParser.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  3.1 KB  |  124 lines

  1. package javax.swing.text.html;
  2.  
  3. import java.io.IOException;
  4. import java.io.Reader;
  5. import java.io.StringReader;
  6. import java.net.URL;
  7. import java.util.Vector;
  8. import javax.swing.text.AttributeSet;
  9. import javax.swing.text.MutableAttributeSet;
  10. import javax.swing.text.SimpleAttributeSet;
  11.  
  12. class StyleSheet$CssParser implements CSSParser.CSSParserCallback {
  13.    Vector selectors;
  14.    Vector selectorTokens;
  15.    String propertyName;
  16.    MutableAttributeSet declaration;
  17.    boolean parsingDeclaration;
  18.    boolean isLink;
  19.    URL base;
  20.    CSSParser parser;
  21.    // $FF: synthetic field
  22.    private final StyleSheet this$0;
  23.  
  24.    StyleSheet$CssParser(StyleSheet var1) {
  25.       this.this$0 = var1;
  26.       this.selectors = new Vector();
  27.       this.selectorTokens = new Vector();
  28.       this.declaration = new SimpleAttributeSet();
  29.       this.parser = new CSSParser();
  30.    }
  31.  
  32.    public AttributeSet parseDeclaration(String var1) {
  33.       try {
  34.          return this.parseDeclaration((Reader)(new StringReader(var1)));
  35.       } catch (IOException var3) {
  36.          return null;
  37.       }
  38.    }
  39.  
  40.    public AttributeSet parseDeclaration(Reader var1) throws IOException {
  41.       this.parse(this.base, var1, true, false);
  42.       return this.declaration.copyAttributes();
  43.    }
  44.  
  45.    public void parse(URL var1, Reader var2, boolean var3, boolean var4) throws IOException {
  46.       this.base = var1;
  47.       this.isLink = var4;
  48.       this.parsingDeclaration = var3;
  49.       this.declaration.removeAttributes(this.declaration);
  50.       this.selectorTokens.removeAllElements();
  51.       this.selectors.removeAllElements();
  52.       this.propertyName = null;
  53.       this.parser.parse(var2, this, var3);
  54.    }
  55.  
  56.    public void handleImport(String var1) {
  57.       URL var2 = CSS.getURL(this.base, var1);
  58.       if (var2 != null) {
  59.          this.this$0.importStyleSheet(var2);
  60.       }
  61.  
  62.    }
  63.  
  64.    public void handleSelector(String var1) {
  65.       int var2 = var1.length();
  66.       if (var1.endsWith(",")) {
  67.          if (var2 > 1) {
  68.             var1 = var1.substring(0, var2 - 1);
  69.             this.selectorTokens.addElement(var1);
  70.          }
  71.  
  72.          this.addSelector();
  73.       } else if (var2 > 0) {
  74.          this.selectorTokens.addElement(var1);
  75.       }
  76.  
  77.    }
  78.  
  79.    public void startRule() {
  80.       if (this.selectorTokens.size() > 0) {
  81.          this.addSelector();
  82.       }
  83.  
  84.       this.propertyName = null;
  85.    }
  86.  
  87.    public void handleProperty(String var1) {
  88.       this.propertyName = var1;
  89.    }
  90.  
  91.    public void handleValue(String var1) {
  92.       if (this.propertyName != null) {
  93.          CSS.Attribute var2 = CSS.getAttribute(this.propertyName);
  94.          if (var2 != null) {
  95.             this.this$0.addCSSAttribute(this.declaration, var2, var1);
  96.          }
  97.  
  98.          this.propertyName = null;
  99.       }
  100.  
  101.    }
  102.  
  103.    public void endRule() {
  104.       int var1 = this.selectors.size();
  105.  
  106.       for(int var2 = 0; var2 < var1; ++var2) {
  107.          String[] var3 = (String[])this.selectors.elementAt(var2);
  108.          if (var3.length > 0) {
  109.             this.this$0.addRule(var3, this.declaration, this.isLink);
  110.          }
  111.       }
  112.  
  113.       this.declaration.removeAttributes(this.declaration);
  114.       this.selectors.removeAllElements();
  115.    }
  116.  
  117.    private void addSelector() {
  118.       String[] var1 = new String[this.selectorTokens.size()];
  119.       this.selectorTokens.copyInto(var1);
  120.       this.selectors.addElement(var1);
  121.       this.selectorTokens.removeAllElements();
  122.    }
  123. }
  124.