View | Details | Raw Unified | Return to bug 31859
Collapse All | Expand All

(-)AttachTag.java (-4 / +13 lines)
Lines 97-104 Link Here
97
        }
97
        }
98
        mbp = new MimeBodyPart();  // create the bodypart for this attachment
98
        mbp = new MimeBodyPart();  // create the bodypart for this attachment
99
        body = null;
99
        body = null;
100
        if (type != null || (file != null && file.length() == 0) ||
100
        if (
101
                (url != null && url.length() == 0) ) {
101
            type != null 
102
        || 
103
            (file != null && file.length() == 0) 
104
        ||
105
            (url != null && url.length() == 0) 
106
        ) {
102
            return EVAL_BODY_TAG;
107
            return EVAL_BODY_TAG;
103
        }
108
        }
104
        return SKIP_BODY;
109
        return SKIP_BODY;
Lines 233-242 Link Here
233
        try {
238
        try {
234
            URL url = new URL(value);
239
            URL url = new URL(value);
235
            mbp.setDataHandler(new DataHandler(url));
240
            mbp.setDataHandler(new DataHandler(url));
236
            if(url.getFile() != null)
241
            if(url.getFile() != null) {
237
                mbp.setFileName(url.getFile());
242
                mbp.setFileName(url.getFile());
238
            else
243
                mbp.setContentID(url.getFile());
244
            } else {
239
                mbp.setFileName(value);
245
                mbp.setFileName(value);
246
                mbp.setContentID(value);
247
            }
240
248
241
        } catch(MalformedURLException e) {
249
        } catch(MalformedURLException e) {
242
            throw new JspException("The URL entered as an attachment was " +
250
            throw new JspException("The URL entered as an attachment was " +
Lines 268-273 Link Here
268
                DataSource attachment = new FileDataSource(file);
276
                DataSource attachment = new FileDataSource(file);
269
                mbp.setDataHandler(new DataHandler(attachment));
277
                mbp.setDataHandler(new DataHandler(attachment));
270
                mbp.setFileName(file.getName());
278
                mbp.setFileName(file.getName());
279
                mbp.setContentID(file.getName());
271
            } else {
280
            } else {
272
                // if the file does not exist it is probably an error in the way
281
                // if the file does not exist it is probably an error in the way
273
                // the page author is adding the path throw an exception so this
282
                // the page author is adding the path throw an exception so this
(-)MessageTag.java (-16 / +103 lines)
Lines 19-24 Link Here
19
import javax.servlet.jsp.JspException;
19
import javax.servlet.jsp.JspException;
20
import javax.servlet.jsp.tagext.BodyContent;
20
import javax.servlet.jsp.tagext.BodyContent;
21
import javax.servlet.jsp.tagext.BodyTagSupport;
21
import javax.servlet.jsp.tagext.BodyTagSupport;
22
import java.net.URL;
23
import javax.mail.internet.MimeBodyPart;
24
import javax.activation.DataHandler;
25
import java.net.MalformedURLException;
26
import javax.mail.MessagingException;
22
27
23
/**
28
/**
24
 * MessageTag - JSP tag <b>Message</b> is used to set the message in an e-mail.
29
 * MessageTag - JSP tag <b>Message</b> is used to set the message in an e-mail.
Lines 55-65 Link Here
55
    private String type = "text";
60
    private String type = "text";
56
61
57
    /**
62
    /**
63
     * holds the value of body if the url is to be retrieved from the body of
64
     * tag
65
     */
66
    private String url = null;
67
    
68
    /**
58
     * character set to be used (default is unspecified)
69
     * character set to be used (default is unspecified)
59
     */
70
     */
60
    private String charset = null;
71
    private String charset = null;
61
72
62
    /**
73
    /**
74
     * object in which the attachment is stored within the e-mail message
75
     */
76
    private MimeBodyPart mbp = null;
77
    
78
    /**
79
     * pointer to the parent tag
80
     */
81
    private MailTag myparent = null;
82
    
83
    /**
63
     *  implementation of the method from the tag interface that tells the JSP
84
     *  implementation of the method from the tag interface that tells the JSP
64
     *  page what to do after the body of this tag
85
     *  page what to do after the body of this tag
65
     *
86
     *
Lines 71-96 Link Here
71
     *
92
     *
72
     */
93
     */
73
    public int doAfterBody() throws JspException {
94
    public int doAfterBody() throws JspException {
95
        BodyContent body = getBodyContent();
96
        mbp = new MimeBodyPart();  // create the bodypart for this attachment        
97
        myparent = (MailTag)findAncestorWithClass(this, MailTag.class);
98
        if (url == null) {
99
            // parent tag must be a MailTag, gives access to methods in parent
100
            if (myparent == null) {
101
                throw new JspException("message tag not nested within mail tag");
102
            }
103
            
104
            String message = body.getString();
105
            // Clear the body since we only used it as input for the email address
106
            body.clearBody();
107
            if (message == null) {
108
                throw new JspException("The message tag is empty");
109
            }
110
            myparent.setMessage(message); // set message in the parent tag
111
            myparent.setType(type);  // set the mime type of the message
112
            myparent.setCharset(charset);  // set the character set of the message
113
            
114
        } else if (url.length() == 0 && body != null) {
115
            String s_body = body.getString();
116
            if(s_body != null)
117
                s_body = s_body.trim();
118
            // the url is supposed to come from the body of the tag
119
            if (s_body.length() > 0) {
120
                // prepare the file or url resource to be an attachment
121
                setUrlBodyPart(s_body);
122
            } else {
123
                // body is empty throw error
124
                throw new JspException(
125
                    "The url must be givenin the body of this tag.");
126
            }
127
        } else
128
            // create the attachment with the url in the url attribute
129
            setUrlBodyPart(url);
130
        return SKIP_BODY;
131
    }
74
132
75
	// parent tag must be a MailTag, gives access to methods in parent
133
    /**
76
	MailTag myparent = (MailTag)findAncestorWithClass(this, MailTag.class);
134
     * wrap the url named attachment in the approiate datahandler and create a
77
	if (myparent == null) {
135
     * mimebodypart to be added to the list of attachments
78
	    throw new JspException("message tag not nested within mail tag");
136
     *
79
        }
137
     * @param value  string that represents a URL
138
     *
139
     */
140
    protected void setUrlBodyPart(String value) throws JspException {
80
141
81
        BodyContent body = getBodyContent();
142
// Added by Jayson Falkner - 5/8/2001
82
        String message = body.getString();
143
83
        // Clear the body since we only used it as input for the email address
144
        try {
84
        body.clearBody();
145
            URL url = new URL(value);
85
        if (message == null) {
146
            mbp.setDataHandler(new DataHandler(url));
86
            throw new JspException("The message tag is empty");
147
            if(url.getFile() != null) {
148
                mbp.setFileName(url.getFile());
149
                mbp.setContentID(url.getFile());
150
            } else {
151
                mbp.setFileName(value);
152
                mbp.setContentID(value);
153
            }   
154
            myparent.setMessage((String)mbp.getContent()); // set message in the parent tag
155
            myparent.setType(type);  // set the mime type of the message
156
            myparent.setCharset(charset);  // set the character set of the message
157
        } catch(MalformedURLException e) {
158
            throw new JspException("The URL entered as an attachment was " +
159
                        "incorrectly formatted please check it and try again.");
160
        } catch(MessagingException e) {
161
            throw new JspException("The Resource named by " + url + " could not"
162
                                   + " be used as the message body.");
163
        } catch(java.io.IOException ioe) {
164
            throw new JspException("The Resource named by " + url + " could not"
165
                                   + " be cast to a String.");
87
        }
166
        }
88
	myparent.setMessage(message); // set message in the parent tag
167
// End of added
89
	myparent.setType(type);  // set the mime type of the message
90
	myparent.setCharset(charset);  // set the character set of the message
91
	return SKIP_BODY;
92
    }
168
    }
93
169
    
94
    /**
170
    /**
95
     * set the mime type for this email text or html
171
     * set the mime type for this email text or html
96
     *
172
     *
Lines 110-113 Link Here
110
    public void setCharset(String value) {
186
    public void setCharset(String value) {
111
	charset = value;
187
	charset = value;
112
    }
188
    }
189
    
190
    /**
191
     * set the resource named by URL into a mimebodypart so that it can be added
192
     * to the list of attachments for this e-mail
193
     *
194
     * @param value  full url including http://, to the resource to be added as
195
     *               an attachment
196
     */
197
    public void setUrl(String value) {
198
        url = value;
199
    }
113
}
200
}

Return to bug 31859