Ejemplo n.º 1
0
  @Override
  public String getHtml(IMacroContext macroContext) {
    htmlSerializerContext = macroContext.getHtmlSerializerContext();
    pageStore = macroContext.getPageStore();
    permissionEvaluator = macroContext.getPermissionEvaluator();

    path = htmlSerializerContext.getPagePath();
    if (path != null) {
      projectName = htmlSerializerContext.getProjectName();
      branchName = htmlSerializerContext.getBranchName();

      if (log.isInfoEnabled()) {
        log.info(
            "rendering neighbors for page: {}/{}/{}, user: {}", //$NON-NLS-1$
            projectName,
            branchName,
            Util.toUrlPagePath(path),
            htmlSerializerContext.getAuthentication().getName());
      }

      try {
        StringBuilder buf = new StringBuilder();
        buf.append(
                "<ul class=\"well well-small nav nav-list neighbors pull-right\">") //$NON-NLS-1$
            .append(printParent(printLinkListItem(path), path))
            .append("</ul>"); // $NON-NLS-1$
        return buf.toString();
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    } else {
      return null;
    }
  }
Ejemplo n.º 2
0
 private CharSequence printRegularLinkListItem(String path, String title) {
   StringBuilder buf = new StringBuilder();
   if (hasViewPermission(path)) {
     String uri = htmlSerializerContext.getPageUri(path);
     buf.append("<li><a href=\"")
         .append(uri)
         .append("\">") // $NON-NLS-1$ //$NON-NLS-2$
         .append(title)
         .append("</a></li>"); // $NON-NLS-1$
   }
   return buf;
 }
Ejemplo n.º 3
0
 private CharSequence printActiveLinkListItem(String path, String title) throws IOException {
   String uri = htmlSerializerContext.getPageUri(path);
   StringBuilder buf = new StringBuilder();
   buf.append("<li class=\"active\"><a href=\"")
       .append(uri)
       .append("\">") // $NON-NLS-1$ //$NON-NLS-2$
       .append(title)
       .append("</a>") // $NON-NLS-1$
       .append(printChildren(path))
       .append("</li>"); // $NON-NLS-1$
   return buf;
 }
Ejemplo n.º 4
0
  private CharSequence printParent(CharSequence inner, String path) throws IOException {
    StringBuilder buf = new StringBuilder();
    Page page = pageStore.getPage(projectName, branchName, path, false);
    if (page.getParentPagePath() != null) {
      if (hasViewPermission(page.getParentPagePath())) {
        StringBuilder parentBuf = new StringBuilder();
        Page parentPage =
            pageStore.getPage(projectName, branchName, page.getParentPagePath(), false);
        String uri = htmlSerializerContext.getPageUri(page.getParentPagePath());
        parentBuf
            .append("<li><a href=\"")
            .append(uri)
            .append("\">") // $NON-NLS-1$ //$NON-NLS-2$
            .append(parentPage.getTitle())
            .append("</a>") // $NON-NLS-1$
            .append("<ul class=\"nav nav-list\">"); // $NON-NLS-1$

        if (path.equals(this.path)) {
          List<String> siblingPaths =
              pageStore.listChildPagePaths(projectName, branchName, page.getParentPagePath());
          for (String siblingPath : siblingPaths) {
            parentBuf.append(siblingPath.equals(path) ? inner : printLinkListItem(siblingPath));
          }
        } else {
          parentBuf.append(inner);
        }
        parentBuf
            .append("</ul>") // $NON-NLS-1$
            .append("</li>"); // $NON-NLS-1$

        buf.append(printParent(parentBuf, page.getParentPagePath()));
      }
    } else {
      buf.append(inner);
    }
    return buf;
  }
Ejemplo n.º 5
0
 private boolean hasViewPermission(String path) {
   Authentication authentication = htmlSerializerContext.getAuthentication();
   return permissionEvaluator.hasPagePermission(
       authentication, projectName, branchName, path, Permission.VIEW);
 }