1 /*
2 * $Id$
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22
23 package org.apache.struts.webapp.example;
24
25
26 import java.io.IOException;
27
28 import jakarta.faces.FacesException;
29 import jakarta.faces.context.FacesContext;
30
31
32 /**
33 * <p>Abstract base class for backing beans.</p>
34 */
35
36 abstract class AbstractBacking {
37
38
39 // ------------------------------------------------------- Protected Methods
40
41
42 /**
43 * <p>Return the context relative path for the specified action.</p>
44 *
45 * @param context <code>FacesContext</code> for the current request
46 * @param action Name of the requested action
47 */
48 protected StringBuilder action(FacesContext context, String action) {
49
50 // FIXME - assumes extension mapping for Struts
51 StringBuilder sb = new StringBuilder(action);
52 sb.append(".do");
53 return (sb);
54
55 }
56
57
58 /**
59 * <p>Forward to the specified URL and mark this response as having
60 * been completed.</p>
61 *
62 * @param context <code>FacesContext</code> for the current request
63 * @param url Context-relative URL to forward to
64 *
65 * @exception FacesException if any error occurs
66 */
67 protected void forward(FacesContext context, String url) {
68
69 try {
70 context.getExternalContext().dispatch(url);
71 } catch (IOException e) {
72 throw new FacesException(e);
73 } finally {
74 context.responseComplete();
75 }
76
77 }
78
79
80 /**
81 * <p>Return the context relative base URL for the "logoff"
82 * action.</p>
83 *
84 * @param context <code>FacesContext</code> for the current request
85 */
86 protected StringBuilder logoff(FacesContext context) {
87
88 return (action(context, "/logoff"));
89
90 }
91
92
93 /**
94 * <p>Return the context relative base URL for the "logon"
95 * action.</p>
96 *
97 * @param context <code>FacesContext</code> for the current request
98 */
99 protected StringBuilder logon(FacesContext context) {
100
101 return (action(context, "/logon"));
102
103 }
104
105
106 /**
107 * <p>Return the context relative base URL for the "edit registration"
108 * action.</p>
109 *
110 * @param context <code>FacesContext</code> for the current request
111 */
112 protected StringBuilder registration(FacesContext context) {
113
114 return (action(context, "/editRegistration"));
115
116 }
117
118
119 /**
120 * <p>Return the context relative base URL for the "edit subscriptions"
121 * action.</p>
122 *
123 * @param context <code>FacesContext</code> for the current request
124 */
125 protected StringBuilder subscription(FacesContext context) {
126
127 return (action(context, "/editSubscription"));
128
129 }
130
131
132 }