Source code: info/crossbar/state/User.java
1 /*
2 * @(#)User.java $Revision: 1.3 $ $Date: 2003/06/21 00:42:13 $
3 *
4 * Copyright 2002 by Daniel Kehoe <kehoe@fortuity.com>
5 * All Rights Reserved
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28 package info.crossbar.state;
29
30 import java.util.logging.Logger;
31 import java.util.Map;
32
33 import javax.servlet.ServletContext;
34
35 import javax.faces.context.FacesContext;
36 import javax.faces.context.ExternalContext;
37
38
39 /**
40 * User class for use by <a href="http://www.crossbar.info/">Crossbar</a>
41 *
42 * @author Daniel Kehoe, <a href="http://www.fortuity.com/">Fortuity Consulting</a>
43 * @version <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/crossbar/crossbar-stylish/src/java/info/crossbar/state/User.java">View source, revision history</a>
44 * $Revision: 1.3 $ $Date: 2003/06/21 00:42:13 $
45 * <p>
46 * DESCRIPTION:
47 * The User class encapsulates all information that defines a
48 * user of the application.
49 */
50
51 public class User {
52
53 /**
54 * Set up logging.
55 *
56 */
57 private static Logger log = Logger.getLogger(User.class.getName());
58
59 private String userName = null;
60 private String stylesheet = "default.css";
61
62 /**
63 * No argument Constructor.
64 * Illustrates use of logging statements and access to
65 * "global" application attributes.
66 *
67 */
68 public User() {
69 log.entering(User.class.getName(), "Constructor");
70 // obtain the application context:
71 ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
72 // get the application name:
73 ServletContext sc = (ServletContext) ec.getContext();
74 String appname = sc.getServletContextName();
75 // get a parameter originating in the web.xml file:
76 Map initParameterMap = ec.getInitParameterMap();
77 String version = (String) initParameterMap.get("info.crossbar.version");
78 /*
79 * For your edification, you might wish to
80 * compare obtaining context attributes (above) with a similar procedure
81 * in info.crossbar.filtersAndListeners.ContextListener. The procedure
82 * above can be used in any bean where the servlet context is not directly
83 * available.
84 */
85 if (version == null) {
86 version = "??";
87 }
88 // unless you've made changes to default parameters in the web.xml file,
89 // this log statement will show up in the <tomcat>/logs/crossbar.log file
90 log.fine(appname + " version " + version + " logging demonstration");
91 // Here are examples of log statements with other severity levels;
92 // log.severe(appname + " version " + version + " logging demonstration");
93 // log.warning(appname + " version " + version + " logging demonstration");
94 // log.info(appname + " version " + version + " logging demonstration");
95 // log.config(appname + " version " + version + " logging demonstration");
96 // log.fine(appname + " version " + version + " logging demonstration");
97 // log.finer(appname + " version " + version + " logging demonstration");
98 // log.finest(appname + " version " + version + " logging demonstration");
99 log.exiting(User.class.getName(), "Constructor");
100 }
101
102 public void setName(String user_name) {
103 this.userName = user_name;
104 }
105
106 public String getName() {
107 return this.userName;
108 }
109
110 public void setStylesheet(String stylesheet) {
111 this.stylesheet = stylesheet;
112 }
113
114 public String getStylesheet() {
115 return this.stylesheet;
116 }
117
118 }