home *** CD-ROM | disk | FTP | other *** search
- package sitemap;
-
- import hhapplet.ResourceLib;
- import hhapplet.URLFileHandler;
- import java.applet.Applet;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.Properties;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipInputStream;
-
- public class SiteMapParser extends Thread {
- protected MyBufferedInputStream m_isInputStream;
- protected Properties m_properties;
- protected SiteMapParserOutput m_smpoOutput;
- protected String m_strFileName;
- protected URL m_urlDocBase;
- protected Applet m_applet;
- protected boolean m_bParseFinish = false;
- private boolean m_bZipSupport = false;
- private boolean m_bZipFileLoaded = false;
- private InputStream m_ZipIs = null;
-
- public synchronized void parse() {
- boolean var1 = false;
- this.m_bParseFinish = false;
- this.m_bZipFileLoaded = false;
- if (!this.m_smpoOutput.matchType(this.m_strFileName) && !this.m_strFileName.toLowerCase().endsWith(".zip")) {
- boolean var9 = false;
- if (this.m_strFileName.indexOf(63) != -1) {
- var9 = false;
- } else {
- var9 = true;
- }
-
- if (this.m_bZipSupport) {
- try {
- InputStream var11 = URLFileHandler.makeURL(this.m_urlDocBase, this.m_strFileName + (var9 ? "?" : "&") + "zip=1", (String)null).openStream();
- ZipInputStream var4 = new ZipInputStream(var11);
- this.m_ZipIs = var4;
- this.getImageandParseForZip(var4);
- } catch (Exception var7) {
- if (!(var7 instanceof MalformedURLException) && !(var7 instanceof IOException)) {
- var1 = true;
- }
- }
- }
-
- if (!var1 && (!this.m_bZipSupport || !this.m_bZipFileLoaded)) {
- try {
- this.m_isInputStream = new MyBufferedInputStream(URLFileHandler.makeURL(this.m_urlDocBase, this.m_strFileName + (var9 ? "?" : "&") + "zip=0", (String)null).openStream());
- this.realParse();
- return;
- } catch (Exception var5) {
- this.m_smpoOutput.throwMessage(ResourceLib.GetRes("CantOpenURLorFile") + " " + ((Throwable)var5).getMessage());
- ((Throwable)var5).printStackTrace();
- return;
- }
- }
- } else {
- if (this.m_bZipSupport && this.m_strFileName.toLowerCase().endsWith(".zip")) {
- try {
- InputStream var2 = URLFileHandler.makeURL(this.m_urlDocBase, this.m_strFileName, (String)null).openStream();
- ZipInputStream var3 = new ZipInputStream(var2);
- this.m_ZipIs = var3;
- this.getImageandParseForZip(var3);
- } catch (Exception var8) {
- if (!(var8 instanceof MalformedURLException) && !(var8 instanceof IOException)) {
- var1 = true;
- }
- }
- } else if (this.m_strFileName.toLowerCase().endsWith(".zip")) {
- return;
- }
-
- if (!var1 && (!this.m_bZipSupport || !this.m_bZipFileLoaded)) {
- try {
- this.m_isInputStream = new MyBufferedInputStream(URLFileHandler.makeURL(this.m_urlDocBase, this.m_strFileName, (String)null).openStream());
- this.realParse();
- return;
- } catch (Exception var6) {
- this.m_smpoOutput.throwMessage(ResourceLib.GetRes("CantOpenURLorFile") + " " + ((Throwable)var6).getMessage());
- ((Throwable)var6).printStackTrace();
- return;
- }
- }
- }
-
- }
-
- public SiteMapParserOutput getOutput() {
- return this.m_smpoOutput;
- }
-
- public Thread parseInSeparateThread(String var1, URL var2, Applet var3) {
- this.m_strFileName = var1;
- this.m_urlDocBase = var2;
- this.m_applet = var3;
- ((Thread)this).setPriority(4);
- ((Thread)this).start();
- return this;
- }
-
- public SiteMapParser(SiteMapParserOutput var1) {
- this.m_smpoOutput = var1;
- this.m_properties = new Properties();
-
- try {
- Class.forName("java.util.zip.ZipFile");
- this.m_bZipSupport = true;
- } catch (ClassNotFoundException var3) {
- ((Throwable)var3).printStackTrace();
- this.m_bZipSupport = false;
- }
- }
-
- public void parseInCurrentThread(String var1, URL var2, Applet var3) {
- this.m_strFileName = var1;
- this.m_urlDocBase = var2;
- this.m_applet = var3;
- this.parse();
- }
-
- protected void parseULTag() throws TagInvalidException {
- for(Tag var1 = Tag.readTag(this.m_isInputStream); !(var1 instanceof UlEndTag); var1 = Tag.readTag(this.m_isInputStream)) {
- if (var1 instanceof LiTag) {
- this.parseLiTag();
- } else if (var1 instanceof UlTag) {
- this.m_smpoOutput.indent(1);
- this.parseULTag();
- this.m_smpoOutput.indent(-1);
- }
- }
-
- }
-
- public void closeFiles() {
- if (this.m_isInputStream != null) {
- try {
- this.m_isInputStream.close();
- } catch (Exception var2) {
- ((Throwable)var2).printStackTrace();
- }
- }
- }
-
- public void realParse() {
- int var1 = 0;
- this.m_smpoOutput.start();
-
- try {
- for(Tag var2 = Tag.readTag(this.m_isInputStream); !(var2 instanceof HtmlTag); var2 = Tag.readTag(this.m_isInputStream)) {
- }
-
- Tag var8 = Tag.readTag(this.m_isInputStream);
-
- while(!(var8 instanceof HtmlEndTag)) {
- if (var8 instanceof ObjectTag) {
- if (((ObjectTag)var8).getType().equalsIgnoreCase("text/site properties")) {
- for(Tag var9 = Tag.readTag(this.m_isInputStream); !(var9 instanceof ObjectEndTag); var9 = Tag.readTag(this.m_isInputStream)) {
- if (var9 instanceof ParamTag) {
- try {
- this.m_smpoOutput.param(((ParamTag)var9).getName(), ((ParamTag)var9).getValue());
- } catch (NullPointerException var6) {
- ((Throwable)var6).printStackTrace();
- }
- }
- }
- } else {
- while(!(var8 instanceof ObjectEndTag)) {
- var8 = Tag.readTag(this.m_isInputStream);
- }
- }
- } else if (var8 instanceof UlTag) {
- this.parseULTag();
- }
-
- var8 = Tag.readTag(this.m_isInputStream);
- ++var1;
- if (var1 % 10 == 0) {
- System.gc();
- Runtime.getRuntime().gc();
- }
- }
- } catch (TagInvalidException var7) {
- this.m_applet.showStatus("Exception occur!");
- ((Throwable)var7).printStackTrace();
- }
-
- try {
- this.m_isInputStream.close();
- } catch (Exception var5) {
- }
-
- if (this.m_ZipIs != null) {
- try {
- this.m_ZipIs.close();
- } catch (Exception var4) {
- }
-
- this.m_ZipIs = null;
- }
-
- this.m_smpoOutput.end();
- this.m_bParseFinish = true;
- }
-
- public boolean IsFinish() {
- return this.m_bParseFinish;
- }
-
- protected void parseLiTag() throws TagInvalidException {
- Tag var1 = Tag.readTag(this.m_isInputStream);
- if (!(var1 instanceof ObjectTag)) {
- if (var1 instanceof UlTag) {
- this.m_smpoOutput.indent(1);
- this.parseULTag();
- this.m_smpoOutput.indent(-1);
- }
-
- } else {
- this.m_smpoOutput.object_start();
- if (((ObjectTag)var1).getType().equalsIgnoreCase("text/sitemap")) {
- for(Tag var2 = Tag.readTag(this.m_isInputStream); !(var2 instanceof ObjectEndTag); var2 = Tag.readTag(this.m_isInputStream)) {
- if (var2 instanceof ParamTag) {
- this.m_smpoOutput.param(((ParamTag)var2).getName(), ((ParamTag)var2).getValue());
- }
- }
-
- this.m_smpoOutput.object_end();
- } else {
- while(!(var1 instanceof ObjectEndTag)) {
- var1 = Tag.readTag(this.m_isInputStream);
- }
-
- }
- }
- }
-
- public void getImageandParseForZip(ZipInputStream var1) throws IOException {
- while(true) {
- ZipEntry var2 = var1.getNextEntry();
- if (var2 == null) {
- return;
- }
-
- if (var2.getName().toLowerCase().endsWith("gif")) {
- this.m_smpoOutput.putImage(var2.getName(), var2.getSize(), var1);
- }
-
- if (this.m_smpoOutput.matchType(var2.getName())) {
- this.m_isInputStream = new MyBufferedInputStream(var1);
- this.realParse();
- this.m_bZipFileLoaded = true;
- }
-
- var1.closeEntry();
- }
- }
-
- public void run() {
- try {
- this.parse();
- } catch (Exception var2) {
- ((Throwable)var2).printStackTrace();
- }
- }
- }
-