예제 #1
0
  @Override
  public ObjectNode findFileInfo(String path) throws SVNException {
    org.tmatesoft.svn.core.io.SVNRepository repository = getSVNRepository();

    SVNNodeKind nodeKind = repository.checkPath(path, -1);

    if (nodeKind == SVNNodeKind.DIR) {
      // 폴더 내용 출력
      ObjectNode result = Json.newObject();

      result.put("type", "folder");
      ObjectNode listData = Json.newObject();

      SVNProperties prop = new SVNProperties();

      Collection<SVNDirEntry> entries =
          repository.getDir(path, -1, prop, SVNDirEntry.DIRENT_ALL, (Collection) null);

      Iterator<SVNDirEntry> iterator = entries.iterator();
      while (iterator.hasNext()) {
        SVNDirEntry entry = iterator.next();

        ObjectNode data = Json.newObject();
        String author = entry.getAuthor();
        User user = User.findByLoginId(author);

        data.put("type", entry.getKind() == SVNNodeKind.DIR ? "folder" : "file");
        data.put("msg", entry.getCommitMessage());
        data.put("author", author);
        data.put("avatar", getAvatar(user));
        data.put("userName", user.name);
        data.put("userLoginId", user.loginId);
        data.put("createdDate", entry.getDate().getTime());

        listData.put(entry.getName(), data);
      }
      result.put("data", listData);

      return result;

    } else if (nodeKind == SVNNodeKind.FILE) {
      // 파일 내용 출력
      return fileAsJson(path, repository);
    } else {
      return null;
    }
  }
예제 #2
0
  private static void list(
      SVNRepository repository,
      String path,
      long rev,
      SVNDepth depth,
      int entryFields,
      Map<SVNURL, SVNPropertyValue> externals,
      SVNURL externalParentUrl,
      String externalTarget,
      ISVNDirEntryHandler handler)
      throws SVNException {
    if (depth == SVNDepth.EMPTY) {
      return;
    }
    Collection entries = new TreeSet();
    SVNProperties properties;
    try {
      properties = externals == null ? null : new SVNProperties();
      entries = repository.getDir(path, rev, properties, entryFields, entries);
    } catch (SVNAuthenticationException e) {
      return;
    } catch (SVNException e) {
      if (e.getErrorMessage().getErrorCode() == SVNErrorCode.RA_NOT_AUTHORIZED) {
        return;
      }
      throw e;
    }

    SVNPropertyValue svnExternalsVaule =
        properties == null ? null : properties.getSVNPropertyValue(SVNProperty.EXTERNALS);
    if (svnExternalsVaule != null) {
      SVNURL location = repository.getLocation();
      externals.put(location.appendPath(path, false), svnExternalsVaule);
    }

    for (Iterator iterator = entries.iterator(); iterator.hasNext(); ) {
      SVNDirEntry entry = (SVNDirEntry) iterator.next();
      String childPath = SVNPathUtil.append(path, entry.getName());
      entry.setRelativePath(childPath);
      if (entry.getKind() == SVNNodeKind.FILE
          || depth == SVNDepth.IMMEDIATES
          || depth == SVNDepth.INFINITY) {
        entry.setExternalParentUrl(externalParentUrl);
        entry.setExternalTarget(externalTarget);
        handler.handleDirEntry(entry);
      }
      if (entry.getKind() == SVNNodeKind.DIR
          && entry.getDate() != null
          && depth == SVNDepth.INFINITY) {
        list(
            repository,
            childPath,
            rev,
            depth,
            entryFields,
            externals,
            externalParentUrl,
            externalTarget,
            handler);
      }
    }
  }