commit | author | age
|
59b817
|
1 |
/*
|
JM |
2 |
* Copyright 2012 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 |
*/
|
|
16 |
package com.gitblit.wicket.panels;
|
|
17 |
|
|
18 |
import java.util.List;
|
|
19 |
|
|
20 |
import org.apache.wicket.Component;
|
|
21 |
import org.apache.wicket.markup.html.basic.Label;
|
|
22 |
import org.apache.wicket.markup.html.panel.Panel;
|
|
23 |
import org.apache.wicket.markup.repeater.Item;
|
|
24 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
25 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
|
26 |
|
|
27 |
import com.gitblit.DownloadZipServlet;
|
|
28 |
import com.gitblit.DownloadZipServlet.Format;
|
|
29 |
import com.gitblit.GitBlit;
|
|
30 |
import com.gitblit.Keys;
|
|
31 |
|
|
32 |
public class CompressedDownloadsPanel extends Panel {
|
|
33 |
|
|
34 |
private static final long serialVersionUID = 1L;
|
|
35 |
|
|
36 |
public CompressedDownloadsPanel(String id, final String baseUrl, final String repositoryName, final String objectId, final String path) {
|
|
37 |
super(id);
|
|
38 |
|
|
39 |
List<String> types = GitBlit.getStrings(Keys.web.compressedDownloads);
|
|
40 |
if (types.isEmpty()) {
|
|
41 |
types.add(Format.zip.name());
|
|
42 |
types.add(Format.gz.name());
|
|
43 |
}
|
|
44 |
|
|
45 |
ListDataProvider<String> refsDp = new ListDataProvider<String>(types);
|
|
46 |
DataView<String> refsView = new DataView<String>("compressedLinks", refsDp) {
|
|
47 |
private static final long serialVersionUID = 1L;
|
|
48 |
int counter;
|
|
49 |
|
|
50 |
@Override
|
|
51 |
protected void onBeforeRender() {
|
|
52 |
super.onBeforeRender();
|
|
53 |
counter = 0;
|
|
54 |
}
|
|
55 |
|
|
56 |
@Override
|
|
57 |
public void populateItem(final Item<String> item) {
|
|
58 |
String compressionType = item.getModelObject();
|
|
59 |
Format format = Format.fromName(compressionType);
|
|
60 |
|
|
61 |
String href = DownloadZipServlet.asLink(baseUrl, repositoryName,
|
|
62 |
objectId, path, format);
|
|
63 |
Component c = new LinkPanel("compressedLink", null, format.name(), href);
|
|
64 |
item.add(c);
|
|
65 |
Label lb = new Label("linkSep", "|");
|
|
66 |
lb.setVisible(counter > 0);
|
|
67 |
lb.setRenderBodyOnly(true);
|
|
68 |
item.add(lb.setEscapeModelStrings(false));
|
|
69 |
item.setRenderBodyOnly(true);
|
|
70 |
counter++;
|
|
71 |
}
|
|
72 |
};
|
|
73 |
add(refsView);
|
|
74 |
|
|
75 |
setVisible(GitBlit.getBoolean(Keys.web.allowZipDownloads, true));
|
|
76 |
}
|
|
77 |
} |