use of com.ramussoft.report.data.Data in project ramus by Vitaliy-Yakovchuk.
the class XMLReportEngine method execute.
@Override
public void execute(String path, OutputStream stream, Map<String, Object> parameters) throws IOException {
createOut(stream);
Query query = (Query) parameters.get("query");
this.data = new Data(engine, query);
try {
final SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser;
parser = factory.newSAXParser();
byte[] bs = engine.getStream(path);
if (bs == null)
throw new DataException("Error.reportEmpty", "Report's form is empty");
do {
try {
parser.parse(new ByteArrayInputStream(bs), new ReportHandler());
} catch (NoRowsException e) {
break;
}
if (null == data.getBaseRows())
break;
connectedLabels.clear();
if (data.isSameBaseQualifier())
break;
} while (data.getBaseRows().next() != null);
} catch (ParserConfigurationException e) {
throw new DataException(e);
} catch (SAXException e) {
throw new DataException(e);
}
if (out.checkError())
throw new IOException();
out.flush();
out.realWrite();
}
use of com.ramussoft.report.data.Data 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.Data 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