Class PackageResource

    • Constructor Detail

      • PackageResource

        protected PackageResource​(Class<?> scope,
                                  String name,
                                  Locale locale,
                                  String style,
                                  String variation)
        Hidden constructor.
        Parameters:
        scope - This argument will be used to get the class loader for loading the package resource, and to determine what package it is in
        name - The relative path to the resource
        locale - The locale of the resource
        style - The style of the resource
        variation - The component's variation (of the style)
    • Method Detail

      • setCachingEnabled

        public void setCachingEnabled​(boolean enabled)
        Sets the caching for this resource to be enabled
        Parameters:
        enabled - if the cacheing should be enabled
      • getTextEncoding

        public String getTextEncoding()
        get text encoding (intented for character-based resources)
        Returns:
        custom encoding or null to use default
      • setTextEncoding

        public void setTextEncoding​(String textEncoding)
        set text encoding (intented for character-based resources)
        Parameters:
        textEncoding - custom encoding or null to use default
      • getScope

        public final Class<?> getScope()
        Gets the scoping class, used for class loading and to determine the package.
        Returns:
        the scoping class
      • getStyle

        public final String getStyle()
        Gets the style.
        Returns:
        the style
      • processResponse

        protected byte[] processResponse​(IResource.Attributes attributes,
                                         byte[] original)
        Gives a chance to modify the resource going to be written in the response
        Parameters:
        attributes - current request attributes from client
        original - the original response
        Returns:
        the processed response
      • compressResponse

        protected byte[] compressResponse​(IResource.Attributes attributes,
                                          byte[] original)
        Compresses the response if its is eligible and there is a configured compressor
        Parameters:
        attributes - * current request attributes from client * @param original * the original response * @return the compressed response
      • getCompressor

        protected ITextResourceCompressor getCompressor()
        Gets the IJavaScriptCompressor to be used. By default returns the configured compressor on application level, but can be overriden by the user application to provide compressor specific to the resource.
        Returns:
        the configured application level JavaScript compressor. May be null.
      • setCompress

        public void setCompress​(boolean compress)
        Parameters:
        compress - A flag indicating whether the resource should be compressed.
      • accept

        protected boolean accept​(String path)
        Checks whether access is granted for this resource. By default IPackageResourceGuard is used to check the permissions but the resource itself can also make the check.
        Parameters:
        path - resource path
        Returns:
        true if resource access is granted
      • exists

        public static boolean exists​(ResourceReference.Key key)
        Checks whether a resource for a given set of criteria exists.
        Parameters:
        key - The key that contains all attributes about the requested resource
        Returns:
        true if there is a package resource with the given attributes
      • exists

        public static boolean exists​(Class<?> scope,
                                     String path,
                                     Locale locale,
                                     String style,
                                     String variation)
        Checks whether a resource for a given set of criteria exists.
        Parameters:
        scope - This argument will be used to get the class loader for loading the package resource, and to determine what package it is in. Typically this is the class in which you call this method
        path - The path to the resource
        locale - The locale of the resource
        style - The style of the resource (see Session)
        variation - The component's variation (of the style)
        Returns:
        true if a resource could be loaded, false otherwise