|
What this is
Other links
The source code/* * $Header: /cvsroot/mvnforum/myvietnam/src/net/myvietnam/mvncore/interceptor/InterceptorService.java,v 1.6 2005/01/26 04:54:40 minhnn Exp $ * $Author: minhnn $ * $Revision: 1.6 $ * $Date: 2005/01/26 04:54:40 $ * * ==================================================================== * * Copyright (C) 2002-2005 by MyVietnam.net * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * All copyright notices regarding MyVietnam and MyVietnam CoreLib * MUST remain intact in the scripts and source code. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Correspondence and Marketing Questions can be sent to: * info@MyVietnam.net * * @author: Minh Nguyen minhnn@MyVietnam.net */ package net.myvietnam.mvncore.interceptor; import net.myvietnam.mvncore.MVNCoreConfig; import net.myvietnam.mvncore.exception.InterceptorException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class InterceptorService { private static Log log = LogFactory.getLog(InterceptorService.class); //private static final String OPTION_FILE_NAME = "mvncore.xml"; /** Singleton instance of this class */ private static InterceptorService instance = new InterceptorService(); private MailInterceptor mailInterceptor = null; private ContentInterceptor contentInterceptor = null; private LoginIDInterceptor loginIDInterceptor = null; /** * Private constructor to prevent instantiation */ private InterceptorService() { loadInterceptorInfo(); } /* private void loadInterceptorInfo() { try { String strPathName = FileUtil.getServletClassesPath(); String configFilename = strPathName + OPTION_FILE_NAME; DOM4JConfiguration conf = new DOM4JConfiguration(new File(configFilename)); String mailInterceptorClassName = conf.getString("interceptor.mailinterceptor_implementation", ""); loadMailInterceptor(mailInterceptorClassName); String contentInterceptorClassName = conf.getString("interceptor.contentinterceptor_implementation", ""); loadContentInterceptor(contentInterceptorClassName); String loginIDInterceptorClassName = conf.getString("interceptor.loginidinterceptor_implementation", ""); loadLoginIDInterceptor(loginIDInterceptorClassName); } catch (Exception e) { log.error("Error loading the interceptor properties", e); } }*/ private void loadInterceptorInfo() { String mailInterceptorClassName = MVNCoreConfig.getMailInterceptorClassName(); loadMailInterceptor(mailInterceptorClassName); String contentInterceptorClassName = MVNCoreConfig.getContentInterceptorClassName(); loadContentInterceptor(contentInterceptorClassName); String loginIDInterceptorClassName = MVNCoreConfig.getLoginIdInterceptorClassName(); loadLoginIDInterceptor(loginIDInterceptorClassName); } private void loadContentInterceptor(String contentInterceptorClassName) { try { if (contentInterceptorClassName.length() > 0) { Class contentInterceptorClass = Class.forName(contentInterceptorClassName); ContentInterceptor interceptor = (ContentInterceptor)contentInterceptorClass.newInstance(); setContentInterceptor(interceptor); } } catch (Exception ex) { log.error("Cannot load ContentInterceptor", ex); } } private void loadMailInterceptor(String mailInterceptorClassName) { try { if (mailInterceptorClassName.length() > 0) { Class mailInterceptorClass = Class.forName(mailInterceptorClassName); MailInterceptor interceptor = (MailInterceptor)mailInterceptorClass.newInstance(); setMailInterceptor(interceptor); } } catch (Exception ex) { log.error("Cannot load MailInterceptor", ex); } } private void loadLoginIDInterceptor(String loginIDInterceptorClassName) { try { if (loginIDInterceptorClassName.length() > 0) { Class loginIDInterceptorClass = Class.forName(loginIDInterceptorClassName); LoginIDInterceptor interceptor = (LoginIDInterceptor)loginIDInterceptorClass.newInstance(); setLoginIDInterceptor(interceptor); } } catch (Exception ex) { log.error("Cannot load LoginIDInterceptor", ex); } } /** * Return singleton instance of this class * * @return InterceptorService the singleton instance of this class */ public static InterceptorService getInstance() { return instance; } /** * Validate email if the MailInterceptor is present * * @param email String email to be validated * @throws InterceptorException if email is not valid for some reason */ public void validateMail(String email) throws InterceptorException { if (mailInterceptor != null) { mailInterceptor.validateEmail(email); } } public MailInterceptor getMailInterceptor() { return mailInterceptor; } public void setMailInterceptor(MailInterceptor interceptor) { log.info("Use MailInterceptor = " + interceptor); this.mailInterceptor = interceptor; } /** * Validate content if the ContentInterceptor is present * * @param content String content to be validated * @throws InterceptorException if content is not valid for some reason */ public void validateContent(String content) throws InterceptorException { if (contentInterceptor != null) { contentInterceptor.validateContent(content); } } public ContentInterceptor getContentInterceptor() { return contentInterceptor; } public void setContentInterceptor(ContentInterceptor interceptor) { log.info("Use ContentInterceptor = " + interceptor); this.contentInterceptor = interceptor; } /** * Validate loginID if the LoginIDInterceptor is present * * @param loginID String loginID to be validated * @throws InterceptorException if loginID is not valid for some reason */ public void validateLoginID(String loginID) throws InterceptorException { if (loginIDInterceptor != null) { loginIDInterceptor.validateLoginID(loginID); } } public LoginIDInterceptor getLoginIDInterceptor() { return loginIDInterceptor; } public void setLoginIDInterceptor(LoginIDInterceptor interceptor) { log.info("Use LoginIDInterceptor = " + interceptor); this.loginIDInterceptor = interceptor; } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.