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.util.Collection;
022: import java.util.Collections;
023:
024: import de.finix.contelligent.CallData;
025: import de.finix.contelligent.components.Folder;
026: import de.finix.contelligent.content.Content;
027: import de.finix.contelligent.content.ContentProvider;
028: import de.finix.contelligent.content.StringContent;
029: import de.finix.contelligent.exception.ContelligentException;
030:
031: public class StoredObject extends Folder implements Constants,
032: ContentProvider, StringContent {
033:
034: private String storageScope = "";
035:
036: private String storageKey = "";
037:
038: public Content getContent() {
039: return this ;
040: }
041:
042: public Object getContentValue(CallData callData)
043: throws IOException, ContelligentException {
044: return getString(callData);
045: }
046:
047: public long lastModified(CallData callData) throws IOException {
048: return -1;
049: }
050:
051: public Collection getSensitiveCategories() {
052: return Collections.EMPTY_SET;
053: }
054:
055: public String getString(CallData callData)
056: throws ContelligentException, IOException {
057: Object obj = getObject(callData);
058: if (obj == null) {
059: return "";
060: }
061: return obj.toString();
062: }
063:
064: public void setStorageScope(String scope) {
065: storageScope = scope;
066: }
067:
068: public String getStorageScope() {
069: return storageScope;
070: }
071:
072: public void setStorageKey(String key) {
073: storageKey = key;
074: }
075:
076: public String getStorageKey() {
077: return storageKey;
078: }
079:
080: public boolean scopeSession() {
081: return storageScope.equals(SCOPE_SESSION_STRING);
082: }
083:
084: public boolean scopeRequest() {
085: return storageScope.equals(SCOPE_REQUEST_STRING);
086: }
087:
088: public Object getObject(CallData callData) {
089: if (scopeSession()) {
090: return callData.getSessionAttribute(getSessionStorageKey());
091: } else {
092: return callData.getRequestAttribute(getRequestStorageKey());
093: }
094: }
095:
096: protected String getSessionStorageKey() {
097: if (storageKey.length() != 0) {
098: return storageKey;
099: }
100: return ctx.getPath().toString();
101: }
102:
103: protected String getRequestStorageKey() {
104: if (storageKey.length() != 0) {
105: return storageKey;
106: }
107: return ctx.getPath().getName();
108: }
109:
110: }
|