001    package railo.runtime.tag;
002    
003    import javax.servlet.jsp.tagext.Tag;
004    
005    import railo.runtime.exp.ApplicationException;
006    import railo.runtime.exp.PageException;
007    import railo.runtime.ext.tag.BodyTagImpl;
008    
009    /**
010    * Specifies one part of a multipart e-mail message. Can only be used in the cfmail tag. 
011    * You can use more than one cfmailpart tag within a cfmail tag
012    *
013    *
014    *
015    **/
016    public final class MailPart extends BodyTagImpl {
017    
018            railo.runtime.net.mail.MailPart part=new railo.runtime.net.mail.MailPart();
019            
020            /**
021            * @see javax.servlet.jsp.tagext.Tag#release()
022            */
023            public void release()   {
024                    super.release();
025                    part=new railo.runtime.net.mail.MailPart();
026            }
027            
028            /**
029         * @param type The type to set.
030             * @throws ApplicationException
031         */
032        public void setType(String type) throws ApplicationException        {
033                    part.setType(type);
034            }
035    
036    
037        /**
038         * @param charset The charset to set.
039         */
040        public void setCharset(String charset) {
041            part.setCharset(charset);
042        }
043        
044        /**
045         * @param wraptext The wraptext to set.
046         */
047        public void setWraptext(double wraptext) {
048            part.setWraptext((int)wraptext);
049        }
050            
051            /**
052            * @see javax.servlet.jsp.tagext.Tag#doStartTag()
053            */
054            public int doStartTag() {
055                
056                    return EVAL_BODY_BUFFERED;
057            }
058    
059            /**
060            * @see javax.servlet.jsp.tagext.BodyTag#doInitBody()
061            */
062            public void doInitBody()        {
063                    
064            }
065    
066            /**
067            * @see javax.servlet.jsp.tagext.BodyTag#doAfterBody()
068            */
069            public int doAfterBody()        {
070            part.setBody(bodyContent.getString());
071                    return SKIP_BODY;
072            }
073    
074            /**
075             * @see javax.servlet.jsp.tagext.Tag#doEndTag()
076            */
077            public int doEndTag() throws PageException      {
078                
079                    getMail().addPart(part);
080                    /*String type = part.getType();
081                    if(StringUtil.isEmpty(part.getCharset())) part.setCharset(mail.getCharset());
082                    if(type!=null && (type.equals("text/plain") || type.equals("plain") || type.equals("text"))){
083                            part.isPlain(true);
084                            mail.setBodyPart(part);
085                    }
086                    else if(type!=null && (type.equals("text/html") || type.equals("html") || type.equals("htm"))){
087                            part.isHTML(true);
088                            mail.setBodyPart(part);
089                    }   
090                    else {
091                            
092                            getMail().setParam(type, null, "susi", part.getBody(), "inline", null);
093                    }*/
094                    // throw new ApplicationException("attribute type of tag mailpart has a invalid values","valid values are [plain,text,html] but value is now ["+type+"]");
095                    
096                    
097                    
098                    return EVAL_PAGE;
099            }
100    
101            
102    
103            private Mail getMail() throws ApplicationException {
104                    Tag parent=getParent();
105                    while(parent!=null && !(parent instanceof Mail)) {
106                            parent=parent.getParent();
107                    }
108                    if(parent instanceof Mail)return (Mail) parent;
109                    throw new ApplicationException("Wrong Context, tag MailPart must be inside a Mail tag");        
110            }
111    }