From 1ffda5ff3a4690c3cf5187b12e8014f67f0d7238 Mon Sep 17 00:00:00 2001 From: Eclipse Mojarra Bot Date: Thu, 2 Jun 2022 16:14:49 +0000 Subject: [PATCH 1/4] Prepare release org.glassfish:mojarra-parent:4.0.0 --- action/pom.xml | 2 +- cdi/pom.xml | 2 +- impl/pom.xml | 2 +- pom.xml | 2 +- rest/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/action/pom.xml b/action/pom.xml index 4b19838933..94ba285615 100644 --- a/action/pom.xml +++ b/action/pom.xml @@ -22,7 +22,7 @@ org.glassfish mojarra-parent - 4.0.0-SNAPSHOT + 4.0.0 org.eclipse.mojarra diff --git a/cdi/pom.xml b/cdi/pom.xml index 8a93551ff0..1bcf8396e9 100644 --- a/cdi/pom.xml +++ b/cdi/pom.xml @@ -22,7 +22,7 @@ org.glassfish mojarra-parent - 4.0.0-SNAPSHOT + 4.0.0 org.eclipse.mojarra diff --git a/impl/pom.xml b/impl/pom.xml index a7623e1878..66cac59755 100644 --- a/impl/pom.xml +++ b/impl/pom.xml @@ -29,7 +29,7 @@ org.glassfish mojarra-parent - 4.0.0-SNAPSHOT + 4.0.0 jakarta.faces diff --git a/pom.xml b/pom.xml index c37e24cab8..f991b77da3 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ org.glassfish mojarra-parent - 4.0.0-SNAPSHOT + 4.0.0 pom Mojarra ${project.version} - Project diff --git a/rest/pom.xml b/rest/pom.xml index f00a08d6bc..41d9c91c68 100644 --- a/rest/pom.xml +++ b/rest/pom.xml @@ -22,7 +22,7 @@ org.glassfish mojarra-parent - 4.0.0-SNAPSHOT + 4.0.0 org.eclipse.mojarra From cb1a526f91323225c9680de3b71eb7027af554d2 Mon Sep 17 00:00:00 2001 From: Eclipse Mojarra Bot Date: Thu, 2 Jun 2022 16:16:42 +0000 Subject: [PATCH 2/4] Prepare next development cycle for 4.0.1-SNAPSHOT --- action/pom.xml | 2 +- cdi/pom.xml | 2 +- impl/pom.xml | 2 +- pom.xml | 2 +- rest/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/action/pom.xml b/action/pom.xml index 94ba285615..e838028fb1 100644 --- a/action/pom.xml +++ b/action/pom.xml @@ -22,7 +22,7 @@ org.glassfish mojarra-parent - 4.0.0 + 4.0.1-SNAPSHOT org.eclipse.mojarra diff --git a/cdi/pom.xml b/cdi/pom.xml index 1bcf8396e9..f2d19292d5 100644 --- a/cdi/pom.xml +++ b/cdi/pom.xml @@ -22,7 +22,7 @@ org.glassfish mojarra-parent - 4.0.0 + 4.0.1-SNAPSHOT org.eclipse.mojarra diff --git a/impl/pom.xml b/impl/pom.xml index 66cac59755..26f6700860 100644 --- a/impl/pom.xml +++ b/impl/pom.xml @@ -29,7 +29,7 @@ org.glassfish mojarra-parent - 4.0.0 + 4.0.1-SNAPSHOT jakarta.faces diff --git a/pom.xml b/pom.xml index f991b77da3..ed00e390da 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ org.glassfish mojarra-parent - 4.0.0 + 4.0.1-SNAPSHOT pom Mojarra ${project.version} - Project diff --git a/rest/pom.xml b/rest/pom.xml index 41d9c91c68..b735b19e31 100644 --- a/rest/pom.xml +++ b/rest/pom.xml @@ -22,7 +22,7 @@ org.glassfish mojarra-parent - 4.0.0 + 4.0.1-SNAPSHOT org.eclipse.mojarra From bbd80e9bf0df94bd32e78e6bd08a71aa98263ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulo=20Cristov=C3=A3o=20de=20Ara=C3=BAjo=20Silva=20Filho?= Date: Sun, 30 Oct 2022 09:48:46 -0300 Subject: [PATCH 3/4] [localized-composite] Fixing localized properties resource loading --- .../resource/ClasspathResourceHelper.java | 74 ++++++++++++++++--- .../resource/WebappResourceHelper.java | 32 +++++++- 2 files changed, 94 insertions(+), 12 deletions(-) diff --git a/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java b/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java index 78c9a00e75..833adc0c74 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java +++ b/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import com.sun.faces.config.WebConfiguration; import com.sun.faces.util.Util; @@ -112,19 +113,14 @@ protected InputStream getNonCompressedInputStream(ResourceInfo resource, FacesCo if (ctx.isProjectStage(Development)) { ClassLoader loader = Util.getCurrentLoader(getClass()); String path = resource.getPath(); - if (loader.getResource(path) != null) { - in = loader.getResource(path).openStream(); - } - if (in == null && getClass().getClassLoader().getResource(path) != null) { - in = getClass().getClassLoader().getResource(path).openStream(); + URL url = getResourceURL(loader, path, ctx); + if (url != null) { + in = url.openStream(); } } else { ClassLoader loader = Util.getCurrentLoader(getClass()); String path = resource.getPath(); - in = loader.getResourceAsStream(path); - if (in == null) { - in = getClass().getClassLoader().getResourceAsStream(path); - } + in = getResourceAsStream(loader, path, ctx); } return in; } @@ -330,4 +326,64 @@ private URL findPathConsideringContracts(ClassLoader loader, LibraryInfo library return result; } + private InputStream getResourceAsStream(ClassLoader loader, String path, FacesContext ctx) { + InputStream in = null; + List localizedPaths = getLocalizedProperties(path, ctx); + for (String path_: localizedPaths) { + in = getResourceAsStream(loader, path_); + if (in != null) { + break; + } + } + return in; + } + + private URL getResourceURL(ClassLoader loader, String path, FacesContext ctx) { + List localizedPaths = getLocalizedProperties(path, ctx); + URL url = null; + for (String path_: localizedPaths) { + url = getResource_(loader, path_); + if (url != null) { + break; + } + } + return url; + } + + private InputStream getResourceAsStream(ClassLoader loader, String path) { + InputStream in = loader.getResourceAsStream(path); + if (in == null) { + in = getClass().getClassLoader().getResourceAsStream(path); + } + return in; + } + + private URL getResource_(ClassLoader loader, String path) { + URL res = loader.getResource(path); + if (res == null) { + res = getClass().getClassLoader().getResource(path); + } + return res; + } + + private List getLocalizedProperties(String path, FacesContext ctx) { + Locale loc = (ctx != null && ctx.getViewRoot() != null) ? ctx.getViewRoot().getLocale() : null; + if (!path.endsWith(".properties") || loc == null) { + return Collections.singletonList(path); + } + List list = new ArrayList<>(); + String base = path.substring(0, path.lastIndexOf(".properties")); + if (!loc.getVariant().isEmpty()) { + list.add(String.format("%s_%s_%s_%s.properties", base, loc.getLanguage(), loc.getCountry(), loc.getVariant())); + } + if (!loc.getCountry().isEmpty()) { + list.add(String.format("%s_%s_%s.properties", base, loc.getLanguage(), loc.getCountry())); + } + if (!loc.getLanguage().isEmpty()) { + list.add(String.format("%s_%s.properties", base, loc.getLanguage())); + } + list.add(path); + return list; + } + } diff --git a/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java b/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java index 4b3902e5d9..13e691aca1 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java +++ b/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -119,9 +120,15 @@ public String getBaseContractsPath() { */ @Override protected InputStream getNonCompressedInputStream(ResourceInfo resource, FacesContext ctx) throws IOException { - - return ctx.getExternalContext().getResourceAsStream(resource.getPath()); - + List localizedPaths = getLocalizedProperties(resource.getPath(), ctx); + InputStream in = null; + for (String path_: localizedPaths) { + in = ctx.getExternalContext().getResourceAsStream(path_); + if (in != null) { + break; + } + } + return in; } /** @@ -289,4 +296,23 @@ private String findPathConsideringContracts(LibraryInfo library, String resource return basePath; } + private List getLocalizedProperties(String path, FacesContext ctx) { + Locale loc = (ctx != null && ctx.getViewRoot() != null) ? ctx.getViewRoot().getLocale() : null; + if (!path.endsWith(".properties") || loc == null) { + return Collections.singletonList(path); + } + List list = new ArrayList<>(); + String base = path.substring(0, path.lastIndexOf(".properties")); + if (!loc.getVariant().isEmpty()) { + list.add(String.format("%s_%s_%s_%s.properties", base, loc.getLanguage(), loc.getCountry(), loc.getVariant())); + } + if (!loc.getCountry().isEmpty()) { + list.add(String.format("%s_%s_%s.properties", base, loc.getLanguage(), loc.getCountry())); + } + if (!loc.getLanguage().isEmpty()) { + list.add(String.format("%s_%s.properties", base, loc.getLanguage())); + } + list.add(path); + return list; + } } From 223044de3d75c16a0138b16ad23f5d2f820d3493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulo=20Cristov=C3=A3o=20de=20Ara=C3=BAjo=20Silva=20Filho?= Date: Mon, 31 Oct 2022 07:45:35 -0300 Subject: [PATCH 4/4] [localized-components] Fixing DRY issue. --- .../resource/ClasspathResourceHelper.java | 24 ++---------------- .../application/resource/ResourceHelper.java | 21 ++++++++++++++++ .../resource/WebappResourceHelper.java | 25 ++----------------- 3 files changed, 25 insertions(+), 45 deletions(-) diff --git a/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java b/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java index 833adc0c74..543838c487 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java +++ b/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java @@ -328,7 +328,7 @@ private URL findPathConsideringContracts(ClassLoader loader, LibraryInfo library private InputStream getResourceAsStream(ClassLoader loader, String path, FacesContext ctx) { InputStream in = null; - List localizedPaths = getLocalizedProperties(path, ctx); + List localizedPaths = getLocalizedPaths(path, ctx); for (String path_: localizedPaths) { in = getResourceAsStream(loader, path_); if (in != null) { @@ -339,7 +339,7 @@ private InputStream getResourceAsStream(ClassLoader loader, String path, FacesCo } private URL getResourceURL(ClassLoader loader, String path, FacesContext ctx) { - List localizedPaths = getLocalizedProperties(path, ctx); + List localizedPaths = getLocalizedPaths(path, ctx); URL url = null; for (String path_: localizedPaths) { url = getResource_(loader, path_); @@ -366,24 +366,4 @@ private URL getResource_(ClassLoader loader, String path) { return res; } - private List getLocalizedProperties(String path, FacesContext ctx) { - Locale loc = (ctx != null && ctx.getViewRoot() != null) ? ctx.getViewRoot().getLocale() : null; - if (!path.endsWith(".properties") || loc == null) { - return Collections.singletonList(path); - } - List list = new ArrayList<>(); - String base = path.substring(0, path.lastIndexOf(".properties")); - if (!loc.getVariant().isEmpty()) { - list.add(String.format("%s_%s_%s_%s.properties", base, loc.getLanguage(), loc.getCountry(), loc.getVariant())); - } - if (!loc.getCountry().isEmpty()) { - list.add(String.format("%s_%s_%s.properties", base, loc.getLanguage(), loc.getCountry())); - } - if (!loc.getLanguage().isEmpty()) { - list.add(String.format("%s_%s.properties", base, loc.getLanguage())); - } - list.add(path); - return list; - } - } diff --git a/impl/src/main/java/com/sun/faces/application/resource/ResourceHelper.java b/impl/src/main/java/com/sun/faces/application/resource/ResourceHelper.java index 31d34aa5f2..7c84420def 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/ResourceHelper.java +++ b/impl/src/main/java/com/sun/faces/application/resource/ResourceHelper.java @@ -35,6 +35,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -705,4 +706,24 @@ private boolean isPropertyValid(String property) { } // END ELEvaluatingInputStream + protected List getLocalizedPaths(String path, FacesContext ctx) { + Locale loc = (ctx != null && ctx.getViewRoot() != null) ? ctx.getViewRoot().getLocale() : null; + if (!path.endsWith(".properties") || loc == null) { + return Collections.singletonList(path); + } + List list = new ArrayList<>(); + String base = path.substring(0, path.lastIndexOf(".properties")); + if (!loc.getVariant().isEmpty()) { + list.add(String.format("%s_%s_%s_%s.properties", base, loc.getLanguage(), loc.getCountry(), loc.getVariant())); + } + if (!loc.getCountry().isEmpty()) { + list.add(String.format("%s_%s_%s.properties", base, loc.getLanguage(), loc.getCountry())); + } + if (!loc.getLanguage().isEmpty()) { + list.add(String.format("%s_%s.properties", base, loc.getLanguage())); + } + list.add(path); + return list; + } + } diff --git a/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java b/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java index 13e691aca1..17ef10ebc0 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java +++ b/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Locale; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -114,13 +113,13 @@ public String getBaseContractsPath() { return BASE_CONTRACTS_PATH; } - /** + /** * @see ResourceHelper#getNonCompressedInputStream(com.sun.faces.application.resource.ResourceInfo, * jakarta.faces.context.FacesContext) */ @Override protected InputStream getNonCompressedInputStream(ResourceInfo resource, FacesContext ctx) throws IOException { - List localizedPaths = getLocalizedProperties(resource.getPath(), ctx); + List localizedPaths = getLocalizedPaths(resource.getPath(), ctx); InputStream in = null; for (String path_: localizedPaths) { in = ctx.getExternalContext().getResourceAsStream(path_); @@ -295,24 +294,4 @@ private String findPathConsideringContracts(LibraryInfo library, String resource return basePath; } - - private List getLocalizedProperties(String path, FacesContext ctx) { - Locale loc = (ctx != null && ctx.getViewRoot() != null) ? ctx.getViewRoot().getLocale() : null; - if (!path.endsWith(".properties") || loc == null) { - return Collections.singletonList(path); - } - List list = new ArrayList<>(); - String base = path.substring(0, path.lastIndexOf(".properties")); - if (!loc.getVariant().isEmpty()) { - list.add(String.format("%s_%s_%s_%s.properties", base, loc.getLanguage(), loc.getCountry(), loc.getVariant())); - } - if (!loc.getCountry().isEmpty()) { - list.add(String.format("%s_%s_%s.properties", base, loc.getLanguage(), loc.getCountry())); - } - if (!loc.getLanguage().isEmpty()) { - list.add(String.format("%s_%s.properties", base, loc.getLanguage())); - } - list.add(path); - return list; - } }