use of org.pentaho.actionsequence.dom.actions.TemplateMsgAction in project pentaho-platform by pentaho.
the class TemplateComponent method executeAction.
@Override
protected boolean executeAction() {
try {
TemplateMsgAction actionDefinition = (TemplateMsgAction) getActionDefinition();
String template = null;
template = actionDefinition.getTemplate().getStringValue();
if ((null == template) && isDefinedResource(TemplateComponent.TEMPLATE)) {
// $NON-NLS-1$
IActionSequenceResource resource = getResource("template");
template = getResourceAsString(resource);
}
String outputName = (String) getOutputNames().iterator().next();
IActionParameter outputParam = getOutputItem(outputName);
if (outputParam.getType().equals(IActionParameter.TYPE_CONTENT)) {
String mimeType = actionDefinition.getMimeType().getStringValue();
String extension = actionDefinition.getExtension().getStringValue();
// This would prevent null values being passed as parameters to getOutputItem
if (mimeType == null) {
// $NON-NLS-1$
mimeType = "";
}
if (extension == null) {
// $NON-NLS-1$
extension = "";
}
// Removing the null check here because if we avoid null exception it gives misleading hibernate
// stale data exception which has nothing to do with a report that simply reads data.
IContentItem outputItem = getOutputContentItem(outputName, mimeType);
// IContentItem outputItem = getOutputItem(outputName, mimeType, extension);
OutputStream outputStream = outputItem.getOutputStream(getActionName());
outputStream.write(applyInputsToFormat(template).getBytes(LocaleHelper.getSystemEncoding()));
outputItem.closeOutputStream();
return true;
} else {
setOutputValue(outputName, applyInputsToFormat(template));
}
return true;
} catch (Exception e) {
// $NON-NLS-1$
error(Messages.getInstance().getString("Template.ERROR_0004_COULD_NOT_FORMAT_TEMPLATE"), e);
return false;
}
}
use of org.pentaho.actionsequence.dom.actions.TemplateMsgAction in project pentaho-platform by pentaho.
the class TemplateComponent method validateAction.
@Override
protected boolean validateAction() {
// see if we have a template defined
TemplateMsgAction actionDefinition = (TemplateMsgAction) getActionDefinition();
boolean templateOk = false;
if (null != actionDefinition.getTemplate()) {
templateOk = true;
} else if (isDefinedResource(TemplateComponent.TEMPLATE)) {
templateOk = true;
}
if (!templateOk) {
// $NON-NLS-1$
error(Messages.getInstance().getString("Template.ERROR_0001_TEMPLATE_NOT_DEFINED"));
return false;
}
Set outputs = getOutputNames();
if ((outputs == null) || (outputs.size() == 0) || (outputs.size() > 1)) {
// $NON-NLS-1$
error(Messages.getInstance().getString("Template.ERROR_0002_OUTPUT_COUNT_WRONG"));
return false;
}
return true;
}
Aggregations