001: package org.osbl.identity.gui;
002:
003: import org.osbl.client.web.WebModule;
004: import org.osbl.ItemRegistry;
005: import org.osbl.persistence.*;
006: import org.osbl.plugin.PluginManager;
007: import org.osbl.plugin.Extension;
008: import org.osbl.identity.model.*;
009: import org.osbl.item.BeanAuthorizationCollector;
010: import org.osbl.item.BeanLocalizationCollector;
011: import org.osbl.client.action.ActionRegistry;
012: import org.osbl.client.wings.action.ShowEditorAction;
013: import org.osbl.client.wings.navigation.NavigationStructure;
014: import org.osbl.client.wings.form.Editors;
015: import org.osbl.client.wings.form.Viewers;
016: import org.osbl.client.wings.shell.Client;
017: import org.osbl.client.wings.shell.ClientInitializer;
018: import org.osbl.client.ClientServiceProvider;
019: import org.conform.format.FormatFactory;
020: import org.conform.hibernate.HibernateEnvironment;
021: import org.wings.session.SessionManager;
022:
023: import java.util.Locale;
024: import java.util.List;
025:
026: public class IdentityWebModule implements WebModule {
027: PluginManager pluginManager;
028: ItemRegistry authorizationItems;
029: ItemRegistry localizationItems;
030:
031: public void setPluginManager(PluginManager pluginManager) {
032: this .pluginManager = pluginManager;
033: }
034:
035: public void setAuthorizationItems(ItemRegistry authorizationItems) {
036: this .authorizationItems = authorizationItems;
037: }
038:
039: public void setLocalizationItems(ItemRegistry localizationItems) {
040: this .localizationItems = localizationItems;
041: }
042:
043: public void initialize() {
044: Client.addInitializer(new ClientInitializer() {
045: public void preInitialization(Client client) {
046: Locale locale = getUserLocale();
047: if (locale != null) {
048: SessionManager.getSession().setLocale(locale);
049: FormatFactory.getInstance().setLocale(locale);
050: }
051: }
052:
053: public void postInitialization(Client client) {
054: }
055: });
056: authorizationItems.addItems(new BeanAuthorizationCollector(
057: Identity.class));
058: authorizationItems.addItems(new BeanAuthorizationCollector(
059: User.class));
060: authorizationItems.addItems(new BeanAuthorizationCollector(
061: Person.class));
062: authorizationItems.addItems(new BeanAuthorizationCollector(
063: Address.class));
064: authorizationItems.addItems(new BeanAuthorizationCollector(
065: Department.class));
066:
067: localizationItems.addItems(new BeanLocalizationCollector(
068: Identity.class));
069: localizationItems.addItems(new BeanLocalizationCollector(
070: User.class));
071: localizationItems.addItems(new BeanLocalizationCollector(
072: Person.class));
073: localizationItems.addItems(new BeanLocalizationCollector(
074: Address.class));
075: localizationItems.addItems(new BeanLocalizationCollector(
076: Department.class));
077:
078: Editors.registerEditor(Identity.class, IdentityEditor.class);
079: Viewers.registerViewer(Identity.class, IdentityViewer.class);
080:
081: ActionRegistry.registerAction(new ShowEditorAction(
082: Identity.class, "org.osbl.identity.actions.manage"));
083:
084: NavigationStructure navigationStructure = NavigationStructure
085: .getInstance();
086: navigationStructure.addAction("administration",
087: "org.osbl.identity.actions.manage");
088:
089: pluginManager.registerExtension(new Extension("UserSubForm",
090: "org.osbl.identity.subForm", UserSubForm.class));
091: pluginManager.registerExtension(new Extension("PersonSubForm",
092: "org.osbl.identity.subForm", PersonSubForm.class));
093: pluginManager.registerExtension(new Extension(
094: "DepartmentSubForm", "org.osbl.identity.subForm",
095: DepartmentSubForm.class));
096: }
097:
098: private Locale getUserLocale() {
099: try {
100: HibernateEnvironment.getInstance().beginTransaction();
101:
102: Persistence persistence = (Persistence) ClientServiceProvider
103: .getInstance().getService("IdentityPersistence");
104: SimpleQueryCommand queryCommand = (SimpleQueryCommand) persistence
105: .createCommand("list");
106: queryCommand.setType(User.class);
107: queryCommand.addFilter("account", Operator.EQUAL,
108: SessionManager.getSession().getServletRequest()
109: .getUserPrincipal().getName());
110: List<User> list = queryCommand.execute();
111: return list.size() == 0 ? null : list.get(0).getLocale();
112: } finally {
113: HibernateEnvironment.getInstance().endTransaction();
114: }
115: }
116: }
|