Source Code Cross Referenced for WorkFlow.java in  » Content-Management-System » openedit » com » openedit » modules » workflow » 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 » openedit » com.openedit.modules.workflow 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on May 19, 2006
003:         */
004:        package com.openedit.modules.workflow;
005:
006:        import java.io.File;
007:        import java.util.ArrayList;
008:        import java.util.Iterator;
009:        import java.util.List;
010:
011:        import org.apache.commons.logging.Log;
012:        import org.apache.commons.logging.LogFactory;
013:        import org.dom4j.Element;
014:        import org.openedit.repository.ContentItem;
015:
016:        import com.openedit.OpenEditException;
017:        import com.openedit.page.FileFinder;
018:        import com.openedit.page.Page;
019:        import com.openedit.page.PageProperty;
020:        import com.openedit.page.manage.PageManager;
021:        import com.openedit.users.User;
022:        import com.openedit.users.UserManager;
023:        import com.openedit.util.XmlUtil;
024:
025:        public class WorkFlow {
026:            protected File fieldRoot;
027:            protected PageManager fieldPageManager;
028:            protected UserManager fieldUserManager;
029:            protected int fieldLevelCount = 0;
030:            private static final Log log = LogFactory.getLog(WorkFlow.class);
031:            protected long fieldLastModified = -2;
032:            protected ArrayList fieldWorkFlowListeners;
033:
034:            public List listAllDrafts() throws OpenEditException {
035:                FileFinder finder = new FileFinder();
036:                finder.setRoot(getRoot());
037:                finder.setPageManager(getPageManager());
038:                finder.addSkipFileName("*.xconf");
039:                finder.setUseMatches(true);
040:                return finder.findPages("*.draft.*");
041:            }
042:
043:            public String getUserDescription(String inUserName) {
044:                if (inUserName == null || inUserName.length() == 0) {
045:                    return "";
046:                }
047:                User user = getUserManager().getUser(inUserName);
048:                if (user != null) {
049:                    return user.getShortDescription();
050:                }
051:                return "";
052:            }
053:
054:            public ContentItem getLastVersion(Page inDraft)
055:                    throws OpenEditException {
056:                ContentItem revision = getPageManager().getLatestVersion(
057:                        inDraft.getPath());
058:                if (revision != null) {
059:                    return revision;
060:                }
061:                return inDraft.getContentItem();
062:
063:            }
064:
065:            public Page getOriginalPage(Page inDraft) throws OpenEditException {
066:                String dpath = inDraft.getPath();
067:                int index = dpath.indexOf(".draft.");
068:                String path = dpath.substring(0, index);
069:                path = path + dpath.substring(index + 6);
070:
071:                Page org = getPageManager().getPage(path);
072:                return org;
073:            }
074:
075:            public PageManager getPageManager() {
076:                return fieldPageManager;
077:            }
078:
079:            public void setPageManager(PageManager inPageManager) {
080:                fieldPageManager = inPageManager;
081:            }
082:
083:            public File getRoot() {
084:                return fieldRoot;
085:            }
086:
087:            public void setRoot(File inRoot) {
088:                fieldRoot = inRoot;
089:            }
090:
091:            public UserManager getUserManager() {
092:                return fieldUserManager;
093:            }
094:
095:            public void setUserManager(UserManager inUserManager) {
096:                fieldUserManager = inUserManager;
097:            }
098:
099:            public void approve(String inPath, User inUser)
100:                    throws OpenEditException {
101:                Page draft = getPageManager().getPage(inPath);
102:                if (!draft.exists()) {
103:                    log.error("No draft found to approve " + inPath);
104:                    return;
105:                }
106:                //read in level count file
107:                loadLevelCount();
108:
109:                //see if we have levels configured
110:                if (getLevelCount() > 0) {
111:                    int newLevel = findHighestApproval(inUser);
112:                    if (newLevel > 0) {
113:                        int oldLevel = findExistingLevel(draft);
114:                        if (oldLevel < newLevel) {
115:                            saveLevel(draft, newLevel);
116:                        }
117:                    }
118:                    if (newLevel < getLevelCount()) //then dont approve just yet
119:                    {
120:                        log.info("Requires more approval");
121:                        return;
122:                    }
123:                }
124:                String orig = inPath.replaceAll("\\.draft", "");
125:                Page dest = getPageManager().getPage(orig);
126:
127:                dest.getContentItem().setAuthor(inUser.getUserName());
128:
129:                ContentItem rev = getLastVersion(draft);
130:                dest.getContentItem().setMessage(
131:                        "Approved: (" + rev.getAuthor() + " "
132:                                + rev.getMessage() + ")");
133:                dest.getContentItem().setType(ContentItem.TYPE_APPROVED);
134:
135:                getPageManager().movePage(draft, dest);
136:                if (getLevelCount() > 0) {
137:                    saveLevel(draft, 0);
138:                }
139:                firePageApproved(dest);
140:            }
141:
142:            private void saveLevel(Page draft, int newLevel)
143:                    throws OpenEditException {
144:                PageProperty property = new PageProperty("approve.level");
145:                property.setValue(String.valueOf(newLevel));
146:                draft.getPageSettings().putProperty(property);
147:                //save
148:                getPageManager().getPageSettingsManager().saveSetting(
149:                        draft.getPageSettings());
150:            }
151:
152:            protected void loadLevelCount() throws OpenEditException {
153:                Page level = getPageManager().getPage(
154:                        "/openedit/workflow/settings.xml");
155:                if (level.getLastModified().getTime() != fieldLastModified) {
156:                    fieldLastModified = level.getLastModified().getTime();
157:                    Element root = new XmlUtil().getXml(level.getReader(),
158:                            "UTF-8");
159:                    String text = root.elementText("levels");
160:                    if (text != null) {
161:                        setLevelCount(Integer.parseInt(text));
162:                    }
163:                }
164:            }
165:
166:            public int findExistingLevel(Page inDraft) {
167:                String existingLevel = inDraft.get("approve.level");
168:                int oldLevel = 0;
169:                if (existingLevel != null) {
170:                    oldLevel = Integer.parseInt(existingLevel);
171:                }
172:                return oldLevel;
173:            }
174:
175:            public boolean canApprove(User inUser, Page inDraft)
176:                    throws OpenEditException {
177:                if (inDraft.isDraft() && !inDraft.exists()) {
178:                    return false;
179:                }
180:                loadLevelCount();
181:                if (getLevelCount() == 0) {
182:                    if (inUser.hasPermission("oe.edit.approves")) {
183:                        return true;
184:                    } else {
185:                        return false;
186:                    }
187:                }
188:                int power = findHighestApproval(inUser);
189:                if (power == 0) {
190:                    return false;
191:                }
192:                int existing = findExistingLevel(inDraft);
193:                if (power > existing) {
194:                    return true;
195:                }
196:                return false;
197:            }
198:
199:            public int findHighestApproval(User inUser) {
200:                int level = 0;
201:                for (int i = 1; i < getLevelCount() + 1; i++) {
202:                    if (inUser.hasPermission("oe.edit.approve.level" + i)) {
203:                        level = i;
204:                    }
205:                }
206:                return level;
207:            }
208:
209:            public void approveAll(User inUser) throws Exception {
210:                List pages = listAllDrafts();
211:                for (Iterator iter = pages.iterator(); iter.hasNext();) {
212:                    Page editPath = (Page) iter.next();
213:                    approve(editPath.getPath(), inUser);
214:                }
215:            }
216:
217:            public void deleteDraft(String inPath, User inUser)
218:                    throws OpenEditException {
219:                Page page = getPageManager().getPage(inPath);
220:                page.getContentItem().setAuthor(inUser.getUserName());
221:                page.getContentItem().setMessage("Deleted Draft");
222:                getPageManager().removePage(page);
223:                firePageDeleted(page);
224:            }
225:
226:            public int getLevelCount() {
227:                return fieldLevelCount;
228:            }
229:
230:            public void setLevelCount(int inLevelCount) {
231:                fieldLevelCount = inLevelCount;
232:            }
233:
234:            public ArrayList getWorkFlowListeners() {
235:                if (fieldWorkFlowListeners == null) {
236:                    fieldWorkFlowListeners = new ArrayList();
237:
238:                }
239:
240:                return fieldWorkFlowListeners;
241:            }
242:
243:            public void setWorkFlowListeners(ArrayList inWorkFlowListeners) {
244:                fieldWorkFlowListeners = inWorkFlowListeners;
245:            }
246:
247:            protected void firePageApproved(Page inPage) {
248:                for (Iterator iter = getWorkFlowListeners().iterator(); iter
249:                        .hasNext();) {
250:                    WorkFlowListener listener = (WorkFlowListener) iter.next();
251:                    listener.pageApproved(inPage);
252:                }
253:            }
254:
255:            protected void firePageDeleted(Page inPage) {
256:                for (Iterator iter = getWorkFlowListeners().iterator(); iter
257:                        .hasNext();) {
258:                    WorkFlowListener listener = (WorkFlowListener) iter.next();
259:                    listener.pageDeleted(inPage);
260:                }
261:            }
262:
263:            public void addWorkFlowListener(WorkFlowListener inListener) {
264:                getWorkFlowListeners().add(inListener);
265:            }
266:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.