Class Customizations

  • All Implemented Interfaces:
    java.util.Observer

    public class Customizations
    extends java.util.Observable
    implements java.util.Observer
    This class is responsible for searching Customizations in MicroStrategy Web. This class is a singleton. Therefore, all classes in the application use the same instance.
    This class searches for customizations in the application's root folder, based on two parameters:
    1. baseFolder: Indicates the subfolder within the application where customizations folders must be included. By default, the application's root folder.
    2. folderPrefix: Indicates a prefix in a folder's name used to identify that the folder is indeed a customization folder. "_custom" is used by default.
    This class also accepts a Comparator used to sort the customization folders. This comparator can indicate the exact order in which the customizations should be applied to avoid conflicts among them. If no Comparator is specified, customizations will be applied in alphabetical order.
    All of these parameters can be set either programatically or through the "webcustomizations.properties" file, which needs to be inside the classpath.
    Since:
    MicroStrategy Web 9.0.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String CUSTOMIZATION_PROPERTIES_FILE
      Represents the name of the properties file used to configure this class.
    • Constructor Summary

      Constructors 
      Constructor Description
      Customizations​(java.lang.ClassLoader parentClassLoader, java.lang.String baseFolder, FileLoader fileLoader)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getAppRelativePathPrefix()  
      java.lang.String getBaseFolder()
      Represents the base folder (relative to the application's root folder) this class searches for customization folders.
      java.lang.ClassLoader getClassLoader()
      Returns a ClassLoader capable of loading classes/resources from all customization folders.
      java.util.Comparator getComparator()
      Represents the Java class used to compare the current CustomizationInfo instances to sort them.
      Logger getConflictsLogger()
      Returns the Logger instance used to log conflicts.
      protected java.lang.String[] getCustomFolders()
      Returns a list of customization folders based on the base folder and the folder prefix.
      CustomizationInfo getCustomization​(java.lang.String name)
      Returns the CustomizationInfo with the given name;
      CustomizationInfo[] getCustomizations()
      Returns a list of CustomizationInfo classes.
      java.lang.String getFolderPrefix()
      Represents the prefix that identifies a folder as a customization folder.
      static Customizations getInstance()
      The method to return the singleton instance of this class.
      java.lang.String getRealPath​(java.lang.String relativePath)
      Returns the full absolute path within the file sytem for a given relative path.
      boolean hasCustomization​(java.lang.String name)
      Returns the CustomizationInfo with the given name;
      protected static void loadProperties​(java.lang.String propertiesFile)
      Loads and initializes this class based on the Properties file (if found).
      static void logConflict​(Level level, java.lang.String className, java.lang.String methodName, java.lang.String message, CustomizationInfo c1, CustomizationInfo c2)
      Logs a conflict message into the log using the conflicts logger.
      CustomizationInfo newCustomization​(java.lang.String name)
      Returns a list of CustomizationInfo classes.
      void reload()
      This method triggers the class to check for changes in the base folder for new customizations.
      void setAppRelativePathPrefix​(java.lang.String prefix)  
      void setBaseFolder​(java.lang.String value)
      Represents the base folder (relative to the application's root folder) this class searches for customization folders.
      void setComparator​(java.util.Comparator comparator)
      Sets the Comparator used to compare two CustomizationInfo instances to sort them.
      void setFolderPrefix​(java.lang.String value)
      Represents the prefix that identifies a folder as a customization folder.
      void update​(java.util.Observable o, java.lang.Object arg)
      This class observes the FileLoader, whenever the FileLoader instances changes this class wants to be notified so it can remove its internal caches.
      • Methods inherited from class java.util.Observable

        addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
      • Methods inherited from class java.lang.Object

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

      • CUSTOMIZATION_PROPERTIES_FILE

        public static final java.lang.String CUSTOMIZATION_PROPERTIES_FILE
        Represents the name of the properties file used to configure this class.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Customizations

        public Customizations​(java.lang.ClassLoader parentClassLoader,
                              java.lang.String baseFolder,
                              FileLoader fileLoader)
    • Method Detail

      • getInstance

        public static Customizations getInstance()
        The method to return the singleton instance of this class.
      • setBaseFolder

        public void setBaseFolder​(java.lang.String value)
        Represents the base folder (relative to the application's root folder) this class searches for customization folders.
      • getBaseFolder

        public java.lang.String getBaseFolder()
        Represents the base folder (relative to the application's root folder) this class searches for customization folders.
      • setAppRelativePathPrefix

        public void setAppRelativePathPrefix​(java.lang.String prefix)
      • getAppRelativePathPrefix

        public java.lang.String getAppRelativePathPrefix()
      • setFolderPrefix

        public void setFolderPrefix​(java.lang.String value)
        Represents the prefix that identifies a folder as a customization folder. A folder is identified as a customization folder when its name within the base folder starts with this prefix.
      • getFolderPrefix

        public java.lang.String getFolderPrefix()
        Represents the prefix that identifies a folder as a customization folder. A folder is identified as a customization folder when its name within the base folder starts with this prefix.
      • getComparator

        public java.util.Comparator getComparator()
        Represents the Java class used to compare the current CustomizationInfo instances to sort them. If no Comparator has been explicitly set, or the properties file didn't include a Comparator name this method returns a string comparator (in which case, customizations are applied in alphabetical order).
        The Comparator will be asked to compare two CustomizationInfo instances to determine the order in which they should be applied. It must return -1 if the first CustomizationInfo is to be applied before the second, and 1 if the second CustomizationInfo is to be applied before the first.

        See Also:
        Comparator
      • setComparator

        public void setComparator​(java.util.Comparator comparator)
        Sets the Comparator used to compare two CustomizationInfo instances to sort them.
        See Also:
        getComparator()
      • getRealPath

        public java.lang.String getRealPath​(java.lang.String relativePath)
        Returns the full absolute path within the file sytem for a given relative path.
      • reload

        public void reload()
        This method triggers the class to check for changes in the base folder for new customizations.
      • getCustomizations

        public CustomizationInfo[] getCustomizations()
        Returns a list of CustomizationInfo classes. Each CustomizationInfo represents a single customization folder, which can be used to query whether there is a customization for a given file in the folder, or to retrieve a ClassLoader that searches for classes/resources only in that customization folder.
      • newCustomization

        public CustomizationInfo newCustomization​(java.lang.String name)
        Returns a list of CustomizationInfo classes. Each CustomizationInfo represents a single customization folder, which can be used to query whether there is a customization for a given file in the folder, or to retrieve a ClassLoader that searches for classes/resources only in that customization folder.
      • getCustomization

        public CustomizationInfo getCustomization​(java.lang.String name)
        Returns the CustomizationInfo with the given name;
      • hasCustomization

        public boolean hasCustomization​(java.lang.String name)
        Returns the CustomizationInfo with the given name;
      • getCustomFolders

        protected java.lang.String[] getCustomFolders()
        Returns a list of customization folders based on the base folder and the folder prefix.
        See Also:
        Customizations
      • getClassLoader

        public java.lang.ClassLoader getClassLoader()
        Returns a ClassLoader capable of loading classes/resources from all customization folders.
      • loadProperties

        protected static void loadProperties​(java.lang.String propertiesFile)
                                      throws java.io.FileNotFoundException
        Loads and initializes this class based on the Properties file (if found). If the file is not found, the current values are used.
        Throws:
        java.io.FileNotFoundException
      • logConflict

        public static void logConflict​(Level level,
                                       java.lang.String className,
                                       java.lang.String methodName,
                                       java.lang.String message,
                                       CustomizationInfo c1,
                                       CustomizationInfo c2)
        Logs a conflict message into the log using the conflicts logger. To log a conflict, please specify the level of conflict, the class and method where the conflict was detected, a detailed message explaining what the conflict is and the action taken, and the pair of customizations among which the conflict was detected.
        For the conflict level, use the following convention:
        • Level.SEVERE: When two customizations modify the same parameter with different values.
        • Level.WARNING: When two customizations modify the same parameter, but use the same value.
      • getConflictsLogger

        public Logger getConflictsLogger()
        Returns the Logger instance used to log conflicts.
      • update

        public void update​(java.util.Observable o,
                           java.lang.Object arg)
        This class observes the FileLoader, whenever the FileLoader instances changes this class wants to be notified so it can remove its internal caches.
        Specified by:
        update in interface java.util.Observer