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 151602 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylar/internal/tasks/web/WebRepositorySettingsPage.java (-2 / +112 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.mylar.internal.tasks.web;
12
package org.eclipse.mylar.internal.tasks.web;
13
13
14
import java.util.ArrayList;
14
import java.util.LinkedHashMap;
15
import java.util.LinkedHashMap;
15
import java.util.Map;
16
import java.util.Map;
16
17
Lines 18-23 Link Here
18
import org.eclipse.jface.util.IPropertyChangeListener;
19
import org.eclipse.jface.util.IPropertyChangeListener;
19
import org.eclipse.jface.util.PropertyChangeEvent;
20
import org.eclipse.jface.util.PropertyChangeEvent;
20
import org.eclipse.mylar.internal.tasks.ui.wizards.AbstractRepositorySettingsPage;
21
import org.eclipse.mylar.internal.tasks.ui.wizards.AbstractRepositorySettingsPage;
22
import org.eclipse.mylar.internal.tasks.web.restui.EHttpMethod;
23
import org.eclipse.mylar.internal.tasks.web.restui.NameValuePair;
24
import org.eclipse.mylar.internal.tasks.web.restui.RESTRequestEditor;
21
import org.eclipse.mylar.tasks.core.RepositoryTemplate;
25
import org.eclipse.mylar.tasks.core.RepositoryTemplate;
22
import org.eclipse.mylar.tasks.core.TaskRepository;
26
import org.eclipse.mylar.tasks.core.TaskRepository;
23
import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnectorUi;
27
import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnectorUi;
Lines 32-37 Link Here
32
import org.eclipse.swt.widgets.Text;
36
import org.eclipse.swt.widgets.Text;
33
import org.eclipse.ui.forms.events.ExpansionAdapter;
37
import org.eclipse.ui.forms.events.ExpansionAdapter;
34
import org.eclipse.ui.forms.events.ExpansionEvent;
38
import org.eclipse.ui.forms.events.ExpansionEvent;
39
import org.eclipse.ui.forms.widgets.ColumnLayout;
35
import org.eclipse.ui.forms.widgets.ExpandableComposite;
40
import org.eclipse.ui.forms.widgets.ExpandableComposite;
36
import org.eclipse.ui.forms.widgets.FormToolkit;
41
import org.eclipse.ui.forms.widgets.FormToolkit;
37
import org.eclipse.ui.forms.widgets.Section;
42
import org.eclipse.ui.forms.widgets.Section;
Lines 56-63 Link Here
56
61
57
	private Text queryPatternText;
62
	private Text queryPatternText;
58
63
64
	private Text loginFormUrlText;
65
66
	private Text loginTokenPatternText;
67
59
	private ParametersEditor parametersEditor;
68
	private ParametersEditor parametersEditor;
60
69
70
	private RESTRequestEditor loginRequestEditor;
71
61
	private FormToolkit toolkit = new FormToolkit(Display.getCurrent());
72
	private FormToolkit toolkit = new FormToolkit(Display.getCurrent());
62
73
63
	private Map<String, String> oldProperties;
74
	private Map<String, String> oldProperties;
Lines 84-99 Link Here
84
					newTaskText.setText(template.newTaskUrl);
95
					newTaskText.setText(template.newTaskUrl);
85
					queryUrlText.setText(template.taskQueryUrl);
96
					queryUrlText.setText(template.taskQueryUrl);
86
					queryPatternText.setText(template.getAttribute(WebRepositoryConnector.PROPERTY_QUERY_REGEXP));
97
					queryPatternText.setText(template.getAttribute(WebRepositoryConnector.PROPERTY_QUERY_REGEXP));
98
					loginFormUrlText.setText(template.getAttribute(WebRepositoryConnector.PROPERTY_LOGIN_FORM_URL));
99
					loginTokenPatternText.setText(template
100
							.getAttribute(WebRepositoryConnector.PROPERTY_LOGIN_TOKEN_REGEXP));
101
					try {
102
						loginRequestEditor.setMethod(EHttpMethod.valueOf(template
103
								.getAttribute(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_METHOD)));
104
					} catch (IllegalArgumentException e1) {
105
						// ignore
106
					}
107
					loginRequestEditor.setUrl(template.getAttribute(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_URL));
87
108
88
					parametersEditor.removeAll();
109
					parametersEditor.removeAll();
89
110
111
					ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();
90
					for (Map.Entry<String, String> entry : template.getAttributes().entrySet()) {
112
					for (Map.Entry<String, String> entry : template.getAttributes().entrySet()) {
91
						String key = entry.getKey();
113
						String key = entry.getKey();
92
						if (key.startsWith(WebRepositoryConnector.PARAM_PREFIX)) {
114
						if (key.startsWith(WebRepositoryConnector.PARAM_PREFIX)) {
93
							parametersEditor.add(key.substring(WebRepositoryConnector.PARAM_PREFIX.length()), entry
115
							parametersEditor.add(key.substring(WebRepositoryConnector.PARAM_PREFIX.length()), entry
94
									.getValue());
116
									.getValue());
95
						}
117
						}
118
						if (key.startsWith(WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX)) {
119
							pairs.add(new NameValuePair(key.substring(WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX
120
									.length()), entry.getValue()));
121
						}
96
					}
122
					}
123
					loginRequestEditor.setParameters(pairs.toArray(new NameValuePair[pairs.size()]));
97
124
98
					getContainer().updateButtons();
125
					getContainer().updateButtons();
99
					return;
126
					return;
Lines 114-122 Link Here
114
			newTaskText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_TASK_CREATION_URL));
141
			newTaskText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_TASK_CREATION_URL));
115
			queryUrlText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_QUERY_URL));
142
			queryUrlText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_QUERY_URL));
116
			queryPatternText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_QUERY_REGEXP));
143
			queryPatternText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_QUERY_REGEXP));
144
			loginFormUrlText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_LOGIN_FORM_URL));
145
			loginTokenPatternText.setText(getTextProperty(WebRepositoryConnector.PROPERTY_LOGIN_TOKEN_REGEXP));
146
			try {
147
				loginRequestEditor.setMethod(EHttpMethod
148
						.valueOf(getTextProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_METHOD)));
149
			} catch (IllegalArgumentException e) {
150
				// ignore
151
			}
152
			loginRequestEditor.setUrl(getTextProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_URL));
117
153
118
			oldProperties = repository.getProperties();
154
			oldProperties = repository.getProperties();
119
			parametersEditor.addParams(oldProperties, new LinkedHashMap<String, String>());
155
			parametersEditor.addParams(oldProperties, new LinkedHashMap<String, String>());
156
			ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();
157
			for (Map.Entry<String, String> entry : oldProperties.entrySet()) {
158
				if (entry.getKey().startsWith(WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX)) {
159
					pairs.add(new NameValuePair(entry.getKey().substring(
160
							WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX.length()), entry.getValue()));
161
				}
162
			}
163
			loginRequestEditor.setParameters(pairs.toArray(new NameValuePair[pairs.size()]));
120
		}
164
		}
121
	}
165
	}
122
166
Lines 153-158 Link Here
153
		gridData_1.minimumHeight = 80;
197
		gridData_1.minimumHeight = 80;
154
		parametersEditor.setLayoutData(gridData_1);
198
		parametersEditor.setLayoutData(gridData_1);
155
199
200
		createAdvancedComposite(parent, composite);
201
		createLoginComposite(parent, composite);
202
203
		return composite;
204
	}
205
206
	private void createAdvancedComposite(Composite parent, final Composite composite) {
156
		ExpandableComposite expComposite = toolkit.createExpandableComposite(composite, Section.COMPACT
207
		ExpandableComposite expComposite = toolkit.createExpandableComposite(composite, Section.COMPACT
157
				| Section.TWISTIE | Section.TITLE_BAR);
208
				| Section.TWISTIE | Section.TITLE_BAR);
158
		expComposite.clientVerticalSpacing = 0;
209
		expComposite.clientVerticalSpacing = 0;
Lines 201-208 Link Here
201
		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
252
		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
202
		gridData.heightHint = 40;
253
		gridData.heightHint = 40;
203
		queryPatternText.setLayoutData(gridData);
254
		queryPatternText.setLayoutData(gridData);
255
	}
204
256
205
		return composite;
257
	private void createLoginComposite(final Composite parent, final Composite composite) {
258
		ExpandableComposite expComposite = toolkit.createExpandableComposite(composite, Section.COMPACT
259
				| Section.TWISTIE | Section.TITLE_BAR);
260
		expComposite.clientVerticalSpacing = 0;
261
		GridData gridData_2 = new GridData(SWT.FILL, SWT.FILL, true, false);
262
		gridData_2.horizontalIndent = -5;
263
		expComposite.setLayoutData(gridData_2);
264
		expComposite.setFont(parent.getFont());
265
		expComposite.setBackground(parent.getBackground());
266
		expComposite.setText("&Login Configuration (Expert)");
267
		expComposite.addExpansionListener(new ExpansionAdapter() {
268
			public void expansionStateChanged(ExpansionEvent e) {
269
				composite.layout();
270
			}
271
		});
272
273
		Composite loginComposite = toolkit.createComposite(expComposite, SWT.BORDER);
274
		loginComposite.setLayout(new ColumnLayout());
275
		Section loginTokenSection = toolkit.createSection(loginComposite, Section.TWISTIE | Section.TITLE_BAR);
276
		loginTokenSection.setText("Step 1. Retrieve login token (optional)");
277
		Composite composite2 = toolkit.createComposite(loginTokenSection);
278
		GridLayout gridLayout2 = new GridLayout();
279
		gridLayout2.numColumns = 2;
280
		gridLayout2.verticalSpacing = 0;
281
		composite2.setLayout(gridLayout2);
282
283
		Label queryUrlLabel = toolkit.createLabel(composite2, "Login &Page URL:", SWT.NONE);
284
		queryUrlLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
285
286
		loginFormUrlText = new Text(composite2, SWT.BORDER);
287
		loginFormUrlText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
288
289
		Label queryPatternLabel = toolkit.createLabel(composite2, "Login &Token Pattern:", SWT.NONE);
290
		queryPatternLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, true));
291
292
		loginTokenPatternText = new Text(composite2, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.WRAP);
293
		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
294
		gridData.heightHint = 40;
295
		loginTokenPatternText.setLayoutData(gridData);
296
297
		loginTokenSection.setClient(composite2);
298
299
		Section loginRequestSection = toolkit.createSection(loginComposite, Section.TWISTIE | Section.TITLE_BAR | Section.EXPANDED);
300
		loginRequestSection.setText("Step 2. Login request");
301
302
		loginRequestEditor = new RESTRequestEditor(loginRequestSection, SWT.NONE);
303
		toolkit.adapt(loginRequestEditor);
304
		loginRequestSection.setClient(loginRequestEditor);
305
306
		expComposite.setClient(loginComposite);
206
	}
307
	}
207
308
208
	public void propertyChange(PropertyChangeEvent event) {
309
	public void propertyChange(PropertyChangeEvent event) {
Lines 218-228 Link Here
218
		repository.setProperty(WebRepositoryConnector.PROPERTY_TASK_CREATION_URL, newTaskText.getText());
319
		repository.setProperty(WebRepositoryConnector.PROPERTY_TASK_CREATION_URL, newTaskText.getText());
219
		repository.setProperty(WebRepositoryConnector.PROPERTY_QUERY_URL, queryUrlText.getText());
320
		repository.setProperty(WebRepositoryConnector.PROPERTY_QUERY_URL, queryUrlText.getText());
220
		repository.setProperty(WebRepositoryConnector.PROPERTY_QUERY_REGEXP, queryPatternText.getText());
321
		repository.setProperty(WebRepositoryConnector.PROPERTY_QUERY_REGEXP, queryPatternText.getText());
322
		repository.setProperty(WebRepositoryConnector.PROPERTY_LOGIN_FORM_URL, loginFormUrlText.getText());
323
		repository.setProperty(WebRepositoryConnector.PROPERTY_LOGIN_TOKEN_REGEXP, loginTokenPatternText.getText());
324
		repository.setProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_METHOD, loginRequestEditor.getMethod()
325
				.name());
326
		repository.setProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_URL, loginRequestEditor.getUrl());
221
327
222
		if (oldProperties != null) {
328
		if (oldProperties != null) {
223
			for (Map.Entry<String, String> e : oldProperties.entrySet()) {
329
			for (Map.Entry<String, String> e : oldProperties.entrySet()) {
224
				String key = e.getKey();
330
				String key = e.getKey();
225
				if (key.startsWith(WebRepositoryConnector.PARAM_PREFIX)) {
331
				if (key.startsWith(WebRepositoryConnector.PARAM_PREFIX)
332
						|| key.startsWith(WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX)) {
226
					repository.removeProperty(key);
333
					repository.removeProperty(key);
227
				}
334
				}
228
			}
335
			}
Lines 231-236 Link Here
231
		for (Map.Entry<String, String> e : parametersEditor.getParameters().entrySet()) {
338
		for (Map.Entry<String, String> e : parametersEditor.getParameters().entrySet()) {
232
			repository.setProperty(e.getKey(), e.getValue());
339
			repository.setProperty(e.getKey(), e.getValue());
233
		}
340
		}
341
		for (NameValuePair pair : loginRequestEditor.getParameters()) {
342
			repository.setProperty(WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX + pair.getName(), pair.getValue());
343
		}
234
	}
344
	}
235
345
236
}
346
}
(-)src/org/eclipse/mylar/internal/tasks/web/WebRepositoryConnector.java (-8 / +119 lines)
Lines 17-22 Link Here
17
import java.net.URLDecoder;
17
import java.net.URLDecoder;
18
import java.util.ArrayList;
18
import java.util.ArrayList;
19
import java.util.Collections;
19
import java.util.Collections;
20
import java.util.HashMap;
20
import java.util.List;
21
import java.util.List;
21
import java.util.Map;
22
import java.util.Map;
22
import java.util.Set;
23
import java.util.Set;
Lines 25-31 Link Here
25
26
26
import org.apache.commons.httpclient.Header;
27
import org.apache.commons.httpclient.Header;
27
import org.apache.commons.httpclient.HttpClient;
28
import org.apache.commons.httpclient.HttpClient;
29
import org.apache.commons.httpclient.HttpMethod;
30
import org.apache.commons.httpclient.NameValuePair;
28
import org.apache.commons.httpclient.methods.GetMethod;
31
import org.apache.commons.httpclient.methods.GetMethod;
32
import org.apache.commons.httpclient.methods.PostMethod;
29
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.core.runtime.IProgressMonitor;
31
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.IStatus;
Lines 34-39 Link Here
34
import org.eclipse.mylar.internal.tasks.core.WebQueryHit;
38
import org.eclipse.mylar.internal.tasks.core.WebQueryHit;
35
import org.eclipse.mylar.internal.tasks.core.WebTask;
39
import org.eclipse.mylar.internal.tasks.core.WebTask;
36
import org.eclipse.mylar.internal.tasks.ui.RetrieveTitleFromUrlJob;
40
import org.eclipse.mylar.internal.tasks.ui.RetrieveTitleFromUrlJob;
41
import org.eclipse.mylar.internal.tasks.web.restui.EHttpMethod;
37
import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector;
42
import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector;
38
import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery;
43
import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery;
39
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
44
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
Lines 60-65 Link Here
60
65
61
	public static final String PROPERTY_QUERY_REGEXP = "queryPattern";
66
	public static final String PROPERTY_QUERY_REGEXP = "queryPattern";
62
67
68
	public static final String PROPERTY_LOGIN_FORM_URL = "loginFormUrl";
69
70
	public static final String PROPERTY_LOGIN_TOKEN_REGEXP = "loginTokenPattern";
71
72
	public static final String PROPERTY_LOGIN_REQUEST_METHOD = "loginRequestMethod";
73
74
	public static final String PROPERTY_LOGIN_REQUEST_URL = "loginRequestUrl";
75
76
	public static final String LOGIN_REQUEST_PARAM_PREFIX = "loginRequestParam_";
77
63
	public static final String PARAM_PREFIX = "param_";
78
	public static final String PARAM_PREFIX = "param_";
64
79
65
	public static final String PARAM_SERVER_URL = "serverUrl";
80
	public static final String PARAM_SERVER_URL = "serverUrl";
Lines 68-73 Link Here
68
83
69
	public static final String PARAM_PASSWORD = "password";
84
	public static final String PARAM_PASSWORD = "password";
70
85
86
	public static final String PARAM_LOGIN_TOKEN = "loginToken";
87
71
	public String getRepositoryType() {
88
	public String getRepositoryType() {
72
		return WebTask.REPOSITORY_TYPE;
89
		return WebTask.REPOSITORY_TYPE;
73
	}
90
	}
Lines 159-169 Link Here
159
			String queryUrl = evaluateParams(query.getUrl(), queryParameters, repository);
176
			String queryUrl = evaluateParams(query.getUrl(), queryParameters, repository);
160
			String queryPattern = evaluateParams(webQuery.getQueryPattern(), queryParameters, repository);
177
			String queryPattern = evaluateParams(webQuery.getQueryPattern(), queryParameters, repository);
161
			String taskPrefix = evaluateParams(webQuery.getTaskPrefix(), queryParameters, repository);
178
			String taskPrefix = evaluateParams(webQuery.getTaskPrefix(), queryParameters, repository);
162
179
			Map<String, String> loginParams = new HashMap<String, String>();
180
			loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_FORM_URL, evaluateParams(repository
181
					.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_FORM_URL), queryParameters, repository));
182
			loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_TOKEN_REGEXP, evaluateParams(repository
183
					.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_TOKEN_REGEXP), queryParameters, repository));
184
			loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_METHOD, evaluateParams(repository
185
					.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_METHOD), queryParameters, repository));
186
			loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_URL, evaluateParams(repository
187
					.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_URL), queryParameters, repository));
188
			for (Map.Entry<String, String> entry : repository.getProperties().entrySet()) {
189
				if (entry.getKey().startsWith(WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX)) {
190
					loginParams.put(entry.getKey(), entry.getValue());
191
				}
192
			}
193
			
163
			try {
194
			try {
164
				// if (regexp != null && regexp.trim().length() > 0) {
195
				// if (regexp != null && regexp.trim().length() > 0) {
165
				return performQuery(fetchResource(queryUrl, repositoryUser, repositoryPassword), queryPattern,
196
				return performQuery(fetchResource(queryUrl, repositoryUser, repositoryPassword, loginParams,
166
						taskPrefix, monitor, resultCollector, repository);
197
						queryParameters, repository), queryPattern, taskPrefix, monitor, resultCollector, repository);
167
				// } else {
198
				// } else {
168
				// return performRssQuery(queryUrl, taskPrefix, repositoryUrl,
199
				// return performRssQuery(queryUrl, taskPrefix, repositoryUrl,
169
				// repositoryUser, repositoryPassword,
200
				// repositoryUser, repositoryPassword,
Lines 270-286 Link Here
270
	 * try { collector.accept(new WebQueryHit(id, id+": "+entry.getTitle(),
301
	 * try { collector.accept(new WebQueryHit(id, id+": "+entry.getTitle(),
271
	 * taskPrefix, repositoryUrl)); } catch (CoreException e) { return new
302
	 * taskPrefix, repositoryUrl)); } catch (CoreException e) { return new
272
	 * Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR, "Unable
303
	 * Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR, "Unable
273
	 * collect results.", e); } } } return Status.OK_STATUS;
304
	 * collect results.", e); } } } return Status.OK_STATUS; } catch (Exception
274
	 *  } catch (Exception ex) { return new Status(IStatus.OK,
305
	 * ex) { return new Status(IStatus.OK, TasksUiPlugin.PLUGIN_ID, IStatus.OK,
275
	 * TasksUiPlugin.PLUGIN_ID, IStatus.OK, "Could not fetch resource: " +
306
	 * "Could not fetch resource: " + queryUrl, ex); } }
276
	 * queryUrl, ex); } }
277
	 */
307
	 */
278
308
279
	public static String fetchResource(String url, String user, String password) throws IOException {
309
	public static String fetchResource(String url, String user, String password, Map<String, String> loginParams,
310
			Map<String, String> params, TaskRepository repository) throws IOException {
280
		HttpClient client = new HttpClient();
311
		HttpClient client = new HttpClient();
281
		Proxy proxySettings = TasksUiPlugin.getDefault().getProxySettings();
312
		Proxy proxySettings = TasksUiPlugin.getDefault().getProxySettings();
282
		WebClientUtil.setupHttpClient(client, proxySettings, url, user, password);
313
		WebClientUtil.setupHttpClient(client, proxySettings, url, user, password);
283
314
315
		if (loginParams != null) {
316
			String loginFormUrl = loginParams.get(PROPERTY_LOGIN_FORM_URL);
317
			if (loginFormUrl != null && !"".equals(loginFormUrl)) {
318
				GetMethod get = new GetMethod(loginFormUrl);
319
				String loginFormPage = null;
320
				try {
321
					client.executeMethod(get);
322
					Header locationHeader = get.getResponseHeader("Location");
323
					if (locationHeader != null) {
324
						get = new GetMethod(locationHeader.getValue());
325
						client.executeMethod(get);
326
					}
327
					Header refreshHeader = get.getResponseHeader("Refresh");
328
					if (refreshHeader != null) {
329
						String value = refreshHeader.getValue();
330
						int n = value.indexOf(";url=");
331
						if (n != -1) {
332
							value = value.substring(n + 5);
333
							int requestPath;
334
							if (value.charAt(0) == '/') {
335
								int colonSlashSlash = url.indexOf("://");
336
								requestPath = url.indexOf('/', colonSlashSlash + 3);
337
							} else {
338
								requestPath = url.lastIndexOf('/');
339
							}
340
341
							String refreshUrl;
342
							if (requestPath == -1) {
343
								refreshUrl = url + "/" + value;
344
							} else {
345
								refreshUrl = url.substring(0, requestPath + 1) + value;
346
							}
347
348
							get = new GetMethod(refreshUrl);
349
							client.executeMethod(get);
350
						}
351
					}
352
					loginFormPage = get.getResponseBodyAsString();
353
				} catch (Exception e) {
354
					// ignore
355
					e.printStackTrace();
356
				} finally {
357
					get.releaseConnection();
358
				}
359
				if (loginFormPage != null) {
360
					Pattern p = Pattern.compile(loginParams.get(PROPERTY_LOGIN_TOKEN_REGEXP));
361
					Matcher m = p.matcher(loginFormPage);
362
					if (m.find()) {
363
						// TODO is it ok to modify the params map?
364
						params.put(PARAM_PREFIX + PARAM_LOGIN_TOKEN, m.group(1));
365
					}
366
				}
367
			}
368
			HttpMethod method = null;
369
			try {
370
				switch (EHttpMethod.valueOf(loginParams.get(PROPERTY_LOGIN_REQUEST_METHOD))) {
371
				case GET:
372
					method = new GetMethod(loginParams.get(PROPERTY_LOGIN_REQUEST_URL));
373
					break;
374
				case POST:
375
					method = new PostMethod(loginParams.get(PROPERTY_LOGIN_REQUEST_URL));
376
					for (Map.Entry<String, String> entry : loginParams.entrySet()) {
377
						if (entry.getKey().startsWith(LOGIN_REQUEST_PARAM_PREFIX)) {
378
							String value = evaluateParams(entry.getValue(), params, repository);
379
							((PostMethod) method).addParameter(new NameValuePair(entry.getKey().substring(
380
									LOGIN_REQUEST_PARAM_PREFIX.length()), value));
381
						}
382
					}
383
					break;
384
				}
385
				client.executeMethod(method);
386
			} catch (Exception e) {
387
				// ignore
388
			} finally {
389
				if (method != null) {
390
					method.releaseConnection();
391
				}
392
			}
393
		}
394
284
		GetMethod get = new GetMethod(url);
395
		GetMethod get = new GetMethod(url);
285
		try {
396
		try {
286
			client.executeMethod(get);
397
			client.executeMethod(get);
(-)src/org/eclipse/mylar/internal/tasks/web/WebQueryWizardPage.java (-54 / +90 lines)
Lines 10-15 Link Here
10
10
11
import java.io.IOException;
11
import java.io.IOException;
12
import java.util.ArrayList;
12
import java.util.ArrayList;
13
import java.util.HashMap;
13
import java.util.LinkedHashMap;
14
import java.util.LinkedHashMap;
14
import java.util.List;
15
import java.util.List;
15
import java.util.Map;
16
import java.util.Map;
Lines 49-79 Link Here
49
50
50
/**
51
/**
51
 * Wizard page for configuring and preview web query
52
 * Wizard page for configuring and preview web query
52
 *
53
 * 
53
 * @author Eugene Kuleshov
54
 * @author Eugene Kuleshov
54
 */
55
 */
55
public class WebQueryWizardPage extends AbstractRepositoryQueryPage {
56
public class WebQueryWizardPage extends AbstractRepositoryQueryPage {
56
	private Text queryUrlText;
57
	private Text queryUrlText;
58
57
	private Text queryPatternText;
59
	private Text queryPatternText;
60
58
	private Table previewTable;
61
	private Table previewTable;
59
62
60
	private String webPage;
63
	private String webPage;
61
64
62
	private TaskRepository repository;
65
	private TaskRepository repository;
66
63
	private WebQuery query;
67
	private WebQuery query;
68
64
	private UpdatePreviewJob updatePreviewJob;
69
	private UpdatePreviewJob updatePreviewJob;
65
70
66
	private FormToolkit toolkit = new FormToolkit(Display.getCurrent());
71
	private FormToolkit toolkit = new FormToolkit(Display.getCurrent());
72
67
	private ParametersEditor parametersEditor;
73
	private ParametersEditor parametersEditor;
68
	private Map<String, String> oldProperties;
69
74
75
	private Map<String, String> oldProperties;
70
76
71
	public WebQueryWizardPage(TaskRepository repository) {
77
	public WebQueryWizardPage(TaskRepository repository) {
72
		this(repository, null);
78
		this(repository, null);
73
	}
79
	}
74
80
75
	public WebQueryWizardPage(TaskRepository repository, WebQuery query) {
81
	public WebQueryWizardPage(TaskRepository repository, WebQuery query) {
76
		super("New web query", query==null ? getDefaultQueryTitle(repository) : query.getDescription());
82
		super("New web query", query == null ? getDefaultQueryTitle(repository) : query.getDescription());
77
		this.repository = repository;
83
		this.repository = repository;
78
		this.query = query;
84
		this.query = query;
79
		setTitle("Create web query");
85
		setTitle("Create web query");
Lines 83-97 Link Here
83
	private static String getDefaultQueryTitle(TaskRepository repository) {
89
	private static String getDefaultQueryTitle(TaskRepository repository) {
84
		String label = repository.getRepositoryLabel();
90
		String label = repository.getRepositoryLabel();
85
		String title = label;
91
		String title = label;
86
		Set<AbstractRepositoryQuery> queries = TasksUiPlugin.getTaskListManager().getTaskList().getRepositoryQueries(repository.getUrl());
92
		Set<AbstractRepositoryQuery> queries = TasksUiPlugin.getTaskListManager().getTaskList().getRepositoryQueries(
87
	    for(int n = 1; true; n++) {
93
				repository.getUrl());
94
		for (int n = 1; true; n++) {
88
			for (AbstractRepositoryQuery query : queries) {
95
			for (AbstractRepositoryQuery query : queries) {
89
				if(query.getDescription().equals(title)) {
96
				if (query.getDescription().equals(title)) {
90
					title = label + " " + n;
97
					title = label + " " + n;
91
				}
98
				}
92
			}
99
			}
93
			return title;
100
			return title;
94
	    }
101
		}
95
	}
102
	}
96
103
97
	public void createControl(Composite parent) {
104
	public void createControl(Composite parent) {
Lines 105-121 Link Here
105
112
106
		super.createControl(composite);
113
		super.createControl(composite);
107
114
108
//		Label descriptionLabel = new Label(composite, SWT.NONE);
115
		// Label descriptionLabel = new Label(composite, SWT.NONE);
109
//		descriptionLabel.setLayoutData(new GridData());
116
		// descriptionLabel.setLayoutData(new GridData());
110
//		descriptionLabel.setText("Query Title:");
117
		// descriptionLabel.setText("Query Title:");
111
118
112
//		queryTitleText = new Text(composite, SWT.BORDER);
119
		// queryTitleText = new Text(composite, SWT.BORDER);
113
//		queryTitleText.addModifyListener(new ModifyListener() {
120
		// queryTitleText.addModifyListener(new ModifyListener() {
114
//			public void modifyText(ModifyEvent e) {
121
		// public void modifyText(ModifyEvent e) {
115
//				setPageComplete(isPageComplete());
122
		// setPageComplete(isPageComplete());
116
//			}
123
		// }
117
//		});
124
		// });
118
//		queryTitleText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
125
		// queryTitleText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
126
		// false));
119
127
120
		parametersEditor = new ParametersEditor(composite, SWT.NONE);
128
		parametersEditor = new ParametersEditor(composite, SWT.NONE);
121
		GridData gridData1 = new GridData(SWT.FILL, SWT.FILL, true, true);
129
		GridData gridData1 = new GridData(SWT.FILL, SWT.FILL, true, true);
Lines 123-129 Link Here
123
		gridData1.minimumHeight = 80;
131
		gridData1.minimumHeight = 80;
124
		parametersEditor.setLayoutData(gridData1);
132
		parametersEditor.setLayoutData(gridData1);
125
133
126
		ExpandableComposite expComposite = toolkit.createExpandableComposite(composite, Section.COMPACT | Section.TWISTIE);
134
		ExpandableComposite expComposite = toolkit.createExpandableComposite(composite, Section.COMPACT
135
				| Section.TWISTIE);
127
		expComposite.setFont(parent.getFont());
136
		expComposite.setFont(parent.getFont());
128
		GridData gridData_1 = new GridData(SWT.FILL, SWT.FILL, true, false);
137
		GridData gridData_1 = new GridData(SWT.FILL, SWT.FILL, true, false);
129
		gridData_1.heightHint = 150;
138
		gridData_1.heightHint = 150;
Lines 161-173 Link Here
161
		gridData.heightHint = 45;
170
		gridData.heightHint = 45;
162
		queryPatternText.setLayoutData(gridData);
171
		queryPatternText.setLayoutData(gridData);
163
172
164
//		regexpText.addModifyListener(new ModifyListener() {
173
		// regexpText.addModifyListener(new ModifyListener() {
165
//				public void modifyText(final ModifyEvent e) {
174
		// public void modifyText(final ModifyEvent e) {
166
//					if(webPage!=null) {
175
		// if(webPage!=null) {
167
//						updatePreview();
176
		// updatePreview();
168
//					}
177
		// }
169
//				}
178
		// }
170
//			});
179
		// });
171
180
172
		Button preview = new Button(composite1, SWT.NONE);
181
		Button preview = new Button(composite1, SWT.NONE);
173
		preview.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
182
		preview.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
Lines 198-213 Link Here
198
207
199
		LinkedHashMap<String, String> vars = new LinkedHashMap<String, String>();
208
		LinkedHashMap<String, String> vars = new LinkedHashMap<String, String>();
200
		Map<String, String> params = new LinkedHashMap<String, String>();
209
		Map<String, String> params = new LinkedHashMap<String, String>();
201
		if(repository!=null) {
210
		if (repository != null) {
202
203
211
204
			queryUrlText.setText(addVars(vars, repository.getProperty(WebRepositoryConnector.PROPERTY_QUERY_URL)));
212
			queryUrlText.setText(addVars(vars, repository.getProperty(WebRepositoryConnector.PROPERTY_QUERY_URL)));
205
			queryPatternText.setText(addVars(vars, repository.getProperty(WebRepositoryConnector.PROPERTY_QUERY_REGEXP)));
213
			queryPatternText
214
					.setText(addVars(vars, repository.getProperty(WebRepositoryConnector.PROPERTY_QUERY_REGEXP)));
206
215
207
			oldProperties = repository.getProperties();
216
			oldProperties = repository.getProperties();
208
			params.putAll(oldProperties);
217
			params.putAll(oldProperties);
209
		}
218
		}
210
		if(query!=null) {
219
		if (query != null) {
211
			setTitle(query.getDescription());
220
			setTitle(query.getDescription());
212
			queryUrlText.setText(addVars(vars, query.getUrl()));
221
			queryUrlText.setText(addVars(vars, query.getUrl()));
213
			queryPatternText.setText(addVars(vars, query.getQueryPattern()));
222
			queryPatternText.setText(addVars(vars, query.getQueryPattern()));
Lines 217-226 Link Here
217
	}
226
	}
218
227
219
	private static String addVars(LinkedHashMap<String, String> vars, String property) {
228
	private static String addVars(LinkedHashMap<String, String> vars, String property) {
220
		if(property==null) {
229
		if (property == null) {
221
			return "";
230
			return "";
222
		}
231
		}
223
		for(String var : WebRepositoryConnector.getTemplateVariables(property)) {
232
		for (String var : WebRepositoryConnector.getTemplateVariables(property)) {
224
			vars.put(var, "");
233
			vars.put(var, "");
225
		}
234
		}
226
		return property;
235
		return property;
Lines 232-279 Link Here
232
		String queryPattern = queryPatternText.getText();
241
		String queryPattern = queryPatternText.getText();
233
		Map<String, String> params = parametersEditor.getParameters();
242
		Map<String, String> params = parametersEditor.getParameters();
234
		return new WebQuery(TasksUiPlugin.getTaskListManager().getTaskList(), description, queryUrl, queryPattern,
243
		return new WebQuery(TasksUiPlugin.getTaskListManager().getTaskList(), description, queryUrl, queryPattern,
235
				repository.getProperty(WebRepositoryConnector.PROPERTY_TASK_URL),
244
				repository.getProperty(WebRepositoryConnector.PROPERTY_TASK_URL), repository.getUrl(), params);
236
				repository.getUrl(), params);
237
	}
245
	}
238
246
239
	synchronized void updatePreview() {
247
	synchronized void updatePreview() {
240
		if(updatePreviewJob==null) {
248
		if (updatePreviewJob == null) {
241
			updatePreviewJob = new UpdatePreviewJob("Updating preview");
249
			updatePreviewJob = new UpdatePreviewJob("Updating preview");
242
			updatePreviewJob.setPriority(Job.DECORATE);
250
			updatePreviewJob.setPriority(Job.DECORATE);
243
		}
251
		}
244
		updatePreviewJob.setParams(queryUrlText.getText(), queryPatternText.getText(), parametersEditor.getParameters());
252
		updatePreviewJob
245
		if(!updatePreviewJob.isActive()) {
253
				.setParams(queryUrlText.getText(), queryPatternText.getText(), parametersEditor.getParameters());
254
		if (!updatePreviewJob.isActive()) {
246
			updatePreviewJob.schedule();
255
			updatePreviewJob.schedule();
247
		}
256
		}
248
	}
257
	}
249
258
250
	public boolean isPageComplete() {
259
	public boolean isPageComplete() {
251
		if(getErrorMessage()!=null) {
260
		if (getErrorMessage() != null) {
252
			return false;
261
			return false;
253
		}
262
		}
254
		return super.isPageComplete();
263
		return super.isPageComplete();
255
	}
264
	}
256
265
257
	void updatePreviewTable(List<AbstractQueryHit> hits, MultiStatus queryStatus) {
266
	void updatePreviewTable(List<AbstractQueryHit> hits, MultiStatus queryStatus) {
258
		if(previewTable.isDisposed()) {
267
		if (previewTable.isDisposed()) {
259
			return;
268
			return;
260
		}
269
		}
261
270
262
		previewTable.removeAll();
271
		previewTable.removeAll();
263
272
264
		if(hits!=null) {
273
		if (hits != null) {
265
			for (AbstractQueryHit hit : hits) {
274
			for (AbstractQueryHit hit : hits) {
266
				TableItem item = new TableItem(previewTable, SWT.NONE);
275
				TableItem item = new TableItem(previewTable, SWT.NONE);
267
				if(hit.getId()!=null) {
276
				if (hit.getId() != null) {
268
					item.setText(0, hit.getId());
277
					item.setText(0, hit.getId());
269
					if(hit.getDescription()!=null) {
278
					if (hit.getDescription() != null) {
270
						item.setText(1, hit.getDescription());
279
						item.setText(1, hit.getDescription());
271
					}
280
					}
272
				}
281
				}
273
			}
282
			}
274
		}
283
		}
275
284
276
		if(queryStatus.isOK()) {
285
		if (queryStatus.isOK()) {
277
			setErrorMessage(null);
286
			setErrorMessage(null);
278
			setPageComplete(true);
287
			setPageComplete(true);
279
		} else {
288
		} else {
Lines 288-295 Link Here
288
297
289
	private final class UpdatePreviewJob extends Job {
298
	private final class UpdatePreviewJob extends Job {
290
		private volatile String url;
299
		private volatile String url;
300
291
		private volatile String regexp;
301
		private volatile String regexp;
302
292
		private volatile Map<String, String> params;
303
		private volatile Map<String, String> params;
304
293
		private volatile boolean active = false;
305
		private volatile boolean active = false;
294
306
295
		private UpdatePreviewJob(String name) {
307
		private UpdatePreviewJob(String name) {
Lines 312-342 Link Here
312
			String evaluatedUrl = WebRepositoryConnector.evaluateParams(url, params, repository);
324
			String evaluatedUrl = WebRepositoryConnector.evaluateParams(url, params, repository);
313
			active = true;
325
			active = true;
314
			do {
326
			do {
315
				final MultiStatus queryStatus = new MultiStatus(TasksUiPlugin.PLUGIN_ID, IStatus.OK, "Query result", null);
327
				final MultiStatus queryStatus = new MultiStatus(TasksUiPlugin.PLUGIN_ID, IStatus.OK, "Query result",
328
						null);
316
				final List<AbstractQueryHit> queryHits = new ArrayList<AbstractQueryHit>();
329
				final List<AbstractQueryHit> queryHits = new ArrayList<AbstractQueryHit>();
317
				try {
330
				try {
318
					if(webPage==null) {
331
					if (webPage == null) {
319
						webPage = WebRepositoryConnector.fetchResource(evaluatedUrl, repository.getUserName(), repository.getPassword());
332
						HashMap<String, String> loginParams = new HashMap<String, String>();
333
						loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_FORM_URL, WebRepositoryConnector
334
								.evaluateParams(repository.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_FORM_URL),
335
										params, repository));
336
						loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_TOKEN_REGEXP, WebRepositoryConnector
337
								.evaluateParams(repository
338
										.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_TOKEN_REGEXP), params,
339
										repository));
340
						loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_METHOD, WebRepositoryConnector
341
								.evaluateParams(repository
342
										.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_METHOD), params,
343
										repository));
344
						loginParams.put(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_URL, WebRepositoryConnector
345
								.evaluateParams(repository
346
										.getProperty(WebRepositoryConnector.PROPERTY_LOGIN_REQUEST_URL), params,
347
										repository));
348
						for (Map.Entry<String, String> entry : repository.getProperties().entrySet()) {
349
							if (entry.getKey().startsWith(WebRepositoryConnector.LOGIN_REQUEST_PARAM_PREFIX)) {
350
								loginParams.put(entry.getKey(), entry.getValue());
351
							}
352
						}
353
						webPage = WebRepositoryConnector.fetchResource(evaluatedUrl, repository.getUserName(),
354
								repository.getPassword(), loginParams, params, repository);
320
					}
355
					}
321
356
322
					QueryHitCollector collector = new QueryHitCollector(TasksUiPlugin.getTaskListManager().getTaskList()) {
357
					QueryHitCollector collector = new QueryHitCollector(TasksUiPlugin.getTaskListManager()
358
							.getTaskList()) {
323
						@Override
359
						@Override
324
						public void addMatch(AbstractQueryHit hit) {
360
						public void addMatch(AbstractQueryHit hit) {
325
							queryHits.add(hit);
361
							queryHits.add(hit);
326
						}
362
						}
327
					};
363
					};
328
364
329
					IStatus status = WebRepositoryConnector.performQuery(webPage, evaluatedRegexp, null, monitor, collector, repository);
365
					IStatus status = WebRepositoryConnector.performQuery(webPage, evaluatedRegexp, null, monitor,
330
					if(!status.isOK()) {
366
							collector, repository);
367
					if (!status.isOK()) {
331
						queryStatus.add(status);
368
						queryStatus.add(status);
332
					}
369
					}
333
370
334
				} catch (final IOException ex) {
371
				} catch (final IOException ex) {
335
					queryStatus.add(new Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR,
372
					queryStatus.add(new Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR,
336
							"Unable to fetch resource: "+ex.getMessage(), null));
373
							"Unable to fetch resource: " + ex.getMessage(), null));
337
				} catch (final Exception ex) {
374
				} catch (final Exception ex) {
338
					queryStatus.add(new Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR,
375
					queryStatus.add(new Status(IStatus.ERROR, TasksUiPlugin.PLUGIN_ID, IStatus.ERROR, "Parsing error: "
339
							"Parsing error: "+ex.getMessage(), null));
376
							+ ex.getMessage(), null));
340
				}
377
				}
341
378
342
				Display.getDefault().asyncExec(new Runnable() {
379
				Display.getDefault().asyncExec(new Runnable() {
Lines 344-354 Link Here
344
						updatePreviewTable(queryHits, queryStatus);
381
						updatePreviewTable(queryHits, queryStatus);
345
					}
382
					}
346
				});
383
				});
347
			} while(!currentRegexp.equals(currentRegexp) && !monitor.isCanceled());
384
			} while (!currentRegexp.equals(currentRegexp) && !monitor.isCanceled());
348
			active = false;
385
			active = false;
349
			return Status.OK_STATUS;
386
			return Status.OK_STATUS;
350
		}
387
		}
351
	}
388
	}
352
389
353
}
390
}
354
(-).project (+1 lines)
Lines 24-28 Link Here
24
	<natures>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
		<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
27
	</natures>
28
	</natures>
28
</projectDescription>
29
</projectDescription>
(-)plugin.xml (+45 lines)
Lines 141-146 Link Here
141
        <attribute name="queryPattern"
141
        <attribute name="queryPattern"
142
                   value="&lt;tr .+?&lt;a href=&quot;view.php\?id=(.+?)&quot;&gt;.+?&lt;td class=&quot;left&quot;&gt;(.+?)&lt;/td&gt;&lt;/tr&gt;"/>
142
                   value="&lt;tr .+?&lt;a href=&quot;view.php\?id=(.+?)&quot;&gt;.+?&lt;td class=&quot;left&quot;&gt;(.+?)&lt;/td&gt;&lt;/tr&gt;"/>
143
     </repository>
143
     </repository>
144
     <repository
145
           anonymous="false"
146
           label="ChangeLogic"
147
           repositoryKind="web"
148
           urlNewTask="${serverUrl}/index.php?event=Add_task&amp;project_id=${projectId}"
149
           urlRepository="http://cvs.rm.sise/arendusweb"
150
           urlTask="${serverUrl}/index.php?event=Show_task&amp;task_id="
151
           urlTaskQuery="${serverUrl}/index.php?event=Show_task_list&amp;project_id=${projectId}">
152
        <attribute
153
              name="loginFormUrl"
154
              value="${serverUrl}">
155
        </attribute>
156
        <attribute
157
              name="loginTokenPattern"
158
              value="&lt;form name=&quot;Login_form&quot; method=&quot;POST&quot; action=&quot;index.php\?event\=Login&amp;amp;project_id\=0&amp;amp;link_uid\=(\p{Alnum}+?)\&quot;(?:.*?)&gt;">
159
        </attribute>
160
        <attribute
161
              name="loginRequestMethod"
162
              value="POST">
163
        </attribute>
164
        <attribute
165
              name="loginRequestUrl"
166
              value="${serverUrl}/index.php?event=Login">
167
        </attribute>
168
        <attribute
169
              name="queryPattern"
170
              value="&lt;a href=&quot;index.php\?event\=Show_task&amp;amp;task_id\=.+?&amp;amp;project_id\=${projectId}&amp;amp;recent_list_id=.+?&quot;&gt;(.+?)&lt;/a&gt;.+?&lt;/td&gt;.+?&lt;td&gt;.+?&lt;/td&gt;.+?&lt;td&gt;.+?&lt;/td&gt;.+?&lt;td&gt;.+?&lt;/td&gt;.+?&lt;td&gt;.+?&lt;/td&gt;.+?&lt;td&gt;(.+?)&lt;/td&gt;">
171
        </attribute>
172
        <attribute
173
              name="loginRequestParam_link_uid"
174
              value="${loginToken}">
175
        </attribute>
176
        <attribute
177
              name="loginRequestParam_username"
178
              value="${userId}">
179
        </attribute>
180
        <attribute
181
              name="loginRequestParam_password"
182
              value="${password}">
183
        </attribute>
184
        <attribute
185
              name="param_projectId"
186
              value="10">
187
        </attribute>
188
     </repository>
144
   </extension>
189
   </extension>
145
190
146
</plugin>
191
</plugin>
(-)src/org/eclipse/mylar/internal/tasks/web/restui/MethodTypeContentProvider.java (+28 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 Erkki Lindpere and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Erkki Lindpere - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.tasks.web.restui;
12
13
import org.eclipse.jface.viewers.IStructuredContentProvider;
14
import org.eclipse.jface.viewers.Viewer;
15
16
public class MethodTypeContentProvider implements IStructuredContentProvider {
17
18
	public Object[] getElements(Object inputElement) {
19
		return EHttpMethod.values();
20
	}
21
22
	public void dispose() {
23
	}
24
25
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
26
	}
27
28
}
(-)src/org/eclipse/mylar/internal/tasks/web/restui/NameValuePairLabelProvider.java (+37 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 Erkki Lindpere and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Erkki Lindpere - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.tasks.web.restui;
12
13
import org.eclipse.jface.viewers.ITableLabelProvider;
14
import org.eclipse.jface.viewers.LabelProvider;
15
import org.eclipse.swt.graphics.Image;
16
17
public class NameValuePairLabelProvider extends LabelProvider implements
18
		ITableLabelProvider {
19
20
	public Image getColumnImage(Object element, int columnIndex) {
21
		return getImage(element);
22
	}
23
24
	public String getColumnText(Object element, int columnIndex) {
25
		if (element instanceof NameValuePair) {
26
			NameValuePair pair = (NameValuePair) element;
27
			switch (columnIndex) {
28
			case 0:
29
				return pair.getName();
30
			case 1:
31
				return pair.getValue();
32
			}
33
		}
34
		return getText(element);
35
	}
36
37
}
(-)src/org/eclipse/mylar/internal/tasks/web/restui/EHttpMethod.java (+20 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 Erkki Lindpere and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Erkki Lindpere - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.tasks.web.restui;
12
13
/**
14
 * Represents a subset of HTTP methods: GET and POST
15
 * 
16
 * @author Erkki Lindpere
17
 */
18
public enum EHttpMethod {
19
	GET, POST
20
}
(-)src/org/eclipse/mylar/internal/tasks/web/restui/RESTRequestEditor.java (+285 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 Erkki Lindpere and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Erkki Lindpere - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.tasks.web.restui;
12
13
import org.eclipse.jface.viewers.CellEditor;
14
import org.eclipse.jface.viewers.ComboViewer;
15
import org.eclipse.jface.viewers.ICellModifier;
16
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.ISelectionChangedListener;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.jface.viewers.SelectionChangedEvent;
20
import org.eclipse.jface.viewers.StructuredSelection;
21
import org.eclipse.jface.viewers.TableViewer;
22
import org.eclipse.jface.viewers.TextCellEditor;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.graphics.Point;
25
import org.eclipse.swt.layout.GridData;
26
import org.eclipse.swt.layout.GridLayout;
27
import org.eclipse.swt.widgets.Button;
28
import org.eclipse.swt.widgets.Combo;
29
import org.eclipse.swt.widgets.Composite;
30
import org.eclipse.swt.widgets.Group;
31
import org.eclipse.swt.widgets.Label;
32
import org.eclipse.swt.widgets.Table;
33
import org.eclipse.swt.widgets.TableColumn;
34
import org.eclipse.swt.widgets.TableItem;
35
import org.eclipse.swt.widgets.Text;
36
37
public class RESTRequestEditor extends Composite {
38
39
	private Label urlLabel = null;
40
41
	private Label methodLabel = null;
42
43
	private Text urlText = null;
44
45
	private Combo methodCombo = null;
46
47
	private Group parametersGroup = null;
48
49
	private Table parametersTable = null;
50
51
	private TableViewer parametersViewer = null;
52
53
	private Composite buttonsComposite = null;
54
55
	private Button addButton = null;
56
57
	private Button removeButton = null;
58
59
	private ComboViewer comboViewer = null;
60
61
	public RESTRequestEditor(Composite parent, int style) {
62
		super(parent, style);
63
		initialize();
64
	}
65
66
	private void initialize() {
67
		GridData gridData = new GridData();
68
		gridData.grabExcessHorizontalSpace = true;
69
		gridData.verticalAlignment = GridData.CENTER;
70
		gridData.horizontalAlignment = GridData.FILL;
71
		GridLayout gridLayout = new GridLayout();
72
		gridLayout.numColumns = 2;
73
		methodLabel = new Label(this, SWT.NONE);
74
		methodLabel.setText("Method:");
75
		createMethodCombo();
76
		urlLabel = new Label(this, SWT.NONE);
77
		urlLabel.setText("URL:");
78
		urlText = new Text(this, SWT.BORDER);
79
		urlText.setLayoutData(gridData);
80
		this.setLayout(gridLayout);
81
		createParametersGroup();
82
		setSize(new Point(300, 200));
83
	}
84
85
	/**
86
	 * This method initializes methodCombo
87
	 * 
88
	 */
89
	private void createMethodCombo() {
90
		methodCombo = new Combo(this, SWT.NONE);
91
		comboViewer = new ComboViewer(methodCombo);
92
		comboViewer.setContentProvider(new MethodTypeContentProvider());
93
		comboViewer.setInput(new Object());
94
		comboViewer.setLabelProvider(new MethodTypeLabelProvider());
95
		comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
96
97
			public void selectionChanged(SelectionChangedEvent event) {
98
				updateParametersGroupEnablement(event.getSelection());
99
			}
100
101
		});
102
	}
103
104
	private void updateParametersGroupEnablement(ISelection selection) {
105
		IStructuredSelection sSel = (IStructuredSelection) selection;
106
		boolean enabled = EHttpMethod.POST.equals(sSel.getFirstElement());
107
		parametersGroup.setEnabled(enabled);
108
		parametersTable.setEnabled(enabled);
109
		updateButtonsEnablement(enabled);
110
	}
111
112
	private void updateButtonsEnablement(boolean enabled) {
113
		addButton.setEnabled(enabled);
114
		removeButton.setEnabled(enabled && !parametersViewer.getSelection().isEmpty());
115
	}
116
117
	/**
118
	 * This method initializes parametersGroup
119
	 * 
120
	 */
121
	private void createParametersGroup() {
122
		GridLayout gridLayout1 = new GridLayout();
123
		gridLayout1.numColumns = 2;
124
		GridData gridData2 = new GridData();
125
		gridData2.grabExcessHorizontalSpace = true;
126
		gridData2.horizontalAlignment = GridData.FILL;
127
		gridData2.verticalAlignment = GridData.FILL;
128
		gridData2.grabExcessVerticalSpace = true;
129
		GridData gridData1 = new GridData();
130
		gridData1.horizontalSpan = 2;
131
		gridData1.verticalAlignment = GridData.FILL;
132
		gridData1.grabExcessVerticalSpace = true;
133
		gridData1.horizontalAlignment = GridData.FILL;
134
		parametersGroup = new Group(this, SWT.NONE);
135
		parametersGroup.setEnabled(false);
136
		parametersGroup.setText("POST Parameters");
137
		parametersGroup.setLayout(gridLayout1);
138
		parametersGroup.setLayoutData(gridData1);
139
		parametersTable = new Table(parametersGroup, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
140
		parametersTable.setHeaderVisible(true);
141
		parametersTable.setLayoutData(gridData2);
142
		parametersTable.setLinesVisible(true);
143
		createButtonsComposite();
144
		TableColumn tableColumn = new TableColumn(parametersTable, SWT.NONE);
145
		tableColumn.setWidth(60);
146
		tableColumn.setText("Name");
147
		TableColumn tableColumn1 = new TableColumn(parametersTable, SWT.NONE);
148
		tableColumn1.setWidth(120);
149
		tableColumn1.setText("Value");
150
		parametersViewer = new TableViewer(parametersTable);
151
		parametersViewer.setLabelProvider(new NameValuePairLabelProvider());
152
		parametersViewer.setCellEditors(new CellEditor[] { new TextCellEditor(parametersTable),
153
				new TextCellEditor(parametersTable) });
154
		parametersViewer.setColumnProperties(new String[] { "name", "value" });
155
		parametersViewer.setCellModifier(new ICellModifier() {
156
157
			public boolean canModify(Object element, String property) {
158
				return true;
159
			}
160
161
			public Object getValue(Object element, String property) {
162
				if (element instanceof NameValuePair) {
163
					NameValuePair pair = (NameValuePair) element;
164
					if ("name".equals(property)) {
165
						return pair.getName();
166
					}
167
					if ("value".equals(property)) {
168
						return pair.getValue();
169
					}
170
				}
171
				return null;
172
			}
173
174
			public void modify(Object element, String property, Object value) {
175
				if (element instanceof TableItem) {
176
					TableItem item = (TableItem) element;
177
					element = item.getData();
178
				}
179
				if (element instanceof NameValuePair) {
180
					NameValuePair pair = (NameValuePair) element;
181
					if ("name".equals(property)) {
182
						pair.setName((String) value);
183
					}
184
					if ("value".equals(property)) {
185
						pair.setValue((String) value);
186
					}
187
					parametersViewer.refresh(element);
188
				}
189
			}
190
191
		});
192
		parametersViewer.addSelectionChangedListener(new ISelectionChangedListener() {
193
194
			public void selectionChanged(SelectionChangedEvent event) {
195
				updateButtonsEnablement(true);
196
			}
197
			
198
		});
199
	}
200
201
	/**
202
	 * This method initializes buttonsComposite
203
	 * 
204
	 */
205
	private void createButtonsComposite() {
206
		GridData gridData5 = new GridData();
207
		gridData5.horizontalAlignment = GridData.FILL;
208
		gridData5.verticalAlignment = GridData.CENTER;
209
		GridData gridData4 = new GridData();
210
		gridData4.horizontalAlignment = GridData.FILL;
211
		gridData4.verticalAlignment = GridData.CENTER;
212
		GridData gridData3 = new GridData();
213
		gridData3.horizontalAlignment = GridData.FILL;
214
		gridData3.verticalAlignment = GridData.FILL;
215
		buttonsComposite = new Composite(parametersGroup, SWT.NONE);
216
		buttonsComposite.setLayout(new GridLayout());
217
		buttonsComposite.setLayoutData(gridData3);
218
		addButton = new Button(buttonsComposite, SWT.NONE);
219
		addButton.setText("Add");
220
		addButton.setLayoutData(gridData4);
221
		addButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
222
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
223
				IStructuredSelection selection = (IStructuredSelection) parametersViewer.getSelection();
224
				Object newObject = new NameValuePair("<name>", "<value>");
225
				if (!selection.isEmpty()) {
226
					int minIndex = -1;
227
					for (int i : parametersTable.getSelectionIndices()) {
228
						if (minIndex == -1 || i < minIndex) {
229
							minIndex = i;
230
						}
231
					}
232
					parametersViewer.insert(newObject, minIndex);
233
				} else {
234
					parametersViewer.add(newObject);
235
				}
236
			}
237
		});
238
		removeButton = new Button(buttonsComposite, SWT.NONE);
239
		removeButton.setText("Remove");
240
		removeButton.setLayoutData(gridData5);
241
		removeButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
242
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
243
				IStructuredSelection selection = (IStructuredSelection) parametersViewer.getSelection();
244
				for (Object selected : selection.toArray()) {
245
					parametersViewer.remove(selected);
246
				}
247
			}
248
		});
249
	}
250
251
	public NameValuePair[] getParameters() {
252
		TableItem[] items = parametersTable.getItems();
253
		NameValuePair[] pairs = new NameValuePair[items.length];
254
		int i = 0;
255
		for (TableItem item : items) {
256
			pairs[i++] = (NameValuePair) item.getData();
257
		}
258
		return pairs;
259
	}
260
261
	public void setParameters(NameValuePair[] pairs) {
262
		parametersTable.removeAll();
263
		for (NameValuePair pair : pairs) {
264
			parametersViewer.add(pair);
265
		}
266
	}
267
268
	public String getUrl() {
269
		return urlText.getText();
270
	}
271
272
	public void setUrl(String url) {
273
		urlText.setText(url);
274
	}
275
276
	public EHttpMethod getMethod() {
277
		return (EHttpMethod) ((IStructuredSelection) comboViewer.getSelection()).getFirstElement();
278
	}
279
280
	public void setMethod(EHttpMethod method) {
281
		ISelection selection = new StructuredSelection(method);
282
		comboViewer.setSelection(selection);
283
		updateParametersGroupEnablement(selection);
284
	}
285
}
(-)src/org/eclipse/mylar/internal/tasks/web/restui/NameValuePair.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 Erkki Lindpere and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Erkki Lindpere - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.tasks.web.restui;
12
13
import java.io.Serializable;
14
15
public class NameValuePair implements Serializable {
16
	private static final long serialVersionUID = 987600743855633022L;
17
	private String name;
18
	private String value;
19
20
	public NameValuePair(String name, String value) {
21
		super();
22
		this.name = name;
23
		this.value = value;
24
	}
25
26
	public String getName() {
27
		return name;
28
	}
29
30
	public void setName(String name) {
31
		this.name = name;
32
	}
33
34
	public String getValue() {
35
		return value;
36
	}
37
38
	public void setValue(String value) {
39
		this.value = value;
40
	}
41
42
}
(-)src/org/eclipse/mylar/internal/tasks/web/restui/MethodTypeLabelProvider.java (+26 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 Erkki Lindpere and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Erkki Lindpere - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.tasks.web.restui;
12
13
import org.eclipse.jface.viewers.LabelProvider;
14
15
public class MethodTypeLabelProvider extends LabelProvider {
16
17
	@Override
18
	public String getText(Object element) {
19
		if (element instanceof EHttpMethod) {
20
			EHttpMethod type = (EHttpMethod) element;
21
			return type.name();
22
		}
23
		return super.getText(element);
24
	}
25
26
}

Return to bug 151602