|
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 |