| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.rest.internal.url; |
| 21 |
|
|
| 22 |
|
import java.net.MalformedURLException; |
| 23 |
|
import java.net.URI; |
| 24 |
|
import java.net.URISyntaxException; |
| 25 |
|
import java.net.URL; |
| 26 |
|
|
| 27 |
|
import javax.inject.Inject; |
| 28 |
|
import javax.inject.Provider; |
| 29 |
|
|
| 30 |
|
import org.xwiki.rest.XWikiRestException; |
| 31 |
|
import org.xwiki.rest.url.ParametrizedRestURLGenerator; |
| 32 |
|
|
| 33 |
|
import com.xpn.xwiki.XWiki; |
| 34 |
|
import com.xpn.xwiki.XWikiContext; |
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
@param |
| 40 |
|
@version |
| 41 |
|
@since |
| 42 |
|
|
| |
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 3 |
Complexity Density: 0.25 |
|
| 43 |
|
public abstract class AbstractParametrizedRestURLGenerator<T> implements ParametrizedRestURLGenerator<T> |
| 44 |
|
{ |
| 45 |
|
@Inject |
| 46 |
|
protected Provider<XWikiContext> contextProvider; |
| 47 |
|
|
| |
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 3 |
Complexity Density: 0.25 |
|
| 48 |
1083 |
protected URI getBaseURI() throws XWikiRestException... |
| 49 |
|
{ |
| 50 |
1083 |
try { |
| 51 |
1083 |
XWikiContext context = contextProvider.get(); |
| 52 |
1083 |
XWiki xwiki = context.getWiki(); |
| 53 |
|
|
| 54 |
1083 |
StringBuilder url = new StringBuilder(); |
| 55 |
|
|
| 56 |
1083 |
url.append(context.getURLFactory().getServerURL(context)); |
| 57 |
|
|
| 58 |
1083 |
url.append('/'); |
| 59 |
|
|
| 60 |
1083 |
String webAppPath = xwiki.getWebAppPath(context); |
| 61 |
1083 |
if (!webAppPath.equals("/")) { |
| 62 |
1083 |
url.append(webAppPath); |
| 63 |
|
} |
| 64 |
|
|
| 65 |
1083 |
url.append("rest"); |
| 66 |
|
|
| 67 |
1083 |
return new URI(url.toString()); |
| 68 |
|
} catch (URISyntaxException | MalformedURLException e) { |
| 69 |
0 |
throw new XWikiRestException("Failed to generate a proper base URI.", e); |
| 70 |
|
} |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
@Override |
| 74 |
|
public abstract URL getURL(T reference) throws XWikiRestException; |
| 75 |
|
} |