From 5ef3ea1681b8e7904de3412450bb9e4ce9db58b0 Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Sat, 21 Jun 2003 01:38:39 +0000 Subject: [PATCH] added menu editor classes and rigged them to be usable by module installation --- conf/venice-db-init-mysql.sql | 1 + .../venice/iface/MenuEditItemObject.java | 78 ++ .../venice/iface/MenuEditObject.java | 60 ++ .../venice/iface/MenuProvider.java | 7 + .../venice/menu/MenuDatabaseOps.java | 53 ++ .../venice/menu/MenuDatabaseOps_mysql.java | 765 +++++++++++++++++- .../venice/menu/MenuDefinition.java | 141 +++- .../silverwrist/venice/menu/MenuEditImpl.java | 202 +++++ .../venice/menu/MenuEditItemImpl.java | 260 ++++++ .../venice/menu/MenuItemDefinition.java | 174 +++- .../silverwrist/venice/menu/MenuManager.java | 103 ++- .../venice/menu/MenuMessages.properties | 22 + 12 files changed, 1797 insertions(+), 69 deletions(-) create mode 100644 src/venice-base/com/silverwrist/venice/iface/MenuEditItemObject.java create mode 100644 src/venice-base/com/silverwrist/venice/iface/MenuEditObject.java create mode 100644 src/venice-base/com/silverwrist/venice/menu/MenuEditImpl.java create mode 100644 src/venice-base/com/silverwrist/venice/menu/MenuEditItemImpl.java create mode 100644 src/venice-base/com/silverwrist/venice/menu/MenuMessages.properties diff --git a/conf/venice-db-init-mysql.sql b/conf/venice-db-init-mysql.sql index 99b1ee7..2b66656 100644 --- a/conf/venice-db-init-mysql.sql +++ b/conf/venice-db-init-mysql.sql @@ -843,6 +843,7 @@ INSERT INTO acedata (aceid, perm_nsid, perm_name) VALUES (3, 13, 'show.admin.menu' ), (3, 13, 'install.modules' ), (3, 13, 'uninstall.modules' ), + (3, 13, 'edit.menus' ), (3, 14, 'see.member.community.lists'), (3, 14, 'community.directory.all' ), (3, 14, 'community.search.all' ), diff --git a/src/venice-base/com/silverwrist/venice/iface/MenuEditItemObject.java b/src/venice-base/com/silverwrist/venice/iface/MenuEditItemObject.java new file mode 100644 index 0000000..e6681c7 --- /dev/null +++ b/src/venice-base/com/silverwrist/venice/iface/MenuEditItemObject.java @@ -0,0 +1,78 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.iface; + +import com.silverwrist.dynamo.except.DatabaseException; +import com.silverwrist.dynamo.util.QualifiedNameKey; + +public interface MenuEditItemObject +{ + public String getItemType(); + + public int getIndexOfItem(); + + public int getSequence(); + + public void setSequence(int seq) throws DatabaseException; + + public boolean isEnabled(); + + public void setEnabled(boolean flag) throws DatabaseException; + + public int getIndent(); + + public void setIndent(int indent) throws DatabaseException; + + public String getText(); + + public void setText(String text) throws DatabaseException; + + public String getLinkType(); + + public String getLink(); + + public void setLink(String type, String link) throws DatabaseException; + + public String getTarget(); + + public void setTarget(String target) throws DatabaseException; + + public String getTitle(); + + public void setTitle(String title) throws DatabaseException; + + public String getOnClick(); + + public void setOnClick(String on_click) throws DatabaseException; + + public QualifiedNameKey getPermission(); + + public void setPermission(String namespace, String name) throws DatabaseException; + + public String getIfDefVar(); + + public void setIfDefVar(String var) throws DatabaseException; + + public String getIfNotDefVar(); + + public void setIfNotDefVar(String var) throws DatabaseException; + + public void delete() throws DatabaseException; + +} // end interface MenuEditItemObject + diff --git a/src/venice-base/com/silverwrist/venice/iface/MenuEditObject.java b/src/venice-base/com/silverwrist/venice/iface/MenuEditObject.java new file mode 100644 index 0000000..9ad2812 --- /dev/null +++ b/src/venice-base/com/silverwrist/venice/iface/MenuEditObject.java @@ -0,0 +1,60 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.iface; + +import java.util.Set; +import com.silverwrist.dynamo.except.DatabaseException; + +public interface MenuEditObject +{ + public String getTitle(); + + public void setTitle(String title) throws DatabaseException; + + public String getSubtitle(); + + public void setSubtitle(String subtitle) throws DatabaseException; + + public Set getVariables(); + + public String getDefaultVal(String variable); + + public void setDefaultVal(String variable, String value) throws DatabaseException; + + public void addVariable(String variable, String value) throws DatabaseException; + + public void removeVariable(String variable) throws DatabaseException; + + public int getItemCount(); + + public MenuEditItemObject getItem(int ndx); + + public MenuEditItemObject getItemBySequence(int seq); + + public MenuEditItemObject getItemByTypeText(String type, String text); + + public MenuEditItemObject getNextItem(MenuEditItemObject obj); + + public MenuEditItemObject getPreviousItem(MenuEditItemObject obj); + + public MenuEditItemObject addItem(String type, int sequence, String text, String linktype, String link) + throws DatabaseException; + + public void delete() throws DatabaseException; + +} // end interface MenuEditObject diff --git a/src/venice-base/com/silverwrist/venice/iface/MenuProvider.java b/src/venice-base/com/silverwrist/venice/iface/MenuProvider.java index 431993a..6dce04a 100644 --- a/src/venice-base/com/silverwrist/venice/iface/MenuProvider.java +++ b/src/venice-base/com/silverwrist/venice/iface/MenuProvider.java @@ -18,6 +18,7 @@ package com.silverwrist.venice.iface; import com.silverwrist.dynamo.except.DatabaseException; +import com.silverwrist.dynamo.except.DynamoSecurityException; import com.silverwrist.dynamo.iface.DynamoUser; public interface MenuProvider @@ -31,4 +32,10 @@ public interface MenuProvider public MenuRenderObject getInlineMenu(DynamoUser caller, String namespace, String name, int[] acl_ids) throws DatabaseException; + public MenuEditObject getEditMenu(DynamoUser caller, String namespace, String name) + throws DatabaseException, DynamoSecurityException; + + public MenuEditObject createMenu(DynamoUser caller, String namespace, String name, String title) + throws DatabaseException, DynamoSecurityException; + } // end interface MenuProvider diff --git a/src/venice-base/com/silverwrist/venice/menu/MenuDatabaseOps.java b/src/venice-base/com/silverwrist/venice/menu/MenuDatabaseOps.java index e8f1b95..a6d55d4 100644 --- a/src/venice-base/com/silverwrist/venice/menu/MenuDatabaseOps.java +++ b/src/venice-base/com/silverwrist/venice/menu/MenuDatabaseOps.java @@ -59,6 +59,18 @@ abstract class MenuDatabaseOps extends OpsBase } // end namespaceIdToName + /*-------------------------------------------------------------------------------- + * Overrides from class OpsBase + *-------------------------------------------------------------------------------- + */ + + public void dispose() + { + m_ns_cache = null; + super.dispose(); + + } // end dispose + /*-------------------------------------------------------------------------------- * Abstract operations *-------------------------------------------------------------------------------- @@ -66,6 +78,47 @@ abstract class MenuDatabaseOps extends OpsBase abstract MenuDefinition getMenu(String namespace, String name) throws DatabaseException; + abstract void setMenuTitle(int id, String title) throws DatabaseException; + + abstract void setMenuSubtitle(int id, String subtitle) throws DatabaseException; + + abstract void setDefaultVal(int id, String variable, String value) throws DatabaseException; + + abstract void addVariable(int id, String variable, String value) throws DatabaseException; + + abstract void removeVariable(int id, String variable) throws DatabaseException; + + abstract void setItemSequence(int id, int old_seq, int new_seq) throws DatabaseException; + + abstract void setItemEnable(int id, int seq, boolean enable) throws DatabaseException; + + abstract void setItemIndent(int id, int seq, int indent) throws DatabaseException; + + abstract void setItemText(int id, int seq, String text) throws DatabaseException; + + abstract void setItemLink(int id, int seq, String linktype, String link) throws DatabaseException; + + abstract void setItemTarget(int id, int seq, String target) throws DatabaseException; + + abstract void setItemTitle(int id, int seq, String title) throws DatabaseException; + + abstract void setItemOnClick(int id, int seq, String on_click) throws DatabaseException; + + abstract void setItemPermission(int id, int seq, String namespace, String name) throws DatabaseException; + + abstract void setItemIfDef(int id, int seq, String var) throws DatabaseException; + + abstract void setItemIfNotDef(int id, int seq, String var) throws DatabaseException; + + abstract void addItem(int id, String type, int seq, String text, String linktype, String link) + throws DatabaseException; + + abstract void deleteItem(int id, int seq) throws DatabaseException; + + abstract void deleteMenu(int id) throws DatabaseException; + + abstract int createMenu(String namespace, String name, String title) throws DatabaseException; + /*-------------------------------------------------------------------------------- * External operations *-------------------------------------------------------------------------------- diff --git a/src/venice-base/com/silverwrist/venice/menu/MenuDatabaseOps_mysql.java b/src/venice-base/com/silverwrist/venice/menu/MenuDatabaseOps_mysql.java index fc45e75..4982e68 100644 --- a/src/venice-base/com/silverwrist/venice/menu/MenuDatabaseOps_mysql.java +++ b/src/venice-base/com/silverwrist/venice/menu/MenuDatabaseOps_mysql.java @@ -80,19 +80,19 @@ public class MenuDatabaseOps_mysql extends MenuDatabaseOps SQLUtils.shutdown(stmt); // get the menu items - stmt = conn.prepareStatement("SELECT itemtype, enable, indent, text, linktype, link, target, title, " + stmt = conn.prepareStatement("SELECT itemtype, sequence, enable, indent, text, linktype, link, target, title, " + "on_click, perm_nsid, perm_name, ifdef_var, ifndef_var FROM menuitems " + "WHERE menuid = ? ORDER BY sequence;"); stmt.setInt(1,id); rs = stmt.executeQuery(); while (rs.next()) { // get the namespace and add the item definition - int nsid = rs.getInt(10); + int nsid = rs.getInt(11); String ns = (rs.wasNull() ? null : namespaceIdToName(nsid)); - MenuItemDefinition item = new MenuItemDefinition(rs.getString(1),(rs.getInt(2)!=0),rs.getInt(3), - rs.getString(4),rs.getString(5),rs.getString(6), - rs.getString(7),rs.getString(8),rs.getString(9),ns, - rs.getString(11),rs.getString(12),rs.getString(13)); + MenuItemDefinition item = new MenuItemDefinition(rs.getString(1),rs.getInt(2),(rs.getInt(3)!=0),rs.getInt(4), + rs.getString(5),rs.getString(6),rs.getString(7), + rs.getString(8),rs.getString(9),rs.getString(10),ns, + rs.getString(12),rs.getString(13),rs.getString(14)); def.addItemDef(item); } // end while @@ -115,4 +115,757 @@ public class MenuDatabaseOps_mysql extends MenuDatabaseOps } // end getMenu + void setMenuTitle(int id, String title) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menus WRITE;"); + + // create and execute the proper statement + stmt = conn.prepareStatement("UPDATE menus SET title = ? WHERE menuid = ?;"); + stmt.setString(1,title); + stmt.setInt(2,id); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end setMenuTitle + + void setMenuSubtitle(int id, String subtitle) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menus WRITE;"); + + // create and execute the proper statement + stmt = conn.prepareStatement("UPDATE menus SET subtitle = ? WHERE menuid = ?;"); + stmt.setString(1,subtitle); + stmt.setInt(2,id); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end setMenuSubtitle + + void setDefaultVal(int id, String variable, String value) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuvars WRITE;"); + + // create and execute the statement + stmt = conn.prepareStatement("UPDATE menuvars SET default_val = ? WHERE menuid = ? AND var_name = ?;"); + stmt.setString(1,value); + stmt.setInt(2,id); + stmt.setString(3,variable); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end setDefaultVal + + void addVariable(int id, String variable, String value) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuvars WRITE;"); + + // create and execute the appropriate statement + stmt = conn.prepareStatement("INSERT INTO menuvars (menuid, var_name, default_val) VALUES (?, ?, ?);"); + stmt.setInt(1,id); + stmt.setString(2,variable); + stmt.setString(3,value); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end addVariable + + void removeVariable(int id, String variable) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuvars WRITE;"); + + // create and execute the appropriate statement + stmt = conn.prepareStatement("DELETE FROM menuvars WHERE menuid = ? AND var_name = ?;"); + stmt.setInt(1,id); + stmt.setString(2,variable); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end removeVariable + + void setItemSequence(int id, int old_seq, int new_seq) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuitems WRITE;"); + + // create and execute the statement + stmt = conn.prepareStatement("UPDATE menuitems SET sequence = ? WHERE menuid = ? AND sequence = ?;"); + stmt.setInt(1,new_seq); + stmt.setInt(2,id); + stmt.setInt(3,old_seq); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end setItemSequence + + void setItemEnable(int id, int seq, boolean enable) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuitems WRITE;"); + + // create and execute the statement + stmt = conn.prepareStatement("UPDATE menuitems SET enable = ? WHERE menuid = ? AND sequence = ?;"); + stmt.setInt(1,(enable ? 1 : 0)); + stmt.setInt(2,id); + stmt.setInt(3,seq); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end setItemEnable + + void setItemIndent(int id, int seq, int indent) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuitems WRITE;"); + + // create and execute the statement + stmt = conn.prepareStatement("UPDATE menuitems SET indent = ? WHERE menuid = ? AND sequence = ?;"); + stmt.setInt(1,indent); + stmt.setInt(2,id); + stmt.setInt(3,seq); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end setItemIndent + + void setItemText(int id, int seq, String text) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuitems WRITE;"); + + // create and execute the statement + stmt = conn.prepareStatement("UPDATE menuitems SET text = ? WHERE menuid = ? AND sequence = ?;"); + stmt.setString(1,text); + stmt.setInt(2,id); + stmt.setInt(3,seq); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end setItemText + + void setItemLink(int id, int seq, String linktype, String link) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuitems WRITE;"); + + // create and execute the statement + stmt = conn.prepareStatement("UPDATE menuitems SET linktype = ?, link = ? WHERE menuid = ? AND sequence = ?;"); + stmt.setString(1,linktype); + stmt.setString(2,link); + stmt.setInt(3,id); + stmt.setInt(4,seq); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end setItemLink + + void setItemTarget(int id, int seq, String target) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuitems WRITE;"); + + // create and execute the statement + stmt = conn.prepareStatement("UPDATE menuitems SET target = ? WHERE menuid = ? AND sequence = ?;"); + stmt.setString(1,target); + stmt.setInt(2,id); + stmt.setInt(3,seq); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end target + + void setItemTitle(int id, int seq, String title) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuitems WRITE;"); + + // create and execute the statement + stmt = conn.prepareStatement("UPDATE menuitems SET title = ? WHERE menuid = ? AND sequence = ?;"); + stmt.setString(1,title); + stmt.setInt(2,id); + stmt.setInt(3,seq); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end setItemTitle + + void setItemOnClick(int id, int seq, String on_click) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuitems WRITE;"); + + // create and execute the statement + stmt = conn.prepareStatement("UPDATE menuitems SET on_click = ? WHERE menuid = ? AND sequence = ?;"); + stmt.setString(1,on_click); + stmt.setInt(2,id); + stmt.setInt(3,seq); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end setItemOnClick + + void setItemPermission(int id, int seq, String namespace, String name) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuitems WRITE;"); + + // create and execute the statement + stmt = conn.prepareStatement("UPDATE menuitems SET perm_nsid = ?, perm_name = ? WHERE menuid = ? " + + "AND sequence = ?;"); + if (namespace==null) + stmt.setNull(1,Types.INTEGER); + else + stmt.setInt(1,namespaceNameToId(namespace)); + stmt.setString(2,name); + stmt.setInt(3,id); + stmt.setInt(4,seq); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end setItemPermission + + void setItemIfDef(int id, int seq, String var) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuitems WRITE;"); + + // create and execute the statement + stmt = conn.prepareStatement("UPDATE menuitems SET ifdef_var = ? WHERE menuid = ? AND sequence = ?;"); + stmt.setString(1,var); + stmt.setInt(2,id); + stmt.setInt(3,seq); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end setItemIfDef + + void setItemIfNotDef(int id, int seq, String var) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuitems WRITE;"); + + // create and execute the statement + stmt = conn.prepareStatement("UPDATE menuitems SET ifndef_var = ? WHERE menuid = ? AND sequence = ?;"); + stmt.setString(1,var); + stmt.setInt(2,id); + stmt.setInt(3,seq); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end setItemIfNotDef + + void addItem(int id, String type, int seq, String text, String linktype, String link) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuitems WRITE;"); + + // create and execute the insert statement + stmt = conn.prepareStatement("INSERT INTO menuitems (menuid, sequence, itemtype, text, linktype, link) " + + "VALUES (?, ?, ?, ?, ?, ?);"); + stmt.setInt(1,id); + stmt.setString(2,type); + stmt.setInt(3,seq); + stmt.setString(4,text); + stmt.setString(5,linktype); + stmt.setString(6,link); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end addItem + + void deleteItem(int id, int seq) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menuitems WRITE;"); + + // create and execute the statement + stmt = conn.prepareStatement("DELETE FROM menuitems WHERE menuid = ? AND sequence = ?;"); + stmt.setInt(1,id); + stmt.setInt(2,seq); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end deleteItem + + void deleteMenu(int id) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menus WRITE, menuvars WRITE, menuitems WRITE;"); + + // delete from the three tables + stmt = conn.prepareStatement("DELETE FROM menus WHERE menuid = ?;"); + stmt.setInt(1,id); + stmt.executeUpdate(); + stmt.close(); + stmt = conn.prepareStatement("DELETE FROM menuvars WHERE menuid = ?;"); + stmt.setInt(1,id); + stmt.executeUpdate(); + stmt.close(); + stmt = conn.prepareStatement("DELETE FROM menuitems WHERE menuid = ?;"); + stmt.setInt(1,id); + stmt.executeUpdate(); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end deleteMenu + + int createMenu(String namespace, String name, String title) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + try + { // get a connection + conn = getConnection(); + + // lock the appropriate table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES menus WRITE;"); + + // insert the menu record + stmt = conn.prepareStatement("INSERT INTO menus (menu_nsid, menu_name, title) VALUES (?, ?, ?);"); + stmt.setInt(1,namespaceNameToId(namespace)); + stmt.setString(2,name); + stmt.setString(3,title); + stmt.executeUpdate(); + return MySQLUtils.getLastInsertInt(conn); + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end createMenu + } // end class MenuDatabaseOps_mysql diff --git a/src/venice-base/com/silverwrist/venice/menu/MenuDefinition.java b/src/venice-base/com/silverwrist/venice/menu/MenuDefinition.java index 2be4c88..dc7ec1f 100644 --- a/src/venice-base/com/silverwrist/venice/menu/MenuDefinition.java +++ b/src/venice-base/com/silverwrist/venice/menu/MenuDefinition.java @@ -19,7 +19,7 @@ package com.silverwrist.venice.menu; import java.util.*; -public class MenuDefinition +class MenuDefinition { /*-------------------------------------------------------------------------------- * Attributes @@ -34,6 +34,7 @@ public class MenuDefinition private HashSet m_vars = new HashSet(); private HashMap m_defaults = new HashMap(); private ArrayList m_items = new ArrayList(); + private boolean m_deleted = false; /*-------------------------------------------------------------------------------- * Constructor @@ -51,11 +52,11 @@ public class MenuDefinition } // end constructor /*-------------------------------------------------------------------------------- - * Internal operations + * External operations *-------------------------------------------------------------------------------- */ - void addVariableDef(String name, String default_val) + synchronized void addVariableDef(String name, String default_val) { m_vars.add(name); if (default_val!=null) @@ -63,66 +64,113 @@ public class MenuDefinition } // end addVariableDef - void addItemDef(MenuItemDefinition item) + synchronized void removeVariableDef(String name) + { + m_vars.remove(name); + m_defaults.remove(name); + + } // end removeVariableDef + + synchronized void setDefaultVal(String variable, String value) + { + if (value!=null) + m_defaults.put(variable,value); + else + m_defaults.remove(variable); + + } // end setDefaultVal + + synchronized void addItemDef(MenuItemDefinition item) { m_items.add(item); } // end addItemDef + synchronized void removeItemDef(MenuItemDefinition item) + { + m_items.remove(item); + + } // end removeItemDef + + Set getVars() + { + return Collections.unmodifiableSet(m_vars); + + } // end getVars + Map getVarDefaults() { return Collections.unmodifiableMap(m_defaults); } // end getVarDefaults - /*-------------------------------------------------------------------------------- - * External operations - *-------------------------------------------------------------------------------- - */ + int getID() + { + return m_id; - public String getNamespace() + } // end getID + + String getNamespace() { return m_namespace; } // end getNamespace - public String getName() + String getName() { return m_name; } // end getName - public String getTitle() + String getTitle() { return m_title; } // end getTitle - public String getSubtitle() + synchronized void setTitle(String title) + { + m_title = title; + + } // end setTitle + + String getSubtitle() { return m_subtitle; } // end getSubtitle - public boolean isVariable(String name) + synchronized void setSubtitle(String subtitle) + { + m_subtitle = subtitle; + + } // end setSubtitle + + boolean isVariable(String name) { return m_vars.contains(name); } // end isVariable - public int getItemCount() + int getItemCount() { return m_items.size(); } // end getItemCount - public MenuItemDefinition getItem(int ndx) + MenuItemDefinition getItem(int ndx) { return (MenuItemDefinition)(m_items.get(ndx)); } // end getItem - public int getItemContainingLinkText(String text) + int getIndexOf(MenuItemDefinition item) + { + return m_items.indexOf(item); + + } // end getIndexOf + + int getItemContainingLinkText(String text) { for (int i=0; iseq) + return -1; + + } // end for + + return -1; + + } // end if + + int getItemByTypeText(String type, String text) + { + for (int i=0; i1) + Collections.sort(m_items); + + } // end resequence + + boolean isDeleted() + { + return m_deleted; + + } // end isDeleted + + synchronized void delete() + { + m_deleted = true; + Iterator it = m_items.iterator(); + while (it.hasNext()) + { // delete all the items as well + MenuItemDefinition item = (MenuItemDefinition)(it.next()); + item.delete(); + + } // end while + + m_items.clear(); + m_vars.clear(); + m_defaults.clear(); + + } // end delete + } // end class MenuDefinition diff --git a/src/venice-base/com/silverwrist/venice/menu/MenuEditImpl.java b/src/venice-base/com/silverwrist/venice/menu/MenuEditImpl.java new file mode 100644 index 0000000..11a082d --- /dev/null +++ b/src/venice-base/com/silverwrist/venice/menu/MenuEditImpl.java @@ -0,0 +1,202 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.menu; + +import java.util.*; +import com.silverwrist.dynamo.except.*; +import com.silverwrist.venice.iface.*; + +class MenuEditImpl implements MenuEditObject +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private MenuDatabaseOps m_ops; + private MenuDefinition m_mdef; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + MenuEditImpl(MenuDatabaseOps ops, MenuDefinition mdef) + { + m_ops = ops; + m_mdef = mdef; + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Internal operations + *-------------------------------------------------------------------------------- + */ + + private final void baleeted() throws DatabaseException + { + if ((m_ops==null) || (m_mdef==null)) + throw new DatabaseException(MenuEditImpl.class,"MenuMessages","menu.deleted"); + if (m_mdef.isDeleted()) + { // isolate the object and throw the exception + m_ops = null; + m_mdef = null; + throw new DatabaseException(MenuEditImpl.class,"MenuMessages","menu.deleted"); + + } // end if + + } // end baleeted + + /*-------------------------------------------------------------------------------- + * Implementations from interface MenuEditObject + *-------------------------------------------------------------------------------- + */ + + public String getTitle() + { + return (m_mdef==null) ? null : m_mdef.getTitle(); + + } // end getTitle + + public void setTitle(String title) throws DatabaseException + { + baleeted(); + m_ops.setMenuTitle(m_mdef.getID(),title); + m_mdef.setTitle(title); + + } // end setTitle + + public String getSubtitle() + { + return (m_mdef==null) ? null : m_mdef.getSubtitle(); + + } // end getSubtitle + + public void setSubtitle(String subtitle) throws DatabaseException + { + baleeted(); + m_ops.setMenuSubtitle(m_mdef.getID(),subtitle); + m_mdef.setSubtitle(subtitle); + + } // end setSubtitle + + public Set getVariables() + { + return (m_mdef==null) ? null : m_mdef.getVars(); + + } // end getVariables + + public String getDefaultVal(String variable) + { + return (m_mdef==null) ? null : (String)(m_mdef.getVarDefaults().get(variable)); + + } // end getDefaultVal + + public void setDefaultVal(String variable, String value) throws DatabaseException + { + baleeted(); + m_ops.setDefaultVal(m_mdef.getID(),variable,value); + m_mdef.setDefaultVal(variable,value); + + } // end setDefaultVal + + public void addVariable(String variable, String value) throws DatabaseException + { + baleeted(); + m_ops.addVariable(m_mdef.getID(),variable,value); + m_mdef.addVariableDef(variable,value); + + } // end addVariable + + public void removeVariable(String variable) throws DatabaseException + { + baleeted(); + m_ops.removeVariable(m_mdef.getID(),variable); + m_mdef.removeVariableDef(variable); + + } // end removeVariable + + public int getItemCount() + { + return (m_mdef==null) ? -1 : m_mdef.getItemCount(); + + } // end getItemCount + + public MenuEditItemObject getItem(int ndx) + { + if (m_mdef==null) + return null; + MenuItemDefinition item = m_mdef.getItem(ndx); + return new MenuEditItemImpl(m_ops,m_mdef,item); + + } // end getItem + + public MenuEditItemObject getItemBySequence(int seq) + { + if (m_mdef==null) + return null; + int ndx = m_mdef.getItemBySequence(seq); + return (ndx<0) ? null : this.getItem(ndx); + + } // end getItemBySequence + + public MenuEditItemObject getItemByTypeText(String type, String text) + { + if (m_mdef==null) + return null; + int ndx = m_mdef.getItemByTypeText(type,text); + return (ndx<0) ? null : this.getItem(ndx); + + } // end getItemByTypeText + + public MenuEditItemObject getNextItem(MenuEditItemObject obj) + { + return this.getItem(obj.getIndexOfItem() + 1); + + } // end getNextItem + + public MenuEditItemObject getPreviousItem(MenuEditItemObject obj) + { + return this.getItem(obj.getIndexOfItem() - 1); + + } // end getPreviousItem + + public MenuEditItemObject addItem(String type, int sequence, String text, String linktype, String link) + throws DatabaseException + { + baleeted(); + m_ops.addItem(m_mdef.getID(),type,sequence,text,linktype,link); + MenuItemDefinition item = new MenuItemDefinition(type,sequence,true,0,text,linktype,link,null,null,null,null, + null,null,null); + m_mdef.addItemDef(item); + m_mdef.resequence(); + return new MenuEditItemImpl(m_ops,m_mdef,item); + + } // end addItem + + public void delete() throws DatabaseException + { + baleeted(); + m_ops.deleteMenu(m_mdef.getID()); + m_mdef.delete(); + m_mdef = null; + m_ops = null; + + } // end delete + +} // end class MenuEditImpl diff --git a/src/venice-base/com/silverwrist/venice/menu/MenuEditItemImpl.java b/src/venice-base/com/silverwrist/venice/menu/MenuEditItemImpl.java new file mode 100644 index 0000000..579cd3d --- /dev/null +++ b/src/venice-base/com/silverwrist/venice/menu/MenuEditItemImpl.java @@ -0,0 +1,260 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.menu; + +import com.silverwrist.dynamo.except.*; +import com.silverwrist.dynamo.util.*; +import com.silverwrist.venice.iface.*; + +class MenuEditItemImpl implements MenuEditItemObject +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private MenuDatabaseOps m_ops; + private MenuDefinition m_mdef; + private MenuItemDefinition m_item; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + MenuEditItemImpl(MenuDatabaseOps ops, MenuDefinition mdef, MenuItemDefinition item) + { + m_ops = ops; + m_mdef = mdef; + m_item = item; + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Internal operations + *-------------------------------------------------------------------------------- + */ + + private final void baleeted() throws DatabaseException + { + if ((m_ops==null) || (m_mdef==null) || (m_item==null)) + throw new DatabaseException(MenuEditItemImpl.class,"MenuMessages","item.deleted"); + if (m_item.isDeleted() || m_mdef.isDeleted()) + { // isolate the object and throw the exception + m_ops = null; + m_mdef = null; + m_item = null; + throw new DatabaseException(MenuEditItemImpl.class,"MenuMessages","item.deleted"); + + } // end if + + } // end baleeted + + /*-------------------------------------------------------------------------------- + * Implementations from interface MenuEditItemObject + *-------------------------------------------------------------------------------- + */ + + public String getItemType() + { + return (m_item==null) ? null : m_item.getItemType(); + + } // end getItemType + + public int getIndexOfItem() + { + return m_mdef.getIndexOf(m_item); + + } // end getIndexOfItem + + public int getSequence() + { + return (m_item==null) ? -1 : m_item.getSequence(); + + } // end getSequence + + public void setSequence(int seq) throws DatabaseException + { + baleeted(); + m_ops.setItemSequence(m_mdef.getID(),m_item.getSequence(),seq); + m_item.setSequence(seq); + m_mdef.resequence(); + + } // end setSequence + + public boolean isEnabled() + { + return (m_item==null) ? false : m_item.isEnabled(); + + } // end isEnabled + + public void setEnabled(boolean flag) throws DatabaseException + { + baleeted(); + m_ops.setItemEnable(m_mdef.getID(),m_item.getSequence(),flag); + m_item.setEnabled(flag); + + } // end setEnabled + + public int getIndent() + { + return (m_item==null) ? 0 : m_item.getIndentLevel(); + + } // end getIndent + + public void setIndent(int indent) throws DatabaseException + { + baleeted(); + if (indent<0) + throw new IllegalArgumentException("indent must be >= 0"); + m_ops.setItemIndent(m_mdef.getID(),m_item.getSequence(),indent); + m_item.setIndentLevel(indent); + + } // end setIndent + + public String getText() + { + return (m_item==null) ? null : m_item.getText(); + + } // end getText + + public void setText(String text) throws DatabaseException + { + baleeted(); + m_ops.setItemText(m_mdef.getID(),m_item.getSequence(),text); + m_item.setText(text); + + } // end setText + + public String getLinkType() + { + return (m_item==null) ? null : m_item.getLinkType(); + + } // end getLinkType + + public String getLink() + { + return (m_item==null) ? null : m_item.getLink(); + + } // end getLink + + public void setLink(String type, String link) throws DatabaseException + { + baleeted(); + m_ops.setItemLink(m_mdef.getID(),m_item.getSequence(),type,link); + m_item.setLink(type,link); + + } // end setLink + + public String getTarget() + { + return (m_item==null) ? null : m_item.getTarget(); + + } // end getTarget + + public void setTarget(String target) throws DatabaseException + { + baleeted(); + m_ops.setItemTarget(m_mdef.getID(),m_item.getSequence(),target); + m_item.setTarget(target); + + } // end setTarget + + public String getTitle() + { + return (m_item==null) ? null : m_item.getTitle(); + + } // end getTitle + + public void setTitle(String title) throws DatabaseException + { + baleeted(); + m_ops.setItemTitle(m_mdef.getID(),m_item.getSequence(),title); + m_item.setTitle(title); + + } // end setTitle + + public String getOnClick() + { + return (m_item==null) ? null : m_item.getOnClick(); + + } // end getOnClick + + public void setOnClick(String on_click) throws DatabaseException + { + baleeted(); + m_ops.setItemOnClick(m_mdef.getID(),m_item.getSequence(),on_click); + m_item.setOnClick(on_click); + + } // end setOnClick + + public QualifiedNameKey getPermission() + { + return (m_item==null) ? null : m_item.getPermission(); + + } // end getPermission + + public void setPermission(String namespace, String name) throws DatabaseException + { + baleeted(); + m_ops.setItemPermission(m_mdef.getID(),m_item.getSequence(),namespace,name); + m_item.setPermission(namespace,name); + + } // end setPermission + + public String getIfDefVar() + { + return (m_item==null) ? null : m_item.getIfDefVar(); + + } // end getIfDefVar + + public void setIfDefVar(String var) throws DatabaseException + { + baleeted(); + m_ops.setItemIfDef(m_mdef.getID(),m_item.getSequence(),var); + m_item.setIfDefVar(var); + + } // end setIfDefVar + + public String getIfNotDefVar() + { + return (m_item==null) ? null : m_item.getIfNotDefVar(); + + } // end getIfNotDefVar + + public void setIfNotDefVar(String var) throws DatabaseException + { + baleeted(); + m_ops.setItemIfNotDef(m_mdef.getID(),m_item.getSequence(),var); + m_item.setIfNotDefVar(var); + + } // end setIfNotDefVar + + public void delete() throws DatabaseException + { + baleeted(); + m_ops.deleteItem(m_mdef.getID(),m_item.getSequence()); + m_mdef.removeItemDef(m_item); + m_item.delete(); + m_ops = null; + m_mdef = null; + m_item = null; + + } // end delete + +} // end class MenuEditItemImpl diff --git a/src/venice-base/com/silverwrist/venice/menu/MenuItemDefinition.java b/src/venice-base/com/silverwrist/venice/menu/MenuItemDefinition.java index 68ad437..4949464 100644 --- a/src/venice-base/com/silverwrist/venice/menu/MenuItemDefinition.java +++ b/src/venice-base/com/silverwrist/venice/menu/MenuItemDefinition.java @@ -20,9 +20,10 @@ package com.silverwrist.venice.menu; import java.util.*; import com.silverwrist.dynamo.except.*; import com.silverwrist.dynamo.iface.*; +import com.silverwrist.dynamo.util.*; import com.silverwrist.dynamo.security.SecurityReferenceMonitor; -public class MenuItemDefinition +class MenuItemDefinition implements Comparable { /*-------------------------------------------------------------------------------- * Attributes @@ -30,6 +31,7 @@ public class MenuItemDefinition */ private String m_type; + private int m_sequence; private boolean m_enable; private int m_indent; private String m_text; @@ -42,17 +44,19 @@ public class MenuItemDefinition private String m_perm_name; private String m_ifdef_var; private String m_ifndef_var; + private boolean m_deleted = false; /*-------------------------------------------------------------------------------- * Constructor *-------------------------------------------------------------------------------- */ - MenuItemDefinition(String type, boolean enable, int indent, String text, String linktype, String link, + MenuItemDefinition(String type, int sequence, boolean enable, int indent, String text, String linktype, String link, String target, String title, String on_click, String perm_namespace, String perm_name, String ifdef_var, String ifndef_var) { m_type = type; + m_sequence = sequence; m_enable = enable; m_indent = indent; m_text = text; @@ -71,12 +75,49 @@ public class MenuItemDefinition } // end constructor /*-------------------------------------------------------------------------------- - * Internal operations + * Overrides from class Object + *-------------------------------------------------------------------------------- + */ + + public boolean equals(Object o) + { + if ((o==null) || !(o instanceof MenuItemDefinition)) + return false; + return (((MenuItemDefinition)o).m_sequence==this.m_sequence); + + } // end equals + + public int hashCode() + { + return m_sequence; + + } // end hashCode + + /*-------------------------------------------------------------------------------- + * Implementations from interface Comparable + *-------------------------------------------------------------------------------- + */ + + public int compareTo(Object o) + { + if (o==null) + throw new NullPointerException("MenuItemDefinition.compareTo"); + if (!(o instanceof MenuItemDefinition)) + throw new ClassCastException("MenuItemDefinition.compareTo"); + MenuItemDefinition other = (MenuItemDefinition)o; + return other.m_sequence - this.m_sequence; + + } // end compareTo + + /*-------------------------------------------------------------------------------- + * External operations *-------------------------------------------------------------------------------- */ boolean itemAppears(DynamoUser caller, SecurityReferenceMonitor srm, int[] acl_ids) throws DatabaseException { + if (m_type.equals("MARKER") || m_deleted) + return false; if ((m_perm_namespace==null) && (m_perm_name==null)) return true; for (int i=0; i. +# +# Software distributed under the License is distributed on an "AS IS" basis, WITHOUT +# WARRANTY OF ANY KIND, either express or implied. See the License for the specific +# language governing rights and limitations under the License. +# +# The Original Code is the Venice Web Communities System. +# +# The Initial Developer of the Original Code is Eric J. Bowersox , +# for Silverwrist Design Studios. Portions created by Eric J. Bowersox are +# Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +# +# Contributor(s): +# --------------------------------------------------------------------------------- +# This file has been localized for the en_US locale +auth.editMenu=You are not permitted to change the contents of menus. +item.deleted=This menu item has been deleted. +menu.deleted=This menu has been deleted. +menu.notFound=The menu {0}::{1} was not found. +auth.createMenu=You are not permitted to create a new menu.