001: /*
002: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License version
007: * 2 only, as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful, but
010: * WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * General Public License version 2 for more details (a copy is
013: * included at /legal/license.txt).
014: *
015: * You should have received a copy of the GNU General Public License
016: * version 2 along with this work; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018: * 02110-1301 USA
019: *
020: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021: * Clara, CA 95054 or visit www.sun.com if you need additional
022: * information or have any questions.
023: */
024:
025: package com.sun.jumpimpl.module.download;
026:
027: import java.io.CharArrayWriter;
028: import java.util.Enumeration;
029: import java.util.Hashtable;
030: import java.util.Vector;
031:
032: import org.xml.sax.Attributes;
033: import org.xml.sax.SAXException;
034: import org.xml.sax.helpers.DefaultHandler;
035:
036: class DocumentElement extends DefaultHandler {
037: String name = null;
038: String nameSpace = null; // If a Document
039: Hashtable attributes = new Hashtable();
040: Vector elements = new Vector();
041: DocumentElement parent = null;
042: boolean isDocument = false;
043:
044: // Have we encountered an error?
045: boolean fastForward = false;
046: int cdepth = 0;
047:
048: // Accumulate contents
049: private CharArrayWriter contents = new CharArrayWriter();
050:
051: DocumentElement(String s, boolean isDoc, DocumentElement parent) {
052: name = s;
053: isDocument = isDoc;
054: this .parent = parent;
055: }
056:
057: String getName() {
058: return name;
059: }
060:
061: void setFastForward(boolean trueFalse) {
062: fastForward = trueFalse;
063: return;
064: }
065:
066: void addAttribute(String attrName, String value) {
067: attributes.put(attrName, value);
068: return;
069: }
070:
071: String getAttribute(String attrName) {
072: return (String) attributes.get(attrName);
073: }
074:
075: void addElement(DocumentElement e) {
076: elements.add(e);
077: return;
078: }
079:
080: String getValue() {
081: return contents.toString().trim();
082: }
083:
084: public String toString() {
085: String s = "attributes:\n";
086: Enumeration e = attributes.keys();
087: while (e.hasMoreElements()) {
088: String attrName = (String) e.nextElement();
089: s += attrName + " -> " + (String) attributes.get(attrName)
090: + "\n";
091: }
092: if (!elements.isEmpty()) {
093: s += "elements: [ ";
094: e = elements.elements();
095: while (e.hasMoreElements()) {
096: DocumentElement de = (DocumentElement) e.nextElement();
097: s += de.toString();
098: }
099: s += "] ";
100: }
101: s += "value: " + getValue();
102: return "\n[ Document Element:\nname: " + name + "\n" + s + " ]";
103: }
104:
105: public void addCharacters(char[] ch, int start, int length) {
106: // accumulate
107: contents.write(ch, start, length);
108: return;
109: }
110:
111: public void warning(SAXException se) {
112: setFastForward(true);
113: // parent.setFastForward( true );
114: se.printStackTrace();
115: return;
116: }
117: }
|