mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-08-20 04:30:42 +02:00
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:
parent
f704e730c9
commit
9f4c928d13
@ -19,11 +19,11 @@
|
|||||||
package com.wisemapping.importer;
|
package com.wisemapping.importer;
|
||||||
|
|
||||||
import com.wisemapping.model.MindMap;
|
import com.wisemapping.model.MindMap;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
public interface Importer
|
public interface Importer {
|
||||||
{
|
public MindMap importMap(@NotNull String mapName, @NotNull String description, @NotNull InputStream input) throws ImporterException;
|
||||||
public MindMap importMap(String mapName,String description,InputStream input) throws ImporterException;
|
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,18 @@ public class TransformerController extends BaseController {
|
|||||||
return new ModelAndView("transformViewFreemind", values);
|
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"})
|
@RequestMapping(method = RequestMethod.POST, value = "/transform", consumes = {"application/x-www-form-urlencoded"})
|
||||||
public ModelAndView transform(@NotNull HttpServletRequest request,
|
public ModelAndView transform(@NotNull HttpServletRequest request,
|
||||||
@NotNull HttpServletResponse response) throws IOException {
|
@NotNull HttpServletResponse response) throws IOException {
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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...
|
// Set format content type...
|
||||||
final String contentType = exportFormat.getContentType();
|
final String contentType = exportFormat.getContentType();
|
||||||
response.setContentType(contentType);
|
response.setContentType(contentType);
|
||||||
@ -61,9 +51,16 @@ public class TransformView extends AbstractView {
|
|||||||
final String fileName = (filename != null ? filename : "map") + "." + exportFormat.getFileExtension();
|
final String fileName = (filename != null ? filename : "map") + "." + exportFormat.getFileExtension();
|
||||||
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
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();
|
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
|
@Override
|
||||||
@ -71,7 +68,6 @@ public class TransformView extends AbstractView {
|
|||||||
return contentType;
|
return contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setBaseBaseImgUrl(@NotNull ExportFormat format, @NotNull ExportProperties properties) {
|
private void setBaseBaseImgUrl(@NotNull ExportFormat format, @NotNull ExportProperties properties) {
|
||||||
|
|
||||||
final String baseUrl;
|
final String baseUrl;
|
||||||
|
@ -38,6 +38,8 @@
|
|||||||
<entry key="png" value="image/png"/>
|
<entry key="png" value="image/png"/>
|
||||||
<entry key="jpeg" value="image/jpg"/>
|
<entry key="jpeg" value="image/jpg"/>
|
||||||
<entry key="svg" value="image/svg+xml"/>
|
<entry key="svg" value="image/svg+xml"/>
|
||||||
|
<entry key="svg" value="application/svg+xml"/>
|
||||||
|
<entry key="wise" value="application/wisemapping+xml"/>
|
||||||
</map>
|
</map>
|
||||||
</property>
|
</property>
|
||||||
<property name="viewResolvers">
|
<property name="viewResolvers">
|
||||||
@ -79,4 +81,8 @@
|
|||||||
<bean id="transformViewSvg" class="com.wisemapping.rest.view.TransformView">
|
<bean id="transformViewSvg" class="com.wisemapping.rest.view.TransformView">
|
||||||
<constructor-arg value="image/svg+xml"/>
|
<constructor-arg value="image/svg+xml"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="transformViewWise" class="com.wisemapping.rest.view.ImportTransformationView">
|
||||||
|
<constructor-arg value="application/wisemapping+xml"/>
|
||||||
|
</bean>
|
||||||
</beans>
|
</beans>
|
@ -32,7 +32,7 @@
|
|||||||
<sec:http pattern="/c/embeddedview.htm" security="none"/>
|
<sec:http pattern="/c/embeddedview.htm" security="none"/>
|
||||||
<sec:http pattern="/c/export.htm" security="none"/>
|
<sec:http pattern="/c/export.htm" security="none"/>
|
||||||
<sec:http pattern="/c/publicview.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:http use-expressions="true" create-session="never" pattern="/service/**">
|
||||||
<sec:intercept-url pattern="/service/admin/users/**" access="isAuthenticated() and hasRole('ROLE_ADMIN')"/>
|
<sec:intercept-url pattern="/service/admin/users/**" access="isAuthenticated() and hasRole('ROLE_ADMIN')"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user