2012-05-31 37 views
2

我試圖解析URL以獲取當前分支或中繼。解析SVNKit中的URL

public SVNConnector(String s_Url, String login, String password, String project) { 
     try { 
      url = SVNURL.parseURIEncoded(s_Url); 
      ISVNAuthenticationManager authManager = new BasicAuthenticationManager(login, password); 
      DAVRepositoryFactory.setup(); 
      repository = SVNRepositoryFactory.create(url, null); 
      repository.setAuthenticationManager(authManager); 
      this.projectName = project; 
      latestRevision = repository.getLatestRevision(); 
     } catch (SVNException svne) { 
      logger.error("Impossible to connect to SVN repository. s_Url: "+s_Url+" login:"+login+" password: "+password, svne); 
     } 
    } 

我的網址是一樣的東西http://10.61.128.222/svn/i18ntest/trunkhttp://10.61.128.222/svn/PFT/branches/protoi18n,我需要一種方法,我可以輸入這個網址,並會返回/trunk//branches/protoi18n/,這樣我就可以運行這個命令:

public List<OutputElement> retrieveI18nFiles() throws SVNException { 
     List<OutputElement> outs = new ArrayList<OutputElement>(); 
     String path = url.getPath()+"/core/src/main/resources/fr/gefco/"+projectName+"/i18n/"; // this is not working! 

     latestRevision = repository.getLatestRevision(); 

     // For some reason, type safety is not insured in SVNKit, even if generics are around for some years, now 
     Collection<SVNDirEntry> entries = repository.getDir(path, latestRevision, (SVNProperties)null, (Collection<SVNDirEntry>)null); 
     for (SVNDirEntry entry : entries) { 
      OutputElement out = new OutputElement(); 
      out.setEntry(entry); 
      out.setOut(retrieveOutputStream(entry,path)); 
      outs.add(out); 
     } 
     return outs; 

    } 

url.getPath()是返回/svn/i18ntest/trunk/,這不是我所需要的。當然,我可以解析它以獲得我需要的位,但是我想首先知道SVNKit是否提供了已經證明的方法。

回答

4

使用SVNRepository時,您需要相對於存儲庫根目錄的路徑。您可以使用SVNURL root = repository.getRepositoryRoot(true)檢索存儲庫根URL,然後使用SVNURLUtil.getRelativeURL(root, url, false)獲取url與存儲庫根URL之間的相對路徑。

+0

謝謝!這正是我需要的。太糟糕了SVNURLUtil是在一個「內部」包中,沒有記錄... –