Package net.sf.jasperreports.engine

Examples of net.sf.jasperreports.engine.JRException


      if (zoomRatio != null)
      {
        zoom = zoomRatio.floatValue();
        if (zoom <= 0)
        {
          throw new JRException("Invalid zoom ratio : " + zoom);
        }
      }
      else
      {
        zoom = DEFAULT_ZOOM;
      }
 
      isIgnorePageMargins =
        getBooleanParameter(
          JRExporterParameter.IGNORE_PAGE_MARGINS,
          JRExporterParameter.PROPERTY_IGNORE_PAGE_MARGINS,
          false
          );
     
      fontMap = (Map) parameters.get(JRExporterParameter.FONT_MAP);
           
      setHyperlinkProducerFactory();
     
      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 (imagesToProcess != null && imagesToProcess.size() > 0)
        {
          if (!imagesDir.exists())
          {
            imagesDir.mkdir();
          }
 
          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

      setTextRenderer();
     
      grx = (Graphics2D)parameters.get(JRGraphics2DExporterParameter.GRAPHICS_2D);
      if (grx == null)
      {
        throw new JRException("No output specified for the exporter. java.awt.Graphics2D object expected.");
      }
     
      BorderOffset.setLegacy(
        JRProperties.getBooleanProperty(jasperPrint, BorderOffset.PROPERTY_LEGACY_BORDER_OFFSET, false)
        );

      /*   */
      setDrawers();

      Float zoomRatio = (Float)parameters.get(JRGraphics2DExporterParameter.ZOOM_RATIO);
      if (zoomRatio != null)
      {
        zoom = zoomRatio.floatValue();
        if (zoom <= 0)
        {
          throw new JRException("Invalid zoom ratio : " + zoom);
        }
      }
      else
      {
        zoom = DEFAULT_ZOOM;
View Full Code Here

   
    InputStream is = JRProperties.class.getResourceAsStream("/default.jasperreports.properties");
   
    if (is == null)
    {
      throw new JRException("Default properties file not found.");
    }

    try
    {
      defaults.load(is);
    }
    catch (IOException e)
    {
      throw new JRException("Failed to load default properties.", e);
    }
    finally
    {
      try
      {
View Full Code Here

      {
        properties.load(is);
      }
      catch (IOException e)
      {
        throw new JRException("Failed to load properties file \"" + name + "\"", e);
      }
      finally
      {
        try
        {
View Full Code Here

      tracker.waitForID(0);
    }
    catch (Exception e)
    {
      //image = null;
      throw new JRException(e);
    }

    if(tracker.isErrorID(0))
    {
      throw new JRException("Image read failed.");
    }

    return image;
  }
View Full Code Here

      String tempDirStr = JRProperties.getProperty(JRProperties.COMPILER_TEMP_DIR);

      tempDirFile = new File(tempDirStr);
      if (!tempDirFile.exists() || !tempDirFile.isDirectory())
      {
        throw new JRException("Temporary directory not found : " + tempDirStr);
      }
    }

    List datasets = jasperDesign.getDatasetsList();
    List crosstabs = jasperDesign.getCrosstabs();
   
    JRCompilationUnit[] units = new JRCompilationUnit[datasets.size() + crosstabs.size() + 1];
   
    // generating source code for the main report dataset
    units[0] = createCompileUnit(jasperDesign, jasperDesign.getMainDesignDataset(), expressionCollector, tempDirFile, nameSuffix);

    int sourcesCount = 1;
    for (Iterator it = datasets.iterator(); it.hasNext(); ++sourcesCount)
    {
      JRDesignDataset dataset = (JRDesignDataset) it.next();
      // generating source code for a sub dataset
      units[sourcesCount] = createCompileUnit(jasperDesign, dataset, expressionCollector, tempDirFile, nameSuffix);
    }
   
    for (Iterator it = crosstabs.iterator(); it.hasNext(); ++sourcesCount)
    {
      JRDesignCrosstab crosstab = (JRDesignCrosstab) it.next();
      // generating source code for a sub dataset
      units[sourcesCount] = createCompileUnit(jasperDesign, crosstab, expressionCollector, tempDirFile, nameSuffix);
    }
   
    //TODO component - component compilation units?

    String classpath = JRProperties.getProperty(JRProperties.COMPILER_CLASSPATH);
   
    try
    {
      // compiling generated sources
      String compileErrors = compileUnits(units, classpath, tempDirFile);
      if (compileErrors != null)
      {
        throw new JRException("Errors were encountered when compiling report expressions class file:\n" + compileErrors);
      }

      // creating the report compile data
      JRReportCompileData reportCompileData = new JRReportCompileData();
      reportCompileData.setMainDatasetCompileData(units[0].getCompileData());
     
      for (ListIterator it = datasets.listIterator(); it.hasNext();)
      {
        JRDesignDataset dataset = (JRDesignDataset) it.next();
        reportCompileData.setDatasetCompileData(dataset, units[it.nextIndex()].getCompileData());
      }
     
      for (ListIterator it = crosstabs.listIterator(); it.hasNext();)
      {
        JRDesignCrosstab crosstab = (JRDesignCrosstab) it.next();
        Integer crosstabId = expressionCollector.getCrosstabId(crosstab);
        reportCompileData.setCrosstabCompileData(crosstabId.intValue(), units[datasets.size() + it.nextIndex()].getCompileData());
      }

      // creating the report
      JasperReport jasperReport =
        new JasperReport(
          jasperDesign,
          getCompilerClass(),
          reportCompileData,
          expressionCollector,
          nameSuffix
          );
     
      return jasperReport;
    }
    catch (JRException e)
    {
      throw e;
    }
    catch (Exception e)
    {
      throw new JRException("Error compiling report design.", e);
    }
    finally
    {
      if (needsSourceFiles && !isKeepJavaFile)
      {
View Full Code Here

          factory.setNamespaceAware(true);  
          DocumentBuilder builder = null;
        try {
          builder = factory.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
          throw new JRException(e);
        }   
          DOMImplementation impl = builder.getDOMImplementation();
         
          Set<String> nsSet = xmlNamespaceMap.keySet();
          Iterator<String> it = nsSet.iterator();
View Full Code Here

        return xpathAPI.selectNodeList(contextNode, expression,  namespaceElement);
      } else {
        return xpathAPI.selectNodeList(contextNode, expression);
      }
    } catch (TransformerException e) {
      throw new JRException("XPath selection failed. Expression: "
          + expression, e);
    }
  }
View Full Code Here

        value = object.str();
        break;
      }
      return value;
    } catch (TransformerException e) {
      throw new JRException("XPath selection failed. Expression: "
          + expression, e);
    }
  }
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.