KickJava   Java API By Example, From Geeks To Geeks.

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


1 package nl.hippo.cms.workflows.multiplesitessite;
2
3 import com.opensymphony.module.propertyset.PropertySet;
4 import com.opensymphony.workflow.WorkflowException;
5 import java.io.IOException JavaDoc;
6 import java.util.Map JavaDoc;
7 import nl.hippo.cms.repositorylocation.RepositoryInformation;
8 import nl.hippo.cms.sitesdirectory.SitesDirectory;
9 import nl.hippo.cms.workflows.shared.FunctionProviderComponent;
10 import org.apache.avalon.framework.service.ServiceException;
11 import org.apache.commons.httpclient.HttpClient;
12 import org.apache.commons.httpclient.HttpState;
13 import org.apache.commons.httpclient.methods.DeleteMethod;
14
15 public class RemoveObjectFromPreviewRepositoryFunction extends FunctionProviderComponent
16 {
17
18     public RemoveObjectFromPreviewRepositoryFunction()
19     {
20         super();
21     }
22
23     public void executeImpl(Map JavaDoc transientVars, Map JavaDoc args, PropertySet ps) throws WorkflowException
24     {
25         DeleteMethod delete = null;
26         try
27         {
28             String JavaDoc relativeUri = ps.getString(MultipleSitesSiteConstants.LOCATION_KEY);
29             SitesDirectory sitesDir = (SitesDirectory) m_manager.lookup(SitesDirectory.ROLE);
30             try
31             {
32                 String JavaDoc siteId = ps.getString(MultipleSitesSiteConstants.SITE_ID_KEY);
33                 RepositoryInformation previewRepoInformation = sitesDir.getSite(siteId).getPreviewRepository();
34                 String JavaDoc previewLocation = previewRepoInformation
35                         .getAbsoluteUri(relativeUri);
36                 HttpState httpState = (HttpState) transientVars.get("httpstate");
37                 HttpClient httpClient = new HttpClient();
38                 httpClient.setState(httpState);
39                 delete = new DeleteMethod(previewLocation);
40                 delete.setDoAuthentication(true);
41                 int deleteResult = httpClient.executeMethod(delete);
42                 // TODO: handle result
43
RepositoryHelper.deletePathIfDangling(previewLocation, previewRepoInformation.getAbsoluteBaseUri(), httpClient);
44             }
45             finally
46             {
47                 m_manager.release(sitesDir);
48             }
49         }
50         catch (IOException JavaDoc e)
51         {
52             throw new WorkflowException(e);
53         }
54         catch (ServiceException e)
55         {
56             throw new WorkflowException(e);
57         }
58         finally
59         {
60             if (delete != null)
61             {
62                 delete.releaseConnection();
63             }
64         }
65     }
66
67 }
Popular Tags