1
2
3
4 package org.rcfaces.core.util;
5
6 import javax.faces.FacesException;
7 import javax.faces.context.FacesContext;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11 import org.rcfaces.core.internal.Constants;
12
13
14
15
16
17
18 public class VariableResolver {
19
20 private static final String REVISION = "$Revision: 1.1 $";
21
22 private static final Log LOG = LogFactory.getLog(VariableResolver.class);
23
24
25
26
27
28
29
30
31
32
33 public static Object resolve(String variable) {
34 return resolve(variable, null);
35 }
36
37
38
39
40
41
42
43
44
45
46
47
48 public static Object resolve(String variable, FacesContext facesContext) {
49
50 if (facesContext == null) {
51 facesContext = FacesContext.getCurrentInstance();
52 }
53
54 if (Constants.VERIFY_VARIABLE_SYNTAX) {
55 char chs[] = variable.toCharArray();
56
57 for (int i = 0; i < chs.length; i++) {
58 if (i == 0) {
59 if (Character.isJavaIdentifierStart(chs[i]) == false) {
60 throw new FacesException(
61 "Illegal start of variable name '" + variable
62 + "'.");
63 }
64
65 continue;
66 }
67
68 if (Character.isJavaIdentifierPart(chs[i]) == false) {
69 throw new FacesException(
70 "Illegal character into variable name '" + variable
71 + "'. (position=" + i + ")");
72 }
73 }
74 }
75
76 if (LOG.isDebugEnabled()) {
77 LOG.debug("Try to resolve variable '" + variable + "'.");
78 }
79
80 Object ret;
81 if (false
82
83
84
85 } else {
86 javax.faces.el.VariableResolver variableResolver = facesContext
87 .getApplication().getVariableResolver();
88
89 ret = variableResolver.resolveVariable(facesContext, variable);
90 }
91
92 if (LOG.isDebugEnabled()) {
93 LOG.debug("Resolved variable '" + variable + "' = " + ret);
94 }
95
96 if (ret == null) {
97 throw new FacesException("No variable associated to name '"
98 + variable + "'.");
99 }
100
101 return ret;
102 }
103 }