{
ContentletAPI conAPI = APILocator.getContentletAPI();
ActionErrors errors = new ActionErrors();
Contentlet parentContentlet = new Contentlet();
HttpSession session = request.getSession();
Captcha captchaSession = (Captcha) session.getAttribute(Captcha.NAME);
try{
parentContentlet = conAPI.find(contentInode, APILocator.getUserAPI().getSystemUser(), true);
}catch(DotDataException e){
Logger.error(this, "Unable to look up contentlet with inode " + contentInode, e);
}catch (DotSecurityException dse) {
Logger.error(this, "Unable to look up contentlet with inode " + contentInode + " because of security issue", dse);
}
if(parentContentlet==null || !InodeUtils.isSet(parentContentlet.getInode())){
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("message.contentlet.required","Contentlet Inode"));
return errors;
}
if (!UtilMethods.isSet(name))
{
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("message.contentlet.required","Name"));
}
if (!UtilMethods.isSet(email) || ! UtilMethods.isValidEmail(email))
{
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("message.contentlet.required","Email"));
}
/* Try to find a title if we don't have one. */
if (!UtilMethods.isSet(commentTitle))
{
Structure s = StructureCache.getStructureByInode(parentContentlet.getStructureInode());
List<Field> lf = s.getFields();
for(Field f : lf){
if("text".equals(f.getFieldType()) && f.isIndexed() && f.isListed()){
try{
commentTitle = "re: " + conAPI.getFieldValue(parentContentlet, f);
}catch (Exception e) {
Logger.error(CommentsForm.class, "Unable to set comment title", e);
}
break;
}
}
}
if (!UtilMethods.isSet(comment))
{
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("message.contentlet.required","Comment"));
}
if (UtilMethods.isSet(accept) && accept == false)
{
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("message.contentlet.required","Accept"));
}
if ( commentUseCaptcha ) {
if ( !UtilMethods.isSet( captcha ) || !UtilMethods.isSet( captchaSession ) || !captcha.equals( captchaSession.getAnswer() ) ) {
errors.add( ActionErrors.GLOBAL_ERROR, new ActionError( "message.contentlet.required", "Validation Image" ) );
}
}
if(commentUseAudioCaptcha && !UtilMethods.isSet(captchaSession)){