Source Code Cross Referenced for HippoFormHelper.java in  » Content-Management-System » hippo-cms » nl » hippo » cocoon » forms » 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 » Content Management System » hippo cms » nl.hippo.cocoon.forms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 Hippo
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the  "License"); 
005:         * you may not use this file except in compliance with the License. 
006:         * You may obtain a copy of the License at
007:         *
008:         * http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" 
012:         * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
013:         * See the License for the specific language governing permissions and 
014:         * limitations under the License.
015:         */
016:        package nl.hippo.cocoon.forms;
017:
018:        import java.util.ArrayList;
019:        import java.util.Iterator;
020:        import java.util.List;
021:
022:        import org.apache.cocoon.forms.formmodel.AbstractContainerWidget;
023:        import org.apache.cocoon.forms.formmodel.Action;
024:        import org.apache.cocoon.forms.formmodel.ActionDefinition;
025:        import org.apache.cocoon.forms.formmodel.Form;
026:        import org.apache.cocoon.forms.formmodel.Repeater;
027:        import org.apache.cocoon.forms.formmodel.RepeaterAction;
028:        import org.apache.cocoon.forms.formmodel.RowAction;
029:        import org.apache.cocoon.forms.formmodel.Widget;
030:        import org.apache.cocoon.forms.formmodel.WidgetState;
031:        import org.apache.cocoon.forms.formmodel.Repeater.RepeaterRow;
032:        import org.apache.commons.lang.StringUtils;
033:
034:        /**
035:         * @author <a href="mailto:d.dam@hippo.nl">Dennis Dam</a>
036:         *
037:         * @version $Id: HippoFormHelper.java 8544 2007-10-16 09:48:55Z ddam $
038:         */
039:        public class HippoFormHelper {
040:
041:            public static String ACTION_ADD_AFTER = "add-after";
042:            public static String ACTION_DELETE = "delete";
043:            public static String ACTION_MOVE_UP = "move-up";
044:            public static String ACTION_MOVE_DOWN = "move-down";
045:
046:            public static String REPEATER_ACTION_ADD = "add-row";
047:            public static String REPEATER_ACTION_DELETE_ROWS = "delete-rows";
048:
049:            /**
050:             *  Tries to retrieve a repeater which is related to a widget. 
051:             * @param widget a widget
052:             * @return the related repeater element
053:             */
054:            public static Repeater getRelatedRepeater(Widget widget) {
055:                if (widget == null) {
056:                    return null;
057:                }
058:                if (widget instanceof  Repeater) {
059:                    return (Repeater) widget;
060:                } else if (widget instanceof  RepeaterAction) {
061:                    return ((RepeaterAction) widget).getRepeater();
062:                }
063:                return getRelatedRepeater(widget.getParent());
064:            }
065:
066:            private static String getActionCommand(Widget w) {
067:                if (w instanceof  Action) {
068:                    return ((ActionDefinition) w.getDefinition())
069:                            .getActionCommand();
070:                }
071:                return null;
072:
073:            }
074:
075:            public static boolean isAction(Widget w, String cmd) {
076:                String actionCmd = getActionCommand(w);
077:                return (actionCmd != null && actionCmd.equals(cmd));
078:            }
079:
080:            /**
081:             * Sets bookmark attributes on the form widget, which is later used to generate a html bookmark.
082:             * This is used to "jump back" to a widget context, after form submit.
083:             *  
084:             * @param w the widget which caused the form submit, usually an action widget
085:             */
086:            public static void setBookmark(Widget w) {
087:                if (w != null) {
088:                    Form form = w.getForm();
089:
090:                    if (w instanceof  RowAction) {
091:                        int currIndex = new Integer((String) w.getParent()
092:                                .getId()).intValue();
093:                        Repeater r = getRelatedRepeater(w);
094:                        if (r != null) {
095:                            form.setAttribute("activeElement", r);
096:                            form.setAttribute("activeRow", new Integer(
097:                                    currIndex));
098:                        }
099:                        return;
100:                    }
101:
102:                    if (HippoFormHelper.isAction(w,
103:                            HippoFormHelper.REPEATER_ACTION_ADD)) {
104:                        Repeater r = getRelatedRepeater(w);
105:                        form.setAttribute("activeElement", r);
106:                        form
107:                                .setAttribute("activeRow", new Integer(r
108:                                        .getSize())); // last row
109:                        return;
110:                    }
111:                    form.setAttribute("activeElement", w);
112:                }
113:
114:            }
115:
116:            /**
117:             * Generates a string containing a javascript array of html element ids, which is used to automatically "jump" down to
118:             * to the context the user was at before the form was submitted. 
119:             * @param form The form for which to generate a bookmark
120:             * @return a string containing a javascript array of HTML element ids
121:             */
122:            public static String getBookmark(Form form) {
123:                List bookmark = new ArrayList();
124:                if (form.getAttribute("activeElement") != null) {
125:                    Widget widget = (Widget) form.getAttribute("activeElement");
126:                    Integer activeRowInt = (Integer) form
127:                            .getAttribute("activeRow");
128:
129:                    if (activeRowInt != null) {
130:                        int activeRow = activeRowInt.intValue();
131:                        Repeater repeater = getRelatedRepeater(widget);
132:
133:                        if (activeRow >= 0 && repeater.getSize() > 0) {
134:                            if (activeRow >= repeater.getSize()) {
135:                                activeRow = repeater.getSize() - 1;
136:                            }
137:                            RepeaterRow row = repeater.getRow(activeRow);
138:                            Iterator it = row.getChildren();
139:                            Widget currWidget;
140:                            while (it.hasNext()) {
141:                                currWidget = (Widget) it.next();
142:                                if (currWidget.getState().equals(
143:                                        WidgetState.ACTIVE)) {
144:                                    bookmark.add(currWidget
145:                                            .getRequestParameterName());
146:                                }
147:                            }
148:                        } else {
149:                            // tro to find the add action for the repeater
150:                            String elementId = StringUtils.substringBefore(
151:                                    repeater.getId(), XSDHelper
152:                                            .getRevSeparator());
153:                            String repeaterAddId = new StringBuffer(elementId)
154:                                    .append(XSDHelper.getRevSeparator())
155:                                    .append("crepeatadd").toString();
156:                            Widget addAction = form.lookupWidget(repeaterAddId);
157:                            if (addAction != null) {
158:                                bookmark.add(addAction
159:                                        .getRequestParameterName());
160:                            } else {
161:                                Widget repParent = repeater.getParent();
162:                                if (repParent instanceof  AbstractContainerWidget) {
163:                                    Iterator it = ((AbstractContainerWidget) repParent)
164:                                            .getChildren();
165:                                    Widget currWidget;
166:                                    while (it.hasNext()) {
167:                                        currWidget = (Widget) it.next();
168:                                        if (currWidget.getState().equals(
169:                                                WidgetState.ACTIVE)) {
170:                                            bookmark.add(currWidget
171:                                                    .getRequestParameterName());
172:                                        }
173:                                    }
174:                                }
175:                            }
176:                        }
177:                    } else {
178:                        bookmark.add(widget.getRequestParameterName());
179:                    }
180:                }
181:                StringBuffer bookmarkStr;
182:                if (bookmark.size() > 0) {
183:                    bookmarkStr = new StringBuffer("[");
184:                    for (int i = 0; i < bookmark.size(); i++) {
185:                        if (i > 0)
186:                            bookmarkStr.append(",");
187:                        bookmarkStr.append("\"").append(
188:                                (String) bookmark.get(i)).append("\"");
189:                    }
190:                    bookmarkStr.append("]");
191:                } else
192:                    bookmarkStr = new StringBuffer("null");
193:                form.removeAttribute("activeElement");
194:                form.removeAttribute("gotoFirst");
195:                form.removeAttribute("activeRow");
196:                return bookmarkStr.toString();
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.