1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.jsp;
20
21 import java.util.LinkedList;
22 import java.util.StringTokenizer;
23 import javax.faces.context.ExternalContext;
24 import javax.faces.context.FacesContext;
25 import javax.faces.view.ViewDeclarationLanguage;
26 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
27
28 import org.apache.myfaces.view.ViewDeclarationLanguageStrategy;
29
30
31
32
33
34
35
36 public class JspViewDeclarationLanguageStrategy implements ViewDeclarationLanguageStrategy
37 {
38 private ViewDeclarationLanguage _language;
39 private LinkedList<String> _suffixes;
40
41
42
43
44 @JSFWebConfigParam(defaultValue=".jsp", since="2.3", group="viewhandler")
45 public static final String JSP_SUFFIX_PARAM_NAME = "org.apache.myfaces.JSP_SUFFIX";
46 public static final String JSP_SUFFIX_DEFAULT = ".jsp";
47
48 public JspViewDeclarationLanguageStrategy()
49 {
50 FacesContext facesContext = FacesContext.getCurrentInstance();
51
52 _suffixes = loadSuffixes (facesContext.getExternalContext());
53 _language = new JspViewDeclarationLanguage(facesContext, this, _suffixes);
54 }
55
56
57
58
59 @Override
60 public ViewDeclarationLanguage getViewDeclarationLanguage()
61 {
62 return _language;
63 }
64
65
66
67
68 @Override
69 public boolean handles(String viewId)
70 {
71
72
73
74
75
76
77
78
79
80
81 return true;
82 }
83
84 static LinkedList<String> loadSuffixes (ExternalContext context)
85 {
86 LinkedList<String> result = new LinkedList<String>();
87 String definedSuffixes = context.getInitParameter (JSP_SUFFIX_PARAM_NAME);
88 StringTokenizer tokenizer;
89
90 if (definedSuffixes == null)
91 {
92 definedSuffixes = JSP_SUFFIX_DEFAULT;
93 }
94
95
96
97 tokenizer = new StringTokenizer (definedSuffixes, " ");
98
99 while (tokenizer.hasMoreTokens())
100 {
101 result.add (tokenizer.nextToken());
102 }
103
104 return result;
105 }
106
107 @Override
108 public String getMinimalImplicitOutcome(String viewId)
109 {
110 for (String suffix : _suffixes)
111 {
112 if (viewId != null && viewId.endsWith(suffix))
113 {
114 return viewId.substring(0, viewId.length()-suffix.length());
115 }
116 }
117 return viewId;
118 }
119 }