Package net.sf.jasperreports.engine

Examples of net.sf.jasperreports.engine.JRRewindableDataSource


        return new Print(getLocalJasperReportsContext(config), print, values, maxDpi[0], maxDpi[1]);
    }

    private void checkRequiredFields(final Configuration configuration, final JRDataSource dataSource, final String reportTemplate) {
        if (dataSource instanceof JRRewindableDataSource) {
            JRRewindableDataSource source = (JRRewindableDataSource) dataSource;
            StringBuilder wrongType = new StringBuilder();
            try {
                while (source.next()) {
                    final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                    factory.setValidating(false);
                    final DocumentBuilder documentBuilder = factory.newDocumentBuilder();
                    final byte[] bytes = configuration.loadFile(reportTemplate);
                    final Document document = documentBuilder.parse(new ByteArrayInputStream(bytes));
                    final NodeList parameters = document.getElementsByTagName("field");
                    JRDesignField field = new JRDesignField();
                    for (int i = 0; i < parameters.getLength(); i++) {
                        final Element param = (Element) parameters.item(i);
                        final String name = param.getAttribute("name");
                        field.setName(name);
                        Object record = dataSource.getFieldValue(field);
                        if (record != null) {
                            final String type = param.getAttribute("class");
                            Class<?> clazz = Class.forName(type);

                            if (!clazz.isInstance(record)) {
                                wrongType.append("\t* ").append(name).append(" : ").append(record.getClass().getName());
                                wrongType.append(" expected type: ").append(type).append("\n");
                            } else {
                                LOGGER.warn("The field " + name + " in " + reportTemplate + " is not available in at least one of the " +
                                            "rows in the datasource.  This may not be an error.");
                            }
                        }
                    }
                }
                source.moveFirst();
            } catch (Throwable e) {
                throw ExceptionUtils.getRuntimeException(e);
            }

            StringBuilder finalError = new StringBuilder();
View Full Code Here

TOP

Related Classes of net.sf.jasperreports.engine.JRRewindableDataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.