blob: 4367631930b1b3072d497ac7bac76c65bb42e3ba (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/*******************************************************************************
* Copyright (c) 2006, 2008 Steffen Pingel and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Steffen Pingel - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.internal.trac.core;
import java.net.MalformedURLException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylyn.commons.net.AbstractWebLocation;
import org.eclipse.mylyn.internal.trac.core.client.ITracClient;
import org.eclipse.mylyn.internal.trac.core.client.TracException;
import org.eclipse.mylyn.internal.trac.core.client.TracLoginException;
import org.eclipse.mylyn.internal.trac.core.client.TracWebClient;
import org.eclipse.mylyn.internal.trac.core.client.TracXmlRpcClient;
import org.eclipse.mylyn.internal.trac.core.client.ITracClient.Version;
/**
* @author Steffen Pingel
*/
public class TracClientFactory {
public static ITracClient createClient(AbstractWebLocation location, Version version) {
if (version == Version.TRAC_0_9) {
return new TracWebClient(location, version);
} else if (version == Version.XML_RPC) {
return new TracXmlRpcClient(location, version);
}
throw new RuntimeException("Invalid repository version: " + version); //$NON-NLS-1$
}
/**
* Tries all supported access types for <code>location</code> and returns the corresponding version if successful;
* throws an exception otherwise.
*
* <p>
* Order of the tried access types: XML-RPC, Trac 0.9
*/
public static Version probeClient(AbstractWebLocation location) throws MalformedURLException, TracException {
try {
ITracClient repository = new TracXmlRpcClient(location, Version.XML_RPC);
repository.validate(new NullProgressMonitor());
return Version.XML_RPC;
} catch (TracException e) {
try {
ITracClient repository = new TracWebClient(location, Version.TRAC_0_9);
repository.validate(new NullProgressMonitor());
return Version.TRAC_0_9;
} catch (TracLoginException e2) {
throw e;
} catch (TracException e2) {
}
}
throw new TracException();
}
}
|