Search in sources :

Example 6 with DataException

use of com.ramussoft.report.data.DataException in project ramus by Vitaliy-Yakovchuk.

the class ReportEditorView method getHTMLText.

protected String getHTMLText() {
    String page;
    try {
        HashMap<String, Object> map = new HashMap<String, Object>();
        Query query = queryView.getQuery();
        if (query != null)
            map.put("query", query);
        page = ((ReportQuery) framework.getEngine()).getHTMLReport(element, map);
    } catch (Exception e1) {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        PrintStream s = new PrintStream(stream);
        e1.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 {
            e1.printStackTrace(s);
        }
        s.flush();
        page = new String(stream.toByteArray());
    }
    return page;
}
Also used : PrintStream(java.io.PrintStream) DataException(com.ramussoft.report.data.DataException) ReportQuery(com.ramussoft.report.ReportQuery) Query(com.ramussoft.report.Query) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MessageFormatter(com.ramussoft.report.data.MessageFormatter) DataException(com.ramussoft.report.data.DataException) PrinterException(java.awt.print.PrinterException)

Example 7 with DataException

use of com.ramussoft.report.data.DataException in project ramus by Vitaliy-Yakovchuk.

the class ReportQueryImpl method getXMLReportAttribute.

private String getXMLReportAttribute(String attributeName, Element element) {
    try {
        final SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser parser;
        final Hashtable<String, String> attrs = new Hashtable<String, String>();
        parser = factory.newSAXParser();
        byte[] bs = engine.getStream(getXMLReportPath(element));
        if ((bs == null) || (bs.length == 0))
            return null;
        parser.parse(new ByteArrayInputStream(bs), new DefaultHandler() {

            private StringBuffer sb = new StringBuffer();

            private String attribute;

            @Override
            public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
                if (qName.equals("attribute")) {
                    attribute = attributes.getValue("name");
                }
                sb = new StringBuffer();
            }

            @Override
            public void endElement(String uri, String localName, String qName) throws SAXException {
                if (qName.equals("attribute")) {
                    attrs.put(attribute, sb.toString());
                }
            }

            @Override
            public void characters(char[] ch, int start, int length) throws SAXException {
                sb.append(ch, start, length);
            }
        });
        return attrs.get(attributeName);
    } catch (ParserConfigurationException e) {
        throw new DataException(e);
    } catch (SAXException e) {
        throw new DataException(e);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Hashtable(java.util.Hashtable) Attributes(org.xml.sax.Attributes) IOException(java.io.IOException) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException) DataException(com.ramussoft.report.data.DataException) ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

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