1
2
3
4 package org.rcfaces.core.internal.tools;
5
6 import java.util.Map;
7
8 import javax.faces.context.FacesContext;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 import org.rcfaces.core.component.capability.IAsyncRenderModeCapability;
13 import org.rcfaces.core.internal.Constants;
14 import org.rcfaces.core.internal.facelets.FaceletViewHandler;
15 import org.rcfaces.core.internal.util.ClassLocator;
16
17
18
19
20
21
22 public class AsyncModeTools {
23 private static final String REVISION = "$Revision: 1.2 $";
24
25 private static final Log LOG = LogFactory.getLog(AsyncModeTools.class);
26
27 private static final String FACELETS_CLASS_NAME = "com.sun.facelets.Facelet";
28
29 private static final String FACELETS_PROCESSOR_PROPERTY = "org.rcfaces.core.internal.tools.FACELETS_PROCESSOR";
30
31 public static boolean isTagProcessor(FacesContext facesContext) {
32 return isFaceletsProcessor(facesContext) == false;
33 }
34
35 private static boolean isFaceletsProcessor(FacesContext context) {
36 if (Constants.FACELETS_SUPPORT == false) {
37 return false;
38 }
39
40 if (context == null) {
41 context = FacesContext.getCurrentInstance();
42 }
43
44 Map applicationMap = context.getExternalContext().getApplicationMap();
45
46 Boolean b;
47 synchronized (AsyncModeTools.class) {
48 b = (Boolean) applicationMap.get(FACELETS_PROCESSOR_PROPERTY);
49 if (b == null) {
50 b = Boolean.valueOf(searchFaceletsProcessor(context));
51
52 applicationMap.put(FACELETS_PROCESSOR_PROPERTY, b);
53 }
54 }
55
56 return b.booleanValue();
57 }
58
59 private static boolean searchFaceletsProcessor(FacesContext context) {
60 Class cls;
61
62 try {
63 cls = ClassLocator.load(FACELETS_CLASS_NAME, ComponentTools.class,
64 context);
65
66 } catch (ClassNotFoundException ex) {
67
68 LOG.debug("Class '" + FACELETS_CLASS_NAME + "' is not found !", ex);
69 return false;
70 }
71
72 LOG.debug("Class '" + cls.getName() + "' detected");
73
74 return FaceletViewHandler.isFaceletProcessor(context);
75 }
76
77 public static int getEnableValue(FacesContext context) {
78 if (isFaceletsProcessor(context)) {
79 return IAsyncRenderModeCapability.TREE_ASYNC_RENDER_MODE;
80 }
81
82
83 return Constants.ENABLE_ASYNC_MODE_VALUE;
84 }
85
86 }