Package net.sf.jasperreports.engine

Examples of net.sf.jasperreports.engine.JRException


          {
            destFile = new File(fileName);
          }
          else
          {
            throw new JRException("No output specified for the exporter.");
          }
        }

        try
        {
          os = new FileOutputStream(destFile);
          exportReportToStream(os);
          os.flush();
        }
        catch (IOException e)
        {
          throw new JRException("Error trying to export to file : " + destFile, e);
        }
        finally
        {
          if (os != null)
          {
View Full Code Here


          for(pageIndex = startPageIndex; pageIndex <= endPageIndex; pageIndex++)
          {
            if (Thread.interrupted())
            {
              throw new JRException("Current thread interrupted.");
            }

            JRPrintPage page = (JRPrintPage)pages.get(pageIndex);

            createSheet(getSheetName(null));

            // we need to count all sheets generated for all exported documents
            sheetIndex++;
            sheetNamesIndex++;

            /*   */
            exportPage(page, /*xCuts*/null, /*startRow*/0);
          }
        }
        else
        {
          // Create the sheet before looping.
          createSheet(getSheetName(jasperPrint.getName()));

          // we need to count all sheets generated for all exported documents
          sheetIndex++;
          sheetNamesIndex++;

          /*
           * Make a pass and calculate the X cuts for all pages on this sheet.
           * The Y cuts can be calculated as each page is exported.
           */
          CutsInfo xCuts =
            JRGridLayout.calculateXCuts(
              getNature(), pages, startPageIndex, endPageIndex,
              jasperPrint.getPageWidth(), globalOffsetX
              );
          //clear the filter's internal cache that might have built up
          if (filter instanceof ResetableExporterFilter)
          {
            ((ResetableExporterFilter)filter).reset();
          }
          int startRow = 0;

          for(pageIndex = startPageIndex; pageIndex <= endPageIndex; pageIndex++)
          {
            if (Thread.interrupted())
            {
              throw new JRException("Current thread interrupted.");
            }
            JRPrintPage page = (JRPrintPage)pages.get(pageIndex);
            startRow = exportPage(page, xCuts, startRow);
          }
         
View Full Code Here

      }
      else
      {
//        if (log.isWarnEnabled())
//          log.warn("The subreport is placed on a non-splitting band, but it does not have a rewindable data source.");
        throw new JRException("The subreport is placed on a non-splitting band, but it does not have a rewindable data source.");
      }
    }
  }
View Full Code Here

        JRSubreportReturnValue returnValue = returnValues[i];
        String subreportVariableName = returnValue.getSubreportVariable();
        JRVariable subrepVariable = subreportFiller.getVariable(subreportVariableName);
        if (subrepVariable == null)
        {
          throw new JRException("Subreport variable " + subreportVariableName + " not found.");
        }
       
        JRVariable variable = filler.getVariable(returnValue.getToVariable());
        if (
          returnValue.getCalculationValue() == CalculationEnum.COUNT
          || returnValue.getCalculationValue() == CalculationEnum.DISTINCT_COUNT
          )
        {
          if (!Number.class.isAssignableFrom(variable.getValueClass()))
          {
            throw new JRException("Variable " + returnValue.getToVariable() +
                " must have a numeric type.");
          }
        }
        else if (!variable.getValueClass().isAssignableFrom(subrepVariable.getValueClass()) &&
            !(Number.class.isAssignableFrom(variable.getValueClass()) && Number.class.isAssignableFrom(subrepVariable.getValueClass())))
        {
          throw new JRException("Variable " + returnValue.getToVariable() +
              " is not assignable from subreport variable " +
              subreportVariableName);
        }
      }
    }
View Full Code Here

  protected static JRSubreportRunnerFactory getRunnerFactory() throws JRException
  {
    String factoryClassName = JRProperties.getProperty(JRSubreportRunnerFactory.SUBREPORT_RUNNER_FACTORY);
    if (factoryClassName == null)
    {
      throw new JRException("Property \"" + JRSubreportRunnerFactory.SUBREPORT_RUNNER_FACTORY + "\" must be set");
    }
    return (JRSubreportRunnerFactory) runnerFactoryCache.getCachedInstance(factoryClassName);
  }
View Full Code Here

    {
      success = ImageIO.write(bi, formatName, baos);
    }
    catch (IOException e)
    {
      throw new JRException(e);
    }
   
    if (!success)
    {
      throw new JRException("No appropriate image writer found for the \"" + formatName + "\" format.");
    }
   
    return baos.toByteArray();
  }
View Full Code Here

      if (zoomRatio != null)
      {
        zoom = zoomRatio.floatValue();
        if (zoom <= 0)
        {
          throw new JRException("Invalid zoom ratio : " + zoom);
        }
      }
      else
      {
        zoom = DEFAULT_ZOOM;
      }
 
      isUsingImagesToAlign =
        getBooleanParameter(
          JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN,
          JRHtmlExporterParameter.PROPERTY_USING_IMAGES_TO_ALIGN,
          true
          );
   
      if (isUsingImagesToAlign)
      {
        emptyCellStringProvider =
          new StringProvider()
          {
            public String getStringForCollapsedTD(Object value, int width, int height)
            {
              return "><img alt=\"\" src=\"" + value + "px\" style=\"width: " + toSizeUnit(width) + "; height: " + toSizeUnit(height) + ";\"/>";
            }
            public String getStringForEmptyTD(Object value)
            {
              return "<img alt=\"\" src=\"" + value + "px\" border=\"0\"/>";
            }
           
            public String getReportTableStyle()
            {
              return null;
            }
          };

        loadPxImage();
      }
      else
      {
        emptyCellStringProvider =
          new StringProvider()
          {
            public String getStringForCollapsedTD(Object value, int width, int height)
            {
              return " style=\"width: " + toSizeUnit(width) + "; height: " + toSizeUnit(height) + ";\">";
            }
            public String getStringForEmptyTD(Object value)
            {
              return "";
            }
           
            public String getReportTableStyle()
            {
              // required for lines and rectangles, but doesn't work in IE
              // border-collapse: collapse seems to take care of this though
              return "empty-cells: show";
            }
          };
      }
     
      isIgnorePageMargins =
        getBooleanParameter(
          JRExporterParameter.IGNORE_PAGE_MARGINS,
          JRExporterParameter.PROPERTY_IGNORE_PAGE_MARGINS,
          false
          );
     
      accessibleHtml =
        JRProperties.getBooleanProperty(
          jasperPrint,
          PROPERTY_ACCESSIBLE,
          false
          );
     
      fontMap = (Map) parameters.get(JRExporterParameter.FONT_MAP);
           
      setHyperlinkProducerFactory();

      //FIXMENOW check all exporter properties that are supposed to work at report level
      boolean deepGrid =
        !getBooleanParameter(
          JRHtmlExporterParameter.FRAMES_AS_NESTED_TABLES,
          JRHtmlExporterParameter.PROPERTY_FRAMES_AS_NESTED_TABLES,
          true
          );
     
      nature = new JRHtmlExporterNature(filter, deepGrid, isIgnorePageMargins);
 
      flushOutput = getBooleanParameter(JRHtmlExporterParameter.FLUSH_OUTPUT,
          JRHtmlExporterParameter.PROPERTY_FLUSH_OUTPUT,
          true);
     
      StringBuffer sb = (StringBuffer)parameters.get(JRExporterParameter.OUTPUT_STRING_BUFFER);
      if (sb != null)
      {
        try
        {
          writer = new StringWriter();
          exportReportToWriter();
          sb.append(writer.toString());
        }
        catch (IOException e)
        {
          throw new JRException("Error writing to StringBuffer writer : " + jasperPrint.getName(), e);
        }
        finally
        {
          if (writer != null)
          {
            try
            {
              writer.close();
            }
            catch(IOException e)
            {
            }
          }
        }
      }
      else
      {
        writer = (Writer)parameters.get(JRExporterParameter.OUTPUT_WRITER);
        if (writer != null)
        {
          try
          {
            exportReportToWriter();
          }
          catch (IOException e)
          {
            throw new JRException("Error writing to writer : " + jasperPrint.getName(), e);
          }
        }
        else
        {
          OutputStream os = (OutputStream)parameters.get(JRExporterParameter.OUTPUT_STREAM);
          if (os != null)
          {
            try
            {
              writer = new OutputStreamWriter(os, encoding);
              exportReportToWriter();
            }
            catch (IOException e)
            {
              throw new JRException("Error writing to OutputStream writer : " + jasperPrint.getName(), e);
            }
          }
          else
          {
            File destFile = (File)parameters.get(JRExporterParameter.OUTPUT_FILE);
            if (destFile == null)
            {
              String fileName = (String)parameters.get(JRExporterParameter.OUTPUT_FILE_NAME);
              if (fileName != null)
              {
                destFile = new File(fileName);
              }
              else
              {
                throw new JRException("No output specified for the exporter.");
              }
            }
 
            try
            {
              os = new FileOutputStream(destFile);
              writer = new OutputStreamWriter(os, encoding);
            }
            catch (IOException e)
            {
              throw new JRException("Error creating to file writer : " + jasperPrint.getName(), e);
            }
 
            if (imagesDir == null)
            {
              imagesDir = new File(destFile.getParent(), destFile.getName() + "_files");
            }
 
            if (isOutputImagesToDirParameter == null)
            {
              isOutputImagesToDir = true;
            }
 
            if (imagesURI == null)
            {
              imagesURI = imagesDir.getName() + "/";
            }
 
            try
            {
              exportReportToWriter();
            }
            catch (IOException e)
            {
              throw new JRException("Error writing to file writer : " + jasperPrint.getName(), e);
            }
            finally
            {
              if (writer != null)
              {
                try
                {
                  writer.close();
                }
                catch(IOException e)
                {
                }
              }
            }
          }
        }
      }
 
      if (isOutputImagesToDir)
      {
        if (imagesDir == null)
        {
          throw new JRException("The images directory was not specified for the exporter.");
        }
 
        if (isPxImageLoaded || (imagesToProcess != null && imagesToProcess.size() > 0))
        {
          if (!imagesDir.exists())
          {
            imagesDir.mkdir();
          }
 
          if (isPxImageLoaded)
          {
            JRRenderable pxRenderer =
              JRImageRenderer.getInstance("net/sf/jasperreports/engine/images/pixel.GIF");
            byte[] imageData = pxRenderer.getImageData();
 
            File imageFile = new File(imagesDir, "px");
            FileOutputStream fos = null;
 
            try
            {
              fos = new FileOutputStream(imageFile);
              fos.write(imageData, 0, imageData.length);
            }
            catch (IOException e)
            {
              throw new JRException("Error writing to image file : " + imageFile, e);
            }
            finally
            {
              if (fos != null)
              {
                try
                {
                  fos.close();
                }
                catch(IOException e)
                {
                }
              }
            }
          }
 
          for(Iterator it = imagesToProcess.iterator(); it.hasNext();)
          {
            JRPrintElementIndex imageIndex = (JRPrintElementIndex)it.next();
 
            JRPrintImage image = getImage(jasperPrintList, imageIndex);
            JRRenderable renderer = image.getRenderer();
            if (renderer.getType() == JRRenderable.TYPE_SVG)
            {
              renderer =
                new JRWrappingSvgRenderer(
                  renderer,
                  new Dimension(image.getWidth(), image.getHeight()),
                  ModeEnum.OPAQUE == image.getModeValue() ? image.getBackcolor() : null
                  );
            }
 
            byte[] imageData = renderer.getImageData();
 
            File imageFile = new File(imagesDir, getImageName(imageIndex));
            FileOutputStream fos = null;
 
            try
            {
              fos = new FileOutputStream(imageFile);
              fos.write(imageData, 0, imageData.length);
            }
            catch (IOException e)
            {
              throw new JRException("Error writing to image file : " + imageFile, e);
            }
            finally
            {
              if (fos != null)
              {
View Full Code Here

        JRPrintPage page = null;
        for(pageIndex = startPageIndex; pageIndex <= endPageIndex; pageIndex++)
        {
          if (Thread.interrupted())
          {
            throw new JRException("Current thread interrupted.");
          }

          page = (JRPrintPage)pages.get(pageIndex);

          writer.write("<a name=\"" + JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + (pageIndex + 1) + "\"></a>\n");
View Full Code Here

    try
    {
      Class clazz = JRClassLoader.loadClassForName(className);
      if (itf != null && !itf.isAssignableFrom(clazz))
      {
        throw new JRException("Class \"" + className + "\" should be compatible with \"" + itf.getName() + "\"");
      }

      return clazz.newInstance();
    }
    catch (ClassNotFoundException e)
    {
      throw new JRException("Class " + className + " not found.", e);
    }
    catch (InstantiationException e)
    {
      throw new JRException("Error instantiating class " + className + ".", e);
    }
    catch (IllegalAccessException e)
    {
      throw new JRException("Error instantiating class " + className + ".", e);
    }
  }
View Full Code Here

    boolean isReprintGroupHeaders
    ) throws JRException
  {
    if (isCreatingNewPage)
    {
      throw new JRException("Infinite loop creating new page.");
    }

    if (keepTogetherSavePoint != null)
    {
      keepTogetherSavePoint.saveEndOffsetY(offsetY);
View Full Code Here

TOP

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

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.