001    /*
002     * Copyright 2010 the original author or authors.
003     * 
004     *  Licensed under the Apache License, Version 2.0 (the "License");
005     *  you may not use this file except in compliance with the License.
006     *  You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     *  Unless required by applicable law or agreed to in writing, software
011     *  distributed under the License is distributed on an "AS IS" BASIS,
012     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     *  See the License for the specific language governing permissions and
014     *  limitations under the License.
015     */
016    package com.hs.mail.smtp.processor;
017    
018    import java.util.StringTokenizer;
019    
020    import org.apache.log4j.Logger;
021    
022    import com.hs.mail.container.config.ComponentManager;
023    import com.hs.mail.container.server.socket.TcpTransport;
024    import com.hs.mail.imap.user.UserManager;
025    import com.hs.mail.smtp.SmtpException;
026    import com.hs.mail.smtp.SmtpSession;
027    
028    /**
029     * 
030     * @author Won Chul Doh
031     * @since May 30, 2010
032     *
033     */
034    public abstract class AbstractSmtpProcessor implements SmtpProcessor {
035    
036            protected static Logger logger = Logger.getLogger(AbstractSmtpProcessor.class);
037            
038            public void process(SmtpSession session, TcpTransport trans,
039                            StringTokenizer st) {
040                    try {
041                            doProcess(session, trans, st);
042                    } catch (SmtpException ex) {
043                            session.writeResponse(ex.getMessage());
044                    }
045            }
046            
047            abstract protected void doProcess(SmtpSession session, TcpTransport trans,
048                            StringTokenizer st) throws SmtpException;
049    
050            protected UserManager getUserManager() {
051                    return (UserManager) ComponentManager.getBean("userManager");
052            }
053            
054            protected String nextToken(StringTokenizer st) {
055                    return st.nextToken().trim();
056            }
057            
058            protected boolean startsWith(String str, String prefix) {
059                    return (str != null) ? str.toUpperCase().startsWith(prefix) : false;
060            }
061            
062    }