Greg Sheremeta has uploaded a new change for review. Change subject: userportal, webadmin: added favicon.ico to branding ......................................................................
userportal, webadmin: added favicon.ico to branding Added favicon.ico serving to the branding feature. Change-Id: I1dcd9d0f22a7c5867c39576020ad16dd6c53deda Bug-Url: https://bugzilla.redhat.com/997547 Signed-off-by: Greg Sheremeta <[email protected]> --- M backend/manager/modules/root/src/main/webapp/WEB-INF/web.xml M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingManager.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingServlet.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingTheme.java M backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingManagerTest.java M backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingServletTest.java A backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/01-test.brand/favicon.ico A backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.brand/branding.properties A backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.brand/favicon.ico A backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.brand/messages.properties A backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.brand/messages_fr.properties A backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/03-test3.brand/branding.properties A backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/03-test3.brand/messages.properties A backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/03-test3.brand/messages_fr.properties R packaging/branding/ovirt.brand/favicon.ico 15 files changed, 178 insertions(+), 5 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/85/18385/1 diff --git a/backend/manager/modules/root/src/main/webapp/WEB-INF/web.xml b/backend/manager/modules/root/src/main/webapp/WEB-INF/web.xml index b797367..25d21e5 100644 --- a/backend/manager/modules/root/src/main/webapp/WEB-INF/web.xml +++ b/backend/manager/modules/root/src/main/webapp/WEB-INF/web.xml @@ -244,6 +244,10 @@ <servlet-name>BrandingServlet</servlet-name> <url-pattern>/ovirt-engine-theme/*</url-pattern> </servlet-mapping> + <servlet-mapping> + <servlet-name>BrandingServlet</servlet-name> + <url-pattern>/favicon.ico</url-pattern> + </servlet-mapping> <!-- Filters --> <filter> diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingManager.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingManager.java index e125cd3..02f0cca 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingManager.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingManager.java @@ -261,4 +261,22 @@ } return templateBuilder.toString(); } + + /** + * Look up the path to the favicon to serve. Like other things in branding, this is cascading. + * We first look in the highest-numbered theme for a favicon.ico file. If it exists, its path is + * returned. If that theme has no favicon, we look in the next-highest theme. And so on. If no + * favicons are found, return null. + * @return path to favicon to serve, or null if no favicons exist + */ + public String getBrandedFaviconPath() { + List<BrandingTheme> brandingThemes = getBrandingThemes(); // assume these are sorted 00, 01, 02, etc. + for (int i = brandingThemes.size() - 1; i >= 0; i--) { + String faviconPath = brandingThemes.get(i).getFaviconPath(); + if (faviconPath != null) { + return faviconPath; + } + } + return null; + } } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingServlet.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingServlet.java index 9c2dd88..667c622 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingServlet.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingServlet.java @@ -45,9 +45,21 @@ final HttpServletResponse response) throws IOException, ServletException { - // serve the file - ServletUtils.sendFile(request, response, - getFile(brandingManager.getBrandingRootPath(), request.getPathInfo()), null); + if (request.getRequestURI().equals("/favicon.ico")) { + String faviconPath = brandingManager.getBrandedFaviconPath(); + if (faviconPath == null) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + else { + ServletUtils.sendFile(request, response, + getFile(brandingManager.getBrandingRootPath(), faviconPath), null); + } + } + else { + ServletUtils.sendFile(request, response, + getFile(brandingManager.getBrandingRootPath(), request.getPathInfo()), null); + } + } /** diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingTheme.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingTheme.java index 79bab40..48433ca 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingTheme.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingTheme.java @@ -283,6 +283,18 @@ return templateBuilder.toString(); } + /** + * Get the path to this theme's favicon, or return null if it doesn't have one. + * @return favicon path, or null if no favicon in this theme + */ + public String getFaviconPath() { + File favicon = new File(filePath + "/favicon.ico"); + if (favicon.exists()) { + return path + "/favicon.ico"; + } + return null; + } + @Override public String toString() { return "Path to theme: " + getPath() + ", User portal css: " //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingManagerTest.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingManagerTest.java index 35b799e..7b71d43 100644 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingManagerTest.java +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingManagerTest.java @@ -34,10 +34,10 @@ public void testGetBrandingThemes() { List<BrandingTheme> result = testManager.getBrandingThemes(); assertNotNull("There should be a result", result); //$NON-NLS-1$ - assertEquals("There should be one active theme", 1, result.size()); //$NON-NLS-1$ + assertEquals("There should be three active themes", 3, result.size()); //$NON-NLS-1$ List<BrandingTheme> result2 = testManager.getBrandingThemes(); assertNotNull("There should be a result", result2); //$NON-NLS-1$ - assertEquals("There should be one active theme", 1, result2.size()); //$NON-NLS-1$ + assertEquals("There should be three active themes", 3, result2.size()); //$NON-NLS-1$ // The second result should be the exact same object as the first one. assertTrue("The result are not the same object", result == result2); //$NON-NLS-1$ } @@ -101,4 +101,18 @@ String result = testManager.getMessage(testKey, Locale.FRENCH); assertEquals("The result should be 'Main header(fr)'", "Main header(fr)", result); } + + /** + * Test that favicon serving works so that the icon in the highest number theme is served, + * unless that theme has no favicon -- in which case search the next highest, and so on. + * e.g. if there are themes 01, 02, and 03, and 01 and 02 have favicons, and 03 does not -- + * the icon in 02 is served. + */ + @Test + public void testGetBrandedFaviconPath() { + // resources for this are hardcoded in test/resources. + // brand 3 has no icon, brands 1 and 2 do. Should retrieve highest brand's (existing) favicon (so, 2) + assertTrue("Should have found test brand 2's favicon", + testManager.getBrandedFaviconPath().contains("02-test2.brand")); + } } diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingServletTest.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingServletTest.java index 4b68889..85ddb7b 100644 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingServletTest.java +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/branding/BrandingServletTest.java @@ -42,6 +42,7 @@ BrandingServlet testServlet; File testFile; + File testFaviconFile; @Before public void setUp() throws Exception { @@ -50,9 +51,13 @@ when(mockBrandingManager.getBrandingRootPath()).thenReturn(mockFile); when(mockFile.getAbsolutePath()).thenReturn("/abs/test"); //$NON-NLS-1$ when(mockRequest.getPathInfo()).thenReturn("/test/something.txt"); //$NON-NLS-1$ + when(mockRequest.getRequestURI()).thenReturn("/test/something.txt"); //$NON-NLS-1$ when(mockResponse.getOutputStream()).thenReturn(mockResponseOutputStream); testFile = new File(this.getClass().getClassLoader(). getResource("./org/ovirt/engine/core/utils/branding/BrandingServletTest.class") //$NON-NLS-1$ + .getFile()); + testFaviconFile = new File(this.getClass().getClassLoader(). + getResource("./org/ovirt/engine/core/utils/branding/01-test.brand/favicon.ico") //$NON-NLS-1$ .getFile()); } @@ -100,4 +105,38 @@ "/abs/test/branding/test", file.getAbsolutePath()); //$NON-NLS-1$ } + /** + * Test that favicon serving works when the request URI is "/favicon". + * @throws IOException + * @throws ServletException + */ + @Test + public void testDoGet_ServeFavicon() throws IOException, ServletException { + when(mockBrandingManager.getBrandingRootPath()).thenReturn( + new File(this.getClass().getClassLoader(). + getResource("./org/ovirt/engine/core/utils/branding") //$NON-NLS-1$ + .getFile())); + when(mockRequest.getRequestURI()).thenReturn("/favicon.ico"); //$NON-NLS-1$ + when(mockBrandingManager.getBrandedFaviconPath()).thenReturn("/02-test2.brand/favicon.ico"); + testServlet.doGet(mockRequest, mockResponse); + verify(mockResponse).setHeader(eq("ETag"), anyString()); //$NON-NLS-1$ + } + + /** + * Test that a 404 is served when no favicons are available. + * @throws IOException + * @throws ServletException + */ + @Test + public void testDoGet_ServeFaviconNotFound() throws IOException, ServletException { + when(mockBrandingManager.getBrandingRootPath()).thenReturn( + new File(this.getClass().getClassLoader(). + getResource("./org/ovirt/engine/core/utils/branding") //$NON-NLS-1$ + .getFile())); + when(mockRequest.getRequestURI()).thenReturn("/favicon.ico"); //$NON-NLS-1$ + when(mockBrandingManager.getBrandedFaviconPath()).thenReturn(null); + testServlet.doGet(mockRequest, mockResponse); + verify(mockResponse).sendError(HttpServletResponse.SC_NOT_FOUND); + } + } diff --git a/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/01-test.brand/favicon.ico b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/01-test.brand/favicon.ico new file mode 100644 index 0000000..91d7b77 --- /dev/null +++ b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/01-test.brand/favicon.ico @@ -0,0 +1 @@ +01-test \ No newline at end of file diff --git a/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.brand/branding.properties b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.brand/branding.properties new file mode 100644 index 0000000..0434c4a --- /dev/null +++ b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.brand/branding.properties @@ -0,0 +1,12 @@ +#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 + +#Version +version=1 \ No newline at end of file diff --git a/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.brand/favicon.ico b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.brand/favicon.ico new file mode 100644 index 0000000..1a7bc71 --- /dev/null +++ b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.brand/favicon.ico @@ -0,0 +1 @@ +02-test2 \ No newline at end of file diff --git a/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.brand/messages.properties b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.brand/messages.properties new file mode 100644 index 0000000..5fb8b17 --- /dev/null +++ b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.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/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.brand/messages_fr.properties b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.brand/messages_fr.properties new file mode 100644 index 0000000..67eee6f --- /dev/null +++ b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/02-test2.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/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/03-test3.brand/branding.properties b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/03-test3.brand/branding.properties new file mode 100644 index 0000000..0434c4a --- /dev/null +++ b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/03-test3.brand/branding.properties @@ -0,0 +1,12 @@ +#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 + +#Version +version=1 \ No newline at end of file diff --git a/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/03-test3.brand/messages.properties b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/03-test3.brand/messages.properties new file mode 100644 index 0000000..5fb8b17 --- /dev/null +++ b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/03-test3.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/utils/src/test/resources/org/ovirt/engine/core/utils/branding/03-test3.brand/messages_fr.properties b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/03-test3.brand/messages_fr.properties new file mode 100644 index 0000000..67eee6f --- /dev/null +++ b/backend/manager/modules/utils/src/test/resources/org/ovirt/engine/core/utils/branding/03-test3.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/backend/manager/modules/root/src/main/webapp/favicon.ico b/packaging/branding/ovirt.brand/favicon.ico similarity index 100% rename from backend/manager/modules/root/src/main/webapp/favicon.ico rename to packaging/branding/ovirt.brand/favicon.ico Binary files differ -- To view, visit http://gerrit.ovirt.org/18385 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1dcd9d0f22a7c5867c39576020ad16dd6c53deda Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Greg Sheremeta <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
