* @throws Exception
* if there was a problem creating the content
*/
public static String getContentAsString( IContentGenerator cg ) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOutputHandler outputHandler = new SimpleOutputHandler( out, false );
Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
SimpleParameterProvider requestParams = new SimpleParameterProvider();
parameterProviders.put( IParameterProvider.SCOPE_REQUEST, requestParams );
SimpleUrlFactory urlFactory = new SimpleUrlFactory( "?" ); //$NON-NLS-1$
List<String> messages = new ArrayList<String>();
cg.setOutputHandler( outputHandler );
IMimeTypeListener mimeTypeListener = new IMimeTypeListener() {
@SuppressWarnings( "unused" )
public String mimeType = null;
@SuppressWarnings( "unused" )
public String name = null;
public void setMimeType( String mimeType ) {
this.mimeType = mimeType;
}
public void setName( String name ) {
this.name = name;
}
};
outputHandler.setMimeTypeListener( mimeTypeListener );
cg.setMessagesList( messages );
cg.setParameterProviders( parameterProviders );
cg.setSession( PentahoSessionHolder.getSession() );
cg.setUrlFactory( urlFactory );
cg.createContent();