1 23 package org.infoglue.cms.applications.workflowtool.function; 24 25 import java.util.Collection ; 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.util.Map ; 29 30 import org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController; 31 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController; 32 import org.infoglue.cms.entities.management.ContentTypeAttribute; 33 import org.infoglue.cms.entities.management.ContentTypeDefinition; 34 35 import com.opensymphony.workflow.WorkflowException; 36 37 40 public class ContentPropertysetPopulator extends ContentFunction 41 { 42 45 private final String PROPERTYSET_PREFIX_ARGUMENT = "propertysetPrefix"; 46 47 50 private final String ATTRIBUTE_PREFIX_ARGUMENT = "attributePrefix"; 51 52 55 private String propertysetPrefix; 56 57 60 private String attributePrefix; 61 62 65 public ContentPropertysetPopulator() 66 { 67 super(); 68 } 69 70 73 protected void execute() throws WorkflowException 74 { 75 final Map attributeValues = getAttributeValues(); 76 for(final Iterator i = attributeValues.keySet().iterator(); i.hasNext(); ) 77 { 78 final String name = i.next().toString(); 79 final String value = (String ) attributeValues.get(name); 80 if(name.startsWith(attributePrefix)) 81 { 82 setPropertySetDataString(propertysetPrefix + name, value); 83 } 84 } 85 } 86 87 90 protected final Map getAttributeValues() throws WorkflowException 91 { 92 final Map values = new HashMap (); 93 if(getContentVO() != null && getContentVersionVO() != null) 94 { 95 try 96 { 97 final ContentTypeDefinitionController ctdController = ContentTypeDefinitionController.getController(); 98 final ContentTypeDefinition ctd = ctdController.getContentTypeDefinitionWithId(getContentVO().getContentTypeDefinitionId(), getDatabase()); 99 final Collection contentTypeAttributes = ctdController.getContentTypeAttributes(ctd.getSchemaValue()); 100 for(final Iterator i=contentTypeAttributes.iterator(); i.hasNext(); ) 101 { 102 final ContentTypeAttribute attribute = (ContentTypeAttribute) i.next(); 103 values.put(attribute.getName(), ContentVersionController.getContentVersionController().getAttributeValue(getContentVersionVO(), attribute.getName(), false)); 104 } 105 } 106 catch(Exception e) 107 { 108 throwException(e); 109 } 110 } 111 return values; 112 } 113 114 120 protected void initialize() throws WorkflowException 121 { 122 super.initialize(); 123 this.propertysetPrefix = getArgument(PROPERTYSET_PREFIX_ARGUMENT, ""); 124 this.attributePrefix = getArgument(ATTRIBUTE_PREFIX_ARGUMENT, ""); 125 } 126 } 127 | Popular Tags |