commit | author | age
|
f13c4c
|
1 |
/*
|
JM |
2 |
* Copyright 2011 gitblit.com.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
5fe7df
|
16 |
package com.gitblit.wicket;
|
JM |
17 |
|
a7db57
|
18 |
import java.util.HashMap;
|
2b480a
|
19 |
import java.util.Locale;
|
a7db57
|
20 |
import java.util.Map;
|
2b480a
|
21 |
|
5fe7df
|
22 |
import org.apache.wicket.Application;
|
JM |
23 |
import org.apache.wicket.Page;
|
|
24 |
import org.apache.wicket.Request;
|
|
25 |
import org.apache.wicket.Response;
|
|
26 |
import org.apache.wicket.Session;
|
2a7306
|
27 |
import org.apache.wicket.markup.html.WebPage;
|
5fe7df
|
28 |
import org.apache.wicket.protocol.http.WebApplication;
|
JM |
29 |
|
fc948c
|
30 |
import com.gitblit.GitBlit;
|
155bf7
|
31 |
import com.gitblit.Keys;
|
2b480a
|
32 |
import com.gitblit.utils.StringUtils;
|
6e6f9f
|
33 |
import com.gitblit.wicket.pages.ActivityPage;
|
6ef8d7
|
34 |
import com.gitblit.wicket.pages.BasePage;
|
716745
|
35 |
import com.gitblit.wicket.pages.BlamePage;
|
608ece
|
36 |
import com.gitblit.wicket.pages.BlobDiffPage;
|
5fe7df
|
37 |
import com.gitblit.wicket.pages.BlobPage;
|
232890
|
38 |
import com.gitblit.wicket.pages.BranchesPage;
|
608ece
|
39 |
import com.gitblit.wicket.pages.CommitDiffPage;
|
94b96b
|
40 |
import com.gitblit.wicket.pages.CommitPage;
|
722e23
|
41 |
import com.gitblit.wicket.pages.ComparePage;
|
c1c3c6
|
42 |
import com.gitblit.wicket.pages.DocsPage;
|
831469
|
43 |
import com.gitblit.wicket.pages.FederationRegistrationPage;
|
1f52c8
|
44 |
import com.gitblit.wicket.pages.ForkPage;
|
1e1b85
|
45 |
import com.gitblit.wicket.pages.ForksPage;
|
4e1930
|
46 |
import com.gitblit.wicket.pages.GitSearchPage;
|
797322
|
47 |
import com.gitblit.wicket.pages.GravatarProfilePage;
|
f602a2
|
48 |
import com.gitblit.wicket.pages.HistoryPage;
|
698678
|
49 |
import com.gitblit.wicket.pages.LogPage;
|
a2ce62
|
50 |
import com.gitblit.wicket.pages.LogoutPage;
|
4e1930
|
51 |
import com.gitblit.wicket.pages.LuceneSearchPage;
|
531cd2
|
52 |
import com.gitblit.wicket.pages.MarkdownPage;
|
716745
|
53 |
import com.gitblit.wicket.pages.MetricsPage;
|
ff7d3c
|
54 |
import com.gitblit.wicket.pages.MyDashboardPage;
|
6ef8d7
|
55 |
import com.gitblit.wicket.pages.OverviewPage;
|
608ece
|
56 |
import com.gitblit.wicket.pages.PatchPage;
|
13a3f5
|
57 |
import com.gitblit.wicket.pages.ProjectPage;
|
JM |
58 |
import com.gitblit.wicket.pages.ProjectsPage;
|
608ece
|
59 |
import com.gitblit.wicket.pages.RawPage;
|
ff7d3c
|
60 |
import com.gitblit.wicket.pages.ReflogPage;
|
608ece
|
61 |
import com.gitblit.wicket.pages.RepositoriesPage;
|
a7571b
|
62 |
import com.gitblit.wicket.pages.ReviewProposalPage;
|
5fe7df
|
63 |
import com.gitblit.wicket.pages.SummaryPage;
|
JM |
64 |
import com.gitblit.wicket.pages.TagPage;
|
|
65 |
import com.gitblit.wicket.pages.TagsPage;
|
|
66 |
import com.gitblit.wicket.pages.TreePage;
|
1e1b85
|
67 |
import com.gitblit.wicket.pages.UserPage;
|
3868ed
|
68 |
import com.gitblit.wicket.pages.UsersPage;
|
5fe7df
|
69 |
|
JM |
70 |
public class GitBlitWebApp extends WebApplication {
|
|
71 |
|
ff7d3c
|
72 |
public final static Class<? extends BasePage> HOME_PAGE_CLASS = MyDashboardPage.class;
|
5dd805
|
73 |
|
a7db57
|
74 |
private final Map<String, CacheControl> cacheablePages = new HashMap<String, CacheControl>();
|
5dd805
|
75 |
|
5fe7df
|
76 |
@Override
|
JM |
77 |
public void init() {
|
|
78 |
super.init();
|
|
79 |
|
94b96b
|
80 |
// Setup page authorization mechanism
|
2a7306
|
81 |
boolean useAuthentication = GitBlit.getBoolean(Keys.web.authenticateViewPages, false)
|
JM |
82 |
|| GitBlit.getBoolean(Keys.web.authenticateAdminPages, false);
|
b55030
|
83 |
if (useAuthentication) {
|
94b96b
|
84 |
AuthorizationStrategy authStrategy = new AuthorizationStrategy();
|
JM |
85 |
getSecuritySettings().setAuthorizationStrategy(authStrategy);
|
|
86 |
getSecuritySettings().setUnauthorizedComponentInstantiationListener(authStrategy);
|
|
87 |
}
|
|
88 |
|
5fe7df
|
89 |
// Grab Browser info (like timezone, etc)
|
2a7306
|
90 |
if (GitBlit.getBoolean(Keys.web.useClientTimezone, false)) {
|
94b96b
|
91 |
getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
|
JM |
92 |
}
|
5fe7df
|
93 |
|
850794
|
94 |
// configure the resource cache duration to 90 days for deployment
|
JM |
95 |
if (!GitBlit.isDebugMode()) {
|
|
96 |
getResourceSettings().setDefaultCacheDuration(90 * 86400);
|
|
97 |
}
|
|
98 |
|
232890
|
99 |
// setup the standard gitweb-ish urls
|
cf17b2
|
100 |
mount("/repositories", RepositoriesPage.class);
|
6ef8d7
|
101 |
mount("/overview", OverviewPage.class, "r", "h");
|
2a7306
|
102 |
mount("/summary", SummaryPage.class, "r");
|
ff7d3c
|
103 |
mount("/reflog", ReflogPage.class, "r", "h");
|
6ef8d7
|
104 |
mount("/commits", LogPage.class, "r", "h");
|
2a7306
|
105 |
mount("/log", LogPage.class, "r", "h");
|
JM |
106 |
mount("/tags", TagsPage.class, "r");
|
|
107 |
mount("/branches", BranchesPage.class, "r");
|
|
108 |
mount("/commit", CommitPage.class, "r", "h");
|
|
109 |
mount("/tag", TagPage.class, "r", "h");
|
|
110 |
mount("/tree", TreePage.class, "r", "h", "f");
|
|
111 |
mount("/blob", BlobPage.class, "r", "h", "f");
|
|
112 |
mount("/raw", RawPage.class, "r", "h", "f");
|
|
113 |
mount("/blobdiff", BlobDiffPage.class, "r", "h", "f");
|
|
114 |
mount("/commitdiff", CommitDiffPage.class, "r", "h");
|
722e23
|
115 |
mount("/compare", ComparePage.class, "r", "h");
|
2a7306
|
116 |
mount("/patch", PatchPage.class, "r", "h", "f");
|
JM |
117 |
mount("/history", HistoryPage.class, "r", "h", "f");
|
4e1930
|
118 |
mount("/search", GitSearchPage.class);
|
424fe1
|
119 |
mount("/metrics", MetricsPage.class, "r");
|
716745
|
120 |
mount("/blame", BlamePage.class, "r", "h", "f");
|
3868ed
|
121 |
mount("/users", UsersPage.class);
|
a2ce62
|
122 |
mount("/logout", LogoutPage.class);
|
008322
|
123 |
|
531cd2
|
124 |
// setup the markdown urls
|
2a7306
|
125 |
mount("/docs", DocsPage.class, "r");
|
JM |
126 |
mount("/markdown", MarkdownPage.class, "r", "h", "f");
|
|
127 |
|
831469
|
128 |
// federation urls
|
dd9ae7
|
129 |
mount("/proposal", ReviewProposalPage.class, "t");
|
831469
|
130 |
mount("/registration", FederationRegistrationPage.class, "u", "n");
|
797322
|
131 |
|
6e6f9f
|
132 |
mount("/activity", ActivityPage.class, "r", "h");
|
797322
|
133 |
mount("/gravatar", GravatarProfilePage.class, "h");
|
4e1930
|
134 |
mount("/lucene", LuceneSearchPage.class);
|
13a3f5
|
135 |
mount("/project", ProjectPage.class, "p");
|
JM |
136 |
mount("/projects", ProjectsPage.class);
|
1e1b85
|
137 |
mount("/user", UserPage.class, "user");
|
JM |
138 |
mount("/forks", ForksPage.class, "r");
|
1f52c8
|
139 |
mount("/fork", ForkPage.class, "r");
|
2a7306
|
140 |
}
|
JM |
141 |
|
|
142 |
private void mount(String location, Class<? extends WebPage> clazz, String... parameters) {
|
|
143 |
if (parameters == null) {
|
|
144 |
parameters = new String[] {};
|
|
145 |
}
|
b01ca0
|
146 |
if (!GitBlit.getBoolean(Keys.web.mountParameters, true)) {
|
JM |
147 |
parameters = new String[] {};
|
|
148 |
}
|
7e5ee5
|
149 |
mount(new GitblitParamUrlCodingStrategy(location, clazz, parameters));
|
5dd805
|
150 |
|
JM |
151 |
// map the mount point to the cache control definition
|
a7db57
|
152 |
if (clazz.isAnnotationPresent(CacheControl.class)) {
|
JM |
153 |
CacheControl cacheControl = clazz.getAnnotation(CacheControl.class);
|
|
154 |
cacheablePages.put(location.substring(1), cacheControl);
|
|
155 |
}
|
5fe7df
|
156 |
}
|
JM |
157 |
|
|
158 |
@Override
|
|
159 |
public Class<? extends Page> getHomePage() {
|
6ef8d7
|
160 |
return HOME_PAGE_CLASS;
|
5fe7df
|
161 |
}
|
5dd805
|
162 |
|
a7db57
|
163 |
public boolean isCacheablePage(String mountPoint) {
|
JM |
164 |
return cacheablePages.containsKey(mountPoint);
|
|
165 |
}
|
|
166 |
|
|
167 |
public CacheControl getCacheControl(String mountPoint) {
|
|
168 |
return cacheablePages.get(mountPoint);
|
|
169 |
}
|
|
170 |
|
5fe7df
|
171 |
@Override
|
JM |
172 |
public final Session newSession(Request request, Response response) {
|
2b480a
|
173 |
GitBlitWebSession gitBlitWebSession = new GitBlitWebSession(request);
|
LJ |
174 |
|
|
175 |
String forcedLocale = GitBlit.getString(Keys.web.forceDefaultLocale, null);
|
|
176 |
if (!StringUtils.isEmpty(forcedLocale)) {
|
|
177 |
gitBlitWebSession.setLocale(new Locale(forcedLocale));
|
|
178 |
}
|
|
179 |
return gitBlitWebSession;
|
5fe7df
|
180 |
}
|
JM |
181 |
|
|
182 |
@Override
|
|
183 |
public final String getConfigurationType() {
|
8c9a20
|
184 |
if (GitBlit.isDebugMode()) {
|
5fe7df
|
185 |
return Application.DEVELOPMENT;
|
2a7306
|
186 |
}
|
5fe7df
|
187 |
return Application.DEPLOYMENT;
|
JM |
188 |
}
|
|
189 |
|
|
190 |
public static GitBlitWebApp get() {
|
|
191 |
return (GitBlitWebApp) WebApplication.get();
|
|
192 |
}
|
|
193 |
}
|