1 16 package nl.hippo.cms.workflows.multiplesitessite; 17 18 import com.opensymphony.module.propertyset.PropertySet; 19 import com.opensymphony.workflow.WorkflowException; 20 import java.util.Map ; 21 import nl.hippo.cms.Constants; 22 import nl.hippo.cms.repositorylocation.CommonRepositoryLocationRoles; 23 import nl.hippo.cms.repositorylocation.RepositoryInformation; 24 import nl.hippo.cms.repositorylocation.RepositoryLocation; 25 import nl.hippo.cms.sitesdirectory.SitesDirectory; 26 import nl.hippo.cocoon.webdav.WebDAVHelper; 27 import nl.hippo.componentcontainers.AvalonSpringBridge; 28 import nl.hippo.servermanager.Project; 29 import nl.hippo.servermanager.Server; 30 import nl.hippo.servermanager.ServerManager; 31 import org.apache.commons.httpclient.HttpState; 32 33 public class CreateVersionIfModifiedFunction extends VersioningHelperComponent 34 { 35 36 public CreateVersionIfModifiedFunction() 37 { 38 super(); 39 } 40 41 public void executeImpl(Map transientVars, Map args, PropertySet ps) throws WorkflowException 42 { 43 try 44 { 45 AvalonSpringBridge asb = (AvalonSpringBridge) m_manager.lookup(AvalonSpringBridge.ROLE); 46 try 47 { 48 long documentWorkflowId = ps.getLong("documentWorkflowId"); 49 Server server = ((ServerManager)asb.getBean("serverManager")).getServer(); 50 String projectName = (String )transientVars.get("projectName"); 51 Project project = server.getProject(projectName); 52 PropertySet documentPropertySet = project.getWorkflowRepository().getPropertySet(documentWorkflowId); 53 boolean isUnmodified = documentPropertySet.getBoolean("isUnmodified"); 54 if (!isUnmodified) 55 { 56 RepositoryLocation editorLocation = (RepositoryLocation) m_manager.lookup(CommonRepositoryLocationRoles.EDITOR_REPOSITORY_LOCATION_ROLE); 57 try 58 { 59 RepositoryInformation editorInfo = editorLocation.getRepositoryInformation(); 60 String relativeLocation = ps.getString("location"); 61 String absoluteLocation = editorInfo.getAbsoluteUri(relativeLocation); 62 HttpState httpState = (HttpState) transientVars.get("httpstate"); 63 String username = WebDAVHelper.propfindAsString(absoluteLocation, Constants.CMS_1_0_NAMESPACE, Constants.LAST_WORKFLOW_USER_PROPERTY_NAME, httpState); 64 SitesDirectory sitesDir = (SitesDirectory) m_manager.lookup(SitesDirectory.ROLE); 65 try 66 { 67 String siteName = sitesDir.getSite(ps.getString(MultipleSitesSiteConstants.SITE_ID_KEY)).getName("en"); 69 createVersion(transientVars, ps, username, "Publish", "Approved publication to location '" + siteName); 70 documentPropertySet.setBoolean("isUnmodified", true); 71 } 72 finally 73 { 74 m_manager.release(sitesDir); 75 } 76 } 77 finally 78 { 79 m_manager.release(editorLocation); 80 } 81 } 82 } 83 finally 84 { 85 m_manager.release(asb); 86 } 87 } 88 catch (Exception e) 89 { 90 throw new WorkflowException(e); 91 } 92 } 93 94 } 95 | Popular Tags |