use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.
the class ResourceReferenceHandlerServlet method getResourceReferenceResolver.
private ResourceReferenceResolver<ExtendedURL> getResourceReferenceResolver() throws ServletException {
ResourceReferenceResolver<ExtendedURL> urlResolver;
try {
Type role = new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class);
urlResolver = this.rootComponentManager.getInstance(role);
} catch (ComponentLookupException e) {
// Should not happen since a URL provider should exist on the system.
throw new ServletException("Failed to locate an ExtendedURL Resource Reference Resolver component", e);
}
return urlResolver;
}
use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.
the class ResourceReferenceHandlerServlet method getResourceReference.
private ResourceReference getResourceReference(HttpServletRequest httpRequest) throws ServletException {
// Get the Resource Type from the request's attribute, where it's been put by the RoutingFilter.
ResourceType resourceType = (ResourceType) httpRequest.getAttribute(RoutingFilter.RESOURCE_TYPE_NAME);
// Get the ExtendedURL from the request's attribute too (so that we don't have to compute it again).
ExtendedURL extendedURL = (ExtendedURL) httpRequest.getAttribute(RoutingFilter.RESOURCE_EXTENDEDURL);
// Extract the Resource Reference, passing the already extracted Resource Type
ResourceReferenceResolver<ExtendedURL> urlResolver = getResourceReferenceResolver();
try {
// the store.
return urlResolver.resolve(extendedURL, resourceType, Collections.<String, Object>emptyMap());
} catch (Exception e) {
// This shouldn't happen, raise an exception
throw new ServletException(String.format("Failed to extract the Resource Reference from the URL [%s]", extendedURL.getWrappedURL()), e);
}
}
use of org.xwiki.url.ExtendedURL 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.url.ExtendedURL in project xwiki-platform by xwiki.
the class RoutingFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// Only handle HTTP Servlet requests...
if (!(request instanceof HttpServletRequest)) {
chain.doFilter(request, response);
return;
}
HttpServletRequest httpRequest = (HttpServletRequest) request;
// Step 1: Construct an ExtendedURL to make it easy to manipulate the URL segments
ExtendedURL extendedURL = constructExtendedURL(httpRequest);
// Step 2: Extract the Resource Type from the ExtendedURL
ResourceTypeResolver<ExtendedURL> urlResourceTypeResolver = getResourceTypeResolver();
ResourceType resourceType;
try {
resourceType = urlResourceTypeResolver.resolve(extendedURL, Collections.<String, Object>emptyMap());
} catch (Exception e) {
// Failed to resolve the passed ExtendedURL. This means it's not a URL that should be handled by a Resource
// Reference Handler and we let it go through so that the next Filter or Servlet from web.xml will handle
// it. Note that since some URL schemes may want to handle features like short URLs where the Resource Type
// is omitted, this catch will not be called in this case and this is why we need Step 2 below in order
// to recognize static resources and serve them!
chain.doFilter(request, response);
return;
}
// content of web.xml and would serve static files using its File Servlet.
if (resourceType.equals(ResourcesResourceReference.TYPE) || resourceType.equals(SkinsResourceReference.TYPE)) {
chain.doFilter(request, response);
return;
}
// Step 4: Check if there's a Handler available for the Resource Type
ResourceReferenceHandlerManager<ResourceType> resourceReferenceHandlerManager = getResourceReferenceHandlerManager();
// "rest", "webdav" and "xmlrpc" Resource Types.
if (!resourceReferenceHandlerManager.canHandle(resourceType)) {
// Let it go through so that the next Filter or Servlet from web.xml will handle it.
chain.doFilter(request, response);
return;
}
// Step 4: There is a Handler to handle our request, call the Resource Handler Servlet. Note that calling a
// Sevlet gives us more flexibility if we wish to execute some more Filters before the Servlet executes for
// example.
//
// However before doing that, we save the Resource Type so that the Servlet doesn't have to extract it again!
// We also save the URL since we don't want to have to compute the full URL again in the Resource Reference
// Handler Servlet!
request.setAttribute(RESOURCE_TYPE_NAME, resourceType);
request.setAttribute(RESOURCE_EXTENDEDURL, extendedURL);
this.servletContext.getNamedDispatcher("resourceReferenceHandler").forward(request, response);
}
use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.
the class ExtendedURLTemporaryResourceReferenceSerializer method serialize.
@Override
public ExtendedURL serialize(TemporaryResourceReference reference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException {
List<String> segments = new LinkedList<String>();
segments.add("tmp");
segments.add(reference.getModuleId());
segments.add(serialize(reference.getOwningEntityReference()));
segments.addAll(reference.getResourcePath());
// A modifiable map is used here so parameters can be added to the URL later.
Map<String, List<String>> parameters = new HashMap<String, List<String>>(reference.getParameters());
ExtendedURL result = new ExtendedURL(segments, parameters);
return this.extendedURLNormalizer.normalize(result);
}
Aggregations