Source Code Cross Referenced for HtmlNodeGenerator.java in  » Web-Framework » JAT » com » jat » presentation » menu » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » JAT » com.jat.presentation.menu 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jat.presentation.menu;
002:
003:        import java.io.IOException;
004:        import java.io.Writer;
005:        import java.util.Enumeration;
006:        import java.util.Vector;
007:        import javax.servlet.http.HttpServletRequest;
008:
009:        /**
010:         * <p>Title: JAT</p>
011:         * <p>Description: </p>
012:         * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
013:         * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
014:         * @author maurizio cesari
015:         * @version 1.1
016:         * @since 1.2
017:         */
018:
019:        class HtmlNodeGenerator {
020:
021:            private String separator, trElement, tdIcon, tdLabel, tableStart,
022:                    tableStop;
023:            private Vector tdsStatic;
024:            private String imgSrcTrasparent;
025:            private char apiceOld = '\'';
026:            private char apiceNew = '\"';
027:            private static HttpServletRequest request;
028:            private Writer out;
029:            private TreeNode nodo;
030:
031:            public HtmlNodeGenerator(TreeNode nodo, Writer out) {
032:                this .out = out;
033:                this .nodo = nodo;
034:                this .request = nodo.getRequest();
035:                this .imgSrcTrasparent = getImgSrc("static_image",
036:                        "static_image_trasparente");
037:                this .tableStart = getTableStart();
038:                this .tableStop = "</TABLE>";
039:                this .separator = getSeparator(imgSrcTrasparent);
040:                this .tdLabel = getTdLabel();
041:                this .tdIcon = getTdIcon();
042:                this .tdsStatic = getTdsStatic(imgSrcTrasparent);
043:                this .trElement = getTrElement();
044:            }
045:
046:            public void printNode() throws IOException {
047:                //out.write("<tr>" + tdSeparator);
048:                out.write(trElement);
049:                out.write(this .getSingleTdStatic(imgSrcTrasparent));
050:                for (int i = 0; i < tdsStatic.size(); i++) {
051:                    out.write((String) tdsStatic.get(i));
052:                }
053:                out.write(tdIcon);
054:                out.write(this .getSingleTdStatic(imgSrcTrasparent));
055:                out.write(tdLabel);
056:                out.write("</TR>");
057:                out.write(separator);
058:            }
059:
060:            public void printChilds() throws IOException {
061:                HtmlNodeGenerator htmlChild;
062:                if (nodo.isWritable()) {
063:                    if (!nodo.isRoot())
064:                        printNode();
065:                    Enumeration ch = nodo.children();
066:                    while (ch.hasMoreElements()) {
067:                        TreeNode child = (TreeNode) ch.nextElement();
068:                        htmlChild = new HtmlNodeGenerator(child, out);
069:                        htmlChild.printChilds();
070:                    }
071:                }
072:            }
073:
074:            public String getTableStart() {
075:                return convert("<table border='0' cellspacing='0' cellpadding='0' width='100%'>");
076:            }
077:
078:            public String getTrElement() {
079:                String app = nodo.getSection();
080:                int pos = app.indexOf('_');
081:                return convert("<tr class='MenuLiv" + nodo.getLevel()
082:                        + app.substring(pos + 1)
083:                        + "' align='left' valign='middle'>");
084:            }
085:
086:            /** L'icona associata all'item dipende dallo stato (selezionato o meno.
087:             *
088:             * Se 'item � stato selezionato, viene caricata l'icona espressa sul file
089:             * di configurazione, altrimenti si carica un'altra icona:
090:             *
091:             * Se nome icona=nomexxxyyy.ext, allora il noem dell'icona ssociata all'item
092:             * nello stato selezionato sar�:
093:             * nomexxxyyy_sel.ext
094:             *
095:             * )*/
096:
097:            public String getTdIcon() {
098:                return convert("<td><img src='"
099:                        + (isSelected() ? this .request.getContextPath()
100:                                + nodo.getSelectedIcon() : this .request
101:                                .getContextPath()
102:                                + nodo.getIcon()) + "' alt='' border='0'></td>");
103:            }
104:
105:            /** Il link associato all'item dipende dallo stato (selezionato o meno).
106:             *
107:             * Se l'item � stato selezionato, il link non � attivo e la classe associata
108:             * alla label � 'testo'.
109:             *
110:             */
111:
112:            public String getTdLabel() {
113:                String normal = "<FONT CLASS='testo'><a target='"
114:                        + nodo.getTarget() + "' href='"
115:                        + this .request.getContextPath() + nodo.getUrl() + "'>"
116:                        + nodo.getLabel() + "</a></FONT>";
117:
118:                String selected = "<FONT CLASS='testoB'>" + nodo.getLabel()
119:                        + "</FONT>";
120:
121:                return convert("<td colspan='" + nodo.getColSpanLabel()
122:                        + "' width='100%'>"
123:                        + (isSelected() ? selected : normal) + "</td>");
124:
125:            }
126:
127:            public String getSeparator(String imgSrc) {
128:                return convert("<tr><td colspan='" + nodo.getColSpanSeparator()
129:                        + "' class='" + "MenuSeparatoreColorRight"
130:                        + "' ><img src='" + this .request.getContextPath()
131:                        + imgSrc
132:                        + "' border='0' width='100%' height='1'></td></tr>" +
133:
134:                        "<tr><td colspan='" + nodo.getColSpanSeparator()
135:                        + "' bgcolor='" + "white" + "' ><img src='"
136:                        + this .request.getContextPath() + imgSrc
137:                        + "' border='0' width='100%' height='1'></td></tr>");
138:            }
139:
140:            public Vector getTdsStatic(String imgSrc) {
141:                Vector ris = new Vector();
142:                int repeat = nodo.getLevel();
143:                for (int i = 0; i < repeat; i++) {
144:                    ris.add(getSingleTdStatic(imgSrc));
145:                }
146:                return ris;
147:            }
148:
149:            public String getSingleTdStatic(String imgSrc) {
150:
151:                return convert("<td><img src='" + this .request.getContextPath()
152:                        + imgSrc + "' border='0' width='"
153:                        + getVoiceVar(nodo.getSection(), "voce.tab")
154:                        + "' height='"
155:                        + getVoiceVar(nodo.getSection(), "voce.height")
156:                        + "'></td>");
157:            }
158:
159:            private String getImgSrc(String imgSectorId, String imgKey) {
160:                String ris = null;
161:                try {
162:                    ris = request.getContextPath()
163:                            + com.jat.core.config.Config.getCurrent().getValue(
164:                                    imgSectorId, imgKey);
165:                } catch (Exception ex) {
166:                }
167:                return ris;
168:            }
169:
170:            private String getVoiceVar(String menuId, String voiceKey) {
171:                String ris = null;
172:                try {
173:                    ris = com.jat.core.config.Config.getCurrent().getValue(
174:                            menuId, voiceKey);
175:                    //("menu_left","voce.height"|"voce.tab")
176:                } catch (Exception ex) {
177:                }
178:                return ris;
179:            }
180:
181:            public String convert(String input) {
182:                return input.replace(apiceOld, apiceNew);
183:            }
184:
185:            /** Il nodo � "selezionato" se il valore del parametro "menu_item"
186:             * corrisponde alla label.
187:             * */
188:
189:            private boolean isSelected() {
190:                String selectedItem = (String) this .request
191:                        .getParameter("menu_item");
192:                if (selectedItem == null)
193:                    return false;
194:                return nodo.getLabel().equals(selectedItem);
195:            }
196:
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.