Java Code Examples for org.pentaho.reporting.engine.classic.core.Element#getAttributeExpression()
The following examples show how to use
org.pentaho.reporting.engine.classic.core.Element#getAttributeExpression() .
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: Prd4625Test.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
/** * Receives notification that report generation initializes the current run. <P> The event carries a * ReportState.Started state. Use this to initialize the report. * * @param event The event. */ public void reportInitialized( final ReportEvent event ) { // identifies the report we are working with. Useful for debugging! ReportStateKey subReportStateKey = event.getState().getProcessKey(); ReportStateKey parentReportStateKey = event.getState().getParentSubReportState().getProcessKey(); // System.out.println ("SubReport: " + subReportStateKey); // System.out.println ("Parent: " + parentReportStateKey); final ReportHeader reportHeader = event.getState().getReport().getReportHeader(); final Element element = reportHeader.getElement( 0 ); // this should be the chart assertEquals( "legacy-chart", element.getElementTypeName() ); final Expression attributeExpression = element.getAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE ); assertNotNull( attributeExpression ); assertTrue( attributeExpression instanceof PieChartExpression ); final PieChartExpression pe = (PieChartExpression) attributeExpression; final String dataSource = pe.getDataSource(); final Expression[] expressions = event.getState().getFlowController().getMasterRow().getExpressionDataRow().getExpressions(); assertEquals( expressions.length, 2 ); // 2 expressions: One is the validate function, the other is the chart-dataset collector. // as the chart-dataset collector is added late (during report processing), our validate function // will always occupy spot 0. assertEquals( expressions[ 1 ].getName(), dataSource ); }
Example 2
Source File: BarSparklineElementFactoryTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testCreateElement() { Element elem = elemFactory.createElement(); assertThat( elem, is( notNullValue() ) ); assertThat( elem.getName(), is( equalTo( StringUtils.EMPTY ) ) ); assertThat( elem.getElementType(), is( instanceOf( BarSparklineType.class ) ) ); assertThat( elem.getAttribute( NAMESPACE, AttributeNames.Core.VALUE ), is( nullValue() ) ); assertThat( elem.getAttribute( NAMESPACE, AttributeNames.Core.FIELD ), is( nullValue() ) ); assertThat( elem.getAttribute( SparklineAttributeNames.NAMESPACE, SparklineAttributeNames.SPACING ), is( nullValue() ) ); assertThat( elem.getAttributeExpression( NAMESPACE, AttributeNames.Core.VALUE ), is( nullValue() ) ); elemFactory.setName( "elem_name" ); elemFactory.setContent( "elem_content" ); elemFactory.setFieldname( "field_name" ); elemFactory.setFormula( "test_formula" ); elemFactory.setSpacing( 20 ); elem = elemFactory.createElement(); assertThat( elem, is( notNullValue() ) ); assertThat( elem.getName(), is( equalTo( elemFactory.getName() ) ) ); assertThat( elem.getElementType(), is( instanceOf( BarSparklineType.class ) ) ); assertThat( elem.getAttribute( NAMESPACE, AttributeNames.Core.VALUE ), is( equalTo( elemFactory.getContent() ) ) ); assertThat( (String) elem.getAttribute( NAMESPACE, AttributeNames.Core.FIELD ), is( equalTo( elemFactory .getFieldname() ) ) ); assertThat( (Integer) elem.getAttribute( SparklineAttributeNames.NAMESPACE, SparklineAttributeNames.SPACING ), is( equalTo( elemFactory.getSpacing() ) ) ); Object expressionObj = elem.getAttributeExpression( NAMESPACE, AttributeNames.Core.VALUE ); assertThat( expressionObj, is( notNullValue() ) ); assertThat( expressionObj, is( instanceOf( FormulaExpression.class ) ) ); assertThat( ( (FormulaExpression) expressionObj ).getFormula(), is( equalTo( elemFactory.getFormula() ) ) ); }
Example 3
Source File: LineSparklineElementFactoryTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testCreateElement() { Element elem = elemFactory.createElement(); assertThat( elem, is( notNullValue() ) ); assertThat( elem.getName(), is( equalTo( StringUtils.EMPTY ) ) ); assertThat( elem.getElementType(), is( instanceOf( LineSparklineType.class ) ) ); assertThat( elem.getAttribute( NAMESPACE, AttributeNames.Core.VALUE ), is( nullValue() ) ); assertThat( elem.getAttribute( NAMESPACE, AttributeNames.Core.FIELD ), is( nullValue() ) ); assertThat( elem.getAttribute( SparklineAttributeNames.NAMESPACE, SparklineAttributeNames.SPACING ), is( nullValue() ) ); assertThat( elem.getAttributeExpression( NAMESPACE, AttributeNames.Core.VALUE ), is( nullValue() ) ); elemFactory.setName( "elem_name" ); elemFactory.setContent( "elem_content" ); elemFactory.setFieldname( "field_name" ); elemFactory.setFormula( "test_formula" ); elemFactory.setSpacing( 20 ); elem = elemFactory.createElement(); assertThat( elem, is( notNullValue() ) ); assertThat( elem.getName(), is( equalTo( elemFactory.getName() ) ) ); assertThat( elem.getElementType(), is( instanceOf( LineSparklineType.class ) ) ); assertThat( elem.getAttribute( NAMESPACE, AttributeNames.Core.VALUE ), is( equalTo( elemFactory.getContent() ) ) ); assertThat( (String) elem.getAttribute( NAMESPACE, AttributeNames.Core.FIELD ), is( equalTo( elemFactory .getFieldname() ) ) ); assertThat( (Integer) elem.getAttribute( SparklineAttributeNames.NAMESPACE, SparklineAttributeNames.SPACING ), is( equalTo( elemFactory.getSpacing() ) ) ); Object expressionObj = elem.getAttributeExpression( NAMESPACE, AttributeNames.Core.VALUE ); assertThat( expressionObj, is( notNullValue() ) ); assertThat( expressionObj, is( instanceOf( FormulaExpression.class ) ) ); assertThat( ( (FormulaExpression) expressionObj ).getFormula(), is( equalTo( elemFactory.getFormula() ) ) ); }
Example 4
Source File: AbstractElementWriteHandler.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
protected void writeAttributeExpressions( final WriteableDocumentBundle bundle, final BundleWriterState state, final Element element, final XmlWriter writer ) throws IOException, BundleWriterException { if ( bundle == null ) { throw new NullPointerException(); } if ( state == null ) { throw new NullPointerException(); } if ( element == null ) { throw new NullPointerException(); } if ( writer == null ) { throw new NullPointerException(); } // write attribute-expressions. final String[] attributeNamespaces = element.getAttributeExpressionNamespaces(); for ( int i = 0; i < attributeNamespaces.length; i++ ) { final String namespace = attributeNamespaces[i]; final String[] attributeNames = element.getAttributeExpressionNames( namespace ); for ( int j = 0; j < attributeNames.length; j++ ) { final String name = attributeNames[j]; final AttributeList attList = new AttributeList(); attList.setAttribute( BundleNamespaces.LAYOUT, "namespace", namespace ); attList.setAttribute( BundleNamespaces.LAYOUT, "name", name ); final Expression ex = element.getAttributeExpression( namespace, name ); ExpressionWriterUtility.writeExpressionCore( bundle, state, ex, writer, BundleNamespaces.LAYOUT, "attribute-expression", attList ); } } }
Example 5
Source File: LegacyChartsUtil.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
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 6
Source File: VisualAttributeTableModel.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
private Expression computeExpressionValue( final AttributeMetaData metaData, final int row ) { final AttributeDataBackend dataBackend1 = getAttributeDataBackend(); final Object[] expressionValues = dataBackend1.getExpressionValues(); final Object o = expressionValues[ row ]; if ( o == NULL_INDICATOR ) { return null; } if ( o != null ) { return (Expression) o; } if ( metaData.isDesignTimeValue() ) { expressionValues[ row ] = NULL_INDICATOR; return null; } Expression lastElement = null; final Element[] elements = dataBackend1.getData(); if ( elements.length > 0 ) { final Element element = elements[ 0 ]; lastElement = element.getAttributeExpression( metaData.getNameSpace(), metaData.getName() ); } if ( lastElement != null ) { expressionValues[ row ] = lastElement; } else { expressionValues[ row ] = NULL_INDICATOR; } return lastElement; }
Example 7
Source File: PieSparklineElementFactoryTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
@Test public void testCreateElement() { Element elem = elemFactory.createElement(); assertThat( elem, is( notNullValue() ) ); assertThat( elem.getName(), is( equalTo( StringUtils.EMPTY ) ) ); assertThat( elem.getElementType(), is( instanceOf( PieSparklineType.class ) ) ); assertThat( elem.getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE ), is( nullValue() ) ); assertThat( elem.getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FIELD ), is( nullValue() ) ); assertThat( elem.getAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE ), is( nullValue() ) ); assertThat( elem.getAttribute( NAMESPACE, SparklineAttributeNames.START_ANGLE ), is( nullValue() ) ); assertThat( elem.getAttribute( NAMESPACE, SparklineAttributeNames.LOW_SLICE ), is( nullValue() ) ); assertThat( elem.getAttribute( NAMESPACE, SparklineAttributeNames.MEDIUM_SLICE ), is( nullValue() ) ); assertThat( elem.getAttribute( NAMESPACE, SparklineAttributeNames.HIGH_SLICE ), is( nullValue() ) ); assertThat( elem.getAttribute( NAMESPACE, SparklineAttributeNames.COUNTER_CLOCKWISE ), is( nullValue() ) ); elemFactory.setName( "elem_name" ); elemFactory.setContent( "elem_content" ); elemFactory.setFieldname( "field_name" ); elemFactory.setFormula( "test_formula" ); elemFactory.setStartAngle( 100 ); elemFactory.setLowSlice( 5.5 ); elemFactory.setMediumSlice( 10.5 ); elemFactory.setHighSlice( 20.5 ); elemFactory.setCounterClockwise( true ); elem = elemFactory.createElement(); assertThat( elem, is( notNullValue() ) ); assertThat( elem.getName(), is( equalTo( elemFactory.getName() ) ) ); assertThat( elem.getElementType(), is( instanceOf( PieSparklineType.class ) ) ); assertThat( elem.getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE ), is( equalTo( elemFactory .getContent() ) ) ); assertThat( (String) elem.getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FIELD ), is( equalTo( elemFactory.getFieldname() ) ) ); assertThat( (Integer) elem.getAttribute( NAMESPACE, SparklineAttributeNames.START_ANGLE ), is( equalTo( elemFactory .getStartAngle() ) ) ); assertThat( (Double) elem.getAttribute( NAMESPACE, SparklineAttributeNames.LOW_SLICE ), is( equalTo( elemFactory .getLowSlice() ) ) ); assertThat( (Double) elem.getAttribute( NAMESPACE, SparklineAttributeNames.MEDIUM_SLICE ), is( equalTo( elemFactory .getMediumSlice() ) ) ); assertThat( (Double) elem.getAttribute( NAMESPACE, SparklineAttributeNames.HIGH_SLICE ), is( equalTo( elemFactory .getHighSlice() ) ) ); assertThat( (Boolean) elem.getAttribute( NAMESPACE, SparklineAttributeNames.COUNTER_CLOCKWISE ), is( equalTo( elemFactory.getCounterClockwise() ) ) ); Object expressionObj = elem.getAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE ); assertThat( expressionObj, is( notNullValue() ) ); assertThat( expressionObj, is( instanceOf( FormulaExpression.class ) ) ); assertThat( ( (FormulaExpression) expressionObj ).getFormula(), is( equalTo( elemFactory.getFormula() ) ) ); }
Example 8
Source File: BarcodeElementFactoryTest.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
@Test public void testCreateElement() { Element elem = barcodeElemFactory.createElement(); assertThat( elem, is( notNullValue() ) ); assertThat( elem.getName(), is( equalTo( StringUtils.EMPTY ) ) ); assertThat( elem.getElementType(), is( instanceOf( SimpleBarcodesType.class ) ) ); assertThat( elem.getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE ), is( nullValue() ) ); assertThat( elem.getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FIELD ), is( nullValue() ) ); assertThat( elem.getAttribute( NAMESPACE, SimpleBarcodesAttributeNames.TYPE_ATTRIBUTE ), is( nullValue() ) ); assertThat( (Boolean) elem.getAttribute( NAMESPACE, SimpleBarcodesAttributeNames.CHECKSUM_ATTRIBUTE ), is( equalTo( false ) ) ); assertThat( elem.getAttribute( NAMESPACE, SimpleBarcodesAttributeNames.BAR_WIDTH_ATTRIBUTE ), is( nullValue() ) ); assertThat( elem.getAttribute( NAMESPACE, SimpleBarcodesAttributeNames.BAR_HEIGHT_ATTRIBUTE ), is( nullValue() ) ); assertThat( (Boolean) elem.getAttribute( NAMESPACE, SimpleBarcodesAttributeNames.SHOW_TEXT_ATTRIBUTE ), is( equalTo( true ) ) ); assertThat( elem.getAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE ), is( nullValue() ) ); barcodeElemFactory.setName( "elem_name" ); barcodeElemFactory.setContent( "elem_content" ); barcodeElemFactory.setFieldname( "field_name" ); barcodeElemFactory.setFormula( "test_formula" ); barcodeElemFactory.setType( "elem_type" ); barcodeElemFactory.setChecksum( true ); barcodeElemFactory.setBarWidth( 200 ); barcodeElemFactory.setBarHeight( 500 ); barcodeElemFactory.setShowText( false ); elem = barcodeElemFactory.createElement(); assertThat( elem, is( notNullValue() ) ); assertThat( elem.getName(), is( equalTo( barcodeElemFactory.getName() ) ) ); assertThat( elem.getElementType(), is( instanceOf( SimpleBarcodesType.class ) ) ); assertThat( elem.getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE ), is( equalTo( barcodeElemFactory.getContent() ) ) ); assertThat( (String) elem.getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FIELD ), is( equalTo( barcodeElemFactory.getFieldname() ) ) ); assertThat( (String) elem.getAttribute( NAMESPACE, SimpleBarcodesAttributeNames.TYPE_ATTRIBUTE ), is( equalTo( barcodeElemFactory.getType() ) ) ); assertThat( (Boolean) elem.getAttribute( NAMESPACE, SimpleBarcodesAttributeNames.CHECKSUM_ATTRIBUTE ), is( equalTo( true ) ) ); assertThat( (Integer) elem.getAttribute( NAMESPACE, SimpleBarcodesAttributeNames.BAR_WIDTH_ATTRIBUTE ), is( equalTo( barcodeElemFactory.getBarWidth() ) ) ); assertThat( (Integer) elem.getAttribute( NAMESPACE, SimpleBarcodesAttributeNames.BAR_HEIGHT_ATTRIBUTE ), is( equalTo( barcodeElemFactory.getBarHeight() ) ) ); assertThat( (Boolean) elem.getAttribute( NAMESPACE, SimpleBarcodesAttributeNames.SHOW_TEXT_ATTRIBUTE ), is( equalTo( false ) ) ); Object expressionObj = elem.getAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE ); assertThat( expressionObj, is( notNullValue() ) ); assertThat( expressionObj, is( instanceOf( FormulaExpression.class ) ) ); assertThat( ( (FormulaExpression) expressionObj ).getFormula(), is( equalTo( barcodeElemFactory.getFormula() ) ) ); }