01: /*
02: * Enhydra Java Application Server Project
03: *
04: * The contents of this file are subject to the Enhydra Public License
05: * Version 1.1 (the "License"); you may not use this file except in
06: * compliance with the License. You may obtain a copy of the License on
07: * the Enhydra web site ( http://www.enhydra.org/ ).
08: *
09: * Software distributed under the License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11: * the License for the specific terms governing rights and limitations
12: * under the License.
13: *
14: * The Initial Developer of the Enhydra Application Server is Lutris
15: * Technologies, Inc. The Enhydra Application Server and portions created
16: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17: * All Rights Reserved.
18: *
19: * Contributor(s):
20: *
21: */
22:
23: package org.enhydra.kelp.common.bridge;
24:
25: // XMLC imports - 1.x and 2.x
26: import org.enhydra.xml.xmlc.dom.XMLCDocument;
27: import org.w3c.dom.*;
28:
29: // Kelp imports
30: import org.enhydra.kelp.common.Constants;
31:
32: // Standard imports
33: import java.io.*;
34: import java.util.ResourceBundle;
35: import java.util.Vector;
36:
37: abstract public class PrintInfo {
38: // string not to be resourced
39: private final String ARROW = " => "; // nores
40: private static ResourceBundle res = ResourceBundle
41: .getBundle("org.enhydra.kelp.common.Res"); // nores
42:
43: /**
44: * Table URLs.
45: */
46: protected Vector urls = new Vector();
47:
48: /**
49: * Table of element ids.
50: */
51: protected Vector ids = new Vector();
52:
53: /**
54: * Construct document info from document.
55: */
56: public PrintInfo(Document doc, XMLCDocument xmlcDoc) {
57: getNodeInfo(doc, xmlcDoc);
58: }
59:
60: /**
61: * Print document information.
62: */
63: public void printInfo(PrintWriter out) {
64: out.println(res.getString("Element_IDs"));
65: for (int i = 0; i < ids.size(); i++) {
66: out.println(Constants.TAB4 + ids.elementAt(i).toString());
67: }
68: out.println(res.getString("Document_URLs"));
69: for (int i = 0; i < urls.size(); i++) {
70: out.println(Constants.TAB4 + urls.elementAt(i).toString());
71: }
72: }
73:
74: abstract protected void getElementURLs(Element element,
75: XMLCDocument xmlcDoc);
76:
77: /**
78: * Recursively scan nodes nodes and accumulate information.
79: */
80: private void getNodeInfo(Node node, XMLCDocument xmlcDoc) {
81: if (node instanceof Element) {
82: Element elem = (Element) node;
83: getElementURLs(elem, xmlcDoc);
84: String id = xmlcDoc.getElementId(elem);
85: if ((id != null) && (id.length() > 0)) {
86: ids.addElement(id + ARROW
87: + xmlcDoc.nodeClassToInterface(node));
88: }
89: }
90:
91: for (Node child = node.getFirstChild(); child != null; child = child
92: .getNextSibling()) {
93: getNodeInfo(child, xmlcDoc);
94: }
95: }
96:
97: }
|