Source Code Cross Referenced for WorkflowModule.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » lenya » cms » cocoon » components » modules » input » 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 » apache lenya 2.0 » org.apache.lenya.cms.cocoon.components.modules.input 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:
019:        package org.apache.lenya.cms.cocoon.components.modules.input;
020:
021:        import java.text.DateFormat;
022:        import java.text.SimpleDateFormat;
023:        import java.util.Arrays;
024:        import java.util.Iterator;
025:        import java.util.Map;
026:
027:        import org.apache.avalon.framework.configuration.Configuration;
028:        import org.apache.avalon.framework.configuration.ConfigurationException;
029:        import org.apache.cocoon.environment.ObjectModelHelper;
030:        import org.apache.lenya.cms.publication.Document;
031:        import org.apache.lenya.cms.publication.PageEnvelope;
032:        import org.apache.lenya.cms.repository.RepositoryUtil;
033:        import org.apache.lenya.cms.repository.Session;
034:        import org.apache.lenya.cms.workflow.WorkflowUtil;
035:        import org.apache.lenya.workflow.Version;
036:        import org.apache.lenya.workflow.Workflow;
037:        import org.apache.lenya.workflow.WorkflowManager;
038:        import org.apache.lenya.workflow.Workflowable;
039:
040:        /**
041:         * Module for workflow access.
042:         * 
043:         * @version $Id: WorkflowModule.java 565823 2007-08-14 16:25:29Z rfrovarp $
044:         */
045:        public class WorkflowModule extends AbstractPageEnvelopeModule {
046:
047:            /**
048:             * <code>STATE</code> The state
049:             */
050:            public static final String STATE = "state";
051:            /**
052:             * <code>VARIABLE_PREFIX</code> The variable prefix
053:             */
054:            public static final String VARIABLE_PREFIX = "variable.";
055:
056:            /**
057:             * The prefix to get the last user who invoked a certain event.
058:             */
059:            public static final String LAST_USER_PREFIX = "lastUser.";
060:
061:            /**
062:             * The prefix to get the last date at which a certain event was invoked.
063:             * @see #DATE_FORMAT
064:             */
065:            public static final String LAST_DATE_PREFIX = "lastDate.";
066:
067:            private final DateFormat DATE_FORMAT = new SimpleDateFormat(
068:                    "yyyy-MM-dd HH:mm:ss");
069:            private final Object lock = new Object();
070:            static final String[] PARAMETER_NAMES = { STATE };
071:
072:            /**
073:             * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String,
074:             *      org.apache.avalon.framework.configuration.Configuration, java.util.Map)
075:             */
076:            public Object getAttribute(String name, Configuration modeConf,
077:                    Map objectModel) throws ConfigurationException {
078:
079:                Object value = null;
080:                WorkflowManager wfManager = null;
081:
082:                try {
083:                    PageEnvelope envelope = getEnvelope(objectModel, name);
084:                    Document document = envelope.getDocument();
085:                    if (document != null && document.exists()) {
086:                        wfManager = (WorkflowManager) this .manager
087:                                .lookup(WorkflowManager.ROLE);
088:                        Session session = RepositoryUtil.getSession(
089:                                this .manager, ObjectModelHelper
090:                                        .getRequest(objectModel));
091:                        Workflowable workflowable = WorkflowUtil
092:                                .getWorkflowable(this .manager, session,
093:                                        getLogger(), document);
094:                        if (wfManager.hasWorkflow(workflowable)) {
095:
096:                            Version latestVersion = workflowable
097:                                    .getLatestVersion();
098:
099:                            if (name.equals(STATE)) {
100:                                if (latestVersion == null) {
101:                                    Workflow workflow = wfManager
102:                                            .getWorkflowSchema(workflowable);
103:                                    value = workflow.getInitialState();
104:                                } else {
105:                                    value = latestVersion.getState();
106:                                }
107:                            } else if (name.startsWith(VARIABLE_PREFIX)) {
108:                                String variableName = name
109:                                        .substring(VARIABLE_PREFIX.length());
110:                                Workflow workflow = wfManager
111:                                        .getWorkflowSchema(workflowable);
112:                                String[] variableNames = workflow
113:                                        .getVariableNames();
114:                                if (Arrays.asList(variableNames).contains(
115:                                        variableName)) {
116:                                    if (latestVersion == null) {
117:                                        value = Boolean.valueOf(workflow
118:                                                .getInitialValue(variableName));
119:                                    } else {
120:                                        value = Boolean.valueOf(latestVersion
121:                                                .getValue(variableName));
122:                                    }
123:                                }
124:                            } else if (name.startsWith(LAST_USER_PREFIX)) {
125:                                String event = name.substring(LAST_USER_PREFIX
126:                                        .length());
127:                                Version latestEventVersion = getLatestVersion(
128:                                        workflowable, event);
129:                                if (latestEventVersion != null) {
130:                                    value = latestEventVersion.getUserId();
131:                                }
132:                            } else if (name.startsWith(LAST_DATE_PREFIX)) {
133:                                String event = name.substring(LAST_DATE_PREFIX
134:                                        .length());
135:                                Version latestEventVersion = getLatestVersion(
136:                                        workflowable, event);
137:                                if (latestEventVersion != null) {
138:                                    synchronized (lock) {
139:                                        value = this .DATE_FORMAT
140:                                                .format(latestEventVersion
141:                                                        .getDate());
142:                                    }
143:                                }
144:                            } else {
145:                                throw new ConfigurationException(
146:                                        "The attribute [" + name
147:                                                + "] is not supported!");
148:                            }
149:                        }
150:                    }
151:                } catch (ConfigurationException e) {
152:                    throw e;
153:                } catch (Exception e) {
154:                    throw new ConfigurationException(
155:                            "Resolving attribute failed: ", e);
156:                } finally {
157:                    if (wfManager != null) {
158:                        this .manager.release(wfManager);
159:                    }
160:                }
161:                return value;
162:            }
163:
164:            protected Version getLatestVersion(Workflowable workflowable,
165:                    String event) {
166:                Version latestEventVersion = null;
167:                Version versions[] = workflowable.getVersions();
168:                int i = versions.length - 1;
169:                while (i > -1 && !versions[i].getEvent().equals(event)) {
170:                    i--;
171:                }
172:                if (i > -1) {
173:                    latestEventVersion = versions[i];
174:                }
175:                return latestEventVersion;
176:            }
177:
178:            /**
179:             * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration,
180:             *      java.util.Map)
181:             */
182:            public Iterator getAttributeNames(Configuration modeConf,
183:                    Map objectModel) throws ConfigurationException {
184:                return Arrays.asList(PARAMETER_NAMES).iterator();
185:            }
186:
187:            /**
188:             * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String,
189:             *      org.apache.avalon.framework.configuration.Configuration, java.util.Map)
190:             */
191:            public Object[] getAttributeValues(String name,
192:                    Configuration modeConf, Map objectModel)
193:                    throws ConfigurationException {
194:                Object[] objects = { getAttribute(name, modeConf, objectModel) };
195:
196:                return objects;
197:            }
198:
199:        }
www___.j___a___v___a2__s_.c___om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.