001: // CvsDirectoryHandler.java
002: // $Id: CvsDirectoryHandler.java,v 1.5 2000/08/16 21:37:31 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1996.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: //
007: // FIXME add extra environment parameter to all public methods
008: // witch run cvs.
009: //
010:
011: package org.w3c.jigedit.cvs;
012:
013: import org.w3c.cvs.CvsDirectory;
014: import org.w3c.cvs.CvsException;
015:
016: import org.w3c.www.http.HTTP;
017: import org.w3c.www.http.HttpMessage;
018:
019: import org.w3c.jigsaw.http.HTTPException;
020: import org.w3c.jigsaw.http.Reply;
021: import org.w3c.jigsaw.http.Request;
022:
023: import org.w3c.jigsaw.auth.AuthFilter;
024:
025: import org.w3c.tools.resources.ProtocolException;
026:
027: import org.w3c.jigsaw.html.HtmlGenerator;
028:
029: public class CvsDirectoryHandler implements CvsHandlerInterface {
030: private static final boolean debug = false;
031:
032: CvsDirectory cvs = null;
033:
034: protected Reply badAction(Request request, String action) {
035: Reply error = request.makeReply(HTTP.BAD_REQUEST);
036: HtmlGenerator g = CvsFrame.getHtmlGenerator("Bad CVS command");
037: g.append("<center>");
038: g
039: .append("[ <A HREF=\"./CVS\">Back</A> ]<hr noshade width=\"80%\">");
040: g.append("<p>Your command " + "<strong>" + action + "</strong>"
041: + " wasn't undesrtood.<p>");
042: g.append("<hr noshade width=\"80%\"></center>");
043: error.setStream(g);
044: return error;
045: }
046:
047: /**
048: * Perform the action on the entity matching the given regexp
049: * @param request The request that triggered this method call.
050: * @param action The action to perform.
051: * @param regexp The regular expression to match
052: * @param comment A string of comments describing the change.
053: * @exception ProtocolException If running the action failed.
054: */
055: public void perform(Request request, String action, String regexp,
056: String comment) throws ProtocolException {
057: try {
058: String u = (String) request
059: .getState(AuthFilter.STATE_AUTHUSER);
060: String env[] = { "USER=" + u, "LOGNAME=" + u };
061: if (action.equals("add")) {
062: cvs.addRegexp(regexp, env);
063: } else if (action.equals("update")) {
064: cvs.updateRegexp(regexp);
065: } else if (action.equals("commit")) {
066: String jcomment = null;
067: if (comment != null) {
068: jcomment = ((u != null) ? "(" + u + ") " + comment
069: : comment);
070: } else {
071: jcomment = ((u != null) ? "(" + u
072: + ") changed through Jigsaw, no comments"
073: : "changed through Jigsaw, no comments");
074: }
075: cvs.commitRegexp(regexp, jcomment, env);
076: } else if (action.equals("addcom")) {
077: cvs.addRegexp(regexp, env);
078: String jcomment = null;
079: if (comment != null) {
080: jcomment = ((u != null) ? "(" + u + ") " + comment
081: : comment);
082: } else {
083: jcomment = ((u != null) ? "(" + u
084: + ") changed through Jigsaw, no comments"
085: : "changed through Jigsaw, no comments");
086: }
087: cvs.commitRegexp(regexp, jcomment, env);
088: } else {
089: throw new HTTPException(badAction(request, action));
090: }
091: } catch (CvsException ex) {
092: String msg = action + " in " + cvs.getDirectory()
093: + " failed";
094: throw new HTTPException(CvsFrame.error(request, msg, ex));
095: }
096: }
097:
098: /**
099: * Perform the action on the entity matching the given regexp
100: * @param request The request that triggered this method call.
101: * @param action The action to perform.
102: * @param regexp The regular expression to match
103: * @exception ProtocolException If running the action failed.
104: */
105: public void perform(Request request, String action, String regexp)
106: throws ProtocolException {
107: perform(request, action, regexp, null);
108: }
109:
110: /**
111: * Perform the action on the given entity.
112: * @param request The request that triggered this method call.
113: * @param action The action to perform.
114: * @param names Name of files to apply the action to.
115: * @exception ProtocolException If running the action failed.
116: */
117:
118: public void perform(Request request, String action, String names[],
119: String revs[]) throws ProtocolException {
120: perform(request, action, names, revs, null);
121: }
122:
123: /**
124: * Perform the action on the given entity.
125: * @param action The action to perform.
126: * @param names The names on which the action should be performed.
127: * @param comment A string of comments describing the change.
128: * @exception ProtocolException If running the action failed.
129: */
130:
131: public void perform(Request request, String action, String names[],
132: String revs[], String comment) throws ProtocolException {
133: String u = (String) request.getState(AuthFilter.STATE_AUTHUSER);
134: String env[] = { "USER=" + u, "LOGNAME=" + u };
135: String jcomment = null;
136: if (comment != null) {
137: jcomment = ((u != null) ? "(" + u + ") " + comment
138: : comment);
139: } else {
140: jcomment = ((u != null) ? "(" + u
141: + ") changed through Jigsaw, no comments"
142: : "changed through Jigsaw, no comments");
143: }
144:
145: if (debug)
146: for (int i = 0; i < names.length; i++)
147: System.out.println("*** perform " + action + " on "
148: + names[i]);
149: try {
150: if (action.equals("add")) {
151: cvs.add(names, env);
152: } else if (action.equals("revert")) {
153: String msg = ((u != null) ? "(" + u + ") " + comment
154: : comment);
155: for (int i = 0; i < names.length; i++)
156: cvs.revert(names[i], revs[i], msg, env);
157: } else if (action.equals("remove")) {
158: cvs.remove(names, jcomment, env);
159: } else if (action.equals("update")) {
160: cvs.update(names);
161: } else if (action.equals("commit")) {
162: cvs.commit(names, jcomment, env);
163: } else if (action.equals("addcom")) {
164: cvs.add(names, env);
165: cvs.commit(names, jcomment, env);
166: } else {
167: throw new HTTPException(badAction(request, action));
168: }
169: } catch (CvsException ex) {
170: String msg = action + " in " + cvs.getDirectory()
171: + " failed";
172: throw new HTTPException(CvsFrame.error(request, msg, ex));
173: }
174: }
175:
176: CvsDirectoryHandler(CvsDirectory cvs) {
177: super();
178: this.cvs = cvs;
179: }
180:
181: }
|