use of java.util.Hashtable in project j2objc by google.
the class Context2 method processName.
/**
* Process a raw XML 1.0 name in this context.
*
* @param qName The raw XML 1.0 name.
* @param isAttribute true if this is an attribute name.
* @return An array of three strings containing the
* URI part (or empty string), the local part,
* and the raw name, all internalized, or null
* if there is an undeclared prefix.
* @see org.xml.sax.helpers.NamespaceSupport2#processName
*/
String[] processName(String qName, boolean isAttribute) {
String[] name;
Hashtable table;
// Select the appropriate table.
if (isAttribute) {
if (elementNameTable == null)
elementNameTable = new Hashtable();
table = elementNameTable;
} else {
if (attributeNameTable == null)
attributeNameTable = new Hashtable();
table = attributeNameTable;
}
// Start by looking in the cache, and
// return immediately if the name
// is already known in this content
name = (String[]) table.get(qName);
if (name != null) {
return name;
}
// We haven't seen this name in this
// context before.
name = new String[3];
int index = qName.indexOf(':');
// No prefix.
if (index == -1) {
if (isAttribute || defaultNS == null) {
name[0] = "";
} else {
name[0] = defaultNS;
}
name[1] = qName.intern();
name[2] = name[1];
} else // Prefix
{
String prefix = qName.substring(0, index);
String local = qName.substring(index + 1);
String uri;
if ("".equals(prefix)) {
uri = defaultNS;
} else {
uri = (String) prefixTable.get(prefix);
}
if (uri == null) {
return null;
}
name[0] = uri;
name[1] = local.intern();
name[2] = qName.intern();
}
// Save in the cache for future use.
table.put(name[2], name);
tablesDirty = true;
return name;
}
use of java.util.Hashtable in project eweb4j-framework by laiweiwei.
the class IOC method getBean.
/**
* 生产出符合beanID名字的bean
*
* @param <T>
* @param beanID
* @return
* @throws Exception
*/
public static synchronized <T> T getBean(String beanID) {
if (!containsBean(beanID)) {
return null;
}
// 声明用来返回的对象
T t = null;
try {
// 声明构造方法参数列表的初始化值
Object[] initargs = null;
// 声明构造方法参数列表
Class<?>[] args = null;
List<Object> initargList = new ArrayList<Object>();
List<Class<?>> argList = new ArrayList<Class<?>>();
// setters cache
Map<String, Object> properties = new Hashtable<String, Object>();
// 遍历配置文件,找出beanID的bean
if (IOCConfigBeanCache.containsKey(beanID)) {
IOCConfigBean iocBean = IOCConfigBeanCache.get(beanID);
// 取出该bean的类型,便于最后使用反射调用构造方法实例化
Class<T> clazz = (Class<T>) Thread.currentThread().getContextClassLoader().loadClass(iocBean.getClazz());
// 判断该bean的生命周期
if (IOCConfigConstant.SINGLETON_SCOPE.equalsIgnoreCase(iocBean.getScope())) {
// 如果是单件,就从单件缓存池中取
if (SingleBeanCache.containsKey(beanID)) {
t = (T) SingleBeanCache.get(beanID);
return t;
}
}
// 遍历每个bean的注入配置
for (Iterator<Injection> it = iocBean.getInject().iterator(); it.hasNext(); ) {
Injection inj = it.next();
if (inj == null)
continue;
String ref = inj.getRef();
if (ref != null && !"".equals(ref)) {
// 如果ref不为空,说明注入的是对象类型,后面需要进入递归
String name = inj.getName();
if (name != null && !"".equals(name)) {
// 如果属性名字不为空,说明使用的是setter注入方式
properties.put(name, getBean(ref));
} else {
// 如果属性名字为空,说明使用的是构造器注入方式
// 使用构造器注入的时候,需要按照构造器参数列表顺序实例化
Object obj = getBean(ref);
initargList.add(obj);
String type = inj.getType();
if (type != null && type.trim().length() > 0) {
Class<?> cls = Thread.currentThread().getContextClassLoader().loadClass(type);
argList.add(cls);
} else {
argList.add(obj.getClass());
}
}
} else {
// 注入基本类型
String type = inj.getType();
String value = inj.getValue();
if (value == null)
value = "";
String name = inj.getName();
if (name != null && !"".equals(name)) {
// 如果属性名字不为空,说明使用的是setter注入方式
if (IOCConfigConstant.INT_ARGTYPE.equalsIgnoreCase(type) || "java.lang.Integer".equalsIgnoreCase(type)) {
if ("".equals(value.trim()))
value = "0";
// int
properties.put(name, Integer.parseInt(value));
} else if (IOCConfigConstant.STRING_ARGTYPE.equalsIgnoreCase(type) || "java.lang.String".equalsIgnoreCase(type)) {
// String
properties.put(name, value);
} else if (IOCConfigConstant.LONG_ARGTYPE.equalsIgnoreCase(type) || "java.lang.Long".equalsIgnoreCase(type)) {
// long
if ("".equals(value.trim()))
value = "0";
properties.put(name, Long.parseLong(value));
} else if (IOCConfigConstant.FLOAT_ARGTYPE.equalsIgnoreCase(type) || "java.lang.Float".equalsIgnoreCase(type)) {
// float
if ("".equals(value.trim()))
value = "0.0";
properties.put(name, Float.parseFloat(value));
} else if (IOCConfigConstant.BOOLEAN_ARGTYPE.equalsIgnoreCase(type) || "java.lang.Boolean".equalsIgnoreCase(type)) {
// boolean
if ("".equals(value.trim()))
value = "false";
properties.put(name, Boolean.parseBoolean(value));
} else if (IOCConfigConstant.DOUBLE_ARGTYPE.equalsIgnoreCase(type) || "java.lang.Double".equalsIgnoreCase(type)) {
// double
if ("".equals(value.trim()))
value = "0.0";
properties.put(name, Double.parseDouble(value));
}
} else {
// 使用构造器注入的时候,需要按照构造器参数列表顺序实例化
if (IOCConfigConstant.INT_ARGTYPE.equalsIgnoreCase(type) || "java.lang.Integer".equalsIgnoreCase(type)) {
// int
if ("".equals(value.trim()))
value = "0";
argList.add(int.class);
initargList.add(Integer.parseInt(value));
} else if (IOCConfigConstant.LONG_ARGTYPE.equalsIgnoreCase(type) || "java.lang.Long".equalsIgnoreCase(type)) {
// long
if ("".equals(value.trim()))
value = "0";
argList.add(long.class);
initargList.add(Long.parseLong(value));
} else if (IOCConfigConstant.FLOAT_ARGTYPE.equalsIgnoreCase(type) || "java.lang.Float".equalsIgnoreCase(type)) {
// float
if ("".equals(value.trim()))
value = "0.0";
argList.add(float.class);
initargList.add(Float.parseFloat(value));
} else if (IOCConfigConstant.BOOLEAN_ARGTYPE.equalsIgnoreCase(type) || "java.lang.Boolean".equalsIgnoreCase(type)) {
// boolean
if ("".equals(value.trim()))
value = "false";
argList.add(boolean.class);
initargList.add(Boolean.parseBoolean(value));
} else if (IOCConfigConstant.DOUBLE_ARGTYPE.equalsIgnoreCase(type) || "java.lang.Double".equalsIgnoreCase(type)) {
// double
if ("".equals(value.trim()))
value = "0.0";
argList.add(double.class);
initargList.add(Double.parseDouble(value));
} else if (IOCConfigConstant.STRING_ARGTYPE.equalsIgnoreCase(type) || "java.lang.String".equalsIgnoreCase(type)) {
// String
argList.add(String.class);
initargList.add(value);
}
}
}
}
// 如果构造方法参数列表不为空,说明需要使用构造方法进行注入
if (argList.size() > 0 && initargList.size() > 0) {
args = new Class<?>[argList.size()];
initargs = new Object[initargList.size()];
for (int i = 0; i < argList.size(); i++) {
args[i] = argList.get(i);
initargs[i] = initargList.get(i);
}
t = clazz.getDeclaredConstructor(args).newInstance(initargs);
} else if (t == null) {
t = clazz.newInstance();
for (Iterator<Entry<String, Object>> it = properties.entrySet().iterator(); it.hasNext(); ) {
Entry<String, Object> e = it.next();
final String name = e.getKey();
ReflectUtil ru = new ReflectUtil(t);
Method m = ru.getSetter(name);
if (m == null)
continue;
m.invoke(t, e.getValue());
}
}
// 判断该bean的生命周期
if (IOCConfigConstant.SINGLETON_SCOPE.equalsIgnoreCase(iocBean.getScope())) {
// 如果是单件,就从单件缓存池中取
if (!SingleBeanCache.containsKey(beanID)) {
SingleBeanCache.add(beanID, t);
}
}
}
} catch (Throwable e) {
log.error("IOC.getBean(" + beanID + ") failed!", e);
}
String info = "IOC.getBean(" + beanID + ") -> " + t;
log.debug(info);
return t;
}
use of java.util.Hashtable in project eweb4j-framework by laiweiwei.
the class Props method readProperties.
// 读取properties的全部信息
public static synchronized String readProperties(Prop f, boolean isCreate) throws IOException {
if (f == null || f.getPath().length() == 0)
return null;
String id = f.getId();
String path = f.getPath();
ConfigBean cb = (ConfigBean) SingleBeanCache.get(ConfigBean.class.getName());
I18N i18n = cb.getLocales();
final String sufPro = ".properties";
if (i18n != null) {
for (Locale l : i18n.getLocale()) {
String suffix1 = "_" + l.getLanguage() + "_" + l.getCountry();
String tmpPath1 = path.replace(sufPro, suffix1 + sufPro);
i18nIds.add(id);
if (FileUtil.exists(ConfigConstant.CONFIG_BASE_PATH + tmpPath1)) {
Prop p = new Prop();
p.setGlobal("false");
p.setId(id + suffix1);
p.setPath(tmpPath1);
// 递归,把国际化文件内容加载仅缓存
readProperties(p, false);
// 如果存在国际化文件,那么默认的文件允许不存在
isCreate = false;
continue;
}
String suffix2 = "_" + l.getLanguage();
String tmpPath2 = path.replace(sufPro, suffix2 + sufPro);
if (FileUtil.exists(ConfigConstant.CONFIG_BASE_PATH + tmpPath2)) {
Prop p = new Prop();
p.setGlobal("false");
p.setId(id + suffix2);
p.setPath(tmpPath2);
// 递归,把国际化文件内容加载仅缓存
readProperties(p, false);
// 如果存在国际化文件,那么默认的文件允许不存在
isCreate = false;
continue;
}
}
}
String error = null;
String filePath = ConfigConstant.CONFIG_BASE_PATH + path;
String global = f.getGlobal();
Properties properties = new Properties();
InputStream in = null;
Hashtable<String, String> tmpHt = new Hashtable<String, String>();
try {
in = new BufferedInputStream(new FileInputStream(filePath));
properties.load(in);
//第一遍全部加进来
Props.loadProperty(properties, tmpHt);
//渲染 ${} 引用值
Pattern pattern = Pattern.compile(RegexList.property_single_regexp);
for (Iterator<Entry<String, String>> it = tmpHt.entrySet().iterator(); it.hasNext(); ) {
Entry<String, String> e = it.next();
String key = e.getKey();
String property = e.getValue();
Props.renderVarable(pattern, key, property, tmpHt);
}
if ("true".equalsIgnoreCase(global) || "1".equalsIgnoreCase(global)) {
globalMap.putAll(tmpHt);
log.debug("global | map -> " + tmpHt.toString());
} else if (id != null && id.length() > 0) {
props.put(id, tmpHt);
log.debug("id -> " + id + " | map -> " + tmpHt.toString());
}
} catch (FileNotFoundException e) {
log.warn(filePath + ", file not found!", e);
if (isCreate) {
boolean flag = FileUtil.createFile(filePath);
if (flag) {
error = filePath + " create success";
Props.writeProperties(filePath, "framework", "eweb4j");
log.warn(error);
} else {
log.warn(filePath + " create fail");
}
}
} finally {
if (in != null)
in.close();
}
return error;
}
use of java.util.Hashtable in project camel by apache.
the class OsgiServletRegisterer method register.
public void register() throws Exception {
ObjectHelper.notEmpty(alias, "alias", this);
ObjectHelper.notEmpty(servletName, "servletName", this);
HttpContext actualHttpContext = (httpContext == null) ? httpService.createDefaultHttpContext() : httpContext;
final Dictionary<String, String> initParams = new Hashtable<String, String>();
initParams.put("matchOnUriPrefix", matchOnUriPrefix ? "true" : "false");
initParams.put("servlet-name", servletName);
httpService.registerServlet(alias, servlet, initParams, actualHttpContext);
alreadyRegistered = true;
}
use of java.util.Hashtable in project jforum2 by rafaelsteil.
the class LDAPAuthenticator method validateLogin.
/**
* @see net.jforum.sso.LoginAuthenticator#validateLogin(java.lang.String, java.lang.String, java.util.Map)
*/
public User validateLogin(String username, String password, Map extraParams) {
Hashtable environment = this.prepareEnvironment();
StringBuffer principal = new StringBuffer(256).append(SystemGlobals.getValue(ConfigKeys.LDAP_LOGIN_PREFIX)).append(username).append(',').append(SystemGlobals.getValue(ConfigKeys.LDAP_LOGIN_SUFFIX));
environment.put(Context.SECURITY_PRINCIPAL, principal.toString());
environment.put(Context.SECURITY_CREDENTIALS, password);
DirContext dir = null;
try {
dir = new InitialDirContext(environment);
String lookupPrefix = SystemGlobals.getValue(ConfigKeys.LDAP_LOOKUP_PREFIX);
String lookupSuffix = SystemGlobals.getValue(ConfigKeys.LDAP_LOOKUP_SUFFIX);
if (lookupPrefix == null || lookupPrefix.length() == 0) {
lookupPrefix = SystemGlobals.getValue(ConfigKeys.LDAP_LOGIN_PREFIX);
}
if (lookupSuffix == null || lookupSuffix.length() == 0) {
lookupSuffix = SystemGlobals.getValue(ConfigKeys.LDAP_LOGIN_SUFFIX);
}
String lookupPrincipal = lookupPrefix + username + "," + lookupSuffix;
Attribute att = dir.getAttributes(lookupPrincipal).get(SystemGlobals.getValue(ConfigKeys.LDAP_FIELD_EMAIL));
SSOUtils utils = new SSOUtils();
if (!utils.userExists(username)) {
String email = att != null ? (String) att.get() : "noemail";
utils.register("ldap", email);
}
return utils.getUser();
} catch (AuthenticationException e) {
return null;
} catch (NamingException e) {
return null;
} finally {
if (dir != null) {
try {
dir.close();
} catch (NamingException e) {
//close jndi context
}
}
}
}
Aggregations