Search in sources :

Example 1 with DataException

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();
}
Also used : DataException(com.ramussoft.report.data.DataException) ByteArrayInputStream(java.io.ByteArrayInputStream) NoRowsException(com.ramussoft.report.xml.NoRowsException) SAXParser(javax.xml.parsers.SAXParser) Data(com.ramussoft.report.data.Data) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 2 with DataException

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>");
    }
}
Also used : ArrayList(java.util.ArrayList) DataException(com.ramussoft.report.data.DataException) DataException(com.ramussoft.report.data.DataException) SerialNumber(com.ramussoft.report.SerialNumber) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 3 with DataException

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]));
    }
}
Also used : DataException(com.ramussoft.report.data.DataException) ArrayList(java.util.ArrayList) Row(com.ramussoft.report.data.Row) Rows(com.ramussoft.report.data.Rows)

Example 4 with DataException

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;
}
Also used : HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Element(com.ramussoft.common.Element) MessageFormatter(com.ramussoft.report.data.MessageFormatter) Source(net.htmlparser.jericho.Source) Qualifier(com.ramussoft.common.Qualifier) IEngine(com.ramussoft.common.IEngine) Engine(com.ramussoft.common.Engine) ReportQuery(com.ramussoft.report.ReportQuery) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Code(com.ramussoft.report.Code) DataException(com.ramussoft.report.data.DataException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ReportQueryImpl(com.ramussoft.report.ReportQueryImpl) Out(com.ramussoft.report.data.Out) DataException(com.ramussoft.report.data.DataException) IEngineImpl(com.ramussoft.core.impl.IEngineImpl) Row(com.ramussoft.pb.Row) NRow(com.ramussoft.pb.data.negine.NRow)

Example 5 with DataException

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;
}
Also used : DataException(com.ramussoft.report.data.DataException) Qualifier(com.ramussoft.common.Qualifier) Rows(com.ramussoft.report.data.Rows)

Aggregations

DataException (com.ramussoft.report.data.DataException)7 IOException (java.io.IOException)3 Qualifier (com.ramussoft.common.Qualifier)2 ReportQuery (com.ramussoft.report.ReportQuery)2 MessageFormatter (com.ramussoft.report.data.MessageFormatter)2 Rows (com.ramussoft.report.data.Rows)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXParser (javax.xml.parsers.SAXParser)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 SAXException (org.xml.sax.SAXException)2 Element (com.ramussoft.common.Element)1 Engine (com.ramussoft.common.Engine)1 IEngine (com.ramussoft.common.IEngine)1 IEngineImpl (com.ramussoft.core.impl.IEngineImpl)1 Row (com.ramussoft.pb.Row)1 NRow (com.ramussoft.pb.data.negine.NRow)1