Class DiagramController

java.lang.Object
com.plantoml.plantomlserver.controller.DiagramController

@CrossOrigin(origins="http://localhost:3000") @RestController @RequestMapping("/plantoml/oml") public class DiagramController extends Object
Controller class for handling diagram-related HTTP requests.

This class manages the web API endpoints for PlantOML, specifically for uploading OML projects and generating diagrams. It includes methods to handle file uploads and to apply various graphical options to the generated diagrams.

  • Constructor Summary

    Constructors
    Constructor
    Description
    DiagramController(org.springframework.web.client.RestTemplate restTemplate)
    Constructs a DiagramController with the specified RestTemplate.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    extractZipFile(Path zipFilePath, Path destDir)
    Extracts the contents of a ZIP file into a specified directory.
    org.springframework.http.ResponseEntity<byte[]>
    getDiagram(String textEncoding, String nodeShape, String nodeColor, String edgeColor, String edgeStyle, String graphLayout, String graphBgColor, String dpi)
    Handles the HTTP GET request to generate a diagram based on the provided text encoding.
    org.springframework.http.ResponseEntity<?>
    uploadOmlProject(org.springframework.web.multipart.MultipartFile file, String nodeShape, String nodeColor, String edgeColor, String edgeStyle, String graphLayout, String graphBgColor, String dpi)
    Handles the HTTP POST request for uploading an OML project.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DiagramController

      @Autowired public DiagramController(org.springframework.web.client.RestTemplate restTemplate)
      Constructs a DiagramController with the specified RestTemplate.

      Parameters:
      restTemplate - The RestTemplate used for HTTP requests within the controller.
  • Method Details

    • uploadOmlProject

      @PostMapping("/upload") public org.springframework.http.ResponseEntity<?> uploadOmlProject(@RequestParam("file") org.springframework.web.multipart.MultipartFile file, @RequestParam(value="nodeShape",required=false) String nodeShape, @RequestParam(value="nodeColor",required=false) String nodeColor, @RequestParam(value="edgeColor",required=false) String edgeColor, @RequestParam(value="edgeStyle",required=false) String edgeStyle, @RequestParam(value="graphLayout",required=false) String graphLayout, @RequestParam(value="graphBgColor",required=false) String graphBgColor, @RequestParam(value="dpi",required=false) String dpi)
      Handles the HTTP POST request for uploading an OML project.

      This method processes the uploaded OML project, generates diagrams, and returns them in a ZIP file. It accepts additional parameters for graphical customizations of the diagrams.

      Parameters:
      file - The uploaded OML project file.
      nodeShape - The shape of the nodes in the diagram.
      nodeColor - The color of the nodes.
      edgeColor - The color of the edges.
      edgeStyle - The style of the edges.
      graphLayout - The layout algorithm for the graph.
      graphBgColor - The background color of the graph.
      dpi - The DPI for the graph images.
      Returns:
      A ResponseEntity containing either the ZIP file of diagrams or an error message.
    • getDiagram

      @GetMapping("/{textEncoding}") public org.springframework.http.ResponseEntity<byte[]> getDiagram(@PathVariable String textEncoding, @RequestParam(required=false) String nodeShape, @RequestParam(required=false) String nodeColor, @RequestParam(required=false) String edgeColor, @RequestParam(required=false) String edgeStyle, @RequestParam(required=false) String graphLayout, @RequestParam(required=false) String graphBgColor, @RequestParam(required=false) String dpi)
      Handles the HTTP GET request to generate a diagram based on the provided text encoding.

      This method decodes the text encoding, applies optional diagram customization options, and returns a PNG image of the generated diagram.

      Parameters:
      textEncoding - The encoded text representing the OML or other diagram information.
      nodeShape - Optional customization for the shape of nodes in the diagram.
      nodeColor - Optional customization for the color of nodes.
      edgeColor - Optional customization for the color of edges.
      edgeStyle - Optional customization for the style of edges.
      graphLayout - Optional customization for the graph layout algorithm.
      graphBgColor - Optional customization for the background color of the graph.
      dpi - Optional customization for the DPI of the graph image.
      Returns:
      A ResponseEntity containing either the PNG image of the diagram or an error message.
    • extractZipFile

      public void extractZipFile(Path zipFilePath, Path destDir) throws IOException
      Extracts the contents of a ZIP file into a specified directory.

      This method iterates through each entry in the ZIP file and extracts files and directories accordingly.

      Parameters:
      zipFilePath - The path to the ZIP file.
      destDir - The destination directory to extract the contents.
      Throws:
      IOException - if an I/O error occurs.