use of com.ramussoft.report.data.Out in project ramus by Vitaliy-Yakovchuk.
the class HTTPParser method getReportHTMLText.
protected Source getReportHTMLText(Engine engine, Element report, Query query) {
String page = null;
try {
HashMap<String, Object> map = new HashMap<String, Object>();
ReportQuery impl;
if (dataPlugin.getEngine().getDeligate() instanceof IEngineImpl)
impl = new ReportQueryImpl(engine) {
@Override
protected Out createOut(OutputStream stream) {
try {
return new Out(stream) {
@Override
public void print(Object object) {
if (!printVersion) {
if (object instanceof Qualifier) {
Engine engine = dataPlugin.getEngine();
Element element = StandardAttributesPlugin.getElement(engine, ((Qualifier) object).getId());
if (element == null) {
print(object.toString());
} else {
String href = "rows/index.html?id=" + element.getId();
print(getStartATeg(href, false, true));
print(object.toString());
print(getEndATeg());
}
} else if (object instanceof Code) {
String href = "rows/index.html?id=" + ((Code) object).getElement().getId();
print(getStartATeg(href, false, true));
print(object.toString());
print(getEndATeg());
} else if (object instanceof com.ramussoft.database.common.Row) {
String href = "rows/index.html?id=" + ((com.ramussoft.database.common.Row) object).getElementId();
print(getStartATeg(href, false, true));
print(object.toString());
print(getEndATeg());
} else
super.print(object);
} else
super.print(object);
}
};
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
};
else
impl = (ReportQuery) dataPlugin.getEngine();
if (query != null)
map.put("query", query);
page = impl.getHTMLReport(report, map);
} catch (Exception e1) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
java.io.PrintStream s = null;
try {
s = new java.io.PrintStream(stream, true, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (e1 instanceof DataException)
s.println(((DataException) e1).getMessage(new MessageFormatter() {
@Override
public String getString(String key, Object[] arguments) {
return MessageFormat.format(ReportResourceManager.getString(key), arguments);
}
}));
else {
s.println("<pre>");
e1.printStackTrace(s);
s.println("</pre>");
}
s.flush();
try {
page = new String(stream.toByteArray(), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
htmlStream.println(page);
return null;
}
if (!printVersion) {
htmlStream.println("<H4>" + report.getName() + "</H4>");
}
Source source = new Source(page);
source.fullSequentialParse();
htmlStream.println(source);
return source;
}
use of com.ramussoft.report.data.Out in project ramus by Vitaliy-Yakovchuk.
the class JSSPDocBookReportEngine method execute.
@SuppressWarnings("deprecation")
public void execute(String scriptPath, OutputStream stream, Map<String, Object> parameters) throws IOException {
byte[] bytes = engine.getStream(scriptPath);
if (bytes == null)
bytes = new byte[] {};
String script = new String(bytes, "UTF-8");
JSSPToJsConverter converter = new JSSPToJsConverter(script);
final ScriptEngine engine = manager.getEngineByName("JavaScript");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Out out = createOut(outputStream);
try {
SimpleOut simpleOut = new SimpleOut(out);
engine.put("doc", simpleOut);
engine.put("document", simpleOut);
engine.put("out", simpleOut);
Query query = (Query) parameters.get("query");
engine.put("data", new Data(this.engine, query, reportQuery));
for (Entry<String, Object> entry : parameters.entrySet()) engine.put(entry.getKey(), entry.getValue());
final String convert = converter.convert();
final Object w = new Object();
final ExceptionHolder exceptionHolder = new ExceptionHolder();
Thread thread = new Thread() {
@Override
public void run() {
try {
engine.eval(convert);
} catch (ScriptException e) {
exceptionHolder.scriptException = e;
} catch (RuntimeException e) {
exceptionHolder.exception = e;
}
synchronized (w) {
exceptionHolder.finished = true;
w.notify();
}
}
};
thread.start();
try {
synchronized (w) {
if (Metadata.CORPORATE) {
if (!exceptionHolder.finished)
w.wait(300000);
} else {
if (!exceptionHolder.finished)
w.wait(50000);
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!exceptionHolder.finished) {
thread.stop();
throw new ScriptException(SCRIPT_WORKED_TOO_LONG);
}
if (exceptionHolder.scriptException != null) {
/*
* if(exceptionHolder.scriptException.getCause() instanceof
* Exception)
* ((Exception)exceptionHolder.scriptException.getCause
* ()).printStackTrace();
*/
throw exceptionHolder.scriptException;
}
if (exceptionHolder.exception != null)
throw exceptionHolder.exception;
out.flush();
out.realWrite(false);
stream.write(outputStream.toByteArray());
} catch (ScriptException e) {
e.printStackTrace();
out = new Out(stream);
String message = e.getLocalizedMessage();
String moz = "sun.org.mozilla.javascript.internal.EcmaError:";
if (message.startsWith(moz))
message = message.substring(moz.length() + 1);
Pattern pattern = Pattern.compile("(\\d+)");
Matcher matcher = pattern.matcher(message);
int minus = 5;
int plus = 5;
if (matcher.find()) {
String group = matcher.group();
while (matcher.find()) group = matcher.group();
int number = Integer.parseInt(group);
int from = 0;
if (number > minus)
from = number - minus;
BufferedReader br = new BufferedReader(new StringReader(script));
int i = 0;
while (i < from) {
try {
br.readLine();
} catch (IOException e1) {
e1.printStackTrace();
}
i++;
}
out.println("<html>");
out.println("<body>");
out.println(message);
out.println("<br><br><table width=\"100%\">");
i = from;
while (true) {
String line = null;
line = br.readLine();
if (line == null)
break;
if (i - plus >= number)
break;
out.println("<tr>");
out.println("<td width=\"1%\"><font color=green>" + (i + 1) + "</font></td>");
String string = line.replace("<", "<").replace(">", ">");
if (i + 1 == number)
string = "<font color=\"#FF0000\">" + string + "</font>";
out.println("<td width=\"99%\"><pre>" + string + "</pre></td>");
out.println("</tr>");
i++;
}
out.println("</table>");
out.println("</body>");
out.println("</html>");
} else {
out.println("<html>");
out.println("<body>");
out.println("<pre>");
if (e.getLocalizedMessage().equals(SCRIPT_WORKED_TOO_LONG))
out.print(e.getLocalizedMessage());
else
e.printStackTrace(out);
out.println("</pre>");
out.println("</body>");
out.println("</html>");
}
out.flush();
out.realWrite();
}
}
use of com.ramussoft.report.data.Out in project ramus by Vitaliy-Yakovchuk.
the class JSSPReportEngine method execute.
@SuppressWarnings("deprecation")
public void execute(String scriptPath, OutputStream stream, Map<String, Object> parameters) throws IOException {
byte[] bytes = engine.getStream(scriptPath);
if (bytes == null)
bytes = new byte[] {};
String script = new String(bytes, "UTF-8");
JSSPToJsConverter converter = new JSSPToJsConverter(script);
final ScriptEngine engine = manager.getEngineByName("JavaScript");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Out out = createOut(outputStream);
try {
SimpleOut simpleOut = new SimpleOut(out);
engine.put("doc", simpleOut);
engine.put("document", simpleOut);
engine.put("out", simpleOut);
Query query = (Query) parameters.get("query");
engine.put("data", new Data(this.engine, query, reportQuery));
for (Entry<String, Object> entry : parameters.entrySet()) engine.put(entry.getKey(), entry.getValue());
final String convert = converter.convert();
final Object w = new Object();
final ExceptionHolder exceptionHolder = new ExceptionHolder();
Thread thread = new Thread() {
@Override
public void run() {
try {
engine.eval(convert);
} catch (ScriptException e) {
exceptionHolder.scriptException = e;
} catch (RuntimeException e) {
exceptionHolder.exception = e;
}
synchronized (w) {
exceptionHolder.finished = true;
w.notify();
}
}
};
thread.start();
try {
synchronized (w) {
if (Metadata.CORPORATE) {
if (!exceptionHolder.finished)
w.wait(300000);
} else {
if (!exceptionHolder.finished)
w.wait(50000);
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!exceptionHolder.finished) {
thread.stop();
throw new ScriptException(SCRIPT_WORKED_TOO_LONG);
}
if (exceptionHolder.scriptException != null) {
/*
* if(exceptionHolder.scriptException.getCause() instanceof
* Exception)
* ((Exception)exceptionHolder.scriptException.getCause
* ()).printStackTrace();
*/
throw exceptionHolder.scriptException;
}
if (exceptionHolder.exception != null)
throw exceptionHolder.exception;
out.flush();
out.realWriteWithHTMLUpdate();
stream.write(outputStream.toByteArray());
} catch (ScriptException e) {
e.printStackTrace();
out = new Out(stream);
String message = e.getLocalizedMessage();
String moz = "sun.org.mozilla.javascript.internal.EcmaError:";
if (message.startsWith(moz))
message = message.substring(moz.length() + 1);
Pattern pattern = Pattern.compile("(\\d+)");
Matcher matcher = pattern.matcher(message);
int minus = 5;
int plus = 5;
if (matcher.find()) {
String group = matcher.group();
while (matcher.find()) group = matcher.group();
int number = Integer.parseInt(group);
int from = 0;
if (number > minus)
from = number - minus;
BufferedReader br = new BufferedReader(new StringReader(script));
int i = 0;
while (i < from) {
try {
br.readLine();
} catch (IOException e1) {
e1.printStackTrace();
}
i++;
}
out.println("<html>");
out.println("<body>");
out.println(message);
out.println("<br><br><table width=\"100%\">");
i = from;
while (true) {
String line = null;
line = br.readLine();
if (line == null)
break;
if (i - plus >= number)
break;
out.println("<tr>");
out.println("<td width=\"1%\"><font color=green>" + (i + 1) + "</font></td>");
String string = line.replace("<", "<").replace(">", ">");
if (i + 1 == number)
string = "<font color=\"#FF0000\">" + string + "</font>";
out.println("<td width=\"99%\"><pre>" + string + "</pre></td>");
out.println("</tr>");
i++;
}
out.println("</table>");
out.println("</body>");
out.println("</html>");
} else {
out.println("<html>");
out.println("<body>");
out.println("<pre>");
if (e.getLocalizedMessage().equals(SCRIPT_WORKED_TOO_LONG))
out.print(e.getLocalizedMessage());
else
e.printStackTrace(out);
out.println("</pre>");
out.println("</body>");
out.println("</html>");
}
out.flush();
out.realWrite();
}
}
Aggregations