|
1 | 1 | /* |
2 | | - * Copyright 2004-2016 the original author or authors. |
| 2 | + * Copyright 2004-2017 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
16 | 16 |
|
17 | 17 | package org.springframework.faces.webflow; |
18 | 18 |
|
19 | | -import javax.faces.FacesWrapper; |
20 | | -import javax.faces.FactoryFinder; |
21 | 19 | import javax.faces.context.FacesContext; |
22 | 20 |
|
23 | 21 | import org.springframework.util.Assert; |
@@ -77,7 +75,7 @@ public class JsfRuntimeInformation { |
77 | 75 | private static final boolean myFacesPresent = |
78 | 76 | ClassUtils.isPresent("org.apache.myfaces.webapp.MyFacesServlet", CLASSLOADER); |
79 | 77 |
|
80 | | - private static boolean myFacesInUse = isMyFacesContextFactoryInUse(); |
| 78 | + private static Boolean myFacesInUse; |
81 | 79 |
|
82 | 80 |
|
83 | 81 | private static boolean portletPresent = ClassUtils.isPresent("javax.portlet.Portlet", CLASSLOADER); |
@@ -121,26 +119,14 @@ public static boolean isMyFacesPresent() { |
121 | 119 | } |
122 | 120 |
|
123 | 121 | 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; |
138 | 126 | } |
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."); |
143 | 128 | } |
| 129 | + return myFacesInUse; |
144 | 130 | } |
145 | 131 |
|
146 | 132 |
|
|
0 commit comments