From c267b1c064b55a1614e82a2126efdc57794013d1 Mon Sep 17 00:00:00 2001 From: Bauke Scholtz Date: Tue, 20 Dec 2016 21:55:50 +0100 Subject: [PATCH] Added Faces#isSystemTest() and Faces#isProduction() --- src/main/java/org/omnifaces/util/Faces.java | 26 +++++++++++++++++++ .../java/org/omnifaces/util/FacesLocal.java | 18 ++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/omnifaces/util/Faces.java b/src/main/java/org/omnifaces/util/Faces.java index bb380fd82..24754fa5c 100644 --- a/src/main/java/org/omnifaces/util/Faces.java +++ b/src/main/java/org/omnifaces/util/Faces.java @@ -318,6 +318,32 @@ public static boolean isDevelopment() { return FacesLocal.isDevelopment(getContext()); } + /** + * Returns whether we're in system test stage. This will be the case when the javax.faces.PROJECT_STAGE + * context parameter in web.xml is set to SystemTest. + *

+ * This is also available in EL as #{faces.systemTest}. + * @return true if we're in system test stage, otherwise false. + * @see Application#getProjectStage() + * @since 2.6 + */ + public static boolean isSystemTest() { + return FacesLocal.isSystemTest(getContext()); + } + + /** + * Returns whether we're in production stage. This will be the case when the javax.faces.PROJECT_STAGE + * context parameter in web.xml is set to Production. + *

+ * This is also available in EL as #{faces.production}. + * @return true if we're in production stage, otherwise false. + * @see Application#getProjectStage() + * @since 2.6 + */ + public static boolean isProduction() { + return FacesLocal.isProduction(getContext()); + } + /** * Determines and returns the faces servlet mapping used in the current request. If JSF is prefix mapped (e.g. * /faces/*), then this returns the whole path, with a leading slash (e.g. /faces). If JSF diff --git a/src/main/java/org/omnifaces/util/FacesLocal.java b/src/main/java/org/omnifaces/util/FacesLocal.java index 2364c9774..9a41c672b 100644 --- a/src/main/java/org/omnifaces/util/FacesLocal.java +++ b/src/main/java/org/omnifaces/util/FacesLocal.java @@ -166,7 +166,23 @@ public static ProjectStage getProjectStage(FacesContext context) { * @see Faces#isDevelopment() */ public static boolean isDevelopment(FacesContext context) { - return context.getApplication().getProjectStage() == ProjectStage.Development; + return getProjectStage(context) == ProjectStage.Development; + } + + /** + * {@inheritDoc} + * @see Faces#isSystemTest() + */ + public static boolean isSystemTest(FacesContext context) { + return getProjectStage(context) == ProjectStage.SystemTest; + } + + /** + * {@inheritDoc} + * @see Faces#isProduction() + */ + public static boolean isProduction(FacesContext context) { + return getProjectStage(context) == ProjectStage.Production; } /**