Subversion Repositories XServices

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 109
Line 1... Line 1...
1
package net.brutex.xservices.ws.rs;
1
package net.brutex.xservices.ws.rs;
Line -... Line 2...
-
 
2
 
2
 
3
import java.io.ByteArrayOutputStream;
-
 
4
import java.io.File;
-
 
5
import java.io.FileReader;
3
import java.io.File;
6
import java.io.IOException;
-
 
7
import java.io.PrintStream;
4
import java.util.ArrayList;
8
import java.net.URI;
5
import java.util.List;
9
import java.util.List;
6
import java.util.StringTokenizer;
-
 
7
 
-
 
8
import javax.ws.rs.core.GenericEntity;
10
import java.util.StringTokenizer;
9
import javax.ws.rs.core.HttpHeaders;
11
import javax.ws.rs.core.HttpHeaders;
-
 
12
import javax.ws.rs.core.Response;
-
 
13
import javax.ws.rs.core.Response.ResponseBuilder;
-
 
14
import net.brutex.xservices.types.scm.AttributeType;
-
 
15
import net.brutex.xservices.types.scm.ItemListType;
-
 
16
import net.brutex.xservices.types.scm.ItemType;
-
 
17
import net.brutex.xservices.types.scm.ModuleListType;
10
import javax.ws.rs.core.Response;
-
 
-
 
18
import net.brutex.xservices.types.scm.ModuleType;
-
 
19
import net.brutex.xservices.types.scm.ObjectFactory;
-
 
20
import net.brutex.xservices.types.scm.RevisionType;
-
 
21
import net.brutex.xservices.types.scm.TagListType;
-
 
22
import net.brutex.xservices.types.scmfindings.FindingsListType;
-
 
23
import net.brutex.xservices.util.BasicCVSListener;
-
 
24
import net.brutex.xservices.util.CVSClient;
11
 
25
import net.brutex.xservices.util.CVSRoot;
12
import org.apache.commons.configuration.ConfigurationException;
26
import org.apache.commons.configuration.ConfigurationException;
13
import org.apache.jcs.JCS;
27
import org.apache.jcs.JCS;
14
import org.apache.jcs.access.exception.CacheException;
28
import org.apache.jcs.access.exception.CacheException;
15
import org.apache.log4j.Logger;
29
import org.apache.log4j.Logger;
16
import org.netbeans.lib.cvsclient.Client;
30
import org.netbeans.lib.cvsclient.Client;
17
import org.netbeans.lib.cvsclient.command.CommandAbortedException;
31
import org.netbeans.lib.cvsclient.command.CommandAbortedException;
-
 
32
import org.netbeans.lib.cvsclient.command.CommandException;
-
 
33
import org.netbeans.lib.cvsclient.command.FileInfoContainer;
18
import org.netbeans.lib.cvsclient.command.CommandException;
34
import org.netbeans.lib.cvsclient.command.PipedFileInformation;
19
import org.netbeans.lib.cvsclient.command.checkout.CheckoutCommand;
35
import org.netbeans.lib.cvsclient.command.checkout.CheckoutCommand;
20
import org.netbeans.lib.cvsclient.command.checkout.ModuleListInformation;
36
import org.netbeans.lib.cvsclient.command.checkout.ModuleListInformation;
-
 
37
import org.netbeans.lib.cvsclient.command.log.LogInformation;
21
import org.netbeans.lib.cvsclient.command.log.LogInformation;
38
import org.netbeans.lib.cvsclient.command.log.LogInformation.Revision;
22
import org.netbeans.lib.cvsclient.command.log.RlogCommand;
39
import org.netbeans.lib.cvsclient.command.log.RlogCommand;
-
 
40
import org.netbeans.lib.cvsclient.connection.AuthenticationException;
23
import org.netbeans.lib.cvsclient.connection.AuthenticationException;
41
import org.netbeans.lib.cvsclient.event.EventManager;
Line 24... Line -...
24
import org.netbeans.lib.cvsclient.event.FileInfoEvent;
-
 
25
 
-
 
26
import net.brutex.xservices.types.scm.ModuleType;
-
 
27
import net.brutex.xservices.types.scm.FileType;
-
 
28
import net.brutex.xservices.types.scm.Revision;
-
 
29
import net.brutex.xservices.util.BasicCVSListener;
-
 
30
import net.brutex.xservices.util.CVSClient;
-
 
31
 
-
 
32
/**
-
 
33
 * @author Brian Rosenberger
-
 
34
 * @since 0.5.0-20120824
-
 
35
 * 
42
import org.netbeans.lib.cvsclient.event.FileInfoEvent;
36
 */
-
 
37
public class CVSInfoImpl implements CVSInfo {
43
 
-
 
44
public class CVSInfoImpl implements CVSInfo {
-
 
45
	final Logger logger = Logger.getLogger(CVSInfoImpl.class);
Line 38... Line 46...
38
	
46
	final ObjectFactory FACTORY = new ObjectFactory();
39
	final Logger logger = Logger.getLogger(CVSInfoImpl.class);
-
 
40
 
-
 
41
	public Response getRepositoryFiles(HttpHeaders h, File f, String modules,
-
 
42
			boolean showRevisions,
47
	final ItemListType list = this.FACTORY.createItemListType();
43
			boolean forceNoCache) {
-
 
44
 
48
 
45
		final List<FileType> list = new ArrayList<FileType>();
49
	public Response getRepositoryFiles(HttpHeaders h, File f, String modules,
46
 
50
			boolean isRecursive, boolean showRevisions, boolean forceNoCache) {
47
		String cachekey = "getFiles" + f.toURI().toString();
51
		String cachekey = "getFiles" + f.toURI().toString();
Line 48... Line 52...
48
		logger.debug("forceNoCache="+forceNoCache);
52
		this.logger.debug("forceNoCache=" + forceNoCache);
49
		List<FileType> cacheresult = (List<FileType>) getCacheInstance().get(
-
 
50
				cachekey);
53
		ItemListType cacheresult = (ItemListType) getCacheInstance().get(
51
 
54
				cachekey);
52
		if (!forceNoCache && cacheresult != null) {
55
 
53
			// Cache hit
56
		if ((!forceNoCache) && (cacheresult != null)) {
54
			list.addAll(cacheresult);
57
			return Response.ok(cacheresult).build();
55
		} else {
58
		}
56
			// Cache miss
59
		Client client;
57
			try {
60
		try {
58
				CVSClient cvsclient = new CVSClient(f);
-
 
59
				Client client = cvsclient.client;
61
			final CVSClient cvsclient = new CVSClient(f);
60
 
62
			client = cvsclient.client;
61
				client.getEventManager().addCVSListener(new BasicCVSListener() {
63
 
-
 
64
			client.getEventManager().addCVSListener(new BasicCVSListener() {
-
 
65
				public void fileInfoGenerated(FileInfoEvent arg0) {
62
					@Override
66
					LogInformation info = (LogInformation) arg0
-
 
67
							.getInfoContainer();
-
 
68
					String repoPath = cvsclient.client.getRepository();
-
 
69
 
-
 
70
					ItemType cvsfile = CVSInfoImpl.this.FACTORY
-
 
71
							.createItemType();
-
 
72
					cvsfile.setIsLeaf(true);
63
					public void fileInfoGenerated(FileInfoEvent arg0) {
73
					cvsfile.setIsBinary(false);
-
 
74
 
-
 
75
					cvsfile.setFullname(info.getRepositoryFilename().substring(
-
 
76
							repoPath.length() + 2,
-
 
77
							info.getRepositoryFilename().length() - 2));
-
 
78
 
64
						LogInformation info = (LogInformation) arg0
79
					cvsfile.setRemotename(info.getRepositoryFilename());
65
								.getInfoContainer();
80
					cvsfile.setRemotefullname(info.getRepositoryFilename());
66
						FileType cvsfile = new FileType(info.getFile(), info
81
					RevisionType revision = CVSInfoImpl.this.FACTORY
-
 
82
							.createRevisionType();
67
								.getRepositoryFilename(), info.getDescription());
83
					revision.setRevision(info.getHeadRevision());
-
 
84
					revision.setComment(info.getDescription());
-
 
85
					cvsfile.setTipRevision(revision);
68
						cvsfile.setHeadRevision(info.getHeadRevision());
86
 
69
						cvsfile.setBranch(info.getBranch());
87
					for (LogInformation.Revision r : info.getRevisionList()) {
70
						cvsfile.setTotalRevisions(info.getTotalRevisions());
-
 
71
						for (LogInformation.Revision r : info.getRevisionList()) {
88
						revision = CVSInfoImpl.this.FACTORY
72
							cvsfile.addRevision(new Revision(r.getNumber(), r
89
								.createRevisionType();
73
									.getMessage()));
-
 
Line -... Line 90...
-
 
90
						revision.setRevision(r.getNumber());
-
 
91
						revision.setComment(r.getMessage());
74
						}
92
						cvsfile.getRevisions().add(revision);
-
 
93
					}
75
						list.add(cvsfile);
94
 
-
 
95
					cvsfile.getAttributes().add(
-
 
96
							CVSInfoImpl.this.getAttribute("TOTALREVISIONS",
-
 
97
									info.getTotalRevisions()));
-
 
98
					cvsfile.getAttributes().add(
-
 
99
							CVSInfoImpl.this.getAttribute("BRANCH",
-
 
100
									info.getBranch()));
-
 
101
					cvsfile.getAttributes().add(
76
					}
102
							CVSInfoImpl.this.getAttribute(
-
 
103
									"KEYWORDSUBSTITUTION",
-
 
104
									info.getKeywordSubstitution()));
77
				});
105
					cvsfile.getAttributes().add(
-
 
106
							CVSInfoImpl.this.getAttribute("LOCKS",
-
 
107
									info.getLocks()));
-
 
108
					cvsfile.getAttributes().add(
-
 
109
							CVSInfoImpl.this.getAttribute("SELECTEDREVISIONS",
-
 
110
									info.getSelectedRevisions()));
-
 
111
					cvsfile.setROOT(cvsclient.getRoot().host + "@"
-
 
112
							+ cvsclient.getRoot().repository);
-
 
113
 
-
 
114
					CVSInfoImpl.this.list.getItems().add(cvsfile);
-
 
115
 
-
 
116
					String key = CVSClient.generateID(cvsfile);
-
 
117
					try {
78
 
118
						CVSInfoImpl.this.getCacheInstance().put(key, cvsfile);
79
				RlogCommand rlog = new RlogCommand();
-
 
80
				StringTokenizer tk = new StringTokenizer(modules, ",");
-
 
81
				while (tk.hasMoreTokens()) {
-
 
82
					rlog.setModule(tk.nextToken());
-
 
83
				}
-
 
84
				if (rlog.getModules().length == 0)
-
 
85
					rlog.setModule("");
-
 
86
 
-
 
87
				rlog.setDefaultBranch(true); // -b Print information about the
-
 
88
												// revisions on the default
-
 
89
												// branch,
-
 
90
												// normally the highest branch
-
 
91
												// on
-
 
92
												// the trunk.
-
 
93
				rlog.setNoTags(true); // -N Do not print the list of tags for
-
 
94
										// this
-
 
95
										// file. This option can be very useful
-
 
96
										// when
-
 
97
										// your site uses a lot of tags, so
-
 
98
										// rather
-
 
99
										// than "more"'ing over 3 pages of tag
-
 
100
										// information, the log information is
-
 
101
										// presented without tags at all.
-
 
102
				rlog.setHeaderAndDescOnly(false); // -t Print only the name of
-
 
103
													// the
-
 
104
													// rcs file, name of the
-
 
105
													// file in
-
 
106
													// the working directory,
-
 
107
													// head,
-
 
108
													// default branch, access
-
 
109
													// list,
-
 
110
													// locks, symbolic names,
119
					} catch (CacheException e) {
111
													// and
-
 
112
													// suffix. + description
120
						CVSInfoImpl.this.logger.error("Could not cache item '"
113
				// rlog.setRevisionFilter("1.1.");
-
 
114
				// rlog.setSuppressHeader(true); // -S Supress log output when
-
 
115
				// no
-
 
116
				// revisions are selected within a file.
121
								+ key + "'", e);
117
				client.executeCommand(rlog, cvsclient.getGlobalOptions());
-
 
118
				logger.info("Execute CVS command '" + rlog.getCVSCommand() + "' against '"+cvsclient.getRoot().host+"@" + cvsclient.getRoot().repository+"'");
-
 
119
				//need to put a new list into cache as we will filter the result 
122
					}
120
				//afterwards
123
				}
121
				getCacheInstance().put(cachekey, new ArrayList<FileType>(list));
-
 
122
				
124
			});
123
				
-
 
124
			} catch (ConfigurationException e) {
-
 
125
				logger.error("CVS Configuration File '"
-
 
126
						+ f.getAbsolutePath() + f.getName() + "'not found.", e);
-
 
127
				
-
 
128
			} catch (CommandAbortedException e) {
-
 
129
				// TODO Auto-generated catch block
125
			RlogCommand rlog = new RlogCommand();
130
				e.printStackTrace();
-
 
131
			} catch (AuthenticationException e) {
-
 
132
				// TODO Auto-generated catch block
-
 
133
				e.printStackTrace();
-
 
134
			} catch (CommandException e) {
126
			StringTokenizer tk = new StringTokenizer(modules, ",");
135
				// TODO Auto-generated catch block
127
			while (tk.hasMoreTokens()) {
-
 
128
				rlog.setModule(tk.nextToken());
-
 
129
			}
-
 
130
			if (rlog.getModules().length == 0) {
-
 
131
				rlog.setModule("");
-
 
132
			}
-
 
133
			rlog.setDefaultBranch(false);
-
 
134
 
-
 
135
			rlog.setNoTags(false);
-
 
136
 
-
 
137
			rlog.setHeaderAndDescOnly(false);
-
 
138
 
-
 
139
			rlog.setRecursive(isRecursive);
Line -... Line 140...
-
 
140
 
-
 
141
			this.logger.info("Executing CVS command '" + rlog.getCVSCommand()
-
 
142
					+ "' against '" + cvsclient.getRoot().host + "@"
-
 
143
					+ cvsclient.getRoot().repository + "'");
-
 
144
			client.executeCommand(rlog, cvsclient.getGlobalOptions());
-
 
145
 
-
 
146
			getCacheInstance().put(cachekey, this.list);
-
 
147
		} catch (ConfigurationException e) {
-
 
148
			this.logger.error("CVS Configuration File '" + f.getAbsolutePath()
-
 
149
					+ f.getName() + "'not found.", e);
-
 
150
		} catch (CommandAbortedException e) {
-
 
151
			e.printStackTrace();
136
				e.printStackTrace();
152
		} catch (AuthenticationException e) {
137
			} catch (CacheException e) {
-
 
138
				// TODO Auto-generated catch block
153
			e.printStackTrace();
139
				e.printStackTrace();
-
 
140
			}
154
		} catch (CommandException e) {
141
 
155
			e.printStackTrace();
142
		}
156
		} catch (CacheException e) {
143
		
157
			e.printStackTrace();
144
		
158
		}
145
		// prepare output after everything is cached
159
 
146
		if (!showRevisions) {
-
 
147
			for (FileType t : list) {
160
		if (!showRevisions) {
148
				t.clearRevisionList();
161
			for (ItemType t : this.list.getItems()) {
Line 149... Line -...
149
			}
-
 
150
		}
162
				t.getRevisions().clear();
151
		
-
 
152
		GenericEntity entity = new GenericEntity<List<FileType>>(list) {};
-
 
153
		return Response.ok(entity).build();
163
			}
154
	}
164
		}
-
 
165
 
155
 
166
		return Response.ok(this.list).build();
156
	@Override
167
	}
157
	public Response getModules(HttpHeaders h, File f, boolean forceNoCache) {
168
 
158
 
-
 
159
		// Try to deliver from Cache
-
 
160
		String cachekey = "Modules" + f.toURI().toString();
169
	public Response getModules(HttpHeaders h, File f, boolean forceNoCache) {
161
		logger.debug("forceNoCache="+forceNoCache);
170
		String cachekey = "Modules" + f.toURI().toString();
162
		List<ModuleType> response = (List<ModuleType>) getCacheInstance().get(
-
 
163
				cachekey);
-
 
164
		if (!forceNoCache && response != null) {
171
		this.logger.debug("forceNoCache=" + forceNoCache);
165
			GenericEntity entity = new GenericEntity<List<ModuleType>>(response) {
172
 
166
			};
173
		ModuleListType response = (ModuleListType) getCacheInstance().get(
167
			return Response.ok(entity).build();
-
 
168
		}
174
				cachekey);
Line 169... Line 175...
169
		// -------------------------
175
		if ((!forceNoCache) && (response != null)) {
170
 
176
			return Response.ok(response).build();
171
		try {
177
		}
172
			CVSClient cvsclient = new CVSClient(f);
178
		try {
173
			Client client = cvsclient.client;
-
 
-
 
179
			CVSClient cvsclient = new CVSClient(f);
-
 
180
			Client client = cvsclient.client;
174
 
181
			final ModuleListType list = this.FACTORY.createModuleListType();
-
 
182
 
-
 
183
			client.getEventManager().addCVSListener(new BasicCVSListener() {
175
			final List<ModuleType> list = new ArrayList<ModuleType>();
184
				public void fileInfoGenerated(FileInfoEvent e) {
-
 
185
					ModuleListInformation info = (ModuleListInformation) e
176
 
186
							.getInfoContainer();
177
			client.getEventManager().addCVSListener(new BasicCVSListener() {
187
					ModuleType module = CVSInfoImpl.this.FACTORY
178
				public void fileInfoGenerated(FileInfoEvent e) {
-
 
179
					ModuleListInformation info = (ModuleListInformation) e
188
							.createModuleType();
180
							.getInfoContainer();
189
					module.setName(info.getModuleName());
Line -... Line 190...
-
 
190
					module.setStatus(info.getModuleStatus());
-
 
191
					module.setPath(info.getPaths());
-
 
192
					module.setType(info.getType());
181
 
193
					list.getModules().add(module);
182
					list.add(new ModuleType(info.getModuleName(), info
-
 
183
							.getModuleStatus(), info.getPaths(), info.getType()));
194
				}
-
 
195
			});
184
				}
196
			CheckoutCommand co = new CheckoutCommand();
185
			});
197
			co.setShowModulesWithStatus(true);
186
 
198
 
187
			CheckoutCommand co = new CheckoutCommand();
199
			this.logger.info("Executing CVS command '" + co.getCVSCommand()
188
			co.setShowModulesWithStatus(true);
-
 
189
 
-
 
190
			client.executeCommand(co, cvsclient.getGlobalOptions());
200
					+ "' against '" + cvsclient.getRoot().host + "@"
191
			logger.info("Execute CVS command '" + co.getCVSCommand() + "' against '"+cvsclient.getRoot().host+"@" + cvsclient.getRoot().repository+"'");
201
					+ cvsclient.getRoot().repository + "'");
192
			if(list.size()==0) {
202
			client.executeCommand(co, cvsclient.getGlobalOptions());
193
				logger.warn("Repository '" + cvsclient.getRoot().repository + "' does not have modules");
203
			if (list.getModules().size() == 0) {
194
				list.add(new ModuleType("","","",""));
204
				this.logger.warn("Repository '"
195
			}
205
						+ cvsclient.getRoot().repository
196
			
206
						+ "' does not have modules");
Line -... Line 207...
-
 
207
			}
-
 
208
 
-
 
209
			getCacheInstance().put(cachekey, list);
-
 
210
			return Response.ok(list).build();
-
 
211
		} catch (Exception e) {
-
 
212
			e.printStackTrace();
-
 
213
		}
-
 
214
		return Response.serverError().build();
197
			GenericEntity entity = new GenericEntity<List<ModuleType>>(list) {
215
	}
-
 
216
 
-
 
217
	public Response getTags(HttpHeaders h, File f, boolean withFiles) {
-
 
218
		String cachekey = f.toURI().toString() + ":taglist";
-
 
219
		this.logger.debug("Retrieving Tags from cache using key '" + cachekey
-
 
220
				+ "'");
-
 
221
		TagListType tags = (TagListType) getCacheInstance().get(cachekey);
-
 
222
		if (tags != null) {
-
 
223
			this.logger.debug("Delivering Tags from cache.");
-
 
224
			return Response.ok(tags).build();
-
 
225
		}
-
 
226
		this.logger.warn("Taglist not found in cache.");
-
 
227
		return Response.noContent().build();
-
 
228
	}
-
 
229
 
-
 
230
	public Response getFileContent(HttpHeaders h, File f, String filestring,
-
 
231
			boolean forceNoCache) {
-
 
232
		final ItemType result = this.FACTORY.createItemType();
-
 
233
		final String cachekey = f.toURI().toString() + ":" + filestring
-
 
234
				+ ":content";
-
 
235
		ItemListType list = null;
-
 
236
 
-
 
237
		if (!forceNoCache) {
-
 
238
			this.logger.debug("Retrieving file content from cache using key '"
-
 
239
					+ cachekey + "'");
-
 
240
			list = (ItemListType) getCacheInstance().get(cachekey);
198
			};
241
		}
-
 
242
 
-
 
243
		if (list != null) {
-
 
244
			this.logger.debug("Delivering file content from cache.");
-
 
245
			return Response.ok(list).build();
-
 
246
		}
-
 
247
 
-
 
248
		this.logger.warn("File content not found in cache.");
-
 
249
		list = this.FACTORY.createItemListType();
-
 
250
		try {
-
 
251
			CVSClient cvsclient = new CVSClient(f);
-
 
252
			Client client = cvsclient.getClient();
-
 
253
 
-
 
254
			CheckoutCommand checkout = new CheckoutCommand();
-
 
255
			BasicCVSListener listener = new BasicCVSListener() {
-
 
256
				public void fileInfoGenerated(FileInfoEvent arg0) {
-
 
257
					System.out.println(arg0.getInfoContainer().getFile()
-
 
258
							.toURI().toString());
-
 
259
					PipedFileInformation info = (PipedFileInformation) arg0
-
 
260
							.getInfoContainer();
-
 
261
					result.setName(info.getFile().getName());
-
 
262
					try {
-
 
263
						boolean isBinary = false;
-
 
264
						result.setIsBinary(isBinary);
-
 
265
						result.setRemotename(info.getRepositoryFileName());
-
 
266
						RevisionType revision = CVSInfoImpl.this.FACTORY
-
 
267
								.createRevisionType();
-
 
268
						revision.setRevision(info.getRepositoryRevision());
-
 
269
						revision.setComment("");
-
 
270
 
-
 
271
						if (!isBinary) {
-
 
272
							FileReader fin = new FileReader(info.getTempFile());
-
 
273
 
-
 
274
							ByteArrayOutputStream bout = new ByteArrayOutputStream();
-
 
275
							StringBuffer sbuf = new StringBuffer();
-
 
276
							int c;
-
 
277
							while ((c = fin.read()) != -1) {
-
 
278
								bout.write(c);
-
 
279
								sbuf.append((char) c);
-
 
280
							}
-
 
281
							result.setData(bout.toByteArray());
-
 
282
							result.setContent(sbuf.toString());
-
 
283
						}
-
 
284
 
-
 
285
					} catch (IOException e2) {
-
 
286
						e2.printStackTrace();
-
 
287
					} catch (NullPointerException ne) {
-
 
288
						ne.printStackTrace();
-
 
289
					}
-
 
290
 
-
 
291
					String key = CVSClient.generateID(result);
-
 
292
					try {
-
 
293
						CVSInfoImpl.this.getCacheInstance().put(cachekey,
-
 
294
								result);
-
 
295
					} catch (CacheException e1) {
-
 
296
						e1.printStackTrace();
-
 
297
					}
-
 
298
				}
-
 
299
			};
-
 
300
			client.getEventManager().addCVSListener(listener);
-
 
301
 
-
 
302
			checkout.setModule(filestring);
-
 
303
			checkout.setPipeToOutput(true);
-
 
304
 
-
 
305
			this.logger.info("Execute CVS command '" + checkout.getCVSCommand()
-
 
306
					+ "' against '" + cvsclient.getRoot().host + "@"
199
			getCacheInstance().put(cachekey, list);
307
					+ cvsclient.getRoot().repository + "'");
-
 
308
			client.executeCommand(checkout, cvsclient.getGlobalOptions());
200
			return Response.ok(entity).build();
309
		} catch (CommandAbortedException e) {
-
 
310
			e.printStackTrace();
201
		} catch (Exception e) {
311
		} catch (ConfigurationException e) {
-
 
312
			e.printStackTrace();
-
 
313
		} catch (AuthenticationException e) {
-
 
314
			e.printStackTrace();
202
			e.printStackTrace();
315
		} catch (CommandException e) {
203
		}
316
			e.printStackTrace();
204
		return Response.serverError().build();
317
		}
205
	}
318
 
206
 
319
		if (result.getContent() != null) {
207
	/**
320
			return Response.ok(result).build();
208
	 * Get the caching manager for CVS objects
321
		}
209
	 * 
322
		return Response.noContent().build();
210
	 * @return The CVSCaching JCS region
323
	}
211
	 */
324
 
212
	public JCS getCacheInstance() {
325
	public JCS getCacheInstance() {
213
		JCS jcs = null;
326
		JCS jcs = null;
Line -... Line 327...
-
 
327
		String cacheinstance = "CVSCache";
-
 
328
		try {
-
 
329
			this.logger.trace("Getting cache instance named 'CVSCache'");
-
 
330
			jcs = JCS.getInstance("CVSCache");
-
 
331
		} catch (CacheException e) {
-
 
332
			this.logger.error("Failed to get cache instance", e);
-
 
333
			e.printStackTrace();
-
 
334
		}
-
 
335
		return jcs;
-
 
336
	}
-
 
337
 
-
 
338
	public Response searchFileContent(HttpHeaders h, File f,
-
 
339
			String file_regexp, String content_regexp, boolean forceNoCache) {
-
 
340
		try {
-
 
341
			CVSClient client = new CVSClient(f);
-
 
342
			String cvsroot = client.getRoot().host + "@"
-
 
343
					+ client.getRoot().repository;
-
 
344
 
-
 
345
			String cachestring = "FINDINGS-" + cvsroot;
-
 
346
			this.logger
-
 
347
					.debug("Fetch searchFileContent response from cache using cachekey '"
-
 
348
							+ cachestring + "'");
-
 
349
			FindingsListType result = (FindingsListType) getCacheInstance()
-
 
350
					.get(cachestring);
-
 
351
			if (result != null)
-
 
352
				this.logger.debug("Found object for key '" + cachestring
-
 
353
						+ "' in cache.");
-
 
354
			else {
-
 
355
				this.logger.debug("Found no object for key '" + cachestring
-
 
356
						+ "' in cache.");
-
 
357
			}
-
 
358
 
-
 
359
			if (result != null)
-
 
360
				return Response.ok(result).build();
-
 
361
		} catch (CommandAbortedException e) {
-
 
362
			e.printStackTrace();
-
 
363
		} catch (ConfigurationException e) {
-
 
364
			e.printStackTrace();
-
 
365
		} catch (AuthenticationException e) {
214
		final String cacheinstance = "CVSCache";
366
			e.printStackTrace();
215
		try {
367
		}