Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * ====================================================================
   * Copyright (c) 2004-2006 TMate Software Ltd.  All rights reserved.
   *
   * This software is licensed as described in the file COPYING, which
   * you should have received as part of this distribution.  The terms
   * are also available at http://svnkit.com/license.html
   * If newer versions of this license are posted there, you may use a
   * newer version instead, at your option.
  * ====================================================================
  */
 
 package org.tmatesoft.svn.core.internal.io.dav;
 
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 

Author(s):
TMate Software Ltd.
Version:
1.1.0
 
 class DAVRepository extends SVNRepository {
 
     private DAVConnection myConnection;
     
     protected DAVRepository(IHTTPConnectionFactory connectionFactorySVNURL locationISVNSession options) {
         super(locationoptions);
          = connectionFactory;
     }
     
     public void testConnection() throws SVNException {
         try {
             openConnection();
             if ( != null) {
                 .fetchRepositoryUUID(this);
                 .fetchRepositoryRoot(this);
             }
         } finally {
             closeConnection();
         }
     }
     
     public boolean hasRepositoryUUID() {
         return  != null;
     }
     
     public void setRepositoryUUID(String uuid) {
          = uuid;
     }
 
     public boolean hasRepositoryRoot() {
         return  != null;
     }
 
     public void setRepositoryRoot(SVNURL root) {
          = root;
    }
    
    public SVNURL getRepositoryRoot(boolean forceConnectionthrows SVNException { 
        if ( == null) {
            if ( != null) {
                .fetchRepositoryRoot(this);
            } else if (forceConnection) {
                openConnection();
                try {
                    .fetchRepositoryRoot(this);
                } finally {
                    closeConnection();
                }
            }
        }
        return ;
    }
    public String getRepositoryUUID(boolean forceConnectionthrows SVNException {
        if ( == null) {
            if ( != null) {
                .fetchRepositoryUUID(this);
            } else if (forceConnection) {
               openConnection();
               try {
                   .fetchRepositoryUUID(this);
                   
               } finally {
                   closeConnection();
               }
            }
        }
        return ;
    }
    
    public void setAuthenticationManager(ISVNAuthenticationManager authManager) {
        if (authManager != getAuthenticationManager() &&  != null) {
            .clearAuthenticationCache();
        }
        super.setAuthenticationManager(authManager);
    }
    public long getLatestRevision() throws SVNException {        
        try {
            openConnection();
            String path = getLocation().getPath();
            path = SVNEncodingUtil.uriEncode(path);
            DAVBaselineInfo info = DAVUtil.getBaselineInfo(thispath, -1, falsetruenull);
            return info.revision;
        } finally {
            closeConnection();
        }
    }
    public long getDatedRevision(Date datethrows SVNException {
    	date = date == null ? new Date(System.currentTimeMillis()) : date;
		StringBuffer request = DAVDateRevisionHandler.generateDateRevisionRequest(nulldate);
    	try {
    		openConnection();
            String path = getLocation().getURIEncodedPath();
            path = DAVUtil.getVCCPath(thispath);
			HTTPStatus status = .doReport(pathrequesthandler);
            if (status.getError() != null) {
                if (status.getError().getErrorCode() == .) {
                    SVNErrorMessage err2 = SVNErrorMessage.create(status.getError().getErrorCode(), "Server does not support date-based operations");
                    SVNErrorManager.error(err2status.getError());
                }
                SVNErrorManager.error(status.getError());
            }
    	} finally {
    		closeConnection();
    	}
    	return handler.getRevisionNumber();
    }
    public SVNNodeKind checkPath(String pathlong revisionthrows SVNException {
        DAVBaselineInfo info = null;
        SVNNodeKind kind = .;
        try {
            openConnection();
            path = getFullPath(path);
            path = SVNEncodingUtil.uriEncode(path);
            info = DAVUtil.getBaselineInfo(thispathrevisiontruefalseinfo);
            kind = info.isDirectory ? . : .;
        } catch (SVNException e) {
            SVNErrorMessage error = e.getErrorMessage();
            if (error != null) {
                if (error.getErrorCode() == .) {
                    return kind;
                }
                error = error.getChildErrorMessage();
            }
            throw e;
        } finally {
            closeConnection();
        }
        return kind;
    }
    
    public Map getRevisionProperties(long revisionMap propertiesthrows SVNException {
        properties = properties == null ? new HashMap() : properties;
        try {
            openConnection();
            String path = getLocation().getPath();
            path = SVNEncodingUtil.uriEncode(path);
            DAVProperties source = DAVUtil.getBaselineProperties(thispathrevisionnull);
            properties = DAVUtil.filterProperties(sourceproperties);
            if (revision >= 0) {
                String commitMessage = (Stringproperties.get(.);
                getOptions().saveCommitMessage(DAVRepository.thisrevisioncommitMessage);
            }
        } finally {
            closeConnection();
        }
        return properties;
    }
    
    public String getRevisionPropertyValue(long revisionString propertyNamethrows SVNException {
        Map properties = getRevisionProperties(revisionnull);
        return (Stringproperties.get(propertyName);
    }
    public long getFile(String pathlong revisionfinal Map propertiesOutputStream contentsthrows SVNException {
        long fileRevision = revision;
        try {
            openConnection();
            path = getFullPath(path);
            path = SVNEncodingUtil.uriEncode(path);
            if (revision != -2) {
                DAVBaselineInfo info = DAVUtil.getBaselineInfo(thispathrevisionfalsetruenull);
                path = SVNPathUtil.append(info.baselineBaseinfo.baselinePath);
                fileRevision = info.revision
            }
            if (properties != null) {
                DAVProperties props = DAVUtil.getResourceProperties(pathnullnull);
                DAVUtil.filterProperties(propsproperties);
                for (Iterator names = props.getProperties().keySet().iterator(); names.hasNext();) {
                    DAVElement property = (DAVElementnames.next();
                    if (property == .) {
                        properties.put(.props.getPropertyValue(property));
                    } else if (property == .) {
                        properties.put(.props.getPropertyValue(property));
                    } else if (property == .) {
                        properties.put(.props.getPropertyValue(property));
                    } else if (property == .) {
                        properties.put(.props.getPropertyValue(property));
                    }
                }
                if (fileRevision >= 0) {
                    properties.put(., Long.toString(fileRevision));
                }
            }
            if (contents != null) {
                .doGet(pathcontents);
            }
        } finally {
            closeConnection();
        }
        return fileRevision;
    }
    public long getDir(String pathlong revisionfinal Map propertiesfinal ISVNDirEntryHandler handlerthrows SVNException {
        long dirRevision = revision;
        try {
            openConnection();
            path = getFullPath(path);
            path = SVNEncodingUtil.uriEncode(path);
            final String fullPath = path;
            if (revision != -2) {
                DAVBaselineInfo info = DAVUtil.getBaselineInfo(thispathrevisionfalsetruenull);
                path = SVNPathUtil.append(info.baselineBaseinfo.baselinePath);
                dirRevision = info.revision
            }
            if (handler != null) {
                final int parentPathSegments = SVNPathUtil.getSegmentsCount(path);
                Map dirEntsMap = new HashMap();
                HTTPStatus status = DAVUtil.getProperties(path.nullnulldirEntsMap);
                if (status.getError() != null) {
                    SVNErrorManager.error(status.getError());
                }
                for(Iterator dirEnts = dirEntsMap.keySet().iterator(); dirEnts.hasNext();) {
                    String url = (StringdirEnts.next();
                    DAVProperties child = (DAVPropertiesdirEntsMap.get(url);
                    String href = child.getURL();
                    if (parentPathSegments == SVNPathUtil.getSegmentsCount(href)) {
                        continue;
                    }
                    String name = SVNEncodingUtil.uriDecode(SVNPathUtil.tail(href));
                    SVNNodeKind kind = .;
                    Object revisionStr = child.getPropertyValue(.);
                    long lastRevision = Long.parseLong(revisionStr.toString());
                    String sizeStr = child.getPropertyValue(.);
                    long size = sizeStr == null ? 0 : Long.parseLong(sizeStr);
                    if (child.isCollection()) {
                        kind = .;
                    }
                    String author = child.getPropertyValue(.);
                    String dateStr = child.getPropertyValue(.);
                    Date date = dateStr != null ? SVNTimeUtil.parseDate(dateStr) : null;
                    boolean hasProperties = false;
                    for(Iterator props = child.getProperties().keySet().iterator(); props.hasNext();) {
                        DAVElement property = (DAVElementprops.next();
                        if (..equals(property.getNamespace()) || 
                                ..equals(property.getNamespace())) {
                            hasProperties = true;
                            break;
                        }
                    }
                    SVNURL childURL = getLocation().setPath(fullPathtrue);
                    childURL = childURL.appendPath(namefalse);
                    SVNDirEntry dirEntry = new SVNDirEntry(childURLnamekindsizehasPropertieslastRevisiondateauthor);
                    handler.handleDirEntry(dirEntry);
                }                
            }
            if (properties != null) {
                DAVProperties dirProps = DAVUtil.getResourceProperties(pathnullnull);
                DAVUtil.filterProperties(dirPropsproperties);
                for(Iterator props = dirProps.getProperties().keySet().iterator(); props.hasNext();) {
                    DAVElement property = (DAVElementprops.next();
                    if (property == .) {
                        properties.put(.dirProps.getPropertyValue(property));
                    } else if (property == .) {
                        properties.put(.dirProps.getPropertyValue(property));
                    } else if (property == .) {
                        properties.put(.dirProps.getPropertyValue(property));
                    }
                }
            }
        } finally {
            closeConnection();
        }
        return dirRevision;
    }
    public SVNDirEntry getDir(String pathlong revisionboolean includeCommentsfinal Collection entriesthrows SVNException {
        final SVNDirEntry[] parent = new SVNDirEntry[1];
        final String[] parentVCC = new String[1];
        try {
            openConnection();
            path = getFullPath(path);
            path = SVNEncodingUtil.uriEncode(path);
            final String fullPath = path;
            if (revision >= 0) {
                DAVBaselineInfo info = DAVUtil.getBaselineInfo(thispathrevisionfalsetruenull);
                path = SVNPathUtil.append(info.baselineBaseinfo.baselinePath);
            }
            final int parentPathSegments = SVNPathUtil.getSegmentsCount(path);
            final List vccs = new ArrayList();
            
            DAVElement[] dirProperties = new DAVElement[] {.
                    ...
                    ..};
            Map dirEntsMap = new HashMap();
            HTTPStatus status = DAVUtil.getProperties(path.nulldirPropertiesdirEntsMap);
            if (status.getError() != null) {
                SVNErrorManager.error(status.getError());
            }
            for(Iterator dirEnts = dirEntsMap.keySet().iterator(); dirEnts.hasNext();) {
                String url = (StringdirEnts.next();
                DAVProperties child = (DAVPropertiesdirEntsMap.get(url);
                String href = child.getURL();
                String name = "";
                if (parentPathSegments != SVNPathUtil.getSegmentsCount(href)) {
                    name = SVNEncodingUtil.uriDecode(SVNPathUtil.tail(href));
                }
                SVNNodeKind kind = .;
                Object revisionStr = child.getPropertyValue(.);
                long lastRevision = Long.parseLong(revisionStr.toString());
                String sizeStr = child.getPropertyValue(.);
                long size = sizeStr == null ? 0 : Long.parseLong(sizeStr);
                if (child.isCollection()) {
                    kind = .;
                }
                String author = child.getPropertyValue(.);
                String dateStr = child.getPropertyValue(.);
                Date date = dateStr != null ? SVNTimeUtil.parseDate(dateStr) : null;
                SVNURL childURL = getLocation().setPath(fullPathtrue);
                if ("".equals(name)) {
                    parent[0] = new SVNDirEntry(childURLnamekindsizefalselastRevisiondateauthor);
                    parentVCC[0] = child.getPropertyValue(.);
                } else {
                    childURL = childURL.appendPath(namefalse);
                    entries.add(new SVNDirEntry(childURLnamekindsizefalselastRevisiondateauthor));
                    vccs.add(child.getPropertyValue(.));
                }
            }
            if (includeComments) {
                DAVElement logProperty = DAVElement.getElement(."log");
                Iterator ents = entries.iterator();
                SVNDirEntry entry = parent[0];
                String vcc = parentVCC[0];
                int index = 0;
                while(true) {
                    String label = Long.toString(entry.getRevision());
                    if (entry.getDate() != null && getOptions().hasCommitMessage(thisentry.getRevision())) {
                        String message = getOptions().getCommitMessage(thisentry.getRevision());
                        entry.setCommitMessage(message);
                    } else if (entry.getDate() != null) {
                        final SVNDirEntry currentEntry = entry;
                        String commitMessage = DAVUtil.getPropertyValue(vcclabellogProperty);
                        getOptions().saveCommitMessage(DAVRepository.thiscurrentEntry.getRevision(), commitMessage);
                        currentEntry.setCommitMessage(commitMessage);
                    }
                    if (ents.hasNext()) {
                        entry = (SVNDirEntryents.next();
                        vcc = (Stringvccs.get(index);
                        index++;
                    } else {
                        break;
                    }
                }
            }
        } finally {
            closeConnection();
        }
        return parent[0];
    }
    public int getFileRevisions(String pathlong startRevisionlong endRevisionISVNFileRevisionHandler handlerthrows SVNException {
		String bcPath = getLocation().getPath();
        bcPath = SVNEncodingUtil.uriEncode(bcPath);
		try {
            openConnection();
            path = "".equals(path) ? "" : getRepositoryPath(path);
            DAVFileRevisionHandler davHandler = new DAVFileRevisionHandler(handler);
            StringBuffer request = DAVFileRevisionHandler.generateFileRevisionsRequest(nullstartRevisionendRevisionpath);
			long revision = -1;
			if (isValidRevision(startRevision) && isValidRevision(endRevision)) {
				revision = Math.max(startRevisionendRevision);				
			}
			DAVBaselineInfo info = DAVUtil.getBaselineInfo(thisbcPathrevisionfalsefalsenull);
			bcPath = SVNPathUtil.append(info.baselineBaseinfo.baselinePath);
			HTTPStatus status = .doReport(bcPathrequestdavHandler);
            if (status.getCode() == 501) {
                SVNErrorMessage err = SVNErrorMessage.create(."'get-file-revs' REPORT not implemented");
                SVNErrorManager.error(errstatus.getError());
            } else if (status.getError() != null) {
                SVNErrorManager.error(status.getError());
            }
            if (davHandler.getEntriesCount() <= 0) {
                SVNErrorMessage err = SVNErrorMessage.create(."The file-revs report didn't contain any revisions");
                SVNErrorManager.error(err);
            }
            return davHandler.getEntriesCount();
finally {
		}
    }
    
    public long log(String[] targetPathslong startRevisionlong endRevision,
            boolean changedPathboolean strictNodelong limitfinal ISVNLogEntryHandler handlerthrows SVNException {
        if (targetPaths == null || targetPaths.length == 0) {
            targetPaths = new String[]{""};
        }
        DAVLogHandler davHandler = null;
        ISVNLogEntryHandler cachingHandler = new ISVNLogEntryHandler() {
                public void handleLogEntry(SVNLogEntry logEntrythrows SVNException {
                    if (logEntry.getDate() != null) {
                        getOptions().saveCommitMessage(DAVRepository.thislogEntry.getRevision(), logEntry.getMessage());
                    }
                    handler.handleLogEntry(logEntry);
                }
            
        };
        long latestRev = -1;
        if (isInvalidRevision(startRevision)) {
            startRevision = latestRev = getLatestRevision();
        }
        if (isInvalidRevision(endRevision)) {
            endRevision = latestRev != -1 ? latestRev : getLatestRevision(); 
        }
        
        try {
			String[] fullPaths = new String[targetPaths.length];
			for (int i = 0; i < targetPaths.lengthi++) {
				fullPaths[i] = getFullPath(targetPaths[i]);
            }
            Collection relativePaths = new HashSet();
            String path = SVNPathUtil.condencePaths(fullPathsrelativePathsfalse);
            if (relativePaths.isEmpty()) {
                relativePaths.add("");
            }
            fullPaths = (String[]) relativePaths.toArray(new String[relativePaths.size()]);
            
	        StringBuffer request = DAVLogHandler.generateLogRequest(nullstartRevisionendRevision,
	        		changedPathstrictNodelimitfullPaths);
	        
            davHandler = new DAVLogHandler(cachingHandlerlimit); 
			long revision = Math.max(startRevisionendRevision);
            path = SVNEncodingUtil.uriEncode(path);
            DAVBaselineInfo info = DAVUtil.getBaselineInfo(thispathrevisionfalsefalsenull);
            path = SVNPathUtil.append(info.baselineBaseinfo.baselinePath);
            HTTPStatus status = .doReport(pathrequestdavHandler);
            if (status.getError() != null && !davHandler.isCompatibleMode()) {
                SVNErrorManager.error(status.getError());
            }
finally {
		}
        return davHandler.getEntriesCount();
    }
    
    private void openConnection() throws SVNException {
        lock();
        if ( != null && getOptions().keepConnection(this)) {
            return;
        }
        if ( == null) {
             = new DAVConnection(this);
        }
        .open(this);
    }
    private void closeConnection() {
        if (getOptions().keepConnection(this)) {
            unlock();
            return;
        }
        if ( != null) {
            .close();
             = null;
        }
        unlock();
    }
    
    public int getLocations(String pathlong pegRevisionlong[] revisionsISVNLocationEntryHandler handlerthrows SVNException {
        try {
            openConnection();
            if (path.startsWith("/")) {
                // (root + path), relative to location
                path = SVNPathUtil.append(getRepositoryRoot(true).getPath(), path);
                if (path.equals(getLocation().getPath())) {
                    path = "";
                } else {
                    path = path.substring(getLocation().getPath().length() + 1);
                }
            }
            StringBuffer request = DAVLocationsHandler.generateLocationsRequest(nullpathpegRevisionrevisions);
            
            DAVLocationsHandler davHandler = new DAVLocationsHandler(handler);
            String root = getLocation().getPath();
            root = SVNEncodingUtil.uriEncode(root);
            DAVBaselineInfo info = DAVUtil.getBaselineInfo(thisrootpegRevisionfalsefalsenull);            
            path = SVNPathUtil.append(info.baselineBaseinfo.baselinePath);
            HTTPStatus status = .doReport(pathrequestdavHandler);
            if (status.getCode() == 501) {
                SVNErrorMessage err = SVNErrorMessage.create(."'get-locations' REPORT not implemented");
                SVNErrorManager.error(errstatus.getError());
            } else if (status.getError() != null) {
                SVNErrorManager.error(status.getError());
            }
            return davHandler.getEntriesCount();
        } finally {
            closeConnection();
        }
    }
    public void replay(long lowRevisionlong highRevisionboolean sendDeltasISVNEditor editorthrows SVNException {
        try {
            openConnection();
            StringBuffer request = DAVReplayHandler.generateReplayRequest(highRevisionlowRevisionsendDeltas);
            DAVReplayHandler handler = new DAVReplayHandler(editortrue);
            String bcPath = SVNEncodingUtil.uriEncode(getLocation().getPath());
            try {
                bcPath = DAVUtil.getVCCPath(thisbcPath);
            } catch (SVNException e) {
                throw e;
            }
            HTTPStatus status = .doReport(bcPathrequesthandler);
            if (status.getCode() == 501) {
                SVNErrorMessage err = SVNErrorMessage.create(."'replay' REPORT not implemented");
                SVNErrorManager.error(errstatus.getError());
            } else if (status.getError() != null) {
                SVNErrorManager.error(status.getError());
            }
        } finally {
            closeConnection();
        }
    }
    public void update(long revisionString targetboolean recursiveISVNReporterBaton reporterISVNEditor editorthrows SVNException {
        try {
            openConnection();
            StringBuffer request = DAVEditorHandler.generateEditorRequest(nullgetLocation().toString(), revisiontargetnullrecursivefalsefalsetruereporter);
            DAVEditorHandler handler = new DAVEditorHandler(editortrue);
            String bcPath = SVNEncodingUtil.uriEncode(getLocation().getPath());
            try {
                bcPath = DAVUtil.getVCCPath(thisbcPath);
            } catch (SVNException e) {
                // no need to call close edit here, I suppose,
                // no editing has been started yet.
                throw e;
            }
        	HTTPStatus status = .doReport(bcPathrequesthandler);
            if (status.getError() != null) {
                SVNErrorManager.error(status.getError());
            }
        } finally {
            closeConnection();
        }
    }
    public void update(SVNURL urllong revisionString targetboolean recursiveISVNReporterBaton reporterISVNEditor editorthrows SVNException {
        if (url == null) {
            SVNErrorMessage err = SVNErrorMessage.create(."URL could not be NULL");
            SVNErrorManager.error(err);
        }
        try {
            openConnection();
            StringBuffer request = DAVEditorHandler.generateEditorRequest(nullgetLocation().toString(), revisiontargeturl.toString(), 
                    recursivetruefalsetruereporter);
            DAVEditorHandler handler = new DAVEditorHandler(editortrue);
            String bcPath = SVNEncodingUtil.uriEncode(getLocation().getPath());
            try {
                bcPath = DAVUtil.getVCCPath(thisbcPath);
            } catch (SVNException e) {
                editor.closeEdit();
                throw e;
            }
            HTTPStatus status = .doReport(bcPathrequesthandler);
            if (status.getError() != null) {
                SVNErrorManager.error(status.getError());
            }
        } finally {
            closeConnection();
        }
    }
    public void diff(SVNURL urllong revisionString targetboolean ignoreAncestryboolean recursiveISVNReporterBaton reporterISVNEditor editorthrows SVNException {
        diff(urlrevisionrevisiontargetignoreAncestryrecursivereportereditor);
    }
    
    public void diff(SVNURL urllong targetRevisionlong revisionString targetboolean ignoreAncestryboolean recursiveISVNReporterBaton reporterISVNEditor editorthrows SVNException {
        diff(urlrevisionrevisiontargetignoreAncestryrecursivetruereportereditor);
    }
    public void diff(SVNURL urllong targetRevisionlong revisionString targetboolean ignoreAncestryboolean recursiveboolean getContentsISVNReporterBaton reporterISVNEditor editorthrows SVNException {
        if (url == null) {
            SVNErrorMessage err = SVNErrorMessage.create(."URL could not be NULL");
            SVNErrorManager.error(err);
        }
        if (revision < 0) {
            revision = targetRevision;
        }
        try {
            openConnection();
            StringBuffer request = DAVEditorHandler.generateEditorRequest(nullgetLocation().toString(), targetRevisiontargeturl.toString(), recursiveignoreAncestryfalsegetContentsreporter);
            DAVEditorHandler handler = new DAVEditorHandler(editortrue);
            String path = SVNEncodingUtil.uriEncode(getLocation().getPath());
            path = DAVUtil.getVCCPath(thispath);
            HTTPStatus status = .doReport(pathrequesthandlertrue);
            if (status.getError() != null) {
                SVNErrorManager.error(status.getError());
            }
        } finally {
            closeConnection();
        }
    }
    public void status(long revisionString targetboolean recursiveISVNReporterBaton reporterISVNEditor editorthrows SVNException {
        try {
            openConnection();
            StringBuffer request = DAVEditorHandler.generateEditorRequest(nullgetLocation().toString(), revisiontargetnullrecursivefalsefalsefalsereporter);
            DAVEditorHandler handler = new DAVEditorHandler(editorfalse);
            String path = SVNEncodingUtil.uriEncode(getLocation().getPath());
            path = DAVUtil.getVCCPath(thispath);
            HTTPStatus status = .doReport(pathrequesthandler);
            if (status.getError() != null) {
                SVNErrorManager.error(status.getError());
            }
        } finally {
            closeConnection();
        }
    }
    public void setRevisionPropertyValue(long revisionString propertyNameString propertyValuethrows SVNException {
        assertValidRevision(revision);
        StringBuffer request = DAVProppatchHandler.generatePropertyRequest(nullpropertyNamepropertyValue);
        try {
            openConnection();
            // get baseline url and proppatch.
            DAVBaselineInfo info = DAVUtil.getBaselineInfo(this, SVNEncodingUtil.uriEncode(getLocation().getPath()), revisionfalsefalsenull);
            String path = SVNPathUtil.append(info.baselineBaseinfo.baselinePath);
            path = info.baseline;
            try {
                .doProppatch(nullpathrequestnullnull);
            } catch (SVNException e) {
                SVNErrorMessage err = SVNErrorMessage.create(."DAV request failed; it's possible that the repository's " +
                        "pre-rev-propchange hook either failed or is non-existent");
                SVNErrorManager.error(erre.getErrorMessage());                
            }
        } finally {
            closeConnection();
        }
    }
    public ISVNEditor getCommitEditor(String logMessageMap locksboolean keepLocksISVNWorkspaceMediator mediatorthrows SVNException {
        try {
            openConnection();
            Map translatedLocks = null;
            if (locks != null) {
                translatedLocks = new HashMap(locks.size());
                String root = getRepositoryRoot(true).getPath();
                root = SVNEncodingUtil.uriEncode(root);
                for (Iterator paths = locks.keySet().iterator(); paths.hasNext();) {
                    String path = (Stringpaths.next();
                    String lock = (Stringlocks.get(path);
    
                    if (path.startsWith("/")) {
                        path = SVNPathUtil.append(root, SVNEncodingUtil.uriEncode(path));
                    } else {
                        path = getFullPath(path);
                        path = SVNEncodingUtil.uriEncode(path);
                    }
                    translatedLocks.put(pathlock);
                }
            }
            .setLocks(translatedLockskeepLocks);
            return new DAVCommitEditor(thislogMessagemediatornew Runnable() {
                public void run() {
                    closeConnection();
                }
            });
        } catch (Throwable th) {
            closeConnection();
            if (th instanceof SVNException) {
                throw (SVNExceptionth;
            } 
            SVNErrorMessage err = SVNErrorMessage.create(."can not get commit editor: ''{0}''"th.getLocalizedMessage());
            SVNErrorManager.error(errth);
            return null;
        }
    }
    public SVNLock getLock(String paththrows SVNException {
        try {
            openConnection();
            path = getFullPath(path);
            path = SVNEncodingUtil.uriEncode(path);
            return .doGetLock(paththis);
        } finally {
            closeConnection();
        }
    }
    public SVNLock[] getLocks(String paththrows SVNException {
        try {
            openConnection();
            path = getFullPath(path);
            path = SVNEncodingUtil.uriEncode(path);
            return .doGetLocks(path);
        } finally {
            closeConnection();
        }
    }
    public void lock(Map pathsToRevisionsString commentboolean forceISVNLockHandler handlerthrows SVNException {
        try {
            openConnection();
            for(Iterator paths = pathsToRevisions.keySet().iterator(); paths.hasNext();) {
                String path = (Stringpaths.next();
                Long revision = (LongpathsToRevisions.get(path);
                String repositoryPath = getRepositoryPath(path);
                path = getFullPath(path);
                path = SVNEncodingUtil.uriEncode(path);
                SVNLock lock = null;
                SVNErrorMessage error = null;
                long revisionNumber = revision != null ? revision.longValue() : -1;
                try {
                     lock = .doLock(paththiscommentforcerevisionNumber);
                } catch (SVNException e) {
                    error = null;
                    if (e.getErrorMessage() != null) {
                        SVNErrorCode code = e.getErrorMessage().getErrorCode();
                        if (code == . || code == .) {
                            error = e.getErrorMessage();                            
                        }
                    }
                    if (error == null) {
                        throw e;
                    }
                }
                if (handler != null) {
                    handler.handleLock(repositoryPathlockerror);
                }
            }
        } finally {
            closeConnection();
        }
    }
    public void unlock(Map pathToTokensboolean forceISVNLockHandler handlerthrows SVNException {
        try {
            openConnection();
            for (Iterator paths = pathToTokens.keySet().iterator(); paths.hasNext();) {
                String path = (Stringpaths.next();
                String shortPath = path;
                String id = (StringpathToTokens.get(path);
                String repositoryPath = getRepositoryPath(path);
                path = getFullPath(path);
                path = SVNEncodingUtil.uriEncode(path);
                SVNErrorMessage error = null;
                try {
                    .doUnlock(paththisidforce);
                    error = null;
                } catch (SVNException e) {
                    if (e.getErrorMessage() != null && e.getErrorMessage().getErrorCode() == .) {
                        error = e.getErrorMessage();
                        error = SVNErrorMessage.create(error.getErrorCode(), error.getMessageTemplate(), shortPath);
                    } else {
                        throw e;
                    }
                }
                if (handler != null) {
                    handler.handleUnlock(repositoryPathnew SVNLock(pathidnullnullnullnull), error);
                }
            }
        } finally {
            closeConnection();
        }
    }
    public SVNDirEntry info(String pathlong revisionthrows SVNException {
        try {
            openConnection();
            path = getFullPath(path);
            path = SVNEncodingUtil.uriEncode(path);
            final String fullPath = path;
            if (revision >= 0) {
                try {
                    DAVBaselineInfo info = DAVUtil.getBaselineInfo(thispathrevisionfalsetruenull);
                    path = SVNPathUtil.append(info.baselineBaseinfo.baselinePath);
                } catch (SVNException e) {
                    if (e.getErrorMessage() != null && e.getErrorMessage().getErrorCode() == .) {
                        return null;
                    }
                    throw e;
                }
            }
            DAVElement[] elements = null;
            Map propsMap = new HashMap();
            HTTPStatus status = DAVUtil.getProperties(path, 0, nullelementspropsMap);
            if (status.getError() != null) {
                if (status.getError().getErrorCode() == .) {
                    return null;
                }
                SVNErrorManager.error(status.getError());
            }
            if (!propsMap.isEmpty()) {
                DAVProperties props = (DAVPropertiespropsMap.values().iterator().next();
                return createDirEntry(fullPathprops);
            }
        } finally {
            closeConnection();
        }
        return null;
    }
    public void closeSession() throws SVNException {
        if ( != null) {
            .close();
             = null;
        }
    }
    
    private SVNDirEntry createDirEntry(String fullPathDAVProperties childthrows SVNException {
        String href = child.getURL();
        href = SVNEncodingUtil.uriDecode(href);
        String name = SVNPathUtil.tail(href);
        // build direntry
        SVNNodeKind kind = .;
        Object revisionStr = child.getPropertyValue(.);
        long lastRevision = Long.parseLong(revisionStr.toString());
        String sizeStr = child.getPropertyValue(.);
        long size = sizeStr == null ? 0 : Long.parseLong(sizeStr);
        if (child.isCollection()) {
            kind = .;
        }
        String author = child.getPropertyValue(.);
        String dateStr = child.getPropertyValue(.);
        Date date = dateStr != null ? SVNTimeUtil.parseDate(dateStr) : null;
        boolean hasProperties = false;
        for(Iterator props = child.getProperties().keySet().iterator(); props.hasNext();) {
            DAVElement property = (DAVElementprops.