1 package org.tigris.scarab.util; 2 3 48 49 import java.util.Locale ; 50 51 import org.apache.commons.lang.StringUtils; 52 import org.apache.fulcrum.localization.Localization; 53 import org.apache.turbine.Turbine; 54 import org.tigris.scarab.om.Module; 55 56 64 public class EmailLinkFactory 65 { 66 private static final String LINK_TOOL_KEY = 67 "scarab.email.link.classname"; 68 69 private static final Class linkClass; 70 static 71 { 72 String className = Turbine.getConfiguration() 73 .getString(LINK_TOOL_KEY, ""); 74 Class c = null; 75 if (StringUtils.isNotEmpty(className)) 76 { 77 try 78 { 79 c = Class.forName(className); 80 } 81 catch (Exception e) 82 { 83 Log.get().warn("Unable to to create '" + className + '\'', e); 84 } 85 } 86 else 87 { 88 Log.get().info(LINK_TOOL_KEY + 89 " parameter exists, but has no value"); 90 } 91 92 if (c == null) 93 { 94 c = EmailLink.class; 95 } 96 97 linkClass = c; 98 } 99 100 101 public static EmailLink getInstance(Module module) 102 { 103 EmailLink result = null; 104 if (linkClass == null) 105 { 106 result = new EmailLink(module); 107 } 108 else 109 { 110 try 111 { 112 result = (EmailLink)linkClass.newInstance(); 113 result.setCurrentModule(module); 114 } 115 catch (Exception e) 116 { 117 Log.get().warn("Unable to to create '" + linkClass.getName() + 118 "'; will use default link tool.", e); 119 result = new ErrorEmailLink(module); 120 } 121 } 122 return result; 123 } 124 125 static class ErrorEmailLink 126 extends EmailLink 127 { 128 ErrorEmailLink() 129 { 130 } 131 132 ErrorEmailLink(Module module) 133 { 134 super(module); 135 } 136 137 public String toString() 138 { 139 Module module = getCurrentModule(); 140 Locale locale = null; 141 if (module != null) 142 { 143 locale = module.getLocale(); 144 } 145 if (locale == null) 146 { 147 locale = ScarabConstants.DEFAULT_LOCALE; 148 } 149 return Localization.getString(ScarabConstants.DEFAULT_BUNDLE_NAME, 150 locale, 151 "EmailLinkError"); 152 } 153 } 154 } 155 | Popular Tags |