1 19 20 package za.org.coefficient.modules.project; 21 22 import za.org.coefficient.core.HardURLConverter; 23 import za.org.coefficient.core.Constants; 24 import za.org.coefficient.core.Project; 25 import za.org.coefficient.util.common.InvokerFactory; 26 27 import org.apache.commons.lang.StringUtils; 28 29 import java.io.UnsupportedEncodingException ; 30 31 import java.net.URLDecoder ; 32 33 38 public class ProjectHardURLConverter extends HardURLConverter { 39 40 private static final String SLASH = "/"; 41 42 44 protected String handleInvoke(String url) throws Exception { 45 String retVal = null; 46 47 if (url != null && 48 (url.indexOf(SLASH + ProjectConstants.PROJECT_NAME + SLASH) != -1)) { 49 String servletPath = url.substring(0, url.indexOf(SLASH + ProjectConstants.PROJECT_NAME + SLASH)); 51 52 int slashIdx = url.lastIndexOf(SLASH); 53 int end = url.length(); 54 if(slashIdx + 1 < end) { 55 String projectShortName = url.substring(slashIdx + 1, end); 56 try { 58 projectShortName = URLDecoder.decode(projectShortName, "UTF-8"); 59 } catch(UnsupportedEncodingException uee) { 60 } 62 63 Project project = null; 65 66 try { 67 project = (Project)InvokerFactory.getRemoteInvoker() 68 .invokeMethodOnModule("Project", "findProjectByShortName", 69 new Object [] {projectShortName}); 70 } catch (Exception e) { 71 e.printStackTrace(); 72 System.err.println("<< problem invoking project module to lookup by name"); 73 } 74 if(project != null) { 75 retVal = servletPath 76 + "index.html?module=Project&projectId=" 77 + project.getId() + "&clearProject=true"; 78 } else { 79 retVal = servletPath 80 + "index.html?module=Error&errorMsg=The%20" 81 + ProjectConstants.PROJECT_NAME + "%20of%20shortname%20" 82 + projectShortName + "%20does%20not%20exist"; 83 } 84 } 85 } 86 return retVal; 87 } 88 } 89 | Popular Tags |