001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.shared.value;
034:
035: import com.flexive.shared.FxContext;
036: import com.flexive.shared.FxLanguage;
037: import com.flexive.shared.FxSharedUtils;
038: import com.flexive.shared.security.UserTicket;
039:
040: /**
041: * A replacement for FxValue objects if the calling user has no access to this value
042: *
043: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
044: */
045: public final class FxNoAccess extends FxValue<Object, FxNoAccess> {
046:
047: private static final long serialVersionUID = 7693998143844598522L;
048:
049: private String noAccess;
050: /**
051: * the wrapped value
052: */
053: private FxValue wrappedValue;
054: private UserTicket ticket;
055:
056: /**
057: * Constructor
058: *
059: * @param ticket to get the correct tranlsation of the no access text (if null a fallback will be used)
060: * @param wrappedValue FxValue to wrap
061: */
062: public FxNoAccess(UserTicket ticket, FxValue wrappedValue) {
063: this .wrappedValue = wrappedValue;
064: this .ticket = ticket;
065: if (ticket != null)
066: this .noAccess = FxSharedUtils.getLocalizedMessage(
067: FxSharedUtils.SHARED_BUNDLE, ticket.getLanguage()
068: .getId(), ticket.getLanguage()
069: .getIso2digit(), "shared.noAccess");
070: else
071: this .noAccess = "Access denied";
072: }
073:
074: /**
075: * Get the wrapped value ie for save operations.
076: * The real wrapped value is only returned if the calling user is a global supervisor, else the
077: * FxNoAccess value itself is returned
078: *
079: * @return wrapped value or this FxNoAccess value depending on the calling user
080: */
081: public FxValue getWrappedValue() {
082: return FxContext.get().getRunAsSystem() ? wrappedValue : this ;
083: }
084:
085: /**
086: * {@inheritDoc}
087: */
088: @Override
089: public boolean isReadOnly() {
090: return true;
091: }
092:
093: /**
094: * {@inheritDoc}
095: */
096: @Override
097: public long getDefaultLanguage() {
098: return wrappedValue.getDefaultLanguage();
099: }
100:
101: /**
102: * {@inheritDoc}
103: */
104: @Override
105: public String getDefaultTranslation() {
106: return noAccess;
107: }
108:
109: /**
110: * {@inheritDoc}
111: */
112: @Override
113: public String getTranslation(FxLanguage lang) {
114: return noAccess;
115: }
116:
117: /**
118: * {@inheritDoc}
119: */
120: @Override
121: public String getBestTranslation(long lang) {
122: return noAccess;
123: }
124:
125: /**
126: * {@inheritDoc}
127: */
128: @Override
129: public Long[] getTranslatedLanguages() {
130: return wrappedValue.getTranslatedLanguages();
131: }
132:
133: /**
134: * {@inheritDoc}
135: */
136: @Override
137: public boolean translationExists(long languageId) {
138: return wrappedValue.translationExists(languageId);
139: }
140:
141: /**
142: * {@inheritDoc}
143: */
144: @Override
145: public boolean isEmpty() {
146: return wrappedValue.isEmpty();
147: }
148:
149: /**
150: * {@inheritDoc}
151: */
152: @Override
153: public boolean isMultiLanguage() {
154: return wrappedValue.isMultiLanguage();
155: }
156:
157: /**
158: * {@inheritDoc}
159: */
160: @Override
161: public Object fromString(String value) {
162: return value;
163: }
164:
165: /**
166: * {@inheritDoc}
167: */
168: @Override
169: public FxNoAccess copy() {
170: return new FxNoAccess(ticket, wrappedValue);
171: }
172:
173: /**
174: * {@inheritDoc}
175: */
176: @SuppressWarnings({"unchecked"})
177: @Override
178: public Class getValueClass() {
179: return wrappedValue.getValueClass();
180: }
181: }
|