001: /**
002: * $Id: NewFolderTag.java,v 1.6 2005/09/21 10:52:46 dg154973 Exp $
003: * Copyright 2002 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and iPlanet
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.wireless.taglibs.mail;
014:
015: import javax.servlet.jsp.*;
016: import javax.servlet.jsp.tagext.*;
017:
018: import javax.mail.*;
019: import javax.mail.internet.*;
020: import javax.mail.search.*;
021:
022: import com.sun.portal.wireless.taglibs.base.*;
023: import com.sun.portal.log.common.PortalLogger;
024:
025: import java.util.logging.Logger;
026: import java.util.logging.Level;
027:
028: /**
029: *
030: * NewFolderTag - execute a create folder on the Store
031: *
032: * @version 1.0
033: * @see com.sun.portal.wireless.taglibs.base.CommandTag
034: */
035: public class NewFolderTag extends CommandTag {
036: private static Logger logger = PortalLogger
037: .getLogger(NewFolderTag.class);
038:
039: private String foldername = null;
040: private String path = null;
041:
042: public boolean execute() throws JspException {
043:
044: MailContext mc;
045: try {
046: mc = MailContext.getContext(pageContext);
047: } catch (Exception e) {
048: throw new JspException(this .getClass().getName()
049: + ".execute(): Couldn't get mail context: "
050: + e.getMessage());
051: }
052:
053: // Reset error code
054: mc.setErrorCode("");
055:
056: // User can specify the fullname to create or a foldername and a path
057: String fullname = null;
058: if (path != null && path.length() > 0)
059: fullname = path + "/" + foldername;
060: else
061: fullname = foldername;
062:
063: Store store = mc.getMailStore();
064:
065: try {
066: Folder dfolder = store.getFolder(fullname);
067:
068: if (dfolder.exists()) {
069: release();
070: mc.setErrorCode("MAIL_003"); // MAIL_003 = Mailbox already exists
071: return false;
072: }
073:
074: // Create
075: boolean b = dfolder.create(Folder.HOLDS_MESSAGES);
076:
077: if (!b) {
078: release();
079: logger.log(Level.FINE, "PSMA_CSPWTM0029", fullname);
080: mc.setErrorCode("MAIL_004"); // MAIL_004 = Create mailbox failed
081: return false;
082: } else {
083: release();
084: return true;
085: }
086: } catch (MessagingException e) {
087: logger.log(Level.FINE, "PSMA_CSPWTM0030", e);
088: mc.setErrorCode("MAIL_008"); // MAIL_008 = General messaging error
089: release();
090: return false;
091: }
092: }
093:
094: /**
095: * Cleanup
096: */
097:
098: public void release() {
099: super .release();
100: foldername = null;
101: path = null;
102: }
103:
104: /**
105: *
106: * Set the folder name attribute
107: *
108: * @param set the folder name attribute
109: */
110:
111: public void setFoldername(String name) {
112: foldername = evalAttribute(name);
113: }
114:
115: /**
116: *
117: * Set the file path attribute
118: *
119: * @param set the file path attribute
120: */
121:
122: public void setPath(String path) {
123: this.path = evalAttribute(path);
124: }
125: }
|