%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.profiler.impl.CreateUserTemplatePagesValveImpl |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.jetspeed.profiler.impl; |
|
18 | ||
19 | import org.apache.jetspeed.om.folder.Folder; |
|
20 | import org.apache.jetspeed.om.folder.FolderNotFoundException; |
|
21 | import org.apache.jetspeed.page.PageManager; |
|
22 | import org.apache.jetspeed.pipeline.PipelineException; |
|
23 | import org.apache.jetspeed.pipeline.valve.ValveContext; |
|
24 | import org.apache.jetspeed.portalsite.PortalSite; |
|
25 | import org.apache.jetspeed.profiler.Profiler; |
|
26 | import org.apache.jetspeed.profiler.impl.ProfilerValveImpl; |
|
27 | import org.apache.jetspeed.request.RequestContext; |
|
28 | ||
29 | import org.apache.commons.logging.Log; |
|
30 | import org.apache.commons.logging.LogFactory; |
|
31 | ||
32 | /** |
|
33 | * CreateUserTemplatePagesValveImpl |
|
34 | * |
|
35 | * Create User Pages from template folder on first login feature |
|
36 | * The CreateUserTemplatePagesValveImpl creates a new user's home page from the user template folder. |
|
37 | * |
|
38 | * @author Woonsan Ko |
|
39 | * @version $Id: CreateUserTemplatePagesValveImpl.java 555324 2007-07-11 16:23:56Z ate $ |
|
40 | */ |
|
41 | public class CreateUserTemplatePagesValveImpl extends ProfilerValveImpl |
|
42 | { |
|
43 | 0 | private static final Log log = LogFactory.getLog(CreateUserTemplatePagesValveImpl.class); |
44 | ||
45 | public static final String USER_TEMPLATE_FOLDER_REQUEST_ATTR_KEY = "org.apache.jetspeed.profiler.UserTemplateFolder"; |
|
46 | ||
47 | protected PageManager pageManager; |
|
48 | 0 | protected String defaultTemplateFolder = "/_user/template/"; |
49 | ||
50 | /** |
|
51 | * CreateUserTemplatePagesValveImpl - constructor |
|
52 | * |
|
53 | * @param profiler profiler component reference |
|
54 | * @param portalSite portal site component reference |
|
55 | * @param requestFallback flag to enable root folder fallback |
|
56 | * @param useHistory flag to enable selection of last visited folder page |
|
57 | * @param pageManager pageManagerComponent reference |
|
58 | */ |
|
59 | public CreateUserTemplatePagesValveImpl(Profiler profiler, PortalSite portalSite, boolean requestFallback, class="keyword">boolean useHistoryPageManager, PageManager pageManager) |
|
60 | { |
|
61 | 0 | super(profiler, portalSite, requestFallback, useHistoryPageManager); |
62 | 0 | this.pageManager = pageManager; |
63 | 0 | } |
64 | ||
65 | /** |
|
66 | * CreateUserTemplatePagesValveImpl - constructor |
|
67 | * |
|
68 | * @param profiler profiler component reference |
|
69 | * @param portalSite portal site component reference |
|
70 | * @param requestFallback flag to enable root folder fallback |
|
71 | * @param pageManager pageManagerComponent reference |
|
72 | */ |
|
73 | public CreateUserTemplatePagesValveImpl(Profiler profiler, PortalSite portalSite, |
|
74 | boolean requestFallback, PageManager pageManager) |
|
75 | { |
|
76 | 0 | super(profiler, portalSite, requestFallback); |
77 | 0 | this.pageManager = pageManager; |
78 | 0 | } |
79 | ||
80 | /** |
|
81 | * CreateUserTemplatePagesValveImpl - constructor |
|
82 | * |
|
83 | * @param profiler profiler component reference |
|
84 | * @param portalSite portal site component reference |
|
85 | * @param pageManager pageManagerComponent reference |
|
86 | */ |
|
87 | public CreateUserTemplatePagesValveImpl(Profiler profiler, PortalSite portalSite, PageManager pageManager) |
|
88 | { |
|
89 | 0 | super(profiler, portalSite); |
90 | 0 | this.pageManager = pageManager; |
91 | 0 | } |
92 | ||
93 | public void setDefaultTemplateFolder(String defaultTemplateFolder) |
|
94 | { |
|
95 | 0 | this.defaultTemplateFolder = defaultTemplateFolder; |
96 | 0 | } |
97 | ||
98 | /** |
|
99 | * @see org.apache.jetspeed.pipeline.valve.Valve#invoke(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.pipeline.valve.ValveContext) |
|
100 | */ |
|
101 | public void invoke(RequestContext request, ValveContext context) throws PipelineException |
|
102 | { |
|
103 | 0 | boolean created = false; |
104 | ||
105 | try |
|
106 | { |
|
107 | 0 | created = createUserFolderPages(request); |
108 | } |
|
109 | 0 | catch (Exception e) |
110 | { |
|
111 | 0 | log.error("Exception occurred during creating user folder.", e); |
112 | } |
|
113 | finally |
|
114 | { |
|
115 | 0 | if (created) |
116 | { |
|
117 | 0 | super.invoke(request, context); |
118 | } |
|
119 | else |
|
120 | { |
|
121 | 0 | context.invokeNext(request); |
122 | } |
|
123 | 0 | } |
124 | 0 | } |
125 | ||
126 | private boolean createUserFolderPages(RequestContext request) throws Exception |
|
127 | { |
|
128 | 0 | boolean created = false; |
129 | ||
130 | 0 | String userName = request.getUserPrincipal().getName(); |
131 | 0 | String userFolder = Folder.USER_FOLDER + userName; |
132 | ||
133 | 0 | boolean found = true; |
134 | ||
135 | try |
|
136 | { |
|
137 | 0 | this.pageManager.getFolder(userFolder); |
138 | } |
|
139 | 0 | catch (FolderNotFoundException e) |
140 | { |
|
141 | 0 | found = false; |
142 | 0 | } |
143 | ||
144 | 0 | if (!found) |
145 | { |
|
146 | try |
|
147 | { |
|
148 | 0 | String templateFolder = (String) request.getAttribute(USER_TEMPLATE_FOLDER_REQUEST_ATTR_KEY); |
149 | ||
150 | 0 | if (templateFolder == null) |
151 | { |
|
152 | 0 | templateFolder = this.defaultTemplateFolder; |
153 | } |
|
154 | ||
155 | 0 | Folder source = this.pageManager.getFolder(templateFolder); |
156 | ||
157 | // copy the entire dir tree from the template folder |
|
158 | 0 | this.pageManager.deepCopyFolder(source, userFolder, userName); |
159 | 0 | created = true; |
160 | } |
|
161 | 0 | catch (Exception e) |
162 | { |
|
163 | 0 | throw e; |
164 | 0 | } |
165 | } |
|
166 | ||
167 | 0 | return created; |
168 | } |
|
169 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |