Alexander Wels has uploaded a new change for review.

Change subject: branding: Allow templates to be replaced
......................................................................

branding: Allow templates to be replaced

- Allowed themes the ability to override the default behaviour of
  append their templates to previous template. This allows themes
  to almost completely replace the entire welcome page.

Change-Id: Id3376500d1ceece80132089d90174e092992d36d
Signed-off-by: Alexander Wels <[email protected]>
---
M README.branding
M 
backend/manager/modules/branding/src/main/java/org/ovirt/engine/core/branding/BrandingManager.java
M 
backend/manager/modules/branding/src/main/java/org/ovirt/engine/core/branding/BrandingTheme.java
M 
backend/manager/modules/branding/src/test/java/org/ovirt/engine/core/branding/BrandingThemeTest.java
A 
backend/manager/modules/branding/src/test/resources/org/ovirt/engine/core/branding/06-test6.brand/branding.properties
A 
backend/manager/modules/branding/src/test/resources/org/ovirt/engine/core/branding/06-test6.brand/messages.properties
A 
backend/manager/modules/branding/src/test/resources/org/ovirt/engine/core/branding/06-test6.brand/messages_fr.properties
M packaging/branding/ovirt.brand/branding.properties
8 files changed, 117 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/55/23455/1

diff --git a/README.branding b/README.branding
index 9a3a82e..dd225af 100644
--- a/README.branding
+++ b/README.branding
@@ -95,6 +95,14 @@
 The output will be:
 <a href="/fr_FR/documenation">Documenation</a>
 
+If you want to completely replace any previous templates you can add a new key 
to
+the branding.properties file called welcome_replace with a value of true. This
+will cause the template engine to wipe out the template generated by processing
+previous theme, and complete replace it with yours. Default behaviour is to 
append
+your template to the end of the previous template(s). This flag allows you to
+override that behaviour and just use your template. Any themes processed after
+yours will default back to append unless they specify the flag as well.
+
 INSTALLATION
 ------------
 
diff --git 
a/backend/manager/modules/branding/src/main/java/org/ovirt/engine/core/branding/BrandingManager.java
 
b/backend/manager/modules/branding/src/main/java/org/ovirt/engine/core/branding/BrandingManager.java
index 45572dc..0ccc1da 100644
--- 
a/backend/manager/modules/branding/src/main/java/org/ovirt/engine/core/branding/BrandingManager.java
+++ 
b/backend/manager/modules/branding/src/main/java/org/ovirt/engine/core/branding/BrandingManager.java
@@ -270,6 +270,10 @@
                 }
             }
             replacedTemplate = replacedTemplate.replaceAll(USER_LOCALE_HOLDER, 
locale.toString());
+            if (theme.shouldReplaceWelcomePageSectionTemplate()) {
+                //Clear the template builder as the theme wants to replace 
instead of append to the template.
+                templateBuilder = new StringBuilder();
+            }
             templateBuilder.append(replacedTemplate);
         }
         return templateBuilder.toString();
diff --git 
a/backend/manager/modules/branding/src/main/java/org/ovirt/engine/core/branding/BrandingTheme.java
 
b/backend/manager/modules/branding/src/main/java/org/ovirt/engine/core/branding/BrandingTheme.java
index 6b139f3..a6e08c9 100644
--- 
a/backend/manager/modules/branding/src/main/java/org/ovirt/engine/core/branding/BrandingTheme.java
+++ 
b/backend/manager/modules/branding/src/main/java/org/ovirt/engine/core/branding/BrandingTheme.java
@@ -8,6 +8,7 @@
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Locale;
 import java.util.MissingResourceException;
@@ -63,6 +64,12 @@
     private static final String TEMPLATE_KEY = "welcome"; //$NON-NLS-1$
 
     /**
+     * The key used to determine if this template should completely replace 
the template build from all
+     * previously processed themes.
+     */
+    private static final String REPLACE_TEMPLATE_KEY = "welcome_replace"; 
//$NON-NLS-1$
+
+    /**
      * Property suffix for cascading resources file.
      */
     private static final String FILE_SUFFIX = ".file"; //$NON-NLS-1$
@@ -76,6 +83,8 @@
      * Post fix for denoting css files.
      */
     private static final String CSS_POST_FIX = "_css";
+
+    private static final String[] TEMPLATE_REPLACE_VALUES = {"true", "false"}; 
//$NON-NLS-1$ //$NON-NLS-2$
 
     /**
      * The properties associated with the branding theme.
@@ -128,6 +137,11 @@
             if (!available) {
                 log.warn("Unable to load branding theme, mismatched version: " 
//$NON-NLS-1$
                     + getVersion(brandingProperties) + " wanted version: " + 
supportedBrandingVersion); //$NON-NLS-1$
+            } else {
+                available = verifyPropertyValues(brandingProperties);
+                if (!available) {
+                    log.warn("Unable to load branding theme, property value 
verification failed"); //$NON-NLS-1$
+                }
             }
         } catch (IOException e) {
             // Unable to load properties file, disable theme.
@@ -136,6 +150,21 @@
                     + propertiesFileName, e);
         }
         return available;
+    }
+
+    /**
+     * Verify that all required property values are valid.
+     * @param properties The {@code Properties} object to check.
+     */
+    private boolean verifyPropertyValues(final Properties properties) {
+        boolean result = true;
+        if (brandingProperties.getProperty(REPLACE_TEMPLATE_KEY) != null &&
+            !Arrays.asList(TEMPLATE_REPLACE_VALUES).contains(
+                    
brandingProperties.getProperty(REPLACE_TEMPLATE_KEY).toLowerCase())) {
+            log.warn(REPLACE_TEMPLATE_KEY + " value is not true or false"); 
//$NON-NLS-1$
+            result = false;
+        }
+        return result;
     }
 
     /**
@@ -241,6 +270,10 @@
         return result;
     }
 
+    public boolean shouldReplaceWelcomePageSectionTemplate() {
+        return 
Boolean.valueOf(brandingProperties.getProperty(REPLACE_TEMPLATE_KEY));
+    }
+
     /**
      * Return the raw welcome template as a string.
      * @return The raw template string.
diff --git 
a/backend/manager/modules/branding/src/test/java/org/ovirt/engine/core/branding/BrandingThemeTest.java
 
b/backend/manager/modules/branding/src/test/java/org/ovirt/engine/core/branding/BrandingThemeTest.java
index 4d9e0bc..a554126 100644
--- 
a/backend/manager/modules/branding/src/test/java/org/ovirt/engine/core/branding/BrandingThemeTest.java
+++ 
b/backend/manager/modules/branding/src/test/java/org/ovirt/engine/core/branding/BrandingThemeTest.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.core.branding;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -105,4 +106,30 @@
                 theme5.getCascadingResource("this_file_is_missing_anyway")); 
//$NON-NLS-1$
     }
 
+    @Test
+    public void testInvalidTemplateReplaceProperty() throws URISyntaxException 
{
+        File testThemeRootPath = new File(this.getClass().getClassLoader().
+                getResource("./org/ovirt/engine/core/branding") //$NON-NLS-1$
+                .toURI().getPath());
+        // theme 6 purposely has an invalid welcome_replace value.
+        File testThemePath = new File(testThemeRootPath.getAbsoluteFile(), 
"06-test6.brand"); //$NON-NLS-1$
+        BrandingTheme theme6 = new 
BrandingTheme(testThemePath.getAbsolutePath(),
+                testThemeRootPath, 1); //$NON-NLS-1$
+        assertFalse("Theme 6 should not load", theme6.load()); //$NON-NLS-1$
+
+    }
+
+    @Test
+    public void testTemplateReplaceProperty() throws URISyntaxException {
+        File testThemeRootPath = new File(this.getClass().getClassLoader().
+                getResource("./org/ovirt/engine/core/branding") //$NON-NLS-1$
+                .toURI().getPath());
+        File testThemePath = new File(testThemeRootPath.getAbsoluteFile(), 
"01-test.brand"); //$NON-NLS-1$
+        BrandingTheme theme1 = new 
BrandingTheme(testThemePath.getAbsolutePath(),
+                testThemeRootPath, 1); //$NON-NLS-1$
+        assertTrue("Theme 1 should load", theme1.load()); //$NON-NLS-1$
+        assertFalse("should replace template should be false", //$NON-NLS-1$
+                theme1.shouldReplaceWelcomePageSectionTemplate());
+
+    }
 }
diff --git 
a/backend/manager/modules/branding/src/test/resources/org/ovirt/engine/core/branding/06-test6.brand/branding.properties
 
b/backend/manager/modules/branding/src/test/resources/org/ovirt/engine/core/branding/06-test6.brand/branding.properties
new file mode 100644
index 0000000..64c42e3
--- /dev/null
+++ 
b/backend/manager/modules/branding/src/test/resources/org/ovirt/engine/core/branding/06-test6.brand/branding.properties
@@ -0,0 +1,18 @@
+#branding properties.
+#possible values OEM, END_USER, if missing defaults to END_USER
+type=END_USER
+#style sheets.
+user_portal_css=user_portal.css
+web_admin_css=web_admin.css
+common_css=common.css
+
+#text
+messages=messages.properties
+
+#resources
+# purposely don't specify for test
+
+welcome_replace=trux
+
+#Version
+version=1
diff --git 
a/backend/manager/modules/branding/src/test/resources/org/ovirt/engine/core/branding/06-test6.brand/messages.properties
 
b/backend/manager/modules/branding/src/test/resources/org/ovirt/engine/core/branding/06-test6.brand/messages.properties
new file mode 100644
index 0000000..5fb8b17
--- /dev/null
+++ 
b/backend/manager/modules/branding/src/test/resources/org/ovirt/engine/core/branding/06-test6.brand/messages.properties
@@ -0,0 +1,12 @@
+#common
+obrand.common.login_header_label=Login header
+obrand.common.main_header_label=Main header
+obrand.common.copy_right_notice=copy right notice
+obrand.common.version_about=version about
+
+#user portal
+obrand.userportal.application_title=User Portal
+
+#web admin
+obrand.webadmin.application_title=Web Admin
+obrand.webadmin.doc=Documentations
diff --git 
a/backend/manager/modules/branding/src/test/resources/org/ovirt/engine/core/branding/06-test6.brand/messages_fr.properties
 
b/backend/manager/modules/branding/src/test/resources/org/ovirt/engine/core/branding/06-test6.brand/messages_fr.properties
new file mode 100644
index 0000000..67eee6f
--- /dev/null
+++ 
b/backend/manager/modules/branding/src/test/resources/org/ovirt/engine/core/branding/06-test6.brand/messages_fr.properties
@@ -0,0 +1,12 @@
+#common
+obrand.common.login_header_label=Login header(fr)
+obrand.common.main_header_label=Main header(fr)
+obrand.common.copy_right_notice=copy right notice(fr)
+obrand.common.version_about=version about(fr)
+
+#user portal
+obrand.userportal.application_title=User Portal(fr)
+
+#web admin
+obrand.webadmin.application_title=Web Admin(fr)
+obrand.webadmin.doc=Documentations(fr)
diff --git a/packaging/branding/ovirt.brand/branding.properties 
b/packaging/branding/ovirt.brand/branding.properties
index 1fc7561..3b524e1 100644
--- a/packaging/branding/ovirt.brand/branding.properties
+++ b/packaging/branding/ovirt.brand/branding.properties
@@ -25,6 +25,9 @@
 
 # Welcome page template (optional, allows you to add things to the welcome 
page)
 welcome=welcome_page.template
+# Set to 'true' if you want your template to completely replace the template 
build from
+# all the templates of earlier processed themes.
+#welcome_replace=
 
 # version (required, the theme will not be applied without this property)
 version=1


-- 
To view, visit http://gerrit.ovirt.org/23455
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id3376500d1ceece80132089d90174e092992d36d
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.3
Gerrit-Owner: Alexander Wels <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to