Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 164219 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylar/internal/tasks/web/WebRepositoryConnector.java (-9 / +18 lines)
Lines 12-18 Link Here
12
package org.eclipse.mylar.internal.tasks.web;
12
package org.eclipse.mylar.internal.tasks.web;
13
13
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.io.UnsupportedEncodingException;
15
import java.net.Proxy;
16
import java.net.Proxy;
17
import java.net.URLDecoder;
16
import java.util.ArrayList;
18
import java.util.ArrayList;
17
import java.util.Collections;
19
import java.util.Collections;
18
import java.util.List;
20
import java.util.List;
Lines 156-162 Link Here
156
	public IStatus performQuery(AbstractRepositoryQuery query, TaskRepository repository, Proxy proxySettings,
158
	public IStatus performQuery(AbstractRepositoryQuery query, TaskRepository repository, Proxy proxySettings,
157
			IProgressMonitor monitor, QueryHitCollector resultCollector) {
159
			IProgressMonitor monitor, QueryHitCollector resultCollector) {
158
		if (query instanceof WebQuery) {
160
		if (query instanceof WebQuery) {
159
			String repositoryUrl = repository.getUrl();
160
			String repositoryUser = repository.getUserName();
161
			String repositoryUser = repository.getUserName();
161
			String repositoryPassword = repository.getPassword();
162
			String repositoryPassword = repository.getPassword();
162
163
Lines 169-175 Link Here
169
			try {
170
			try {
170
//				if (regexp != null && regexp.trim().length() > 0) {
171
//				if (regexp != null && regexp.trim().length() > 0) {
171
					return performQuery(fetchResource(queryUrl, repositoryUser, repositoryPassword), queryPattern,
172
					return performQuery(fetchResource(queryUrl, repositoryUser, repositoryPassword), queryPattern,
172
							taskPrefix, repositoryUrl, monitor, resultCollector);
173
							taskPrefix, monitor, resultCollector, repository);
173
//				} else {
174
//				} else {
174
//					return performRssQuery(queryUrl, taskPrefix, repositoryUrl, repositoryUser, repositoryPassword,
175
//					return performRssQuery(queryUrl, taskPrefix, repositoryUrl, repositoryUser, repositoryPassword,
175
//							monitor, resultCollector);
176
//							monitor, resultCollector);
Lines 204-214 Link Here
204
		// ignore
205
		// ignore
205
	}
206
	}
206
207
207
	public static IStatus performQuery(String resource, String regexp, String taskPrefix, String repositoryUrl,
208
	public static IStatus performQuery(String resource, String regexp, String taskPrefix, IProgressMonitor monitor, QueryHitCollector collector, TaskRepository repository) {
208
			IProgressMonitor monitor, QueryHitCollector collector) {
209
210
		// List<AbstractQueryHit> hits = new ArrayList<AbstractQueryHit>();
211
212
		Pattern p = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL
209
		Pattern p = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL
213
				| Pattern.UNICODE_CASE | Pattern.CANON_EQ);
210
				| Pattern.UNICODE_CASE | Pattern.CANON_EQ);
214
		Matcher matcher = p.matcher(resource);
211
		Matcher matcher = p.matcher(resource);
Lines 224-232 Link Here
224
				}
221
				}
225
				if (matcher.groupCount() >= 1) {
222
				if (matcher.groupCount() >= 1) {
226
					String id = matcher.group(1);
223
					String id = matcher.group(1);
227
					String description = matcher.groupCount() > 1 ? matcher.group(2) : null;
224
					String description = matcher.groupCount() > 1 ? cleanup(matcher.group(2), repository) : null;
228
					try {
225
					try {
229
						collector.accept(new WebQueryHit(TasksUiPlugin.getTaskListManager().getTaskList(), repositoryUrl, description, id, taskPrefix));
226
						collector.accept(new WebQueryHit(TasksUiPlugin.getTaskListManager().getTaskList(),
227
								repository.getUrl(), description, id, taskPrefix));
230
					} catch (CoreException e) {
228
					} catch (CoreException e) {
231
						return new Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR,
229
						return new Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR,
232
								"Unable collect results.", e);
230
								"Unable collect results.", e);
Lines 243-248 Link Here
243
		}
241
		}
244
	}
242
	}
245
243
244
	private static String cleanup(String text, TaskRepository repository) {
245
		try {
246
			text = URLDecoder.decode(text, repository.getCharacterEncoding());
247
		} catch (UnsupportedEncodingException ex) {
248
			// ignore
249
		}
250
251
		text = text.replaceAll("<!--.+?-->", "");
252
		return text.trim();
253
	}
254
246
/*
255
/*
247
	public static IStatus performRssQuery(String queryUrl, String taskPrefix, String repositoryUrl,
256
	public static IStatus performRssQuery(String queryUrl, String taskPrefix, String repositoryUrl,
248
			String repositoryUser, String repositoryPassword, IProgressMonitor monitor, QueryHitCollector collector) {
257
			String repositoryUser, String repositoryPassword, IProgressMonitor monitor, QueryHitCollector collector) {
(-)src/org/eclipse/mylar/internal/tasks/web/WebQueryWizardPage.java (-23 / +31 lines)
Lines 49-64 Link Here
49
49
50
/**
50
/**
51
 * Wizard page for configuring and preview web query
51
 * Wizard page for configuring and preview web query
52
 * 
52
 *
53
 * @author Eugene Kuleshov
53
 * @author Eugene Kuleshov
54
 */
54
 */
55
public class WebQueryWizardPage extends AbstractRepositoryQueryPage {
55
public class WebQueryWizardPage extends AbstractRepositoryQueryPage {
56
	private Text queryUrlText;
56
	private Text queryUrlText;
57
	private Text queryPatternText;
57
	private Text queryPatternText;
58
	private Table previewTable;
58
	private Table previewTable;
59
	
59
60
	private String webPage;
60
	private String webPage;
61
	
61
62
	private TaskRepository repository;
62
	private TaskRepository repository;
63
	private WebQuery query;
63
	private WebQuery query;
64
	private UpdatePreviewJob updatePreviewJob;
64
	private UpdatePreviewJob updatePreviewJob;
Lines 66-73 Link Here
66
	private FormToolkit toolkit = new FormToolkit(Display.getCurrent());
66
	private FormToolkit toolkit = new FormToolkit(Display.getCurrent());
67
	private ParametersEditor parametersEditor;
67
	private ParametersEditor parametersEditor;
68
	private Map<String, String> oldProperties;
68
	private Map<String, String> oldProperties;
69
	
69
70
	
70
71
	public WebQueryWizardPage(TaskRepository repository) {
71
	public WebQueryWizardPage(TaskRepository repository) {
72
		this(repository, null);
72
		this(repository, null);
73
	}
73
	}
Lines 116-122 Link Here
116
//			}
116
//			}
117
//		});
117
//		});
118
//		queryTitleText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
118
//		queryTitleText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
119
		
119
120
		parametersEditor = new ParametersEditor(composite, SWT.NONE);
120
		parametersEditor = new ParametersEditor(composite, SWT.NONE);
121
		GridData gridData1 = new GridData(SWT.FILL, SWT.FILL, true, true);
121
		GridData gridData1 = new GridData(SWT.FILL, SWT.FILL, true, true);
122
		gridData1.heightHint = 80;
122
		gridData1.heightHint = 80;
Lines 160-166 Link Here
160
		GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
160
		GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
161
		gridData.heightHint = 45;
161
		gridData.heightHint = 45;
162
		queryPatternText.setLayoutData(gridData);
162
		queryPatternText.setLayoutData(gridData);
163
		
163
164
//		regexpText.addModifyListener(new ModifyListener() {
164
//		regexpText.addModifyListener(new ModifyListener() {
165
//				public void modifyText(final ModifyEvent e) {
165
//				public void modifyText(final ModifyEvent e) {
166
//					if(webPage!=null) {
166
//					if(webPage!=null) {
Lines 178-184 Link Here
178
				updatePreview();
178
				updatePreview();
179
			}
179
			}
180
		});
180
		});
181
		
181
182
		previewTable = new Table(composite1, SWT.BORDER);
182
		previewTable = new Table(composite1, SWT.BORDER);
183
		GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, false, true, 3, 1);
183
		GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, false, true, 3, 1);
184
		gridData2.heightHint = 60;
184
		gridData2.heightHint = 60;
Lines 195-209 Link Here
195
		colDescription.setText("Description");
195
		colDescription.setText("Description");
196
196
197
		setControl(composite);
197
		setControl(composite);
198
		
198
199
		LinkedHashMap<String, String> vars = new LinkedHashMap<String, String>();
199
		LinkedHashMap<String, String> vars = new LinkedHashMap<String, String>();
200
		Map<String, String> params = new LinkedHashMap<String, String>();
200
		Map<String, String> params = new LinkedHashMap<String, String>();
201
		if(repository!=null) {
201
		if(repository!=null) {
202
			
202
203
			
203
204
			queryUrlText.setText(addVars(vars, repository.getProperty(WebRepositoryConnector.PROPERTY_QUERY_URL)));
204
			queryUrlText.setText(addVars(vars, repository.getProperty(WebRepositoryConnector.PROPERTY_QUERY_URL)));
205
			queryPatternText.setText(addVars(vars, repository.getProperty(WebRepositoryConnector.PROPERTY_QUERY_REGEXP)));
205
			queryPatternText.setText(addVars(vars, repository.getProperty(WebRepositoryConnector.PROPERTY_QUERY_REGEXP)));
206
			
206
207
			oldProperties = repository.getProperties();
207
			oldProperties = repository.getProperties();
208
			params.putAll(oldProperties);
208
			params.putAll(oldProperties);
209
		}
209
		}
Lines 245-258 Link Here
245
		if(!updatePreviewJob.isActive()) {
245
		if(!updatePreviewJob.isActive()) {
246
			updatePreviewJob.schedule();
246
			updatePreviewJob.schedule();
247
		}
247
		}
248
		
249
	}
248
	}
250
	
249
250
	public boolean isPageComplete() {
251
		if(getErrorMessage()!=null) {
252
			return false;
253
		}
254
		return super.isPageComplete();
255
	}
256
251
	void updatePreviewTable(List<AbstractQueryHit> hits, MultiStatus queryStatus) {
257
	void updatePreviewTable(List<AbstractQueryHit> hits, MultiStatus queryStatus) {
252
		if(previewTable.isDisposed()) {
258
		if(previewTable.isDisposed()) {
253
			return;
259
			return;
254
		}
260
		}
255
		
261
256
		previewTable.removeAll();
262
		previewTable.removeAll();
257
263
258
		if(hits!=null) {
264
		if(hits!=null) {
Lines 279-285 Link Here
279
			setPageComplete(false);
285
			setPageComplete(false);
280
		}
286
		}
281
	}
287
	}
282
	
288
283
	private final class UpdatePreviewJob extends Job {
289
	private final class UpdatePreviewJob extends Job {
284
		private volatile String url;
290
		private volatile String url;
285
		private volatile String regexp;
291
		private volatile String regexp;
Lines 289-295 Link Here
289
		private UpdatePreviewJob(String name) {
295
		private UpdatePreviewJob(String name) {
290
			super(name);
296
			super(name);
291
		}
297
		}
292
		
298
293
		public boolean isActive() {
299
		public boolean isActive() {
294
			return active;
300
			return active;
295
		}
301
		}
Lines 319-328 Link Here
319
							queryHits.add(hit);
325
							queryHits.add(hit);
320
						}
326
						}
321
					};
327
					};
322
					
328
323
					// TODO: Handle returned status
329
					IStatus status = WebRepositoryConnector.performQuery(webPage, evaluatedRegexp, null, monitor, collector, repository);
324
					WebRepositoryConnector.performQuery(webPage, evaluatedRegexp, null, null, monitor, collector);
330
					if(!status.isOK()) {
325
					
331
						queryStatus.add(status);
332
					}
333
326
				} catch (final IOException ex) {
334
				} catch (final IOException ex) {
327
					queryStatus.add(new Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR,
335
					queryStatus.add(new Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR,
328
							"Unable to fetch resource: "+ex.getMessage(), null));
336
							"Unable to fetch resource: "+ex.getMessage(), null));
Lines 330-336 Link Here
330
					queryStatus.add(new Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR,
338
					queryStatus.add(new Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR,
331
							"Parsing error: "+ex.getMessage(), null));
339
							"Parsing error: "+ex.getMessage(), null));
332
				}
340
				}
333
				
341
334
				Display.getDefault().asyncExec(new Runnable() {
342
				Display.getDefault().asyncExec(new Runnable() {
335
					public void run() {
343
					public void run() {
336
						updatePreviewTable(queryHits, queryStatus);
344
						updatePreviewTable(queryHits, queryStatus);
Lines 341-346 Link Here
341
			return Status.OK_STATUS;
349
			return Status.OK_STATUS;
342
		}
350
		}
343
	}
351
	}
344
	
352
345
}
353
}

Return to bug 164219