001: package vicazh.hyperpool.stream.net.http.html;
002:
003: import java.io.*;
004: import java.util.*;
005: import javax.swing.text.html.*;
006: import javax.swing.text.*;
007: import vicazh.hyperpool.stream.*;
008: import vicazh.hyperpool.stream.net.http.*;
009:
010: class TaskStream extends Stream {
011: TaskStream(Session session) {
012: super (session, new NullStream());
013: }
014:
015: boolean c;
016:
017: public void field(String s1, String s2) throws IOException {
018: if (s1.equalsIgnoreCase("Location"))
019: ((TaskSession) session).src(s2);
020: else if (s1.equalsIgnoreCase("Connection")
021: && s2.equalsIgnoreCase("close"))
022: c = true;
023: super .field(s1, s2);
024: }
025:
026: private boolean b;
027:
028: public void start(HTML.Tag tag, MutableAttributeSet attributes,
029: int position) throws IOException {
030: super .start(tag, attributes, position);
031: if (tag == HTML.Tag.SCRIPT)
032: b = true;
033: if (b)
034: return;
035: // if (tag == HTML.Tag.A) {
036: Enumeration<?> e = attributes.getAttributeNames();
037: while (e.hasMoreElements()) {
038: Object name = e.nextElement();
039: if (name == HTML.Attribute.HREF) {
040: String s = (String) attributes.getAttribute(name);
041: if (s.indexOf(':') == -1 ? !s.startsWith("#") : (s
042: .startsWith("http:") || s.startsWith("ftp:")))
043: ((TaskSession) session).href(s);
044: } else if (name == HTML.Attribute.CODE) {
045: String s = (String) attributes.getAttribute(name);
046: if (!s.endsWith(".class"))
047: s += ".class";
048: ((TaskSession) session).src(s);
049: } else if (name == HTML.Attribute.ARCHIVE
050: || name == HTML.Attribute.BACKGROUND)
051: ((TaskSession) session).src((String) attributes
052: .getAttribute(name));
053: }
054: // }
055: }
056:
057: public void end(HTML.Tag tag, int position) throws IOException {
058: super .end(tag, position);
059: if (tag == HTML.Tag.SCRIPT)
060: b = false;
061: }
062:
063: public void simple(HTML.Tag tag, MutableAttributeSet attributes,
064: int position) throws IOException {
065: super .simple(tag, attributes, position);
066: if (b || tag == HTML.Tag.AREA)
067: return;
068: // if (tag == HTML.Tag.FRAME
069: // || tag == HTML.Tag.IMG
070: // || tag == HTML.Tag.LINK) {
071: Enumeration<?> e = attributes.getAttributeNames();
072: while (e.hasMoreElements()) {
073: Object name = e.nextElement();
074: if (name == HTML.Attribute.SRC
075: || name == HTML.Attribute.HREF)
076: ((TaskSession) session).src((String) attributes
077: .getAttribute(name));
078: }
079: // }
080: }
081:
082: public void end() {
083: super .end();
084: try {
085: if (c)
086: session.connection.getClient().close();
087: } catch (IOException e) {
088: }
089: }
090:
091: public void close() throws IOException {
092: super .close();
093: session.connection.getClient().close();
094: }
095:
096: protected void go() {
097: if (getCode() == ServerStream.OK)
098: super.go();
099: }
100: }
|