use of org.mvel2.templates.TemplateError in project drools by kiegroup.
the class AbstractModel method getMappedOutputPojo.
public Map.Entry<String, String> getMappedOutputPojo() {
Map<String, String> result = new HashMap<>();
if (!templateRegistry.contains(getOutputPojoTemplateName())) {
this.addOutputTemplateToRegistry(templateRegistry);
}
List<PMMLOutputField> dataFields = this.getOutputFields();
Map<String, Object> vars = new HashMap<>();
String className = this.getOutputPojoClassName();
vars.put("pmmlPackageName", PMML_JAVA_PACKAGE_NAME);
vars.put("className", className);
vars.put("imports", new ArrayList<>());
vars.put("dataFields", dataFields);
vars.put("modelName", this.getModelId());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
TemplateRuntime.execute(templateRegistry.getNamedTemplate(this.getOutputPojoTemplateName()), null, new MapVariableResolverFactory(vars), baos);
} catch (TemplateError te) {
return null;
} catch (TemplateRuntimeError tre) {
// need to figure out logging here
return null;
}
result.put(className, new String(baos.toByteArray()));
return result.entrySet().iterator().next();
}
use of org.mvel2.templates.TemplateError in project mvel by mikebrock.
the class CompiledIncludeNode method readInFile.
public static String readInFile(TemplateRuntime runtime, File file) {
try {
FileInputStream instream = new FileInputStream(file);
BufferedInputStream bufstream = new BufferedInputStream(instream);
runtime.getRelPath().push(file.getParent());
byte[] buf = new byte[10];
int read;
int i;
StringBuilder appender = new StringBuilder();
while ((read = bufstream.read(buf)) != -1) {
for (i = 0; i < read; i++) {
appender.append((char) buf[i]);
}
}
bufstream.close();
instream.close();
runtime.getRelPath().pop();
return appender.toString();
} catch (FileNotFoundException e) {
throw new TemplateError("cannot include template '" + file.getPath() + "': file not found.");
} catch (IOException e) {
throw new TemplateError("unknown I/O exception while including '" + file.getPath() + "' (stacktrace nested)", e);
}
}
use of org.mvel2.templates.TemplateError in project mvel by mikebrock.
the class IncludeNode method readInFile.
public static String readInFile(TemplateRuntime runtime, String fileName) {
File file = new File(String.valueOf(runtime.getRelPath().peek()) + "/" + fileName);
try {
FileInputStream instream = new FileInputStream(file);
BufferedInputStream bufstream = new BufferedInputStream(instream);
runtime.getRelPath().push(file.getParent());
byte[] buf = new byte[10];
int read;
int i;
StringBuilder appender = new StringBuilder();
while ((read = bufstream.read(buf)) != -1) {
for (i = 0; i < read; i++) {
appender.append((char) buf[i]);
}
}
bufstream.close();
instream.close();
runtime.getRelPath().pop();
return appender.toString();
} catch (FileNotFoundException e) {
throw new TemplateError("cannot include template '" + fileName + "': file not found.");
} catch (IOException e) {
throw new TemplateError("unknown I/O exception while including '" + fileName + "' (stacktrace nested)", e);
}
}
use of org.mvel2.templates.TemplateError in project mvel by mikebrock.
the class TemplateTools method readStream.
public static String readStream(InputStream instream) {
try {
byte[] buf = new byte[10];
StringBuilder appender = new StringBuilder();
int read;
while ((read = instream.read(buf)) != -1) {
for (int i = 0; i < read; i++) {
appender.append((char) buf[i]);
}
}
return appender.toString();
} catch (NullPointerException e) {
if (instream == null) {
throw new TemplateError("null input stream", e);
} else {
throw e;
}
} catch (IOException e) {
throw new TemplateError("unknown I/O exception while including (stacktrace nested)", e);
}
}
use of org.mvel2.templates.TemplateError in project mvel by mikebrock.
the class CompiledNamedIncludeNode method eval.
public Object eval(TemplateRuntime runtime, TemplateOutputStream appender, Object ctx, VariableResolverFactory factory) {
if (cPreExpression != null) {
MVEL.executeExpression(cPreExpression, ctx, factory);
}
if (next != null) {
String namedTemplate = MVEL.executeExpression(cIncludeExpression, ctx, factory, String.class);
CompiledTemplate ct = runtime.getNamedTemplateRegistry().getNamedTemplate(namedTemplate);
if (ct == null)
throw new TemplateError("named template does not exist: " + namedTemplate);
return next.eval(runtime, appender.append(String.valueOf(TemplateRuntime.execute(ct, ctx, factory, runtime.getNamedTemplateRegistry()))), ctx, factory);
// return next.eval(runtime,
// appender.append(String.valueOf(TemplateRuntime.execute(runtime.getNamedTemplateRegistry().getNamedTemplate(MVEL.executeExpression(cIncludeExpression, ctx, factory, String.class)), ctx, factory))), ctx, factory);
} else {
return appender.append(String.valueOf(TemplateRuntime.execute(runtime.getNamedTemplateRegistry().getNamedTemplate(MVEL.executeExpression(cIncludeExpression, ctx, factory, String.class)), ctx, factory, runtime.getNamedTemplateRegistry())));
}
}
Aggregations