home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 4 / Macwelt DVD 4.cdr / Entwickler / Mac-OS / oxygen / oxygen.app / Contents / Resources / Java / jh.jar / javax / help / IndexView$IndexParser.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-06-24  |  5.1 KB  |  210 lines

  1. package javax.help;
  2.  
  3. import com.sun.java.help.impl.LangElement;
  4. import com.sun.java.help.impl.Parser;
  5. import com.sun.java.help.impl.ParserEvent;
  6. import com.sun.java.help.impl.ParserListener;
  7. import com.sun.java.help.impl.Tag;
  8. import com.sun.java.help.impl.TagProperties;
  9. import java.io.IOException;
  10. import java.io.Reader;
  11. import java.util.Hashtable;
  12. import java.util.Locale;
  13. import java.util.Stack;
  14. import javax.swing.tree.DefaultMutableTreeNode;
  15.  
  16. class IndexView$IndexParser implements ParserListener {
  17.    private HelpSet currentParseHS;
  18.    private Stack nodeStack;
  19.    private Stack itemStack;
  20.    private Stack tagStack;
  21.    private Locale defaultLocale;
  22.    private Locale lastLocale;
  23.    private boolean startedindex;
  24.    private TreeItemFactory factory;
  25.  
  26.    IndexView$IndexParser(TreeItemFactory var1) {
  27.       this.factory = var1;
  28.    }
  29.  
  30.    synchronized DefaultMutableTreeNode parse(Reader var1, HelpSet var2, Locale var3) throws IOException {
  31.       this.nodeStack = new Stack();
  32.       this.itemStack = new Stack();
  33.       this.tagStack = new Stack();
  34.       if (var3 == null) {
  35.          this.defaultLocale = Locale.getDefault();
  36.       } else {
  37.          this.defaultLocale = var3;
  38.       }
  39.  
  40.       this.lastLocale = this.defaultLocale;
  41.       DefaultMutableTreeNode var4 = new DefaultMutableTreeNode();
  42.       this.nodeStack.push(var4);
  43.       this.currentParseHS = var2;
  44.       Parser var5 = new Parser(var1);
  45.       var5.addParserListener(this);
  46.       var5.parse();
  47.       return var4;
  48.    }
  49.  
  50.    public void tagFound(ParserEvent var1) {
  51.       Locale var2 = null;
  52.       Tag var3 = var1.getTag();
  53.       TagProperties var4 = var3.atts;
  54.       if (var4 != null) {
  55.          String var5 = var4.getProperty("xml:lang");
  56.          var2 = HelpUtilities.localeFromLang(var5);
  57.       }
  58.  
  59.       if (var2 == null) {
  60.          var2 = this.lastLocale;
  61.       }
  62.  
  63.       if (var3.name.equals("indexitem")) {
  64.          if (!this.startedindex) {
  65.             this.factory.reportMessage(HelpUtilities.getText("index.invalidIndexFormat"), false);
  66.          }
  67.  
  68.          if (var3.isEnd && !var3.isEmpty) {
  69.             this.nodeStack.pop();
  70.             this.itemStack.pop();
  71.             this.removeTag(var3);
  72.             return;
  73.          }
  74.  
  75.          Object var9 = null;
  76.  
  77.          try {
  78.             Hashtable var6 = null;
  79.             if (var4 != null) {
  80.                var6 = var4.getHashtable();
  81.             }
  82.  
  83.             var10 = this.factory.createItem("indexitem", var6, this.currentParseHS, var2);
  84.          } catch (Exception var8) {
  85.             if (IndexView.access$000()) {
  86.                String var7 = null;
  87.                if (var4 != null) {
  88.                   var7 = var4.getProperty("target");
  89.                }
  90.  
  91.                System.err.println("Failure in IndexItem Creation; ");
  92.                System.err.println("  id: " + var7);
  93.                System.err.println("  hs: " + this.currentParseHS);
  94.             }
  95.  
  96.             var10 = this.factory.createItem();
  97.          }
  98.  
  99.          DefaultMutableTreeNode var12 = new DefaultMutableTreeNode(var10);
  100.          DefaultMutableTreeNode var13 = (DefaultMutableTreeNode)this.nodeStack.peek();
  101.          var13.add(var12);
  102.          if (!var3.isEmpty) {
  103.             this.itemStack.push(var10);
  104.             this.nodeStack.push(var12);
  105.             this.addTag(var3, var2);
  106.          }
  107.       } else if (var3.name.equals("index")) {
  108.          if (!var3.isEnd) {
  109.             if (var4 != null) {
  110.                String var11 = var4.getProperty("version");
  111.                if (var11 != null && var11.compareTo("1.0") != 0) {
  112.                   this.factory.reportMessage(HelpUtilities.getText("index.unknownVersion", var11), false);
  113.                }
  114.             }
  115.  
  116.             if (this.startedindex) {
  117.                this.factory.reportMessage(HelpUtilities.getText("index.invalidIndexFormat"), false);
  118.             }
  119.  
  120.             this.startedindex = true;
  121.             this.addTag(var3, var2);
  122.          } else {
  123.             if (this.startedindex) {
  124.                this.startedindex = false;
  125.             }
  126.  
  127.             this.removeTag(var3);
  128.          }
  129.  
  130.          return;
  131.       }
  132.  
  133.    }
  134.  
  135.    public void piFound(ParserEvent var1) {
  136.    }
  137.  
  138.    public void doctypeFound(ParserEvent var1) {
  139.       this.factory.processDOCTYPE(var1.getRoot(), var1.getPublicId(), var1.getSystemId());
  140.    }
  141.  
  142.    public void textFound(ParserEvent var1) {
  143.       if (!this.tagStack.empty()) {
  144.          LangElement var2 = (LangElement)this.tagStack.peek();
  145.          Tag var3 = var2.getTag();
  146.          if (var3.name.equals("indexitem")) {
  147.             IndexItem var4 = (IndexItem)this.itemStack.peek();
  148.             String var5 = var4.getName();
  149.             if (var5 == null) {
  150.                var4.setName(var1.getText().trim());
  151.             } else {
  152.                var4.setName(var5.concat(var1.getText()).trim());
  153.             }
  154.          }
  155.  
  156.       }
  157.    }
  158.  
  159.    public void commentFound(ParserEvent var1) {
  160.    }
  161.  
  162.    public void errorFound(ParserEvent var1) {
  163.       this.factory.reportMessage(var1.getText(), false);
  164.    }
  165.  
  166.    protected void addTag(Tag var1, Locale var2) {
  167.       LangElement var3 = new LangElement(var1, var2);
  168.       this.tagStack.push(var3);
  169.       if (this.lastLocale == null) {
  170.          this.lastLocale = var2;
  171.       } else if (var2 == null) {
  172.          this.lastLocale = var2;
  173.       } else {
  174.          if (!this.lastLocale.equals(var2)) {
  175.             this.lastLocale = var2;
  176.          }
  177.  
  178.       }
  179.    }
  180.  
  181.    protected void removeTag(Tag var1) {
  182.       String var3 = var1.name;
  183.       Locale var4 = null;
  184.  
  185.       while(!this.tagStack.empty()) {
  186.          LangElement var2 = (LangElement)this.tagStack.pop();
  187.          if (!var2.getTag().name.equals(var3)) {
  188.             if (this.tagStack.empty()) {
  189.                var4 = this.defaultLocale;
  190.             } else {
  191.                var2 = (LangElement)this.tagStack.peek();
  192.                var4 = var2.getLocale();
  193.             }
  194.             break;
  195.          }
  196.       }
  197.  
  198.       if (this.lastLocale == null) {
  199.          this.lastLocale = var4;
  200.       } else if (var4 == null) {
  201.          this.lastLocale = var4;
  202.       } else {
  203.          if (!this.lastLocale.equals(var4)) {
  204.             this.lastLocale = var4;
  205.          }
  206.  
  207.       }
  208.    }
  209. }
  210.