1 23 package org.infoglue.cms.applications.workflowtool.function; 24 25 import org.apache.log4j.Logger; 26 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController; 27 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController; 28 import org.infoglue.cms.entities.content.ContentVO; 29 import org.infoglue.cms.entities.content.ContentVersionVO; 30 import org.infoglue.cms.entities.management.LanguageVO; 31 32 import com.opensymphony.workflow.WorkflowException; 33 34 37 public class ContentProvider extends InfoglueFunction 38 { 39 private final static Logger logger = Logger.getLogger(ContentProvider.class.getName()); 40 41 44 public static final String CONTENT_ID_PROPERTYSET_KEY = ContentPopulator.CONTENT_PROPERTYSET_PREFIX + "contentID"; 45 46 49 private LanguageVO languageVO; 50 51 54 private ContentVO contentVO; 55 56 59 private ContentVersionVO contentVersionVO; 60 61 64 protected void execute() throws WorkflowException 65 { 66 initializeContentVO(); 67 initializeContentVersionVO(); 68 if(getContentParameterName() != null && getContentParameterName().length() > 0) 69 { 70 setParameter(getContentParameterName(), contentVO); 71 72 } 73 if(getContentVersionParameterName() != null && getContentVersionParameterName().length() > 0) 74 { 75 setParameter(getContentVersionParameterName(), contentVersionVO); 76 } 77 } 78 79 82 protected void setContentVO(final ContentVO contentVO) 83 { 84 this.contentVO = contentVO; 85 } 86 87 90 protected void setContentVersionVO(final ContentVersionVO contentVersionVO) 91 { 92 this.contentVersionVO = contentVersionVO; 93 } 94 95 98 protected final LanguageVO getLanguageVO() 99 { 100 return this.languageVO; 101 } 102 103 106 protected String getContentParameterName() 107 { 108 return ContentFunction.CONTENT_PARAMETER; 109 } 110 111 114 protected String getContentVersionParameterName() 115 { 116 return ContentFunction.CONTENT_VERSION_PARAMETER; 117 } 118 119 122 protected void initializeContentVO() throws WorkflowException 123 { 124 if(!propertySetContains(CONTENT_ID_PROPERTYSET_KEY)) 125 { 126 return; 127 } 128 try 129 { 130 final Integer contentID = new Integer (getPropertySetString(CONTENT_ID_PROPERTYSET_KEY)); 131 setContentVO(ContentController.getContentController().getContentVOWithId(contentID, getDatabase())); 132 } 133 catch(Exception e) 134 { 135 logger.warn("Non-existing contentId found; removing from the resultset."); 136 removeFromPropertySet(CONTENT_ID_PROPERTYSET_KEY); 137 } 138 } 139 140 143 protected void initializeContentVersionVO() throws WorkflowException 144 { 145 if(contentVO != null) 146 { 147 try 148 { 149 final ContentVersionController controller = ContentVersionController.getContentVersionController(); 150 setContentVersionVO(controller.getLatestActiveContentVersionVO(contentVO.getId(), languageVO.getId(), getDatabase())); 151 } 152 catch(Exception e) 153 { 154 throwException(e); 155 } 156 } 157 } 158 159 165 protected void initialize() throws WorkflowException 166 { 167 super.initialize(); 168 languageVO = (LanguageVO) getParameter(LanguageProvider.LANGUAGE_PARAMETER); 169 } 170 } 171 | Popular Tags |