Merge branch 'master' of ssh://wisemapping.com/var/git-repos/wise-source

This commit is contained in:
Pablo Luna 2011-04-06 10:47:53 +01:00
commit a349672170
7 changed files with 35 additions and 50 deletions

View File

@ -19,6 +19,7 @@
package com.wisemapping.controller;
import com.wisemapping.exporter.ExportFormat;
import com.wisemapping.exporter.ExporterFactory;
import com.wisemapping.model.MindMap;
import com.wisemapping.service.MindmapService;
import com.wisemapping.view.MindMapBean;
@ -60,6 +61,11 @@ public class ExportController extends BaseMultiActionController {
int mindmapId = Integer.parseInt(mapIdStr);
final String mapSvg = request.getParameter(MAP_SVG_PARAMETER);
logger.debug("SVG Map to export:"+mapSvg);
if(mapSvg==null || mapSvg.isEmpty())
{
throw new IllegalArgumentException("SVG map could not be null");
}
String formatStr = request.getParameter(EXPORT_FORMAT_PARAMETER);
if (IMG_EXPORT_FORMAT.endsWith(formatStr)) {
@ -96,7 +102,7 @@ public class ExportController extends BaseMultiActionController {
// Write content ...
final ServletOutputStream outputStream = response.getOutputStream();
mindMap.export(properties, outputStream, mapSvg);
ExporterFactory.export(properties, mindMap, outputStream, mapSvg);
} catch (Throwable e) {
@ -141,9 +147,7 @@ public class ExportController extends BaseMultiActionController {
final String mapIdStr = request.getParameter(MAP_ID_PARAMETER);
final String mapSvg = request.getParameter(MAP_SVG_PARAMETER);
int mindmapId = Integer.parseInt(mapIdStr);
final MindmapService service = getMindmapService();
final MindMap mindMap = service.getMindmapById(mindmapId);
//Image Format
ExportFormat imageFormat = ExportFormat.PNG;
@ -160,7 +164,7 @@ public class ExportController extends BaseMultiActionController {
// Write content ...
final ServletOutputStream outputStream = response.getOutputStream();
mindMap.export(imageProperties, outputStream, mapSvg);
ExporterFactory.export(imageProperties, null, outputStream, mapSvg);
} catch (Throwable e) {

View File

@ -18,7 +18,6 @@
package com.wisemapping.exporter;
import com.wisemapping.exporter.freemind.FreemindExporter;
import com.wisemapping.model.MindMap;
import org.apache.batik.transcoder.Transcoder;
import org.apache.batik.transcoder.TranscoderException;
@ -28,6 +27,8 @@ import org.apache.batik.transcoder.image.ImageTranscoder;
import org.apache.batik.transcoder.image.JPEGTranscoder;
import org.apache.batik.transcoder.image.PNGTranscoder;
import org.apache.fop.svg.PDFTranscoder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.w3c.dom.*;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@ -44,15 +45,15 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.*;
public class SvgExporter {
public class ExporterFactory {
private static final String GROUP_NODE_NAME = "g";
private static final String RECT_NODE_NAME = "rect";
private static final String IMAGE_NODE_NAME = "image";
private SvgExporter() {
private ExporterFactory() {
}
public static void export(ExportProperties properties, MindMap map, OutputStream output, String mapSvg) throws TranscoderException, IOException, ParserConfigurationException, SAXException, XMLStreamException, TransformerException, JAXBException, ExportException {
public static void export(@NotNull ExportProperties properties, @Nullable MindMap map, @NotNull OutputStream output, @NotNull String mapSvg) throws TranscoderException, IOException, ParserConfigurationException, SAXException, XMLStreamException, TransformerException, JAXBException, ExportException {
final ExportFormat format = properties.getFormat();
final String imgPath = properties.getBaseImgPath();
@ -66,7 +67,7 @@ public class SvgExporter {
transcoder.addTranscodingHint(ImageTranscoder.KEY_WIDTH, size.getWidth());
// Create the transcoder input.
char[] xml = map.generateSvgXml(mapSvg);
char[] xml = convertBrowserSvgToXmlSvg(mapSvg);
xml = normalizeSvg(xml, imgPath);
final CharArrayReader is = new CharArrayReader(xml);
TranscoderInput input = new TranscoderInput(is);
@ -87,7 +88,7 @@ public class SvgExporter {
transcoder.addTranscodingHint(ImageTranscoder.KEY_WIDTH, size.getWidth());
// Create the transcoder input.
final char[] xml = map.generateSvgXml(mapSvg);
final char[] xml = convertBrowserSvgToXmlSvg(mapSvg);
char[] svgXml = normalizeSvg(xml, imgPath);
final CharArrayReader is = new CharArrayReader(svgXml);
TranscoderInput input = new TranscoderInput(is);
@ -102,7 +103,7 @@ public class SvgExporter {
final Transcoder transcoder = new PDFTranscoder();
// Create the transcoder input.
final char[] xml = map.generateSvgXml(mapSvg);
final char[] xml = convertBrowserSvgToXmlSvg(mapSvg);
char[] svgXml = normalizeSvg(xml, imgPath);
final CharArrayReader is = new CharArrayReader(svgXml);
TranscoderInput input = new TranscoderInput(is);
@ -113,7 +114,7 @@ public class SvgExporter {
break;
}
case SVG: {
final char[] xml = map.generateSvgXml(mapSvg);
final char[] xml = convertBrowserSvgToXmlSvg(mapSvg);
char[] svgXml = normalizeSvg(xml, imgPath);
output.write(new String(svgXml).getBytes("UTF-8"));
break;
@ -277,4 +278,16 @@ public class SvgExporter {
final String transate = value.substring(initTranslate + 1, endTranslate);
return transate.split(",");
}
@NotNull
static private char[] convertBrowserSvgToXmlSvg(@NotNull String mapSvg)
throws IOException, JAXBException {
String result = "<?xml version='1.0' encoding='UTF-8'?>\n" + mapSvg;
// Add namespace...
result = result.replaceFirst("<svg ", "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" ");
return result.toCharArray();
}
}

View File

@ -16,7 +16,7 @@
* limitations under the License.
*/
package com.wisemapping.exporter.freemind;
package com.wisemapping.exporter;
import com.wisemapping.exporter.ExportException;
import com.wisemapping.exporter.Exporter;

View File

@ -27,23 +27,10 @@
package com.wisemapping.model;
import com.wisemapping.exporter.ExportProperties;
import com.wisemapping.exporter.SvgExporter;
import com.wisemapping.util.ZipUtils;
import com.wisemapping.xml.VmlToSvgConverter;
import com.wisemapping.exporter.ExportException;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.log4j.Logger;
import org.xml.sax.SAXException;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLStreamException;
import javax.xml.transform.TransformerException;
import java.io.CharArrayReader;
import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
@ -215,20 +202,6 @@ public class MindMap {
return tags;
}
public char[] generateSvgXml(String mapSvg)
throws IOException, JAXBException {
String svgText = mapSvg;
String result = "<?xml version='1.0' encoding='UTF-8'?>\n" + svgText;
// Add namespace...
result = result.replaceFirst("<svg ", "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" ");
// result = result.replaceAll("<image([^>]+)>", "<image$1/>");
return result.toCharArray();
}
public String getDescription() {
return description;
}
@ -245,10 +218,6 @@ public class MindMap {
this.creationTime = creationTime;
}
public void export(final ExportProperties properties, OutputStream output, String mapSvg) throws JAXBException, TranscoderException, TransformerException, IOException, ParserConfigurationException, ExportException, SAXException, XMLStreamException {
SvgExporter.export(properties, this, output, mapSvg);
}
public void setOwner(User owner) {
this.owner = owner;
}

View File

@ -3,6 +3,7 @@ package com.wisemapping.test.export;
import com.wisemapping.exporter.ExportException;
import com.wisemapping.exporter.ExportFormat;
import com.wisemapping.exporter.ExportProperties;
import com.wisemapping.exporter.ExporterFactory;
import com.wisemapping.importer.ImporterException;
import com.wisemapping.model.MindMap;
@ -45,12 +46,10 @@ public class ExportTest {
properties.setBaseImagePath(baseUrl);
// Write content ...
MindMap mindMap = new MindMap();
if(pngFile.exists()){
// Export mile content ...
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
mindMap.export(properties, bos, svgXml);
ExporterFactory.export(imageProperties, null, bos, svgXml);
// Load rec file co
final FileInputStream fis = new FileInputStream(pngFile);
@ -82,7 +81,7 @@ public class ExportTest {
}
else{
OutputStream outputStream = new FileOutputStream(pngFile, false);
mindMap.export(properties, outputStream, svgXml);
ExporterFactory.export(imageProperties, null, outputStream, svgXml);
outputStream.close();
}
}

View File

@ -1,7 +1,7 @@
package com.wisemapping.test.freemind;
import com.wisemapping.exporter.ExportException;
import com.wisemapping.exporter.freemind.FreemindExporter;
import com.wisemapping.exporter.FreemindExporter;
import com.wisemapping.importer.ImporterException;
import com.wisemapping.model.MindMap;

View File

@ -1,7 +1,7 @@
package com.wisemapping.test.freemind;
import com.wisemapping.exporter.ExportException;
import com.wisemapping.exporter.freemind.FreemindExporter;
import com.wisemapping.exporter.FreemindExporter;
import com.wisemapping.importer.ImportFormat;
import com.wisemapping.importer.Importer;
import com.wisemapping.importer.ImporterException;