From 2d37cbb1af30001a2bae01d862371b63ea696eb2 Mon Sep 17 00:00:00 2001
From: Emil Ivov <emcho@jitsi.org>
Date: Tue, 21 May 2013 16:17:59 +0300
Subject: [PATCH] Add support for a second defaults file.

The file is named jitsi-default-overrides.properties and it allows a
deployer (system administrator) to keep a separate set of locally
define properties, different from the ones the come with the client.

This commit also allows for zero length override property values.
---
 .../ConfigurationServiceImpl.java             | 37 +++++++++++++++----
 1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/src/org/jitsi/impl/configuration/ConfigurationServiceImpl.java b/src/org/jitsi/impl/configuration/ConfigurationServiceImpl.java
index fe8e5743..67aaf3c9 100644
--- a/src/org/jitsi/impl/configuration/ConfigurationServiceImpl.java
+++ b/src/org/jitsi/impl/configuration/ConfigurationServiceImpl.java
@@ -54,10 +54,17 @@ public class ConfigurationServiceImpl
         = "net.java.sip.communicator.SYS_PROPS_FILE_NAME";
 
     /**
-     * Name of the system file name property.
+     * Name of the file containing default properties.
      */
     private static final String DEFAULT_PROPS_FILE_NAME
-                                                = "jitsi-defaults.properties";
+                                         = "jitsi-defaults.properties";
+
+    /**
+     * Name of the file containing overrides (possibly set by the deployer)
+     * for any of the default properties.
+     */
+    private static final String DEFAULT_OVERRIDES_PROPS_FILE_NAME
+                                         = "jitsi-default-overrides.properties";
 
     /**
      * A reference to the currently used configuration file.
@@ -1530,16 +1537,30 @@ else if (XMLConfigurationStore.class.isAssignableFrom(clazz))
     }
 
     /**
-     * Loads the default properties maps from the Jitsi installation directory.
+     * Loads the default propertiy maps from the Jitsi installation directory
+     * then overrides them with the default override values.
      */
     private void loadDefaultProperties()
+    {
+        loadDefaultProperties(DEFAULT_PROPS_FILE_NAME);
+        loadDefaultProperties(DEFAULT_OVERRIDES_PROPS_FILE_NAME);
+    }
+
+    /**
+     * Loads the specified default properties maps from the Jitsi installation
+     * directory. Typically this file is to be called for the default properties
+     * and the admin overrides.
+     *
+     * @param  fileName the name of the file we need to load.
+     */
+    private void loadDefaultProperties(String fileName)
     {
         try
         {
             Properties fileProps = new Properties();
 
             fileProps.load(ClassLoader.getSystemClassLoader()
-                .getSystemResourceAsStream(DEFAULT_PROPS_FILE_NAME));
+                .getSystemResourceAsStream(fileName));
 
             // now get those properties and place them into the mutable and
             // immutable properties maps.
@@ -1550,8 +1571,7 @@ private void loadDefaultProperties()
 
                 if (   name == null
                     || value == null
-                    || name.trim().length() == 0
-                    || value.trim().length() == 0)
+                    || name.trim().length() == 0)
                 {
                     continue;
                 }
@@ -1579,8 +1599,9 @@ private void loadDefaultProperties()
         {
             //we can function without defaults so we are just logging those.
             logger.error("Failed to load property file: "
-                + DEFAULT_PROPS_FILE_NAME, ex);
+                + fileName, ex);
         }
-
     }
+
+
 }
-- 
GitLab