added menu editor classes and rigged them to be usable by module installation

This commit is contained in:
Eric J. Bowersox 2003-06-21 01:38:39 +00:00
parent 6269e1c3e8
commit 5ef3ea1681
12 changed files with 1797 additions and 69 deletions

View File

@ -843,6 +843,7 @@ INSERT INTO acedata (aceid, perm_nsid, perm_name) VALUES
(3, 13, 'show.admin.menu' ), (3, 13, 'show.admin.menu' ),
(3, 13, 'install.modules' ), (3, 13, 'install.modules' ),
(3, 13, 'uninstall.modules' ), (3, 13, 'uninstall.modules' ),
(3, 13, 'edit.menus' ),
(3, 14, 'see.member.community.lists'), (3, 14, 'see.member.community.lists'),
(3, 14, 'community.directory.all' ), (3, 14, 'community.directory.all' ),
(3, 14, 'community.search.all' ), (3, 14, 'community.search.all' ),

View File

@ -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 <http://www.mozilla.org/MPL/>.
*
* 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 <erbo@silcom.com>,
* 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

View File

@ -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 <http://www.mozilla.org/MPL/>.
*
* 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 <erbo@silcom.com>,
* 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

View File

@ -18,6 +18,7 @@
package com.silverwrist.venice.iface; package com.silverwrist.venice.iface;
import com.silverwrist.dynamo.except.DatabaseException; import com.silverwrist.dynamo.except.DatabaseException;
import com.silverwrist.dynamo.except.DynamoSecurityException;
import com.silverwrist.dynamo.iface.DynamoUser; import com.silverwrist.dynamo.iface.DynamoUser;
public interface MenuProvider public interface MenuProvider
@ -31,4 +32,10 @@ public interface MenuProvider
public MenuRenderObject getInlineMenu(DynamoUser caller, String namespace, String name, int[] acl_ids) public MenuRenderObject getInlineMenu(DynamoUser caller, String namespace, String name, int[] acl_ids)
throws DatabaseException; 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 } // end interface MenuProvider

View File

@ -59,6 +59,18 @@ abstract class MenuDatabaseOps extends OpsBase
} // end namespaceIdToName } // end namespaceIdToName
/*--------------------------------------------------------------------------------
* Overrides from class OpsBase
*--------------------------------------------------------------------------------
*/
public void dispose()
{
m_ns_cache = null;
super.dispose();
} // end dispose
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Abstract operations * Abstract operations
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
@ -66,6 +78,47 @@ abstract class MenuDatabaseOps extends OpsBase
abstract MenuDefinition getMenu(String namespace, String name) throws DatabaseException; 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 * External operations
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------

View File

@ -80,19 +80,19 @@ public class MenuDatabaseOps_mysql extends MenuDatabaseOps
SQLUtils.shutdown(stmt); SQLUtils.shutdown(stmt);
// get the menu items // 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 " + "on_click, perm_nsid, perm_name, ifdef_var, ifndef_var FROM menuitems "
+ "WHERE menuid = ? ORDER BY sequence;"); + "WHERE menuid = ? ORDER BY sequence;");
stmt.setInt(1,id); stmt.setInt(1,id);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) while (rs.next())
{ // get the namespace and add the item definition { // 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)); String ns = (rs.wasNull() ? null : namespaceIdToName(nsid));
MenuItemDefinition item = new MenuItemDefinition(rs.getString(1),(rs.getInt(2)!=0),rs.getInt(3), MenuItemDefinition item = new MenuItemDefinition(rs.getString(1),rs.getInt(2),(rs.getInt(3)!=0),rs.getInt(4),
rs.getString(4),rs.getString(5),rs.getString(6), rs.getString(5),rs.getString(6),rs.getString(7),
rs.getString(7),rs.getString(8),rs.getString(9),ns, rs.getString(8),rs.getString(9),rs.getString(10),ns,
rs.getString(11),rs.getString(12),rs.getString(13)); rs.getString(12),rs.getString(13),rs.getString(14));
def.addItemDef(item); def.addItemDef(item);
} // end while } // end while
@ -115,4 +115,757 @@ public class MenuDatabaseOps_mysql extends MenuDatabaseOps
} // end getMenu } // 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 } // end class MenuDatabaseOps_mysql

View File

@ -19,7 +19,7 @@ package com.silverwrist.venice.menu;
import java.util.*; import java.util.*;
public class MenuDefinition class MenuDefinition
{ {
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Attributes * Attributes
@ -34,6 +34,7 @@ public class MenuDefinition
private HashSet m_vars = new HashSet(); private HashSet m_vars = new HashSet();
private HashMap m_defaults = new HashMap(); private HashMap m_defaults = new HashMap();
private ArrayList m_items = new ArrayList(); private ArrayList m_items = new ArrayList();
private boolean m_deleted = false;
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Constructor * Constructor
@ -51,11 +52,11 @@ public class MenuDefinition
} // end constructor } // 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); m_vars.add(name);
if (default_val!=null) if (default_val!=null)
@ -63,66 +64,113 @@ public class MenuDefinition
} // end addVariableDef } // 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); m_items.add(item);
} // end addItemDef } // end addItemDef
synchronized void removeItemDef(MenuItemDefinition item)
{
m_items.remove(item);
} // end removeItemDef
Set getVars()
{
return Collections.unmodifiableSet(m_vars);
} // end getVars
Map getVarDefaults() Map getVarDefaults()
{ {
return Collections.unmodifiableMap(m_defaults); return Collections.unmodifiableMap(m_defaults);
} // end getVarDefaults } // end getVarDefaults
/*-------------------------------------------------------------------------------- int getID()
* External operations {
*-------------------------------------------------------------------------------- return m_id;
*/
public String getNamespace() } // end getID
String getNamespace()
{ {
return m_namespace; return m_namespace;
} // end getNamespace } // end getNamespace
public String getName() String getName()
{ {
return m_name; return m_name;
} // end getName } // end getName
public String getTitle() String getTitle()
{ {
return m_title; return m_title;
} // end getTitle } // end getTitle
public String getSubtitle() synchronized void setTitle(String title)
{
m_title = title;
} // end setTitle
String getSubtitle()
{ {
return m_subtitle; return m_subtitle;
} // end getSubtitle } // 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); return m_vars.contains(name);
} // end isVariable } // end isVariable
public int getItemCount() int getItemCount()
{ {
return m_items.size(); return m_items.size();
} // end getItemCount } // end getItemCount
public MenuItemDefinition getItem(int ndx) MenuItemDefinition getItem(int ndx)
{ {
return (MenuItemDefinition)(m_items.get(ndx)); return (MenuItemDefinition)(m_items.get(ndx));
} // end getItem } // 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; i<m_items.size(); i++) for (int i=0; i<m_items.size(); i++)
{ // simple linear search through menu items { // simple linear search through menu items
@ -136,4 +184,65 @@ public class MenuDefinition
} // end getItemContainingLinkText } // end getItemContainingLinkText
int getItemBySequence(int seq)
{
for (int i=0; i<m_items.size(); i++)
{ // simple linear search through menu items
MenuItemDefinition md = (MenuItemDefinition)(m_items.get(i));
int md_seq = md.getSequence();
if (md_seq==seq)
return i;
else if (md_seq>seq)
return -1;
} // end for
return -1;
} // end if
int getItemByTypeText(String type, String text)
{
for (int i=0; i<m_items.size(); i++)
{ // simple linear search through menu items
MenuItemDefinition md = (MenuItemDefinition)(m_items.get(i));
if ((md.getItemType().equals(type)) && (md.getText().equals(text)))
return i;
} // end for
return -1;
} // end getItemByTypeText
synchronized void resequence()
{
if (m_items.size()>1)
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 } // end class MenuDefinition

View File

@ -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 <http://www.mozilla.org/MPL/>.
*
* 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 <erbo@silcom.com>,
* 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

View File

@ -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 <http://www.mozilla.org/MPL/>.
*
* 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 <erbo@silcom.com>,
* 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

View File

@ -20,9 +20,10 @@ package com.silverwrist.venice.menu;
import java.util.*; import java.util.*;
import com.silverwrist.dynamo.except.*; import com.silverwrist.dynamo.except.*;
import com.silverwrist.dynamo.iface.*; import com.silverwrist.dynamo.iface.*;
import com.silverwrist.dynamo.util.*;
import com.silverwrist.dynamo.security.SecurityReferenceMonitor; import com.silverwrist.dynamo.security.SecurityReferenceMonitor;
public class MenuItemDefinition class MenuItemDefinition implements Comparable
{ {
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Attributes * Attributes
@ -30,6 +31,7 @@ public class MenuItemDefinition
*/ */
private String m_type; private String m_type;
private int m_sequence;
private boolean m_enable; private boolean m_enable;
private int m_indent; private int m_indent;
private String m_text; private String m_text;
@ -42,17 +44,19 @@ public class MenuItemDefinition
private String m_perm_name; private String m_perm_name;
private String m_ifdef_var; private String m_ifdef_var;
private String m_ifndef_var; private String m_ifndef_var;
private boolean m_deleted = false;
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Constructor * 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 target, String title, String on_click, String perm_namespace, String perm_name,
String ifdef_var, String ifndef_var) String ifdef_var, String ifndef_var)
{ {
m_type = type; m_type = type;
m_sequence = sequence;
m_enable = enable; m_enable = enable;
m_indent = indent; m_indent = indent;
m_text = text; m_text = text;
@ -71,12 +75,49 @@ public class MenuItemDefinition
} // end constructor } // 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 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)) if ((m_perm_namespace==null) && (m_perm_name==null))
return true; return true;
for (int i=0; i<acl_ids.length; i++) for (int i=0; i<acl_ids.length; i++)
@ -105,63 +146,162 @@ public class MenuItemDefinition
} // end itemDefined } // end itemDefined
/*-------------------------------------------------------------------------------- String getItemType()
* External operations
*--------------------------------------------------------------------------------
*/
public String getItemType()
{ {
return m_type; return m_type;
} // end getItemType } // end getItemType
public boolean isEnabled() int getSequence()
{
return m_sequence;
} // end getSequence
synchronized void setSequence(int seq)
{
m_sequence = seq;
} // end setSequence
boolean isEnabled()
{ {
return m_enable; return m_enable;
} // end isEnabled } // end isEnabled
public int getIndentLevel() synchronized void setEnabled(boolean flag)
{
m_enable = flag;
} // end setEnabled
int getIndentLevel()
{ {
return m_indent; return m_indent;
} // end getIndentLevel } // end getIndentLevel
public String getText() synchronized void setIndentLevel(int level)
{
m_indent = level;
} // end setIndentLevel
String getText()
{ {
return m_text; return m_text;
} // end getText } // end getText
public String getLinkType() synchronized void setText(String s)
{
m_text = s;
} // end setText
String getLinkType()
{ {
return m_linktype; return m_linktype;
} // end getLinkType } // end getLinkType
public String getLink() String getLink()
{ {
return m_link; return m_link;
} // end getLink } // end getLink
public String getTarget() synchronized void setLink(String type, String link)
{
m_linktype = type;
m_link = link;
} // end setLink
String getTarget()
{ {
return m_target; return m_target;
} // end getTarget } // end getTarget
public String getTitle() synchronized void setTarget(String target)
{
m_target = target;
} // end setTarget
String getTitle()
{ {
return m_title; return m_title;
} // end getTitle } // end getTitle
public String getOnClick() synchronized void setTitle(String title)
{
m_title = title;
} // end setTitle
String getOnClick()
{ {
return m_on_click; return m_on_click;
} // end getOnClick } // end getOnClick
void setOnClick(String on_click)
{
m_on_click = on_click;
} // end setOnClick
QualifiedNameKey getPermission()
{
return new QualifiedNameKey(m_perm_namespace,m_perm_name);
} // end getPermission
synchronized void setPermission(String namespace, String name)
{
m_perm_namespace = namespace;
m_perm_name = name;
} // end setPermission
String getIfDefVar()
{
return m_ifdef_var;
} // end getIfDefVar
synchronized void setIfDefVar(String var)
{
m_ifdef_var = var;
} // end setIfDefVar
String getIfNotDefVar()
{
return m_ifndef_var;
} // end getIfNotDefVar
synchronized void setIfNotDefVar(String var)
{
m_ifndef_var = var;
} // end setIfNotDefVar
boolean isDeleted()
{
return m_deleted;
} // end isDeleted
synchronized void delete()
{
m_deleted = true;
} // end delete
} // end class MenuItemDefinition } // end class MenuItemDefinition

View File

@ -24,8 +24,10 @@ import com.silverwrist.util.xml.*;
import com.silverwrist.dynamo.db.NamespaceCache; import com.silverwrist.dynamo.db.NamespaceCache;
import com.silverwrist.dynamo.except.*; import com.silverwrist.dynamo.except.*;
import com.silverwrist.dynamo.iface.*; import com.silverwrist.dynamo.iface.*;
import com.silverwrist.dynamo.module.ModuleOperations;
import com.silverwrist.dynamo.security.SecurityReferenceMonitor; import com.silverwrist.dynamo.security.SecurityReferenceMonitor;
import com.silverwrist.dynamo.util.*; import com.silverwrist.dynamo.util.*;
import com.silverwrist.venice.VeniceNamespaces;
import com.silverwrist.venice.iface.*; import com.silverwrist.venice.iface.*;
public class MenuManager implements NamedObject, ComponentInitialize, ComponentShutdown, MenuProvider public class MenuManager implements NamedObject, ComponentInitialize, ComponentShutdown, MenuProvider
@ -47,6 +49,7 @@ public class MenuManager implements NamedObject, ComponentInitialize, ComponentS
private SecurityReferenceMonitor m_srm; private SecurityReferenceMonitor m_srm;
private MenuDatabaseOps m_ops; private MenuDatabaseOps m_ops;
private HardSoftCache m_menudef_cache; private HardSoftCache m_menudef_cache;
private ComponentShutdown m_installreg;
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Constructor * Constructor
@ -57,6 +60,42 @@ public class MenuManager implements NamedObject, ComponentInitialize, ComponentS
{ // do nothing { // do nothing
} // end constructor } // end constructor
/*--------------------------------------------------------------------------------
* Internal operations
*--------------------------------------------------------------------------------
*/
private final MenuDefinition getMenuDefinition(String namespace, String name) throws DatabaseException
{
QualifiedNameKey key = new QualifiedNameKey(namespace,name);
MenuDefinition mdef = (MenuDefinition)(m_menudef_cache.get(key));
if ((mdef!=null) && mdef.isDeleted())
{ // discard deleted menu definitions
m_menudef_cache.remove(key);
mdef = null;
} // end if
if (mdef==null)
{ // get it and add it to the cache
mdef = m_ops.getMenu(namespace,name);
if (mdef==null)
{ // menu was not found
DatabaseException de = new DatabaseException(MenuManager.class,"MenuMessages","menu.notFound");
de.setParameter(0,namespace);
de.setParameter(1,name);
throw de;
} // end if
m_menudef_cache.put(key,mdef);
} // end if
return mdef;
} // end getMenuDefinition
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Implementations from interface NamedObject * Implementations from interface NamedObject
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
@ -134,6 +173,11 @@ public class MenuManager implements NamedObject, ComponentInitialize, ComponentS
// Create the menu definition cache. // Create the menu definition cache.
m_menudef_cache = new HardSoftCache(3,10); m_menudef_cache = new HardSoftCache(3,10);
// Register our install service to let modules make changes to menus.
ModuleOperations module_ops = (ModuleOperations)(services.queryService(ModuleOperations.class));
SingletonServiceProvider ssp = new SingletonServiceProvider("Menu install services",MenuProvider.class,this);
m_installreg = module_ops.hookInstallServices(ssp);
} // end initialize } // end initialize
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
@ -143,8 +187,13 @@ public class MenuManager implements NamedObject, ComponentInitialize, ComponentS
public void shutdown() public void shutdown()
{ {
m_installreg.shutdown();
m_installreg = null;
m_ns_cache = null; m_ns_cache = null;
m_srm = null; m_srm = null;
m_ops.dispose();
m_ops = null;
m_menudef_cache.clear();
} // end shutdown } // end shutdown
@ -156,49 +205,43 @@ public class MenuManager implements NamedObject, ComponentInitialize, ComponentS
public MenuRenderObject getStandardMenu(DynamoUser caller, String namespace, String name, int[] acl_ids) public MenuRenderObject getStandardMenu(DynamoUser caller, String namespace, String name, int[] acl_ids)
throws DatabaseException throws DatabaseException
{ {
QualifiedNameKey key = new QualifiedNameKey(namespace,name); return new StandardMenuRendering(caller,getMenuDefinition(namespace,name),m_srm,acl_ids);
MenuDefinition mdef = (MenuDefinition)(m_menudef_cache.get(key));
if (mdef==null)
{ // get it and add it to the cache
mdef = m_ops.getMenu(namespace,name);
m_menudef_cache.put(key,mdef);
} // end if
return new StandardMenuRendering(caller,mdef,m_srm,acl_ids);
} // end getStandardMenu } // end getStandardMenu
public MenuRenderObject getLeftMenu(DynamoUser caller, String namespace, String name, int[] acl_ids) public MenuRenderObject getLeftMenu(DynamoUser caller, String namespace, String name, int[] acl_ids)
throws DatabaseException throws DatabaseException
{ {
QualifiedNameKey key = new QualifiedNameKey(namespace,name); return new LeftMenuRendering(caller,getMenuDefinition(namespace,name),m_srm,acl_ids);
MenuDefinition mdef = (MenuDefinition)(m_menudef_cache.get(key));
if (mdef==null)
{ // get it and add it to the cache
mdef = m_ops.getMenu(namespace,name);
m_menudef_cache.put(key,mdef);
} // end if
return new LeftMenuRendering(caller,mdef,m_srm,acl_ids);
} // end getLeftMenu } // end getLeftMenu
public MenuRenderObject getInlineMenu(DynamoUser caller, String namespace, String name, int[] acl_ids) public MenuRenderObject getInlineMenu(DynamoUser caller, String namespace, String name, int[] acl_ids)
throws DatabaseException throws DatabaseException
{ {
QualifiedNameKey key = new QualifiedNameKey(namespace,name); return new InlineMenuRendering(caller,getMenuDefinition(namespace,name),m_srm,acl_ids);
MenuDefinition mdef = (MenuDefinition)(m_menudef_cache.get(key));
if (mdef==null)
{ // get it and add it to the cache
mdef = m_ops.getMenu(namespace,name);
m_menudef_cache.put(key,mdef);
} // end if
return new InlineMenuRendering(caller,mdef,m_srm,acl_ids);
} // end getInlineMenu } // end getInlineMenu
public MenuEditObject getEditMenu(DynamoUser caller, String namespace, String name)
throws DatabaseException, DynamoSecurityException
{
if (!(m_srm.getGlobalAcl().testPermission(caller,VeniceNamespaces.SYSTEM_PERMS_NAMESPACE,"edit.menus")))
throw new DynamoSecurityException(MenuManager.class,"MenuMessages","auth.editMenu");
return new MenuEditImpl(m_ops,getMenuDefinition(namespace,name));
} // end getEditMenu
public MenuEditObject createMenu(DynamoUser caller, String namespace, String name, String title)
throws DatabaseException, DynamoSecurityException
{
if (!(m_srm.getGlobalAcl().testPermission(caller,VeniceNamespaces.SYSTEM_PERMS_NAMESPACE,"edit.menus")))
throw new DynamoSecurityException(MenuManager.class,"MenuMessages","auth.createMenu");
int menuid = m_ops.createMenu(namespace,name,title);
MenuDefinition mdef = new MenuDefinition(menuid,namespace,name,title,null);
m_menudef_cache.put(new QualifiedNameKey(namespace,name),mdef);
return new MenuEditImpl(m_ops,mdef);
} // end createMenu
} // end class MenuManager } // end class MenuManager

View File

@ -0,0 +1,22 @@
# 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 <http://www.mozilla.org/MPL/>.
#
# 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 <erbo@silcom.com>,
# 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.