01: /*
02: * XmlTreeElement.java
03: *
04: * Copyright (C) 2000-2002 Peter Graves
05: * $Id: XmlTreeElement.java,v 1.2 2003/06/04 00:09:58 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.j;
23:
24: import org.xml.sax.Attributes;
25: import org.xml.sax.helpers.AttributesImpl;
26:
27: public final class XmlTreeElement {
28: private final String name;
29: private final Attributes attributes;
30: private final int lineNumber;
31: private final int columnNumber;
32:
33: public XmlTreeElement(String name, Attributes attributes,
34: int lineNumber, int columnNumber) {
35: this .name = name;
36: // Must copy attributes!
37: this .attributes = new AttributesImpl(attributes);
38: this .lineNumber = lineNumber;
39: this .columnNumber = columnNumber;
40: }
41:
42: public final String getName() {
43: return name;
44: }
45:
46: // This is used for the text in the sidebar tree.
47: public String toString() {
48: return getStatusText();
49: }
50:
51: public String getStatusText() {
52: FastStringBuffer sb = new FastStringBuffer(name);
53: for (int i = 0; i < attributes.getLength(); i++)
54: appendNameAndValue(sb, attributes.getQName(i), attributes
55: .getValue(i));
56: return sb.toString();
57: }
58:
59: private void appendNameAndValue(FastStringBuffer sb, String name,
60: String value) {
61: sb.append(' ');
62: sb.append(name);
63: sb.append("=");
64: final char quoteChar = value.indexOf('"') < 0 ? '"' : '\'';
65: sb.append(quoteChar);
66: sb.append(value);
67: sb.append(quoteChar);
68: }
69:
70: public final int getLineNumber() {
71: return lineNumber;
72: }
73:
74: public final int getColumnNumber() {
75: return columnNumber;
76: }
77: }
|