KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > coplets > basket > UserConfiguration


1 /*
2  * Copyright 2004-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.portal.coplets.basket;
17
18 import java.util.Map JavaDoc;
19
20 import org.apache.cocoon.environment.ObjectModelHelper;
21 import org.apache.cocoon.environment.Request;
22 import org.apache.cocoon.environment.Session;
23 import org.apache.cocoon.portal.PortalService;
24 import org.apache.cocoon.portal.coplet.CopletInstanceData;
25 import org.apache.cocoon.portal.profile.ProfileManager;
26
27 /**
28  * This data object holds the configuration of a user for the basket
29  *
30  * @version CVS $Id: BasketTransformer.java 47047 2004-09-22 12:27:27Z vgritsenko $
31  */

32 public class UserConfiguration {
33
34     /** The attribute name used to store this configuration in the session */
35     public static final String JavaDoc ATTR_NAME = "basket-config";
36     
37     protected boolean basketEnabled = true;
38     protected boolean briefcaseEnabled = false;
39     protected boolean folderEnabled = false;
40     
41     /**
42      * Get/create the user configuration
43      */

44     public static UserConfiguration get(Map JavaDoc objectModel,
45                                         PortalService service) {
46         final Request req = ObjectModelHelper.getRequest(objectModel);
47         final Session session = req.getSession();
48         UserConfiguration uc = (UserConfiguration)session.getAttribute(ATTR_NAME);
49         if ( uc == null ) {
50             final ProfileManager pm = service.getComponentManager().getProfileManager();
51             final CopletInstanceData cid = pm.getCopletInstanceData("basket");
52             if ( cid != null ) {
53                 uc = new UserConfiguration(cid.getAttributes());
54                 session.setAttribute(ATTR_NAME, uc);
55             }
56         }
57         return uc;
58     }
59     
60     /**
61      * Constructor
62      * Read the configuration from the map
63      */

64     public UserConfiguration(Map JavaDoc attributes) {
65         final String JavaDoc enabledKinds = (String JavaDoc)attributes.get("basket:enabled-storages");
66         if ( enabledKinds != null ) {
67             this.basketEnabled = (enabledKinds.indexOf("basket") != -1);
68             this.briefcaseEnabled = (enabledKinds.indexOf("briefcase") != -1);
69             this.folderEnabled = (enabledKinds.indexOf("folder") != -1);
70         }
71     }
72     
73     public boolean isBasketEnabled() {
74         return this.basketEnabled;
75     }
76
77     public boolean isBriefcaseEnabled() {
78         return this.briefcaseEnabled;
79     }
80
81     public boolean isFolderEnabled() {
82         return this.folderEnabled;
83     }
84 }
85
Popular Tags