Change export controller path and keep compatibility with old SVG images.

This commit is contained in:
Paulo Gustavo Veiga 2011-03-28 02:55:54 -03:00
parent 9849414abb
commit 5d939a1e78
2 changed files with 15 additions and 9 deletions

View File

@ -25,6 +25,7 @@ import com.wisemapping.view.MindMapBean;
import com.wisemapping.exporter.ExportProperties;
import com.wisemapping.filter.UserAgent;
import org.apache.batik.transcoder.TranscoderException;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
@ -106,14 +107,14 @@ public class ExportController extends BaseMultiActionController {
return null;
}
private void setBaseBaseImgUrl(ExportFormat format, ExportProperties properties) {
private void setBaseBaseImgUrl(ExportFormat format, @NotNull ExportProperties properties) {
final String baseUrl;
if (format == ExportFormat.SVG) {
baseUrl = "http://www.wisemapping.com/images";
} else {
final ServletContext servletContext = this.getServletContext();
baseUrl = "file://" + servletContext.getRealPath("/images/");
baseUrl = "file://" + servletContext.getRealPath("/icons/");
}
properties.setBaseImagePath(baseUrl);
}

View File

@ -187,13 +187,18 @@ public class SvgExporter {
Element elem = (Element) node;
// Cook image href ...
String imgName = elem.getAttribute("href");
int index = imgName.lastIndexOf("/");
final String imgUrl = elem.getAttribute("href");
int index = imgUrl.lastIndexOf("/");
elem.removeAttribute("href");
if (index != -1)
{
imgName = imgName.substring(index);
final String imgPath = imgBaseUrl + imgName;
if (index != -1) {
final String iconName = imgUrl.substring(index);
// Hack for backward compatibility . This can be removed in 2012. :)
String imgPath;
if (imgUrl.contains("images")) {
imgPath = imgBaseUrl + "../images/" + imgUrl;
} else {
imgPath = imgBaseUrl + imgUrl;
}
elem.setAttribute("xlink:href", imgPath);
}
}
@ -231,7 +236,7 @@ public class SvgExporter {
final NodeList groupChildren = node.getChildNodes();
for (int idx = 0; idx < groupChildren.getLength(); idx++) {
final Node rectNode = groupChildren.item(idx);
float curentHeight = 0 ;
float curentHeight = 0;
float curentWidth = 0;
// If has a rect use the rect to calcular the real width of the topic