001: /*
002: * ====================================================================
003: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
004: *
005: * This software is licensed as described in the file COPYING, which
006: * you should have received as part of this distribution. The terms
007: * are also available at http://svnkit.com/license.html
008: * If newer versions of this license are posted there, you may use a
009: * newer version instead, at your option.
010: * ====================================================================
011: */
012: package org.tmatesoft.svn.core.internal.wc;
013:
014: import java.util.HashMap;
015: import java.util.Map;
016:
017: import org.tmatesoft.svn.core.SVNErrorCode;
018: import org.tmatesoft.svn.core.SVNException;
019: import org.tmatesoft.svn.core.SVNLock;
020: import org.tmatesoft.svn.core.SVNURL;
021: import org.tmatesoft.svn.core.internal.util.SVNPathUtil;
022: import org.tmatesoft.svn.core.io.ISVNReporter;
023: import org.tmatesoft.svn.core.io.ISVNReporterBaton;
024: import org.tmatesoft.svn.core.io.SVNRepository;
025:
026: /**
027: * @version 1.1.1
028: * @author TMate Software Ltd.
029: */
030: public class SVNStatusReporter implements ISVNReporterBaton,
031: ISVNReporter {
032:
033: private ISVNReporter myReporter;
034: private ISVNReporterBaton myBaton;
035: private String myRepositoryLocation;
036: private SVNRepository myRepository;
037: private SVNURL myRepositoryRoot;
038: private Map myLocks;
039:
040: private SVNStatusEditor myEditor;
041:
042: public SVNStatusReporter(SVNRepository repos,
043: ISVNReporterBaton baton, SVNStatusEditor editor) {
044: myBaton = baton;
045: myRepository = repos;
046: myRepositoryLocation = repos.getLocation().toString();
047: myEditor = editor;
048: myLocks = new HashMap();
049: }
050:
051: public SVNLock getLock(SVNURL url) {
052: // get decoded path
053: if (myRepositoryRoot == null || myLocks.isEmpty()
054: || url == null) {
055: return null;
056: }
057: String urlString = url.getPath();
058: String root = myRepositoryRoot.getPath();
059: String path;
060: if (urlString.equals(root)) {
061: path = "/";
062: } else {
063: path = urlString.substring(root.length());
064: }
065: return (SVNLock) myLocks.get(path);
066: }
067:
068: public void report(ISVNReporter reporter) throws SVNException {
069: myReporter = reporter;
070: myBaton.report(this );
071: }
072:
073: public void setPath(String path, String lockToken, long revision,
074: boolean startEmpty) throws SVNException {
075: myReporter.setPath(path, lockToken, revision, startEmpty);
076: }
077:
078: public void deletePath(String path) throws SVNException {
079: myReporter.deletePath(path);
080: }
081:
082: public void linkPath(SVNURL url, String path, String lockToken,
083: long revison, boolean startEmpty) throws SVNException {
084: String rootURL = SVNPathUtil.getCommonURLAncestor(url
085: .toString(), myRepositoryLocation);
086: if (rootURL.length() < myRepositoryLocation.length()) {
087: myRepositoryLocation = rootURL;
088: }
089: myReporter.linkPath(url, path, lockToken, revison, startEmpty);
090: }
091:
092: public void finishReport() throws SVNException {
093: // collect locks
094: SVNLock[] locks = null;
095: try {
096: myRepositoryRoot = myRepository.getRepositoryRoot(true);
097: locks = myRepository.getLocks("");
098: } catch (SVNException e) {
099: if (!(e.getErrorMessage() != null && e.getErrorMessage()
100: .getErrorCode() == SVNErrorCode.RA_NOT_IMPLEMENTED)) {
101: throw e;
102: }
103: } finally {
104: myRepository.closeSession();
105: }
106: if (locks != null) {
107: for (int i = 0; i < locks.length; i++) {
108: SVNLock lock = locks[i];
109: myLocks.put(lock.getPath(), lock);
110: }
111: }
112: myEditor.setRepositoryInfo(myRepositoryRoot, myLocks);
113: myReporter.finishReport();
114: }
115:
116: public void abortReport() throws SVNException {
117: myReporter.abortReport();
118: }
119: }
|