1 33 package net.myvietnam.mvncore.interceptor; 34 35 import net.myvietnam.mvncore.MVNCoreConfig; 36 import net.myvietnam.mvncore.exception.InterceptorException; 37 import org.apache.commons.logging.Log; 38 import org.apache.commons.logging.LogFactory; 39 40 public class InterceptorService { 41 42 private static Log log = LogFactory.getLog(InterceptorService.class); 43 44 46 47 private static InterceptorService instance = new InterceptorService(); 48 49 private MailInterceptor mailInterceptor = null; 50 51 private ContentInterceptor contentInterceptor = null; 52 53 private LoginIDInterceptor loginIDInterceptor = null; 54 55 58 private InterceptorService() { 59 loadInterceptorInfo(); 60 } 61 62 private void loadInterceptorInfo() { 63 String mailInterceptorClassName = MVNCoreConfig.getMailInterceptorClassName(); 64 loadMailInterceptor(mailInterceptorClassName); 65 66 String contentInterceptorClassName = MVNCoreConfig.getContentInterceptorClassName(); 67 loadContentInterceptor(contentInterceptorClassName); 68 69 String loginIDInterceptorClassName = MVNCoreConfig.getLoginIdInterceptorClassName(); 70 loadLoginIDInterceptor(loginIDInterceptorClassName); 71 } 72 73 private void loadContentInterceptor(String contentInterceptorClassName) { 74 75 try { 76 if (contentInterceptorClassName.length() > 0) { 77 Class contentInterceptorClass = Class.forName(contentInterceptorClassName); 78 ContentInterceptor interceptor = (ContentInterceptor)contentInterceptorClass.newInstance(); 79 setContentInterceptor(interceptor); 80 } 81 } catch (Exception ex) { 82 log.error("Cannot load ContentInterceptor", ex); 83 } 84 } 85 86 private void loadMailInterceptor(String mailInterceptorClassName) { 87 88 try { 89 if (mailInterceptorClassName.length() > 0) { 90 Class mailInterceptorClass = Class.forName(mailInterceptorClassName); 91 MailInterceptor interceptor = (MailInterceptor)mailInterceptorClass.newInstance(); 92 setMailInterceptor(interceptor); 93 } 94 } catch (Exception ex) { 95 log.error("Cannot load MailInterceptor", ex); 96 } 97 } 98 99 private void loadLoginIDInterceptor(String loginIDInterceptorClassName) { 100 101 try { 102 if (loginIDInterceptorClassName.length() > 0) { 103 Class loginIDInterceptorClass = Class.forName(loginIDInterceptorClassName); 104 LoginIDInterceptor interceptor = (LoginIDInterceptor)loginIDInterceptorClass.newInstance(); 105 setLoginIDInterceptor(interceptor); 106 } 107 } catch (Exception ex) { 108 log.error("Cannot load LoginIDInterceptor", ex); 109 } 110 } 111 112 117 public static InterceptorService getInstance() { 118 return instance; 119 } 120 121 127 public void validateMail(String email) throws InterceptorException { 128 if (mailInterceptor != null) { 129 mailInterceptor.validateEmail(email); 130 } 131 } 132 133 public MailInterceptor getMailInterceptor() { 134 return mailInterceptor; 135 } 136 137 public void setMailInterceptor(MailInterceptor interceptor) { 138 log.info("Use MailInterceptor = " + interceptor); 139 this.mailInterceptor = interceptor; 140 } 141 142 149 public String validateContent(String content) throws InterceptorException { 150 if (contentInterceptor != null) { 151 return contentInterceptor.validateContent(content); 152 } 153 return content; 154 } 155 156 public ContentInterceptor getContentInterceptor() { 157 return contentInterceptor; 158 } 159 160 public void setContentInterceptor(ContentInterceptor interceptor) { 161 log.info("Use ContentInterceptor = " + interceptor); 162 this.contentInterceptor = interceptor; 163 } 164 165 171 public void validateLoginID(String loginID) throws InterceptorException { 172 if (loginIDInterceptor != null) { 173 loginIDInterceptor.validateLoginID(loginID); 174 } 175 } 176 177 public LoginIDInterceptor getLoginIDInterceptor() { 178 return loginIDInterceptor; 179 } 180 181 public void setLoginIDInterceptor(LoginIDInterceptor interceptor) { 182 log.info("Use LoginIDInterceptor = " + interceptor); 183 this.loginIDInterceptor = interceptor; 184 } 185 186 } 187 | Popular Tags |