Remove trunk directory
This commit is contained in:
29
wise-webapp/src/main/java/com/wisemapping/exporter/ExportException.java
Executable file
29
wise-webapp/src/main/java/com/wisemapping/exporter/ExportException.java
Executable file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
|
||||
*/
|
||||
|
||||
package com.wisemapping.exporter;
|
||||
|
||||
public class ExportException
|
||||
extends Exception
|
||||
{
|
||||
public ExportException(Throwable e)
|
||||
{
|
||||
super(e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
|
||||
*/
|
||||
|
||||
package com.wisemapping.exporter;
|
||||
|
||||
public enum ExportFormat {
|
||||
SVG("image/svg+xml", "xml"),
|
||||
JPEG("image/jpeg", "jpg"),
|
||||
PNG("image/png", "png"),
|
||||
MINDJET("text/xml", "xml"),
|
||||
PDF("application/pdf", "pdf"),
|
||||
FREEMIND("text/xml", "mm");
|
||||
|
||||
private String contentType;
|
||||
private String fileExtension;
|
||||
|
||||
ExportFormat(String contentType, String fileExtension) {
|
||||
this.contentType = contentType;
|
||||
this.fileExtension = fileExtension;
|
||||
}
|
||||
|
||||
public String getFileExtension() {
|
||||
return fileExtension;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
|
||||
*/
|
||||
|
||||
package com.wisemapping.exporter;
|
||||
|
||||
public class ExportProperties {
|
||||
private ExportFormat format;
|
||||
private String baseImgPath;
|
||||
|
||||
public ExportFormat getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
private ExportProperties(final ExportFormat format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public static ExportProperties create(final ExportFormat format) {
|
||||
ExportProperties result;
|
||||
if (format == ExportFormat.JPEG || format == ExportFormat.PNG) {
|
||||
result = new ImageProperties(format);
|
||||
} else {
|
||||
result = new GenericProperties(format);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setBaseImagePath(String baseUrl) {
|
||||
this.baseImgPath = baseUrl;
|
||||
}
|
||||
|
||||
public String getBaseImgPath() {
|
||||
return baseImgPath;
|
||||
}
|
||||
|
||||
static public class GenericProperties extends ExportProperties {
|
||||
private GenericProperties(ExportFormat format) {
|
||||
super(format);
|
||||
}
|
||||
}
|
||||
|
||||
static public class ImageProperties extends ExportProperties {
|
||||
private Size size;
|
||||
|
||||
public Size getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(Size size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public ImageProperties(ExportFormat format) {
|
||||
super(format);
|
||||
}
|
||||
|
||||
public enum Size {
|
||||
SMALL(100), MEDIUM(800), XMEDIUM(1024), LARGE(2048);
|
||||
private int width;
|
||||
|
||||
Size(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public Float getWidth() {
|
||||
return (float) width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
29
wise-webapp/src/main/java/com/wisemapping/exporter/Exporter.java
Executable file
29
wise-webapp/src/main/java/com/wisemapping/exporter/Exporter.java
Executable file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
|
||||
*/
|
||||
|
||||
package com.wisemapping.exporter;
|
||||
|
||||
import com.wisemapping.model.MindMap;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
public interface Exporter {
|
||||
public void export(byte[] xml, OutputStream outputStream) throws ExportException;
|
||||
public void export(MindMap map, OutputStream outputStream) throws ExportException;
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
|
||||
*/
|
||||
|
||||
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;
|
||||
import org.apache.batik.transcoder.TranscoderInput;
|
||||
import org.apache.batik.transcoder.TranscoderOutput;
|
||||
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.w3c.dom.*;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.*;
|
||||
|
||||
public class SvgExporter {
|
||||
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() {
|
||||
}
|
||||
|
||||
public static void export(ExportProperties properties, MindMap map, OutputStream output) throws TranscoderException, IOException, ParserConfigurationException, SAXException, XMLStreamException, TransformerException, JAXBException, ExportException {
|
||||
final ExportFormat format = properties.getFormat();
|
||||
|
||||
final String imgPath = properties.getBaseImgPath();
|
||||
switch (format) {
|
||||
case PNG: {
|
||||
// Create a JPEG transcoder
|
||||
final Transcoder transcoder = new PNGTranscoder();
|
||||
final ExportProperties.ImageProperties imageProperties =
|
||||
(ExportProperties.ImageProperties) properties;
|
||||
final ExportProperties.ImageProperties.Size size = imageProperties.getSize();
|
||||
transcoder.addTranscodingHint(ImageTranscoder.KEY_WIDTH, size.getWidth());
|
||||
|
||||
// Create the transcoder input.
|
||||
char[] xml = map.generateSvgXml();
|
||||
xml = normalizeSvg(xml, imgPath);
|
||||
final CharArrayReader is = new CharArrayReader(xml);
|
||||
TranscoderInput input = new TranscoderInput(is);
|
||||
TranscoderOutput trascoderOutput = new TranscoderOutput(output);
|
||||
|
||||
// Save the image.
|
||||
transcoder.transcode(input, trascoderOutput);
|
||||
break;
|
||||
}
|
||||
case JPEG: {
|
||||
// Create a JPEG transcoder
|
||||
final Transcoder transcoder = new JPEGTranscoder();
|
||||
transcoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(.99));
|
||||
|
||||
final ExportProperties.ImageProperties imageProperties =
|
||||
(ExportProperties.ImageProperties) properties;
|
||||
final ExportProperties.ImageProperties.Size size = imageProperties.getSize();
|
||||
transcoder.addTranscodingHint(ImageTranscoder.KEY_WIDTH, size.getWidth());
|
||||
|
||||
// Create the transcoder input.
|
||||
final char[] xml = map.generateSvgXml();
|
||||
char[] svgXml = normalizeSvg(xml, imgPath);
|
||||
final CharArrayReader is = new CharArrayReader(svgXml);
|
||||
TranscoderInput input = new TranscoderInput(is);
|
||||
TranscoderOutput trascoderOutput = new TranscoderOutput(output);
|
||||
|
||||
// Save the image.
|
||||
transcoder.transcode(input, trascoderOutput);
|
||||
break;
|
||||
}
|
||||
case PDF: {
|
||||
// Create a JPEG transcoder
|
||||
final Transcoder transcoder = new PDFTranscoder();
|
||||
|
||||
// Create the transcoder input.
|
||||
final char[] xml = map.generateSvgXml();
|
||||
char[] svgXml = normalizeSvg(xml, imgPath);
|
||||
final CharArrayReader is = new CharArrayReader(svgXml);
|
||||
TranscoderInput input = new TranscoderInput(is);
|
||||
TranscoderOutput trascoderOutput = new TranscoderOutput(output);
|
||||
|
||||
// Save the image.
|
||||
transcoder.transcode(input, trascoderOutput);
|
||||
break;
|
||||
}
|
||||
case SVG: {
|
||||
final char[] xml = map.generateSvgXml();
|
||||
char[] svgXml = normalizeSvg(xml, imgPath);
|
||||
output.write(new String(svgXml).getBytes("UTF-8"));
|
||||
break;
|
||||
}
|
||||
case FREEMIND: {
|
||||
final FreemindExporter exporter = new FreemindExporter();
|
||||
exporter.export(map.getUnzippedXml().getBytes(), output);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new UnsupportedOperationException("Export method not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
private static char[] normalizeSvg(final char[] svgXml, final String imgBaseUrl) throws XMLStreamException, ParserConfigurationException, IOException, SAXException, TransformerException {
|
||||
final Reader in = new CharArrayReader(svgXml);
|
||||
|
||||
// Load document ...
|
||||
final InputSource is = new InputSource(in);
|
||||
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder documentBuilder = factory.newDocumentBuilder();
|
||||
|
||||
final Document svgDocument = documentBuilder.parse(is);
|
||||
|
||||
fitSvg(svgDocument);
|
||||
|
||||
fixImageTagHref(svgDocument, imgBaseUrl);
|
||||
|
||||
DOMSource domSource = new DOMSource(svgDocument);
|
||||
|
||||
// Save document ...
|
||||
|
||||
// Create a string writer
|
||||
final CharArrayWriter outDocument = new CharArrayWriter();
|
||||
|
||||
// Create the result stream for the transform
|
||||
StreamResult result = new StreamResult(outDocument);
|
||||
|
||||
// Create a Transformer to serialize the document
|
||||
TransformerFactory tFactory = TransformerFactory.newInstance();
|
||||
|
||||
Transformer transformer = tFactory.newTransformer();
|
||||
transformer.setOutputProperty("indent", "yes");
|
||||
|
||||
// Transform the document to the result stream
|
||||
transformer.transform(domSource, result);
|
||||
|
||||
return outDocument.toCharArray();
|
||||
|
||||
}
|
||||
|
||||
private static void fixImageTagHref(Document svgDocument, String imgBaseUrl) {
|
||||
final Node child = svgDocument.getFirstChild();
|
||||
fixImageTagHref((Element) child, imgBaseUrl);
|
||||
}
|
||||
|
||||
private static void fixImageTagHref(Element element, String imgBaseUrl) {
|
||||
|
||||
final NodeList list = element.getChildNodes();
|
||||
|
||||
for (int i = 0; i < list.getLength(); i++) {
|
||||
final Node node = list.item(i);
|
||||
// find all groups
|
||||
if (GROUP_NODE_NAME.equals(node.getNodeName())) {
|
||||
// Must continue looking ....
|
||||
fixImageTagHref((Element) node, imgBaseUrl);
|
||||
|
||||
} else if (IMAGE_NODE_NAME.equals(node.getNodeName())) {
|
||||
|
||||
Element elem = (Element) node;
|
||||
|
||||
// Cook image href ...
|
||||
String imgName = elem.getAttribute("href");
|
||||
int index = imgName.lastIndexOf("/");
|
||||
elem.removeAttribute("href");
|
||||
if (index != -1)
|
||||
{
|
||||
imgName = imgName.substring(index);
|
||||
final String imgPath = imgBaseUrl + imgName;
|
||||
elem.setAttribute("xlink:href", imgPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void fitSvg(Document document) {
|
||||
// viewBox size
|
||||
int mapWidth = 1024;
|
||||
int mapHeight = 768;
|
||||
// some browser return width and heigth with precision
|
||||
float currentMaxWidth = 0;
|
||||
float currentMaxHeight = 0;
|
||||
|
||||
final Element svgNode = (Element) document.getFirstChild();
|
||||
final NodeList list = svgNode.getChildNodes();
|
||||
|
||||
for (int i = 0; i < list.getLength(); i++) {
|
||||
final Node node = list.item(i);
|
||||
// find all groups
|
||||
if (GROUP_NODE_NAME.equals(node.getNodeName())) {
|
||||
final NamedNodeMap groupAttributes = node.getAttributes();
|
||||
|
||||
final String[] transformUnit = getTransformUnit(groupAttributes);
|
||||
|
||||
int groupPositionX = Integer.parseInt(transformUnit[0].trim());
|
||||
int groupPositionY = 0;
|
||||
if (transformUnit.length > 1) {
|
||||
groupPositionY = Integer.parseInt(transformUnit[1].trim());
|
||||
}
|
||||
|
||||
int signumX = Integer.signum(groupPositionX);
|
||||
int signumY = Integer.signum(groupPositionY);
|
||||
|
||||
final NodeList groupChildren = node.getChildNodes();
|
||||
for (int idx = 0; idx < groupChildren.getLength(); idx++) {
|
||||
final Node rectNode = groupChildren.item(idx);
|
||||
float curentHeight = 0 ;
|
||||
float curentWidth = 0;
|
||||
|
||||
// If has a rect use the rect to calcular the real width of the topic
|
||||
if (RECT_NODE_NAME.equals(rectNode.getNodeName())) {
|
||||
final NamedNodeMap rectAttributes = rectNode.getAttributes();
|
||||
|
||||
final Node attributeHeight = rectAttributes.getNamedItem("height");
|
||||
final Node attributeWidth = rectAttributes.getNamedItem("width");
|
||||
|
||||
curentHeight = Float.valueOf(attributeHeight.getNodeValue());
|
||||
curentWidth = Float.valueOf(attributeWidth.getNodeValue());
|
||||
}
|
||||
|
||||
float newMaxWidth = groupPositionX + (curentWidth * signumX);
|
||||
if (Math.abs(currentMaxWidth) < Math.abs(newMaxWidth)) {
|
||||
currentMaxWidth = newMaxWidth;
|
||||
}
|
||||
|
||||
float newMaxHeight = groupPositionY + curentHeight * signumY;
|
||||
if (Math.abs(currentMaxHeight) < Math.abs(newMaxHeight)) {
|
||||
currentMaxHeight = newMaxHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
svgNode.setAttribute("viewBox", -Math.abs(currentMaxWidth) + " " + -Math.abs(currentMaxHeight) + " " + Math.abs(currentMaxWidth * 2) + " " + Math.abs(currentMaxHeight * 2));
|
||||
svgNode.setAttribute("width", Float.toString(mapWidth / 2));
|
||||
svgNode.setAttribute("height", Float.toString(mapHeight / 2));
|
||||
svgNode.setAttribute("preserveAspectRatio", "xMinYMin");
|
||||
}
|
||||
|
||||
private static String[] getTransformUnit(NamedNodeMap groupAttributes) {
|
||||
final String value = groupAttributes.getNamedItem("transform").getNodeValue();
|
||||
final int pos = value.indexOf("translate");
|
||||
final int initTranslate = value.indexOf("(", pos);
|
||||
final int endTranslate = value.indexOf(")", pos);
|
||||
final String transate = value.substring(initTranslate + 1, endTranslate);
|
||||
return transate.split(",");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
|
||||
*/
|
||||
|
||||
package com.wisemapping.exporter.freemind;
|
||||
|
||||
import com.wisemapping.exporter.ExportException;
|
||||
import com.wisemapping.exporter.Exporter;
|
||||
import com.wisemapping.model.MindMap;
|
||||
import com.wisemapping.util.JAXBUtils;
|
||||
import com.wisemapping.xml.freemind.Font;
|
||||
import com.wisemapping.xml.freemind.Node;
|
||||
import com.wisemapping.xml.freemind.Edge;
|
||||
import com.wisemapping.xml.freemind.Hook;
|
||||
import com.wisemapping.xml.mindmap.TopicType;
|
||||
import com.wisemapping.xml.mindmap.Icon;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
public class FreemindExporter
|
||||
implements Exporter
|
||||
{
|
||||
|
||||
private com.wisemapping.xml.freemind.ObjectFactory freemindObjectFactory;
|
||||
|
||||
public void export(MindMap map, OutputStream outputStream) throws ExportException {
|
||||
try {
|
||||
export(map.getUnzippedXml().getBytes(),outputStream);
|
||||
} catch (IOException e) {
|
||||
throw new ExportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void export(byte[] xml, OutputStream outputStream) throws ExportException {
|
||||
|
||||
freemindObjectFactory = new com.wisemapping.xml.freemind.ObjectFactory();
|
||||
final com.wisemapping.xml.mindmap.Map mindmapMap;
|
||||
|
||||
try {
|
||||
final ByteArrayInputStream stream = new ByteArrayInputStream(xml);
|
||||
mindmapMap = (com.wisemapping.xml.mindmap.Map) JAXBUtils.getMapObject(stream,"com.wisemapping.xml.mindmap");
|
||||
|
||||
final com.wisemapping.xml.freemind.Map freemindMap = freemindObjectFactory.createMap();
|
||||
|
||||
final List<TopicType> topics = mindmapMap.getTopic();
|
||||
|
||||
// Insolated Topic doesn´t exists in Freemind only take the center topic
|
||||
TopicType centerTopic = null;
|
||||
if (topics.size() >1)
|
||||
{
|
||||
for (TopicType topic : topics) {
|
||||
if (topic.isCentral())
|
||||
{
|
||||
centerTopic = topic;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
centerTopic = topics.get(0);
|
||||
}
|
||||
|
||||
final Node main = freemindObjectFactory.createNode();
|
||||
freemindMap.setNode(main);
|
||||
if (centerTopic != null)
|
||||
{
|
||||
setTopicPropertiesToNode(main,centerTopic);
|
||||
addNodeFromTopic(centerTopic,main);
|
||||
}
|
||||
|
||||
JAXBUtils.saveMap(freemindMap,outputStream,"com.wisemapping.xml.freemind");
|
||||
} catch (JAXBException e) {
|
||||
throw new ExportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void addNodeFromTopic(TopicType mainTopic, Node destNode)
|
||||
{
|
||||
final List<TopicType> currentTopic = mainTopic.getTopic();
|
||||
|
||||
for (TopicType topicType : currentTopic) {
|
||||
final Node newNode = freemindObjectFactory.createNode();
|
||||
setTopicPropertiesToNode(newNode,topicType);
|
||||
destNode.getArrowlinkOrCloudOrEdge().add(newNode);
|
||||
addNodeFromTopic(topicType,newNode);
|
||||
}
|
||||
}
|
||||
|
||||
private void setTopicPropertiesToNode(com.wisemapping.xml.freemind.Node freemindNode, com.wisemapping.xml.mindmap.TopicType mindmapTopic)
|
||||
{
|
||||
freemindNode.setTEXT(mindmapTopic.getText());
|
||||
freemindNode.setBACKGROUNDCOLOR(mindmapTopic.getBgColor());
|
||||
String style = "line"; // default style for freemind
|
||||
if ("rounded rectagle".equals(mindmapTopic.getShape()))
|
||||
{
|
||||
style = "bubble";
|
||||
}
|
||||
freemindNode.setSTYLE(style);
|
||||
addIconNode(freemindNode,mindmapTopic);
|
||||
addLinkNode(freemindNode,mindmapTopic);
|
||||
addFontNode(freemindNode,mindmapTopic);
|
||||
addEdgeNode(freemindNode,mindmapTopic);
|
||||
addNote(freemindNode,mindmapTopic);
|
||||
|
||||
}
|
||||
|
||||
private void addNote(com.wisemapping.xml.freemind.Node freemindNode,com.wisemapping.xml.mindmap.TopicType mindmapTopic)
|
||||
{
|
||||
if (mindmapTopic.getNote() != null)
|
||||
{
|
||||
final Hook note = new Hook();
|
||||
String textNote = mindmapTopic.getNote().getText();
|
||||
textNote = textNote.replaceAll("%0A","\n");
|
||||
note.setNAME("accessories/plugins/NodeNote.properties");
|
||||
note.setText(textNote);
|
||||
freemindNode.getArrowlinkOrCloudOrEdge().add(note);
|
||||
}
|
||||
}
|
||||
|
||||
private void addLinkNode(com.wisemapping.xml.freemind.Node freemindNode,com.wisemapping.xml.mindmap.TopicType mindmapTopic)
|
||||
{
|
||||
if (mindmapTopic.getLink() != null)
|
||||
{
|
||||
final String url = mindmapTopic.getLink().getUrl();
|
||||
freemindNode.setLINK(url);
|
||||
}
|
||||
}
|
||||
|
||||
private void addIconNode(com.wisemapping.xml.freemind.Node freemindNode,com.wisemapping.xml.mindmap.TopicType mindmapTopic)
|
||||
{
|
||||
if (mindmapTopic.getIcon() != null)
|
||||
{
|
||||
final List<Icon> iconsList = mindmapTopic.getIcon();
|
||||
for (Icon icon : iconsList) {
|
||||
final String id = icon.getId();
|
||||
com.wisemapping.xml.freemind.Icon freemindIcon = new com.wisemapping.xml.freemind.Icon();
|
||||
final String freemindIconId = FreemindIconMapper.getFreemindIcon(id);
|
||||
freemindIcon.setBUILTIN(freemindIconId);
|
||||
freemindNode.getArrowlinkOrCloudOrEdge().add(freemindIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addEdgeNode(com.wisemapping.xml.freemind.Node freemindNode,com.wisemapping.xml.mindmap.TopicType mindmapTopic)
|
||||
{
|
||||
if (mindmapTopic.getBrColor() != null)
|
||||
{
|
||||
final Edge edgeNode = freemindObjectFactory.createEdge();
|
||||
edgeNode.setCOLOR(mindmapTopic.getBrColor());
|
||||
freemindNode.getArrowlinkOrCloudOrEdge().add(edgeNode);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* MindmapFont format : fontName ; size ; color ; bold; italic;
|
||||
* eg: Verdana;10;#ffffff;bold;italic;
|
||||
*
|
||||
*/
|
||||
private void addFontNode(com.wisemapping.xml.freemind.Node freemindNode,com.wisemapping.xml.mindmap.TopicType mindmapTopic)
|
||||
{
|
||||
final String fontStyle = mindmapTopic.getFontStyle();
|
||||
if (fontStyle!= null && fontStyle.length()!=0)
|
||||
{
|
||||
final Font font = freemindObjectFactory.createFont();
|
||||
final String[] part = fontStyle.split(";",6);
|
||||
int countParts = part.length;
|
||||
int idx=0;
|
||||
// Font name
|
||||
if (idx < countParts && part[idx].length()!=0)
|
||||
{
|
||||
font.setNAME(part[idx]);
|
||||
}
|
||||
idx++;
|
||||
// Font size
|
||||
String size = "10"; // default value
|
||||
if (idx < countParts && part[idx].length()!=0)
|
||||
{
|
||||
size = part[idx];
|
||||
}
|
||||
|
||||
font.setSIZE(new BigInteger(size));
|
||||
idx++;
|
||||
|
||||
// Font Color
|
||||
if (idx < countParts && part[idx].length()!=0)
|
||||
{
|
||||
freemindNode.setCOLOR(part[idx]);
|
||||
}
|
||||
idx++;
|
||||
if (idx < countParts && part[idx].length()!=0)
|
||||
{
|
||||
font.setBOLD(Boolean.TRUE.toString());
|
||||
}
|
||||
idx++;
|
||||
if (idx < countParts && part[idx].length()!=0)
|
||||
{
|
||||
font.setITALIC(Boolean.TRUE.toString());
|
||||
}
|
||||
freemindNode.getArrowlinkOrCloudOrEdge().add(font);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* $Id: file 64488 2006-03-10 17:32:09Z paulo $
|
||||
*/
|
||||
|
||||
package com.wisemapping.exporter.freemind;
|
||||
|
||||
import com.wisemapping.model.MindmapImagesFactory;
|
||||
import com.wisemapping.model.ImageFamily;
|
||||
import com.wisemapping.model.MindmapImage;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class FreemindIconMapper {
|
||||
|
||||
|
||||
private static Map<String,String> mindmapImageToFreemind = new HashMap<String,String>();
|
||||
private static final String DEFAULT_ICON = "button_ok";
|
||||
|
||||
public FreemindIconMapper()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static String getFreemindIcon(String mindmapImageId)
|
||||
{
|
||||
|
||||
String freemindIconId = mindmapImageToFreemind.get(mindmapImageId);
|
||||
|
||||
// The image doesn´t exists in freemind select he default image
|
||||
if (freemindIconId == null)
|
||||
{
|
||||
freemindIconId = DEFAULT_ICON;
|
||||
}
|
||||
return freemindIconId;
|
||||
}
|
||||
|
||||
static {
|
||||
|
||||
List<MindmapImage> images = MindmapImagesFactory.getImagesByFamily(ImageFamily.BULLET);
|
||||
|
||||
for (int idx=0; idx < images.size() ; idx++)
|
||||
{
|
||||
mindmapImageToFreemind.put(images.get(idx).getId(), "full-"+(idx+1));
|
||||
}
|
||||
|
||||
images = MindmapImagesFactory.getImagesByFamily(ImageFamily.FLAG);
|
||||
for (MindmapImage mindmapImage : images) {
|
||||
mindmapImageToFreemind.put(mindmapImage.getId(), "flag");
|
||||
}
|
||||
|
||||
images = MindmapImagesFactory.getImagesByFamily(ImageFamily.BULB);
|
||||
mindmapImageToFreemind.put(images.get(0).getId(), "idea");
|
||||
|
||||
images = MindmapImagesFactory.getImagesByFamily(ImageFamily.TICK);
|
||||
mindmapImageToFreemind.put(images.get(0).getId(), "button_ok");
|
||||
mindmapImageToFreemind.put(images.get(1).getId(), "button_cancel");
|
||||
|
||||
images = MindmapImagesFactory.getImagesByFamily(ImageFamily.ARROW);
|
||||
mindmapImageToFreemind.put(images.get(2).getId(), "back");
|
||||
mindmapImageToFreemind.put(images.get(3).getId(), "forward");
|
||||
|
||||
images = MindmapImagesFactory.getImagesByFamily(ImageFamily.FACE);
|
||||
mindmapImageToFreemind.put(images.get(3).getId(), "ksmiletris");
|
||||
|
||||
images = MindmapImagesFactory.getImagesByFamily(ImageFamily.FLAG);
|
||||
for (MindmapImage mindmapImage : images) {
|
||||
mindmapImageToFreemind.put(mindmapImage.getId(), "flag");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user