Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

RepositoriesPage.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  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. */
  16. package com.gitblit.wicket.pages;
  17. import java.io.File;
  18. import java.io.FileReader;
  19. import java.io.InputStream;
  20. import java.io.InputStreamReader;
  21. import org.apache.wicket.Component;
  22. import org.apache.wicket.markup.html.basic.Label;
  23. import org.apache.wicket.resource.ContextRelativeResource;
  24. import com.gitblit.GitBlit;
  25. import com.gitblit.Keys;
  26. import com.gitblit.utils.MarkdownUtils;
  27. import com.gitblit.utils.StringUtils;
  28. import com.gitblit.wicket.BasePage;
  29. import com.gitblit.wicket.GitBlitWebSession;
  30. import com.gitblit.wicket.WicketUtils;
  31. import com.gitblit.wicket.panels.RepositoriesPanel;
  32. import com.gitblit.wicket.panels.UsersPanel;
  33. public class RepositoriesPage extends BasePage {
  34. public RepositoriesPage() {
  35. super();
  36. setupPage("", "");
  37. final boolean showAdmin;
  38. if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {
  39. boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
  40. showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();
  41. // authentication requires state and session
  42. setStatelessHint(false);
  43. } else {
  44. showAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
  45. if (GitBlit.getBoolean(Keys.web.authenticateViewPages, false)) {
  46. // authentication requires state and session
  47. setStatelessHint(false);
  48. } else {
  49. // no authentication required, no state and no session required
  50. setStatelessHint(true);
  51. }
  52. }
  53. // display an error message cached from a redirect
  54. String cachedMessage = GitBlitWebSession.get().clearErrorMessage();
  55. if (!StringUtils.isEmpty(cachedMessage)) {
  56. error(cachedMessage);
  57. }
  58. // Load the markdown welcome message
  59. String messageSource = GitBlit.getString(Keys.web.repositoriesMessage, "gitblit");
  60. String message = "<br/>";
  61. if (messageSource.equalsIgnoreCase("gitblit")) {
  62. // Read default welcome message
  63. try {
  64. ContextRelativeResource res = WicketUtils.getResource("welcome.mkd");
  65. InputStream is = res.getResourceStream().getInputStream();
  66. InputStreamReader reader = new InputStreamReader(is);
  67. message = MarkdownUtils.transformMarkdown(reader);
  68. } catch (Throwable t) {
  69. message = "Failed to read default welcome message!";
  70. error(message, t, false);
  71. }
  72. } else {
  73. // Read user-supplied welcome message
  74. if (!StringUtils.isEmpty(messageSource)) {
  75. File file = new File(messageSource);
  76. if (file.exists()) {
  77. try {
  78. FileReader reader = new FileReader(file);
  79. message = MarkdownUtils.transformMarkdown(reader);
  80. } catch (Throwable t) {
  81. message = "Failed to read " + file;
  82. error(message, t, false);
  83. }
  84. } else {
  85. message = messageSource + " is not a valid file.";
  86. }
  87. }
  88. }
  89. Component repositoriesMessage = new Label("repositoriesMessage", message)
  90. .setEscapeModelStrings(false);
  91. add(repositoriesMessage);
  92. add(new RepositoriesPanel("repositoriesPanel", showAdmin, getAccessRestrictions()));
  93. add(new UsersPanel("usersPanel", showAdmin).setVisible(showAdmin));
  94. }
  95. }