001: /*
002: * $Id: AbstractBacking.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: package org.apache.struts.webapp.example;
023:
024: import java.io.IOException;
025: import javax.faces.FacesException;
026: import javax.faces.context.FacesContext;
027:
028: /**
029: * <p>Abstract base class for backing beans.</p>
030: */
031:
032: abstract class AbstractBacking {
033:
034: // ------------------------------------------------------- Protected Methods
035:
036: /**
037: * <p>Return the context relative path for the specified action.</p>
038: *
039: * @param context <code>FacesContext</code> for the current request
040: * @param action Name of the requested action
041: */
042: protected StringBuffer action(FacesContext context, String action) {
043:
044: // FIXME - assumes extension mapping for Struts
045: StringBuffer sb = new StringBuffer(action);
046: sb.append(".do");
047: return (sb);
048:
049: }
050:
051: /**
052: * <p>Forward to the specified URL and mark this response as having
053: * been completed.</p>
054: *
055: * @param context <code>FacesContext</code> for the current request
056: * @param url Context-relative URL to forward to
057: *
058: * @exception FacesException if any error occurs
059: */
060: protected void forward(FacesContext context, String url) {
061:
062: try {
063: context.getExternalContext().dispatch(url);
064: } catch (IOException e) {
065: throw new FacesException(e);
066: } finally {
067: context.responseComplete();
068: }
069:
070: }
071:
072: /**
073: * <p>Return the context relative base URL for the "logoff"
074: * action.</p>
075: *
076: * @param context <code>FacesContext</code> for the current request
077: */
078: protected StringBuffer logoff(FacesContext context) {
079:
080: return (action(context, "/logoff"));
081:
082: }
083:
084: /**
085: * <p>Return the context relative base URL for the "logon"
086: * action.</p>
087: *
088: * @param context <code>FacesContext</code> for the current request
089: */
090: protected StringBuffer logon(FacesContext context) {
091:
092: return (action(context, "/logon"));
093:
094: }
095:
096: /**
097: * <p>Return the context relative base URL for the "edit registration"
098: * action.</p>
099: *
100: * @param context <code>FacesContext</code> for the current request
101: */
102: protected StringBuffer registration(FacesContext context) {
103:
104: return (action(context, "/editRegistration"));
105:
106: }
107:
108: /**
109: * <p>Return the context relative base URL for the "edit subscriptions"
110: * action.</p>
111: *
112: * @param context <code>FacesContext</code> for the current request
113: */
114: protected StringBuffer subscription(FacesContext context) {
115:
116: return (action(context, "/editSubscription"));
117:
118: }
119:
120: }
|