Checking in newly added components

This commit is contained in:
dubtraxis 2003-10-13 17:15:10 +00:00
parent 90d7c70657
commit e89a54a612
7 changed files with 670 additions and 0 deletions

BIN
lib/log4j/log4j-1.2.6.jar Normal file

Binary file not shown.

View file

@ -0,0 +1,62 @@
package org.thdl.lex;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
/**
* Description of the Class
*
* @author Hibernate WIKI
* @created October 1, 2003
*/
public class HibernateTransaction
{
/**
* Description of the Field
*/
public final static ThreadLocal transaction = new ThreadLocal();
/**
* Description of the Method
*
* @exception HibernateException Description of Exception
* @since
*/
public static void beginTransaction() throws HibernateException
{
Transaction t = (Transaction) transaction.get();
if ( t == null )
{
t = HibernateSession.currentSession().beginTransaction();
transaction.set( t );
}
}
/**
* Description of the Method
*
* @param commit Description of the Parameter
* @exception HibernateException Description of Exception
* @since
*/
public static void endTransaction( boolean commit ) throws HibernateException
{
Transaction t = (Transaction) transaction.get();
transaction.set( null );
if ( t != null && commit )
{
t.commit();
}
else if ( t != null )
{
t.rollback();
}
}
}

View file

@ -0,0 +1,107 @@
package org.thdl.lex;
import java.util.*;
import javax.servlet.http.*;
import org.apache.log4j.*;
/**
* Description of the Class
*
* @author travis
* @created October 9, 2003
*/
public class LexLogger
{
private final static Logger LOGGER = Logger.getLogger( "org.thdl.lex" );
/**
* Description of the Method
*
* @param req Description of the Parameter
*/
public static void logRequestState( HttpServletRequest req )
{
Iterator it;
Enumeration enum = req.getParameterNames();
while ( enum.hasMoreElements() )
{
String parm = (String) enum.nextElement();
LOGGER.debug( "Request Parameter " + parm + " = " + req.getParameter( parm ) );
}
enum = req.getAttributeNames();
while ( enum.hasMoreElements() )
{
String att = (String) enum.nextElement();
LOGGER.debug( "Request Attribute " + att + " = " + req.getAttribute( att ) );
}
}
/**
* Description of the Method
*
* @param req Description of the Parameter
*/
public static void logSessionState( HttpServletRequest req )
{
HttpSession ses = req.getSession( false );
if ( null == ses )
{
LOGGER.debug( "Session was null" );
return;
}
Enumeration enum = ses.getAttributeNames();
while ( enum.hasMoreElements() )
{
String att = (String) enum.nextElement();
LOGGER.debug( "Session Attribute " + att + " = " + ses.getAttribute( att ) );
}
LexQuery query = (LexQuery) ses.getAttribute( "query" );
if ( null == query )
{
return;
}
LOGGER.debug( "Query Entry: " + query.getEntry() );
LOGGER.debug( "Query QueryComponent: " + query.getQueryComponent() );
LOGGER.debug( "Query UpdateComponent: " + query.getUpdateComponent() );
LOGGER.debug( "Query Results, " + query.getResults() + ", contain: " + query.getResults().values() + "\n" );
}
/**
* Description of the Method
*
* @param msg Description of the Parameter
*/
public static void info( String msg )
{
LOGGER.info( msg );
}
/**
* Description of the Method
*
* @param msg Description of the Parameter
*/
public static void debug( String msg )
{
LOGGER.debug( msg );
}
/**
* Description of the Method
*
* @param msg Description of the Parameter
*/
public static void warn( String msg )
{
LOGGER.warn( msg );
}
}

View file

@ -0,0 +1,251 @@
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 GetFormCommand 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
*
* @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
{
String defaultNext = getNext();
LexQuery query = getSessionManager().getQuery( req.getSession( true ) );
ITerm term = query.getEntry();
String msg = null;
try
{
component.populate( req.getParameterMap() );
if ( isInsertMode() && !isTermMode() )
{
term.addChild( component );
}
else if ( isInsertMode() && isTermMode() )
{
Term newTerm = new Term();
newTerm.populate( component );
LexQuery newTermQuery = new LexQuery( newTerm, LexComponentRepository.EXACT );
if ( termExists( newTermQuery ) )
{
msg = newTerm.getTerm() + " is present in the dictionary, please add to this term.";
setNext( "displayEntry.jsp" );
getSessionManager().setQuery( req.getSession( true ), query );
}
else
{
query.setEntry( newTerm );
}
}
else if ( !isTermMode() )
{
LexComponentRepository.loadByPk( component );
//find the persistent copy of this component from the term stored in session.query
component = term.findChild( component );
}
query.setUpdateComponent( component );
req.setAttribute( LexConstants.COMPONENT_REQ_ATTR, component );
}
catch ( LexRepositoryException e )
{
throw new CommandException( e );
}
catch ( LexComponentException e )
{
throw new CommandException( e );
}
finally
{
setNext( defaultNext );
}
//if the component is a translation of another component get the original as well to assist in editing
if ( component instanceof Translatable )
{
Translatable translatable = (Translatable) component;
if ( null != translatable.getTranslationOf() && translatable.getTranslationOf().intValue() > 0 )
{
try
{
LexComponent source = (LexComponent) translatable.getClass().newInstance();
Integer sourcePk = translatable.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 );
}
}
}
if ( false == isInsertMode() )
{
Integer creator = component.getMeta().getCreatedBy();
ThdlUser user = getSessionManager().getSessionUser( req.getSession( true ) );
if ( user.getId().equals( creator ) || user.hasRole( "admin" ) || user.hasRole( "dev" ) )
{
msg = "You have reached the Update Form";
getSessionManager().setDisplayMode( req.getSession( true ), "addEditForm" );
}
else
{
msg = "A dictionary component can only be edited by the person who created it or an administrator.";
setNext( "displayEntry.jsp" );
}
}
else
{
msg = "You have reached the Insert Form";
getSessionManager().setDisplayMode( req.getSession( true ), "addEditForm" );
}
req.setAttribute( LexConstants.MESSAGE_REQ_ATTR, msg );
return getNext();
}
/**
* Description of the Method
*
* @param query Description of the Parameter
* @return The newTerm value
* @exception LexRepositoryException Description of the Exception
*/
public boolean termExists( LexQuery query ) throws LexRepositoryException
{
boolean termExists = false;
query.setFindMode( LexComponentRepository.EXACT );
LexComponentRepository.findTermsByTerm( query );
if ( query.getResults().keySet().size() > 0 )
{
termExists = true;
}
return termExists;
}
/**
* 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 GetFormCommand object
*
* @param next Description of the Parameter
* @param insertMode Description of the Parameter
* @param termMode Description of the Parameter
*/
public GetFormCommand( String next, Boolean insertMode, Boolean termMode )
{
super( next );
setInsertMode( insertMode.booleanValue() );
setTermMode( termMode.booleanValue() );
}
/**
*Constructor for the GetFormCommand object
*
* @param next Description of the Parameter
* @param insertMode Description of the Parameter
*/
public GetFormCommand( String next, Boolean insertMode )
{
this( next, insertMode, Boolean.FALSE );
}
}

View file

@ -0,0 +1,59 @@
package org.thdl.lex.commands;
/**
* Description of the Class
*
* @author travis
* @created October 1, 2003
*/
public class LexCommandException extends Exception
{
/**
* Constructor for the LexCommandException object
*
* @since
*/
public LexCommandException()
{
super();
}
/**
* Constructor for the LexCommandException object
*
* @param msg Description of Parameter
* @since
*/
public LexCommandException( String msg )
{
super( msg );
}
/**
* Constructor for the LexCommandException object
*
* @param e Description of Parameter
* @since
*/
public LexCommandException( Exception e )
{
super( e );
}
/**
* Constructor for the LexCommandException object
*
* @param msg Description of Parameter
* @param e Description of Parameter
* @since
*/
public LexCommandException( String msg, Exception e )
{
super( msg, e );
}
}

View file

@ -0,0 +1,166 @@
package org.thdl.lex.component;
import java.io.Serializable;
import org.apache.commons.lang.builder.ToStringBuilder;
/** @author Hibernate CodeGenerator */
abstract public class BaseMeta implements Serializable {
/** persistent field */
private java.lang.Integer createdBy;
/** persistent field */
private java.lang.Integer modifiedBy;
/** persistent field */
private java.lang.Integer createdByProjSub;
/** persistent field */
private java.lang.Integer modifiedByProjSub;
/** nullable persistent field */
private java.util.Date createdOn;
/** nullable persistent field */
private java.util.Date modifiedOn;
/** persistent field */
private java.lang.Integer source;
/** persistent field */
private java.lang.Short language;
/** persistent field */
private java.lang.Short script;
/** persistent field */
private java.lang.Short dialect;
/** nullable persistent field */
private java.lang.String note;
/** full constructor */
public BaseMeta(java.lang.Integer createdBy, java.lang.Integer modifiedBy, java.lang.Integer createdByProjSub, java.lang.Integer modifiedByProjSub, java.util.Date createdOn, java.util.Date modifiedOn, java.lang.Integer source, java.lang.Short language, java.lang.Short script, java.lang.Short dialect, java.lang.String note) {
this.createdBy = createdBy;
this.modifiedBy = modifiedBy;
this.createdByProjSub = createdByProjSub;
this.modifiedByProjSub = modifiedByProjSub;
this.createdOn = createdOn;
this.modifiedOn = modifiedOn;
this.source = source;
this.language = language;
this.script = script;
this.dialect = dialect;
this.note = note;
}
/** default constructor */
public BaseMeta() {
}
/** minimal constructor */
public BaseMeta(java.lang.Integer createdBy, java.lang.Integer modifiedBy, java.lang.Integer createdByProjSub, java.lang.Integer modifiedByProjSub, java.lang.Integer source, java.lang.Short language, java.lang.Short script, java.lang.Short dialect) {
this.createdBy = createdBy;
this.modifiedBy = modifiedBy;
this.createdByProjSub = createdByProjSub;
this.modifiedByProjSub = modifiedByProjSub;
this.source = source;
this.language = language;
this.script = script;
this.dialect = dialect;
}
public java.lang.Integer getCreatedBy() {
return this.createdBy;
}
public void setCreatedBy(java.lang.Integer createdBy) {
this.createdBy = createdBy;
}
public java.lang.Integer getModifiedBy() {
return this.modifiedBy;
}
public void setModifiedBy(java.lang.Integer modifiedBy) {
this.modifiedBy = modifiedBy;
}
public java.lang.Integer getCreatedByProjSub() {
return this.createdByProjSub;
}
public void setCreatedByProjSub(java.lang.Integer createdByProjSub) {
this.createdByProjSub = createdByProjSub;
}
public java.lang.Integer getModifiedByProjSub() {
return this.modifiedByProjSub;
}
public void setModifiedByProjSub(java.lang.Integer modifiedByProjSub) {
this.modifiedByProjSub = modifiedByProjSub;
}
public java.util.Date getCreatedOn() {
return this.createdOn;
}
public void setCreatedOn(java.util.Date createdOn) {
this.createdOn = createdOn;
}
public java.util.Date getModifiedOn() {
return this.modifiedOn;
}
public void setModifiedOn(java.util.Date modifiedOn) {
this.modifiedOn = modifiedOn;
}
public java.lang.Integer getSource() {
return this.source;
}
public void setSource(java.lang.Integer source) {
this.source = source;
}
public java.lang.Short getLanguage() {
return this.language;
}
public void setLanguage(java.lang.Short language) {
this.language = language;
}
public java.lang.Short getScript() {
return this.script;
}
public void setScript(java.lang.Short script) {
this.script = script;
}
public java.lang.Short getDialect() {
return this.dialect;
}
public void setDialect(java.lang.Short dialect) {
this.dialect = dialect;
}
public java.lang.String getNote() {
return this.note;
}
public void setNote(java.lang.String note) {
this.note = note;
}
public String toString() {
return new ToStringBuilder(this)
.toString();
}
}

View file

@ -0,0 +1,25 @@
package org.thdl.lex.component;
/**
* Description of the Interface
*
* @author travis
* @created October 13, 2003
*/
public interface LexComponentNode extends ILexComponent
{
/*
public ILexComponent findChild( ILexComponent component ) throws LexComponentException;
public void addChild( ILexComponent component ) throws LexComponentException;
*/
/**
* Gets the childMap attribute of the ISubdefinition object
*
* @return The childMap value
*/
public java.util.HashMap getChildMap();
// public java.util.List getSiblings();
}