Fix scape name with spaces.

This commit is contained in:
Paulo Gustavo Veiga 2013-02-24 17:33:04 -03:00
parent fe331a5170
commit 9ab0637690
4 changed files with 43 additions and 8 deletions

View File

@ -267,7 +267,6 @@ public class FreemindExporter
/* /*
* MindmapFont format : fontName ; size ; color ; bold; italic; * MindmapFont format : fontName ; size ; color ; bold; italic;
* eg: Verdana;10;#ffffff;bold;italic; * eg: Verdana;10;#ffffff;bold;italic;
*
*/ */
private void addFontNode(@NotNull com.wisemapping.jaxb.freemind.Node freemindNode, com.wisemapping.jaxb.wisemap.TopicType mindmapTopic) { private void addFontNode(@NotNull com.wisemapping.jaxb.freemind.Node freemindNode, com.wisemapping.jaxb.wisemap.TopicType mindmapTopic) {
final String fontStyle = mindmapTopic.getFontStyle(); final String fontStyle = mindmapTopic.getFontStyle();

View File

@ -131,9 +131,8 @@ public class TransformerController extends BaseController {
throw new IllegalArgumentException("Unsupported export format"); throw new IllegalArgumentException("Unsupported export format");
} }
// IE does not support spaces in the name... As usual ... if (filename != null) {
if(filename!=null){ result.getModelMap().put("filename", filename);
result.getModelMap().put("filename", filename.replaceAll(" ","_"));
} }
return result; return result;
} }

View File

@ -31,6 +31,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Map; import java.util.Map;
public class ImportTransformationView extends AbstractView { public class ImportTransformationView extends AbstractView {
@ -53,15 +54,32 @@ public class ImportTransformationView extends AbstractView {
final InputStream is = new ByteArrayInputStream(content.getBytes("UTF-8")); final InputStream is = new ByteArrayInputStream(content.getBytes("UTF-8"));
final Mindmap mindMap = importer.importMap("filename", "filename", is); final Mindmap mindMap = importer.importMap("filename", "filename", is);
// Set file name... // Set file name...:http://stackoverflow.com/questions/5325322/java-servlet-download-filename-special-characters/13359949#13359949
final String fileName = (filename != null ? filename : "map") + "." + "xwise"; final String fileName = (filename != null ? filename : "map") + "." + "xwise";
response.setHeader("Content-Disposition", "attachment;filename=" + fileName); setContentDisposition(request, response, fileName);
// Write the conversion content ... // Write the conversion content ...
final ServletOutputStream outputStream = response.getOutputStream(); final ServletOutputStream outputStream = response.getOutputStream();
outputStream.print(mindMap.getXmlStr()); outputStream.print(mindMap.getXmlStr());
} }
private void setContentDisposition(HttpServletRequest request, HttpServletResponse response, String fileName) {
final String userAgent = request.getHeader("user-agent");
String disposition = fileName;
boolean isInternetExplorer = (userAgent.contains("MSIE"));
try {
byte[] fileNameBytes = fileName.getBytes((isInternetExplorer) ? ("windows-1250") : ("utf-8"));
String dispositionFileName = "";
for (byte b : fileNameBytes) {
dispositionFileName += (char) (b & 0xff);
}
disposition = "attachment; filename=\"" + dispositionFileName + "\"";
} catch (UnsupportedEncodingException ence) {
// ... handle exception ...
}
response.setHeader("Content-disposition", disposition);
}
@Override @Override
public String getContentType() { public String getContentType() {
return contentType; return contentType;

View File

@ -33,6 +33,7 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import java.io.UnsupportedEncodingException;
import java.util.Map; import java.util.Map;
public class TransformView extends AbstractView { public class TransformView extends AbstractView {
@ -67,9 +68,9 @@ public class TransformView extends AbstractView {
final String contentType = exportFormat.getContentType(); final String contentType = exportFormat.getContentType();
response.setContentType(contentType); response.setContentType(contentType);
// Set file name... // Set file name...:http://stackoverflow.com/questions/5325322/java-servlet-download-filename-special-characters/13359949#13359949
final String fileName = (filename != null ? filename : "map") + "." + exportFormat.getFileExtension(); final String fileName = (filename != null ? filename : "map") + "." + exportFormat.getFileExtension();
response.setHeader("Content-Disposition", "attachment;filename=" + fileName); setContentDisposition(request, response, fileName);
// Change image link URL. // Change image link URL.
final ServletContext servletContext = request.getSession().getServletContext(); final ServletContext servletContext = request.getSession().getServletContext();
@ -93,6 +94,24 @@ public class TransformView extends AbstractView {
} }
} }
private void setContentDisposition(HttpServletRequest request, HttpServletResponse response, String fileName) {
final String userAgent = request.getHeader("user-agent");
boolean isInternetExplorer = (userAgent.contains("MSIE"));
String disposition = fileName;
try {
byte[] fileNameBytes = fileName.getBytes((isInternetExplorer) ? ("windows-1250") : ("utf-8"));
String dispositionFileName = "";
for (byte b : fileNameBytes) {
dispositionFileName += (char) (b & 0xff);
}
disposition = "attachment; filename=\"" + dispositionFileName + "\"";
} catch (UnsupportedEncodingException ence) {
// ... handle exception ...
}
response.setHeader("Content-disposition", disposition);
}
@Override @Override
public String getContentType() { public String getContentType() {
return contentType; return contentType;