Skip to content

Commit 5a86845

Browse files
committed
One time only runtime check if MyFaces is in use
Issue: SWF-1698
1 parent 380de15 commit 5a86845

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

spring-faces/src/main/java/org/springframework/faces/webflow/JsfRuntimeInformation.java

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2004-2016 the original author or authors.
2+
* Copyright 2004-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.faces.webflow;
1818

19-
import javax.faces.FacesWrapper;
20-
import javax.faces.FactoryFinder;
2119
import javax.faces.context.FacesContext;
2220

2321
import org.springframework.util.Assert;
@@ -77,7 +75,7 @@ public class JsfRuntimeInformation {
7775
private static final boolean myFacesPresent =
7876
ClassUtils.isPresent("org.apache.myfaces.webapp.MyFacesServlet", CLASSLOADER);
7977

80-
private static boolean myFacesInUse = isMyFacesContextFactoryInUse();
78+
private static Boolean myFacesInUse;
8179

8280

8381
private static boolean portletPresent = ClassUtils.isPresent("javax.portlet.Portlet", CLASSLOADER);
@@ -121,26 +119,14 @@ public static boolean isMyFacesPresent() {
121119
}
122120

123121
public static boolean isMyFacesInUse() {
124-
if (myFacesInUse) {
125-
return true;
126-
}
127-
// On WebSphere MyFaces may have loaded after this class...
128-
myFacesInUse = isMyFacesContextFactoryInUse();
129-
return myFacesInUse;
130-
}
131-
132-
private static boolean isMyFacesContextFactoryInUse() {
133-
try {
134-
Class<?> clazz = CLASSLOADER.loadClass("org.apache.myfaces.context.FacesContextFactoryImpl");
135-
Object factory = FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
136-
while (!clazz.isInstance(factory) && factory instanceof FacesWrapper) {
137-
factory = ((FacesWrapper) factory).getWrapped();
122+
if (myFacesInUse == null) {
123+
FacesContext facesContext = FacesContext.getCurrentInstance();
124+
if (facesContext == null) {
125+
return false;
138126
}
139-
return (factory != null && clazz.isInstance(factory));
140-
}
141-
catch (Throwable ex) {
142-
return false;
127+
myFacesInUse = facesContext.getClass().getPackage().getName().startsWith("org.apache.myfaces.");
143128
}
129+
return myFacesInUse;
144130
}
145131

146132

0 commit comments

Comments
 (0)