You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CompressedDownloadsPanel.java 2.6KB

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