001 package com.khubla.pragmatach.framework.controller.impl.redirect; 002 003 import java.net.URI; 004 import java.net.URLEncoder; 005 006 import com.khubla.pragmatach.framework.api.PragmatachException; 007 import com.khubla.pragmatach.framework.api.Response; 008 import com.khubla.pragmatach.framework.controller.impl.AbstractController; 009 010 /** 011 * @author tome 012 */ 013 public class RedirectController extends AbstractController { 014 /** 015 * uri 016 */ 017 private final URI uri; 018 019 public RedirectController(String uri) throws PragmatachException { 020 try { 021 this.uri = new URI(uri); 022 } catch (final Exception e) { 023 throw new PragmatachException(e); 024 } 025 } 026 027 public RedirectController(String uri, String[] parameters) throws PragmatachException { 028 try { 029 String completeURI = uri; 030 if (null != parameters) { 031 for (final String parameter : parameters) { 032 completeURI += "/" + URLEncoder.encode(parameter, "UTF-8"); 033 } 034 } 035 this.uri = new URI(completeURI); 036 } catch (final Exception e) { 037 throw new PragmatachException(e); 038 } 039 } 040 041 public Response render() throws PragmatachException { 042 return new RedirectResponse(getCacheHeaders(), uri.toASCIIString()); 043 } 044 }