1 23 package org.infoglue.cms.applications.workflowtool.function; 24 25 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController; 26 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController; 27 import org.infoglue.cms.entities.content.Content; 28 import org.infoglue.cms.entities.content.ContentVO; 29 import org.infoglue.cms.entities.content.ContentVersion; 30 import org.infoglue.cms.entities.content.ContentVersionVO; 31 32 import com.opensymphony.workflow.WorkflowException; 33 34 37 public abstract class ContentFunction extends InfoglueFunction 38 { 39 42 public static final String CONTENT_PARAMETER = "content"; 43 44 47 public static final String CONTENT_VERSION_PARAMETER = "contentVersion"; 48 49 52 private static final String CONTENT_PARAMETER_NAME_ARGUMENT = "contentParameterName"; 53 54 57 private static final String CONTENT_VERSION_PARAMETER_NAME_ARGUMENT = "contentVersionParameterName"; 58 59 62 private Content content; 63 64 67 private ContentVO contentVO; 68 69 72 private ContentVersion contentVersion; 73 74 77 private ContentVersionVO contentVersionVO; 78 79 82 protected ContentFunction() 83 { 84 super(); 85 } 86 87 90 protected ContentVO getContentVO() 91 { 92 return contentVO; 93 } 94 95 98 protected ContentVersionVO getContentVersionVO() 99 { 100 return contentVersionVO; 101 } 102 103 106 protected Content getContent() 107 { 108 if(contentVO != null && content == null) 109 { 110 try 111 { 112 content = ContentController.getContentController().getContentWithId(contentVO.getContentId(), getDatabase()); 113 } 114 catch(Exception e) 115 { 116 } 118 } 119 return content; 120 } 121 122 125 protected ContentVersion getContentVersion() 126 { 127 if(contentVersionVO != null && contentVersion == null) 128 { 129 try 130 { 131 contentVersion = ContentVersionController.getContentVersionController().getContentVersionWithId(contentVersionVO.getContentVersionId(), getDatabase()); 132 } 133 catch(Exception e) 134 { 135 } 137 } 138 return contentVersion; 139 } 140 141 144 protected String getAttribute(final String name, final boolean escapeHTML) throws WorkflowException 145 { 146 if(contentVersionVO == null) 147 { 148 throwException("No content version."); 149 } 150 String value = ""; 151 try 152 { 153 value = ContentVersionController.getContentVersionController().getAttributeValue(contentVersionVO, name, escapeHTML); 154 } 155 catch(Exception e) 156 { 157 throwException(e); 158 } 159 return value; 160 } 161 162 168 protected void initialize() throws WorkflowException 169 { 170 super.initialize(); 171 contentVO = (ContentVO) getParameter(getArgument(CONTENT_PARAMETER_NAME_ARGUMENT, CONTENT_PARAMETER), false); 172 contentVersionVO = (ContentVersionVO) getParameter(getArgument(CONTENT_VERSION_PARAMETER_NAME_ARGUMENT, CONTENT_VERSION_PARAMETER), false); 173 } 174 } 175 | Popular Tags |