KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > util > common > HardURLConverterChainUtil


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.util.common;
21
22 import za.org.coefficient.core.HardURLConverter;
23
24 /**
25  *
26  * @author <a HREF="mailto:detkin@csir.co.za">Dylan Etkin</a>
27  */

28 public class HardURLConverterChainUtil {
29
30     //~ Instance fields ========================================================
31

32     private static HardURLConverter converter;
33
34     //~ Methods ================================================================
35

36     /**
37      * This method is used to register a new URL converter into the chain.
38      *
39      * @param val is the implementation of HardURLConverter to add to the
40      * chain.
41      */

42     public static void addConverter(HardURLConverter val) {
43         if (val == null) {
44             throw new IllegalArgumentException JavaDoc("Cannot add a null URL converter");
45         }
46         if (converter == null) {
47             converter = val;
48         } else {
49             converter.append(val);
50         }
51     }
52
53     /**
54      * Will pass the url throught the registered URL converters returing a
55      * new converted URL if one of the converters could handle the url.
56      *
57      * @param url is the URL that came in the request
58      * @return is the URL that should be redirected to, null if none of the
59      * registered converters could handle the URL.
60      */

61     public static String JavaDoc execute(String JavaDoc url) {
62         String JavaDoc newURL = null;
63         try {
64             if (converter != null) {
65                 newURL = converter.invoke(url);
66             }
67         } catch (Exception JavaDoc e) {
68             e.printStackTrace();
69         }
70         return newURL;
71     }
72 }
Popular Tags