Package com.gitblit.utils

Examples of com.gitblit.utils.ByteFormat


          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;
View Full Code Here


      fragment.add(tabsView);
    }

    // document list
    final String id = getBestCommitId(head);
    final ByteFormat byteFormat = new ByteFormat();
    Fragment docs = new Fragment("documents", "documentsFragment", this);
    ListDataProvider<PathModel> pathsDp = new ListDataProvider<PathModel>(paths);
    DataView<PathModel> pathsView = new DataView<PathModel>("document", pathsDp) {
      private static final long serialVersionUID = 1L;
      int counter;

      @Override
      public void populateItem(final Item<PathModel> item) {
        PathModel entry = item.getModelObject();
        item.add(WicketUtils.newImage("docIcon", "file_world_16x16.png"));
        item.add(new Label("docSize", byteFormat.format(entry.size)));
        item.add(new LinkPanel("docName", "list", StringUtils.stripFileExtension(entry.name),
            DocPage.class, WicketUtils.newPathParameter(repositoryName, id, entry.path)));

        // links
        item.add(new BookmarkablePageLink<Void>("view", DocPage.class, WicketUtils
View Full Code Here

      model.isParentPath = true;
      paths.add(0, model);
    }

    final String id = getBestCommitId(commit);
    final ByteFormat byteFormat = new ByteFormat();
    final String baseUrl = WicketUtils.getGitblitURL(getRequest());

    // changed paths list
    ListDataProvider<PathModel> pathsDp = new ListDataProvider<PathModel>(paths);
    DataView<PathModel> pathsView = new DataView<PathModel>("changedPath", pathsDp) {
      private static final long serialVersionUID = 1L;
      int counter;

      @Override
      public void populateItem(final Item<PathModel> item) {
        PathModel entry = item.getModelObject();
        item.add(new Label("pathPermissions", JGitUtils.getPermissionsFromMode(entry.mode)));
        if (entry.isParentPath) {
          // parent .. path
          item.add(WicketUtils.newBlankImage("pathIcon"));
          item.add(new Label("pathSize", ""));
          item.add(new LinkPanel("pathName", null, entry.name, TreePage.class,
              WicketUtils
                  .newPathParameter(repositoryName, id, entry.path)));
          item.add(new Label("pathLinks", ""));
        } else {
          if (entry.isTree()) {
            // folder/tree link
            item.add(WicketUtils.newImage("pathIcon", "folder_16x16.png"));
            item.add(new Label("pathSize", ""));
            item.add(new LinkPanel("pathName", "list", entry.name, TreePage.class,
                WicketUtils.newPathParameter(repositoryName, id,
                    entry.path)));

            // links
            Fragment links = new Fragment("pathLinks", "treeLinks", this);
            links.add(new BookmarkablePageLink<Void>("tree", TreePage.class,
                WicketUtils.newPathParameter(repositoryName, id,
                    entry.path)));
            links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
                WicketUtils.newPathParameter(repositoryName, id,
                    entry.path)));
            links.add(new CompressedDownloadsPanel("compressedLinks", baseUrl,
                repositoryName, objectId, entry.path));

            item.add(links);
          } else if (entry.isSubmodule()) {
            // submodule
            String submoduleId = entry.objectId;
            String submodulePath;
            boolean hasSubmodule = false;
            SubmoduleModel submodule = getSubmodule(entry.path);
            submodulePath = submodule.gitblitPath;
            hasSubmodule = submodule.hasSubmodule;

            item.add(WicketUtils.newImage("pathIcon", "git-orange-16x16.png"));
            item.add(new Label("pathSize", ""));
            item.add(new LinkPanel("pathName", "list", entry.name + " @ " +
                getShortObjectId(submoduleId), TreePage.class,
                WicketUtils.newPathParameter(submodulePath, submoduleId, "")).setEnabled(hasSubmodule));

            Fragment links = new Fragment("pathLinks", "submoduleLinks", this);
            links.add(new BookmarkablePageLink<Void>("view", SummaryPage.class,
                WicketUtils.newRepositoryParameter(submodulePath)).setEnabled(hasSubmodule));
            links.add(new BookmarkablePageLink<Void>("tree", TreePage.class,
                WicketUtils.newPathParameter(submodulePath, submoduleId,
                    "")).setEnabled(hasSubmodule));
            links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
                WicketUtils.newPathParameter(repositoryName, id,
                    entry.path)));
            links.add(new CompressedDownloadsPanel("compressedLinks", baseUrl,
                submodulePath, submoduleId, "").setEnabled(hasSubmodule));
            item.add(links);
          } else {
            // blob link
            String displayPath = entry.name;
            String path = entry.path;
            if (entry.isSymlink()) {
              path = JGitUtils.getStringContent(getRepository(), getCommit().getTree(), path);
              displayPath = entry.name + " -> " + path;
            }
            item.add(WicketUtils.getFileImage("pathIcon", entry.name));
            item.add(new Label("pathSize", byteFormat.format(entry.size)));
            item.add(new LinkPanel("pathName", "list", displayPath, BlobPage.class,
                WicketUtils.newPathParameter(repositoryName, id,
                    path)));

            // links
View Full Code Here

      File gitDir = r.getDirectory();
      long sz = com.gitblit.utils.FileUtils.folderSize(gitDir);
      repositorySizeCache.updateObject(model.name, model.lastChange, sz);
    }
    long size = repositorySizeCache.getObject(model.name);
    ByteFormat byteFormat = new ByteFormat();
    model.size = byteFormat.format(size);
    return size;
  }
View Full Code Here

        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
            String pp = URLEncoder.encode(requestedPath, Constants.ENCODING);
            pathEntries.add(0, new PathModel("..", pp + "/..", 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) {
          String pp = URLEncoder.encode(entry.name, Constants.ENCODING);
          response.getWriter().append(MessageFormat.format(pattern, basePath, pp,
              JGitUtils.getPermissionsFromMode(entry.mode),
              entry.isFile() ? byteFormat.format(entry.size) : ""));
        }
        response.getWriter().append("</tbody>");
        response.getWriter().append("</table>");
      }
    } catch (Throwable t) {
View Full Code Here

      };
      fragment.add(tabsView);
    }

    // document list
    final ByteFormat byteFormat = new ByteFormat();
    Fragment docs = new Fragment("documents", "documentsFragment", this);
    ListDataProvider<PathModel> pathsDp = new ListDataProvider<PathModel>(paths);
    DataView<PathModel> pathsView = new DataView<PathModel>("document", pathsDp) {
      private static final long serialVersionUID = 1L;
      int counter;

      @Override
      public void populateItem(final Item<PathModel> item) {
        PathModel entry = item.getModelObject();
        item.add(WicketUtils.newImage("docIcon", "file_world_16x16.png"));
        item.add(new Label("docSize", byteFormat.format(entry.size)));
        item.add(new LinkPanel("docName", "list", StringUtils.stripFileExtension(entry.name),
            DocPage.class, WicketUtils.newPathParameter(repositoryName, commitId, entry.path)));

        // links
        item.add(new BookmarkablePageLink<Void>("view", DocPage.class, WicketUtils
View Full Code Here

      File gitDir = r.getDirectory();
      long sz = com.gitblit.utils.FileUtils.folderSize(gitDir);
      repositorySizeCache.updateObject(model.name, model.lastChange, sz);
    }
    long size = repositorySizeCache.getObject(model.name);
    ByteFormat byteFormat = new ByteFormat();
    model.size = byteFormat.format(size);
    return size;
  }
View Full Code Here

      model.isParentPath = true;
      paths.add(0, model);
    }

    final String id = getBestCommitId(commit);
    final ByteFormat byteFormat = new ByteFormat();
    final String baseUrl = WicketUtils.getGitblitURL(getRequest());

    // changed paths list
    ListDataProvider<PathModel> pathsDp = new ListDataProvider<PathModel>(paths);
    DataView<PathModel> pathsView = new DataView<PathModel>("changedPath", pathsDp) {
      private static final long serialVersionUID = 1L;
      int counter;

      @Override
      public void populateItem(final Item<PathModel> item) {
        PathModel entry = item.getModelObject();
        item.add(new Label("pathPermissions", JGitUtils.getPermissionsFromMode(entry.mode)));
        if (entry.isParentPath) {
          // parent .. path
          item.add(WicketUtils.newBlankImage("pathIcon"));
          item.add(new Label("pathSize", ""));
          item.add(new LinkPanel("pathName", null, entry.name, TreePage.class,
              WicketUtils
                  .newPathParameter(repositoryName, id, entry.path)));
          item.add(new Label("pathLinks", ""));
        } else {
          if (entry.isTree()) {
            // folder/tree link
            item.add(WicketUtils.newImage("pathIcon", "folder_16x16.png"));
            item.add(new Label("pathSize", ""));
            item.add(new LinkPanel("pathName", "list", entry.name, TreePage.class,
                WicketUtils.newPathParameter(repositoryName, id,
                    entry.path)));

            // links
            Fragment links = new Fragment("pathLinks", "treeLinks", this);
            links.add(new BookmarkablePageLink<Void>("tree", TreePage.class,
                WicketUtils.newPathParameter(repositoryName, id,
                    entry.path)));
            links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
                WicketUtils.newPathParameter(repositoryName, id,
                    entry.path)));
            links.add(new CompressedDownloadsPanel("compressedLinks", baseUrl,
                repositoryName, objectId, entry.path));

            item.add(links);
          } else if (entry.isSubmodule()) {
            // submodule
            String submoduleId = entry.objectId;
            String submodulePath;
            boolean hasSubmodule = false;
            SubmoduleModel submodule = getSubmodule(entry.path);
            submodulePath = submodule.gitblitPath;
            hasSubmodule = submodule.hasSubmodule;

            item.add(WicketUtils.newImage("pathIcon", "git-orange-16x16.png"));
            item.add(new Label("pathSize", ""));
            item.add(new LinkPanel("pathName", "list", entry.name + " @ " +
                getShortObjectId(submoduleId), TreePage.class,
                WicketUtils.newPathParameter(submodulePath, submoduleId, "")).setEnabled(hasSubmodule));

            Fragment links = new Fragment("pathLinks", "submoduleLinks", this);
            links.add(new BookmarkablePageLink<Void>("view", SummaryPage.class,
                WicketUtils.newRepositoryParameter(submodulePath)).setEnabled(hasSubmodule));
            links.add(new BookmarkablePageLink<Void>("tree", TreePage.class,
                WicketUtils.newPathParameter(submodulePath, submoduleId,
                    "")).setEnabled(hasSubmodule));
            links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
                WicketUtils.newPathParameter(repositoryName, id,
                    entry.path)));
            links.add(new CompressedDownloadsPanel("compressedLinks", baseUrl,
                submodulePath, submoduleId, "").setEnabled(hasSubmodule));
            item.add(links);
          } else {
            // blob link
            String displayPath = entry.name;
            String path = entry.path;
            if (entry.isSymlink()) {
              path = JGitUtils.getStringContent(getRepository(), getCommit().getTree(), path);
              displayPath = entry.name + " -> " + path;
            }
            item.add(WicketUtils.getFileImage("pathIcon", entry.name));
            item.add(new Label("pathSize", byteFormat.format(entry.size)));
            item.add(new LinkPanel("pathName", "list", displayPath, BlobPage.class,
                WicketUtils.newPathParameter(repositoryName, id,
                    path)));

            // links
View Full Code Here

    // sets locale for this test
    Locale defaultLocale = Locale.getDefault();

    try {
      Locale.setDefault(Locale.ENGLISH);
      ByteFormat format = new ByteFormat();
      assertEquals("10 b", format.format(10));
      assertEquals("10 KB", format.format(1024 * 10));
      assertEquals("1,000 KB", format.format(1024 * 1000));
      assertEquals("2.0 MB", format.format(2 * 1024 * 1000));
      assertEquals("1,000.0 MB", format.format(1024 * 1024 * 1000));
      assertEquals("2.0 GB", format.format(2 * 1024 * 1024 * 1000));
    } finally {
      Locale.setDefault(defaultLocale);
    }
  }
View Full Code Here

    releaseDate.setText(status.releaseDate);
    bootDate.setText(status.bootDate.toString() + " (" + Translation.getTimeUtils().timeAgo(status.bootDate)
        + ")");
    url.setText(gitblit.url);
    servletContainer.setText(status.servletContainer);
    ByteFormat byteFormat = new ByteFormat();
    heapMaximum.setText(byteFormat.format(status.heapMaximum));
    heapAllocated.setText(byteFormat.format(status.heapAllocated));
    heapUsed.setText(byteFormat.format(status.heapAllocated - status.heapFree) + " ("
        + byteFormat.format(status.heapFree) + " " + Translation.get("gb.free") + ")");
    tableModel.setProperties(status.systemProperties);
    tableModel.fireTableDataChanged();
  }
View Full Code Here

TOP

Related Classes of com.gitblit.utils.ByteFormat

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.