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.cli.command;
013:
014: import java.io.File;
015: import java.io.InputStream;
016: import java.io.PrintStream;
017: import java.util.Iterator;
018: import java.util.Map;
019:
020: import org.tmatesoft.svn.cli.SVNArgument;
021: import org.tmatesoft.svn.cli.SVNCommand;
022: import org.tmatesoft.svn.core.SVNException;
023: import org.tmatesoft.svn.core.internal.util.SVNPathUtil;
024: import org.tmatesoft.svn.core.wc.SVNRevision;
025: import org.tmatesoft.svn.core.wc.admin.SVNLookClient;
026:
027: /**
028: * @version 1.1.1
029: * @author TMate Software Ltd.
030: * @since 1.1.1
031: */
032: public class SVNLookProplistCommand extends SVNCommand {
033:
034: public void run(PrintStream out, PrintStream err)
035: throws SVNException {
036: if (!getCommandLine().hasPaths()) {
037: SVNCommand.println(err,
038: "jsvnlook: Repository argument required");
039: System.exit(1);
040: }
041:
042: boolean isRevProp = getCommandLine().hasArgument(
043: SVNArgument.REV_PROP);
044: boolean isVerbose = getCommandLine().hasArgument(
045: SVNArgument.VERBOSE);
046: File reposRoot = new File(getCommandLine().getPathAt(0));
047: SVNRevision revision = SVNRevision.HEAD;
048: SVNLookClient lookClient = getClientManager().getLookClient();
049:
050: if (getCommandLine().hasArgument(SVNArgument.TRANSACTION)) {
051: String transactionName = (String) getCommandLine()
052: .getArgumentValue(SVNArgument.TRANSACTION);
053: Map props = null;
054: if (isRevProp) {
055: props = lookClient.doGetRevisionProperties(reposRoot,
056: transactionName);
057: } else {
058: String path = getCommandLine().getPathCount() < 2 ? null
059: : SVNPathUtil
060: .canonicalizeAbsPath(getCommandLine()
061: .getPathAt(2));
062: props = lookClient.doGetProperties(reposRoot, path,
063: transactionName);
064: }
065: printProps(out, props, isVerbose);
066: return;
067: } else if (getCommandLine().hasArgument(SVNArgument.REVISION)) {
068: revision = SVNRevision.parse((String) getCommandLine()
069: .getArgumentValue(SVNArgument.REVISION));
070: }
071:
072: Map props = null;
073: if (isRevProp) {
074: props = lookClient.doGetRevisionProperties(reposRoot,
075: revision);
076: } else {
077: String path = getCommandLine().getPathCount() < 2 ? null
078: : SVNPathUtil.canonicalizeAbsPath(getCommandLine()
079: .getPathAt(2));
080: props = lookClient.doGetProperties(reposRoot, path,
081: revision);
082: }
083: printProps(out, props, isVerbose);
084: }
085:
086: public void run(InputStream in, PrintStream out, PrintStream err)
087: throws SVNException {
088: run(out, err);
089: }
090:
091: public void printProps(PrintStream out, Map props, boolean isVerbose) {
092: if (props != null) {
093: for (Iterator propNames = props.keySet().iterator(); propNames
094: .hasNext();) {
095: String propName = (String) propNames.next();
096: if (isVerbose) {
097: String propVal = (String) props.get(propName);
098: SVNCommand.println(out, " " + propName + " : "
099: + propVal);
100: } else {
101: SVNCommand.println(out, " " + propName);
102: }
103: }
104: }
105: }
106:
107: }
|