Add support for Freemind to Wise transformation:

curl http://localhost:8080/service/transform.wise --data @fonts.mm  -H "Content-Type:application/freemind" --post301
This commit is contained in:
Paulo Gustavo Veiga 2012-02-29 20:22:27 -03:00
parent f704e730c9
commit 9f4c928d13
6 changed files with 83 additions and 17 deletions

View File

@ -19,11 +19,11 @@
package com.wisemapping.importer;
import com.wisemapping.model.MindMap;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.InputStream;
public interface Importer
{
public MindMap importMap(String mapName,String description,InputStream input) throws ImporterException;
public interface Importer {
public MindMap importMap(@NotNull String mapName, @NotNull String description, @NotNull InputStream input) throws ImporterException;
}

View File

@ -81,6 +81,18 @@ public class TransformerController extends BaseController {
return new ModelAndView("transformViewFreemind", values);
}
@RequestMapping(method = RequestMethod.POST, value = "/transform", produces = {"application/wisemapping+xml"}, consumes = {"application/freemind"})
@ResponseBody
public ModelAndView transformWisemapping(@RequestBody @Nullable final String content) throws IOException {
final Map<String, Object> values = new HashMap<String, Object>();
if (content == null || content.length() == 0) {
throw new IllegalArgumentException("Body can not be null.");
}
values.put("content", content);
return new ModelAndView("transformViewWise", values);
}
@RequestMapping(method = RequestMethod.POST, value = "/transform", consumes = {"application/x-www-form-urlencoded"})
public ModelAndView transform(@NotNull HttpServletRequest request,
@NotNull HttpServletResponse response) throws IOException {

View File

@ -0,0 +1,52 @@
package com.wisemapping.rest.view;
import com.wisemapping.importer.ImportFormat;
import com.wisemapping.importer.Importer;
import com.wisemapping.importer.ImporterException;
import com.wisemapping.importer.ImporterFactory;
import com.wisemapping.model.MindMap;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.servlet.view.AbstractView;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Map;
public class ImportTransformationView extends AbstractView {
private String contentType;
private Importer importer;
public ImportTransformationView(@NotNull final String contentType) throws ImporterException {
ImporterFactory exporterFactory = ImporterFactory.getInstance();
importer = exporterFactory.getImporter(ImportFormat.FREEMIND);
this.contentType = contentType;
}
@Override
protected void renderMergedOutputModel(@NotNull Map<String, Object> viewMap, @NotNull HttpServletRequest request, @NotNull final HttpServletResponse response) throws Exception {
final String content = (String) viewMap.get("content");
final String filename = (String) viewMap.get("filename");
// Convert to map ...
final InputStream is = new ByteArrayInputStream(content.getBytes("UTF-8"));
final MindMap mindMap = importer.importMap("filename", "filename", is);
// Set file name...
final String fileName = (filename != null ? filename : "map") + "." + "xwise";
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
// Write the conversion content ...
final ServletOutputStream outputStream = response.getOutputStream();
outputStream.print(mindMap.getXmlStr());
}
@Override
public String getContentType() {
return contentType;
}
}

View File

@ -43,16 +43,6 @@ public class TransformView extends AbstractView {
}
}
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
// Change image link URL.
setBaseBaseImgUrl(exportFormat, properties);
if (exportFormat == ExportFormat.FREEMIND) {
ExporterFactory.export(properties, content, bos, null);
} else {
ExporterFactory.export(properties, null, bos, content);
}
// Set format content type...
final String contentType = exportFormat.getContentType();
response.setContentType(contentType);
@ -61,9 +51,16 @@ public class TransformView extends AbstractView {
final String fileName = (filename != null ? filename : "map") + "." + exportFormat.getFileExtension();
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
// Write content ...
// Change image link URL.
setBaseBaseImgUrl(exportFormat, properties);
// Write the conversion content ...
final ServletOutputStream outputStream = response.getOutputStream();
outputStream.write(bos.toByteArray());
if (exportFormat == ExportFormat.FREEMIND) {
ExporterFactory.export(properties, content, outputStream, null);
} else {
ExporterFactory.export(properties, null, outputStream, content);
}
}
@Override
@ -71,7 +68,6 @@ public class TransformView extends AbstractView {
return contentType;
}
private void setBaseBaseImgUrl(@NotNull ExportFormat format, @NotNull ExportProperties properties) {
final String baseUrl;

View File

@ -38,6 +38,8 @@
<entry key="png" value="image/png"/>
<entry key="jpeg" value="image/jpg"/>
<entry key="svg" value="image/svg+xml"/>
<entry key="svg" value="application/svg+xml"/>
<entry key="wise" value="application/wisemapping+xml"/>
</map>
</property>
<property name="viewResolvers">
@ -79,4 +81,8 @@
<bean id="transformViewSvg" class="com.wisemapping.rest.view.TransformView">
<constructor-arg value="image/svg+xml"/>
</bean>
<bean id="transformViewWise" class="com.wisemapping.rest.view.ImportTransformationView">
<constructor-arg value="application/wisemapping+xml"/>
</bean>
</beans>

View File

@ -32,7 +32,7 @@
<sec:http pattern="/c/embeddedview.htm" security="none"/>
<sec:http pattern="/c/export.htm" security="none"/>
<sec:http pattern="/c/publicview.htm" security="none"/>
<sec:http pattern="/service/transform.*" security="none"/>
<sec:http pattern="/service/transform*" security="none"/>
<sec:http use-expressions="true" create-session="never" pattern="/service/**">
<sec:intercept-url pattern="/service/admin/users/**" access="isAuthenticated() and hasRole('ROLE_ADMIN')"/>