use of com.ramussoft.report.data.DataException 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.DataException in project ramus by Vitaliy-Yakovchuk.
the class TablePrint method print.
@SuppressWarnings("unchecked")
@Override
public void print(Out out, Data data) {
if (!data.isPrintFor(attributes.get("printFor")))
return;
if (rows.next() != null) {
onNext();
String style = attributes.get("Style");
if (style == null)
style = "";
if (style.length() > 0)
style = " style=\"" + style + "\"";
String border;
if ((border = attributes.get("Border")) != null)
out.println("<table width =\"100%\" border=\"" + border + "\"" + style + ">");
else
out.println("<table width =\"100%\"" + style + ">");
out.println("<tr>");
for (ColumnHeader header : columnHeaders) {
header.print(out, data);
}
out.println("</tr>");
HashSet<TableRow> tableRows = new HashSet<TableRow>();
List<TableRow> tableRowsList = new ArrayList<TableRow>();
List<Index> orders = new ArrayList<Index>(columnHeaders.size());
int index = 0;
for (ColumnHeader header : columnHeaders) {
String order = header.attributes.get("ColumnOrderNumber");
if ((order != null) && (order.length() > 0)) {
try {
orders.add(new Index(index, Integer.parseInt(order)));
} catch (Exception e) {
throw new DataException("Error.wrongNumberFormatForOrderNumber", e.getLocalizedMessage(), order);
}
}
index++;
}
Collections.sort(orders);
int[] indexes = null;
if (orders.size() > 0) {
indexes = new int[orders.size()];
for (int i = 0; i < indexes.length; i++) indexes[i] = orders.get(i).index;
}
do {
List[] lists = new List[columnBodies.size()];
for (int i = 0; i < lists.length; i++) {
lists[i] = new ArrayList(4);
ColumnBody body = columnBodies.get(i);
body.setTablePrint(this);
body.print(lists[i], data);
}
TableRow holder = new TableRow(lists, indexes);
if (!tableRows.contains(holder)) {
tableRows.add(holder);
tableRowsList.add(holder);
}
} while (rows.next() != null);
TableRow[] tableRows2;
if (indexes != null) {
tableRows2 = new TableRow[tableRows.size()];
Iterator<TableRow> iterator = tableRows.iterator();
int j = 0;
while (iterator.hasNext()) {
tableRows2[j] = iterator.next();
j++;
}
Arrays.sort(tableRows2);
} else {
tableRows2 = tableRowsList.toArray(new TableRow[tableRowsList.size()]);
}
int number = 1;
for (TableRow tableRow : tableRows2) {
out.println("<tr>");
List[] lists = tableRow.lists;
for (int i = 0; i < lists.length; i++) {
out.print(columnBodies.get(i).getTdStartTag());
for (Object object : lists[i]) {
if (object instanceof SerialNumber)
((SerialNumber) object).setNumber(number);
out.print(object);
}
out.println("</td>");
}
out.println("</tr>");
number++;
}
out.println("</table>");
}
}
use of com.ramussoft.report.data.DataException in project ramus by Vitaliy-Yakovchuk.
the class TableBodyQuery method print.
@Override
public void print(List<Object> buffer, Data data) {
String tableQuary = tablePrint.getQuery();
String[] words = query.split("\\.");
String[] tableWords = tableQuary.split("\\.");
int i = 0;
while (words[i].equals(tableWords[i])) {
if (i + 1 >= tableWords.length) {
i++;
break;
}
if (i + 2 >= words.length) {
i++;
break;
}
i++;
}
if (i == 0) {
String name1 = "Unknown";
String name2 = "Unknown";
if (words.length > 0)
name2 = words[0];
if (tableWords.length > 0)
name1 = tableWords[0];
throw new DataException("Error.differentBaseQualifiers", "Report contains diffetents base qualifiers in queries", name1, name2);
}
Rows rows = tablePrint.getRows();
int diff = tableWords.length - i;
while (diff > 0) {
diff--;
rows = rows.getParent();
}
if (rows == null)
rows = data.getBaseRows();
if (i + 1 < words.length) {
StringBuffer sb = new StringBuffer();
boolean first = true;
for (int j = i; j < words.length - 1; j++) {
if (first)
first = false;
else
sb.append('.');
sb.append(words[j]);
}
rows = data.getRowsByQuery(rows.getCurrent(), sb.toString());
first = true;
List<Row> list = new ArrayList<Row>();
Row row;
while ((row = rows.next()) != null) {
if (list.indexOf(row) < 0)
list.add(row);
else
continue;
if (first)
first = false;
else
buffer.add("; ");
buffer.add(rows.getAttribute(words[words.length - 1]));
}
} else {
buffer.add(rows.getAttribute(words[words.length - 1]));
}
}
use of com.ramussoft.report.data.DataException 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.DataException in project ramus by Vitaliy-Yakovchuk.
the class FastIdef0Connection method getConnected.
@Override
public Rows getConnected(Data data, Row row) {
branchId = data.getBranchId();
String modelName = data.getQuery().getAttribute("ReportFunction");
if (modelName == null)
throw new DataException("Error.noModelProperty", "Set model attribute for report first!!!");
List<Qualifier> models = getQualifiers(data, modelName);
Rows res = null;
for (Qualifier model : models) {
Key key = new Key(all, model);
IDEF0Buffer[] buffer = getIDEF0Buffers(key, data);
Rows rows;
if (row.getElement().getQualifierId() == model.getId()) {
rows = buffer[type].getStreams(row);
} else {
rows = buffer[type].getFunctions(row);
}
if (res == null)
res = rows;
else
res.addAll(rows);
}
if (res == null)
throw new DataException("Error.noModelProperty", "Set model attribute for report first!!!");
return res;
}
Aggregations