update dev300-m58
[ooovba.git] / xmlsecurity / tools / uno / AdapterNode.java
blobe98ed2afd0d05d1dba097e50f85fb01dcc9569f3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AdapterNode.java,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com.sun.star.xml.security.uno;
33 import org.w3c.dom.Node;
34 import org.w3c.dom.Attr;
35 import org.w3c.dom.NamedNodeMap;
39 * This class wraps a DOM node and returns the text we want to
40 * display in the tree. It also returns children, index values,
41 * and child counts.
43 class AdapterNode
45 private Node m_domNode;
46 static final int ELEMENT_TYPE = Node.ELEMENT_NODE;
49 * An array of names for DOM node-types
51 static final String[] typeName = {
52 "none",
53 "Element",
54 "Attr",
55 "Text",
56 "CDATA",
57 "EntityRef",
58 "Entity",
59 "ProcInstr",
60 "Comment",
61 "Document",
62 "DocType",
63 "DocFragment",
64 "Notation",
67 protected Node getNode()
69 return m_domNode;
73 * Construct an Adapter node from a DOM node
75 protected AdapterNode(org.w3c.dom.Node node)
77 m_domNode = node;
81 * Return children, index, and count values
83 protected int index(AdapterNode child)
85 int count = childCount();
86 for (int i=0; i<count; ++i)
88 AdapterNode n = this.child(i);
89 if (child.m_domNode == n.m_domNode) return i;
91 return -1;
94 protected AdapterNode child(int searchIndex)
96 if (m_domNode == null) return null;
99 * Note: JTree index is zero-based.
101 org.w3c.dom.Node node =
102 m_domNode.getChildNodes().item(searchIndex);
104 return new AdapterNode(node);
107 protected int childCount()
109 int rc = 0;
111 if (m_domNode != null)
113 rc = m_domNode.getChildNodes().getLength();
116 return rc;
120 * Return a string that identifies this node in the tree
122 public String toString()
124 String rc = null;
126 if (m_domNode != null)
128 String s = typeName[m_domNode.getNodeType()];
129 String nodeName = m_domNode.getNodeName();
131 if (! nodeName.startsWith("#"))
133 s += ": " + nodeName;
136 if (m_domNode.getNodeValue() != null)
138 if (s.startsWith("ProcInstr"))
140 s += ", ";
142 else
144 s += ": ";
147 String t = m_domNode.getNodeValue();
148 s += t;
151 if (m_domNode.getNodeType() == ELEMENT_TYPE)
153 NamedNodeMap attrs = m_domNode.getAttributes();
155 int length = attrs.getLength();
156 for (int i=0; i<length; ++i)
158 Attr attr = (Attr)(attrs.item(i));
159 s += " "+ attr.getName()+"='"+attr.getValue() + "'";
162 rc = s;
165 return rc;