From 0420cc1d039a53c8fe74cea6fd4680644b12fa66 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Wed, 6 Apr 2011 17:27:18 -0300 Subject: [PATCH] Replace by dom. --- .../wisemapping/exporter/ExporterFactory.java | 131 +++++++++++------- 1 file changed, 80 insertions(+), 51 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/exporter/ExporterFactory.java b/wise-webapp/src/main/java/com/wisemapping/exporter/ExporterFactory.java index 9b9af051..fdb0302d 100644 --- a/wise-webapp/src/main/java/com/wisemapping/exporter/ExporterFactory.java +++ b/wise-webapp/src/main/java/com/wisemapping/exporter/ExporterFactory.java @@ -50,10 +50,12 @@ public class ExporterFactory { private static final String RECT_NODE_NAME = "rect"; private static final String IMAGE_NODE_NAME = "image"; - private ExporterFactory() { + + private ExporterFactory() throws ParserConfigurationException { + } - 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 { + 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(); @@ -67,10 +69,10 @@ public class ExporterFactory { transcoder.addTranscodingHint(ImageTranscoder.KEY_WIDTH, size.getWidth()); // Create the transcoder input. - char[] xml = convertBrowserSvgToXmlSvg(mapSvg); - xml = normalizeSvg(xml, imgPath); - final CharArrayReader is = new CharArrayReader(xml); - TranscoderInput input = new TranscoderInput(is); + final Document document = normalizeSvg(mapSvg, imgPath); + final String svgString = domToString(document); + final TranscoderInput input = new TranscoderInput(new CharArrayReader(svgString.toCharArray())); + TranscoderOutput trascoderOutput = new TranscoderOutput(output); // Save the image. @@ -88,10 +90,10 @@ public class ExporterFactory { transcoder.addTranscodingHint(ImageTranscoder.KEY_WIDTH, size.getWidth()); // Create the transcoder input. - final char[] xml = convertBrowserSvgToXmlSvg(mapSvg); - char[] svgXml = normalizeSvg(xml, imgPath); - final CharArrayReader is = new CharArrayReader(svgXml); - TranscoderInput input = new TranscoderInput(is); + final Document document = normalizeSvg(mapSvg, imgPath); + final String svgString = domToString(document); + final TranscoderInput input = new TranscoderInput(new CharArrayReader(svgString.toCharArray())); + TranscoderOutput trascoderOutput = new TranscoderOutput(output); // Save the image. @@ -103,10 +105,10 @@ public class ExporterFactory { final Transcoder transcoder = new PDFTranscoder(); // Create the transcoder input. - final char[] xml = convertBrowserSvgToXmlSvg(mapSvg); - char[] svgXml = normalizeSvg(xml, imgPath); - final CharArrayReader is = new CharArrayReader(svgXml); - TranscoderInput input = new TranscoderInput(is); + final Document document = normalizeSvg(mapSvg, imgPath); + final String svgString = domToString(document); + final TranscoderInput input = new TranscoderInput(new CharArrayReader(svgString.toCharArray())); + TranscoderOutput trascoderOutput = new TranscoderOutput(output); // Save the image. @@ -114,9 +116,9 @@ public class ExporterFactory { break; } case SVG: { - final char[] xml = convertBrowserSvgToXmlSvg(mapSvg); - char[] svgXml = normalizeSvg(xml, imgPath); - output.write(new String(svgXml).getBytes("UTF-8")); + final Document dom = normalizeSvg(mapSvg, imgPath); + String s = domToString(dom); + output.write(null); break; } case FREEMIND: { @@ -129,30 +131,39 @@ public class ExporterFactory { } } - private static char[] normalizeSvg(final char[] svgXml, final String imgBaseUrl) throws XMLStreamException, ParserConfigurationException, IOException, SAXException, TransformerException { - final Reader in = new CharArrayReader(svgXml); + private static Document normalizeSvg(String svgXml, final String imgBaseUrl) throws XMLStreamException, ParserConfigurationException, IOException, SAXException, TransformerException { + + final DocumentBuilder documentBuilder = getDocumentBuilder(); + svgXml = svgXml.replaceFirst("]+)>", ""); result = result.replaceAll("]+)//+>", ""); return result.toCharArray(); - } - -} +======= +*/ \ No newline at end of file