assert reportDocument != null;  OutputStream out = os; if ( out == null ) out = new ByteArrayOutputStream( );   IRenderTask renderTask = engine.createRenderTask( reportDocument );   BirtUtility.addTask( request, renderTask );  HashMap context = new HashMap( ); String format = ParameterAccessor.getFormat( request ); if ( format.equalsIgnoreCase( ParameterAccessor.PARAM_FORMAT_PDF ) ) { context.put( EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT, createPDFrenderContext( request.getServletPath( ) ) ); } else { context .put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT, createHTMLrenderContext( svgFlag, request .getServletPath( ) ) ); } context.put( EngineConstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVET_REQUEST, request ); context.put( EngineConstants.APPCONTEXT_CLASSLOADER_KEY, ReportEngineService.class.getClassLoader( ) );   ParameterAccessor.pushAppContext( context, request );  renderTask.setAppContext( context );   HTMLRenderOption setting = new HTMLRenderOption( ); setting.setOutputStream( out ); if ( format.equalsIgnoreCase( ParameterAccessor.PARAM_FORMAT_PDF ) ) { setting.setOutputFormat( IBirtConstants.PDF_RENDER_FORMAT ); setting.setActionHandle( new ViewerHTMLActionHandler( reportDocument, -1, locale, false, rtl, masterPage ) ); } else { setting.setOutputFormat( IBirtConstants.HTML_RENDER_FORMAT ); boolean isEmbeddable = false; if ( ParameterAccessor.SERVLET_PATH_FRAMESET .equalsIgnoreCase( request.getServletPath( ) ) ) isEmbeddable = true; setting.setEmbeddable( isEmbeddable ); setting.setHtmlRtLFlag( rtl ); setting.setInstanceIDs( activeIds ); setting.setMasterPageContent( masterPage ); setting .setActionHandle( new ViewerHTMLActionHandler( reportDocument, -1, locale, isEmbeddable, rtl, masterPage ) ); }  renderTask.setRenderOption( setting ); renderTask.setLocale( locale );   try { if ( ParameterAccessor.isIidReportlet( request ) ) { InstanceID instanceId = InstanceID.parse( reportletId ); renderTask.setInstanceID( instanceId ); } else { renderTask.setReportlet( reportletId ); } if ( format.equalsIgnoreCase( ParameterAccessor.PARAM_FORMAT_PDF ) ) renderTask.render( ); else { renderTask.render( ); } } catch ( BirtException e ) { AxisFault fault = new AxisFault( e.getLocalizedMessage( ) ); fault.setFaultCode( new QName( "ReportEngineService.renderReport( )" ) ); fault.setFaultString( e.getLocalizedMessage( ) ); throw fault; } catch ( Exception e ) { AxisFault fault = new AxisFault( e.getLocalizedMessage( ) ); fault.setFaultCode( new QName( "ReportEngineService.renderReport( )" ) ); fault.setFaultString( e.getLocalizedMessage( ) ); throw fault; } finally {  BirtUtility.removeTask( request ); renderTask.close( ); }
renderReportlet( os, request, reportDocument, reportletId, masterPage, svgFlag, activeIds, locale, rtl, null );
	public void renderReportlet( OutputStream os, HttpServletRequest request,			IReportDocument reportDocument, String reportletId,			boolean masterPage, boolean svgFlag, List activeIds, Locale locale,			boolean rtl ) throws RemoteException	{		assert reportDocument != null;		OutputStream out = os;		if ( out == null )			out = new ByteArrayOutputStream( );		// Create render task.		IRenderTask renderTask = engine.createRenderTask( reportDocument );		// add task into session		BirtUtility.addTask( request, renderTask );		HashMap context = new HashMap( );		String format = ParameterAccessor.getFormat( request );		if ( format.equalsIgnoreCase( ParameterAccessor.PARAM_FORMAT_PDF ) )		{			context.put( EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT,					createPDFrenderContext( request.getServletPath( ) ) );		}		else		{			context					.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,							createHTMLrenderContext( svgFlag, request									.getServletPath( ) ) );		}		context.put( EngineConstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVET_REQUEST,				request );		context.put( EngineConstants.APPCONTEXT_CLASSLOADER_KEY,				ReportEngineService.class.getClassLoader( ) );		// Push user-defined application context		ParameterAccessor.pushAppContext( context, request );		renderTask.setAppContext( context );		// Render option		HTMLRenderOption setting = new HTMLRenderOption( );		setting.setOutputStream( out );		if ( format.equalsIgnoreCase( ParameterAccessor.PARAM_FORMAT_PDF ) )		{			setting.setOutputFormat( IBirtConstants.PDF_RENDER_FORMAT );			setting.setActionHandle( new ViewerHTMLActionHandler(					reportDocument, -1, locale, false, rtl, masterPage ) );		}		else		{			setting.setOutputFormat( IBirtConstants.HTML_RENDER_FORMAT );			boolean isEmbeddable = false;			if ( ParameterAccessor.SERVLET_PATH_FRAMESET					.equalsIgnoreCase( request.getServletPath( ) ) )				isEmbeddable = true;			setting.setEmbeddable( isEmbeddable );			setting.setHtmlRtLFlag( rtl );			setting.setInstanceIDs( activeIds );			setting.setMasterPageContent( masterPage );			setting					.setActionHandle( new ViewerHTMLActionHandler(							reportDocument, -1, locale, isEmbeddable, rtl,							masterPage ) );		}		renderTask.setRenderOption( setting );		renderTask.setLocale( locale );		// Render designated page.		try		{			if ( ParameterAccessor.isIidReportlet( request ) )			{				InstanceID instanceId = InstanceID.parse( reportletId );				renderTask.setInstanceID( instanceId );			}			else			{				renderTask.setReportlet( reportletId );			}			if ( format.equalsIgnoreCase( ParameterAccessor.PARAM_FORMAT_PDF ) )				renderTask.render( );			else			{				renderTask.render( );			}		}		catch ( BirtException e )		{			AxisFault fault = new AxisFault( e.getLocalizedMessage( ) );			fault.setFaultCode( new QName(					"ReportEngineService.renderReport( )" ) ); //$NON-NLS-1$			fault.setFaultString( e.getLocalizedMessage( ) );			throw fault;		}		catch ( Exception e )		{			AxisFault fault = new AxisFault( e.getLocalizedMessage( ) );			fault.setFaultCode( new QName(					"ReportEngineService.renderReport( )" ) ); //$NON-NLS-1$			fault.setFaultString( e.getLocalizedMessage( ) );			throw fault;		}		finally		{			// Remove task from http session			BirtUtility.removeTask( request );			renderTask.close( );		}	}