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 ; 6 import java.util.Map ; 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 RemoveObjectFromLiveRepositoryFunction extends FunctionProviderComponent 16 { 17 18 public RemoveObjectFromLiveRepositoryFunction() 19 { 20 super(); 21 } 22 23 public void executeImpl(Map transientVars, Map args, PropertySet ps) throws WorkflowException 24 { 25 DeleteMethod delete = null; 26 try 27 { 28 String relativeUri = ps.getString(MultipleSitesSiteConstants.LOCATION_KEY); 29 SitesDirectory sitesDir = (SitesDirectory) m_manager.lookup(SitesDirectory.ROLE); 30 try 31 { 32 String siteId = ps.getString(MultipleSitesSiteConstants.SITE_ID_KEY); 33 RepositoryInformation liveRepoInformation = sitesDir.getSite(siteId).getLiveRepository(); 34 String liveLocation = liveRepoInformation 35 .getAbsoluteUri(relativeUri); 36 HttpState httpState = (HttpState) transientVars.get("httpstate"); 37 HttpClient httpClient = new HttpClient(); 38 httpClient.setState(httpState); 39 delete = new DeleteMethod(liveLocation); 40 delete.setDoAuthentication(true); 41 int deleteResult = httpClient.executeMethod(delete); 42 RepositoryHelper.deletePathIfDangling(liveLocation, liveRepoInformation.getAbsoluteBaseUri(), httpClient); 44 } 45 finally 46 { 47 m_manager.release(sitesDir); 48 } 49 } 50 catch (IOException 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 |