1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.util;
20
21 import java.util.ArrayList;
22 import java.util.List;
23 import javax.faces.FacesException;
24 import javax.faces.component.UIComponent;
25 import javax.faces.component.UIViewRoot;
26 import javax.faces.context.FacesContext;
27 import org.apache.myfaces.shared.renderkit.JSFAttr;
28 import org.apache.myfaces.shared.util.ClassUtils;
29
30
31
32
33
34
35 public class FaceletsViewDeclarationLanguageUtils
36 {
37 public static Class getReturnType(String signature)
38 {
39 int endName = signature.indexOf('(');
40 if (endName < 0)
41 {
42 throw new FacesException("Invalid method signature:" + signature);
43 }
44 int end = signature.lastIndexOf(' ', endName);
45 if (end < 0)
46 {
47 throw new FacesException("Invalid method signature:" + signature);
48 }
49 try
50 {
51 return ClassUtils.javaDefaultTypeToClass(signature.substring(0, end));
52 }
53 catch (ClassNotFoundException e)
54 {
55 throw new FacesException("Invalid method signature:" + signature);
56 }
57 }
58
59
60
61
62
63
64 public static Class[] getParameters(String signature) throws FacesException
65 {
66 ArrayList<Class> params = new ArrayList<Class>();
67
68
69
70 int start = signature.indexOf('(') + 1;
71 boolean lastArg = false;
72 while (true)
73 {
74 int p = signature.indexOf(',', start);
75 if (p < 0)
76 {
77 p = signature.indexOf(')', start);
78 if (p < 0)
79 {
80 throw new FacesException("Invalid method signature:" + signature);
81 }
82 lastArg = true;
83 }
84 String arg = signature.substring(start, p).trim();
85 if (!"".equals(arg))
86 {
87 try
88 {
89 params.add(ClassUtils.javaDefaultTypeToClass(arg));
90 }
91 catch (ClassNotFoundException e)
92 {
93 throw new FacesException("Invalid method signature:" + signature);
94 }
95 }
96 if (lastArg)
97 {
98 break;
99 }
100 start = p + 1;
101 }
102 return params.toArray(new Class[params.size()]);
103 }
104
105
106
107
108
109
110
111
112 public static void markRenderedResources(FacesContext facesContext, UIViewRoot view)
113 {
114 if (view != null && facesContext.getPartialViewContext().isAjaxRequest())
115 {
116 markRenderedResources(facesContext, view, view.getComponentResources(facesContext, "head"));
117 markRenderedResources(facesContext, view, view.getComponentResources(facesContext, "body"));
118 }
119 }
120
121 private static void markRenderedResources(FacesContext facesContext, UIViewRoot view,
122 List<UIComponent> componentResources)
123 {
124 if (componentResources != null)
125 {
126 for (UIComponent component : componentResources)
127 {
128 if ("javax.faces.resource.Script".equals(component.getRendererType()) ||
129 "javax.faces.resource.Stylesheet".equals(component.getRendererType()))
130 {
131 String resourceName = (String) component.getAttributes().get(JSFAttr.NAME_ATTR);
132 String libraryName = (String) component.getAttributes().get(JSFAttr.LIBRARY_ATTR);
133
134 if (resourceName == null)
135 {
136 continue;
137 }
138 if ("".equals(resourceName))
139 {
140 continue;
141 }
142
143 int index = resourceName.indexOf('?');
144 if (index >= 0)
145 {
146 resourceName = resourceName.substring(0, index);
147 }
148
149 facesContext.getApplication().getResourceHandler().markResourceRendered(
150 facesContext, resourceName, libraryName);
151 }
152 }
153 }
154 }
155 }