roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r533433 - in /roller/trunk: src/org/apache/roller/ui/core/util/menu/ src/org/apache/roller/ui/core/util/struts2/ web/WEB-INF/jsps/tiles/struts2/
Date Sat, 28 Apr 2007 22:14:52 GMT
Author: agilliland
Date: Sat Apr 28 15:14:47 2007
New Revision: 533433

URL: http://svn.apache.org/viewvc?view=rev&rev=533433
Log:
a couple new utilites for struts2 support.

1. New code for supporting the tabbed menu rendering which is no longer a custom jsp tag using
velocity.  The new code provides a few classes which deal with parsing the menu configs from
xml, a few classes which are used to model a menu for use in rendering on the UI, a helper
class for building a menu based on the current action/user/weblog combo, and a new tiles jsp
used to render the menu.

2. A new interface and struts2 interceptor to support a Roller specific version of struts2's
Preparable interface.  The UIActionPreparable interface works the same way except that instead
of being executed early in the interceptor chain like the struts2 Preparable interface does,
the UIActionPreparable interceptor is the very last in the chain which allows Roller actions
to use data loaded by previous interceptors like the UIActionInterceptor.

3. Support for both the new menu code and new myPrepare() method are added to the UIAction
class so that actions get built-in support and default implementations which they can override
if they want to.


Added:
    roller/trunk/src/org/apache/roller/ui/core/util/menu/
    roller/trunk/src/org/apache/roller/ui/core/util/menu/Menu.java
    roller/trunk/src/org/apache/roller/ui/core/util/menu/MenuHelper.java
    roller/trunk/src/org/apache/roller/ui/core/util/menu/MenuTab.java
    roller/trunk/src/org/apache/roller/ui/core/util/menu/MenuTabItem.java
    roller/trunk/src/org/apache/roller/ui/core/util/menu/ParsedMenu.java
    roller/trunk/src/org/apache/roller/ui/core/util/menu/ParsedTab.java
    roller/trunk/src/org/apache/roller/ui/core/util/menu/ParsedTabItem.java
    roller/trunk/src/org/apache/roller/ui/core/util/struts2/UIActionPreparable.java
    roller/trunk/src/org/apache/roller/ui/core/util/struts2/UIActionPrepareInterceptor.java
    roller/trunk/web/WEB-INF/jsps/tiles/struts2/menu.jsp
Modified:
    roller/trunk/src/org/apache/roller/ui/core/util/struts2/UIAction.java

Added: roller/trunk/src/org/apache/roller/ui/core/util/menu/Menu.java
URL: http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/ui/core/util/menu/Menu.java?view=auto&rev=533433
==============================================================================
--- roller/trunk/src/org/apache/roller/ui/core/util/menu/Menu.java (added)
+++ roller/trunk/src/org/apache/roller/ui/core/util/menu/Menu.java Sat Apr 28 15:14:47 2007
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.ui.core.util.menu;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * A Menu of MenuTab objects.
+ */
+public class Menu {
+    
+    private List tabs = new ArrayList();
+    
+    
+    public void addTab(MenuTab tab) {
+        this.tabs.add(tab);
+    }
+    
+    
+    public List getTabs() {
+        return tabs;
+    }
+
+    public void setTabs(List menus) {
+        this.tabs = menus;
+    }
+    
+}

Added: roller/trunk/src/org/apache/roller/ui/core/util/menu/MenuHelper.java
URL: http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/ui/core/util/menu/MenuHelper.java?view=auto&rev=533433
==============================================================================
--- roller/trunk/src/org/apache/roller/ui/core/util/menu/MenuHelper.java (added)
+++ roller/trunk/src/org/apache/roller/ui/core/util/menu/MenuHelper.java Sat Apr 28 15:14:47
2007
@@ -0,0 +1,294 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.ui.core.util.menu;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.config.RollerConfig;
+import org.apache.roller.pojos.PermissionsData;
+import org.apache.roller.pojos.UserData;
+import org.apache.roller.pojos.WebsiteData;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+
+
+/**
+ * A helper class for dealing with UI menus.
+ */
+public class MenuHelper {
+    
+    private static Log log = LogFactory.getLog(MenuHelper.class);
+    
+    private static Hashtable menus = new Hashtable();
+    
+    
+    static {
+        try {
+            // parse menus and cache so we can efficiently reuse them
+            // TODO: there is probably a better way than putting the whole path
+            ParsedMenu editorMenu = unmarshall(MenuHelper.class.getResourceAsStream("/org/apache/roller/ui/authoring/struts2/editor-menu.xml"));
+            menus.put("editor", editorMenu);
+            
+            ParsedMenu adminMenu = unmarshall(MenuHelper.class.getResourceAsStream("/org/apache/roller/ui/admin/struts2/admin-menu.xml"));
+            menus.put("admin", adminMenu);
+            
+        } catch (Exception ex) {
+            log.error("Error parsing menu configs", ex);
+        }
+    }
+    
+    
+    public static Menu getMenu(String menuId, String currentAction,
+                               UserData user, WebsiteData weblog) {
+        
+        if(menuId == null) {
+            return null;
+        }
+        
+        Menu menu = null;
+        
+        // do we know the specified menu config?
+        ParsedMenu menuConfig = (ParsedMenu) menus.get(menuId);
+        if(menuConfig != null) {
+            menu = buildMenu(menuConfig, currentAction, user, weblog);
+        }
+        
+        return menu;
+    }
+    
+    
+    private static Menu buildMenu(ParsedMenu menuConfig, String currentAction, 
+                                  UserData user, WebsiteData weblog) {
+        
+        log.debug("creating menu for action - "+currentAction);
+        
+        Menu tabMenu = new Menu();
+        
+        // iterate over tabs from parsed config
+        ParsedTab configTab = null;
+        Iterator tabsIter = menuConfig.getTabs().iterator();
+        while(tabsIter.hasNext()) {
+            configTab = (ParsedTab) tabsIter.next();
+            
+            log.debug("config tab = "+configTab.getName());
+            
+            // does this tab have an enabledProperty?
+            boolean includeTab = true;
+            if(configTab.getEnabledProperty() != null) {
+                includeTab = RollerConfig.getBooleanProperty(configTab.getEnabledProperty());
+            }
+            
+            if(includeTab) {
+                // user roles check
+                if(configTab.getRole() != null) {
+                    if(!user.hasRole(configTab.getRole())) {
+                        includeTab = false;
+                    }
+                }
+            }
+            
+            if(includeTab) {
+                // weblog permissions check
+                includeTab = isPermitted(configTab.getPerm(), user, weblog);
+            }
+            
+            if(includeTab) {
+                log.debug("tab allowed - "+configTab.getName());
+                
+                // all checks passed, tab should be included
+                MenuTab tab = new MenuTab();
+                tab.setKey(configTab.getName());
+                
+                // setup tab items
+                boolean firstItem = true;
+                ParsedTabItem configTabItem = null;
+                Iterator itemsIter = configTab.getTabItems().iterator();
+                while(itemsIter.hasNext()) {
+                    configTabItem = (ParsedTabItem) itemsIter.next();
+                    
+                    log.debug("config tab item = "+configTabItem.getName());
+                    
+                    boolean includeItem = true;
+                    if(configTabItem.getEnabledProperty() != null) {
+                        includeItem = RollerConfig.getBooleanProperty(configTabItem.getEnabledProperty());
+                    }
+                    
+                    if(includeItem) {
+                        // user roles check
+                        if(configTabItem.getRole() != null) {
+                            if(!user.hasRole(configTabItem.getRole())) {
+                                includeItem = false;
+                            }
+                        }
+                    }
+                    
+                    if(includeItem) {
+                        // weblog permissions check
+                        includeItem = isPermitted(configTabItem.getPerm(), user, weblog);
+                    }
+                    
+                    if(includeItem) {
+                        log.debug("tab item allowed - "+configTabItem.getName());
+                        
+                        // all checks passed, item should be included
+                        MenuTabItem tabItem = new MenuTabItem();
+                        tabItem.setKey(configTabItem.getName());
+                        tabItem.setAction(configTabItem.getAction());
+                        
+                        // is this the selected item?
+                        if(isSelected(currentAction, configTabItem)) {
+                            tabItem.setSelected(true);
+                            tab.setSelected(true);
+                        }
+                        
+                        // the url for the tab is the url of the first item of the tab
+                        if(firstItem) {
+                            tab.setAction(tabItem.getAction());
+                            firstItem = false;
+                        }
+                        
+                        // add the item
+                        tab.addItem(tabItem);
+                    }
+                }
+                
+                // add the tab
+                tabMenu.addTab(tab);
+            }
+        }
+        
+        return tabMenu;
+    }
+    
+    
+    private static boolean isPermitted(String perm, UserData user, WebsiteData weblog) {
+        
+        // convert permissions string to short
+        short permMask = -1;
+        if(perm == null) {
+            return true;
+        } else if("limited".equals(perm)) {
+            permMask = PermissionsData.LIMITED;
+        } else if("author".equals(perm)) {
+            permMask = PermissionsData.AUTHOR;
+        } else if("admin".equals(perm)) {
+            permMask = PermissionsData.ADMIN;
+        } else {
+            // unknown perm
+            return false;
+        }
+        
+        return weblog.hasUserPermissions(user, permMask);
+    }
+    
+    
+    private static boolean isSelected(String currentAction, ParsedTabItem tabItem) {
+        
+        if(currentAction.equals(tabItem.getAction())) {
+            return true;
+        }
+        
+        // an item is also considered selected if it's subforwards are the current action
+        String[] subActions = tabItem.getSubActions();
+        if(subActions != null && subActions.length > 0) {
+            for(int i=0; i < subActions.length; i++) {
+                if(currentAction.equals(subActions[i])) {
+                    return true;
+                }
+            }
+        }
+        
+        return false;
+    }
+    
+    
+    /**
+     * Unmarshall the given input stream into our defined
+     * set of Java objects.
+     **/
+    private static ParsedMenu unmarshall(InputStream instream) 
+        throws IOException, JDOMException {
+        
+        if(instream == null)
+            throw new IOException("InputStream is null!");
+        
+        ParsedMenu config = new ParsedMenu();
+        
+        SAXBuilder builder = new SAXBuilder();
+        Document doc = builder.build(instream);
+        
+        Element root = doc.getRootElement();
+        List menus = root.getChildren("menu");
+        Iterator iter = menus.iterator();
+        while (iter.hasNext()) {
+            Element e = (Element) iter.next();
+            config.addTab(elementToConfigMenu(e));
+        }
+        
+        return config;
+    }
+    
+    
+    private static ParsedTab elementToConfigMenu(Element element) {
+        
+        ParsedTab menu = new ParsedTab();
+        
+        menu.setName(element.getAttributeValue("name"));
+        menu.setPerm(element.getAttributeValue("perms"));
+        menu.setRole(element.getAttributeValue("roles"));
+        menu.setEnabledProperty(element.getAttributeValue("enabledProperty"));
+        
+        List menuItems = element.getChildren("menu-item");
+        Iterator iter = menuItems.iterator();
+        while (iter.hasNext()) {
+            Element e = (Element) iter.next();
+            menu.addItem(elementToConfigMenuItem(e));
+        }
+        
+        return menu;
+    }
+    
+    
+    private static ParsedTabItem elementToConfigMenuItem(Element element) {
+        
+        ParsedTabItem menuItem = new ParsedTabItem();
+        
+        menuItem.setName(element.getAttributeValue("name"));
+        menuItem.setAction(element.getAttributeValue("action"));
+        
+        String subActions = element.getAttributeValue("subactions");
+        if(subActions != null) {
+            menuItem.setSubActions(subActions.split(","));
+        }
+        
+        menuItem.setPerm(element.getAttributeValue("perms"));
+        menuItem.setRole(element.getAttributeValue("roles"));
+        menuItem.setEnabledProperty(element.getAttributeValue("enabledProperty"));
+        
+        return menuItem;
+    }
+    
+}

Added: roller/trunk/src/org/apache/roller/ui/core/util/menu/MenuTab.java
URL: http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/ui/core/util/menu/MenuTab.java?view=auto&rev=533433
==============================================================================
--- roller/trunk/src/org/apache/roller/ui/core/util/menu/MenuTab.java (added)
+++ roller/trunk/src/org/apache/roller/ui/core/util/menu/MenuTab.java Sat Apr 28 15:14:47
2007
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.ui.core.util.menu;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * Tab in a Menu.
+ */
+public class MenuTab {
+    
+    private String key = null;
+    private String action = null;
+    private boolean selected = false;
+    private List items = new ArrayList();
+    
+    
+    public void addItem(MenuTabItem item) {
+        this.items.add(item);
+    }
+    
+    
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getAction() {
+        return action;
+    }
+
+    public void setAction(String url) {
+        this.action = url;
+    }
+
+    public boolean isSelected() {
+        return selected;
+    }
+
+    public void setSelected(boolean selected) {
+        this.selected = selected;
+    }
+    
+    public List getItems() {
+        return items;
+    }
+
+    public void setItems(List items) {
+        this.items = items;
+    }
+    
+}

Added: roller/trunk/src/org/apache/roller/ui/core/util/menu/MenuTabItem.java
URL: http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/ui/core/util/menu/MenuTabItem.java?view=auto&rev=533433
==============================================================================
--- roller/trunk/src/org/apache/roller/ui/core/util/menu/MenuTabItem.java (added)
+++ roller/trunk/src/org/apache/roller/ui/core/util/menu/MenuTabItem.java Sat Apr 28 15:14:47
2007
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.ui.core.util.menu;
+
+
+/**
+ * Items in a Tab.
+ */
+public class MenuTabItem {
+    
+    private String key = null;
+    private String action = null;
+    private boolean selected = false;
+    
+    
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getAction() {
+        return action;
+    }
+
+    public void setAction(String url) {
+        this.action = url;
+    }
+
+    public boolean isSelected() {
+        return selected;
+    }
+
+    public void setSelected(boolean selected) {
+        this.selected = selected;
+    }
+    
+}

Added: roller/trunk/src/org/apache/roller/ui/core/util/menu/ParsedMenu.java
URL: http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/ui/core/util/menu/ParsedMenu.java?view=auto&rev=533433
==============================================================================
--- roller/trunk/src/org/apache/roller/ui/core/util/menu/ParsedMenu.java (added)
+++ roller/trunk/src/org/apache/roller/ui/core/util/menu/ParsedMenu.java Sat Apr 28 15:14:47
2007
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.ui.core.util.menu;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * A parsed xml defined menu.
+ */
+public class ParsedMenu {
+    
+    private List tabs = new ArrayList();
+    
+    
+    public void addTab(ParsedTab tab) {
+        this.tabs.add(tab);
+    }
+    
+    
+    public List getTabs() {
+        return tabs;
+    }
+
+    public void setTabs(List tabs) {
+        this.tabs = tabs;
+    }
+    
+}

Added: roller/trunk/src/org/apache/roller/ui/core/util/menu/ParsedTab.java
URL: http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/ui/core/util/menu/ParsedTab.java?view=auto&rev=533433
==============================================================================
--- roller/trunk/src/org/apache/roller/ui/core/util/menu/ParsedTab.java (added)
+++ roller/trunk/src/org/apache/roller/ui/core/util/menu/ParsedTab.java Sat Apr 28 15:14:47
2007
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.ui.core.util.menu;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * A parsed "tab" from an xml defined menu config.
+ */
+public class ParsedTab {
+    
+    private String name = null;
+    private String perm = null;
+    private String role = null;
+    private String enabledProperty = null;
+    
+    private List tabItems = new ArrayList();
+    
+    
+    public void addItem(ParsedTabItem item) {
+        this.tabItems.add(item);
+    }
+    
+    
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getPerm() {
+        return perm;
+    }
+
+    public void setPerm(String perm) {
+        this.perm = perm;
+    }
+
+    public String getRole() {
+        return role;
+    }
+
+    public void setRole(String role) {
+        this.role = role;
+    }
+
+    public String getEnabledProperty() {
+        return enabledProperty;
+    }
+
+    public void setEnabledProperty(String enabledProperty) {
+        this.enabledProperty = enabledProperty;
+    }
+
+    public List getTabItems() {
+        return tabItems;
+    }
+
+    public void setTabItems(List tabItems) {
+        this.tabItems = tabItems;
+    }
+    
+}

Added: roller/trunk/src/org/apache/roller/ui/core/util/menu/ParsedTabItem.java
URL: http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/ui/core/util/menu/ParsedTabItem.java?view=auto&rev=533433
==============================================================================
--- roller/trunk/src/org/apache/roller/ui/core/util/menu/ParsedTabItem.java (added)
+++ roller/trunk/src/org/apache/roller/ui/core/util/menu/ParsedTabItem.java Sat Apr 28 15:14:47
2007
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.ui.core.util.menu;
+
+
+/**
+ * A parsed "tab-item" from an xml defined menu config.
+ */
+public class ParsedTabItem {
+    
+    private String name = null;
+    private String action = null;
+    private String[] subActions = null;
+    private String perm = null;
+    private String role = null;
+    private String enabledProperty = null;
+    
+    
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getAction() {
+        return action;
+    }
+
+    public void setAction(String action) {
+        this.action = action;
+    }
+
+    public String[] getSubActions() {
+        return subActions;
+    }
+
+    public void setSubActions(String[] subActions) {
+        this.subActions = subActions;
+    }
+
+    public String getPerm() {
+        return perm;
+    }
+
+    public void setPerm(String perm) {
+        this.perm = perm;
+    }
+
+    public String getRole() {
+        return role;
+    }
+
+    public void setRole(String role) {
+        this.role = role;
+    }
+
+    public String getEnabledProperty() {
+        return enabledProperty;
+    }
+
+    public void setEnabledProperty(String enabledProperty) {
+        this.enabledProperty = enabledProperty;
+    }
+    
+}

Modified: roller/trunk/src/org/apache/roller/ui/core/util/struts2/UIAction.java
URL: http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/ui/core/util/struts2/UIAction.java?view=diff&rev=533433&r1=533432&r2=533433
==============================================================================
--- roller/trunk/src/org/apache/roller/ui/core/util/struts2/UIAction.java (original)
+++ roller/trunk/src/org/apache/roller/ui/core/util/struts2/UIAction.java Sat Apr 28 15:14:47
2007
@@ -27,6 +27,8 @@
 import org.apache.roller.pojos.UserData;
 import org.apache.roller.pojos.WebsiteData;
 import org.apache.roller.ui.core.util.UIUtils;
+import org.apache.roller.ui.core.util.menu.Menu;
+import org.apache.roller.ui.core.util.menu.MenuHelper;
 
 
 /**
@@ -39,7 +41,7 @@
  * getText(key) on the param passed into setError() and setSuccess().
  */
 public abstract class UIAction extends ActionSupport 
-        implements UISecurityEnforced {
+        implements UIActionPreparable, UISecurityEnforced {
     
     // the authenticated user accessing this action, or null if client is not logged in
     private UserData authenticatedUser = null;
@@ -47,10 +49,21 @@
     // the weblog this action is intended to work on, or null if no weblog specified
     private WebsiteData actionWeblog = null;
     
+    // action name (used by tabbed menu utility)
+    protected String actionName = null;
+    
+    // the name of the menu this action wants to show, or null for no menu
+    protected String desiredMenu = null;
+    
     // page title
     protected String pageTitle = null;
     
     
+    public void myPrepare() {
+        // no-op
+    }
+    
+    
     // default action permissions, user is required
     public boolean isUserRequired() {
         return true;
@@ -169,6 +182,27 @@
 
     public void setPageTitle(String pageTitle) {
         this.pageTitle = pageTitle;
+    }
+    
+    
+    public String getActionName() {
+        return this.actionName;
+    }
+    
+    public void setActionName(String actionName) {
+        this.actionName = actionName;
+    }
+
+    public String getDesiredMenu() {
+        return desiredMenu;
+    }
+
+    public void setDesiredMenu(String desiredMenu) {
+        this.desiredMenu = desiredMenu;
+    }
+    
+    public Menu getMenu() {
+        return MenuHelper.getMenu(getDesiredMenu(), getActionName(), getAuthenticatedUser(),
getActionWeblog());
     }
     
     

Added: roller/trunk/src/org/apache/roller/ui/core/util/struts2/UIActionPreparable.java
URL: http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/ui/core/util/struts2/UIActionPreparable.java?view=auto&rev=533433
==============================================================================
--- roller/trunk/src/org/apache/roller/ui/core/util/struts2/UIActionPreparable.java (added)
+++ roller/trunk/src/org/apache/roller/ui/core/util/struts2/UIActionPreparable.java Sat Apr
28 15:14:47 2007
@@ -0,0 +1,34 @@
+/*
+ * UIActionPreparable.java
+ *
+ * Created on April 26, 2007, 3:10 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package org.apache.roller.ui.core.util.struts2;
+
+
+/**
+ * A Roller specific version of the struts2 Preparable interface.
+ *
+ * We only have this because we don't want to use the struts2 Preparable IF due
+ * to the fact that it is meant to be called much earlier in the interceptor
+ * stack, namely before our custom interceptors have been processed.  While
+ * that may make sense in some cases, typically we want to prepare things based
+ * on the user or weblog that we are working on, so it's often of more use for
+ * us to prepare *after* our custom interceptors have been processed.
+ *
+ * So, this duplicate of the struts2 Preparable interface is here so that we
+ * can leave the default struts2 prepare() logic in place for any actions we
+ * may define that want to use that, but also provide a prepare option that is
+ * executed at the very end of our interceptor stack, just before the action
+ * method is executed.  This way our custom prepare method can make use of 
+ * anything our custom interceptors provide.
+ */
+public interface UIActionPreparable {
+    
+    public void myPrepare();
+    
+}

Added: roller/trunk/src/org/apache/roller/ui/core/util/struts2/UIActionPrepareInterceptor.java
URL: http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/ui/core/util/struts2/UIActionPrepareInterceptor.java?view=auto&rev=533433
==============================================================================
--- roller/trunk/src/org/apache/roller/ui/core/util/struts2/UIActionPrepareInterceptor.java
(added)
+++ roller/trunk/src/org/apache/roller/ui/core/util/struts2/UIActionPrepareInterceptor.java
Sat Apr 28 15:14:47 2007
@@ -0,0 +1,54 @@
+/*
+ * UIActionInterceptor.java
+ *
+ * Created on April 16, 2007, 5:30 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package org.apache.roller.ui.core.util.struts2;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
+import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.business.RollerFactory;
+import org.apache.roller.business.UserManager;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.ui.core.RequestConstants;
+import org.apache.roller.ui.core.RollerSession;
+import org.apache.struts2.StrutsStatics;
+
+
+/**
+ * A struts2 interceptor for doing custom prepare logic.
+ */
+public class UIActionPrepareInterceptor extends AbstractInterceptor {
+    
+    private static Log log = LogFactory.getLog(UIActionPrepareInterceptor.class);
+    
+    
+    public String intercept(ActionInvocation invocation) throws Exception {
+        
+        log.debug("Entering UIActionPrepareInterceptor");
+        
+        final Object action = invocation.getAction();
+        final ActionContext context = invocation.getInvocationContext();
+        
+        // is this one of our own UIAction classes?
+        if (action instanceof UIActionPreparable) {
+            
+            log.debug("action is UIActionPreparable, calling myPrepare() method");
+            
+            UIActionPreparable theAction = (UIActionPreparable) action;
+            theAction.myPrepare();
+        }
+        
+        return invocation.invoke();
+    }
+    
+}

Added: roller/trunk/web/WEB-INF/jsps/tiles/struts2/menu.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/web/WEB-INF/jsps/tiles/struts2/menu.jsp?view=auto&rev=533433
==============================================================================
--- roller/trunk/web/WEB-INF/jsps/tiles/struts2/menu.jsp (added)
+++ roller/trunk/web/WEB-INF/jsps/tiles/struts2/menu.jsp Sat Apr 28 15:14:47 2007
@@ -0,0 +1,60 @@
+<%--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  The ASF licenses this file to You
+  under the Apache License, Version 2.0 (the "License"); you may not
+  use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.  For additional information regarding
+  copyright in this work, please see the NOTICE file in the top level
+  directory of this distribution.
+--%>
+<%@ include file="/WEB-INF/jsps/taglibs-struts2.jsp" %>
+
+<s:set name="tabMenu" value="menu"/>
+<s:if test="#tabMenu != null">
+
+<table class="menuTabTable" cellspacing="0" >
+<tr>
+<s:iterator id="tab" value="#tabMenu.tabs" >
+    <s:if test="#tab.selected">
+        <s:set name="selectedTab" value="#tab" />
+        <td class="menuTabSelected">
+    </s:if>
+    <s:else>
+        <td class="menuTabUnselected">
+    </s:else>
+    <div class="menu-tr">
+        <div class="menu-tl">
+            &nbsp;&nbsp;<a href="<s:url action="%{#tab.action}"><s:param
name="weblog" value="actionWeblog.handle"/></s:url>"><s:text name="%{#tab.key}"
/></a>&nbsp;&nbsp;
+        </div>
+    </div>
+    </td>
+    <td class="menuTabSeparator"></td>
+</s:iterator>
+</tr>
+</table>
+
+<table class="menuItemTable" cellspacing="0" >
+    <tr>
+        <td class="padleft">
+            <s:iterator id="tabItem" value="#selectedTab.items" status="stat">
+                <s:if test="!#stat.first">|</s:if>
+                <s:if test="#tabItem.selected">
+                    <a class="menuItemSelected" href="<s:url action="%{#tabItem.action}"><s:param
name="weblog" value="actionWeblog.handle"/></s:url>"><s:text name="%{#tabItem.key}"
/></a>
+                </s:if>
+                <s:else>
+                    <a class="menuItemUnselected" href="<s:url action="%{#tabItem.action}"><s:param
name="weblog" value="actionWeblog.handle"/></s:url>"><s:text name="%{#tabItem.key}"
/></a>
+                </s:else>
+            </s:iterator>
+        </td>
+    </tr>
+</table>
+
+</s:if>



Mime
View raw message