KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > GenericResult


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.controller;
8
9
10 import java.net.URISyntaxException JavaDoc;
11
12 import javax.servlet.http.HttpServletRequest JavaDoc;
13
14 import com.inversoft.verge.util.url.URLGenerator;
15 import com.inversoft.verge.util.url.config.CategoryConfig;
16
17
18 /**
19  * <p>
20  * This class is a generic result that can be used whenever
21  * a Result object is required, but nothing more than a URL
22  * and a category are needed.
23  * </p>
24  *
25  * @author Brian Pontarelli
26  */

27 public class GenericResult implements Result {
28     
29     protected String JavaDoc url;
30     protected String JavaDoc category;
31     protected boolean forward;
32
33
34     /**
35      * Constructs a new empty <code>Result</code>.
36      */

37     protected GenericResult() {
38     }
39
40     /**
41      * Constructs a new <code>Result</code> with the given URL and category.
42      * Forward flag is set to false
43      */

44     public GenericResult(String JavaDoc url, String JavaDoc category) {
45         this.url = url;
46         this.category = category;
47     }
48
49     /**
50      * Constructs a new <code>Result</code> with the given URL and category and
51      * the forward flag.
52      */

53     public GenericResult(String JavaDoc url, String JavaDoc category, boolean forward) {
54         this.url = url;
55         this.category = category;
56         this.forward = forward;
57     }
58
59     
60     /**
61      * Returns the URL passed into the constructor or setup by a sub-class.
62      */

63     public String JavaDoc getURL() {
64         return url;
65     }
66
67     /**
68      * Returns the forward passed into the constructor or setup by a sub-class.
69      * If nothing setup this value, it defaults to false.
70      */

71     public boolean isForward() {
72         return forward;
73     }
74
75     /**
76      * Returns the category passed to the constructor or setup by a sub-class.
77      */

78     public String JavaDoc getCategory() {
79         return category;
80     }
81
82     /**
83      * Returns the fully generated URL if this Result is not a forward and has
84      * a URL and possibly a category.
85      */

86     public String JavaDoc getGeneratedURL(HttpServletRequest JavaDoc request)
87     throws URISyntaxException JavaDoc {
88         String JavaDoc ret = null;
89         if (isForward()) {
90             ret = getURL();
91         } else {
92             CategoryConfig cc = URLGenerator.getCategory(request, category);
93             ret = URLGenerator.generateURL(cc, url, true, request);
94         }
95
96         return ret;
97     }
98 }
Popular Tags