home *** CD-ROM | disk | FTP | other *** search
Wrap
import java.applet.Applet; import java.awt.Image; import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; public class FolderData { private Applet theApplet; private String dataFile = ""; private Folder rootFolder; private String defaultTarget; private Image defaultRoot; private Image defaultNode; private Image defaultOpen; private Image defaultClosed; private static final String OPENER = "<"; private static final String CLOSER = ">"; private String buffer = ""; public FolderData(String dataFile, Image defaultRoot, Image defaultNode, Image defaultOpen, Image defaultClosed, String defaultTarget, Applet theApplet) { this.dataFile = dataFile; this.defaultRoot = defaultRoot; this.defaultNode = defaultNode; this.defaultOpen = defaultOpen; this.defaultClosed = defaultClosed; this.defaultTarget = defaultTarget; this.theApplet = theApplet; DataInputStream in = this.openDataFile(this.dataFile); String tag = ""; while((tag = this.readSegment(in)) != null) { if (tag.equals("<FOLDER>")) { this.readFolder(in, (Folder)null); } } this.getRootFolder().setOpen(true); } private void readFolder(DataInputStream in, Folder parent) { String tag = ""; boolean closedIconGiven = false; boolean openIconGiven = false; Folder f1 = new Folder(parent); f1.setIconOpen(this.defaultNode); f1.setIconClosed(this.defaultNode); f1.setTarget(this.defaultTarget); for(String var7 = this.readSegment(in); var7 != null && !var7.equals("</FOLDER>"); var7 = this.readSegment(in)) { if (var7.equals("<HREF>")) { f1.setHRef(this.createURL(this.readSimpleField(in, "HREF"))); } else if (var7.equals("<TEXT>")) { f1.setText(this.readSimpleField(in, "TEXT")); } else if (var7.equals("<ICONOPEN>")) { f1.setIconOpen(this.theApplet.getImage(this.theApplet.getDocumentBase(), this.readSimpleField(in, "ICONOPEN"))); openIconGiven = true; } else if (var7.equals("<ICON>")) { f1.setIconClosed(this.theApplet.getImage(this.theApplet.getDocumentBase(), this.readSimpleField(in, "ICON"))); closedIconGiven = true; } else if (var7.equals("<FOLDER>")) { if (!openIconGiven) { f1.setIconOpen(this.defaultOpen); } if (!closedIconGiven) { f1.setIconClosed(this.defaultClosed); } this.readFolder(in, f1); } else if (var7.equals("<TARGET>")) { f1.setTarget(this.readSimpleField(in, "TARGET")); } else if (var7.equals("<WARNING>")) { f1.setWarning(this.readSimpleField(in, "WARNING")); } else if (var7.equals("<NOJAVA>")) { this.readSimpleField(in, "NOJAVA"); } else { this.alert(String.valueOf("Unknown text/tag: ").concat(String.valueOf(var7))); } } if (parent == null) { this.rootFolder = f1; this.rootFolder.setIconOpen(this.defaultRoot); this.rootFolder.setIconClosed(this.defaultRoot); } } private URL createURL(String u) { URL createURL = null; if (u != null) { try { createURL = new URL(this.theApplet.getDocumentBase(), u); } catch (MalformedURLException var4) { System.out.println(String.valueOf("Bad URL: ").concat(String.valueOf(u))); createURL = null; } } return createURL; } public Folder getRootFolder() { return this.rootFolder; } private String readSimpleField(DataInputStream in, String field) { String tag = ""; String text = ""; for(String var5 = this.readSegment(in); var5 != null && !var5.equals(String.valueOf(String.valueOf("</").concat(String.valueOf(field))).concat(String.valueOf(">"))); var5 = this.readSegment(in)) { if (var5.startsWith("<")) { this.alert(String.valueOf(String.valueOf(String.valueOf("Error found this in ").concat(String.valueOf(field))).concat(String.valueOf(" tag: "))).concat(String.valueOf(var5))); } else { text = String.valueOf(text).concat(String.valueOf(var5)); } } return text; } private DataInputStream openDataFile(String dataFile) { DataInputStream in = null; try { URL fileURL = new URL(this.theApplet.getDocumentBase(), dataFile); in = new DataInputStream(new BufferedInputStream(fileURL.openStream())); } catch (IOException e) { this.alert(String.valueOf(String.valueOf(String.valueOf("Cannot open ").concat(String.valueOf(dataFile))).concat(String.valueOf(": "))).concat(String.valueOf(((Throwable)e).getMessage()))); } return in; } public String readSegment(DataInputStream in) { String temp = ""; String temp2 = ""; String text = ""; if (!this.buffer.equals("")) { temp = this.buffer; } else { try { temp = in.readLine(); } catch (IOException e) { this.alert(String.valueOf("IOException: ").concat(String.valueOf(((Throwable)e).getMessage()))); } if (temp == null) { return temp; } } int pos1 = temp.indexOf("<"); int pos2 = temp.indexOf(">"); if (pos1 == -1) { this.buffer = ""; text = temp; } else { if (pos2 == -1) { for(String var10 = " "; !var10.equals("") && pos2 == -1; pos2 = temp.indexOf(">")) { try { var10 = in.readLine(); temp = String.valueOf(String.valueOf(temp).concat(String.valueOf(" "))).concat(String.valueOf(var10)); } catch (IOException e) { this.alert(String.valueOf("IOException: ").concat(String.valueOf(((Throwable)e).getMessage()))); } } if (pos2 == -1) { this.alert("No closing '>' on line"); } } if (pos1 == 0) { text = temp.substring(0, pos2 + ">".length()).toUpperCase(); this.buffer = temp.substring(pos2 + ">".length()); } else { text = temp.substring(0, pos1); this.buffer = temp.substring(pos1); } } if (text.startsWith("<?") || text.startsWith("<!")) { text = ""; } return text.trim(); } private void alert(String msg) { this.theApplet.showStatus(msg); } }