Class LinkedHashMapSecuredJsCache

  • All Implemented Interfaces:
    SecuredJsCache

    class LinkedHashMapSecuredJsCache
    extends java.lang.Object
    implements SecuredJsCache
    Default implementation of SecuredJsCache, uses a LinkedHashMap as its cache and is not thread-safe. Also, mixing scripts with missing braces allowed and not allowed is forbidden.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean allowNoBraces  
      private java.util.LinkedHashMap<java.lang.String,​java.lang.String> map  
    • Constructor Summary

      Constructors 
      Constructor Description
      LinkedHashMapSecuredJsCache​(java.util.LinkedHashMap<java.lang.String,​java.lang.String> linkedHashMap, boolean allowNoBraces)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void assertConfiguration​(boolean allowNoBraces)  
      java.lang.String getOrCreate​(java.lang.String js, boolean allowNoBraces, java.util.function.Supplier<java.lang.String> producer)
      Gets a value from the cache and tries to create it if it couldn't be found.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • map

        private final java.util.LinkedHashMap<java.lang.String,​java.lang.String> map
      • allowNoBraces

        private final boolean allowNoBraces
    • Constructor Detail

      • LinkedHashMapSecuredJsCache

        public LinkedHashMapSecuredJsCache​(java.util.LinkedHashMap<java.lang.String,​java.lang.String> linkedHashMap,
                                           boolean allowNoBraces)
    • Method Detail

      • getOrCreate

        public java.lang.String getOrCreate​(java.lang.String js,
                                            boolean allowNoBraces,
                                            java.util.function.Supplier<java.lang.String> producer)
        Description copied from interface: SecuredJsCache
        Gets a value from the cache and tries to create it if it couldn't be found.
        Specified by:
        getOrCreate in interface SecuredJsCache
        Parameters:
        js - the raw javascript code
        allowNoBraces - whether missing braces are allowed.
        producer - if no cached value could be found, this is used to create the value
        Returns:
        the cached or created value, or null if it could be neither found in the cache nor created.
      • assertConfiguration

        private void assertConfiguration​(boolean allowNoBraces)