Package net.sf.jasperreports.engine.design

Examples of net.sf.jasperreports.engine.design.JasperDesign


                is = new java.io.ByteArrayInputStream(templateContent);              
              }
            }
          }
         
          JasperDesign  jasperDesign = JRXmlLoader.load(is);
          //the following instruction is necessary because the above instruction cleans variable 'is'
          is = new java.io.ByteArrayInputStream(templateContent);
         
          files[i] = new File(destDir, jasperDesign.getName() + ".jasper");
          logger.debug("Compiling template file: " + files[i]);
 
          FileOutputStream fos =  null;
          try {
            fos = new FileOutputStream(files[i]);
View Full Code Here


            String type = req.getParameter(Constants.TYPE).trim().toLowerCase();
            String locale = req.getParameter("locale");
            setNoCache(res);
            if (isAuthorizedReport(req, reportName))
            {
                JasperDesign jasperDesign = JRXmlLoader.load(getServletConfig().getServletContext().getResourceAsStream(
                        "/WEB-INF/reports/"+reportName+".jrxml"));
                JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
                jasperReport.setWhenNoDataType(WhenNoDataTypeEnum.ALL_SECTIONS_NO_DETAIL);
                Map<String, Object> parameters = new HashMap<String, Object>();
                if (null != locale) parameters.put(JRParameter.REPORT_LOCALE, new Locale(locale));
View Full Code Here

      if (dr.getTemplateFileName() != null) {
        log.info("loading template file: "+dr.getTemplateFileName());
        log.info("Attemping to find the file directly in the file system...");
        File file = new File(dr.getTemplateFileName());
        if (file.exists()){
          JasperDesign jdesign = JRXmlLoader.load(file);
          jd = downCast(jdesign);
        } else {
          log.info("Not found: Attemping to find the file in the classpath...");
          URL url = DynamicJasperHelper.class.getClassLoader().getResource(
              dr.getTemplateFileName());
          JasperDesign jdesign = JRXmlLoader.load(url.openStream());
          jd = downCast(jdesign);
        }
        populateReportOptionsFromDesign(jd,dr);
       
      } else {
View Full Code Here

    public MapSubReport(final List<URI> layerGraphics, final Dimension mapSize, final double dpi) {
        this.reportDesign = createReport(layerGraphics, mapSize, dpi);
    }

    private JasperDesign createReport(final List<URI> layerGraphics, final Dimension mapSize, final double dpi) {
        final JasperDesign design = new JasperDesign();
        design.setName("map");

        // report size and margins
        design.setPageWidth(mapSize.width);
        design.setPageHeight(mapSize.height);
        design.setColumnWidth(mapSize.width);
        design.setColumnSpacing(0);
        design.setLeftMargin(0);
        design.setRightMargin(0);
        design.setTopMargin(0);
        design.setBottomMargin(0);
       
        JRDesignBand band = new JRDesignBand();
        band.setHeight(mapSize.height);

        // add layer graphics to report
        addLayers(layerGraphics, band, mapSize, design);
       
        // note that the images are added to the "NoData" band, this ensures
        // that they are displayed even if no data connection is passed to the
        // sub-report
        design.setNoData(band);
        design.setWhenNoDataType(WhenNoDataTypeEnum.NO_DATA_SECTION);
        design.setProperty(Renderable.PROPERTY_IMAGE_DPI, String.valueOf(Math.round(dpi)));
        return design;
    }
View Full Code Here

    private String generateSubReport(
            final Input input,
            final Map<String, Class<?>> columns) throws JRException, ClassNotFoundException, IOException {
        byte[] bytes = input.template.getConfiguration().loadFile(this.jasperTemplate);
        final JasperDesign templateDesign = JRXmlLoader.load(new ByteArrayInputStream(bytes));
        int headerHeight = templateDesign.getColumnHeader().getHeight();
        final JRDesignSection detailSection = (JRDesignSection) templateDesign.getDetailSection();
        int detailHeight = detailSection.getBands()[0].getHeight();

        final JRElement sampleHeaderEl = templateDesign.getColumnHeader().getElements()[0];
        int headerPosX = sampleHeaderEl.getX();
        int headerPosY = sampleHeaderEl.getY();
        final JRElement sampleDetailEl = detailSection.getBands()[0].getElements()[0];
        int detailPosX = sampleDetailEl.getX();
        int detailPosY = sampleDetailEl.getY();
        clearFields(templateDesign);
        removeDetailBand(templateDesign);
        JRDesignBand headerBand = new JRDesignBand();
        headerBand.setHeight(headerHeight);
        templateDesign.setColumnHeader(headerBand);

        JRDesignBand detailBand = new JRDesignBand();
        detailBand.setHeight(detailHeight);
        detailSection.addBand(detailBand);

        final int columnWidth;
        final int numColumns = columns.size();
        if (columns.isEmpty()) {
            columnWidth = templateDesign.getPageWidth();
        } else {
            columnWidth = (templateDesign.getPageWidth() - (SPACE_BETWEEN_COLS * (numColumns - 1))) / numColumns;
        }

        int i = 0;
        for (Map.Entry<String, Class<?>> entry : columns.entrySet()) {
            i++;

            JRStyle columnDetailStyle;
            JRStyle columnHeaderStyle;
            if (i == 1) {
                columnDetailStyle = getStyle(templateDesign, this.firstDetailStyle, this.detailStyle);
                columnHeaderStyle = getStyle(templateDesign, this.firstHeaderStyle, this.headerStyle);
            } else if (i == numColumns) {
                columnDetailStyle = getStyle(templateDesign, this.lastDetailStyle, this.detailStyle);
                columnHeaderStyle = getStyle(templateDesign, this.lastHeaderStyle, this.headerStyle);
            } else {
                columnDetailStyle = templateDesign.getStylesMap().get(this.detailStyle);
                columnHeaderStyle = templateDesign.getStylesMap().get(this.headerStyle);
            }
            String columnName = entry.getKey();
            Class<?> valueClass = String.class;
            if (entry.getValue() != null) {
                valueClass = entry.getValue();
            }
            // Create a Column Field
            JRDesignField field = new JRDesignField();
            field.setName(columnName);
            if (this.converters.isEmpty()) {
                // if there are no cell converters, the type for all cells in a column should be the same.
                // so we can set a specific type. otherwise we have to set a generic type (Object.class).
                field.setValueClass(valueClass);
            } else {
                field.setValueClass(Object.class);
            }
            templateDesign.addField(field);

            // Add a Header Field to the headerBand
            JRDesignTextField colHeaderField = new JRDesignTextField();
            colHeaderField.setX(headerPosX);
            colHeaderField.setY(headerPosY);
View Full Code Here

                        "'detailStyle' property must be declared if !tableProcessor is dynamic."));
        }

            try {
                byte[] bytes = configuration.loadFile(this.jasperTemplate);
                final JasperDesign templateDesign = JRXmlLoader.load(new ByteArrayInputStream(bytes));
                final Map<String, JRStyle> stylesMap = templateDesign.getStylesMap();
                if (templateDesign.getColumnHeader() == null) {
                    validationErrors.add(new ConfigurationException(
                            "JasperTemplate must have a column band defined for height and positioning information"));
                } else if (templateDesign.getColumnHeader().getElements().length == 0) {
                        validationErrors.add(new ConfigurationException(
                                "column header band must have at least one element defined for to height and positioning information"));
                }

                final JRDesignSection detailSection = (JRDesignSection) templateDesign.getDetailSection();
                if (detailSection.getBands().length == 0) {
                    validationErrors.add(new ConfigurationException(
                            "JasperTemplate must have a detail band defined for height and positioning information"));
                } else if (detailSection.getBands()[0].getElements().length == 0) {
                    validationErrors.add(new ConfigurationException(
View Full Code Here

                layer2Tiff.toURI(),
                layer3SVG.toURI());

        MapSubReport subReport = new MapSubReport(layerImages, new Dimension(400, 500), 72);

        JasperDesign report = subReport.getReportDesign();

        assertEquals(400, report.getPageWidth());
        assertEquals(500, report.getPageHeight());

        assertEquals(4, report.getNoData().getChildren().size());

        JRDesignImage image0 = (JRDesignImage) report.getNoData().getChildren().get(0);
        assertEquals(400, image0.getWidth());
        assertEquals(500, image0.getHeight());
        assertEquals('"' + layer0Tiff.getPath().replace('\\', '/') + '"', image0.getExpression().getText());

        JRDesignImage image3 = (JRDesignImage) report.getNoData().getChildren().get(3);
        assertEquals(400, image3.getWidth());
        assertEquals(500, image3.getHeight());
        assertEquals("net.sf.jasperreports.renderers.BatikRenderer.getInstance(new java.io.File(\"" + layer3SVG.getPath().replace('\\',
                        '/') + "\"))",
                image3.getExpression().getText());
View Full Code Here

        Connection connection;
        try {
            // - Connexion à la base
            connection = MySQLConnexion.getInstance();
            // - Chargement et compilation du rapport
            JasperDesign jasperDesign = JRXmlLoader.load(".\\allmatches.jrxml");
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
            // - Paramètres à envoyer au rapport
            Map parameters = new HashMap();
            parameters.put("Titre", "Titre");
            // - Execution du rapport
View Full Code Here

      if (dr.getTemplateFileName() != null) {
        log.info("loading template file: "+dr.getTemplateFileName());
        log.info("Attemping to find the file directly in the file system...");
        File file = new File(dr.getTemplateFileName());
        if (file.exists()){
          JasperDesign jdesign = JRXmlLoader.load(file);
          jd = downCast(jdesign);
        } else {
          log.info("Not found: Attemping to find the file in the classpath...");
          URL url = DynamicJasperHelper.class.getClassLoader().getResource(
              dr.getTemplateFileName());
          JasperDesign jdesign = JRXmlLoader.load(url.openStream());
          jd = downCast(jdesign);
        }
        populateReportOptionsFromDesign(jd,dr);
       
      } else {
View Full Code Here

          if (logger.isInfoEnabled()) {
            logger.info("Compiling Jasper Report loaded from " + resource);
          }
          InputStream is = resource.getInputStream();
          try {
            JasperDesign design = JRXmlLoader.load(is);
            return JasperCompileManager.compileReport(design);
          }
          finally {
            is.close();
          }
View Full Code Here

TOP

Related Classes of net.sf.jasperreports.engine.design.JasperDesign

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.