KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > XmlTreeElement


1 /*
2  * XmlTreeElement.java
3  *
4  * Copyright (C) 2000-2002 Peter Graves
5  * $Id: XmlTreeElement.java,v 1.2 2003/06/04 00:09:58 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * 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 JavaDoc;
25 import org.xml.sax.helpers.AttributesImpl JavaDoc;
26
27 public final class XmlTreeElement
28 {
29     private final String JavaDoc name;
30     private final Attributes JavaDoc attributes;
31     private final int lineNumber;
32     private final int columnNumber;
33
34     public XmlTreeElement(String JavaDoc name, Attributes JavaDoc attributes, int lineNumber,
35         int columnNumber)
36     {
37         this.name = name;
38         // Must copy attributes!
39
this.attributes = new AttributesImpl JavaDoc(attributes);
40         this.lineNumber = lineNumber;
41         this.columnNumber = columnNumber;
42     }
43
44     public final String JavaDoc getName()
45     {
46         return name;
47     }
48
49     // This is used for the text in the sidebar tree.
50
public String JavaDoc toString()
51     {
52         return getStatusText();
53     }
54
55     public String JavaDoc getStatusText()
56     {
57         FastStringBuffer sb = new FastStringBuffer(name);
58         for (int i = 0; i < attributes.getLength(); i++)
59             appendNameAndValue(sb, attributes.getQName(i), attributes.getValue(i));
60         return sb.toString();
61     }
62
63     private void appendNameAndValue(FastStringBuffer sb, String JavaDoc name, String JavaDoc value)
64     {
65         sb.append(' ');
66         sb.append(name);
67         sb.append("=");
68         final char quoteChar = value.indexOf('"') < 0 ? '"' : '\'';
69         sb.append(quoteChar);
70         sb.append(value);
71         sb.append(quoteChar);
72     }
73
74     public final int getLineNumber()
75     {
76         return lineNumber;
77     }
78
79     public final int getColumnNumber()
80     {
81         return columnNumber;
82     }
83 }
84
Popular Tags