KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nl > hippo > cms > workflows > multiplesitessite > CreateVersionIfModifiedFunction


1 /*
2  * Copyright 2004 Hippo Webworks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
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 JavaDoc transientVars, Map JavaDoc 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 JavaDoc projectName = (String JavaDoc)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 JavaDoc relativeLocation = ps.getString("location");
61                         String JavaDoc absoluteLocation = editorInfo.getAbsoluteUri(relativeLocation);
62                         HttpState httpState = (HttpState) transientVars.get("httpstate");
63                         String JavaDoc 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                             // TODO: where to get locale?
68
String JavaDoc 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 JavaDoc e)
89         {
90             throw new WorkflowException(e);
91         }
92     }
93
94 }
95
Popular Tags