Java Code Examples for org.pentaho.reporting.engine.classic.core.Element#getDataSource()

The following examples show how to use org.pentaho.reporting.engine.classic.core.Element#getDataSource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LegacyType.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns information about the formatstring that was used to transform a raw-value into a formatted text. Not all
 * elements will make use of a format-string. These elements will return
 * {@link org.pentaho.reporting.engine .classic.core.filter.FormatSpecification#TYPE_UNDEFINED} in that case.
 *
 * @param runtime
 *          the Expression runtime used to possibly compute the raw-value.
 * @param element
 *          the element to which this datasource is added.
 * @param formatSpecification
 *          the format specification (can be null). @return a filled format specififcation. If the
 *          <code>formatSpecification</code> parameter was not null, this given instance is reused.
 */
public FormatSpecification getFormatString( final ExpressionRuntime runtime, final ReportElement element,
    FormatSpecification formatSpecification ) {
  if ( !( element instanceof Element ) ) {
    return null;
  }
  final Element e = (Element) element;
  final DataSource source = e.getDataSource();
  if ( source instanceof RawDataSource ) {
    final RawDataSource rds = (RawDataSource) source;
    return rds.getFormatString( runtime, element, formatSpecification );
  }

  if ( formatSpecification == null ) {
    formatSpecification = new FormatSpecification();
  }
  formatSpecification.redefine( FormatSpecification.TYPE_UNDEFINED, null );
  return formatSpecification;
}
 
Example 2
Source File: ReportDescriptionWriter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Writes the datasource- or template-tag for an given element.
 *
 * @param element
 *          the element, which should be written.
 * @throws ReportWriterException
 *           if there is a problem writing the report
 * @throws IOException
 *           if there is an IO error.
 */
protected void writeDataSourceForElement( final Element element ) throws ReportWriterException, IOException {
  if ( ( element.getDataSource() instanceof EmptyDataSource ) ) {
    return;
  }

  if ( element.getDataSource() instanceof Template == false ) {
    writeDataSource( element.getDataSource() );
    return;
  }

  final TemplateCollector tc = getReportWriter().getTemplateCollector();
  final Template template = (Template) element.getDataSource();

  // the template description of the element template will get the
  // template name as its name.
  final TemplateDescription templateDescription = tc.getDescription( template );

  if ( templateDescription == null ) {
    throw new ReportWriterException( "Unknown template type: " + template );
  }

  // create the parent description before the template description is filled.
  final TemplateDescription parentTemplate = (TemplateDescription) templateDescription.getInstance();

  try {
    templateDescription.setParameterFromObject( template );
  } catch ( ObjectFactoryException ofe ) {
    throw new ReportWriterException( "Error while preparing the template", ofe );
  }

  final TemplateWriter templateWriter =
      new TemplateWriter( getReportWriter(), getXmlWriter(), templateDescription, parentTemplate );
  templateWriter.write();
}
 
Example 3
Source File: LegacyType.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the unformated raw value. Whether that raw value is useable for the export is beyond the scope of this API
 * definition, but providing access to {@link Number} or {@link java.util.Date} objects is a good idea.
 *
 * @param runtime
 *          the expression runtime that is used to evaluate formulas and expressions when computing the value of this
 *          filter.
 * @param element
 * @return the raw data.
 */
public Object getRawValue( final ExpressionRuntime runtime, final ReportElement element ) {
  if ( !( element instanceof Element ) ) {
    return null;
  }
  final Element e = (Element) element;
  final DataSource source = e.getDataSource();
  if ( source instanceof RawDataSource ) {
    final RawDataSource rds = (RawDataSource) source;
    return rds.getRawValue( runtime, element );
  }
  return e.getDataSource().getValue( runtime, element );
}
 
Example 4
Source File: LegacyElementWriteHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Writes a single element as XML structure.
 *
 * @param bundle
 *          the bundle to which to write to.
 * @param state
 *          the current write-state.
 * @param xmlWriter
 *          the xml writer.
 * @param element
 *          the element.
 * @throws IOException
 *           if an IO error occured.
 * @throws BundleWriterException
 *           if an Bundle writer.
 */
@SuppressWarnings( "deprecation" )
public void writeElement( final WriteableDocumentBundle bundle, final BundleWriterState state,
    final XmlWriter xmlWriter, final Element element ) throws IOException, BundleWriterException {
  if ( bundle == null ) {
    throw new NullPointerException();
  }
  if ( state == null ) {
    throw new NullPointerException();
  }
  if ( xmlWriter == null ) {
    throw new NullPointerException();
  }
  if ( element == null ) {
    throw new NullPointerException();
  }

  final AttributeList attList = createMainAttributes( element, xmlWriter );
  attList.addNamespaceDeclaration( "ext", ExtParserModule.NAMESPACE );

  xmlWriter.writeTag( BundleNamespaces.LAYOUT, "legacy", attList, XmlWriterSupport.OPEN );
  writeElementBody( bundle, state, element, xmlWriter );

  final ReportWriter writer = new ReportWriter( state.getMasterReport(), "UTF-8" );
  writer.addClassFactoryFactory( new URLClassFactory() );
  writer.addClassFactoryFactory( new DefaultClassFactory() );
  writer.addClassFactoryFactory( new BandLayoutClassFactory() );
  writer.addClassFactoryFactory( new ArrayClassFactory() );

  writer.addStyleKeyFactory( new DefaultStyleKeyFactory() );
  writer.addStyleKeyFactory( new PageableLayoutStyleKeyFactory() );
  writer.addTemplateCollection( new DefaultTemplateCollection() );
  writer.addElementFactory( new DefaultElementFactory() );
  writer.addDataSourceFactory( new DefaultDataSourceFactory() );
  final DataSource datasource = element.getDataSource();

  if ( datasource instanceof Template ) {
    writeLegacyTemplate( xmlWriter, writer, (Template) datasource );
  } else {
    writeLegacyDataSource( xmlWriter, writer, datasource );
  }

  xmlWriter.writeCloseTag();

}