formattedStr );
formattedStr, content );
	private void evaluateEmbeddedExpression( Node node, TextItemDesign text,			TextItemContent content, HTMLProcessor htmlProcessor )	{		if ( node.getNodeType( ) == Node.ELEMENT_NODE )		{			Element ele = (Element) node;			if ( node.getNodeName( ).equals( "img" ) ) //$NON-NLS-1$			{				String src = ele.getAttribute( "src" ); //$NON-NLS-1$				if ( FileUtil.isLocalResource( src ) )				{					src = FileUtil.getAbsolutePath( context.getReport( )							.getBasePath( ), src );					ele.removeAttribute( "src" ); //$NON-NLS-1$					ImageItemContent imgContent = (ImageItemContent)ContentFactory							.createImageContent( null, content );					content.addImageContent( node, imgContent );					imgContent.setImageSource( ImageItemDesign.IMAGE_FILE );					imgContent.setUri( src );					imgContent.setExtension( FileUtil.getExtFromFileName( src,							FileUtil.SEPARATOR_PATH ) );				}			}			else if ( node.getNodeName( ).equals( "value-of" ) ) //$NON-NLS-1$			{				String strExpr = node.getFirstChild( ).getNodeValue( );				IBaseExpression expr = text.getExpression( strExpr );				Object value;				if ( expr != null )				{					value = context.evaluate( expr );				}				else				{					value = context.evaluate( strExpr );				}				if ( value != null )				{					String format = ( (Element) ( node ) )							.getAttribute( "format" ); //$NON-NLS-1$					//TODO Only the type string and blob are done in the format					// of HTML, or else only string type.					if ( "html".equals( format ) ) //$NON-NLS-1$					{						//parse the value to get the DOM tree						Document doc = null;						if ( value.getClass( ).isArray( )								&& value.getClass( ).getComponentType( ) == byte.class )						{							byte[] blob = (byte[]) value;							doc = new TextParser( ).parse(									new ByteArrayInputStream( blob ), "html" ); //$NON-NLS-1$						}						else						{							doc = new TextParser( ).parse( value.toString( ),									"html" ); //$NON-NLS-1$						}						if ( doc != null )						{							Element body = null;							if ( doc.getFirstChild( ) instanceof Element )							{								body = (Element) doc.getFirstChild( );							}							if ( body != null )							{								htmlProcessor.execute( body, content );								content.addExpressionVal( node, doc );							}						}					}					else					{						StringBuffer formattedStr = new StringBuffer( );						//Uses the ROM style of design because the						// format-related styles are constant, which are the						// same as those of the content.						formatValue( value, format, text.getStyle( ),								formattedStr );						Element appendedNode = null;						Document textDoc;						try						{							textDoc = DocumentBuilderFactory.newInstance( )									.newDocumentBuilder( ).newDocument( );							if ( textDoc != null									&& textDoc.getFirstChild( ) != null									&& textDoc.getFirstChild( ) instanceof Element )							{								( (Element) ( textDoc.getFirstChild( ) ) )										.setAttribute( "text-type", //$NON-NLS-1$												TextParser.TEXT_TYPE_PLAIN );							}							appendedNode = textDoc.createElement( "body" ); //$NON-NLS-1$							textDoc.appendChild( appendedNode );							appendedNode									.appendChild( textDoc											.createTextNode( formattedStr													.toString( ) ) );							content.addExpressionVal( node, textDoc );						}						catch ( ParserConfigurationException e )						{							logger									.log(											Level.SEVERE,											"[TextItemExecutor] Fails to create document for value-of", //$NON-NLS-1$											e );						}						catch ( FactoryConfigurationError e )						{							logger									.log(											Level.SEVERE,											"[TextItemExecutor] Fails to create document for value-of", //$NON-NLS-1$											e );						}					}				}				return;			}			else if ( node.getNodeName( ).equals( "image" ) ) //$NON-NLS-1$			{				ImageItemContent image = (ImageItemContent)ContentFactory						.createImageContent( null, content );				//Get the image content				String imageType = ( (Element) ( node ) ).getAttribute( "type" ); //$NON-NLS-1$				if ( "expr".equalsIgnoreCase( imageType ) ) //$NON-NLS-1$				{					image.setImageSource( ImageItemDesign.IMAGE_EXPRESSION );					//The image is from data source					String strExpression = node.getFirstChild( ).getNodeValue( );					Object value = context.evaluate( text							.getExpression( strExpression ) );					if ( value != null							&& value.getClass( ).isArray( )							&& value.getClass( ).getComponentType( ) == byte.class )					{						image.setData( (byte[]) value );					}				}				else				{					//The image is an embedded one.					String name = ( (Element) ( node ) ).getAttribute( "name" ); //$NON-NLS-1$					EmbeddedImage embeddedImage = context.getReport( )							.getReportDesign( ).findImage( name );					if ( embeddedImage != null )					{						image.setData( embeddedImage.getData( ) );						image.setImageSource( ImageItemDesign.IMAGE_NAME );						image.setUri( name );						String extension = FileUtil								.getExtFromType( embeddedImage.getType( ) );						if ( extension == null )						{							extension = FileUtil.getExtFromFileName( name,									FileUtil.SEPARATOR_PATH );						}						image.setExtension( extension );					}				}				if ( image.getData( ) != null )				{					try					{						Document imgDoc;						imgDoc = DocumentBuilderFactory.newInstance( )								.newDocumentBuilder( ).newDocument( );						Element body = imgDoc.createElement( "body" ); //$NON-NLS-1$						Element imgNode = imgDoc.createElement( "img" ); //$NON-NLS-1$						content.addImageContent( imgNode, image );						// add image node to DOM tree						body.appendChild( imgNode );						imgDoc.appendChild( body );						content.addExpressionVal( node, imgDoc );					}					catch ( ParserConfigurationException e )					{						logger								.log(										Level.SEVERE,										"[TextItemExecutor] Fails to create document for img", //$NON-NLS-1$										e );					}					catch ( FactoryConfigurationError e )					{						logger								.log(										Level.SEVERE,										"[TextItemExecutor] Fails to create document for img", //$NON-NLS-1$										e );					}				}				else				{					logger.log( Level.SEVERE,							"can't handle image element in HTML" ); //$NON-NLS-1$				}				return;			}			// call recursively			for ( Node child = node.getFirstChild( ); child != null; child = child					.getNextSibling( ) )			{				evaluateEmbeddedExpression( child, text, content, htmlProcessor );			}		}	}