Source code: org/enhydra/kelp/common/bridge/PrintInfo.java
1 /*
2 * Enhydra Java Application Server Project
3 *
4 * The contents of this file are subject to the Enhydra Public License
5 * Version 1.1 (the "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy of the License on
7 * the Enhydra web site ( http://www.enhydra.org/ ).
8 *
9 * 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.getBundle("org.enhydra.kelp.common.Res"); // nores
41
42 /**
43 * Table URLs.
44 */
45 protected Vector urls = new Vector();
46
47 /**
48 * Table of element ids.
49 */
50 protected Vector ids = new Vector();
51
52 /**
53 * Construct document info from document.
54 */
55 public PrintInfo(Document doc, XMLCDocument xmlcDoc) {
56 getNodeInfo(doc, xmlcDoc);
57 }
58
59 /**
60 * Print document information.
61 */
62 public void printInfo(PrintWriter out) {
63 out.println(res.getString("Element_IDs"));
64 for (int i = 0; i < ids.size(); i++) {
65 out.println(Constants.TAB4 + ids.elementAt(i).toString());
66 }
67 out.println(res.getString("Document_URLs"));
68 for (int i = 0; i < urls.size(); i++) {
69 out.println(Constants.TAB4 + urls.elementAt(i).toString());
70 }
71 }
72
73 abstract protected void getElementURLs(Element element, XMLCDocument xmlcDoc);
74
75
76 /**
77 * Recursively scan nodes nodes and accumulate information.
78 */
79 private void getNodeInfo(Node node, XMLCDocument xmlcDoc) {
80 if (node instanceof Element) {
81 Element elem = (Element)node;
82 getElementURLs(elem, xmlcDoc);
83 String id = xmlcDoc.getElementId(elem);
84 if ((id != null) && (id.length() > 0)) {
85 ids.addElement(id + ARROW
86 + xmlcDoc.nodeClassToInterface(node));
87 }
88 }
89
90 for (Node child = node.getFirstChild(); child != null;
91 child = child.getNextSibling()) {
92 getNodeInfo(child, xmlcDoc);
93 }
94 }
95
96 }