001: package org.osbl.client.wings.shell;
002:
003: import org.wings.event.SRequestListener;
004: import org.wings.event.SRequestEvent;
005: import org.wings.session.SessionManager;
006: import org.osbl.client.action.ActionProvider;
007: import org.osbl.client.wings.action.ShowViewerAction;
008: import org.osbl.client.wings.action.ShowEditorAction;
009: import org.apache.commons.logging.LogFactory;
010:
011: import javax.swing.*;
012: import java.awt.event.ActionEvent;
013: import java.util.Map;
014: import java.util.HashMap;
015:
016: /**
017: * @author hengels
018: * @version $Revision$
019: */
020: public class URLNavigation {
021: private static org.apache.commons.logging.Log LOG = LogFactory
022: .getLog(URLNavigation.class);
023:
024: public URLNavigation() {
025: final ActionProvider sessionActionProvider = Client
026: .getInstance().getActionProvider();
027: SessionManager.getSession().addRequestListener(
028: new SRequestListener() {
029: public void processRequest(SRequestEvent event) {
030: if (event.getType() == SRequestEvent.DISPATCH_START) {
031: String navigate = SessionManager
032: .getSession().getServletRequest()
033: .getParameter("navigate");
034: if (navigate != null) {
035: Action action = sessionActionProvider
036: .getAction(navigate);
037: if (action != null
038: && action.isEnabled()) {
039: action
040: .actionPerformed(new ActionEvent(
041: URLNavigation.this ,
042: 0, navigate));
043: }
044: return;
045: }
046:
047: String view = SessionManager.getSession()
048: .getServletRequest().getParameter(
049: "view");
050: if (view != null) {
051: try {
052: ClassLoader classLoader = Thread
053: .currentThread()
054: .getContextClassLoader();
055: ShowViewerAction action = new ShowViewerAction(
056: classLoader.loadClass(view),
057: view);
058: action = (ShowViewerAction) sessionActionProvider
059: .configure(action);
060: if (action.isEnabled()) {
061: action.navigate(query());
062: }
063: } catch (ClassNotFoundException e) {
064: LOG.warn(view, e);
065: }
066: return;
067: }
068:
069: String edit = SessionManager.getSession()
070: .getServletRequest().getParameter(
071: "edit");
072: if (edit != null) {
073: try {
074: ClassLoader classLoader = Thread
075: .currentThread()
076: .getContextClassLoader();
077: ShowEditorAction action = new ShowEditorAction(
078: classLoader.loadClass(edit),
079: edit);
080: action = (ShowEditorAction) sessionActionProvider
081: .configure(action);
082: if (action.isEnabled()) {
083: action.navigate(query());
084: }
085: } catch (ClassNotFoundException e) {
086: LOG.warn(edit, e);
087: }
088: return;
089: }
090: }
091: }
092: });
093: }
094:
095: private Map<String, String> query() {
096: Map<String, String[]> map = SessionManager.getSession()
097: .getServletRequest().getParameterMap();
098: Map<String, String> query = new HashMap<String, String>();
099: for (Map.Entry<String, String[]> entry : map.entrySet()) {
100: String key = entry.getKey();
101: String[] value = entry.getValue();
102: if (value != null && value.length == 1)
103: query.put(key, value[0]);
104: }
105: query.put("locale", SessionManager.getSession().getLocale()
106: .toString());
107: query.put("user", SessionManager.getSession()
108: .getServletRequest().getUserPrincipal().getName());
109: return query;
110: }
111: }
|