/** * Returns a string representation of the band, useful mainly for debugging purposes. * * @return a string representation of this band. */ public String toString() { final StringBuilder b = new StringBuilder( 100 ); b.append( this.getClass().getName() ); b.append( "={name=\"" ); b.append( getName() ); b.append( "\", type=\"" ); b.append( getElementTypeName() ); b.append( "\"}" ); return b.toString(); }
/** * Returns the first element in the list that is known by the given name. Functions should use * {@link org.pentaho.reporting.engine.classic.core.function.FunctionUtilities#findAllElements(Band, String)} or * {@link org.pentaho.reporting.engine.classic.core.function.FunctionUtilities#findElement(Band, String)} instead. * * @param name * the element name. * @return the first element with the specified name, or <code>null</code> if there is no such element. * @throws NullPointerException * if the given name is null. */ public Element getElement( final String name ) { if ( name == null ) { throw new NullPointerException( "Band.getElement(...): name is null." ); } final Element[] elements = internalGetElementArray(); final int elementsSize = elements.length; for ( int i = 0; i < elementsSize; i++ ) { final Element e = elements[i]; final String elementName = e.getName(); if ( elementName != null ) { if ( elementName.equals( name ) ) { return e; } } } return null; }
for ( int i = 0; i < elements.length; i++ ) { final Element e = elements[i]; if ( element.equals( e.getName() ) ) { return e;
/** * Internal function that collects all elements of a given band with a given name. * * @param band * the band from which elements should be collected. * @param element * the name of the element to collect. * @param collector * the list of results. */ private static void performFindElement( final Band band, final String element, final ArrayList<Element> collector ) { final int count = band.getElementCount(); final Element[] buffer = band.getElementArray(); for ( int i = 0; i < count; i++ ) { final Element e = buffer[i]; if ( e.getName().equals( element ) ) { collector.add( e ); } if ( e instanceof Band ) { performFindElement( (Band) e, element, collector ); } } }
/** * Writes the band's elements into the assigned Writer. * * @param b * the band that should be written. * @throws IOException * if an IO-Error occurs. */ private void writeBand( final Band b ) throws IOException { final Element[] elementBuffer = b.unsafeGetElementArray(); final int elementCount = elementBuffer.length; for ( int i = 0; i < elementCount; i++ ) { final Element e = elementBuffer[i]; if ( e instanceof Band ) { w.write( "<band>" ); writeBand( (Band) e ); w.write( "</band>" ); } else { w.write( "<element name=\"" ); w.write( entityParser.encodeEntities( e.getName() ) ); w.write( "\">" ); final String value = String.valueOf( e.getElementType().getValue( getRuntime(), e ) ); w.write( entityParser.encodeEntities( value ) ); w.write( "</element>" ); } } }
/** * Writes an element to a character stream writer. * * @param element * the element. * @throws IOException * if there is an I/O problem. * @throws ReportWriterException * if there is a problem writing the report. */ private void writeElement( final Element element ) throws IOException, ReportWriterException { final AttributeList attList = new AttributeList(); if ( element.getName().startsWith( Element.ANONYMOUS_ELEMENT_PREFIX ) == false ) { attList.setAttribute( ExtParserModule.NAMESPACE, "name", element.getName() ); } final XmlWriter writer = getXmlWriter(); writer.writeTag( ExtParserModule.NAMESPACE, ReportDescriptionWriter.ELEMENT_TAG, attList, XmlWriterSupport.OPEN ); writeStyleInfo( element ); writeDataSourceForElement( element ); writer.writeCloseTag(); }
public void testGetElement() { Band band = new Band(); try { band.getElement( null ); fail( "should throw exception" ); } catch ( NullPointerException e ) { // expected } Element elem = mock( Element.class ); doReturn( "test_name" ).when( elem ).getName(); band.addElement( elem ); assertEquals( 1, band.getElementCount() ); assertEquals( elem, band.getElement( "test_name" ) ); }
public void testElementCreate() { final Element e = new Element(); assertNotNull( e.getDataSource() ); assertNotNull( e.getStyle() ); assertNotNull( e.getName() ); assertTrue( e.isVisible() ); assertNull( e.getParent() ); }
public void testElementClone() throws CloneNotSupportedException { final Band band = new Band(); final Element e = new Element(); band.addElement( e ); assertNotNull( e.getParent() ); assertNotNull( e.getDataSource() ); assertNotNull( e.getStyle() ); assertNotNull( e.getName() ); assertTrue( e.isVisible() ); final Element clone = (Element) e.clone(); assertNull( clone.getParent() ); assertNotNull( clone.getDataSource() ); assertNotNull( clone.getStyle() ); assertNotNull( clone.getName() ); assertTrue( clone.isVisible() ); final Band clonedBand = (Band) band.clone(); assertNull( clonedBand.getParent() ); assertNotNull( clonedBand.getDataSource() ); assertNotNull( clonedBand.getStyle() ); assertNotNull( clonedBand.getName() ); assertTrue( clonedBand.isVisible() ); final Element clientElement = clonedBand.getElement( 0 ); assertNotNull( clientElement.getParent() ); assertNotNull( clientElement.getDataSource() ); assertNotNull( clientElement.getStyle() ); assertNotNull( clientElement.getName() ); assertTrue( clientElement.isVisible() ); assertEquals( clonedBand, clientElement.getParent() ); }