Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 7 additions & 29 deletions src/java/fr/paris/lutece/portal/util/mvc/xpage/MVCApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -758,29 +759,7 @@ protected String getActionFullUrl( String strAction )
*/
protected XPage download( String strData, String strFilename, String strContentType )
{
HttpServletResponse response = LocalVariables.getResponse( );
PrintWriter out = null;
response.setHeader( "Content-Disposition", "attachment; filename=\"" + strFilename + "\";" );
MVCUtils.addDownloadHeaderToResponse( response, strFilename, strContentType );

try
{
out = response.getWriter( );
out.print( strData );
}
catch( IOException e )
{
AppLogService.error( e.getStackTrace( ), e );
}
finally
{
if ( out != null )
{
out.close( );
}
}

return new XPage( );
return download( strData.getBytes( StandardCharsets.UTF_8 ), strFilename, strContentType );
}

/**
Expand All @@ -797,21 +776,20 @@ protected XPage download( String strData, String strFilename, String strContentT
protected XPage download( byte [ ] data, String strFilename, String strContentType )
{
HttpServletResponse response = LocalVariables.getResponse( );
OutputStream os;
MVCUtils.addDownloadHeaderToResponse( response, strFilename, strContentType );

try
try ( OutputStream os = response.getOutputStream( ) )
{
os = response.getOutputStream( );
os.write( data );
os.close( );
}
catch( IOException e )
{
AppLogService.error( e.getStackTrace( ), e );
AppLogService.error( "An error occured while writing the downloaded data", e );
}

return new XPage( );
XPage xPage = new XPage( );
xPage.setStandalone( true );
return xPage;
}

/**
Expand Down
8 changes: 5 additions & 3 deletions webapp/jsp/site/Portal.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
try
{
String strContent = portal.getContent( request );

out.print( strContent );
out.flush();
if ( strContent != null && strContent.length( ) > 0 )
{
out.print( strContent );
out.flush();
}
}
catch ( PageNotFoundException pnfe )
{
Expand Down