home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / text / html / StyleReader.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  4.7 KB  |  138 lines

  1. package com.sun.java.swing.text.html;
  2.  
  3. import com.sun.java.swing.text.Style;
  4. import com.sun.java.swing.text.StyleConstants;
  5. import com.sun.java.swing.text.StyleContext;
  6. import java.io.InputStream;
  7. import java.io.InputStreamReader;
  8. import java.util.Enumeration;
  9. import java.util.Vector;
  10.  
  11. class StyleReader extends HTMLStyleCallbackDefault {
  12.    public static final String DEFAULT_STYLE_HIERARCHY = "default-hierarchy";
  13.    public static final String CHILD_STYLE = "child-style";
  14.    private style32 styleParser;
  15.    private StyleContext styleContext;
  16.    private Style _newStyle;
  17.    private Style _parentStyle;
  18.    private String _name;
  19.    private Vector tags;
  20.    // $FF: renamed from: ss com.sun.java.swing.text.html.StyleSheet
  21.    protected static StyleSheet field_0 = new StyleSheet();
  22.  
  23.    public StyleReader(StyleContext var1) {
  24.       this.styleContext = var1;
  25.       Style var2 = this.styleContext.addStyle("default-hierarchy", (Style)null);
  26.       var2.addAttribute("child-style", this.styleContext.getStyle("default"));
  27.       field_0 = new StyleSheet(this.styleContext.getStyle("default-hierarchy"));
  28.       this.tags = new Vector();
  29.       this._parentStyle = this.styleContext.getStyle("default-hierarchy");
  30.    }
  31.  
  32.    public int read(StyleContext var1, int var2, InputStream var3) {
  33.       this.styleParser = new style32(new InputStreamReader(var3));
  34.       this.styleParser.setCallback(this);
  35.  
  36.       try {
  37.          this.styleParser.extstylesheet();
  38.       } catch (ParseException var5) {
  39.          System.out.println("Style Parse Error");
  40.          System.out.println(var5);
  41.       }
  42.  
  43.       return 0;
  44.    }
  45.  
  46.    public static StyleSheet getStyleSheet() {
  47.       return field_0;
  48.    }
  49.  
  50.    private String makePName(String var1) {
  51.       Object var2 = null;
  52.       String var3;
  53.       if (var1.equals("p")) {
  54.          var3 = "impliedp";
  55.       } else {
  56.          var3 = var1.substring(0, var1.length() - 1) + "impliedp";
  57.       }
  58.  
  59.       return var3;
  60.    }
  61.  
  62.    private void dumpStyles(Style var1, String var2) {
  63.       Enumeration var3 = var1.getAttributeNames();
  64.  
  65.       while(var3.hasMoreElements()) {
  66.          Object var4 = var3.nextElement();
  67.          Object var5 = var1.getAttribute(var4);
  68.          if (!var4.equals(StyleConstants.ResolveAttribute)) {
  69.             System.out.println(var2 + var4.toString() + " = " + var5.toString());
  70.          }
  71.  
  72.          if (var5 instanceof Style && !var4.equals(StyleConstants.ResolveAttribute)) {
  73.             this.dumpStyles((Style)var5, var2 + "  ");
  74.          }
  75.       }
  76.  
  77.    }
  78.  
  79.    public void tagAction(String var1) {
  80.       if (var1.equals("body")) {
  81.          this._parentStyle = this.styleContext.getStyle("default-hierarchy");
  82.       }
  83.  
  84.       this.tags.addElement(var1);
  85.       String var2 = this.makeStyleName();
  86.       Object var3 = null;
  87.       if (!var1.equals("body")) {
  88.          this._newStyle = this.styleContext.getStyle("SH" + var2);
  89.          if (this._newStyle == null) {
  90.             this._newStyle = this.styleContext.addStyle("SH" + var2, (Style)null);
  91.             Style var4 = (Style)this._parentStyle.getAttribute("child-style");
  92.             Style var5 = this.styleContext.addStyle(var2, var4);
  93.             this._newStyle.addAttribute("child-style", var5);
  94.             this._newStyle.addAttribute(StyleConstants.ResolveAttribute, this._parentStyle);
  95.             this._parentStyle.addAttribute("SH" + var1, this._newStyle);
  96.          }
  97.       } else {
  98.          this._newStyle = this._parentStyle;
  99.       }
  100.  
  101.       this._parentStyle = this._newStyle;
  102.    }
  103.  
  104.    public void depTagAction() {
  105.    }
  106.  
  107.    public void classAction(String var1) {
  108.    }
  109.  
  110.    public void pseudoclassAction(String var1) {
  111.    }
  112.  
  113.    public void propertyAction(String var1) {
  114.       this._name = var1;
  115.    }
  116.  
  117.    public void valueAction(String var1) {
  118.       Style var2 = (Style)this._newStyle.getAttribute("child-style");
  119.       StyleXlater.translateProperty(field_0, var2, this._name, var1);
  120.       this.tags.removeAllElements();
  121.       this._parentStyle = this.styleContext.getStyle("default-hierarchy");
  122.    }
  123.  
  124.    private String makeStyleName() {
  125.       int var1 = this.tags.size();
  126.       String var2 = new String();
  127.       String var3 = (String)this.tags.elementAt(0);
  128.       var2 = var2 + var3;
  129.  
  130.       for(int var4 = 1; var4 < var1; ++var4) {
  131.          var3 = (String)this.tags.elementAt(var4);
  132.          var2 = var2 + " " + var3;
  133.       }
  134.  
  135.       return var2;
  136.    }
  137. }
  138.