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:
013: package org.tmatesoft.svn.cli.command;
014:
015: import java.io.File;
016: import java.io.InputStream;
017: import java.io.PrintStream;
018:
019: import org.tmatesoft.svn.cli.SVNArgument;
020: import org.tmatesoft.svn.cli.SVNCommand;
021: import org.tmatesoft.svn.core.SVNException;
022: import org.tmatesoft.svn.core.SVNURL;
023: import org.tmatesoft.svn.core.internal.util.SVNFormatUtil;
024: import org.tmatesoft.svn.core.wc.ISVNPropertyHandler;
025: import org.tmatesoft.svn.core.wc.SVNPropertyData;
026: import org.tmatesoft.svn.core.wc.SVNRevision;
027: import org.tmatesoft.svn.core.wc.SVNWCClient;
028:
029: /**
030: * @version 1.1.1
031: * @author TMate Software Ltd.
032: */
033: public class SVNProplistCommand extends SVNCommand implements
034: ISVNPropertyHandler {
035:
036: private boolean myIsVerbose;
037: private boolean myIsRecursive;
038: private PrintStream myOut;
039: private boolean myIsRevProp;
040:
041: public void run(InputStream in, PrintStream out, PrintStream err)
042: throws SVNException {
043: run(out, err);
044: }
045:
046: public final void run(final PrintStream out, PrintStream err)
047: throws SVNException {
048: myIsRecursive = getCommandLine().hasArgument(
049: SVNArgument.RECURSIVE);
050: myIsRevProp = getCommandLine()
051: .hasArgument(SVNArgument.REV_PROP);
052: myIsVerbose = getCommandLine().hasArgument(SVNArgument.VERBOSE);
053: myOut = out;
054: myIsRecursive = myIsRecursive & !myIsRevProp;
055: SVNRevision revision = SVNRevision.UNDEFINED;
056: if (getCommandLine().hasArgument(SVNArgument.REVISION)) {
057: revision = SVNRevision.parse((String) getCommandLine()
058: .getArgumentValue(SVNArgument.REVISION));
059: }
060: SVNWCClient wcClient = getClientManager().getWCClient();
061: if (getCommandLine().hasURLs()) {
062: String url = getCommandLine().getURL(0);
063: if (myIsRevProp) {
064: wcClient.doGetRevisionProperty(SVNURL
065: .parseURIEncoded(url), null, revision, this );
066: } else {
067: SVNRevision pegRevision = getCommandLine()
068: .getPegRevision(0);
069: wcClient.doGetProperty(SVNURL.parseURIEncoded(url),
070: null, pegRevision, revision, myIsRecursive,
071: this );
072: }
073: } else if (getCommandLine().getPathCount() > 0) {
074: String path = getCommandLine().getPathAt(0);
075: SVNRevision pegRevision = getCommandLine()
076: .getPathPegRevision(0);
077: if (myIsRevProp) {
078: wcClient.doGetRevisionProperty(new File(path), null,
079: revision, this );
080: } else {
081: wcClient.doGetProperty(new File(path), null,
082: pegRevision, revision, myIsRecursive, this );
083: }
084: }
085: }
086:
087: private File myCurrentFile;
088: private SVNURL myCurrentURL;
089: private long myCurrentRev = -1;
090:
091: public void handleProperty(File path, SVNPropertyData property)
092: throws SVNException {
093: if (!path.equals(myCurrentFile)) {
094: myOut.println("Properties on '"
095: + SVNFormatUtil.formatPath(path) + "':");
096: myCurrentFile = path;
097: }
098: myOut.print(" ");
099: myOut.print(property.getName());
100: if (myIsVerbose) {
101: myOut.print(" : " + property.getValue());
102: }
103: myOut.println();
104: }
105:
106: public void handleProperty(SVNURL url, SVNPropertyData property)
107: throws SVNException {
108: if (!url.equals(myCurrentURL)) {
109: myOut.println("Properties on '" + url + "':");
110: myCurrentURL = url;
111: }
112: myOut.print(" ");
113: myOut.print(property.getName());
114: if (myIsVerbose) {
115: myOut.print(" : " + property.getValue());
116: }
117: myOut.println();
118: }
119:
120: public void handleProperty(long revision, SVNPropertyData property)
121: throws SVNException {
122: if (myCurrentRev < 0) {
123: myCurrentRev = revision;
124: myOut.println("Unversioned properties on revision "
125: + revision + ":");
126: }
127: myOut.print(" ");
128: myOut.print(property.getName());
129: if (myIsVerbose) {
130: myOut.print(" : " + property.getValue());
131: }
132: myOut.println();
133: }
134: }
|