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 SVNPropgetCommand extends SVNCommand implements
034: ISVNPropertyHandler {
035:
036: private boolean myIsStrict;
037: private boolean myIsRecursive;
038: private PrintStream myOut;
039:
040: public void run(InputStream in, PrintStream out, PrintStream err)
041: throws SVNException {
042: run(out, err);
043: }
044:
045: public final void run(final PrintStream out, PrintStream err)
046: throws SVNException {
047: String propertyName = getCommandLine().getPathAt(0);
048: myIsRecursive = getCommandLine().hasArgument(
049: SVNArgument.RECURSIVE);
050: boolean revProp = getCommandLine().hasArgument(
051: SVNArgument.REV_PROP);
052: myIsStrict = getCommandLine().hasArgument(SVNArgument.STRICT);
053: myOut = out;
054: myIsRecursive = myIsRecursive & !revProp;
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 (revProp) {
064: wcClient.doGetRevisionProperty(SVNURL
065: .parseURIEncoded(url), propertyName, revision,
066: this );
067: } else {
068: SVNRevision pegRevision = getCommandLine()
069: .getPegRevision(0);
070: wcClient.doGetProperty(SVNURL.parseURIEncoded(url),
071: propertyName, pegRevision, revision,
072: myIsRecursive, this );
073: }
074: } else if (getCommandLine().getPathCount() > 1) {
075: String path = getCommandLine().getPathAt(1);
076: SVNRevision pegRevision = getCommandLine()
077: .getPathPegRevision(1);
078: if (revProp) {
079: wcClient.doGetRevisionProperty(new File(path),
080: propertyName, revision, this );
081: } else {
082: wcClient.doGetProperty(new File(path), propertyName,
083: pegRevision, revision, myIsRecursive, this );
084: }
085: }
086: }
087:
088: public void handleProperty(File path, SVNPropertyData property)
089: throws SVNException {
090: if (!myIsStrict && myIsRecursive) {
091: myOut.print(SVNFormatUtil.formatPath(path) + " - ");
092: }
093: myOut.print(property.getValue());
094: if (!myIsStrict) {
095: myOut.println();
096: }
097: }
098:
099: public void handleProperty(SVNURL url, SVNPropertyData property)
100: throws SVNException {
101: if (!myIsStrict && myIsRecursive) {
102: myOut.print(url + " - ");
103: }
104: myOut.print(property.getValue());
105: if (!myIsStrict) {
106: myOut.println();
107: }
108: }
109:
110: public void handleProperty(long revision, SVNPropertyData property)
111: throws SVNException {
112: myOut.print(property.getValue());
113: if (!myIsStrict) {
114: myOut.println();
115: }
116: }
117:
118: }
|