use of org.xwiki.resource.CreateResourceReferenceException in project xwiki-platform by xwiki.
the class RoutingFilter method constructExtendedURL.
private ExtendedURL constructExtendedURL(HttpServletRequest httpRequest) throws ServletException {
ExtendedURL extendedURL;
URL url = getRequestURL(httpRequest);
try {
extendedURL = new ExtendedURL(url, httpRequest.getContextPath());
} catch (CreateResourceReferenceException e) {
throw new ServletException(String.format("Invalid URL [%s]", url), e);
}
return extendedURL;
}
use of org.xwiki.resource.CreateResourceReferenceException in project xwiki-platform by xwiki.
the class ExtendedURLTemporaryResourceReferenceResolver method resolve.
@Override
public TemporaryResourceReference resolve(ExtendedURL extendedURL, ResourceType resourceType, Map<String, Object> parameters) throws CreateResourceReferenceException, UnsupportedResourceReferenceException {
TemporaryResourceReference reference;
List<String> segments = extendedURL.getSegments();
if (segments.size() < 3) {
throw new CreateResourceReferenceException(String.format("Invalid temporary resource URL format [%s].", extendedURL.toString()));
} else {
// The first segment is the module id.
String moduleId = segments.get(0);
// The second segment is the serialized owning entity reference. This is used to check access rights.
EntityReference owningEntityReference = resolveEntityReference(segments.get(1));
// The other segments point to the resource path.
List<String> resourcePath = segments.subList(2, segments.size());
reference = new TemporaryResourceReference(moduleId, resourcePath, owningEntityReference);
copyParameters(extendedURL, reference);
}
return reference;
}
use of org.xwiki.resource.CreateResourceReferenceException in project xwiki-platform by xwiki.
the class DefaultResourceReferenceResolver method resolve.
@Override
public ResourceReference resolve(ExtendedURL extendedURL, ResourceType type, Map<String, Object> parameters) throws CreateResourceReferenceException, UnsupportedResourceReferenceException {
ResourceReferenceResolver resolver;
// Step 1: Look for a URL-scheme-specific Resolver (a general one that is independent of the passed
// Resource Type). This allows URL-scheme implementation to completely override handling of any
// Resource Type if they wish.
DefaultParameterizedType parameterizedType = new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class);
String hint = this.configuration.getURLFormatId();
if (this.componentManager.hasComponent(parameterizedType, hint)) {
try {
resolver = this.componentManager.getInstance(parameterizedType, hint);
} catch (ComponentLookupException e) {
throw new CreateResourceReferenceException(String.format("Failed to create Resource Reference for [%s].", extendedURL.getWrappedURL()), e);
}
} else {
// Step 2: If not found, use the Generic Resolver, which tries to find a Resolver registered for the
// specific Resource Type.
resolver = this.genericResourceReferenceResolver;
}
return resolver.resolve(extendedURL, type, parameters);
}
use of org.xwiki.resource.CreateResourceReferenceException in project xwiki-platform by xwiki.
the class VfsResourceReferenceResolver method resolve.
@Override
public VfsResourceReference resolve(ExtendedURL extendedURL, ResourceType resourceType, Map<String, Object> parameters) throws CreateResourceReferenceException, UnsupportedResourceReferenceException {
List<String> segments = extendedURL.getSegments();
// First segment is the url-encoded VFS reference, defined as URI
URI vfsUri;
try {
vfsUri = new URI(segments.get(0));
} catch (URISyntaxException e) {
throw new CreateResourceReferenceException(String.format("Invalid VFS URI [%s] for URL [%s]", segments.get(0), extendedURL));
}
// Other segments are the path to the archive resource
List<String> vfsPathSegments = new ArrayList<>(segments);
vfsPathSegments.remove(0);
VfsResourceReference vfsReference = new VfsResourceReference(vfsUri, vfsPathSegments);
copyParameters(extendedURL, vfsReference);
return vfsReference;
}
use of org.xwiki.resource.CreateResourceReferenceException in project xwiki-platform by xwiki.
the class EntityResourceReferenceResolver method resolve.
@Override
public EntityResourceReference resolve(ExtendedURL extendedURL, ResourceType resourceType, Map<String, Object> parameters) throws CreateResourceReferenceException, UnsupportedResourceReferenceException {
EntityResourceReference entityURL;
// UC1: <action>/<entity reference type>/<entity reference>
// UC2: <action>/<entity reference> ==> type = page
// UC3: <entity reference> ==> type = page, action = view
List<String> pathSegments = extendedURL.getSegments();
String action = ACTION_VIEW;
EntityType entityType;
String entityReferenceAsString;
if (pathSegments.size() == 3) {
action = pathSegments.get(0);
entityType = computeEntityType(pathSegments.get(1));
entityReferenceAsString = pathSegments.get(2);
} else if (pathSegments.size() == 2) {
action = pathSegments.get(0);
entityType = computeDefaultEntityType(action);
entityReferenceAsString = pathSegments.get(1);
} else if (pathSegments.size() == 1) {
entityType = computeDefaultEntityType(action);
entityReferenceAsString = pathSegments.get(0);
} else {
throw new CreateResourceReferenceException(String.format("Invalid Entity URL [%s]", extendedURL.serialize()));
}
// Convert the string representation of the Entity reference into a proper EntityResourceReference.
entityURL = new EntityResourceReference(this.defaultEntityReferenceResolver.resolve(entityReferenceAsString, entityType), EntityResourceAction.fromString(action));
return entityURL;
}
Aggregations