1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.extensions.surf.mvc;
20
21 import java.util.Locale;
22
23 import org.springframework.extensions.surf.FrameworkUtil;
24 import org.springframework.extensions.surf.RequestContext;
25 import org.springframework.extensions.surf.WebFrameworkConstants;
26 import org.springframework.extensions.surf.types.Page;
27 import org.springframework.extensions.surf.types.PageType;
28 import org.springframework.extensions.surf.types.Theme;
29 import org.springframework.web.servlet.view.AbstractUrlBasedView;
30
31
32
33
34
35
36 public class PageTypeViewResolver extends AbstractWebFrameworkViewResolver
37 {
38 private static final String URI_PREFIX_PAGE_TYPE = "type/";
39
40 public PageTypeViewResolver()
41 {
42 super();
43 }
44
45
46
47
48 protected boolean canHandle(String viewName, Locale locale)
49 {
50 boolean canHandle = false;
51
52 if (!canHandle && viewName.startsWith(URI_PREFIX_PAGE_TYPE))
53 {
54 String pageTypeId = viewName.substring(URI_PREFIX_PAGE_TYPE.length());
55
56
57 PageType pageType = FrameworkUtil.getCurrentRequestContext().getModel().getPageType(pageTypeId);
58 canHandle = (pageType != null);
59 }
60
61 return canHandle;
62 }
63
64
65
66
67
68 protected AbstractUrlBasedView buildView(String viewName) throws Exception
69 {
70 AbstractUrlBasedView view = null;
71
72
73 RequestContext context = FrameworkUtil.getCurrentRequestContext();
74
75 if (viewName.startsWith(URI_PREFIX_PAGE_TYPE))
76 {
77 String pageTypeId = viewName.substring(URI_PREFIX_PAGE_TYPE.length());
78
79
80 PageType pageType = FrameworkUtil.getCurrentRequestContext().getModel().getPageType(pageTypeId);
81
82
83 String pageId = null;
84
85
86 String themeId = (String) context.getThemeId();
87 Theme theme = context.getModel().getTheme(themeId);
88 if (theme != null)
89 {
90 pageId = theme.getPageId(pageTypeId);
91 }
92
93
94 if (pageId == null)
95 {
96 pageId = FrameworkUtil.getWebFrameworkConfiguration().getDefaultPageTypeInstanceId(pageTypeId);
97 }
98
99
100 if (pageId == null)
101 {
102 pageId = FrameworkUtil.getWebFrameworkConfiguration().getDefaultPageTypeInstanceId(WebFrameworkConstants.GENERIC_PAGE_TYPE_DEFAULT_PAGE_ID);
103 }
104
105
106 Page page = FrameworkUtil.getCurrentRequestContext().getModel().getPage(pageId);
107 if (page != null)
108 {
109 view = new PageView(getServiceRegistry());
110 view.setUrl(pageId);
111 }
112 }
113
114 return view;
115 }
116 }