1 package nl.hippo.cms.workflows.reviewedactions; 2 3 import com.opensymphony.module.propertyset.PropertySet; 4 import com.opensymphony.workflow.WorkflowException; 5 import java.io.IOException ; 6 import java.text.DateFormat ; 7 import java.text.SimpleDateFormat ; 8 import java.util.Date ; 9 import java.util.HashSet ; 10 import java.util.Map ; 11 import java.util.Set ; 12 import nl.hippo.cms.Constants; 13 import nl.hippo.cms.workflows.shared.DateUtil; 14 import nl.hippo.cms.workflows.shared.FunctionProviderComponent; 15 import nl.hippo.cms.workflows.shared.WorkflowExtensionUtil; 16 import nl.hippo.cocoon.webdav.Property; 17 import nl.hippo.cocoon.webdav.WebDAVHelper; 18 import org.apache.commons.httpclient.HttpState; 19 20 public class StorePublicationDatesFunction extends FunctionProviderComponent 21 { 22 23 public StorePublicationDatesFunction() 24 { 25 super(); 26 } 27 28 public void executeImpl(final Map transientVars, Map args, PropertySet ps) throws WorkflowException 29 { 30 try 31 { 32 String location = (String ) transientVars.get("location"); 33 HttpState httpState = (HttpState) transientVars.get("httpstate"); 34 Set propertiesToSet = new HashSet (); 35 Set propertiesToRemove = new HashSet (); 36 DateFormat df = new SimpleDateFormat ("yyyyMMddHHmm"); 37 String publicationDateMode = (String ) transientVars.get("publicationDateMode"); 38 Date publicationDate; 39 if (publicationDateMode.equals("now")) 40 { 41 publicationDate = DateUtil.createToday(); 42 } 43 else 44 { 45 publicationDate = WorkflowExtensionUtil.getDateAndTime(transientVars.get("publicationDate")); 46 } 47 propertiesToSet.add(new Property("H", Constants.CMS_1_0_NAMESPACE, Constants.PUBLICATION_DATE_PROPERTY_NAME, df.format(publicationDate))); 48 49 String unpublicationDateMode = (String ) transientVars.get("unpublicationDateMode"); 50 if (unpublicationDateMode.equals("never")) 51 { 52 propertiesToRemove.add(new Property("H", Constants.CMS_1_0_NAMESPACE, Constants.UNPUBLICATION_DATE_PROPERTY_NAME)); 53 } 54 else 55 { 56 Date unpublicationDate = WorkflowExtensionUtil.getDateAndTime(transientVars.get("unpublicationDate")); 57 propertiesToSet.add(new Property("H", Constants.CMS_1_0_NAMESPACE, Constants.UNPUBLICATION_DATE_PROPERTY_NAME, df.format(unpublicationDate))); 58 } 59 WebDAVHelper.proppatch(location, propertiesToSet, propertiesToRemove, httpState); 60 } 61 catch (IOException e) 62 { 63 throw new WorkflowException(e); 64 } 65 } 66 67 } | Popular Tags |