Source Code Cross Referenced for AllCommentsHandlerPO.java in  » Workflow-Engines » shark » org » enhydra » shark » webclient » presentation » 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 » Workflow Engines » shark » org.enhydra.shark.webclient.presentation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.enhydra.shark.webclient.presentation;
002:
003:        import java.text.SimpleDateFormat;
004:        import java.util.ArrayList;
005:        import java.util.Calendar;
006:        import java.util.Date;
007:        import java.util.HashMap;
008:        import java.util.Iterator;
009:        import java.util.Locale;
010:        import java.util.Map;
011:
012:        import org.enhydra.shark.api.client.wfmc.wapi.WAPI;
013:        import org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
014:        import org.enhydra.shark.api.client.wfservice.ExecutionAdministration;
015:        import org.enhydra.shark.client.utilities.SharkInterfaceWrapper;
016:        import org.enhydra.shark.utilities.MiscUtilities;
017:        import org.enhydra.shark.utilities.WMEntityUtilities;
018:        import org.enhydra.shark.webclient.business.SharkUtils;
019:        import org.enhydra.shark.webclient.presentation.utils.NavigConsts;
020:        import org.enhydra.shark.webclient.spec.utils.ParamConsts;
021:        import org.enhydra.xml.io.OutputOptions;
022:        import org.w3c.dom.Node;
023:        import org.w3c.dom.html.HTMLAnchorElement;
024:
025:        import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
026:        import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
027:
028:        public class AllCommentsHandlerPO extends BasePO {
029:
030:            private final String COMMENT_ARRAY = "comment_array_values";
031:
032:            private final String USER_ARRAY = "comment_array_users";
033:
034:            private final String DATE_ARRAY = "comment_array_dates";
035:
036:            private static Map demoMap = new HashMap();
037:
038:            public Node handleDefault() throws HttpPresentationException {
039:                AllCommentsHTML allCommPage = (AllCommentsHTML) myComms.xmlcFactory
040:                        .create(AllCommentsHTML.class);
041:
042:                String proId = myComms.request
043:                        .getParameter(ParamConsts.PROCESS_ID);
044:                String actId = myComms.request
045:                        .getParameter(ParamConsts.ACTIVITY_ID);
046:                String errMessage = myComms.request.getParameter("errMessage");
047:                if (null != errMessage) {
048:                    allCommPage.setTextErrorText(errMessage);
049:                }
050:                if (!MiscUtilities.isEmptyString(proId)) {
051:                    allCommPage.getElementPro_id().setAttribute("value", proId);
052:                    if (!MiscUtilities.isEmptyString(actId)) {
053:                        allCommPage.getElementAct_id().setAttribute("value",
054:                                actId);
055:                    }
056:                    try {
057:                        WAPI wapi = SharkInterfaceWrapper.getShark()
058:                                .getWAPIConnection();
059:                        WMSessionHandle shandle = SharkInterfaceWrapper
060:                                .makeWAPIConnection(wapi, getUsername(), null);
061:                        Map cnt = null;
062:                        if (MiscUtilities.isEmptyString(actId)) {
063:                            cnt = WMEntityUtilities
064:                                    .getMapFromWMAttributeArray(wapi
065:                                            .listProcessInstanceAttributes(
066:                                                    shandle, proId, null, true)
067:                                            .getArray());
068:                        } else {
069:                            cnt = WMEntityUtilities
070:                                    .getMapFromWMAttributeArray(wapi
071:                                            .listActivityInstanceAttributes(
072:                                                    shandle, proId, actId,
073:                                                    null, true).getArray());
074:
075:                        }
076:                        Node fileRow = allCommPage.getElementCommentRow();
077:                        HTMLAnchorElement deleteLink = allCommPage
078:                                .getElementDeleteLink();
079:                        String pref = MiscUtilities.isEmptyString(actId) ? ""
080:                                : "act_";
081:                        if (cnt.containsKey(pref + COMMENT_ARRAY)
082:                                && cnt.containsKey(pref + USER_ARRAY)
083:                                && cnt.containsKey(pref + DATE_ARRAY)) {
084:
085:                            String[] comments = (String[]) cnt.get(pref
086:                                    + COMMENT_ARRAY);
087:                            String[] users = (String[]) cnt.get(pref
088:                                    + USER_ARRAY);
089:                            Date[] date = (Date[]) cnt.get(pref + DATE_ARRAY);
090:                            SimpleDateFormat sdf = new SimpleDateFormat(
091:                                    "dd.MM.yyyy. H:mm:ss");
092:                            if (null != comments && null != users
093:                                    && null != date) {
094:                                for (int i = 0; i < comments.length; i++) {
095:
096:                                    allCommPage
097:                                            .setTextCommentValue(comments[i]);
098:                                    allCommPage.setTextCommentUser(users[i]);
099:                                    Date commentDate = date[i];
100:
101:                                    String strCommentDate = sdf
102:                                            .format(commentDate);
103:                                    allCommPage
104:                                            .setTextCommentDate(strCommentDate);
105:
106:                                    String href = "AllCommentsHandlerPO.po?event=delete&comment="
107:                                            + comments[i]
108:                                            + "&user="
109:                                            + users[i]
110:                                            + "&strdate="
111:                                            + strCommentDate
112:                                            + "&pro_id=" + proId;
113:                                    if (!MiscUtilities.isEmptyString(actId)) {
114:                                        href += "&act_id=" + actId;
115:                                    }
116:                                    deleteLink.setHref(href);
117:
118:                                    fileRow.getParentNode().insertBefore(
119:                                            fileRow.cloneNode(true), fileRow);
120:                                }
121:                            }
122:                        }
123:                        fileRow.getParentNode().removeChild(fileRow);
124:
125:                        wapi.disconnect(shandle);
126:                    } catch (Exception e) {
127:
128:                        e.printStackTrace();
129:                        throw new PresentationException("Can't show page", e);
130:                    }
131:
132:                }
133:
134:                return allCommPage;
135:            }
136:
137:            public Node handleDelete() throws HttpPresentationException {
138:
139:                if (SharkUtils.sharkEdition.equalsIgnoreCase("demo")) {
140:                    if (demoMap.containsKey("allcomments")) {
141:                        Integer count = (Integer) demoMap.get("allcomments");
142:                        int i = count.intValue();
143:                        if (i == 3) {
144:                            throw new ClientPageRedirectException(
145:                                    NavigConsts.LIMIT_HANDLER);
146:
147:                        }
148:                        i++;
149:                        demoMap.put("allcomments", new Integer(i));
150:                    } else {
151:                        demoMap.put("allcomments", new Integer(1));
152:                    }
153:                }
154:
155:                String comment = myComms.request.getParameter("comment");
156:                String user = myComms.request.getParameter("user");
157:                String strDate = myComms.request.getParameter("strdate");
158:                String proId = myComms.request
159:                        .getParameter(ParamConsts.PROCESS_ID);
160:                String actId = myComms.request
161:                        .getParameter(ParamConsts.ACTIVITY_ID);
162:                if (comment.length() > 254) {
163:                    comment = comment.substring(0, 254);
164:                }
165:
166:                Map tempMap = new HashMap();
167:
168:                try {
169:                    WAPI wapi = SharkInterfaceWrapper.getShark()
170:                            .getWAPIConnection();
171:                    ExecutionAdministration ea = SharkInterfaceWrapper
172:                            .getShark().getExecutionAdministration();
173:                    WMSessionHandle shandle = SharkInterfaceWrapper
174:                            .makeWAPIConnection(wapi, getUsername(), null);
175:                    Map cnt = null;
176:                    if (MiscUtilities.isEmptyString(actId)) {
177:                        cnt = WMEntityUtilities.getMapFromWMAttributeArray(wapi
178:                                .listProcessInstanceAttributes(shandle, proId,
179:                                        null, true).getArray());
180:                    } else {
181:                        cnt = WMEntityUtilities.getMapFromWMAttributeArray(wapi
182:                                .listActivityInstanceAttributes(shandle, proId,
183:                                        actId, null, true).getArray());
184:                    }
185:                    deleteObjectFromArray(cnt, tempMap, comment, user, strDate,
186:                            !MiscUtilities.isEmptyString(actId));
187:
188:                    Iterator it = tempMap.entrySet().iterator();
189:                    while (it.hasNext()) {
190:                        Map.Entry me = (Map.Entry) it.next();
191:
192:                        if (MiscUtilities.isEmptyString(actId)) {
193:                            wapi.assignProcessInstanceAttribute(shandle, proId,
194:                                    me.getKey().toString(), me.getValue());
195:                        } else {
196:                            ea.assignActivityInstanceAttributeForLocalContext(
197:                                    shandle, proId, actId, me.getKey()
198:                                            .toString(), me.getValue());
199:                        }
200:                    }
201:
202:                    wapi.disconnect(shandle);
203:                } catch (Exception e) {
204:
205:                    e.printStackTrace();
206:                    throw new PresentationException("Can't delete", e);
207:                }
208:
209:                String redirectTo = NavigConsts.ALL_COMMENTS_HANDLER
210:                        + "?pro_id=" + proId;
211:                if (!MiscUtilities.isEmptyString(actId)) {
212:                    redirectTo += "&act_id=" + actId;
213:                }
214:                throw new ClientPageRedirectException(redirectTo);
215:            }
216:
217:            private void deleteObjectFromArray(Map map, Map tempMap,
218:                    String comment, String user, String strdate, boolean isAct) {
219:                String pref = !isAct ? "" : "act_";
220:                String[] commArr = (String[]) map.get(pref + COMMENT_ARRAY);
221:                String[] usrArr = (String[]) map.get(pref + USER_ARRAY);
222:                Date[] dateArr = (Date[]) map.get(pref + DATE_ARRAY);
223:                ArrayList alcomm = new ArrayList();
224:                ArrayList alusr = new ArrayList();
225:                ArrayList aldate = new ArrayList();
226:                SimpleDateFormat sdf = new SimpleDateFormat(
227:                        "dd.MM.yyyy. H:mm:ss");
228:
229:                int length = commArr.length;// arrays must be with same lenght
230:                if (length != usrArr.length || length != dateArr.length) {
231:                    // /???
232:                    return;
233:                }
234:
235:                for (int i = 0; i < length; i++) {
236:                    alcomm.add(commArr[i]);
237:                    alusr.add(usrArr[i]);
238:                    aldate.add(dateArr[i]);
239:                }
240:
241:                for (int i = 0; i < alcomm.size(); i++) {
242:                    if (alcomm.get(i).equals(comment)
243:                            && alusr.get(i).equals(user)
244:                            && (sdf.format((Date) aldate.get(i)))
245:                                    .equals(strdate)) {
246:                        alcomm.remove(i);
247:                        alusr.remove(i);
248:                        aldate.remove(i);
249:                        break;
250:                    }
251:
252:                }
253:                commArr = null;
254:                usrArr = null;
255:                dateArr = null;
256:
257:                if (alcomm.size() > 0) { // arrays must be with the same length
258:                    commArr = new String[alcomm.size()];
259:                    usrArr = new String[alusr.size()];
260:                    dateArr = new Date[aldate.size()];
261:
262:                    alcomm.toArray(commArr);
263:                    alusr.toArray(usrArr);
264:                    aldate.toArray(dateArr);
265:                }
266:
267:                tempMap.put(pref + COMMENT_ARRAY, commArr);
268:                tempMap.put(pref + USER_ARRAY, usrArr);
269:                tempMap.put(pref + DATE_ARRAY, dateArr);
270:
271:            }
272:
273:            public Node handleSave() throws HttpPresentationException {
274:
275:                if (SharkUtils.sharkEdition.equalsIgnoreCase("demo")) {
276:                    if (demoMap.containsKey("comment")) {
277:                        Integer count = (Integer) demoMap.get("comment");
278:                        int i = count.intValue();
279:                        if (i == 3) {
280:                            throw new ClientPageRedirectException(
281:                                    NavigConsts.LIMIT_HANDLER);
282:
283:                        }
284:                        i++;
285:                        demoMap.put("comment", new Integer(i));
286:                    } else {
287:                        demoMap.put("comment", new Integer(1));
288:                    }
289:                }
290:
291:                String comment = myComms.request.getParameter("comment");
292:                String proId = myComms.request
293:                        .getParameter(ParamConsts.PROCESS_ID);
294:                String actId = myComms.request
295:                        .getParameter(ParamConsts.ACTIVITY_ID);
296:
297:                Map tempMap = new HashMap();
298:
299:                try {
300:                    WAPI wapi = SharkInterfaceWrapper.getShark()
301:                            .getWAPIConnection();
302:                    ExecutionAdministration ea = SharkInterfaceWrapper
303:                            .getShark().getExecutionAdministration();
304:                    WMSessionHandle shandle = SharkInterfaceWrapper
305:                            .makeWAPIConnection(wapi, getUsername(), null);
306:                    Map cnt = null;
307:                    if (MiscUtilities.isEmptyString(actId)) {
308:                        cnt = WMEntityUtilities.getMapFromWMAttributeArray(wapi
309:                                .listProcessInstanceAttributes(shandle, proId,
310:                                        null, true).getArray());
311:                    } else {
312:                        cnt = WMEntityUtilities.getMapFromWMAttributeArray(wapi
313:                                .listActivityInstanceAttributes(shandle, proId,
314:                                        actId, null, true).getArray());
315:                    }
316:
317:                    String pref = MiscUtilities.isEmptyString(actId) ? ""
318:                            : "act_";
319:                    // comment
320:                    createObjectArray(cnt, tempMap, pref + COMMENT_ARRAY,
321:                            comment);
322:                    // user
323:                    createObjectArray(cnt, tempMap, pref + USER_ARRAY,
324:                            getUsername());
325:                    // date
326:                    createObjectArray(cnt, tempMap, pref + DATE_ARRAY, Calendar
327:                            .getInstance(Locale.getDefault()).getTime());
328:
329:                    Iterator it = tempMap.entrySet().iterator();
330:                    while (it.hasNext()) {
331:                        Map.Entry me = (Map.Entry) it.next();
332:                        if (MiscUtilities.isEmptyString(actId)) {
333:                            wapi.assignProcessInstanceAttribute(shandle, proId,
334:                                    me.getKey().toString(), me.getValue());
335:                        } else {
336:                            ea.assignActivityInstanceAttributeForLocalContext(
337:                                    shandle, proId, actId, me.getKey()
338:                                            .toString(), me.getValue());
339:                        }
340:                    }
341:
342:                    wapi.disconnect(shandle);
343:                } catch (Exception e) {
344:
345:                    String redirectTo = NavigConsts.ALL_COMMENTS_HANDLER
346:                            + "?pro_id=" + proId;
347:                    if (!MiscUtilities.isEmptyString(actId)) {
348:                        redirectTo += "&act_id=" + actId;
349:                    }
350:                    redirectTo += "&errMessage=";
351:                    if (MiscUtilities.isEmptyString(actId)) {
352:                        redirectTo += "Process";
353:                    } else {
354:                        redirectTo += "Activity";
355:                    }
356:                    redirectTo += " does not support Comments!";
357:                    throw new ClientPageRedirectException(redirectTo);
358:                }
359:
360:                String redirectTo = NavigConsts.ALL_COMMENTS_HANDLER
361:                        + "?pro_id=" + proId;
362:                if (!MiscUtilities.isEmptyString(actId)) {
363:                    redirectTo += "&act_id=" + actId;
364:                }
365:                throw new ClientPageRedirectException(redirectTo);
366:            }
367:
368:            private void createObjectArray(Map map, Map tempMap, String key,
369:                    Object value) {
370:
371:                Object[] arr = null;
372:
373:                if (!map.containsKey(key)) {
374:
375:                    if (value instanceof  String) {
376:                        // comment or username
377:                        arr = new String[1];
378:
379:                    } else {
380:                        // comment date
381:                        arr = new Date[1];
382:                    }
383:
384:                    arr[0] = value;
385:
386:                } else {
387:
388:                    ArrayList al = new ArrayList();
389:                    arr = (Object[]) map.get(key);
390:
391:                    if (null != arr) {
392:                        for (int i = 0; i < arr.length; i++) {
393:                            al.add(arr[i]);
394:                        }
395:                    }
396:                    al.add(value);
397:                    if (value instanceof  String) {
398:
399:                        arr = new String[al.size()];
400:
401:                    } else {
402:                        arr = new Date[al.size()];
403:                    }
404:                    al.toArray(arr);
405:
406:                }
407:                tempMap.put(key, arr);
408:
409:            }
410:
411:            public OutputOptions getPostProcessingOptions() throws Exception {
412:
413:                return null;
414:            }
415:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.