Source Code Cross Referenced for JspExpand.java in  » J2EE » Sofia » com » salmonllc » jsp » 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 » J2EE » Sofia » com.salmonllc.jsp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.salmonllc.jsp;
002:
003:        import com.salmonllc.html.HtmlPage;
004:        import com.salmonllc.html.HtmlComponent;
005:
006:        /**
007:         * This tag creates an expand component    
008:         * @author Nicolás Genta 
009:         */
010:        public class JspExpand extends HtmlComponent {
011:
012:            private String _div;
013:            private String _imgexp;
014:            private String _imgcont;
015:            private String _altexp;
016:            private String _altcont;
017:            private boolean _keepstate;
018:
019:            public JspExpand(String name, String div, String imgexp,
020:                    String imgcont, HtmlPage p) {
021:                super (name, p);
022:                setTheme(null);
023:                _div = div;
024:                _imgexp = imgexp;
025:                _imgcont = imgcont;
026:                _altexp = null;
027:                _altcont = null;
028:                _keepstate = true;
029:            }
030:
031:            public void generateHTML(java.io.PrintWriter p, int rowNo)
032:                    throws Exception {
033:                if (!getVisible())
034:                    return;
035:
036:                String name = getFullName();
037:                if (rowNo != -1)
038:                    name += "_" + rowNo;
039:                String altExp = ((_altexp == null) ? "" : _altexp);
040:                String altCont = ((_altcont == null) ? "" : _altcont);
041:                String src = translateSiteMapURL(_imgcont);
042:                String alt = altCont;
043:                String onClick = "";
044:                String onLoad = "";
045:
046:                JspController controller = (JspController) getPage();
047:                HtmlComponent comp = controller.getComponent(_div);
048:                if (comp != null && comp instanceof  JspDiv) {
049:                    JspDiv div = (JspDiv) comp;
050:                    onLoad = "init('" + div.getFullName() + "','"
051:                            + getFullName() + "','"
052:                            + translateSiteMapURL(_imgexp) + "','"
053:                            + translateSiteMapURL(_imgcont) + "','" + altExp
054:                            + "','" + altCont + "'," + _keepstate + ");";
055:                    if (div.isHidden()) {
056:                        src = translateSiteMapURL(_imgexp);
057:                        alt = altExp;
058:                    }
059:                    onClick = "expand('" + div.getFullName() + "'," + rowNo
060:                            + ");";
061:                }
062:
063:                StringBuffer sbOut = new StringBuffer("<IMG NAME=\"" + name
064:                        + "\"" + " ID=\"" + name + "\"" + " SRC=\"" + src
065:                        + "\"" + " ALT=\"" + alt + "\"" + " ONCLICK=\""
066:                        + onClick + "\"/>");
067:                p.print(sbOut.toString());
068:                addScript(_keepstate);
069:
070:                String currentOnLoad = controller.getOnLoad();
071:                if (currentOnLoad != null) {
072:                    if (!JspExpand.isSubString(onLoad, currentOnLoad)) {
073:                        controller.setOnLoad(currentOnLoad + "\n" + onLoad);
074:                    }
075:                } else {
076:                    controller.setOnLoad(onLoad);
077:                }
078:            }
079:
080:            public String getDiv() {
081:                return _div;
082:            }
083:
084:            public void setDiv(String div) {
085:                this ._div = div;
086:            }
087:
088:            public String getImgexp() {
089:                return _imgexp;
090:            }
091:
092:            public void setImgexp(String imgexp) {
093:                this ._imgexp = imgexp;
094:            }
095:
096:            public String getImgcont() {
097:                return _imgcont;
098:            }
099:
100:            public void setImgcont(String imgcont) {
101:                this ._imgcont = imgcont;
102:            }
103:
104:            public String getAltexp() {
105:                return _altexp;
106:            }
107:
108:            public void setAltexp(String altexp) {
109:                this ._altexp = altexp;
110:            }
111:
112:            public String getAltcont() {
113:                return _altcont;
114:            }
115:
116:            public void setAltcont(String altcont) {
117:                this ._altcont = altcont;
118:            }
119:
120:            public boolean isKeepstate() {
121:                return _keepstate;
122:            }
123:
124:            public void setKeepstate(boolean keepstate) {
125:                this ._keepstate = keepstate;
126:            }
127:
128:            private void addScript(boolean keepState) {
129:                if (!getPage().isScriptAdded("ExpandScript")) {
130:                    StringBuffer jsExpand = new StringBuffer();
131:
132:                    jsExpand
133:                            .append("var tagsData = new Array();\n"
134:                                    + "var tagsState = new Array();\n"
135:                                    + "\n"
136:                                    + "function TagData(divId, imgId, srcExp, srcCont, altExp, altCont, keepState) {\n"
137:                                    + "\tthis.divId = divId;\n"
138:                                    + "\tthis.imgId = imgId;\n"
139:                                    + "\tthis.srcExp = srcExp;\n"
140:                                    + "\tthis.srcCont = srcCont;\n"
141:                                    + "\tthis.altExp = altExp;\n"
142:                                    + "\tthis.altCont = altCont;\n"
143:                                    + "\tthis.keepState = keepState;\n"
144:                                    + "}\n"
145:                                    + "\n"
146:                                    + "function TagState(divId, expanded, contracted) {\n"
147:                                    + "\tthis.divId = divId;\n"
148:                                    + "\tthis.expanded = expanded;\n"
149:                                    + "\tthis.contracted = contracted;\n"
150:                                    + "}\n\n");
151:                    jsExpand.append("function find(array, divId) {\n"
152:                            + "\tvar i = 0;\n" + "\tvar found = false;\n"
153:                            + "\twhile (i<array.length && !found) {\n"
154:                            + "\t\tif (array[i].divId == divId) {\n"
155:                            + "\t\t\tfound = true;\n" + "\t\t} else {\n"
156:                            + "\t\t\ti++;\n" + "\t\t}\n" + "\t}\n"
157:                            + "\tif (found) {\n" + "\t\treturn array[i];\n"
158:                            + "\t} else {\n" + "\t\treturn null;\n" + "\t}\n"
159:                            + "}\n\n");
160:                    jsExpand
161:                            .append("function init(divId, imgId, srcExp, srcCont, altExp, altCont, keepState) {\n"
162:                                    + "\tvar tagData = find(tagsData, divId);\n"
163:                                    + "\tif (tagData == null) {\n"
164:                                    + "\t\ttagData = new TagData(divId, imgId, srcExp, srcCont, altExp, altCont, keepState);\n"
165:                                    + "\t\ttagsData.push(tagData);\n"
166:                                    + "\t}\n"
167:                                    + "\tif (keepState) {\n"
168:                                    + "\t\tload(divId);\n" + "\t}\n" + "}\n\n");
169:                    jsExpand
170:                            .append("function expand(divId, row) {\n"
171:                                    + "\tvar tagData = find(tagsData, divId);\n"
172:                                    + "\tvar imgId = tagData.imgId;\n"
173:                                    + "\tvar srcExp = tagData.srcExp;\n"
174:                                    + "\tvar srcCont = tagData.srcCont;\n"
175:                                    + "\tvar altExp = tagData.altExp;\n"
176:                                    + "\tvar altCont = tagData.altCont;\n"
177:                                    + "\tvar keepState = tagData.keepState;\n"
178:                                    + "\tif (row == -1) {\n"
179:                                    + "\t\tvar img = document.getElementById(imgId);\n"
180:                                    + "\t\tvar div = document.getElementById(divId);\n"
181:                                    + "\t}\n"
182:                                    + "\telse {\n"
183:                                    + "\t\tvar img = document.getElementById(imgId + \"_\" + row);\n"
184:                                    + "\t\tvar div = document.getElementById(divId + \"_\" + row);\n"
185:                                    + "\t}\n"
186:                                    + "\tif (keepState) {\n"
187:                                    + "\t\tchangeState(divId, row, div);\n"
188:                                    + "\t}\n"
189:                                    + "\tif (div.style.display == \"none\") {\n"
190:                                    + "\t\tshow(img, div, srcCont, altCont);\n"
191:                                    + "\t} else {\n"
192:                                    + "\t\thide(img, div, srcExp, altExp);\n"
193:                                    + "\t}\n" + "}\n\n");
194:                    jsExpand.append("function show(img, div, src, alt) {\n"
195:                            + "\tdiv.style.display = \"block\";\n"
196:                            + "\timg.src = src;\n" + "\timg.alt = alt;\n"
197:                            + "}\n" + "\n"
198:                            + "function hide(img, div, src, alt) {\n"
199:                            + "\tdiv.style.display = \"none\";\n"
200:                            + "\timg.src = src;\n" + "\timg.alt = alt;\n"
201:                            + "}\n\n");
202:
203:                    getPage().addScript("ExpandScript", jsExpand.toString());
204:                }
205:
206:                if (keepState && !getPage().isScriptAdded("KeepStateScript")) {
207:                    StringBuffer jsKeepState = new StringBuffer();
208:
209:                    jsKeepState.append("function remove(array, row) {\n"
210:                            + "\tvar i = 0;\n" + "\tvar found = false;\n"
211:                            + "\twhile (i<array.length && !found) {\n"
212:                            + "\t\tif (row == array[i]) {\n"
213:                            + "\t\t\tfound = true;\n" + "\t\t} else {\n"
214:                            + "\t\t\ti++;\n" + "\t\t}\n" + "\t}\n"
215:                            + "\tif (found) {\n" + "\t\tarray.splice(i,1);\n"
216:                            + "\t}\n" + "}\n\n");
217:                    jsKeepState
218:                            .append("function changeState(divId, row, div) {\n"
219:                                    + "\tvar tagState = find(tagsState, divId);\n"
220:                                    + "\tif (tagState == null) {\n"
221:                                    + "\t\texpanded = new Array();\n"
222:                                    + "\t\tcontracted = new Array();\n"
223:                                    + "\t\ttagState = new TagState(divId, expanded, contracted);\n"
224:                                    + "\t\ttagsState.push(tagState);\n"
225:                                    + "\t} else {\n"
226:                                    + "\t\texpanded = tagState.expanded;\n"
227:                                    + "\t\tcontracted = tagState.contracted;\n"
228:                                    + "\t}\n"
229:                                    + "\tif (div.style.display == \"none\") {\n"
230:                                    + "\t\texpanded.push(row);\n"
231:                                    + "\t\tremove(contracted, row);\n"
232:                                    + "\t} else {\n"
233:                                    + "\t\tcontracted.push(row);\n"
234:                                    + "\t\tremove(expanded, row);\n" + "\t}\n"
235:                                    + "\tsave();\n" + "}\n\n");
236:                    jsKeepState
237:                            .append("function save() {\n"
238:                                    + "\tsetCookie(\"ExpandTag\", array2String(tagsState));\n"
239:                                    + "}\n"
240:                                    + "\n"
241:                                    + "function load(divId) {\n"
242:                                    + "\tvar cookie = getCookie(\"ExpandTag\");\n"
243:                                    + "\tif (cookie != null) {\n"
244:                                    + "\t\ttagsState = string2Array(cookie);\n"
245:                                    + "\t\tvar tagState = find(tagsState, divId);\n"
246:                                    + "\t\tif (tagState != null) {\n"
247:                                    + "\t\t\tvar expanded = tagState.expanded;\n"
248:                                    + "\t\t\tvar contracted = tagState.contracted;\n"
249:                                    + "\t\t\tvar tagData = find(tagsData, divId);\n"
250:                                    + "\t\t\tvar imgId = tagData.imgId;\n"
251:                                    + "\t\t\tvar divId = tagData.divId;\n"
252:                                    + "\t\t\tvar srcExp = tagData.srcExp;\n"
253:                                    + "\t\t\tvar srcCont = tagData.srcCont;\n"
254:                                    + "\t\t\tvar altExp = tagData.altExp;\n"
255:                                    + "\t\t\tvar altCont = tagData.altCont;\n"
256:                                    + "\t\t\tfor (var i=0; i<expanded.length; i++) {\n"
257:                                    + "\t\t\t\tvar row = expanded[i];\n"
258:                                    + "\t\t\t\tif (row == -1) {\n"
259:                                    + "\t\t\t\t\tvar img = document.getElementById(imgId);\n"
260:                                    + "\t\t\t\t\tvar div = document.getElementById(divId);\n"
261:                                    + "\t\t\t\t}\n"
262:                                    + "\t\t\t\telse {\n"
263:                                    + "\t\t\t\t\tvar img = document.getElementById(imgId + \"_\" + row);\n"
264:                                    + "\t\t\t\t\tvar div = document.getElementById(divId + \"_\" + row);\n"
265:                                    + "\t\t\t\t}\n"
266:                                    + "\t\t\t\tif (div != null) {\n"
267:                                    + "\t\t\t\t\tshow(img, div, srcCont, altCont);\n"
268:                                    + "\t\t\t\t}\n"
269:                                    + "\t\t\t}\n"
270:                                    + "\t\t\tfor (var j=0; j<contracted.length; j++) {\n"
271:                                    + "\t\t\t\tvar row = contracted[j];\n"
272:                                    + "\t\t\t\tif (row == -1) {\n"
273:                                    + "\t\t\t\t\tvar img = document.getElementById(imgId);\n"
274:                                    + "\t\t\t\t\tvar div = document.getElementById(divId);\n"
275:                                    + "\t\t\t\t}\n"
276:                                    + "\t\t\t\telse {\n"
277:                                    + "\t\t\t\t\tvar img = document.getElementById(imgId + \"_\" + row);\n"
278:                                    + "\t\t\t\t\tvar div = document.getElementById(divId + \"_\" + row);\n"
279:                                    + "\t\t\t\t}\n"
280:                                    + "\t\t\t\tif (div != null) {\n"
281:                                    + "\t\t\t\t\thide(img, div, srcExp, altExp);\n"
282:                                    + "\t\t\t\t}\n" + "\t\t\t}\n" + "\t\t}\n"
283:                                    + "\t}\n" + "}\n\n");
284:                    jsKeepState
285:                            .append("function getCookieVal(offset) {\n"
286:                                    + "\tvar endstr = document.cookie.indexOf (\";\", offset);\n"
287:                                    + "\tif (endstr == -1) {\n"
288:                                    + "\t\tendstr = document.cookie.length;\n"
289:                                    + "\t}\n"
290:                                    + "\treturn unescape(document.cookie.substring(offset, endstr));\n"
291:                                    + "}\n"
292:                                    + "\n"
293:                                    + "function getCookie(name) {\n"
294:                                    + "\tvar arg = name + \"=\";\n"
295:                                    + "\tvar alen = arg.length;\n"
296:                                    + "\tvar clen = document.cookie.length;\n"
297:                                    + "\tvar i = 0;\n"
298:                                    + "\twhile (i < clen) {\n"
299:                                    + "\t\tvar j = i + alen;\n"
300:                                    + "\t\tif (document.cookie.substring(i, j) == arg) {\n"
301:                                    + "\t\t\treturn getCookieVal(j);\n"
302:                                    + "\t\t}\n"
303:                                    + "\t\ti = document.cookie.indexOf(\" \", i) + 1;\n"
304:                                    + "\t\tif (i == 0) break; \n"
305:                                    + "\t}\n"
306:                                    + "\treturn null;\n"
307:                                    + "}\n"
308:                                    + "\n"
309:                                    + "function setCookie(name, value, expires, path, domain, secure) {\n"
310:                                    + "\tdocument.cookie = name + \"=\" + escape (value) +\n"
311:                                    + "\t\t((expires) ? \"; expires=\" + expires : \"\") +\n"
312:                                    + "\t\t((path) ? \"; path=\" + path : \"\") +\n"
313:                                    + "\t\t((domain) ? \"; domain=\" + domain : \"\") +\n"
314:                                    + "\t\t((secure) ? \"; secure\" : \"\");\n"
315:                                    + "}\n\n");
316:                    jsKeepState
317:                            .append("function object2String(obj) {\n"
318:                                    + "\tvar val, output = \"\";\n"
319:                                    + "\tif (obj.length ==0) {\n"
320:                                    + "\t\treturn \"[]\";\n"
321:                                    + "\t}\n"
322:                                    + "\tif (obj) {    \n"
323:                                    + "\t\toutput += \"{\";\n"
324:                                    + "\t\tfor (var i in obj) {\n"
325:                                    + "\t\t\tval = obj[i];\n"
326:                                    + "\t\t\tswitch (typeof val) {\n"
327:                                    + "\t\t\t\tcase (\"object\"):\n"
328:                                    + "\t\t\t\t\tif (val[0]!=null) {\n"
329:                                    + "\t\t\t\t\t\toutput += i + \":\" + array2String(val) + \",\";\n"
330:                                    + "\t\t\t\t\t} else {\n"
331:                                    + "\t\t\t\t\t\toutput += i + \":\" + object2String(val) + \",\";\n"
332:                                    + "\t\t\t\t\t}\n"
333:                                    + "\t\t\t\t\tbreak;\n"
334:                                    + "\t\t\t\tcase (\"string\"):\n"
335:                                    + "\t\t\t\t\toutput += i + \":'\" + escape(val) + \"',\";\n"
336:                                    + "\t\t\t\t\tbreak;\n"
337:                                    + "\t\t\t\tdefault:\n"
338:                                    + "\t\t\t\t\toutput += i + \":\" + val + \",\";\n"
339:                                    + "\t\t\t}\n"
340:                                    + "\t\t}\n"
341:                                    + "\t\toutput = output.substring(0, output.length-1) + \"}\";\n"
342:                                    + "\t}\n" + "\treturn output;\n" + "}\n"
343:                                    + "\n"
344:                                    + "function string2Object(string) {\n"
345:                                    + "\teval(\"var result = \" + string);\n"
346:                                    + "\treturn result;\n" + "}\n\n");
347:                    jsKeepState
348:                            .append("function array2String(array) {\n"
349:                                    + "\tvar output = \"\";\n"
350:                                    + "\tif (array.length ==0) {\n"
351:                                    + "\t\treturn \"[]\";\n"
352:                                    + "\t}\n"
353:                                    + "\tif (array) {\n"
354:                                    + "\t\toutput += \"[\";\n"
355:                                    + "\t\tfor (var i in array) {\n"
356:                                    + "\t\tval = array[i];\n"
357:                                    + "\t\t\tswitch (typeof val) {\n"
358:                                    + "\t\t\t\tcase (\"object\"):\n"
359:                                    + "\t\t\t\t\tif (val[0]!=null) {\n"
360:                                    + "\t\t\t\t\t\toutput += array2String(val) + \",\";\n"
361:                                    + "\t\t\t\t\t} else {\n"
362:                                    + "\t\t\t\t\t\toutput += object2String(val) + \",\";\n"
363:                                    + "\t\t\t\t\t}\n"
364:                                    + "\t\t\t\t\tbreak;\n"
365:                                    + "\t\t\t\tcase (\"string\"):\n"
366:                                    + "\t\t\t\t\toutput += \"'\" + escape(val) + \"',\";\n"
367:                                    + "\t\t\t\t\tbreak;\n"
368:                                    + "\t\t\t\tdefault:\n"
369:                                    + "\t\t\t\t\toutput += val + \",\";\n"
370:                                    + "\t\t\t}\n"
371:                                    + "\t\t}\n"
372:                                    + "\t\toutput = output.substring(0, output.length-1) + \"]\";\n"
373:                                    + "\t}\n" + "\treturn output;\n" + "}\n"
374:                                    + "\n"
375:                                    + "function string2Array(string) {\n"
376:                                    + "\teval(\"var result = \" + string);\n"
377:                                    + "\treturn result;\n" + "}\n\n");
378:
379:                    getPage().addScript("KeepStateScript",
380:                            jsKeepState.toString());
381:                }
382:            }
383:
384:            public static boolean isSubString(String sub, String str) {
385:                for (int j = 0; j < str.length(); j++) {
386:                    if (str.regionMatches(j, sub, 0, sub.length())) {
387:                        return true;
388:                    }
389:                }
390:                return false;
391:            }
392:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.