代码拉取完成,页面将自动刷新
package plugin.template;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.vfs.FileObject;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.row.RowDataUtil;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.row.ValueMetaInterface;
import org.pentaho.di.core.vfs.KettleVFS;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.BaseStep;
import org.pentaho.di.trans.step.StepDataInterface;
import org.pentaho.di.trans.step.StepInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInterface;
/**
* @Title: 步骤类
* @Package plugin.template
* @Description: TODO(用一句话描述该文件做什么)
* @author http://www.ahuoo.com
* @date 2010-8-8 下午05:10:26
* @version V1.0
*/
public class TemplateStep extends BaseStep implements StepInterface {
private TemplateStepData data;
private TemplateStepMeta meta;
private ArrayList<Map<String, Object>> rows = new ArrayList<Map<String, Object>>();
public TemplateStep(StepMeta s, StepDataInterface stepDataInterface, int c, TransMeta t, Trans dis) {
super(s, stepDataInterface, c, t, dis);
}
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
meta = (TemplateStepMeta) smi;
data = (TemplateStepData) sdi;
Object[] r = getRow(); // get row, blocks when needed!
if (r == null) // no more input to be expected...
{
setOutputDone();
return false;
}
if (first) {
first = false;
data.outputRowMeta = (RowMetaInterface) getInputRowMeta().clone();
meta.getFields(data.outputRowMeta, getStepname(), null, null, this);
logBasic("template step initialized successfully");
}
Map<String, Object> map = new HashMap<String, Object>();
for (int c = 0; c < data.outputRowMeta.size(); c++) {
ValueMetaInterface v = data.outputRowMeta.getValueMeta(c);
String show;
show = v.getString(r[c]);
map.put(v.getName(), show);
}
rows.add(map);
Object[] outputRow = RowDataUtil.addValueData(r, data.outputRowMeta.size() - 1, "dummy value");
putRow(data.outputRowMeta, outputRow); // copy row to possible alternate rowset(s)
if (checkFeedback(getLinesRead())) {
logBasic("Linenr " + getLinesRead()); // Some basic logging
}
return true;
}
public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
meta = (TemplateStepMeta) smi;
data = (TemplateStepData) sdi;
return super.init(smi, sdi);
}
public void dispose(StepMetaInterface smi, StepDataInterface sdi) {
meta = (TemplateStepMeta) smi;
data = (TemplateStepData) sdi;
try {
Map<String, Object> context = new HashMap<String, Object>();
context.put("rows",rows);
if(meta.isUseVariableSubstitution()){
//将kettle的变量加入模板变量中
context.putAll(getVariables());
}
//替换环境变量
String filename=environmentSubstitute(meta.getOutfilename());
FileObject file = KettleVFS.getFileObject(filename, getTransMeta());
if(meta.isSqlfromfile()){
VelocityUtils.mergeStrToFile(meta.getSql(), context, file.getURL().getFile(), false);
}else{
VelocityUtils.mergeToFile(meta.getSqlfilename(), context, file.getURL().getFile(), false);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.dispose(smi, sdi);
}
//
// Run is were the action happens!
// public void run() {
// logBasic("Starting to run...");
// try {
// System.out.println("haha");
// while (processRow(meta, data) && !isStopped())
// ;
// System.out.println(list);
// } catch (Exception e) {
// logError("Unexpected error : " + e.toString());
// logError(Const.getStackTracker(e));
// setErrors(1);
// stopAll();
// } finally {
// dispose(meta, data);
// logBasic("Finished, processing " + getLinesRead() + " rows");
// markStop();
// }
// System.out.println(list);
// }
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。