01: package com.jat.presentation.menu;
02:
03: import java.io.IOException;
04: import java.io.Writer;
05: import javax.servlet.http.HttpServletRequest;
06:
07: /**
08: * <p>Title: JAT</p>
09: * <p>Description: </p>
10: * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
11: * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
12: * @author maurizio cesari
13: * @version 1.0
14: * @since 1.2
15: */
16:
17: public class HtmlTreeGenerator {
18:
19: private String tdTerminator, tableStart, tableStop, tdSeparator;
20: private String imgSrcTrasparent;
21: private char apiceOld = '\'';
22: private char apiceNew = '\"';
23: private HttpServletRequest request;
24: private Writer out;
25: private TreeNode root;
26: private HtmlNodeGenerator htmlNodeGenerator;
27:
28: public HtmlTreeGenerator(TreeNode nodoRoot, Writer out) {
29: this .out = out;
30: this .root = nodoRoot;
31: this .request = nodoRoot.getRequest();
32: this .imgSrcTrasparent = getImgSrc("static_image",
33: "static_image_trasparente");
34: this .tableStart = getTableStart();
35: this .tableStop = "</TABLE>";
36: this .tdTerminator = getTdTreeSeparator(imgSrcTrasparent);
37: this .htmlNodeGenerator = new HtmlNodeGenerator(root, out);
38: this .tdSeparator = getTdTreeSeparator(imgSrcTrasparent);
39: }
40:
41: public void printTree() throws IOException {
42: printStart();
43: out.write("<tr>" + tdSeparator);
44: htmlNodeGenerator.printChilds();
45: printStop();
46: }
47:
48: public void printStart() throws IOException {
49: out.write(tableStart);
50: }
51:
52: public void printStop() throws IOException {
53: //out.write(tdTerminator);
54: out.write(tableStop);
55: }
56:
57: public String getTableStart() {
58: return convert("<table border='0' cellspacing='0' cellpadding='0' width='100%'>");
59: }
60:
61: public String getTdTreeSeparator(String imgSrc) {
62: return convert("<td colspan='" + root.getColSpanSeparator()
63: + "' bgcolor='White'><img src='" + imgSrc
64: + "' border='0' width='100%' height='1'></td>");
65: }
66:
67: private String getImgSrc(String imgSectorId, String imgKey) {
68: String ris = null;
69: try {
70: ris = request.getContextPath()
71: + com.jat.core.config.Config.getCurrent().getValue(
72: imgSectorId, imgKey);
73: } catch (Exception ex) {
74: }
75: return ris;
76: }
77:
78: public String convert(String input) {
79: return input.replace(apiceOld, apiceNew);
80: }
81:
82: }
|