FileDocCategorySizeDatePackage
ApproveTag.javaAPI DocExample4884Mon Sep 09 12:43:24 BST 2002org.dasein.gb.jsp

ApproveTag

public class ApproveTag extends javax.servlet.jsp.tagext.BodyTagSupport

Fields Summary
private String
admin
private String
error
private static final String
NOT_ALLOWED
private static final String
NOT_AUTH
private static final String
NO_COMMENT
Constructors Summary
Methods Summary
public intdoEndTag()


         
        if( getBodyContent() != null ) {
            try {
                getPreviousOut().print(getBodyContent().getString());
                error = null;
                admin = null;
            }
            catch( IOException e ) {
                throw new JspException(e.getMessage());
            }
        }
        return EVAL_PAGE;
    
public intdoStartTag()

    
         
        try {
            ServletRequest request = pageContext.getRequest();
            ArrayList pending = Comment.getPending();
            Iterator it = pending.iterator();

            if( !getAdminUser().isAuthenticated() ) {
                if( error != null ) {
                    pageContext.setAttribute(error, NOT_AUTH);
                    error = null;
                    admin = null;
                    return SKIP_BODY;
                }
                else {
                    throw new JspException(NOT_AUTH);
                }
            }
            if( !getAdminUser().authorize(1) ) {
                if( error != null ) {
                    pageContext.setAttribute(error, NOT_ALLOWED);
                    error = null;
                    admin = null;
                    return SKIP_BODY;
                }
                else {
                    throw new JspException(NOT_ALLOWED);
                }
            }
            while( it.hasNext() ) {
                Comment cmt = (Comment)it.next();
                HashMap data = new HashMap();
                long cid = cmt.getCommentID();
                String decision, comment;

                decision = request.getParameter("" + cid);
                comment = request.getParameter("" + cid + "-" +
                                               Comment.COMMENT);
                if( decision == null ) {
                    continue;
                }
                decision = decision.trim();
                if( decision.equalsIgnoreCase("approve") ) {
                    data.put(Comment.COMMENT_ID, new Long(cid));
                    if( comment != null ) {
                        comment = comment.trim();
                        if( comment.length() < 1 ) {
                            comment = null;
                        }
                    }
                    if( comment == null ) {
                        if( error != null ) {
                            pageContext.setAttribute(error, NO_COMMENT);
                            error = null;
                            admin = null;
                            return SKIP_BODY;
                        }
                        else {
                            throw new JspException(NO_COMMENT);
                        }
                    }
                    data.put(Comment.CREATED, cmt.getCreated());
                    data.put(Comment.COMMENT, comment);
                    data.put(Comment.APPROVED, new Boolean(true));
                    data.put(Comment.NAME, cmt.getName());
                    data.put(Comment.EMAIL, cmt.getEmail());
                    cmt.save(data);
                }
                else if( decision.equalsIgnoreCase("reject") ) {
                    cmt.remove();
                }
            }
            pageContext.setAttribute(error, null);
            return EVAL_BODY_TAG;
        }
        catch( PersistenceException e ) {
            if( error != null ) {
                pageContext.setAttribute(error, "<p class=\"error\">" +
                                         e.getMessage() +"</p>");
                error = null;
                admin = null;
                return SKIP_BODY;
            }
            else {
                throw new JspException(e.getMessage());
            }
        }
    
public org.dasein.security.UsergetAdminUser()

        return (User)pageContext.findAttribute(admin);
    
public voidsetAdmin(java.lang.String adm)

        admin = adm;
    
public voidsetError(java.lang.String err)

        error = err;