01: package it.geosolutions.imageio.plugins.jhdf;
02:
03: import javax.imageio.metadata.IIOMetadataNode;
04:
05: import org.w3c.dom.NamedNodeMap;
06: import org.w3c.dom.Node;
07:
08: /**
09: * Simple abstract class used to build a String representing the structure
10: * of a <code>IIOMetadataNode</coded> tree.
11: *
12: * @author Daniele Romagnoli
13: *
14: */
15: public abstract class MetadataDisplay {
16:
17: private static int depth = 0;
18:
19: public static String buildMetadataFromNode(IIOMetadataNode node) {
20: String localMetadata = "";
21: final String name = node.getNodeName();
22: final StringBuffer sb = new StringBuffer("<").append(name);
23: NamedNodeMap attributes = node.getAttributes();
24: if (attributes != null) {
25: final int nAttributes = attributes.getLength();
26: if (nAttributes > 0) {
27: sb.append(" ");
28: int i = 0;
29: for (; i < nAttributes; i++) {
30: Node attribNode = attributes.item(i);
31: final String attribName = attribNode.getNodeName();
32: final String attribValue = attribNode
33: .getNodeValue();
34: sb.append("\"").append(attribName).append("\"=\"")
35: .append(attribValue).append("\"");
36: if (i != nAttributes - 1)
37: sb.append(" ");
38: }
39: }
40: }
41: sb.append(">");
42: localMetadata = sb.toString();
43: if (node.hasChildNodes()) {
44: depth++;
45: localMetadata = localMetadata
46: + "\n"
47: + setTab(depth)
48: + buildMetadataFromNode((IIOMetadataNode) node
49: .getFirstChild());
50: }
51: IIOMetadataNode sibling = (IIOMetadataNode) node
52: .getNextSibling();
53: if (sibling != null) {
54: localMetadata = localMetadata + "\n" + setTab(depth)
55: + buildMetadataFromNode(sibling);
56: } else
57: depth--;
58:
59: return localMetadata;
60: }
61:
62: private static String setTab(int depth) {
63: final StringBuffer sb = new StringBuffer();
64: for (int i = 0; i < depth; i++)
65: sb.append("\t");
66: return sb.toString();
67: }
68: }
|