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

The following examples show how to use org.pentaho.reporting.engine.classic.core.Element#getElementType() . 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: BundleWriterUtilities.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static BundleDataFactoryWriterHandler lookupWriteHandler( final Element element ) {
  if ( element == null ) {
    throw new NullPointerException();
  }

  final ElementType type = element.getElementType();
  if ( type == null ) {
    // A legacy element. Cannot handle that this way.
    return null;
  }

  final ElementMetaData metaData = type.getMetaData();
  final String configKey = ELEMENT_PREFIX + metaData.getName();
  final Configuration globalConfig = ClassicEngineBoot.getInstance().getGlobalConfig();
  final String value = globalConfig.getConfigProperty( configKey );
  if ( value != null ) {
    return (BundleDataFactoryWriterHandler) ObjectUtilities.loadAndInstantiate( value, metaData.getClass(),
        BundleDataFactoryWriterHandler.class );
  }
  return null;
}
 
Example 2
Source File: CrosstabEditSupport.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static String findTitle( final String field, final Band titleHeader ) {
  final MatcherContext context = new MatcherContext();
  context.setMatchSubReportChilds( false );

  NodeMatcher m = new AndMatcher( new ElementMatcher( LabelType.INSTANCE ),
    new AttributeMatcher( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.LABEL_FOR, field ) );
  ReportElement match = ReportStructureMatcher.match( context, titleHeader, m );
  if ( match == null ) {
    if ( titleHeader.getElementCount() > 0 ) {
      Element e = titleHeader.getElement( 0 );
      if ( e.getElementType() instanceof LabelType ) {
        return e.getAttributeTyped( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, String.class );
      }
    }
    return null;
  }

  return match.getAttributeTyped( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, String.class );
}
 
Example 3
Source File: StyleTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private DefaultStyleDataBackend( final StyleMetaData[] metaData,
                                 final GroupingHeader[] groupings,
                                 final Element[] elements ) {
  super( metaData, groupings );
  this.elements = elements;
  this.elementTypes = new ElementType[ elements.length ];

  for ( int i = 0; i < elements.length; i++ ) {
    final Element element = elements[ i ];
    elementTypes[ i ] = element.getElementType();
  }

  final ResolverStyleSheet resolverStyleSheet = getResolvedStyle();
  if ( elements.length > 0 ) {
    final StyleResolver resolver = new SimpleStyleResolver( true );
    resolver.resolve( elements[ 0 ], resolverStyleSheet );
  }

  this.inheritValues = new Object[ metaData.length ];
  this.expressionValues = new Object[ metaData.length ];
}
 
Example 4
Source File: LegacyChartsUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean isLegacyChartElement( final Element element ) {
  if ( element.getElementType() instanceof LegacyChartType ) {
    return true;
  }
  final Expression valueExpression =
    element.getAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE );
  if ( valueExpression instanceof AbstractChartExpression ) {
    return true;
  }

  return false;
}
 
Example 5
Source File: AbstractElementWriteHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void copyStaticResources( final WriteableDocumentBundle bundle, final BundleWriterState state,
    final Element element ) throws BundleWriterException {
  if ( bundle == null ) {
    throw new NullPointerException();
  }
  if ( state == null ) {
    throw new NullPointerException();
  }
  if ( element == null ) {
    throw new NullPointerException();
  }

  final ResourceKey contentBase = element.getContentBase();
  if ( contentBase == null ) {
    // treat all resources as linked resources ..
    AbstractElementWriteHandler.logger.debug( "No content base, treating all content as linked." );
    return;
  }
  final ResourceKey defSource = element.getDefinitionSource();
  if ( defSource == null ) {
    // treat all resources as linked resources ..
    AbstractElementWriteHandler.logger.debug( "No report definition source, treating all content as linked." );
    return;
  }

  if ( ObjectUtilities.equal( contentBase.getParent(), defSource.getParent() ) == false ) {
    // treat all resources as linked resources ..
    AbstractElementWriteHandler.logger
        .debug( "Content base points to non-bundle location, treating all content as linked." );
    return;
  }

  final Object contentBasePathRaw = contentBase.getIdentifier();
  if ( contentBasePathRaw instanceof String == false ) {
    return;
  }

  final String contentBasePath = String.valueOf( contentBasePathRaw );
  final ResourceManager resourceManager = state.getMasterReport().getResourceManager();

  final ElementType type = element.getElementType();
  final ElementMetaData data = type.getMetaData();
  final AttributeMetaData[] datas = data.getAttributeDescriptions();
  for ( int i = 0; i < datas.length; i++ ) {
    final AttributeMetaData attributeMetaData = datas[i];
    if ( attributeMetaData.isTransient() ) {
      continue;
    }
    if ( isFiltered( attributeMetaData ) ) {
      continue;
    }

    final Object attValue = element.getAttribute( attributeMetaData.getNameSpace(), attributeMetaData.getName() );
    if ( attValue == null ) {
      continue;
    }
    final ResourceReference[] referencedResources =
        attributeMetaData.getReferencedResources( element, state.getMasterReport().getResourceManager(), attValue );
    for ( int j = 0; j < referencedResources.length; j++ ) {
      final ResourceReference reference = referencedResources[j];
      if ( reference.isLinked() ) {
        AbstractElementWriteHandler.logger.debug( "Linked Resource will not be copied into bundle: " + reference );
        continue;
      }

      final ResourceKey path = reference.getPath();
      final Object identifier = path.getIdentifier();
      if ( identifier instanceof String == false ) {
        AbstractElementWriteHandler.logger.warn( "Resource-Bundle-Key has no parseable path: " + path );
        continue;
      }

      final String identifierString = String.valueOf( identifier );
      final String relativePath = IOUtils.getInstance().createRelativePath( identifierString, contentBasePath );
      try {
        BundleUtilities.copyInto( bundle, relativePath, path, resourceManager );
      } catch ( Exception e ) {
        throw new BundleWriterException( "Failed to copy content from key " + path, e );
      }
      AbstractElementWriteHandler.logger.debug( "Copied " + path + " as " + relativePath );
    }
  }
}