Here are many changes to the object model including two new interfaces, LexComponentNode and Translatable. Also translation collections have been moved from generic LexComponent to specific components that allow translation.

This commit is contained in:
dubtraxis 2003-10-13 17:11:27 +00:00
parent 7e0932bbe0
commit 2dea08d7de
9 changed files with 99 additions and 411 deletions

View file

@ -60,7 +60,7 @@ public class DisplayCommand extends LexCommand implements Command
{
component.populate( req.getParameterMap() );
LexQuery query = getSessionMgr().getQuery( req.getSession( true ) );
LexQuery query = getSessionManager().getQuery( req.getSession( true ) );
query.setQueryComponent( component );
LexComponentRepository.loadTermByPk( query );

View file

@ -42,7 +42,7 @@ public class FindCommand extends LexCommand implements Command
{
ITerm term = (ITerm) component;
LexQuery query = getSessionMgr().getQuery( req.getSession( true ) );
LexQuery query = getSessionManager().getQuery( req.getSession( true ) );
query.setQueryComponent( term );
LexComponentRepository.findTermsByTerm( query );
@ -50,7 +50,7 @@ public class FindCommand extends LexCommand implements Command
if ( iterator.hasNext() )
{
setNext( "displayEntry.jsp" );
getSessionMgr().setQuery( req.getSession( true ), query );
getSessionManager().setQuery( req.getSession( true ), query );
msg = "There are " + query.getResults().size() + " terms matching " + term.getTerm();
}
else

View file

@ -1,65 +0,0 @@
package org.thdl.lex.commands;
import org.thdl.lex.*;
import org.thdl.lex.component.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
public class GetInsertFormCommand extends LexCommand implements Command
{
//contract methods
public String execute(HttpServletRequest req, ILexComponent component) throws CommandException
{
/* try
{
setComponent( (LexComponent)component );
getComponent().scrapeRequest( req );
String msg="You have reached the New Entry form.";
req.setAttribute(LexConstants.MESSAGE_REQ_ATTR, msg);
if ( req.getParameter( LexConstants.COMMAND_REQ_PARAM ).equals( "annotate" ) )
{
setComponent( (LexComponent)component );
getComponent().scrapeRequest( req );
getComponent().query();
AnalyticalNote note = new AnalyticalNote();
note.setParentMeta( getComponent().getMetaId() );
req.setAttribute( LexConstants.COMPONENT_REQ_ATTR, component );
}
getSessionMgr().setDisplayMode( req.getSession( true ), "addNewComponent" );
*/ return getNext();
/* }
catch (LexComponentException e)
{
throw new CommandException("Lex Action Exception: " + e.getMessage());
}
*/ }
//helper methods
public HashMap initForwards()
{
HashMap map = new HashMap();
map.put( LexConstants.TERMLABEL_VALUE, "displayEntry.jsp?formMode=insert" );
map.put( LexConstants.SUBDEFINITIONLABEL_VALUE, "displayEntry.jsp?formMode=insert" );
map.put( LexConstants.TRANSLATIONLABEL_VALUE, "displayEntry.jsp?formMode=insert" );
// map.put( LexConstants.DEFINITIONLABEL_VALUE, "displayEntry.jsp" );
// map.put( LexConstants.PASSAGELABEL_VALUE, "displayEntry.jsp" );
return map;
}
//constructors
public GetInsertFormCommand()
{
super();
setForwards( initForwards() );
}
public GetInsertFormCommand( String next )
{
super();
setNext( next );
}
}

View file

@ -1,57 +0,0 @@
package org.thdl.lex.commands;
import org.thdl.lex.*;
import org.thdl.lex.component.*;
import org.thdl.users.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
public class GetTranslationFormCommand extends LexCommand implements Command
{
//helper methods
public String execute(HttpServletRequest req, ILexComponent component) throws CommandException
{
/* try
{
ThdlUser user = getSessionMgr().getSessionUser( req.getSession( true ) );
Preferences preferences = getSessionMgr().getPreferences( req.getSession( true ) );
Meta meta = new Meta( user, preferences );
meta.scrapeRequest( req );
component.setTranslationOf( Integer.parseInt( req.getParameter("id") ) );
meta.insert();
setComponent( component );
getComponent().query( Integer.parseInt( req.getParameter("id") ) );
req.setAttribute( LexConstants.ORIGINALBEAN_REQ_ATTR , getComponent() );
getComponent().setMeta( meta );
//getComponent().insert();
String msg="You have reached the Translation Form";
req.setAttribute(LexConstants.MESSAGE_REQ_ATTR, msg);
getSessionMgr().setDisplayMode( req.getSession( true ) , "addEditForm" );
*/ return getNext();
/* }
catch (LexComponentException e)
{
throw new CommandException("Lex Action Exception: " + e.getMessage());
}
*/ }
public HashMap initForwards()
{
return null;
}
//constructors
public GetTranslationFormCommand()
{
super();
}
public GetTranslationFormCommand( String next )
{
super();
setNext( next );
}
}

View file

@ -1,137 +0,0 @@
package org.thdl.lex.commands;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.thdl.lex.*;
import org.thdl.lex.component.*;
import org.thdl.users.*;
/**
* Description of the Class
*
* @author travis
* @created October 6, 2003
*/
public class GetUpdateFormCommand extends LexCommand implements Command
{
//helper methods
/**
* Description of the Method
*
* @param req Description of the Parameter
* @param component Description of the Parameter
* @return Description of the Return Value
* @exception CommandException Description of the Exception
*/
public String execute( HttpServletRequest req, ILexComponent component ) throws CommandException
{
LexQuery query = getSessionMgr().getQuery( req.getSession( true ) );
Term term = null;
try
{
term = (Term) query.getEntry();
}
catch ( ClassCastException cce )
{
throw new CommandException( term.toString(), cce );
}
String msg = null;
try
{
component.populate( req.getParameterMap() );
ILexComponent child = term.findChild( component );
query.setUpdateComponent( child );
req.setAttribute( LexConstants.COMPONENT_REQ_ATTR, child );
}
catch ( LexComponentException e )
{
throw new CommandException( e );
}
//if the component is a translation of another component get the original as well to assist in editing
if ( component.getTranslationOf().intValue() > 0 )
{
try
{
LexComponent source = (LexComponent) component.getClass().newInstance();
Integer sourcePk = component.getTranslationOf();
source.setMetaId( sourcePk );
LexComponentRepository.loadByPk( source );
req.setAttribute( LexConstants.ORIGINALBEAN_REQ_ATTR, source );
}
catch ( InstantiationException ie )
{
throw new CommandException( ie );
}
catch ( IllegalAccessException iae )
{
throw new CommandException( iae );
}
catch ( LexRepositoryException lre )
{
throw new CommandException( lre );
}
}
Integer creator = component.getMeta().getCreatedBy();
ThdlUser user = getSessionMgr().getSessionUser( req.getSession( true ) );
if ( user.getId().equals( creator ) || user.hasRole( "admin" ) || user.hasRole( "dev" ) )
{
msg = "You have reached the Update Form";
getSessionMgr().setDisplayMode( req.getSession( true ), "addEditForm" );
setNext( "displayForm.jsp?formMode=update" );
}
else
{
msg = "A dictionary component can only be edited by the person who created it or an administrator.";
setNext( "displayEntry.jsp" );
}
req.setAttribute( LexConstants.MESSAGE_REQ_ATTR, msg );
return getNext();
}
/**
* Description of the Method
*
* @return Description of the Return Value
*/
public HashMap initForwards()
{
HashMap map = new HashMap();
//map.put( LexConstants.TERMLABEL_VALUE, "displayEntry.jsp?formMode=update" );
//map.put( LexConstants.SUBDEFINITIONLABEL_VALUE, "displayEntry.jsp?formMode=update" );
//map.put( LexConstants.TRANSLATIONLABEL_VALUE, "displayEntry.jsp?formMode=update" );
// map.put( LexConstants.DEFINITIONLABEL_VALUE, "displayEntry.jsp" );
// map.put( LexConstants.PASSAGELABEL_VALUE, "displayEntry.jsp" );
return map;
}
//constructors
/**
*Constructor for the GetUpdateFormCommand object
*/
public GetUpdateFormCommand()
{
super();
//setForwards( initForwards() );
}
/**
*Constructor for the GetUpdateFormCommand object
*
* @param next Description of the Parameter
*/
public GetUpdateFormCommand( String next )
{
super();
setNext( next );
}
}

View file

@ -1,97 +0,0 @@
package org.thdl.lex.commands;
import org.thdl.lex.*;
import org.thdl.lex.component.*;
import org.thdl.users.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
public class InsertCommand extends LexCommand implements Command
{
//helper methods
public String execute(HttpServletRequest req, ILexComponent component) throws CommandException
{
/* try
{
if ( CommandToken.isValid( req ) )
{
ThdlUser user = getSessionMgr().getSessionUser( req.getSession( true ) );
Preferences preferences = getSessionMgr().getPreferences( req.getSession( true ) );
if ( null == user )
throw new CommandException("No ThdlUser available in this Session");
if ( null == preferences )
throw new CommandException("No Preferences available in this Session");
Meta meta = new Meta( user, preferences );
meta.scrapeRequest( req );
meta.insert();
setComponent( component );
getComponent().setMeta( meta );
getComponent().scrapeRequest( req );
getComponent().insert();
getComponent().query();
req.setAttribute( "jumpToLocation", getComponent().getLabel() );
if ( null != req.getParameter( "analyticalNote" ) )
{
if ( ! LexConstants.LABEL_REQ_PARAM.equals( LexConstants.ANALYTICALNOTELABEL_VALUE )
&& ! "".equals( req.getParameter( "analyticalNote" ) ) )
{
AnalyticalNote note = new AnalyticalNote();
Meta mb = new Meta( meta );
mb.insert();
note.setMeta( mb );
note.scrapeRequest( req );
note.setParentMeta( getComponent().getMetaId() );
note.insert();
}
}
String msg="Successful new " +getComponent().getLabel() +" Entry.";
req.setAttribute(LexConstants.MESSAGE_REQ_ATTR, msg);
if ( getComponent() instanceof Term )
getSessionMgr().setEntry( req.getSession( true ) , new TermEntry( getComponent() ) );
else
getSessionMgr().getEntry( req.getSession( true ) ).rebuild();
if (null == getSessionMgr().getResults( req.getSession( true ) ) )
{
LexComponent[] results = {component};
getSessionMgr().setResults( req.getSession( true ), results );
}
getSessionMgr().setDisplayMode( req.getSession( true ), "edit" );
}
else
{
String msg="Invalid Reload Attempted";
req.setAttribute(LexConstants.MESSAGE_REQ_ATTR, msg);
}
*/ return getNext();
/* }
catch (LexComponentException e)
{
throw new CommandException("Lex Action Exception: " + e.getMessage());
}
catch (LexEntryException e)
{
throw new CommandException("Lex Entry Exception: " + e.getMessage());
}
*/ }
public HashMap initForwards()
{
HashMap map = new HashMap();
// map.put( LexConstants.TERMLABEL_VALUE, "displayEntry.jsp" );
// map.put( LexConstants.DEFINITIONLABEL_VALUE, "displayEntry.jsp" );
// map.put( LexConstants.PASSAGELABEL_VALUE, "displayEntry.jsp" );
return map;
}
public InsertCommand( String next)
{
super( next );
setForwards( initForwards() );
}
}

View file

@ -34,7 +34,7 @@ public abstract class LexCommand implements Command
*@param sessionMgr The new sessionMgr value
*@since
*/
public void setSessionMgr( UserSessionManager sessionMgr )
public void setSessionManager( UserSessionManager sessionMgr )
{
this.sessionMgr = sessionMgr;
}
@ -107,11 +107,11 @@ public abstract class LexCommand implements Command
*@return The sessionMgr value
*@since
*/
public UserSessionManager getSessionMgr()
public UserSessionManager getSessionManager()
{
if ( null == sessionMgr )
{
setSessionMgr( UserSessionManager.getInstance() );
setSessionManager( UserSessionManager.getInstance() );
}
return sessionMgr;
}

View file

@ -12,7 +12,7 @@ public class NullCommand extends LexCommand implements Command
if( null == req.getParameter( LexConstants.COMMAND_REQ_PARAM ) )
req.setAttribute( LexConstants.MESSAGE_REQ_ATTR, "Start from here." );
if( "login" == req.getParameter( LexConstants.COMMAND_REQ_PARAM )
&& null != getSessionMgr().getSessionUser( req.getSession(true) ) )
&& null != getSessionManager().getSessionUser( req.getSession(true) ) )
setNext("menu.jsp");
return getNext();
}

View file

@ -19,6 +19,54 @@ import org.thdl.users.*;
*/
public class UpdateCommand extends LexCommand implements Command
{
private boolean insertMode;
private boolean termMode;
/**
* Sets the termMode attribute of the GetFormCommand object
*
* @param termMode The new termMode value
*/
public void setTermMode( boolean termMode )
{
this.termMode = termMode;
}
/**
* Gets the termMode attribute of the GetFormCommand object
*
* @return The termMode value
*/
public boolean isTermMode()
{
return termMode;
}
/**
* Sets the insertMode attribute of the GetFormCommand object
*
* @param insertMode The new insertMode value
*/
public void setInsertMode( boolean insertMode )
{
this.insertMode = insertMode;
}
/**
* Gets the insertMode attribute of the GetFormCommand object
*
* @return The insertMode value
*/
public boolean isInsertMode()
{
return insertMode;
}
//helper methods
/**
* Description of the Method
@ -35,49 +83,40 @@ public class UpdateCommand extends LexCommand implements Command
{
if ( CommandToken.isValid( req ) )
{
ThdlUser user = getSessionMgr().getSessionUser( req.getSession( true ) );
msg = "Successful Update";
HttpSession ses = req.getSession( false );
if ( null == ses )
{
throw new CommandException( "Could not update component, uses session has expired" );
}
ThdlUser user = getSessionManager().getSessionUser( ses );
LexQuery query = getSessionManager().getQuery( ses );
/*
component.setMetaId( new Integer( req.getParameter( "metaId" ) ) );
LexComponentRepository.loadByPk( component );
component.populate( req.getParameterMap() );
Map params = req.getParameterMap();
query.getUpdateComponent().populate( params );
query.getUpdateComponent().getMeta().populate( params );
Date now = new Date( System.currentTimeMillis() );
component.getMeta().setModifiedOn( now );
component.getMeta().setModifiedBy( user.getId() );
LexComponentRepository.update( component );
req.setAttribute( LexConstants.MESSAGE_REQ_ATTR, msg );
req.setAttribute( "jumpToLocation", component.getLabel() );
*/
ITerm term = getSessionMgr().getQuery( req.getSession( true ) ).getEntry();
LexComponentRepository.update( term );
/*
term = new Term();
term.setMetaId( new Integer( 1 ) );
try
query.getUpdateComponent().getMeta().setModifiedOn( now );
query.getUpdateComponent().getMeta().setModifiedBy( user.getId() );
if ( isInsertMode() )
{
LexComponentRepository.loadTermByPk( term );
query.getUpdateComponent().getMeta().setCreatedOn( now );
query.getUpdateComponent().getMeta().setCreatedBy( user.getId() );
}
catch ( LexRepositoryException e )
{
throw new CommandException( "Command had trouble processing " + term, e );
}
*/
getSessionMgr().setDisplayMode( req.getSession( true ), "edit" );
ITerm term = query.getEntry();
LexComponentRepository.saveOrUpdate( term );
msg = "Successful Update";
getSessionManager().setDisplayMode( req.getSession( true ), "edit" );
}
else
{
msg = "Invalid Reload Attempted";
msg = "Invalid Reload Attempted.";
}
return getNext();
}
/*
catch ( LexComponentException e )
{
throw new CommandException( e );
}
*/
catch ( LexRepositoryException e )
{
throw new CommandException( "Command had trouble processing " + component, e );
@ -97,9 +136,9 @@ public class UpdateCommand extends LexCommand implements Command
public HashMap initForwards()
{
HashMap map = new HashMap();
map.put( LexConstants.TERMLABEL_VALUE, "displayEntry.jsp" );
map.put( LexConstants.SUBDEFINITIONLABEL_VALUE, "displayEntry.jsp" );
map.put( LexConstants.TRANSLATIONLABEL_VALUE, "displayEntry.jsp" );
// map.put( LexConstants.TERMLABEL_VALUE, "displayEntry.jsp" );
// map.put( LexConstants.SUBDEFINITIONLABEL_VALUE, "displayEntry.jsp" );
// map.put( LexConstants.TRANSLATIONLABEL_VALUE, "displayEntry.jsp" );
// map.put( LexConstants.DEFINITIONLABEL_VALUE, "displayEntry.jsp" );
// map.put( LexConstants.PASSAGELABEL_VALUE, "displayEntry.jsp" );
return map;
@ -107,24 +146,29 @@ public class UpdateCommand extends LexCommand implements Command
//constructors
/**
*Constructor for the UpdateCommand object
*Constructor for the GetFormCommand object
*
* @param next Description of the Parameter
* @param insertMode Description of the Parameter
* @param termMode Description of the Parameter
*/
public UpdateCommand()
public UpdateCommand( String next, Boolean insertMode, Boolean termMode )
{
super();
//setForwards( initForwards() );
super( next );
setInsertMode( insertMode.booleanValue() );
setTermMode( termMode.booleanValue() );
}
/**
*Constructor for the UpdateCommand object
*Constructor for the GetFormCommand object
*
* @param next Description of the Parameter
* @param insertMode Description of the Parameter
*/
public UpdateCommand( String next )
public UpdateCommand( String next, Boolean insertMode )
{
this();
setNext( next );
this( next, insertMode, Boolean.FALSE );
}
}