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 155904
Collapse All | Expand All

(-)src/org/eclipse/mylar/internal/sandbox/web/WebQueryWizardPage.java (-7 / +3 lines)
Lines 57-63 Link Here
57
	private Text regexpText;
57
	private Text regexpText;
58
	private Table previewTable;
58
	private Table previewTable;
59
	
59
	
60
	private StringBuffer webPage;
60
	private String webPage;
61
	
61
	
62
	private TaskRepository repository;
62
	private TaskRepository repository;
63
	private AbstractRepositoryConnector connector;
63
	private AbstractRepositoryConnector connector;
Lines 267-286 Link Here
267
			active = true;
267
			active = true;
268
			do {
268
			do {
269
				final MultiStatus queryStatus = new MultiStatus(TasksUiPlugin.PLUGIN_ID, IStatus.OK, "Query result", null);
269
				final MultiStatus queryStatus = new MultiStatus(TasksUiPlugin.PLUGIN_ID, IStatus.OK, "Query result", null);
270
				final List<AbstractQueryHit> hits = new ArrayList<AbstractQueryHit>();
270
				final List<AbstractQueryHit> queryHits = new ArrayList<AbstractQueryHit>();
271
				try {
271
				try {
272
					if(webPage==null) {
272
					if(webPage==null) {
273
						webPage = WebRepositoryConnector.fetchResource(currentUrl);
273
						webPage = WebRepositoryConnector.fetchResource(currentUrl);
274
					}
274
					}
275
275
276
					AbstractQueryHitCollector collector = new AbstractQueryHitCollector(TasksUiPlugin.getTaskListManager().getTaskList()) {
276
					AbstractQueryHitCollector collector = new AbstractQueryHitCollector(TasksUiPlugin.getTaskListManager().getTaskList()) {
277
278
						@Override
277
						@Override
279
						public void addMatch(AbstractQueryHit hit) {
278
						public void addMatch(AbstractQueryHit hit) {
280
							hits.add(hit);
279
							queryHits.add(hit);
281
							
282
						}
280
						}
283
						
284
					};
281
					};
285
					
282
					
286
					// TODO: Handle returned status
283
					// TODO: Handle returned status
Lines 294-300 Link Here
294
							"Parsing error: "+ex.getMessage(), null));
291
							"Parsing error: "+ex.getMessage(), null));
295
				}
292
				}
296
				
293
				
297
				final List<AbstractQueryHit> queryHits = hits;
298
				Display.getDefault().asyncExec(new Runnable() {
294
				Display.getDefault().asyncExec(new Runnable() {
299
					public void run() {
295
					public void run() {
300
						updatePreviewTable(queryHits, queryStatus);
296
						updatePreviewTable(queryHits, queryStatus);
(-)src/org/eclipse/mylar/internal/sandbox/web/WebRepositoryConnector.java (-38 / +43 lines)
Lines 11-31 Link Here
11
11
12
package org.eclipse.mylar.internal.sandbox.web;
12
package org.eclipse.mylar.internal.sandbox.web;
13
13
14
import java.io.BufferedReader;
15
import java.io.IOException;
14
import java.io.IOException;
16
import java.io.InputStream;
15
import java.net.Proxy;
17
import java.io.InputStreamReader;
18
import java.net.URL;
19
import java.util.Collections;
16
import java.util.Collections;
20
import java.util.List;
17
import java.util.List;
21
import java.util.Set;
18
import java.util.Set;
22
import java.util.regex.Matcher;
19
import java.util.regex.Matcher;
23
import java.util.regex.Pattern;
20
import java.util.regex.Pattern;
24
21
22
import org.apache.commons.httpclient.Header;
23
import org.apache.commons.httpclient.HttpClient;
24
import org.apache.commons.httpclient.methods.GetMethod;
25
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.IProgressMonitor;
27
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.IStatus;
28
import org.eclipse.core.runtime.Status;
28
import org.eclipse.core.runtime.Status;
29
import org.eclipse.mylar.internal.tasks.core.WebClientUtil;
29
import org.eclipse.mylar.internal.tasks.core.WebTask;
30
import org.eclipse.mylar.internal.tasks.core.WebTask;
30
import org.eclipse.mylar.internal.tasks.ui.RetrieveTitleFromUrlJob;
31
import org.eclipse.mylar.internal.tasks.ui.RetrieveTitleFromUrlJob;
31
import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector;
32
import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector;
Lines 179-185 Link Here
179
	}
180
	}
180
	
181
	
181
	
182
	
182
	public static IStatus performQuery(StringBuffer resource, String regexp, String taskPrefix, String repositoryUrl, IProgressMonitor monitor, IQueryHitCollector collector) {
183
	public static IStatus performQuery(String resource, String regexp, String taskPrefix, String repositoryUrl, IProgressMonitor monitor, IQueryHitCollector collector) {
183
		//List<AbstractQueryHit> hits = new ArrayList<AbstractQueryHit>();
184
		//List<AbstractQueryHit> hits = new ArrayList<AbstractQueryHit>();
184
		
185
		
185
		Pattern p = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL | Pattern.UNICODE_CASE | Pattern.CANON_EQ);
186
		Pattern p = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL | Pattern.UNICODE_CASE | Pattern.CANON_EQ);
Lines 215-256 Link Here
215
		}
216
		}
216
	}
217
	}
217
218
218
	// TODO use commons http client
219
	public static String fetchResource(String url) throws IOException {
219
	public static StringBuffer fetchResource(String url) throws IOException {
220
		HttpClient client = new HttpClient();
220
		URL u = new URL(url);
221
		Proxy proxySettings = TasksUiPlugin.getDefault().getProxySettings();
221
		InputStream is = null;
222
		WebClientUtil.setupHttpClient(client, proxySettings, url);
223
		
224
		GetMethod get = new GetMethod(url);
222
		try {
225
		try {
223
			is = u.openStream();
226
			client.executeMethod(get);
224
		    BufferedReader r = new BufferedReader(new InputStreamReader(is));
227
			
225
228
			Header refreshHeader = get.getResponseHeader("Refresh");
226
		    StringBuffer resource = new StringBuffer();
229
			if(refreshHeader!=null) {
227
		    String line;
230
				String value = refreshHeader.getValue();
228
		    while(true) {
231
				int n = value.indexOf(";url=");
229
		    	int retryCount = 0;
232
				if(n!=-1) {
230
		    	do {
233
					value = value.substring(n + 5);
231
		    		if(retryCount>0) {
234
					
232
		    			try {
235
					int requestPath;
233
							Thread.sleep(1000L);
236
					if(value.charAt(0)=='/') {
234
						} catch (InterruptedException ex) {
237
						int colonSlashSlash = url.indexOf("://");
235
							// ignore
238
						requestPath = url.indexOf('/', colonSlashSlash + 3);
236
						}
239
					} else {
237
		    		}
240
						requestPath = url.lastIndexOf('/');
238
		    		line = r.readLine();
241
					}
239
		    		retryCount++;
242
					
240
		    	} while(line==null && retryCount<5);
243
					String refreshUrl;
241
		    	if(line==null) {
244
					if (requestPath==-1) {
242
		    		break;
245
						refreshUrl = url + "/" + value;
243
		    	}
246
					} else {
244
		    	resource.append(line).append("\n");
247
						refreshUrl = url.substring(0, requestPath+1) + value;
245
		    }
248
					}
246
		    return resource;
249
					
247
		    
250
					get = new GetMethod(refreshUrl);
248
		} finally {
251
					client.executeMethod(get);
249
			if(is!=null) {
252
				}
250
				is.close();
251
			}
253
			}
254
			
255
			return get.getResponseBodyAsString();
256
		} finally {
257
			get.releaseConnection();
252
		}
258
		}
253
		
254
	}
259
	}
255
260
256
	@Override
261
	@Override

Return to bug 155904