Package com.gitblit.wicket

Examples of com.gitblit.wicket.MarkupProcessor


            repository);
        error(response, mkd);
        return;
      }

      MarkupProcessor processor = new MarkupProcessor(settings);
      String [] encodings = settings.getStrings(Keys.web.blobEncodings).toArray(new String[0]);

      RevTree tree = commit.getTree();

      String res = resource;
      if (res.endsWith("/")) {
        res = res.substring(0, res.length() - 1);
      }

      List<PathModel> pathEntries = JGitUtils.getFilesInPath(r, res, commit);

      byte[] content = null;
      if (pathEntries.isEmpty()) {
        // not a path, a specific resource
        try {
          String contentType = context.getMimeType(res);
          if (contentType == null) {
            contentType = "text/plain";
          }
          if (contentType.startsWith("text")) {
            content = JGitUtils.getStringContent(r, tree, res, encodings).getBytes(
                Constants.ENCODING);
          } else {
            content = JGitUtils.getByteContent(r, tree, res, false);
          }
          response.setContentType(contentType);
        } catch (Exception e) {
        }
      } else {
        // path request
        if (!request.getPathInfo().endsWith("/")) {
          // redirect to trailing '/' url
          response.sendRedirect(request.getServletPath() + request.getPathInfo() + "/");
          return;
        }

        Map<String, String> names = new TreeMap<String, String>();
        for (PathModel entry : pathEntries) {
          names.put(entry.name.toLowerCase(), entry.name);
        }

        List<String> extensions = new ArrayList<String>();
        extensions.add("html");
        extensions.add("htm");
        extensions.addAll(processor.getMarkupExtensions());
        for (String ext : extensions) {
          String key = "index." + ext;

          if (names.containsKey(key)) {
            String fileName = names.get(key);
            String fullPath = fileName;
            if (!res.isEmpty()) {
              fullPath = res + "/" + fileName;
            }
            String stringContent = JGitUtils.getStringContent(r, tree, fullPath, encodings);
            if (stringContent == null) {
              continue;
            }
            content = stringContent.getBytes(Constants.ENCODING);
            if (content != null) {
              res = fullPath;
              // assume text/html unless the servlet container
              // overrides
              response.setContentType("text/html; charset=" + Constants.ENCODING);
              break;
            }
          }
        }
      }

      // no content, document list or custom 404 page
      if (ArrayUtils.isEmpty(content)) {
        if (pathEntries.isEmpty()) {
          // 404
          String custom404 = JGitUtils.getStringContent(r, tree, "404.html", encodings);
          if (!StringUtils.isEmpty(custom404)) {
            content = custom404.getBytes(Constants.ENCODING);
          }

          // still no content
          if (ArrayUtils.isEmpty(content)) {
            String str = MessageFormat.format(
                "# Error\nSorry, the requested resource **{0}** was not found.",
                resource);
            content = MarkdownUtils.transformMarkdown(str).getBytes(Constants.ENCODING);
          }

          try {
            // output the content
            logger.warn("Pages 404: " + resource);
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            response.getOutputStream().write(content);
            response.flushBuffer();
          } catch (Throwable t) {
            logger.error("Failed to write page to client", t);
          }
        } else {
          // document list
          response.setContentType("text/html");
          response.getWriter().append("<style>table th, table td { min-width: 150px; text-align: left; }</style>");
          response.getWriter().append("<table>");
          response.getWriter().append("<thead><tr><th>path</th><th>mode</th><th>size</th></tr>");
          response.getWriter().append("</thead>");
          response.getWriter().append("<tbody>");
          String pattern = "<tr><td><a href=\"{0}/{1}\">{1}</a></td><td>{2}</td><td>{3}</td></tr>";
          final ByteFormat byteFormat = new ByteFormat();
          if (!pathEntries.isEmpty()) {
            if (pathEntries.get(0).path.indexOf('/') > -1) {
              // we are in a subdirectory, add parent directory link
              pathEntries.add(0, new PathModel("..", resource + "/..", 0, FileMode.TREE.getBits(), null, null));
            }
          }

          String basePath = request.getServletPath() + request.getPathInfo();
          if (basePath.charAt(basePath.length() - 1) == '/') {
            // strip trailing slash
            basePath = basePath.substring(0, basePath.length() - 1);
          }
          for (PathModel entry : pathEntries) {
            response.getWriter().append(MessageFormat.format(pattern, basePath, entry.name,
                JGitUtils.getPermissionsFromMode(entry.mode), byteFormat.format(entry.size)));
          }
          response.getWriter().append("</tbody>");
          response.getWriter().append("</table>");
        }
        return;
      }

      // check to see if we should transform markup files
      String ext = StringUtils.getFileExtension(resource);
      if (processor.getMarkupExtensions().contains(ext)) {
        String markup = new String(content, Constants.ENCODING);
        MarkupDocument markupDoc = processor.parse(repository, commit.getName(), resource, markup);
        content = markupDoc.html.getBytes("UTF-8");
        response.setContentType("text/html; charset=" + Constants.ENCODING);
      }

      try {
View Full Code Here


    if (app().settings().getBoolean(Keys.web.summaryShowReadme, false)) {
      // show a readme on the summary page
      MarkupDocument markupDoc = null;
      RevCommit head = JGitUtils.getCommit(r, null);
      if (head != null) {
        MarkupProcessor processor = new MarkupProcessor(app().settings());
        markupDoc = processor.getReadme(r, repositoryName, getBestCommitId(head));
      }
      if (markupDoc == null || markupDoc.markup == null) {
        add(new Label("readme").setVisible(false));
      } else {
        Fragment fragment = new Fragment("readme", MarkupSyntax.PLAIN.equals(markupDoc.syntax) ? "plaintextPanel" : "markdownPanel", this);
View Full Code Here

public class DocsPage extends RepositoryPage {

  public DocsPage(PageParameters params) {
    super(params);

    MarkupProcessor processor = new MarkupProcessor(app().settings());

    Repository r = getRepository();
    RevCommit head = JGitUtils.getCommit(r, null);
    final String commitId = getBestCommitId(head);
    List<String> extensions = processor.getAllExtensions();
    List<PathModel> paths = JGitUtils.getDocuments(r, extensions);

    List<MarkupDocument> roots = processor.getRootDocs(r, repositoryName, commitId);
    Fragment fragment = null;
    if (roots.isEmpty()) {
      // no identified root documents
      fragment = new Fragment("docs", "noIndexFragment", this);
      setResponsePage(NoDocsPage.class, params);
View Full Code Here

  public DocPage(PageParameters params) {
    super(params);

    final String path = WicketUtils.getPath(params).replace("%2f", "/").replace("%2F", "/");
    MarkupProcessor processor = new MarkupProcessor(app().settings());

    Repository r = getRepository();
    RevCommit commit = JGitUtils.getCommit(r, objectId);
    String [] encodings = getEncodings();

    // Read raw markup content and transform it to html
    String documentPath = path;
    String markupText = JGitUtils.getStringContent(r, commit.getTree(), path, encodings);

    // Hunt for document
    if (StringUtils.isEmpty(markupText)) {
      String name = StringUtils.stripFileExtension(path);

      List<String> docExtensions = processor.getAllExtensions();
      for (String ext : docExtensions) {
        String checkName = name + "." + ext;
        markupText = JGitUtils.getStringContent(r, commit.getTree(), checkName, encodings);
        if (!StringUtils.isEmpty(markupText)) {
          // found it
          documentPath = path;
          break;
        }
      }
    }

    if (markupText == null) {
      markupText = "";
    }

    BugtraqProcessor bugtraq = new BugtraqProcessor(app().settings());
    markupText = bugtraq.processText(getRepository(), repositoryName, markupText);

    Fragment fragment;
    MarkupDocument markupDoc = processor.parse(repositoryName, getBestCommitId(commit), documentPath, markupText);
    if (MarkupSyntax.PLAIN.equals(markupDoc.syntax)) {
      fragment = new Fragment("doc", "plainContent", this);
    } else {
      fragment = new Fragment("doc", "markupContent", this);
    }
View Full Code Here

      if (blobPath.lastIndexOf('.') > -1) {
        extension = blobPath.substring(blobPath.lastIndexOf('.') + 1).toLowerCase();
      }

      // see if we should redirect to the doc page
      MarkupProcessor processor = new MarkupProcessor(app().settings());
      for (String ext : processor.getMarkupExtensions()) {
        if (ext.equals(extension)) {
          setResponsePage(DocPage.class, params);
          return;
        }
      }
View Full Code Here

      if (blobPath.lastIndexOf('.') > -1) {
        extension = blobPath.substring(blobPath.lastIndexOf('.') + 1).toLowerCase();
      }

      // see if we should redirect to the doc page
      MarkupProcessor processor = new MarkupProcessor(app().settings(), app().xssFilter());
      for (String ext : processor.getMarkupExtensions()) {
        if (ext.equals(extension)) {
          setResponsePage(DocPage.class, params);
          return;
        }
      }
View Full Code Here

  public DocPage(PageParameters params) {
    super(params);

    final String path = WicketUtils.getPath(params).replace("%2f", "/").replace("%2F", "/");
    MarkupProcessor processor = new MarkupProcessor(app().settings(), app().xssFilter());

    Repository r = getRepository();
    RevCommit commit = JGitUtils.getCommit(r, objectId);
    String [] encodings = getEncodings();

    // Read raw markup content and transform it to html
    String documentPath = path;
    String markupText = JGitUtils.getStringContent(r, commit.getTree(), path, encodings);

    // Hunt for document
    if (StringUtils.isEmpty(markupText)) {
      String name = StringUtils.stripFileExtension(path);

      List<String> docExtensions = processor.getAllExtensions();
      for (String ext : docExtensions) {
        String checkName = name + "." + ext;
        markupText = JGitUtils.getStringContent(r, commit.getTree(), checkName, encodings);
        if (!StringUtils.isEmpty(markupText)) {
          // found it
          documentPath = path;
          break;
        }
      }
    }

    if (markupText == null) {
      markupText = "";
    }

    BugtraqProcessor bugtraq = new BugtraqProcessor(app().settings());
    markupText = bugtraq.processText(getRepository(), repositoryName, markupText);

    Fragment fragment;
    MarkupDocument markupDoc = processor.parse(repositoryName, getBestCommitId(commit), documentPath, markupText);
    if (MarkupSyntax.PLAIN.equals(markupDoc.syntax)) {
      fragment = new Fragment("doc", "plainContent", this);
    } else {
      fragment = new Fragment("doc", "markupContent", this);
    }
View Full Code Here

  public DocsPage(PageParameters params) {
    super(params);

    String objectId = WicketUtils.getObject(params);

    MarkupProcessor processor = new MarkupProcessor(app().settings(), app().xssFilter());

    Repository r = getRepository();
    RevCommit head = JGitUtils.getCommit(r, objectId);
    final String commitId = getBestCommitId(head);

    List<String> extensions = processor.getAllExtensions();
    List<PathModel> paths = JGitUtils.getDocuments(r, extensions);

    List<MarkupDocument> roots = processor.getRootDocs(r, repositoryName, commitId);
    Fragment fragment = null;
    if (roots.isEmpty()) {
      // no identified root documents
      fragment = new Fragment("docs", "noIndexFragment", this);
      setResponsePage(NoDocsPage.class, params);
View Full Code Here

    if (app().settings().getBoolean(Keys.web.summaryShowReadme, false)) {
      // show a readme on the summary page
      MarkupDocument markupDoc = null;
      RevCommit head = JGitUtils.getCommit(r, null);
      if (head != null) {
        MarkupProcessor processor = new MarkupProcessor(app().settings(), app().xssFilter());
        markupDoc = processor.getReadme(r, repositoryName, getBestCommitId(head));
      }
      if (markupDoc == null || markupDoc.markup == null) {
        add(new Label("readme").setVisible(false));
      } else {
        Fragment fragment = new Fragment("readme", MarkupSyntax.PLAIN.equals(markupDoc.syntax) ? "plaintextPanel" : "markdownPanel", this);
View Full Code Here

TOP

Related Classes of com.gitblit.wicket.MarkupProcessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.