v0.0.1
Feature: 1. 支持uml源码生成SVG.
This commit is contained in:
13
src/main/java/com/yame/uml/Application.java
Normal file
13
src/main/java/com/yame/uml/Application.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.yame.uml;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScans;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
80
src/main/java/com/yame/uml/control/api.java
Normal file
80
src/main/java/com/yame/uml/control/api.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package com.yame.uml.control;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.yame.uml.model.Result;
|
||||
import com.yame.uml.model.ResultType;
|
||||
|
||||
import net.sourceforge.plantuml.BlockUml;
|
||||
import net.sourceforge.plantuml.FileFormat;
|
||||
import net.sourceforge.plantuml.FileFormatOption;
|
||||
import net.sourceforge.plantuml.LineLocation;
|
||||
import net.sourceforge.plantuml.SourceStringReader;
|
||||
import net.sourceforge.plantuml.api.PlantumlUtils;
|
||||
import net.sourceforge.plantuml.code.Transcoder;
|
||||
import net.sourceforge.plantuml.code.TranscoderUtil;
|
||||
import net.sourceforge.plantuml.core.*;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class api {
|
||||
|
||||
static public String getUmlSource(String source) {
|
||||
// encapsulate the UML syntax if necessary
|
||||
String uml;
|
||||
if (source.startsWith("@start")) {
|
||||
uml = source;
|
||||
} else {
|
||||
StringBuilder plantUmlSource = new StringBuilder();
|
||||
plantUmlSource.append("@startuml\n");
|
||||
plantUmlSource.append(source);
|
||||
if (source.endsWith("\n") == false) {
|
||||
plantUmlSource.append("\n");
|
||||
}
|
||||
plantUmlSource.append("@enduml");
|
||||
uml = plantUmlSource.toString();
|
||||
}
|
||||
return uml;
|
||||
}
|
||||
|
||||
@PostMapping("/v1/megreflow")
|
||||
public Result megreSVG(@RequestParam("data") String data) throws IOException {
|
||||
String source = getUmlSource(data);
|
||||
List<BlockUml> blocks = new SourceStringReader(source).getBlocks();
|
||||
// FileOutputStream os = new FileOutputStream(new File("./t.svg"));
|
||||
// new SourceStringReader(testUML).outputImage(os,new FileFormatOption(FileFormat.SVG));
|
||||
|
||||
Result result = new Result();
|
||||
if(blocks.size() != 0) {
|
||||
for(BlockUml block: blocks) {
|
||||
OutputStream os = new ByteArrayOutputStream();
|
||||
block.getDiagram().exportDiagram(os, 0, new FileFormatOption(FileFormat.SVG));
|
||||
result.setType(ResultType.Source2SVG);
|
||||
result.getContent().add(os.toString());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
result.setType(ResultType.ErrorSource2SVG);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
32
src/main/java/com/yame/uml/model/Result.java
Normal file
32
src/main/java/com/yame/uml/model/Result.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.yame.uml.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* result
|
||||
*/
|
||||
public class Result {
|
||||
|
||||
public ResultType type;
|
||||
public List<String> content;
|
||||
|
||||
|
||||
public Result() {
|
||||
content = new ArrayList<String>();
|
||||
}
|
||||
|
||||
public List<String> getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public ResultType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(ResultType type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
36
src/main/java/com/yame/uml/model/ResultType.java
Normal file
36
src/main/java/com/yame/uml/model/ResultType.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.yame.uml.model;
|
||||
|
||||
public enum ResultType {
|
||||
Success("Success", 1),
|
||||
Source2PNG("Source2PNG", 101),
|
||||
Source2SVG("Source2SVG", 102),
|
||||
|
||||
Error("Error", 0),
|
||||
ErrorSource2PNG("Error Source2PNG: source format is erorr", -101),
|
||||
ErrorSource2SVG("Error Source2SVG: source format is erorr", -102),
|
||||
;
|
||||
|
||||
private String status;
|
||||
private int code;
|
||||
|
||||
private ResultType(String status, int code) {
|
||||
this.status = status;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user