1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
|
/*
* Copyright 2011 gitblit.com.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitblit.wicket.pages;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.wicket.Component;
import org.apache.wicket.PageParameters;
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.target.basic.RedirectRequestTarget;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.gitblit.Constants;
import com.gitblit.GitBlit;
import com.gitblit.GitBlitException;
import com.gitblit.Keys;
import com.gitblit.PagesServlet;
import com.gitblit.SyndicationServlet;
import com.gitblit.models.ProjectModel;
import com.gitblit.models.RefModel;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.SubmoduleModel;
import com.gitblit.models.UserModel;
import com.gitblit.models.UserRepositoryPreferences;
import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.DeepCopier;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.RefLogUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.PageRegistration;
import com.gitblit.wicket.PageRegistration.OtherPageLink;
import com.gitblit.wicket.SessionlessForm;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.NavigationPanel;
import com.gitblit.wicket.panels.RefsPanel;
public abstract class RepositoryPage extends RootPage {
protected final Logger logger = LoggerFactory.getLogger(getClass());
private final String PARAM_STAR = "star";
protected final String projectName;
protected final String repositoryName;
protected final String objectId;
private transient Repository r;
private RepositoryModel m;
private Map<String, SubmoduleModel> submodules;
private final Map<String, PageRegistration> registeredPages;
private boolean showAdmin;
private boolean isOwner;
public RepositoryPage(PageParameters params) {
super(params);
repositoryName = WicketUtils.getRepositoryName(params);
String root =StringUtils.getFirstPathElement(repositoryName);
if (StringUtils.isEmpty(root)) {
projectName = GitBlit.getString(Keys.web.repositoryRootGroupName, "main");
} else {
projectName = root;
}
objectId = WicketUtils.getObject(params);
if (StringUtils.isEmpty(repositoryName)) {
error(MessageFormat.format(getString("gb.repositoryNotSpecifiedFor"), getPageName()), true);
}
if (!getRepositoryModel().hasCommits) {
setResponsePage(EmptyRepositoryPage.class, params);
}
if (getRepositoryModel().isCollectingGarbage) {
error(MessageFormat.format(getString("gb.busyCollectingGarbage"), getRepositoryModel().name), true);
}
if (objectId != null) {
RefModel branch = null;
if ((branch = JGitUtils.getBranch(getRepository(), objectId)) != null) {
UserModel user = GitBlitWebSession.get().getUser();
if (user == null) {
// workaround until get().getUser() is reviewed throughout the app
user = UserModel.ANONYMOUS;
}
boolean canAccess = user.canView(getRepositoryModel(),
branch.reference.getName());
if (!canAccess) {
error(getString("gb.accessDenied"), true);
}
}
}
if (params.containsKey(PARAM_STAR)) {
// set starred state
boolean star = params.getBoolean(PARAM_STAR);
UserModel user = GitBlitWebSession.get().getUser();
if (user != null && user.isAuthenticated) {
UserRepositoryPreferences prefs = user.getPreferences().getRepositoryPreferences(getRepositoryModel().name);
prefs.starred = star;
try {
GitBlit.self().updateUserModel(user.username, user, false);
} catch (GitBlitException e) {
logger.error("Failed to update user " + user.username, e);
error(getString("gb.failedToUpdateUser"), false);
}
}
}
// register the available page links for this page and user
registeredPages = registerPages();
// standard page links
List<PageRegistration> pages = new ArrayList<PageRegistration>(registeredPages.values());
NavigationPanel navigationPanel = new NavigationPanel("repositoryNavPanel", getRepoNavPageClass(), pages);
add(navigationPanel);
add(new ExternalLink("syndication", SyndicationServlet.asLink(getRequest()
.getRelativePathPrefixToContextRoot(), repositoryName, null, 0)));
// add floating search form
SearchForm searchForm = new SearchForm("searchForm", repositoryName);
add(searchForm);
searchForm.setTranslatedAttributes();
// set stateless page preference
setStatelessHint(true);
}
@Override
protected Class<? extends BasePage> getRootNavPageClass() {
return RepositoriesPage.class;
}
protected Class<? extends BasePage> getRepoNavPageClass() {
return getClass();
}
private Map<String, PageRegistration> registerPages() {
PageParameters params = null;
if (!StringUtils.isEmpty(repositoryName)) {
params = WicketUtils.newRepositoryParameter(repositoryName);
}
Map<String, PageRegistration> pages = new LinkedHashMap<String, PageRegistration>();
Repository r = getRepository();
RepositoryModel model = getRepositoryModel();
// standard links
if (RefLogUtils.getRefLogBranch(r) == null) {
pages.put("summary", new PageRegistration("gb.summary", SummaryPage.class, params));
} else {
pages.put("summary", new PageRegistration("gb.summary", SummaryPage.class, params));
// pages.put("overview", new PageRegistration("gb.overview", OverviewPage.class, params));
pages.put("reflog", new PageRegistration("gb.reflog", ReflogPage.class, params));
}
pages.put("commits", new PageRegistration("gb.commits", LogPage.class, params));
pages.put("tree", new PageRegistration("gb.tree", TreePage.class, params));
pages.put("docs", new PageRegistration("gb.docs", DocsPage.class, params, true));
pages.put("compare", new PageRegistration("gb.compare", ComparePage.class, params, true));
if (GitBlit.getBoolean(Keys.web.allowForking, true)) {
pages.put("forks", new PageRegistration("gb.forks", ForksPage.class, params, true));
}
// conditional links
// per-repository extra page links
if (JGitUtils.getPagesBranch(r) != null) {
OtherPageLink pagesLink = new OtherPageLink("gb.pages", PagesServlet.asLink(
getRequest().getRelativePathPrefixToContextRoot(), repositoryName, null), true);
pages.put("pages", pagesLink);
}
// Conditionally add edit link
showAdmin = false;
if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {
boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();
} else {
showAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
}
isOwner = GitBlitWebSession.get().isLoggedIn()
&& (model.isOwner(GitBlitWebSession.get()
.getUsername()));
return pages;
}
protected boolean allowForkControls() {
return GitBlit.getBoolean(Keys.web.allowForking, true);
}
@Override
protected void setupPage(String repositoryName, String pageName) {
String projectName = StringUtils.getFirstPathElement(repositoryName);
ProjectModel project = GitBlit.self().getProjectModel(projectName);
if (project.isUserProject()) {
// user-as-project
add(new LinkPanel("projectTitle", null, project.getDisplayName(),
UserPage.class, WicketUtils.newUsernameParameter(project.name.substring(1))));
} else {
// project
add(new LinkPanel("projectTitle", null, project.name,
ProjectPage.class, WicketUtils.newProjectParameter(project.name)));
}
String name = StringUtils.stripDotGit(repositoryName);
if (!StringUtils.isEmpty(projectName) && name.startsWith(projectName)) {
name = name.substring(projectName.length() + 1);
}
add(new LinkPanel("repositoryName", null, name, SummaryPage.class,
WicketUtils.newRepositoryParameter(repositoryName)));
add(new Label("pageName", pageName).setRenderBodyOnly(true));
UserModel user = GitBlitWebSession.get().getUser();
if (user == null) {
user = UserModel.ANONYMOUS;
}
// indicate origin repository
RepositoryModel model = getRepositoryModel();
if (StringUtils.isEmpty(model.originRepository)) {
if (model.isMirror) {
Fragment mirrorFrag = new Fragment("originRepository", "mirrorFragment", this);
Label lbl = new Label("originRepository", MessageFormat.format(getString("gb.mirrorOf"), "<b>" + model.origin + "</b>"));
mirrorFrag.add(lbl.setEscapeModelStrings(false));
add(mirrorFrag);
} else {
add(new Label("originRepository").setVisible(false));
}
} else {
RepositoryModel origin = GitBlit.self().getRepositoryModel(model.originRepository);
if (origin == null) {
// no origin repository
add(new Label("originRepository").setVisible(false));
} else if (!user.canView(origin)) {
// show origin repository without link
Fragment forkFrag = new Fragment("originRepository", "originFragment", this);
forkFrag.add(new Label("originRepository", StringUtils.stripDotGit(model.originRepository)));
add(forkFrag);
} else {
// link to origin repository
Fragment forkFrag = new Fragment("originRepository", "originFragment", this);
forkFrag.add(new LinkPanel("originRepository", null, StringUtils.stripDotGit(model.originRepository),
SummaryPage.class, WicketUtils.newRepositoryParameter(model.originRepository)));
add(forkFrag);
}
}
// (un)star link allows a user to star a repository
if (user.isAuthenticated) {
PageParameters starParams = DeepCopier.copy(getPageParameters());
starParams.put(PARAM_STAR, !user.getPreferences().isStarredRepository(model.name));
String toggleStarUrl = getRequestCycle().urlFor(getClass(), starParams).toString();
if (user.getPreferences().isStarredRepository(model.name)) {
// show unstar button
add(new Label("starLink").setVisible(false));
addToolbarButton("unstarLink", "icon-star-empty", getString("gb.unstar"), toggleStarUrl);
} else {
// show star button
addToolbarButton("starLink", "icon-star", getString("gb.star"), toggleStarUrl);
add(new Label("unstarLink").setVisible(false));
}
} else {
// anonymous user
add(new Label("starLink").setVisible(false));
add(new Label("unstarLink").setVisible(false));
}
// fork controls
if (!allowForkControls() || user == null || !user.isAuthenticated) {
// must be logged-in to fork, hide all fork controls
add(new ExternalLink("forkLink", "").setVisible(false));
add(new ExternalLink("myForkLink", "").setVisible(false));
} else {
String fork = GitBlit.self().getFork(user.username, model.name);
boolean hasFork = fork != null;
boolean canFork = user.canFork(model);
if (hasFork || !canFork) {
// user not allowed to fork or fork already exists or repo forbids forking
add(new ExternalLink("forkLink", "").setVisible(false));
if (hasFork && !fork.equals(model.name)) {
// user has fork, view my fork link
String url = getRequestCycle().urlFor(SummaryPage.class, WicketUtils.newRepositoryParameter(fork)).toString();
add(new ExternalLink("myForkLink", url));
} else {
// no fork, hide view my fork link
add(new ExternalLink("myForkLink", "").setVisible(false));
}
} else if (canFork) {
// can fork and we do not have one
add(new ExternalLink("myForkLink", "").setVisible(false));
String url = getRequestCycle().urlFor(ForkPage.class, WicketUtils.newRepositoryParameter(model.name)).toString();
add(new ExternalLink("forkLink", url));
}
}
if (showAdmin || isOwner) {
String url = getRequestCycle().urlFor(EditRepositoryPage.class, WicketUtils.newRepositoryParameter(model.name)).toString();
add(new ExternalLink("editLink", url));
} else {
add(new Label("editLink").setVisible(false));
}
super.setupPage(repositoryName, pageName);
}
protected void addToolbarButton(String wicketId, String iconClass, String label, String url) {
Fragment button = new Fragment(wicketId, "toolbarLinkFragment", this);
Label icon = new Label("icon");
WicketUtils.setCssClass(icon, iconClass);
button.add(icon);
button.add(new Label("label", label));
button.add(new SimpleAttributeModifier("href", url));
add(button);
}
protected void addSyndicationDiscoveryLink() {
add(WicketUtils.syndicationDiscoveryLink(SyndicationServlet.getTitle(repositoryName,
objectId), SyndicationServlet.asLink(getRequest()
.getRelativePathPrefixToContextRoot(), repositoryName, objectId, 0)));
}
protected Repository getRepository() {
if (r == null) {
Repository r = GitBlit.self().getRepository(repositoryName);
if (r == null) {
error(getString("gb.canNotLoadRepository") + " " + repositoryName, true);
return null;
}
this.r = r;
}
return r;
}
protected RepositoryModel getRepositoryModel() {
if (m == null) {
RepositoryModel model = GitBlit.self().getRepositoryModel(
GitBlitWebSession.get().getUser(), repositoryName);
if (model == null) {
if (GitBlit.self().hasRepository(repositoryName, true)) {
// has repository, but unauthorized
authenticationError(getString("gb.unauthorizedAccessForRepository") + " " + repositoryName);
} else {
// does not have repository
error(getString("gb.canNotLoadRepository") + " " + repositoryName, true);
}
return null;
}
m = model;
}
return m;
}
protected RevCommit getCommit() {
RevCommit commit = JGitUtils.getCommit(r, objectId);
if (commit == null) {
error(MessageFormat.format(getString("gb.failedToFindCommit"),
objectId, repositoryName, getPageName()), null, LogPage.class,
WicketUtils.newRepositoryParameter(repositoryName));
}
getSubmodules(commit);
return commit;
}
protected String getBestCommitId(RevCommit commit) {
String head = null;
try {
head = r.resolve(getRepositoryModel().HEAD).getName();
} catch (Exception e) {
}
String id = commit.getName();
if (!StringUtils.isEmpty(head) && head.equals(id)) {
// match default branch
return Repository.shortenRefName(getRepositoryModel().HEAD);
}
// find first branch match
for (RefModel ref : JGitUtils.getLocalBranches(r, false, -1)) {
if (ref.getObjectId().getName().equals(id)) {
return ref.getName();
}
}
// return sha
return id;
}
protected Map<String, SubmoduleModel> getSubmodules(RevCommit commit) {
if (submodules == null) {
submodules = new HashMap<String, SubmoduleModel>();
for (SubmoduleModel model : JGitUtils.getSubmodules(r, commit.getTree())) {
submodules.put(model.path, model);
}
}
return submodules;
}
protected SubmoduleModel getSubmodule(String path) {
SubmoduleModel model = null;
if (submodules != null) {
model = submodules.get(path);
}
if (model == null) {
// undefined submodule?!
model = new SubmoduleModel(path.substring(path.lastIndexOf('/') + 1), path, path);
model.hasSubmodule = false;
model.gitblitPath = model.name;
return model;
} else {
// extract the repository name from the clone url
List<String> patterns = GitBlit.getStrings(Keys.git.submoduleUrlPatterns);
String submoduleName = StringUtils.extractRepositoryPath(model.url, patterns.toArray(new String[0]));
// determine the current path for constructing paths relative
// to the current repository
String currentPath = "";
if (repositoryName.indexOf('/') > -1) {
currentPath = repositoryName.substring(0, repositoryName.lastIndexOf('/') + 1);
}
// try to locate the submodule repository
// prefer bare to non-bare names
List<String> candidates = new ArrayList<String>();
// relative
candidates.add(currentPath + StringUtils.stripDotGit(submoduleName));
candidates.add(candidates.get(candidates.size() - 1) + ".git");
// relative, no subfolder
if (submoduleName.lastIndexOf('/') > -1) {
String name = submoduleName.substring(submoduleName.lastIndexOf('/') + 1);
candidates.add(currentPath + StringUtils.stripDotGit(name));
candidates.add(candidates.get(candidates.size() - 1) + ".git");
}
// absolute
candidates.add(StringUtils.stripDotGit(submoduleName));
candidates.add(candidates.get(candidates.size() - 1) + ".git");
// absolute, no subfolder
if (submoduleName.lastIndexOf('/') > -1) {
String name = submoduleName.substring(submoduleName.lastIndexOf('/') + 1);
candidates.add(StringUtils.stripDotGit(name));
candidates.add(candidates.get(candidates.size() - 1) + ".git");
}
// create a unique, ordered set of candidate paths
Set<String> paths = new LinkedHashSet<String>(candidates);
for (String candidate : paths) {
if (GitBlit.self().hasRepository(candidate)) {
model.hasSubmodule = true;
model.gitblitPath = candidate;
return model;
}
}
// we do not have a copy of the submodule, but we need a path
model.gitblitPath = candidates.get(0);
return model;
}
}
protected String getShortObjectId(String objectId) {
return objectId.substring(0, GitBlit.getInteger(Keys.web.shortCommitIdLength, 6));
}
protected void addRefs(Repository r, RevCommit c) {
add(new RefsPanel("refsPanel", repositoryName, c, JGitUtils.getAllRefs(r, getRepositoryModel().showRemoteBranches)));
}
protected void addFullText(String wicketId, String text) {
RepositoryModel model = getRepositoryModel();
String content = GitBlit.self().processCommitMessage(model, text);
String html;
switch (model.commitMessageRenderer) {
case MARKDOWN:
html = MessageFormat.format("<div class='commit_message'>{0}</div>", content);
break;
default:
html = MessageFormat.format("<pre class='commit_message'>{0}</pre>", content);
break;
}
add(new Label(wicketId, html).setEscapeModelStrings(false));
}
protected abstract String getPageName();
protected Component createPersonPanel(String wicketId, PersonIdent identity,
Constants.SearchType searchType) {
String name = identity == null ? "" : identity.getName();
String address = identity == null ? "" : identity.getEmailAddress();
name = StringUtils.removeNewlines(name);
address = StringUtils.removeNewlines(address);
boolean showEmail = GitBlit.getBoolean(Keys.web.showEmailAddresses, false);
if (!showEmail || StringUtils.isEmpty(name) || StringUtils.isEmpty(address)) {
String value = name;
if (StringUtils.isEmpty(value)) {
if (showEmail) {
value = address;
} else {
value = getString("gb.missingUsername");
}
}
Fragment partial = new Fragment(wicketId, "partialPersonIdent", this);
LinkPanel link = new LinkPanel("personName", "list", value, GitSearchPage.class,
WicketUtils.newSearchParameter(repositoryName, objectId, value, searchType));
setPersonSearchTooltip(link, value, searchType);
partial.add(link);
return partial;
} else {
Fragment fullPerson = new Fragment(wicketId, "fullPersonIdent", this);
LinkPanel nameLink = new LinkPanel("personName", "list", name, GitSearchPage.class,
WicketUtils.newSearchParameter(repositoryName, objectId, name, searchType));
setPersonSearchTooltip(nameLink, name, searchType);
fullPerson.add(nameLink);
LinkPanel addressLink = new LinkPanel("personAddress", "hidden-phone list", "<" + address + ">",
GitSearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId,
address, searchType));
setPersonSearchTooltip(addressLink, address, searchType);
fullPerson.add(addressLink);
return fullPerson;
}
}
protected void setPersonSearchTooltip(Component component, String value,
Constants.SearchType searchType) {
if (searchType.equals(Constants.SearchType.AUTHOR)) {
WicketUtils.setHtmlTooltip(component, getString("gb.searchForAuthor") + " " + value);
} else if (searchType.equals(Constants.SearchType.COMMITTER)) {
WicketUtils.setHtmlTooltip(component, getString("gb.searchForCommitter") + " " + value);
}
}
protected void setChangeTypeTooltip(Component container, ChangeType type) {
switch (type) {
case ADD:
WicketUtils.setHtmlTooltip(container, getString("gb.addition"));
break;
case COPY:
case RENAME:
WicketUtils.setHtmlTooltip(container, getString("gb.rename"));
break;
case DELETE:
WicketUtils.setHtmlTooltip(container, getString("gb.deletion"));
break;
case MODIFY:
WicketUtils.setHtmlTooltip(container, getString("gb.modification"));
break;
}
}
@Override
protected void onBeforeRender() {
// dispose of repository object
if (r != null) {
r.close();
r = null;
}
// setup page header and footer
setupPage(repositoryName, "/ " + getPageName());
super.onBeforeRender();
}
@Override
protected void setLastModified() {
if (getClass().isAnnotationPresent(CacheControl.class)) {
CacheControl cacheControl = getClass().getAnnotation(CacheControl.class);
switch (cacheControl.value()) {
case REPOSITORY:
RepositoryModel repository = getRepositoryModel();
if (repository != null) {
setLastModified(repository.lastChange);
}
break;
case COMMIT:
RevCommit commit = getCommit();
if (commit != null) {
Date commitDate = JGitUtils.getCommitDate(commit);
setLastModified(commitDate);
}
break;
default:
super.setLastModified();
}
}
}
protected PageParameters newRepositoryParameter() {
return WicketUtils.newRepositoryParameter(repositoryName);
}
protected PageParameters newCommitParameter() {
return WicketUtils.newObjectParameter(repositoryName, objectId);
}
protected PageParameters newCommitParameter(String commitId) {
return WicketUtils.newObjectParameter(repositoryName, commitId);
}
public boolean isShowAdmin() {
return showAdmin;
}
public boolean isOwner() {
return isOwner;
}
private class SearchForm extends SessionlessForm<Void> implements Serializable {
private static final long serialVersionUID = 1L;
private final String repositoryName;
private final IModel<String> searchBoxModel = new Model<String>("");
private final IModel<Constants.SearchType> searchTypeModel = new Model<Constants.SearchType>(
Constants.SearchType.COMMIT);
public SearchForm(String id, String repositoryName) {
super(id, RepositoryPage.this.getClass(), RepositoryPage.this.getPageParameters());
this.repositoryName = repositoryName;
DropDownChoice<Constants.SearchType> searchType = new DropDownChoice<Constants.SearchType>(
"searchType", Arrays.asList(Constants.SearchType.values()));
searchType.setModel(searchTypeModel);
add(searchType.setVisible(GitBlit.getBoolean(Keys.web.showSearchTypeSelection, false)));
TextField<String> searchBox = new TextField<String>("searchBox", searchBoxModel);
add(searchBox);
}
void setTranslatedAttributes() {
WicketUtils.setHtmlTooltip(get("searchType"), getString("gb.searchTypeTooltip"));
WicketUtils.setHtmlTooltip(get("searchBox"),
MessageFormat.format(getString("gb.searchTooltip"), repositoryName));
WicketUtils.setInputPlaceholder(get("searchBox"), getString("gb.search"));
}
@Override
public void onSubmit() {
Constants.SearchType searchType = searchTypeModel.getObject();
String searchString = searchBoxModel.getObject();
if (StringUtils.isEmpty(searchString)) {
// redirect to self to avoid wicket page update bug
String absoluteUrl = getCanonicalUrl();
getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
return;
}
for (Constants.SearchType type : Constants.SearchType.values()) {
if (searchString.toLowerCase().startsWith(type.name().toLowerCase() + ":")) {
searchType = type;
searchString = searchString.substring(type.name().toLowerCase().length() + 1)
.trim();
break;
}
}
Class<? extends BasePage> searchPageClass = GitSearchPage.class;
RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
if (GitBlit.getBoolean(Keys.web.allowLuceneIndexing, true)
&& !ArrayUtils.isEmpty(model.indexedBranches)) {
// this repository is Lucene-indexed
searchPageClass = LuceneSearchPage.class;
}
// use an absolute url to workaround Wicket-Tomcat problems with
// mounted url parameters (issue-111)
PageParameters params = WicketUtils.newSearchParameter(repositoryName, null, searchString, searchType);
String absoluteUrl = getCanonicalUrl(searchPageClass, params);
getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
}
}
}
|