Greg Sheremeta has posted comments on this change.
Change subject: userportal, webadmin: added branding cascading resource servlet
......................................................................
Patch Set 6:
(9 comments)
....................................................
File
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingCascadingResourceServlet.java
Line 47: String resourceFilePath =
brandingManager.getCascadedResource(resourceName);
Line 48:
Line 49: // serve the file
Line 50: ServletUtils.sendFile(request, response,
Line 51:
BrandingUtils.getFile(brandingManager.getBrandingRootPath(), resourceFilePath),
null);
Done
Line 52: }
Line 53:
....................................................
File
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingManager.java
Line 292: List<BrandingTheme> brandingThemes = getBrandingThemes();
// assume these are sorted 00, 01, 02, etc.
Line 293: for (int i = brandingThemes.size() - 1; i >= 0; i--) {
Line 294: String resourcePath =
brandingThemes.get(i).getResourcePath(resourceName);
Line 295: if (resourcePath != null) {
Line 296: return resourcePath;
I don't have a problem with multiple returns. The belief that there should only
be one return in a function is antiquated and leads to code that's hard to read.
Added the CascadingResource class.
Line 297: }
Line 298: }
Line 299: }
Line 300: return null;
....................................................
File
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingTheme.java
Line 235: * Get the theme cascading resources bundle.
Line 236: * @return A {@code ResourceBundle} containing resource paths.
Line 237: */
Line 238: public ResourceBundle getResourcesBundle() {
Line 239: List<ResourceBundle> bundleList = getBundle(RESOURCES_KEY,
LocaleFilter.DEFAULT_LOCALE);
Dummy removed. Instead of a null check, I throw a MissingResourceException.
Same results. The dummy was a bad idea. Thanks.
Line 240: if (bundleList.size() >= 1) {
Line 241: return bundleList.get(0);
Line 242: }
Line 243:
Line 347: * Look for the resource in this theme, and return the path to it
if it exists.
Line 348: * Return null if the resource isn't found in the theme.
Line 349: * @return resource path, or null if no resource found in this
theme
Line 350: */
Line 351: public String getResourcePath(String resourceName) {
Done
Line 352: if (resourceName != null) {
Line 353: try {
Line 354: String resourceFile =
getResourcesBundle().getString(resourceName);
Line 355: if (resourceFile != null) {
Line 350: */
Line 351: public String getResourcePath(String resourceName) {
Line 352: if (resourceName != null) {
Line 353: try {
Line 354: String resourceFile =
getResourcesBundle().getString(resourceName);
Done
Line 355: if (resourceFile != null) {
Line 356: File file = new File(filePath + "/" +
resourceFile); //$NON-NLS-1$
Line 357: if (file.exists() && file.canRead()) {
Line 358: return path + "/" + resourceFile;
//$NON-NLS-1$
Line 354: String resourceFile =
getResourcesBundle().getString(resourceName);
Line 355: if (resourceFile != null) {
Line 356: File file = new File(filePath + "/" +
resourceFile); //$NON-NLS-1$
Line 357: if (file.exists() && file.canRead()) {
Line 358: return path + "/" + resourceFile;
//$NON-NLS-1$
you could ... I usually don't :)
Line 359: }
Line 360: }
Line 361: }
Line 362: catch (MissingResourceException mre) {
Line 363: // no-op -- this theme just doesn't have this
resource. will try the next lowest theme.
Line 364: }
Line 365: }
Line 366: return null;
Line 367: }
basically done
Line 368:
Line 369: @Override
Line 370: public String toString() {
Line 371: return "Path to theme: " + getPath() + ", User portal css: "
//$NON-NLS-1$ //$NON-NLS-2$
....................................................
File
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/branding/BrandingUtils.java
Line 18: * @param brandingRootPath The path to the root of the branding.
Cannot be null
Line 19: * @param path The path to translate.
Line 20: * @return A full absolute path for the passed in path.
Line 21: */
Line 22: public static File getFile(final File brandingRootPath, final
String path) {
Done / no longer needed to extract this
Line 23: File result = null;
Line 24: String mergedPath = new
File(brandingRootPath.getAbsolutePath(), path == null ? "":
path).getAbsolutePath();
Line 25: if (path != null && ServletUtils.isSane(mergedPath)) {
Line 26: // Return a result relative to the branding root path.
....................................................
File packaging/branding/ovirt.brand/resources.properties
Line 5: # If the same resource key exists in a higher brand, the higher brand
"wins" and
Line 6: # its copy of the resource gets served.
Line 7: #
Line 8:
Line 9: favicon=images/favicon.ico
Done
--
To view, visit http://gerrit.ovirt.org/18385
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I1dcd9d0f22a7c5867c39576020ad16dd6c53deda
Gerrit-PatchSet: 6
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Greg Sheremeta <[email protected]>
Gerrit-Reviewer: Alexander Wels <[email protected]>
Gerrit-Reviewer: Alon Bar-Lev <[email protected]>
Gerrit-Reviewer: Einav Cohen <[email protected]>
Gerrit-Reviewer: Greg Sheremeta <[email protected]>
Gerrit-Reviewer: Vojtech Szocs <[email protected]>
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches