1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package com
.sun
.star
.xml
.security
.uno
;
30 import org
.w3c
.dom
.Node
;
31 import org
.w3c
.dom
.Attr
;
32 import org
.w3c
.dom
.NamedNodeMap
;
36 * This class wraps a DOM node and returns the text we want to
37 * display in the tree. It also returns children, index values,
42 private Node m_domNode
;
43 static final int ELEMENT_TYPE
= Node
.ELEMENT_NODE
;
46 * An array of names for DOM node-types
48 static final String
[] typeName
= {
64 protected Node
getNode()
70 * Construct an Adapter node from a DOM node
72 protected AdapterNode(org
.w3c
.dom
.Node node
)
78 * Return children, index, and count values
80 protected int index(AdapterNode child
)
82 int count
= childCount();
83 for (int i
=0; i
<count
; ++i
)
85 AdapterNode n
= this.child(i
);
86 if (child
.m_domNode
== n
.m_domNode
) return i
;
91 protected AdapterNode
child(int searchIndex
)
93 if (m_domNode
== null) return null;
96 * Note: JTree index is zero-based.
98 org
.w3c
.dom
.Node node
=
99 m_domNode
.getChildNodes().item(searchIndex
);
101 return new AdapterNode(node
);
104 protected int childCount()
108 if (m_domNode
!= null)
110 rc
= m_domNode
.getChildNodes().getLength();
117 * Return a string that identifies this node in the tree
119 public String
toString()
123 if (m_domNode
!= null)
125 String s
= typeName
[m_domNode
.getNodeType()];
126 String nodeName
= m_domNode
.getNodeName();
128 if (! nodeName
.startsWith("#"))
130 s
+= ": " + nodeName
;
133 if (m_domNode
.getNodeValue() != null)
135 if (s
.startsWith("ProcInstr"))
144 String t
= m_domNode
.getNodeValue();
148 if (m_domNode
.getNodeType() == ELEMENT_TYPE
)
150 NamedNodeMap attrs
= m_domNode
.getAttributes();
152 int length
= attrs
.getLength();
153 for (int i
=0; i
<length
; ++i
)
155 Attr attr
= (Attr
)(attrs
.item(i
));
156 s
+= " "+ attr
.getName()+"='"+attr
.getValue() + "'";