home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / windowsxp / ftgateoffice / ftgateoffice.exe / Main / webhelp.cab / sitemap / SiteMapParser.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-11-07  |  4.9 KB  |  271 lines

  1. package sitemap;
  2.  
  3. import hhapplet.ResourceLib;
  4. import hhapplet.URLFileHandler;
  5. import java.applet.Applet;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.net.MalformedURLException;
  9. import java.net.URL;
  10. import java.util.Properties;
  11. import java.util.zip.ZipEntry;
  12. import java.util.zip.ZipInputStream;
  13.  
  14. public class SiteMapParser extends Thread {
  15.    protected MyBufferedInputStream m_isInputStream;
  16.    protected Properties m_properties;
  17.    protected SiteMapParserOutput m_smpoOutput;
  18.    protected String m_strFileName;
  19.    protected URL m_urlDocBase;
  20.    protected Applet m_applet;
  21.    protected boolean m_bParseFinish = false;
  22.    private boolean m_bZipSupport = false;
  23.    private boolean m_bZipFileLoaded = false;
  24.    private InputStream m_ZipIs = null;
  25.  
  26.    public synchronized void parse() {
  27.       boolean var1 = false;
  28.       this.m_bParseFinish = false;
  29.       this.m_bZipFileLoaded = false;
  30.       if (!this.m_smpoOutput.matchType(this.m_strFileName) && !this.m_strFileName.toLowerCase().endsWith(".zip")) {
  31.          boolean var9 = false;
  32.          if (this.m_strFileName.indexOf(63) != -1) {
  33.             var9 = false;
  34.          } else {
  35.             var9 = true;
  36.          }
  37.  
  38.          if (this.m_bZipSupport) {
  39.             try {
  40.                InputStream var11 = URLFileHandler.makeURL(this.m_urlDocBase, this.m_strFileName + (var9 ? "?" : "&") + "zip=1", (String)null).openStream();
  41.                ZipInputStream var4 = new ZipInputStream(var11);
  42.                this.m_ZipIs = var4;
  43.                this.getImageandParseForZip(var4);
  44.             } catch (Exception var7) {
  45.                if (!(var7 instanceof MalformedURLException) && !(var7 instanceof IOException)) {
  46.                   var1 = true;
  47.                }
  48.             }
  49.          }
  50.  
  51.          if (!var1 && (!this.m_bZipSupport || !this.m_bZipFileLoaded)) {
  52.             try {
  53.                this.m_isInputStream = new MyBufferedInputStream(URLFileHandler.makeURL(this.m_urlDocBase, this.m_strFileName + (var9 ? "?" : "&") + "zip=0", (String)null).openStream());
  54.                this.realParse();
  55.                return;
  56.             } catch (Exception var5) {
  57.                this.m_smpoOutput.throwMessage(ResourceLib.GetRes("CantOpenURLorFile") + " " + ((Throwable)var5).getMessage());
  58.                ((Throwable)var5).printStackTrace();
  59.                return;
  60.             }
  61.          }
  62.       } else {
  63.          if (this.m_bZipSupport && this.m_strFileName.toLowerCase().endsWith(".zip")) {
  64.             try {
  65.                InputStream var2 = URLFileHandler.makeURL(this.m_urlDocBase, this.m_strFileName, (String)null).openStream();
  66.                ZipInputStream var3 = new ZipInputStream(var2);
  67.                this.m_ZipIs = var3;
  68.                this.getImageandParseForZip(var3);
  69.             } catch (Exception var8) {
  70.                if (!(var8 instanceof MalformedURLException) && !(var8 instanceof IOException)) {
  71.                   var1 = true;
  72.                }
  73.             }
  74.          } else if (this.m_strFileName.toLowerCase().endsWith(".zip")) {
  75.             return;
  76.          }
  77.  
  78.          if (!var1 && (!this.m_bZipSupport || !this.m_bZipFileLoaded)) {
  79.             try {
  80.                this.m_isInputStream = new MyBufferedInputStream(URLFileHandler.makeURL(this.m_urlDocBase, this.m_strFileName, (String)null).openStream());
  81.                this.realParse();
  82.                return;
  83.             } catch (Exception var6) {
  84.                this.m_smpoOutput.throwMessage(ResourceLib.GetRes("CantOpenURLorFile") + " " + ((Throwable)var6).getMessage());
  85.                ((Throwable)var6).printStackTrace();
  86.                return;
  87.             }
  88.          }
  89.       }
  90.  
  91.    }
  92.  
  93.    public SiteMapParserOutput getOutput() {
  94.       return this.m_smpoOutput;
  95.    }
  96.  
  97.    public Thread parseInSeparateThread(String var1, URL var2, Applet var3) {
  98.       this.m_strFileName = var1;
  99.       this.m_urlDocBase = var2;
  100.       this.m_applet = var3;
  101.       ((Thread)this).setPriority(4);
  102.       ((Thread)this).start();
  103.       return this;
  104.    }
  105.  
  106.    public SiteMapParser(SiteMapParserOutput var1) {
  107.       this.m_smpoOutput = var1;
  108.       this.m_properties = new Properties();
  109.  
  110.       try {
  111.          Class.forName("java.util.zip.ZipFile");
  112.          this.m_bZipSupport = true;
  113.       } catch (ClassNotFoundException var3) {
  114.          ((Throwable)var3).printStackTrace();
  115.          this.m_bZipSupport = false;
  116.       }
  117.    }
  118.  
  119.    public void parseInCurrentThread(String var1, URL var2, Applet var3) {
  120.       this.m_strFileName = var1;
  121.       this.m_urlDocBase = var2;
  122.       this.m_applet = var3;
  123.       this.parse();
  124.    }
  125.  
  126.    protected void parseULTag() throws TagInvalidException {
  127.       for(Tag var1 = Tag.readTag(this.m_isInputStream); !(var1 instanceof UlEndTag); var1 = Tag.readTag(this.m_isInputStream)) {
  128.          if (var1 instanceof LiTag) {
  129.             this.parseLiTag();
  130.          } else if (var1 instanceof UlTag) {
  131.             this.m_smpoOutput.indent(1);
  132.             this.parseULTag();
  133.             this.m_smpoOutput.indent(-1);
  134.          }
  135.       }
  136.  
  137.    }
  138.  
  139.    public void closeFiles() {
  140.       if (this.m_isInputStream != null) {
  141.          try {
  142.             this.m_isInputStream.close();
  143.          } catch (Exception var2) {
  144.             ((Throwable)var2).printStackTrace();
  145.          }
  146.       }
  147.    }
  148.  
  149.    public void realParse() {
  150.       int var1 = 0;
  151.       this.m_smpoOutput.start();
  152.  
  153.       try {
  154.          for(Tag var2 = Tag.readTag(this.m_isInputStream); !(var2 instanceof HtmlTag); var2 = Tag.readTag(this.m_isInputStream)) {
  155.          }
  156.  
  157.          Tag var8 = Tag.readTag(this.m_isInputStream);
  158.  
  159.          while(!(var8 instanceof HtmlEndTag)) {
  160.             if (var8 instanceof ObjectTag) {
  161.                if (((ObjectTag)var8).getType().equalsIgnoreCase("text/site properties")) {
  162.                   for(Tag var9 = Tag.readTag(this.m_isInputStream); !(var9 instanceof ObjectEndTag); var9 = Tag.readTag(this.m_isInputStream)) {
  163.                      if (var9 instanceof ParamTag) {
  164.                         try {
  165.                            this.m_smpoOutput.param(((ParamTag)var9).getName(), ((ParamTag)var9).getValue());
  166.                         } catch (NullPointerException var6) {
  167.                            ((Throwable)var6).printStackTrace();
  168.                         }
  169.                      }
  170.                   }
  171.                } else {
  172.                   while(!(var8 instanceof ObjectEndTag)) {
  173.                      var8 = Tag.readTag(this.m_isInputStream);
  174.                   }
  175.                }
  176.             } else if (var8 instanceof UlTag) {
  177.                this.parseULTag();
  178.             }
  179.  
  180.             var8 = Tag.readTag(this.m_isInputStream);
  181.             ++var1;
  182.             if (var1 % 10 == 0) {
  183.                System.gc();
  184.                Runtime.getRuntime().gc();
  185.             }
  186.          }
  187.       } catch (TagInvalidException var7) {
  188.          this.m_applet.showStatus("Exception occur!");
  189.          ((Throwable)var7).printStackTrace();
  190.       }
  191.  
  192.       try {
  193.          this.m_isInputStream.close();
  194.       } catch (Exception var5) {
  195.       }
  196.  
  197.       if (this.m_ZipIs != null) {
  198.          try {
  199.             this.m_ZipIs.close();
  200.          } catch (Exception var4) {
  201.          }
  202.  
  203.          this.m_ZipIs = null;
  204.       }
  205.  
  206.       this.m_smpoOutput.end();
  207.       this.m_bParseFinish = true;
  208.    }
  209.  
  210.    public boolean IsFinish() {
  211.       return this.m_bParseFinish;
  212.    }
  213.  
  214.    protected void parseLiTag() throws TagInvalidException {
  215.       Tag var1 = Tag.readTag(this.m_isInputStream);
  216.       if (!(var1 instanceof ObjectTag)) {
  217.          if (var1 instanceof UlTag) {
  218.             this.m_smpoOutput.indent(1);
  219.             this.parseULTag();
  220.             this.m_smpoOutput.indent(-1);
  221.          }
  222.  
  223.       } else {
  224.          this.m_smpoOutput.object_start();
  225.          if (((ObjectTag)var1).getType().equalsIgnoreCase("text/sitemap")) {
  226.             for(Tag var2 = Tag.readTag(this.m_isInputStream); !(var2 instanceof ObjectEndTag); var2 = Tag.readTag(this.m_isInputStream)) {
  227.                if (var2 instanceof ParamTag) {
  228.                   this.m_smpoOutput.param(((ParamTag)var2).getName(), ((ParamTag)var2).getValue());
  229.                }
  230.             }
  231.  
  232.             this.m_smpoOutput.object_end();
  233.          } else {
  234.             while(!(var1 instanceof ObjectEndTag)) {
  235.                var1 = Tag.readTag(this.m_isInputStream);
  236.             }
  237.  
  238.          }
  239.       }
  240.    }
  241.  
  242.    public void getImageandParseForZip(ZipInputStream var1) throws IOException {
  243.       while(true) {
  244.          ZipEntry var2 = var1.getNextEntry();
  245.          if (var2 == null) {
  246.             return;
  247.          }
  248.  
  249.          if (var2.getName().toLowerCase().endsWith("gif")) {
  250.             this.m_smpoOutput.putImage(var2.getName(), var2.getSize(), var1);
  251.          }
  252.  
  253.          if (this.m_smpoOutput.matchType(var2.getName())) {
  254.             this.m_isInputStream = new MyBufferedInputStream(var1);
  255.             this.realParse();
  256.             this.m_bZipFileLoaded = true;
  257.          }
  258.  
  259.          var1.closeEntry();
  260.       }
  261.    }
  262.  
  263.    public void run() {
  264.       try {
  265.          this.parse();
  266.       } catch (Exception var2) {
  267.          ((Throwable)var2).printStackTrace();
  268.       }
  269.    }
  270. }
  271.