01: /*
02: * ====================================================================
03: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
04: *
05: * This software is licensed as described in the file COPYING, which
06: * you should have received as part of this distribution. The terms
07: * are also available at http://svnkit.com/license.html
08: * If newer versions of this license are posted there, you may use a
09: * newer version instead, at your option.
10: * ====================================================================
11: */
12:
13: package org.tmatesoft.svn.cli.command;
14:
15: import org.tmatesoft.svn.cli.SVNArgument;
16: import org.tmatesoft.svn.cli.SVNCommand;
17: import org.tmatesoft.svn.core.SVNException;
18: import org.tmatesoft.svn.core.SVNURL;
19: import org.tmatesoft.svn.core.wc.SVNRevision;
20: import org.tmatesoft.svn.core.wc.SVNWCClient;
21:
22: import java.io.File;
23: import java.io.InputStream;
24: import java.io.PrintStream;
25:
26: /**
27: * @version 1.1.1
28: * @author TMate Software Ltd.
29: */
30: public class SVNCatCommand extends SVNCommand {
31:
32: public void run(InputStream in, PrintStream out, PrintStream err)
33: throws SVNException {
34: run(out, err);
35: }
36:
37: public void run(PrintStream out, PrintStream err)
38: throws SVNException {
39: SVNWCClient wcClient = getClientManager().getWCClient();
40: SVNRevision revision = SVNRevision.BASE;
41:
42: if (getCommandLine().hasArgument(SVNArgument.REVISION)) {
43: revision = SVNRevision.parse((String) getCommandLine()
44: .getArgumentValue(SVNArgument.REVISION));
45: }
46: for (int index = 0; index < getCommandLine().getPathCount(); index++) {
47: final String absolutePath = getCommandLine().getPathAt(
48: index);
49: SVNRevision pegRevision = getCommandLine()
50: .getPathPegRevision(index);
51: try {
52: wcClient.doGetFileContents(new File(absolutePath),
53: pegRevision, revision, true, out);
54: } catch (SVNException e) {
55: String message = e.getMessage();
56: err.println(message);
57: }
58: out.flush();
59: }
60:
61: revision = SVNRevision.HEAD;
62: if (getCommandLine().hasArgument(SVNArgument.REVISION)) {
63: revision = SVNRevision.parse((String) getCommandLine()
64: .getArgumentValue(SVNArgument.REVISION));
65: }
66: for (int index = 0; index < getCommandLine().getURLCount(); index++) {
67: final String url = getCommandLine().getURL(index);
68: SVNRevision pegRevision = getCommandLine().getPegRevision(
69: index);
70: try {
71: wcClient.doGetFileContents(SVNURL.parseURIEncoded(url),
72: pegRevision, revision, true, out);
73: } catch (SVNException e) {
74: String message = e.getMessage();
75: err.println(message);
76: }
77: out.flush();
78: }
79: }
80: }
|