KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > modules > project > ProjectHardURLConverter


1 /*
2  * Coefficient - facilitates project based collaboration
3  * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
4  * PO Box 395
5  * Pretoria 0001, RSA
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

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 JavaDoc;
30
31 import java.net.URLDecoder JavaDoc;
32
33 /**
34  *
35  * @version $Revision: 1.5 $ $Date: 2004/11/24 12:02:52 $
36  * @author <a HREF="mailto:detkin@csir.co.za">Dylan Etkin</a>
37  */

38 public class ProjectHardURLConverter extends HardURLConverter {
39
40     private static final String JavaDoc SLASH = "/";
41
42     //~ Methods ================================================================
43

44     protected String JavaDoc handleInvoke(String JavaDoc url) throws Exception JavaDoc {
45         String JavaDoc retVal = null;
46
47         if (url != null &&
48             (url.indexOf(SLASH + ProjectConstants.PROJECT_NAME + SLASH) != -1)) {
49             // Get the prefix context of the url
50
String JavaDoc 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 JavaDoc projectShortName = url.substring(slashIdx + 1, end);
56                 // decode the string
57
try {
58                     projectShortName = URLDecoder.decode(projectShortName, "UTF-8");
59                 } catch(UnsupportedEncodingException JavaDoc uee) {
60                     // do nothing
61
}
62                 
63                 // Lookup the project by name and redirect if found
64
Project project = null;
65                 
66                 try {
67                     project = (Project)InvokerFactory.getRemoteInvoker()
68                         .invokeMethodOnModule("Project", "findProjectByShortName",
69                                               new Object JavaDoc[] {projectShortName});
70                 } catch (Exception JavaDoc 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