Class JavascriptResource

java.lang.Object
io.github.jeemv.springboot.vuejs.utilities.resources.JavascriptResource

public class JavascriptResource extends Object
JavascriptResource This class is part of springBoot-VueJS Allows to Externalize a js script (from resources/static/js) and to use java variables in it.
  • Constructor Details

    • JavascriptResource

      public JavascriptResource()
    • JavascriptResource

      public JavascriptResource(Map<String,Object> variables)
  • Method Details

    • put

      public Object put(String name, Object value)
      Adds java content identified by its name.
      Parameters:
      name - The name of the java content (use ${name} in the js file to refer to it.
      value - The java content
      Returns:
      the previous value associated with name, or null if there was no mapping for name.
    • addVariables

      public void addVariables(Object[][] keyValues)
      Adds an array of names,values to the resource.
      Parameters:
      keyValues - Sample new Object[][] { {"id",5},{"name","doe"} }
    • addVariables

      public void addVariables(String jsonString) throws IOException
      Adds names,values of contents to the resource from a json array.
      Parameters:
      jsonString - sample "{'id':5}"
      Throws:
      IOException
    • addVariables

      public void addVariables(Object o) throws IOException
      Adds all members name/value of an object to java contents.
      Parameters:
      o -
      Throws:
      IOException
    • loadFile

      public void loadFile(String filename) throws IOException
      Loads a javascript file.
      Parameters:
      filename - The name of the js file
      Throws:
      IOException
    • parseContent

      public String parseContent()
      Returns the javascript content of the file parsed with the java contents.
      Returns:
      The javascript parsed with the java contents
    • load

      public static String load(String filename, Map<String,Object> variables) throws IOException
      Returns the javascript content of a javascript file parsed with java contents.
      Parameters:
      filename - The javascript file to load
      variables - The java contents to be parsed.
      Returns:
      The javascript content of the file parsed with the java contents
      Throws:
      IOException
    • create

      public static JavascriptResource create(String filename, Map<String,Object> variables) throws IOException
      Creates and returns a javascript resource.
      Parameters:
      filename - The javascript file to load
      variables - The javascript content of the file parsed with the java contents
      Returns:
      A Javascript resource
      Throws:
      IOException
    • create

      public static JavascriptResource create(String filename) throws IOException
      Creates and returns a javascript resource.
      Parameters:
      filename -
      Returns:
      The javascript file to load
      Throws:
      IOException