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.pages;
|
JM |
17 |
|
c3f4f1
|
18 |
import java.io.File;
|
JM |
19 |
import java.io.FileReader;
|
|
20 |
import java.io.InputStream;
|
|
21 |
import java.io.InputStreamReader;
|
8c5d72
|
22 |
import java.text.MessageFormat;
|
cb57ec
|
23 |
import java.util.List;
|
5fe7df
|
24 |
|
31bcbe
|
25 |
import org.apache.wicket.Application;
|
c3f4f1
|
26 |
import org.apache.wicket.Component;
|
cb57ec
|
27 |
import org.apache.wicket.PageParameters;
|
5fe7df
|
28 |
import org.apache.wicket.markup.html.basic.Label;
|
c3f4f1
|
29 |
import org.apache.wicket.resource.ContextRelativeResource;
|
5fe7df
|
30 |
|
fc948c
|
31 |
import com.gitblit.GitBlit;
|
155bf7
|
32 |
import com.gitblit.Keys;
|
cb57ec
|
33 |
import com.gitblit.models.RepositoryModel;
|
cf9550
|
34 |
import com.gitblit.utils.MarkdownUtils;
|
c3f4f1
|
35 |
import com.gitblit.utils.StringUtils;
|
8c5d72
|
36 |
import com.gitblit.wicket.GitBlitWebSession;
|
31bcbe
|
37 |
import com.gitblit.wicket.PageRegistration;
|
JM |
38 |
import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;
|
5fe7df
|
39 |
import com.gitblit.wicket.WicketUtils;
|
a4d249
|
40 |
import com.gitblit.wicket.panels.RepositoriesPanel;
|
5fe7df
|
41 |
|
a7571b
|
42 |
public class RepositoriesPage extends RootPage {
|
5fe7df
|
43 |
|
JM |
44 |
public RepositoriesPage() {
|
94750e
|
45 |
super();
|
cb57ec
|
46 |
setup(null);
|
JM |
47 |
}
|
dfb889
|
48 |
|
cb57ec
|
49 |
public RepositoriesPage(PageParameters params) {
|
JM |
50 |
super(params);
|
|
51 |
setup(params);
|
|
52 |
}
|
|
53 |
|
|
54 |
private void setup(PageParameters params) {
|
|
55 |
setupPage("", "");
|
8c5d72
|
56 |
// check to see if we should display a login message
|
JM |
57 |
boolean authenticateView = GitBlit.getBoolean(Keys.web.authenticateViewPages, true);
|
|
58 |
if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) {
|
|
59 |
String messageSource = GitBlit.getString(Keys.web.loginMessage, "gitblit");
|
|
60 |
String message = readMarkdown(messageSource, "login.mkd");
|
|
61 |
Component repositoriesMessage = new Label("repositoriesMessage", message);
|
|
62 |
add(repositoriesMessage.setEscapeModelStrings(false));
|
|
63 |
add(new Label("repositoriesPanel"));
|
|
64 |
return;
|
|
65 |
}
|
|
66 |
|
c3f4f1
|
67 |
// Load the markdown welcome message
|
2a7306
|
68 |
String messageSource = GitBlit.getString(Keys.web.repositoriesMessage, "gitblit");
|
8c5d72
|
69 |
String message = readMarkdown(messageSource, "welcome.mkd");
|
JM |
70 |
Component repositoriesMessage = new Label("repositoriesMessage", message)
|
|
71 |
.setEscapeModelStrings(false).setVisible(message.length() > 0);
|
|
72 |
add(repositoriesMessage);
|
cb57ec
|
73 |
|
JM |
74 |
List<RepositoryModel> repositories = getRepositories(params);
|
|
75 |
|
|
76 |
RepositoriesPanel repositoriesPanel = new RepositoriesPanel("repositoriesPanel", showAdmin,
|
|
77 |
repositories, true, getAccessRestrictions());
|
8c5d72
|
78 |
// push the panel down if we are hiding the admin controls and the
|
JM |
79 |
// welcome message
|
|
80 |
if (!showAdmin && !repositoriesMessage.isVisible()) {
|
cb57ec
|
81 |
WicketUtils.setCssStyle(repositoriesPanel, "padding-top:5px;");
|
8c5d72
|
82 |
}
|
cb57ec
|
83 |
add(repositoriesPanel);
|
8c5d72
|
84 |
}
|
JM |
85 |
|
31bcbe
|
86 |
@Override
|
JM |
87 |
protected void addDropDownMenus(List<PageRegistration> pages) {
|
|
88 |
DropDownMenuRegistration menu = new DropDownMenuRegistration("gb.filters", RepositoriesPage.class);
|
|
89 |
menu.menuItems.addAll(getFilterMenuItems());
|
|
90 |
pages.add(menu);
|
|
91 |
}
|
|
92 |
|
8c5d72
|
93 |
private String readMarkdown(String messageSource, String resource) {
|
94750e
|
94 |
String message = "";
|
c3f4f1
|
95 |
if (messageSource.equalsIgnoreCase("gitblit")) {
|
8c5d72
|
96 |
// Read default message
|
JM |
97 |
message = readDefaultMarkdown(resource);
|
c3f4f1
|
98 |
} else {
|
8c5d72
|
99 |
// Read user-supplied message
|
c3f4f1
|
100 |
if (!StringUtils.isEmpty(messageSource)) {
|
JM |
101 |
File file = new File(messageSource);
|
|
102 |
if (file.exists()) {
|
|
103 |
try {
|
|
104 |
FileReader reader = new FileReader(file);
|
cf9550
|
105 |
message = MarkdownUtils.transformMarkdown(reader);
|
c3f4f1
|
106 |
} catch (Throwable t) {
|
JM |
107 |
message = "Failed to read " + file;
|
5450d0
|
108 |
warn(message, t);
|
c3f4f1
|
109 |
}
|
JM |
110 |
} else {
|
|
111 |
message = messageSource + " is not a valid file.";
|
|
112 |
}
|
|
113 |
}
|
|
114 |
}
|
8c5d72
|
115 |
return message;
|
JM |
116 |
}
|
|
117 |
|
|
118 |
private String readDefaultMarkdown(String file) {
|
|
119 |
String message;
|
|
120 |
try {
|
|
121 |
ContextRelativeResource res = WicketUtils.getResource(file);
|
|
122 |
InputStream is = res.getResourceStream().getInputStream();
|
|
123 |
InputStreamReader reader = new InputStreamReader(is);
|
|
124 |
message = MarkdownUtils.transformMarkdown(reader);
|
|
125 |
reader.close();
|
|
126 |
} catch (Throwable t) {
|
|
127 |
message = MessageFormat.format("Failed to read default message from {0}!", file);
|
|
128 |
error(message, t, false);
|
94750e
|
129 |
}
|
8c5d72
|
130 |
return message;
|
00afd7
|
131 |
}
|
31bcbe
|
132 |
|
JM |
133 |
@Override
|
|
134 |
protected void onBeforeRender() {
|
|
135 |
if (GitBlit.isDebugMode()) {
|
|
136 |
// strip Wicket tags in debug mode for jQuery DOM traversal
|
|
137 |
Application.get().getMarkupSettings().setStripWicketTags(true);
|
|
138 |
}
|
|
139 |
super.onBeforeRender();
|
|
140 |
}
|
|
141 |
@Override
|
|
142 |
protected void onAfterRender() {
|
|
143 |
if (GitBlit.isDebugMode()) {
|
|
144 |
// restore Wicket debug tags
|
|
145 |
Application.get().getMarkupSettings().setStripWicketTags(false);
|
|
146 |
}
|
|
147 |
super.onAfterRender();
|
|
148 |
}
|
5fe7df
|
149 |
}
|