1 23 package org.infoglue.cms.applications.workflowtool.function; 24 25 import java.util.Iterator ; 26 import java.util.List ; 27 28 import org.apache.log4j.Logger; 29 import org.infoglue.cms.applications.workflowtool.util.ContentValues; 30 import org.infoglue.cms.applications.workflowtool.util.ContentVersionValues; 31 import org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController; 32 import org.infoglue.cms.entities.management.ContentTypeAttribute; 33 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO; 34 35 import com.opensymphony.workflow.WorkflowException; 36 37 40 public class ContentPopulator extends InfoglueFunction 41 { 42 private final static Logger logger = Logger.getLogger(ContentPopulator.class.getName()); 43 44 47 public static final String CONTENT_PROPERTYSET_PREFIX = "content_"; 48 49 52 public static final String CONTENT_VERSION_PROPERTYSET_PREFIX = "contentversion_"; 53 54 57 public static final String CONTENT_VALUES_PARAMETER = "contentValues"; 58 59 62 public static final String CONTENT_VERSION_VALUES_PARAMETER = "contentVersionValues"; 63 64 67 private ContentTypeDefinitionVO contentTypeDefinitionVO; 68 69 70 71 74 protected void execute() throws WorkflowException 75 { 76 populateContentValues(); 77 populateContentVersionValues(); 78 } 79 80 83 protected void initialize() throws WorkflowException 84 { 85 super.initialize(); 86 contentTypeDefinitionVO = (ContentTypeDefinitionVO) getParameter(ContentTypeDefinitionProvider.CONTENT_TYPE_DEFINITION_PARAMETER); 87 } 88 89 92 protected void populateContentValues() throws WorkflowException 93 { 94 final ContentValues result = new ContentValues(); 95 96 result.setName(populate(CONTENT_PROPERTYSET_PREFIX + ContentValues.NAME)); 97 result.setPublishDateTime(populate(CONTENT_PROPERTYSET_PREFIX + ContentValues.PUBLISH_DATE_TIME)); 98 result.setExpireDateTime(populate(CONTENT_PROPERTYSET_PREFIX + ContentValues.EXPIRE_DATE_TIME)); 99 100 setParameter(CONTENT_VALUES_PARAMETER, result); 101 } 102 103 106 protected void populateContentVersionValues() throws WorkflowException 107 { 108 final ContentVersionValues result = new ContentVersionValues(); 109 final List contentTypeAttributes = getContentTypeAttributes(); 110 for(Iterator i=contentTypeAttributes.iterator(); i.hasNext(); ) 111 { 112 final ContentTypeAttribute attribute = (ContentTypeAttribute) i.next(); 113 result.set(attribute.getName(), populate(CONTENT_VERSION_PROPERTYSET_PREFIX + attribute.getName())); 114 } 115 setParameter(CONTENT_VERSION_VALUES_PARAMETER, result); 116 } 117 118 121 private String populate(final String name) throws WorkflowException 122 { 123 if(parameterExists(name)) 124 { 125 setPropertySetDataString(name, getRequestParameter(name)); 126 logger.debug(name + " is found in the request; propertyset updated."); 127 } 128 else 129 { 130 logger.debug(name + " is not found in the request; propertyset not updated."); 131 } 132 return propertySetContains(name) ? getPropertySetDataString(name) : ""; 133 } 134 137 private List getContentTypeAttributes() 138 { 139 return ContentTypeDefinitionController.getController().getContentTypeAttributes(contentTypeDefinitionVO.getSchemaValue()); 140 } 141 } 142 | Popular Tags |