001package org.nuxeo.apidoc.browse; 002 003import javax.ws.rs.GET; 004import javax.ws.rs.Path; 005import javax.ws.rs.PathParam; 006import javax.ws.rs.Produces; 007import javax.ws.rs.core.Response; 008 009import org.nuxeo.ecm.webengine.model.WebObject; 010import org.nuxeo.ecm.webengine.model.impl.DefaultObject; 011 012@WebObject(type = "redirectWO") 013@Produces("text/html") 014public class RedirectResource extends DefaultObject { 015 016 protected String orgDistributionId = null; 017 018 protected String targetDistributionId = null; 019 020 @Override 021 protected void initialize(Object... args) { 022 orgDistributionId = (String) args[0]; 023 targetDistributionId = (String) args[1]; 024 targetDistributionId = targetDistributionId.replace(" ", "%20"); 025 } 026 027 @GET 028 @Produces("text/html") 029 public Object get() { 030 return newLocation(targetDistributionId, null); 031 } 032 033 @GET 034 @Produces("text/html") 035 @Path("/{subPath:.*}") 036 public Object catchAll(@PathParam("subPath") String subPath) { 037 return newLocation(targetDistributionId, subPath); 038 } 039 040 protected Response newLocation(String target, String subPath) { 041 String path = getPrevious().getPath(); 042 String url = ctx.getServerURL().append(path).append("/" + target).toString(); 043 if (subPath != null) { 044 url = url + "/" + subPath; 045 } 046 return redirect(url); 047 } 048 049}