/*******************************************************************************
 * Copyright (c) 2005,2008 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.report.engine.script.internal;

import java.io.Serializable;
import java.net.URL;
import java.util.Locale;
import java.util.Map;

import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.IEngineTask;
import org.eclipse.birt.report.engine.api.IRenderOption;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.script.IReportContext;
import org.eclipse.birt.report.engine.executor.ExecutionContext;
import org.eclipse.birt.report.model.api.ReportDesignHandle;

import com.ibm.icu.text.MessageFormat;
import com.ibm.icu.util.TimeZone;

/**
 * Implementation of the IReportContext interface
 */
public class ReportContextImpl implements IReportContext
{

	protected ExecutionContext context;

	public ReportContextImpl( ExecutionContext context )
	{
		this.context = context;
	}

	public IReportRunnable getReportRunnable( )
	{
		return context.getRunnable( );
	}

	public Map getAppContext( )
	{
		return context.getAppContext( );
	}

	public void setAppContext( Map appContext )
	{
		context.setAppContext( appContext );
	}

	public void setGlobalVariable( String name, Object obj )
	{
		context.registerBean( name, obj );
	}

	public void deleteGlobalVariable( String name )
	{
		context.registerBean( name, null );
	}

	public Object getGlobalVariable( String name )
	{
		return context.getBeans( ).get( name );
	}

	public void setPersistentGlobalVariable( String name, Serializable obj )
	{
		context.registerGlobalBean( name, obj );
	}

	public void deletePersistentGlobalVariable( String name )
	{
		context.unregisterGlobalBean( name );
	}

	public Object getPersistentGlobalVariable( String name )
	{
		return context.getGlobalBeans( ).get( name );
	}

	public void setRegisteredPersistantObjects( Map persistantMap )
	{
		context.registerBeans( persistantMap );
	}

	public Object getParameterValue( String name )
	{
		return context.getParameterValue( name );
	}

	public void setParameterValue( String name, Object value )
	{
		context.setParameterValue( name, value );
	}

	public Locale getLocale( )
	{
		return context.getLocale( );
	}

	public TimeZone getTimeZone( )
	{
		return context.getTimeZone( );
	}

	public String getOutputFormat( )
	{
		return context.getOutputFormat( );
	}

	public IRenderOption getRenderOption( )
	{
		return context.getRenderOption( );
	}

	public Object getHttpServletRequest( )
	{
		return getAppContext( ).get(
				EngineConstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVET_REQUEST );
	}

	public String getMessage( String key )
	{
		return context.getDesign( ).getMessage( key );
	}

	public String getMessage( String key, Locale locale )
	{
		return context.getDesign( ).getMessage( key, locale );
	}

	public String getMessage( String key, Object[] params )
	{
		String msg = context.getDesign( ).getMessage( key );
		if ( msg == null )
			return "";
		return MessageFormat.format( msg, params );
	}

	public String getMessage( String key, Locale locale, Object[] params )
	{
		String msg = context.getDesign( ).getMessage( key, locale );
		if ( msg == null )
			return "";
		return MessageFormat.format( msg, params );
	}

	public String getParameterDisplayText( String name )
	{
		return context.getParameterDisplayText( name );
	}

	public void setParameterDisplayText( String name, String displayText )
	{
		context.setParameterDisplayText( name, displayText );
	}

	public int getTaskType( )
	{
		IEngineTask task = context.getEngineTask( );
		if ( task != null )
		{
			return task.getTaskType( );
		}
		return IEngineTask.TASK_UNKNOWN;
	}

	public ReportDesignHandle getDesignHandle( )
	{
		return (ReportDesignHandle) getReportRunnable( ).getDesignHandle( );
	}

	public URL getResource( String resourceName )
	{
		return context.getResource( resourceName );
	}

	public Object evaluate( String script ) throws BirtException
	{
		if ( null != script && script.length( ) > 0 )
		{
			return context.evaluate( script );
		}
		return null;
	}
}

@@ -3769,39 +3769,32 @@
 %09%09%09return %22%22;%0A%09%09
-return 
 MessageFormat.fo
@@ -3786,32 +3786,97 @@
 essageFormat
+ formatter = new MessageFormat( msg, locale );%0A%09%09return formatter
 .format(
  msg, params
@@ -3859,37 +3859,69 @@
 tter.format(
- msg,
  params
- 
+, new StringBuffer(), null ).toString(
 );%0A%09%7D%0A%0A%09publ

Fix bugzilla bug 194246 Internationalized messages do not work correctly when supplying arguments.