001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.compiler.model;
020:
021: import java.util.List;
022: import java.util.ArrayList;
023:
024: import org.apache.beehive.netui.compiler.JpfLanguageConstants;
025: import org.w3c.dom.Element;
026:
027: /**
028: * Represents an action forward in a Struts application.
029: */
030: public class ForwardModel extends StrutsElementSupport implements
031: JpfLanguageConstants {
032: private static final String JPF_ACTION_FWD_CLASSNAME = PAGEFLOW_PACKAGE
033: + ".config.PageFlowActionForward";
034:
035: private boolean _isNestedReturn = false;
036: private boolean _contextRelative = false;
037: private String _name; // required to be set
038: private String _path; // required to be set
039: private boolean _redirect = false;
040: private boolean _externalRedirect = false;
041: private boolean _returnToPage = false;
042: private boolean _returnToAction = false;
043: private String _outputFormBeanType;
044: private String _outputFormBeanMember;
045: private boolean _hasExplicitRedirectValue = false;
046: private List _actionOutputs = null;
047: private boolean _restoreQueryString = false;
048: private String _relativeTo;
049:
050: protected ForwardModel(StrutsApp parent) {
051: super (parent);
052: }
053:
054: public ForwardModel(String name, String path, StrutsApp parent) {
055: super (parent);
056: _name = name;
057: _path = path;
058: }
059:
060: protected void writeToElement(XmlModelWriter xw, Element element) {
061: assert _name != null;
062: element.setAttribute("name", _name);
063: setElementAttributeMayBeEmpty(element, "path",
064: _path == null ? "" : _path);
065: setElementAttribute(element, "contextRelative",
066: _contextRelative);
067: setElementAttribute(element, "redirect", _redirect);
068:
069: //
070: // "externalRedirect" is set using set-property, to indicate that the redirect
071: // is to another app.
072: //
073: if (_externalRedirect)
074: addSetProperty(xw, element, "externalRedirect", "true");
075:
076: //
077: // "returnToPage" is set using set-property, which requires us to override the
078: // ActionForward class.
079: //
080: if (_returnToPage)
081: addSetProperty(xw, element, "returnToPage", "true");
082:
083: //
084: // "returnToAction" is set using set-property, which requires us to override the
085: // ActionForward class.
086: //
087: if (_returnToAction)
088: addSetProperty(xw, element, "returnToAction", "true");
089:
090: if (_hasExplicitRedirectValue)
091: addSetProperty(xw, element, "hasExplicitRedirectValue",
092: "true");
093:
094: if (_restoreQueryString)
095: addSetProperty(xw, element, "restoreQueryString", "true");
096:
097: if (_actionOutputs != null && _actionOutputs.size() > 0) {
098: int n = _actionOutputs.size();
099: addSetProperty(xw, element, "actionOutputCount", Integer
100: .toString(n));
101:
102: for (int i = 0; i < n; ++i) {
103: ActionOutputModel pi = (ActionOutputModel) _actionOutputs
104: .get(i);
105: String value = pi.getType() + '|' + pi.getNullable()
106: + '|' + pi.getName();
107: addSetProperty(xw, element, "actionOutput" + i, value);
108: }
109: }
110:
111: //
112: // "nestedReturn" is set using set-property, which requires us to override the
113: // ActionForward class.
114: //
115: if (_isNestedReturn)
116: addSetProperty(xw, element, "nestedReturn", "true");
117: if (_outputFormBeanType != null)
118: addSetProperty(xw, element, "returnFormType",
119: _outputFormBeanType);
120: if (_outputFormBeanMember != null)
121: addSetProperty(xw, element, "returnFormMember",
122: _outputFormBeanMember);
123: if (_relativeTo != null)
124: addSetProperty(xw, element, "relativeTo", _relativeTo);
125: }
126:
127: public boolean isReturnToPage() {
128: return _returnToPage;
129: }
130:
131: public void setReturnToPage(boolean returnToPage) {
132: _returnToPage = returnToPage;
133: }
134:
135: public boolean isReturnToAction() {
136: return _returnToAction;
137: }
138:
139: public void setReturnToAction(boolean returnToAction) {
140: _returnToAction = returnToAction;
141: }
142:
143: public void setIsNestedReturn(boolean nestedReturn) {
144: _isNestedReturn = nestedReturn;
145: }
146:
147: public String getOutputFormBeanType() {
148: return _outputFormBeanType;
149: }
150:
151: public void setOutputFormBeanType(String outputFormBeanType) {
152: _outputFormBeanType = outputFormBeanType;
153: }
154:
155: public String getOutputFormBeanMember() {
156: return _outputFormBeanMember;
157: }
158:
159: public void setOutputFormBeanMember(String outputFormBeanMember) {
160: _outputFormBeanMember = outputFormBeanMember;
161: }
162:
163: public boolean getContextRelative() {
164: return _contextRelative;
165: }
166:
167: public void setContextRelative(boolean contextRelative) {
168: _contextRelative = contextRelative;
169: }
170:
171: public String getName() {
172: return _name;
173: }
174:
175: public void setName(String name) {
176: _name = name;
177: }
178:
179: public String getPath() {
180: return _path;
181: }
182:
183: public void setPath(String path) {
184: _path = path;
185: }
186:
187: public boolean isRedirect() {
188: return _redirect;
189: }
190:
191: public void setRedirect(boolean redirect) {
192: _redirect = redirect;
193: _hasExplicitRedirectValue = redirect;
194: }
195:
196: public boolean isExternalRedirect() {
197: return _externalRedirect;
198: }
199:
200: public void setExternalRedirect(boolean externalRedirect) {
201: _externalRedirect = externalRedirect;
202: if (externalRedirect)
203: setRedirect(externalRedirect);
204: }
205:
206: public boolean isRestoreQueryString() {
207: return _restoreQueryString;
208: }
209:
210: public void setRestoreQueryString(boolean restore) {
211: _restoreQueryString = restore;
212: }
213:
214: /**
215: * @deprecated
216: * @see #forwardsToPage
217: */
218: public final boolean isPageForward() {
219: return forwardsToPage();
220: }
221:
222: public boolean forwardsToPage() {
223: return !_path.endsWith(".do") && !_path.endsWith(".jpf"); // NOI18N
224: }
225:
226: public boolean forwardsToAction() {
227: return _path.endsWith(ACTION_EXTENSION_DOT); // NOI18N
228: }
229:
230: public final boolean forwardsToPageFlow() {
231: return _path.endsWith(JPF_FILE_EXTENSION_DOT); // NOI18N
232: }
233:
234: public String getPageName() {
235: assert forwardsToPage() : "getPageName() called for non-page "
236: + _path; // NOI18N
237:
238: int slash = _path.lastIndexOf('/'); // NOI18N
239: return slash != -1 ? _path.substring(slash + 1) : _path;
240: }
241:
242: public String getActionName() {
243: assert forwardsToAction() : "getActionName() called for non-action"
244: + _path; // NOI18N
245:
246: int index = _path.indexOf(ACTION_EXTENSION_DOT); // NOI18N
247: assert index != -1;
248: return _path.substring(0, index);
249: }
250:
251: public void addActionOutput(ActionOutputModel actionOutput) {
252: if (_actionOutputs == null)
253: _actionOutputs = new ArrayList();
254: _actionOutputs.add(actionOutput);
255: }
256:
257: public boolean isNestedReturn() {
258: return _isNestedReturn;
259: }
260:
261: protected void addSetProperty(XmlModelWriter xw, Element element,
262: String propertyName, String propertyValue) {
263: setCustomProperty(xw, element, propertyName, propertyValue,
264: JPF_ACTION_FWD_CLASSNAME);
265: }
266:
267: /**
268: * Set the path for the struts module that this forward is relative to.
269: * @param relativeTo The struts module path that this forward is relative to.
270: */
271: public void setRelativeTo(String relativeTo) {
272: _relativeTo = relativeTo;
273: }
274: }
|