1 23 package org.infoglue.cms.applications.workflowtool.function; 24 25 import java.io.File ; 26 27 import org.apache.log4j.Logger; 28 import org.infoglue.cms.io.FileHelper; 29 import org.infoglue.cms.util.CmsPropertyHandler; 30 31 import com.opensymphony.workflow.WorkflowException; 32 33 57 public class FilePopulator extends InfoglueFunction 58 { 59 private final static Logger logger = Logger.getLogger(FilePopulator.class.getName()); 60 61 64 private static final String PATH_ARGUMENT = "path"; 65 66 69 private static final String PROPERTYSET_KEY_ARGUMENT = "key"; 70 71 74 private String path; 75 76 79 private String key; 80 81 84 public FilePopulator() 85 { 86 super(); 87 } 88 89 94 protected void execute() throws WorkflowException 95 { 96 try 97 { 98 final String fullPath = getFullPath(); 99 final String unparsed = FileHelper.getFileAsString(new File (fullPath)); 100 final String parsed = translate(unparsed); 101 102 logger.debug("path=[" + fullPath + "],unparsed=[" + unparsed + "],parsed=[" + parsed + "]"); 103 setPropertySetDataString(key, parsed); 104 } 105 catch(Exception e) 106 { 107 throwException(e); 108 } 109 } 110 111 116 private String getFullPath() 117 { 118 return CmsPropertyHandler.getContextRootPath() + path; 119 } 120 121 127 protected void initialize() throws WorkflowException 128 { 129 super.initialize(); 130 this.path = getArgument(PATH_ARGUMENT); 131 this.key = getArgument(PROPERTYSET_KEY_ARGUMENT); 132 } 133 } 134 | Popular Tags |