| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.resource.temporary.internal; |
| 21 |
|
|
| 22 |
|
import java.util.List; |
| 23 |
|
import java.util.Map; |
| 24 |
|
|
| 25 |
|
import javax.inject.Inject; |
| 26 |
|
import javax.inject.Named; |
| 27 |
|
import javax.inject.Singleton; |
| 28 |
|
|
| 29 |
|
import org.xwiki.component.annotation.Component; |
| 30 |
|
import org.xwiki.model.EntityType; |
| 31 |
|
import org.xwiki.model.reference.EntityReference; |
| 32 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
| 33 |
|
import org.xwiki.resource.CreateResourceReferenceException; |
| 34 |
|
import org.xwiki.resource.ResourceType; |
| 35 |
|
import org.xwiki.resource.UnsupportedResourceReferenceException; |
| 36 |
|
import org.xwiki.resource.temporary.TemporaryResourceReference; |
| 37 |
|
import org.xwiki.url.ExtendedURL; |
| 38 |
|
import org.xwiki.url.internal.AbstractResourceReferenceResolver; |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
@link@link |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
@version |
| 45 |
|
@since |
| 46 |
|
@since |
| 47 |
|
@since |
| 48 |
|
|
| 49 |
|
@Component |
| 50 |
|
@Named("standard/tmp") |
| 51 |
|
@Singleton |
| |
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 5 |
Complexity Density: 0.28 |
|
| 52 |
|
public class ExtendedURLTemporaryResourceReferenceResolver extends AbstractResourceReferenceResolver |
| 53 |
|
{ |
| 54 |
|
@Inject |
| 55 |
|
@Named("url") |
| 56 |
|
private EntityReferenceResolver<String> urlEntityReferenceResolver; |
| 57 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
| 58 |
0 |
@Override... |
| 59 |
|
public TemporaryResourceReference resolve(ExtendedURL extendedURL, ResourceType resourceType, |
| 60 |
|
Map<String, Object> parameters) throws CreateResourceReferenceException, UnsupportedResourceReferenceException |
| 61 |
|
{ |
| 62 |
0 |
TemporaryResourceReference reference; |
| 63 |
0 |
List<String> segments = extendedURL.getSegments(); |
| 64 |
|
|
| 65 |
0 |
if (segments.size() < 3) { |
| 66 |
0 |
throw new CreateResourceReferenceException( |
| 67 |
|
String.format("Invalid temporary resource URL format [%s].", extendedURL.toString())); |
| 68 |
|
} else { |
| 69 |
|
|
| 70 |
0 |
String moduleId = segments.get(0); |
| 71 |
|
|
| 72 |
0 |
EntityReference owningEntityReference = resolveEntityReference(segments.get(1)); |
| 73 |
|
|
| 74 |
0 |
List<String> resourcePath = segments.subList(2, segments.size()); |
| 75 |
0 |
reference = new TemporaryResourceReference(moduleId, resourcePath, owningEntityReference); |
| 76 |
0 |
copyParameters(extendedURL, reference); |
| 77 |
|
} |
| 78 |
0 |
return reference; |
| 79 |
|
} |
| 80 |
|
|
| |
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 81 |
0 |
private EntityReference resolveEntityReference(String representation) throws CreateResourceReferenceException... |
| 82 |
|
{ |
| 83 |
0 |
int index = representation.indexOf(':'); |
| 84 |
0 |
if (index > 0) { |
| 85 |
0 |
String entityTypeString = representation.substring(0, index); |
| 86 |
0 |
try { |
| 87 |
0 |
EntityType entityType = EntityType.valueOf(entityTypeString.toUpperCase()); |
| 88 |
0 |
return this.urlEntityReferenceResolver.resolve(representation.substring(index + 1), entityType); |
| 89 |
|
} catch (Exception e) { |
| 90 |
0 |
throw new CreateResourceReferenceException( |
| 91 |
|
String.format("Unknown entity type [%s].", entityTypeString)); |
| 92 |
|
} |
| 93 |
|
} else { |
| 94 |
0 |
throw new CreateResourceReferenceException( |
| 95 |
|
String.format("Entity type is missing from [%s].", representation)); |
| 96 |
|
} |
| 97 |
|
} |
| 98 |
|
} |