001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.action;
019:
020: import java.io.IOException;
021: import java.io.Writer;
022: import java.util.Collection;
023: import java.util.Map;
024:
025: import de.finix.contelligent.CallData;
026: import de.finix.contelligent.Component;
027: import de.finix.contelligent.content.Content;
028: import de.finix.contelligent.content.ContentProvider;
029: import de.finix.contelligent.content.StringContent;
030: import de.finix.contelligent.exception.ContelligentException;
031: import de.finix.contelligent.render.MissingParameterException;
032: import de.finix.contelligent.render.ParameterDescription;
033: import de.finix.contelligent.render.Renderable;
034: import de.finix.contelligent.render.Renderer;
035:
036: public class ActionResult extends StoredObject implements Variable,
037: Renderable, Renderer, ContentProvider, StringContent {
038: private String storageDomain = "";
039:
040: public void setStorageDomain(String key) {
041: storageDomain = key;
042: }
043:
044: public String getStorageDomain() {
045: return storageDomain;
046: }
047:
048: public void setObject(Object value, CallData callData) {
049: if (storageDomain.length() == 0) {
050: if (scopeSession()) {
051: callData.setSessionAttribute(getSessionStorageKey(),
052: value);
053: } else {
054: callData.setRequestAttribute(getRequestStorageKey(),
055: value);
056: }
057: } else {
058: if (scopeSession()) {
059: callData.setSessionAttribute(getSessionStorageKey(),
060: value, storageDomain);
061: } else {
062: callData.setRequestAttribute(getRequestStorageKey(),
063: value, storageDomain);
064: }
065: }
066: }
067:
068: public void clearObject(CallData callData) {
069: if (storageDomain.length() == 0) {
070: if (scopeSession()) {
071: callData.removeSessionAttribute(getSessionStorageKey());
072: } else {
073: callData.removeRequestAttribute(getRequestStorageKey());
074: }
075: } else {
076: if (scopeSession()) {
077: callData.removeSessionAttribute(getSessionStorageKey(),
078: storageDomain);
079: } else {
080: callData.removeRequestAttribute(getRequestStorageKey(),
081: storageDomain);
082: }
083: }
084: }
085:
086: public Object getObject(CallData callData) {
087: if (storageDomain.length() == 0) {
088: if (scopeSession()) {
089: return callData
090: .getSessionAttribute(getSessionStorageKey());
091: } else {
092: return callData
093: .getRequestAttribute(getRequestStorageKey());
094: }
095: } else {
096: if (scopeSession()) {
097: return callData.getSessionAttribute(
098: getSessionStorageKey(), storageDomain);
099: } else {
100: return callData.getRequestAttribute(
101: getRequestStorageKey(), storageDomain);
102: }
103: }
104: }
105:
106: public Renderer getRenderer() {
107: return this ;
108: }
109:
110: public ParameterDescription[] getParameterDescription() {
111: return new ParameterDescription[0];
112: }
113:
114: public void render(Writer writer, Map parameterMap,
115: CallData callData) throws IOException,
116: MissingParameterException, ContelligentException {
117: Object storedObject = getObject(callData);
118: if (storedObject != null) {
119: if (storedObject instanceof Renderable) {
120: ((Renderable) storedObject).getRenderer().render(
121: writer, parameterMap, callData);
122: } else {
123: writer.write(storedObject.toString());
124: }
125: }
126: }
127:
128: public Collection getSensitiveCategories() {
129: return null;
130: }
131:
132: public long lastModified(CallData callData) {
133: return -1;
134: }
135:
136: public String getString(CallData callData)
137: throws ContelligentException, IOException {
138: Object tmp = getObject(callData);
139: if (tmp == null) {
140: return "";
141: } else {
142: if (tmp instanceof Component) {
143: return renderComponent((Component) tmp, callData);
144: }
145: return tmp.toString();
146: }
147: }
148:
149: public Object getContentValue(CallData callData)
150: throws IOException, ContelligentException {
151: return getString(callData);
152: }
153:
154: public Content getContent() {
155: return this;
156: }
157: }
|