Adding GetRemoveForm command
This commit is contained in:
parent
57c4afe8bc
commit
7af072de84
1 changed files with 146 additions and 0 deletions
146
src/java/org/thdl/lex/commands/GetRemoveFormCommand.java
Normal file
146
src/java/org/thdl/lex/commands/GetRemoveFormCommand.java
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
package org.thdl.lex.commands;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
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 GetRemoveFormCommand extends LexCommand implements Command
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//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 next = getNext();
|
||||||
|
Visit visit = UserSessionManager.getInstance().getVisit( req.getSession( true ) );
|
||||||
|
LexQuery query = visit.getQuery();
|
||||||
|
ITerm term = query.getEntry();
|
||||||
|
String msg = null;
|
||||||
|
ThdlUser user = visit.getUser();
|
||||||
|
if ( validate( user, component ) )
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
LexLogger.debug( "Checking component state from GetRemoveFormCommand BEFORE component assignment" );
|
||||||
|
LexLogger.debugComponent( component );
|
||||||
|
if ( isTermMode() )
|
||||||
|
{
|
||||||
|
component = query.getEntry();
|
||||||
|
}
|
||||||
|
else if ( component instanceof Translatable && null != ( (Translatable) component ).getTranslationOf() )
|
||||||
|
{
|
||||||
|
LexComponentRepository.update( term );
|
||||||
|
Translatable translation = (Translatable) component;
|
||||||
|
Translatable source = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
source = (Translatable) translation.getClass().newInstance();
|
||||||
|
}
|
||||||
|
catch ( Exception e )
|
||||||
|
{
|
||||||
|
throw new CommandException( e );
|
||||||
|
}
|
||||||
|
source.setMetaId( translation.getTranslationOf() );
|
||||||
|
source.setParentId( translation.getParentId() );
|
||||||
|
source = (Translatable) term.findChild( source );
|
||||||
|
List translationList = source.getTranslations();
|
||||||
|
component = (ILexComponent) translationList.get( translationList.indexOf( translation ) );
|
||||||
|
req.setAttribute( LexConstants.ORIGINALBEAN_REQ_ATTR, source );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LexComponentRepository.update( term );
|
||||||
|
component = term.findChild( component.getMetaId() );
|
||||||
|
}
|
||||||
|
req.setAttribute( LexConstants.COMPONENT_REQ_ATTR, component );
|
||||||
|
LexLogger.debug( "Checking component state from GetRemoveFormCommand AFTER component assignment" );
|
||||||
|
LexLogger.debugComponent( component );
|
||||||
|
}
|
||||||
|
catch ( LexRepositoryException e )
|
||||||
|
{
|
||||||
|
throw new CommandException( e );
|
||||||
|
}
|
||||||
|
catch ( LexComponentException e )
|
||||||
|
{
|
||||||
|
throw new CommandException( e );
|
||||||
|
}
|
||||||
|
|
||||||
|
msg = "You have reached the Remove Form";
|
||||||
|
visit.setDisplayMode( "addEditForm" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg = "A dictionary component can only be removed by the person who created it or an administrator.";
|
||||||
|
next = "displayEntry.jsp";
|
||||||
|
}
|
||||||
|
|
||||||
|
req.setAttribute( LexConstants.MESSAGE_REQ_ATTR, msg );
|
||||||
|
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//constructors
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Constructor for the GetFormCommand object
|
||||||
|
*
|
||||||
|
* @param next Description of the Parameter
|
||||||
|
* @param termMode Description of the Parameter
|
||||||
|
*/
|
||||||
|
public GetRemoveFormCommand( String next, Boolean termMode )
|
||||||
|
{
|
||||||
|
super( next );
|
||||||
|
setTermMode( termMode.booleanValue() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue