1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AdapterNode.java,v $
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,
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
= {
67 protected Node
getNode()
73 * Construct an Adapter node from a DOM node
75 protected AdapterNode(org
.w3c
.dom
.Node 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
;
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()
111 if (m_domNode
!= null)
113 rc
= m_domNode
.getChildNodes().getLength();
120 * Return a string that identifies this node in the tree
122 public String
toString()
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"))
147 String t
= m_domNode
.getNodeValue();
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() + "'";