1 4 package com.openedit.modules.workflow; 5 6 import java.util.List ; 7 8 import org.apache.commons.logging.Log; 9 import org.apache.commons.logging.LogFactory; 10 11 import com.openedit.OpenEditException; 12 import com.openedit.WebPageRequest; 13 import com.openedit.modules.BaseModule; 14 import com.openedit.page.Page; 15 import com.openedit.page.PageAction; 16 import com.openedit.users.User; 17 import com.openedit.util.PathUtilities; 18 19 public class WorkFlowModule extends BaseModule 20 { 21 private static final Log log = LogFactory.getLog(WorkFlowModule.class); 22 23 protected WorkFlow fieldWorkFlow; 24 25 public List listDrafts(WebPageRequest inReq) throws OpenEditException 26 { 27 List drafts = getWorkFlow().listAllDrafts(); 29 inReq.putPageValue("drafts", drafts); 30 inReq.putPageValue("workflow", getWorkFlow()); 31 return drafts; 32 } 33 public void flipDraftMode(WebPageRequest inReq) throws Exception 34 { 35 User user = inReq.getUser(); 36 String mode = "oe.edit.draftmode"; 37 if( user.hasProperty(mode)) 38 { 39 user.remove(mode); 40 } 41 else 42 { 43 user.put(mode,"true"); 44 } 45 redirectBack(inReq); 46 } 47 public void approveAll(WebPageRequest inReq) throws Exception 48 { 49 User user = inReq.getUser(); 50 getWorkFlow().approveAll(user); 51 redirectBack(inReq); 52 } 53 public void approve(WebPageRequest inReq) throws Exception 54 { 55 String path = inReq.getRequestParameter("editPath"); 56 57 if ( path.indexOf(".draft.") > -1) 58 { 59 getWorkFlow().approve(path, inReq.getUser() ); 60 redirectBack(inReq); 61 } 62 } 63 public void deleteDraft(WebPageRequest inReq) throws OpenEditException 64 { 65 String path = inReq.getRequestParameter("editPath"); 66 67 if ( path.indexOf(".draft.") > -1) 68 { 69 getWorkFlow().deleteDraft(path, inReq.getUser() ); 70 } 71 redirectBack(inReq); 72 } 73 protected void redirectBack(WebPageRequest inReq) 74 { 75 String redirect = inReq.getRequestParameter("origURL"); 76 if ( redirect != null) 77 { 78 if( redirect.indexOf("?") > -1) 79 { 80 inReq.redirect(redirect); 81 } 82 else 83 { 84 inReq.redirect(redirect + "?cache=false"); 85 } 86 } 87 } 88 public WorkFlow getWorkFlow() 89 { 90 return fieldWorkFlow; 91 } 92 public void setWorkFlow(WorkFlow inWorkFlow) 93 { 94 fieldWorkFlow = inWorkFlow; 95 } 96 97 public void showDraftComparison(WebPageRequest inReq) throws OpenEditException 99 { 100 String draftpath = inReq.getRequestParameter("draftpath"); 101 String livepath = PathUtilities.createLivePath(draftpath); 102 Page livepage = getPageManager().getPage(livepath); 103 Page draftpage = getPageManager().getPage(draftpath); 104 inReq.putPageValue("livepage", livepage); 105 inReq.putPageValue("draftpage", draftpage); 106 inReq.putPageValue("draftcontent", draftpage.getContentItem()); 107 inReq.putPageValue("parentName", inReq.getRequestParameter("parentName")); 109 inReq.putPageValue("origURL", inReq.getRequestParameter("origURL")); 110 } 111 112 public void canApprove(WebPageRequest inReq) throws OpenEditException 113 { 114 Page editPage = (Page)inReq.getPageValue("editPage"); 115 boolean can = getWorkFlow().canApprove(inReq.getUser(), editPage); 117 inReq.putPageValue("canapprove", Boolean.valueOf(can)); 118 } 119 120 public void runPath(WebPageRequest inReq) throws OpenEditException 121 { 122 PageAction action = inReq.getCurrentAction(); 123 String path = action.getConfig().getChildValue("path"); 124 Page page = getPageManager().getPage(path); 125 if( page.exists() ) 126 { 127 getModuleManager().executePathActions(page, inReq); 128 getModuleManager().executePageActions(page, inReq); 129 } 131 else 132 { 133 log.error("No such page to run actions on " + path); 134 } 135 } 136 } 137 | Popular Tags |