01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.portal.coplets.basket;
18:
19: import java.util.Map;
20:
21: import org.apache.cocoon.environment.ObjectModelHelper;
22: import org.apache.cocoon.environment.Request;
23: import org.apache.cocoon.environment.Session;
24: import org.apache.cocoon.portal.PortalService;
25: import org.apache.cocoon.portal.coplet.CopletInstanceData;
26: import org.apache.cocoon.portal.profile.ProfileManager;
27:
28: /**
29: * This data object holds the configuration of a user for the basket
30: *
31: * @version CVS $Id: BasketTransformer.java 47047 2004-09-22 12:27:27Z vgritsenko $
32: */
33: public class UserConfiguration {
34:
35: /** The attribute name used to store this configuration in the session */
36: public static final String ATTR_NAME = "basket-config";
37:
38: protected boolean basketEnabled = true;
39: protected boolean briefcaseEnabled = false;
40: protected boolean folderEnabled = false;
41:
42: /**
43: * Get/create the user configuration
44: */
45: public static UserConfiguration get(Map objectModel,
46: PortalService service) {
47: final Request req = ObjectModelHelper.getRequest(objectModel);
48: final Session session = req.getSession();
49: UserConfiguration uc = (UserConfiguration) session
50: .getAttribute(ATTR_NAME);
51: if (uc == null) {
52: final ProfileManager pm = service.getComponentManager()
53: .getProfileManager();
54: final CopletInstanceData cid = pm
55: .getCopletInstanceData("basket");
56: if (cid != null) {
57: uc = new UserConfiguration(cid.getAttributes());
58: session.setAttribute(ATTR_NAME, uc);
59: }
60: }
61: return uc;
62: }
63:
64: /**
65: * Constructor
66: * Read the configuration from the map
67: */
68: public UserConfiguration(Map attributes) {
69: final String enabledKinds = (String) attributes
70: .get("basket:enabled-storages");
71: if (enabledKinds != null) {
72: this .basketEnabled = (enabledKinds.indexOf("basket") != -1);
73: this .briefcaseEnabled = (enabledKinds.indexOf("briefcase") != -1);
74: this .folderEnabled = (enabledKinds.indexOf("folder") != -1);
75: }
76: }
77:
78: public boolean isBasketEnabled() {
79: return this .basketEnabled;
80: }
81:
82: public boolean isBriefcaseEnabled() {
83: return this .briefcaseEnabled;
84: }
85:
86: public boolean isFolderEnabled() {
87: return this.folderEnabled;
88: }
89: }
|