Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DocPage.java 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.util.List;
  18. import org.apache.wicket.PageParameters;
  19. import org.apache.wicket.markup.html.basic.Label;
  20. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  21. import org.eclipse.jgit.lib.Repository;
  22. import org.eclipse.jgit.revwalk.RevCommit;
  23. import com.gitblit.GitBlit;
  24. import com.gitblit.utils.JGitUtils;
  25. import com.gitblit.utils.StringUtils;
  26. import com.gitblit.wicket.CacheControl;
  27. import com.gitblit.wicket.CacheControl.LastModified;
  28. import com.gitblit.wicket.MarkupProcessor;
  29. import com.gitblit.wicket.MarkupProcessor.MarkupDocument;
  30. import com.gitblit.wicket.WicketUtils;
  31. @CacheControl(LastModified.BOOT)
  32. public class DocPage extends RepositoryPage {
  33. public DocPage(PageParameters params) {
  34. super(params);
  35. final String path = WicketUtils.getPath(params).replace("%2f", "/").replace("%2F", "/");
  36. MarkupProcessor processor = new MarkupProcessor(GitBlit.getSettings());
  37. Repository r = getRepository();
  38. RevCommit commit = JGitUtils.getCommit(r, objectId);
  39. String [] encodings = GitBlit.getEncodings();
  40. // Read raw markup content and transform it to html
  41. String documentPath = path;
  42. String markupText = JGitUtils.getStringContent(r, commit.getTree(), path, encodings);
  43. // Hunt for document
  44. if (StringUtils.isEmpty(markupText)) {
  45. String name = StringUtils.stripFileExtension(path);
  46. List<String> docExtensions = processor.getAllExtensions();
  47. for (String ext : docExtensions) {
  48. String checkName = name + "." + ext;
  49. markupText = JGitUtils.getStringContent(r, commit.getTree(), checkName, encodings);
  50. if (!StringUtils.isEmpty(markupText)) {
  51. // found it
  52. documentPath = path;
  53. break;
  54. }
  55. }
  56. }
  57. // document page links
  58. add(new BookmarkablePageLink<Void>("blameLink", BlamePage.class,
  59. WicketUtils.newPathParameter(repositoryName, objectId, documentPath)));
  60. add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
  61. WicketUtils.newPathParameter(repositoryName, objectId, documentPath)));
  62. add(new BookmarkablePageLink<Void>("rawLink", RawPage.class, WicketUtils.newPathParameter(
  63. repositoryName, objectId, documentPath)));
  64. MarkupDocument markupDoc = processor.parse(repositoryName, getBestCommitId(commit), documentPath, markupText);
  65. add(new Label("content", markupDoc.html).setEscapeModelStrings(false));
  66. }
  67. @Override
  68. protected String getPageName() {
  69. return getString("gb.docs");
  70. }
  71. @Override
  72. protected Class<? extends BasePage> getRepoNavPageClass() {
  73. return DocsPage.class;
  74. }
  75. }