コード例 #1
0
  private static JRCompiler getCompiler(JasperDesign jasperDesign) throws JRException {
    JRCompiler compiler = null;

    String compilerClassName = JRProperties.getProperty(JRProperties.COMPILER_CLASS);
    if (compilerClassName == null || compilerClassName.trim().length() == 0) {
      String language = jasperDesign.getLanguage();
      compilerClassName = JRProperties.getProperty(JRCompiler.COMPILER_PREFIX + language);
      if (compilerClassName == null || compilerClassName.trim().length() == 0) {
        if (JRReport.LANGUAGE_JAVA.equals(language)) {
          return getJavaCompiler();
        } else {
          throw new JRException("No report compiler set for language : " + language);
        }
      }
    }

    try {
      Class clazz = JRClassLoader.loadClassForName(compilerClassName);
      compiler = (JRCompiler) clazz.newInstance();
    } catch (Exception e) {
      throw new JRException("Could not instantiate report compiler : " + compilerClassName, e);
    }

    return compiler;
  }
  /**
   * Creates a data source out of the query result.
   *
   * @return the data source
   */
  protected JRDataSource createResultDatasource() {
    JRDataSource resDatasource;

    String runType =
        JRProperties.getProperty(
            dataset, JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_QUERY_RUN_TYPE);
    boolean useFieldDescriptions =
        JRProperties.getBooleanProperty(
            dataset,
            JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_FIELD_MAPPING_DESCRIPTIONS,
            true);

    if (runType == null
        || runType.equals(JRHibernateQueryExecuterFactory.VALUE_HIBERNATE_QUERY_RUN_TYPE_LIST)) {
      try {
        int pageSize =
            JRProperties.getIntegerProperty(
                dataset,
                JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_QUERY_LIST_PAGE_SIZE,
                0);

        resDatasource = new JRHibernateListDataSource(this, useFieldDescriptions, pageSize);
      } catch (NumberFormatException e) {
        throw new JRRuntimeException(
            "The "
                + JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_QUERY_LIST_PAGE_SIZE
                + " property must be numerical.",
            e);
      }
    } else if (runType.equals(
        JRHibernateQueryExecuterFactory.VALUE_HIBERNATE_QUERY_RUN_TYPE_ITERATE)) {
      resDatasource = new JRHibernateIterateDataSource(this, useFieldDescriptions);
    } else if (runType.equals(
        JRHibernateQueryExecuterFactory.VALUE_HIBERNATE_QUERY_RUN_TYPE_SCROLL)) {
      resDatasource = new JRHibernateScrollDataSource(this, useFieldDescriptions);
    } else {
      throw new JRRuntimeException(
          "Unknown value for the "
              + JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_QUERY_RUN_TYPE
              + " property.  Possible values are "
              + JRHibernateQueryExecuterFactory.VALUE_HIBERNATE_QUERY_RUN_TYPE_LIST
              + ", "
              + JRHibernateQueryExecuterFactory.VALUE_HIBERNATE_QUERY_RUN_TYPE_ITERATE
              + " and "
              + JRHibernateQueryExecuterFactory.VALUE_HIBERNATE_QUERY_RUN_TYPE_SCROLL
              + ".");
    }

    return resDatasource;
  }
コード例 #3
0
  protected static MarkupProcessor getMarkupProcessor(String markup) {
    MarkupProcessor markupProcessor = (MarkupProcessor) markupProcessors.get(markup);

    if (markupProcessor == null) {
      String factoryClass =
          JRProperties.getProperty(
              MarkupProcessorFactory.PROPERTY_MARKUP_PROCESSOR_FACTORY_PREFIX + markup);
      if (factoryClass == null) {
        throw new JRRuntimeException(
            "No markup processor factory specifyed for '" + markup + "' markup.");
      }

      MarkupProcessorFactory factory = null;
      try {
        factory =
            (MarkupProcessorFactory) markupProcessorFactoryCache.getCachedInstance(factoryClass);
      } catch (JRException e) {
        throw new JRRuntimeException(e);
      }

      markupProcessor = factory.createMarkupProcessor();
      markupProcessors.put(markup, markupProcessor);
    }

    return markupProcessor;
  }
コード例 #4
0
ファイル: BarcodeUtils.java プロジェクト: kenjox/hospitalMS
  public static BarcodeImageProducer getImageProducer(JRPropertiesHolder propertiesHolder) {
    String producerProperty =
        JRProperties.getProperty(propertiesHolder, BarcodeImageProducer.PROPERTY_IMAGE_PRODUCER);

    String producerClass =
        JRProperties.getProperty(
            propertiesHolder,
            BarcodeImageProducer.PROPERTY_PREFIX_IMAGE_PRODUCER + producerProperty);
    if (producerClass == null) {
      producerClass = producerProperty;
    }

    try {
      return (BarcodeImageProducer) imageProducerCache.getCachedInstance(producerClass);
    } catch (JRException e) {
      throw new JRRuntimeException(e);
    }
  }
  protected void setTextRenderer() {
    boolean isMinimizePrinterJobSize = true;
    Boolean isMinimizePrinterJobSizeParam =
        (Boolean) parameters.get(JRGraphics2DExporterParameter.MINIMIZE_PRINTER_JOB_SIZE);
    if (isMinimizePrinterJobSizeParam == null) {
      isMinimizePrinterJobSize =
          JRProperties.getBooleanProperty(
              MINIMIZE_PRINTER_JOB_SIZE); // FIXMENOW check other potential report properties
    } else {
      isMinimizePrinterJobSize = isMinimizePrinterJobSizeParam.booleanValue();
    }

    textRenderer =
        new TextRenderer(
            isMinimizePrinterJobSize,
            JRProperties.getBooleanProperty(
                jasperPrint, JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT, false));
  }
 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 runnerFactoryCache.getCachedInstance(factoryClassName);
 }
コード例 #7
0
  protected void configureDigester(Digester digester)
      throws SAXException, ParserConfigurationException {
    boolean validating = JRProperties.getBooleanProperty(JRProperties.COMPILER_XML_VALIDATION);

    digester.setErrorHandler(this);
    digester.setValidating(validating);
    digester.setFeature("http://xml.org/sax/features/validation", validating);

    digester.addRuleSet(rules);
  }
  public void exportReport() throws JRException {
    progressMonitor =
        (JRExportProgressMonitor) parameters.get(JRExporterParameter.PROGRESS_MONITOR);

    /*   */
    setOffset(false);

    try {
      /*   */
      setExportContext();

      /*   */
      setInput();

      if (!parameters.containsKey(JRExporterParameter.FILTER)) {
        filter = createFilter(GRAPHICS2D_EXPORTER_PROPERTIES_PREFIX);
      }

      /*   */
      setPageRange();

      /*   */
      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;
      }

      exportReportToGraphics2D();
    } finally {
      resetExportContext();
    }
  }
  public JRHibernateQueryExecuter(JRDataset dataset, Map parameters) {
    super(dataset, parameters);

    session =
        (Session) getParameterValue(JRHibernateQueryExecuterFactory.PARAMETER_HIBERNATE_SESSION);
    reportMaxCount = (Integer) getParameterValue(JRParameter.REPORT_MAX_COUNT);
    isClearCache =
        JRProperties.getBooleanProperty(
            dataset, JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_CLEAR_CACHE, false);

    if (session == null) {
      log.warn("The supplied org.hibernate.Session object is null.");
    }

    parseQuery();
  }
コード例 #10
0
  /**
   * Creates a crosstab bucketing engine.
   *
   * @param rowBuckets the row bucket definitions
   * @param columnBuckets the column bucket definitions
   * @param measures the measure definitions
   * @param sorted whether the data is presorted
   * @param retrieveTotal totals to retrieve along with the cell values
   */
  public BucketingService(
      List rowBuckets,
      List columnBuckets,
      List measures,
      boolean sorted,
      boolean[][] retrieveTotal) {
    this.sorted = sorted;

    buckets = new BucketDefinition[DIMENSIONS][];

    rowBucketCount = rowBuckets.size();
    buckets[DIMENSION_ROW] = new BucketDefinition[rowBucketCount];
    rowBuckets.toArray(buckets[DIMENSION_ROW]);

    colBucketCount = columnBuckets.size();
    buckets[DIMENSION_COLUMN] = new BucketDefinition[colBucketCount];
    columnBuckets.toArray(buckets[DIMENSION_COLUMN]);

    allBuckets = new BucketDefinition[rowBucketCount + colBucketCount];
    System.arraycopy(buckets[DIMENSION_ROW], 0, allBuckets, 0, rowBucketCount);
    System.arraycopy(buckets[DIMENSION_COLUMN], 0, allBuckets, rowBucketCount, colBucketCount);

    origMeasureCount = measures.size();
    List measuresList = new ArrayList(measures.size() * 2);
    List measureIndexList = new ArrayList(measures.size() * 2);
    for (int i = 0; i < measures.size(); ++i) {
      MeasureDefinition measure = (MeasureDefinition) measures.get(i);
      addMeasure(measure, i, measuresList, measureIndexList);
    }
    this.measures = new MeasureDefinition[measuresList.size()];
    measuresList.toArray(this.measures);
    this.measureIndexes = new int[measureIndexList.size()];
    for (int i = 0; i < measureIndexes.length; ++i) {
      measureIndexes[i] = ((Integer) measureIndexList.get(i)).intValue();
    }

    this.retrieveTotal = retrieveTotal;
    checkTotals();

    bucketValueMap = createBucketMap(0);

    zeroUserMeasureValues = initUserMeasureValues();

    bucketMeasureLimit = JRProperties.getIntegerProperty(PROPERTY_BUCKET_MEASURE_LIMIT, 0);
  }
コード例 #11
0
  protected void setPrintText(JRPrintText printText) {
    int startIndex = getTextStart();
    int endIndex = getTextEnd();
    JRStyledText fullStyledText = getStyledText();
    String fullText = fullStyledText.getText();

    boolean keepAllText =
        !canOverflow()
            && JRProperties.getBooleanProperty(
                this, JRTextElement.PROPERTY_PRINT_KEEP_FULL_TEXT, false);
    if (keepAllText) {
      // assert getTextStart() == 0
      if (startIndex != 0) {
        throw new JRRuntimeException("Text start index != 0 on keep all text.");
      }

      if (!JRCommonText.MARKUP_NONE.equals(getMarkup())) {
        // rewrite as styled text
        String styledText = filler.getStyledTextParser().write(fullStyledText);
        printText.setText(styledText);
      } else {
        printText.setText(fullText);
      }

      if (endIndex < fullText.length()) {
        printText.setTextTruncateIndex(new Integer(endIndex));
      }
    } else {
      String printedText;
      if (!JRCommonText.MARKUP_NONE.equals(getMarkup())) {
        printedText = filler.getStyledTextParser().write(fullStyledText, startIndex, endIndex);
      } else {
        printedText = fullText.substring(startIndex, endIndex);
      }
      printText.setText(printedText);
    }

    printText.setTextTruncateSuffix(getTextTruncateSuffix());
    printText.setLineBreakOffsets(getLineBreakOffsets());
  }
  /**
   * Creates the Hibernate query object.
   *
   * <p>If the value of the {@link
   * JRHibernateQueryExecuterFactory#PARAMETER_HIBERNATE_FILTER_COLLECTION
   * PARAMETER_HIBERNATE_FILTER_COLLECTION} is not null, then a filter query is created using the
   * value of the parameter as the collection.
   *
   * @param queryString the query string
   */
  protected synchronized void createQuery(String queryString) {
    if (log.isDebugEnabled()) {
      log.debug("HQL query: " + queryString);
    }

    Object filterCollection =
        getParameterValue(JRHibernateQueryExecuterFactory.PARAMETER_HIBERNATE_FILTER_COLLECTION);
    if (filterCollection == null) {
      query = session.createQuery(queryString);
    } else {
      query = session.createFilter(filterCollection, queryString);
    }
    query.setReadOnly(true);

    int fetchSize =
        JRProperties.getIntegerProperty(
            dataset, JRJdbcQueryExecuterFactory.PROPERTY_JDBC_FETCH_SIZE, 0);
    if (fetchSize != 0) {
      query.setFetchSize(fetchSize);
    }

    setParameters();
  }
コード例 #13
0
  protected Map getJdtSettings() {
    final Map settings = new HashMap();
    settings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
    settings.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
    settings.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);
    //		if (ctxt.getOptions().getJavaEncoding() != null)
    //		{
    //			settings.put(CompilerOptions.OPTION_Encoding, ctxt.getOptions().getJavaEncoding());
    //		}
    //		if (ctxt.getOptions().getClassDebugInfo())
    //		{
    //			settings.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
    //		}

    List properties = JRProperties.getProperties(JDT_PROPERTIES_PREFIX);
    for (Iterator it = properties.iterator(); it.hasNext(); ) {
      JRProperties.PropertySuffix property = (JRProperties.PropertySuffix) it.next();
      String propVal = property.getValue();
      if (propVal != null && propVal.length() > 0) {
        settings.put(property.getKey(), propVal);
      }
    }

    Properties systemProps = System.getProperties();
    for (Enumeration it = systemProps.propertyNames(); it.hasMoreElements(); ) {
      String propName = (String) it.nextElement();
      if (propName.startsWith(JDT_PROPERTIES_PREFIX)) {
        String propVal = systemProps.getProperty(propName);
        if (propVal != null && propVal.length() > 0) {
          settings.put(propName, propVal);
        }
      }
    }

    return settings;
  }