use of io.github.ihongs.HongsExemption in project HongsCORE by ihongs.
the class ActionHelper method parseQuery.
// ** 工具方法 **/
/**
* 解析参数
* 用于处理查询串
* @param s
* @return
*/
public static final Map parseQuery(String s) {
Map<String, List<String>> a = new HashMap();
int j, i;
j = 0;
while (j < s.length()) {
// 查找键
i = j;
while (j < s.length() && s.charAt(j) != '=' && s.charAt(j) != '&') {
j++;
}
String k;
try {
k = s.substring(i, j);
k = URLDecoder.decode(k, "UTF-8");
} catch (UnsupportedEncodingException ex) {
throw new HongsExemption(1111, ex);
}
if (j < s.length() && s.charAt(j) == '=') {
j++;
}
// 查找值
i = j;
while (j < s.length() && s.charAt(j) != '&') {
j++;
}
String v;
try {
v = s.substring(i, j);
v = URLDecoder.decode(v, "UTF-8");
} catch (UnsupportedEncodingException ex) {
throw new HongsExemption(1111, ex);
}
if (j < s.length() && s.charAt(j) == '&') {
j++;
}
Dict.setParam(a, v, k);
}
return a;
}
use of io.github.ihongs.HongsExemption in project HongsCORE by ihongs.
the class CommitRunner method run.
public static void run(Run run, Core core) throws HongsException, HongsExemption {
// 外部已指定则不再处理
if (core.isset(Cnst.REFLUX_MODE)) {
try {
// 执行
run.run();
} catch (Throwable ex) {
if (ex instanceof HongsException) {
throw (HongsException) ex;
} else if (ex instanceof HongsExemption) {
throw (HongsExemption) ex;
}
throw new HongsException(ex);
}
return;
}
try {
// 开启
core.set(Cnst.REFLUX_MODE, true);
Hub crux = new Hub(core);
Core.THREAD_CORE.set(crux);
for (Object o : crux.values()) {
if (o instanceof IReflux) {
((IReflux) o).begin();
}
}
try {
// 执行
run.run();
// 提交
for (Object o : crux.values().toArray()) {
if (o instanceof IReflux) {
((IReflux) o).commit();
}
}
} catch (Throwable ex) {
// 回滚
for (Object o : crux.values().toArray()) {
if (o instanceof IReflux) {
((IReflux) o).revert();
}
}
if (ex instanceof HongsException) {
throw (HongsException) ex;
} else if (ex instanceof HongsExemption) {
throw (HongsExemption) ex;
}
// 其他异常需包裹
throw new HongsException(1109, ex);
}
} finally {
// 重置
core.unset(Cnst.REFLUX_MODE);
Core.THREAD_CORE.set(core);
}
}
use of io.github.ihongs.HongsExemption in project HongsCORE by ihongs.
the class Loop method next.
@Override
public Map next() {
// 判断是否到达末尾
if (!hasNext()) {
this.close();
return null;
}
il = null;
// 获取当前字段类型
try {
// getMetaData();
getTypeDict();
} catch (HongsException ex) {
this.close();
throw ex.toExemption();
}
// 获取行内每列数据
try {
int i = 0;
Map<String, Object> row = new LinkedHashMap();
if (ib) {
for (Map.Entry<String, Class> et : td.entrySet()) {
// row.put(et.getKey() , rs.getString(++ i /* No Type */ ));
Dict.put(row, rs.getString(++i), (Object[]) et.getKey().split("\\."));
}
} else {
for (Map.Entry<String, Class> et : td.entrySet()) {
// row.put(et.getKey() , rs.getObject(++ i, et.getValue()));
Dict.put(row, rs.getObject(++i), (Object[]) et.getKey().split("\\."));
}
}
return row;
} catch (SQLException ex) {
this.close();
throw new HongsExemption(1153, ex);
}
}
use of io.github.ihongs.HongsExemption in project HongsCORE by ihongs.
the class Default method verify.
@Override
public Object verify(Value watch) throws Wrong, Wrongs {
Object value = watch.get();
Object force = getParam("deforce");
if ("create".equals(force)) {
if (watch.isUpdate() == true) {
return BLANK;
}
} else if ("update".equals(force)) {
if (watch.isUpdate() == false) {
return BLANK;
}
} else if ("always".equals(force) == false) {
// 非 always
if ("blanks".equals(force) == false) {
/**
* 一般情况
* 空串空值将设为默认值
* 更新时没赋值将会跳过
*/
if (value != null && !"".equals(value)) {
return value;
}
if (watch.isUpdate() && !watch.isDefined()) {
return BLANK;
}
} else {
/**
* 留空模式
* 空串空值将设为空对象
* 更新时没赋值也会跳过
*/
if (value != null && !"".equals(value)) {
return value;
}
if (watch.isUpdate() && !watch.isDefined()) {
return BLANK;
} else {
return null;
}
}
}
Object val = getParam("default");
if (null == val || !(val instanceof String)) {
return val;
}
String def = ((String) val).trim();
// 需等号开头时, 用两个表一个
if (def.startsWith("==")) {
return def.substring(1);
}
// 应用属性
if (def.startsWith("=#")) {
return Core.getInstance(ActionHelper.class).getAttribute(def.substring(2));
}
// 会话属性
if (def.startsWith("=$")) {
return Core.getInstance(ActionHelper.class).getSessibute(def.substring(2));
}
if (def.startsWith("=%")) {
// 新唯一ID
if (def.equals("=%id")) {
return Core.newIdentity();
}
// 空或丢弃
if (def.equals("=%null")) {
return null;
}
if (def.equals("=%void")) {
return BLANK;
}
// 动作选项
if (def.equals("=%zone")) {
return Core.ACTION_ZONE.get();
}
if (def.equals("=%lang")) {
return Core.ACTION_LANG.get();
}
if (def.equals("=%addr")) {
return Core.CLIENT_ADDR.get();
}
// 默认时间
Matcher mat = NOW.matcher(def);
if (mat.matches()) {
Date now = new Date();
String flag = mat.group(1);
String plus = mat.group(2);
if (flag.length() == 4) {
// time 字串长度
now.setTime(Core.ACTION_TIME.get());
}
if (plus != null) {
Long msc = Long.valueOf(plus.substring(1));
if ("+".equals(plus.substring(0, 1))) {
now.setTime(now.getTime() + msc);
} else {
now.setTime(now.getTime() - msc);
}
}
return now;
}
}
if (def.startsWith("=@")) {
// 别名字段, 通常用于截取字串, 清理 HTML
if (def.startsWith("=@alias:")) {
return alias(watch, def.substring(8));
}
// 组合字段
if (def.startsWith("=@merge:")) {
return merge(watch, def.substring(8));
}
// 计数字段
if (def.startsWith("=@count:")) {
return count(watch, def.substring(8));
}
// 其他计算
if (def.startsWith("=@max:")) {
return max(watch, def.substring(6));
}
if (def.startsWith("=@min:")) {
return min(watch, def.substring(6));
}
if (def.startsWith("=@sum:")) {
return sum(watch, def.substring(6));
}
if (def.startsWith("=@avg:")) {
return avg(watch, def.substring(6));
}
// 自定方法
try {
String c, p;
int i = def.indexOf(':');
if (i != -1) {
c = def.substring(2, i);
p = def.substring(1 + i);
} else {
c = def.substring(2);
p = "";
}
return ((Def) Core.getInstance(c)).def(watch, p);
} catch (HongsExemption | ClassCastException e) {
throw new HongsExemption(e);
}
}
return val;
}
use of io.github.ihongs.HongsExemption in project HongsCORE by ihongs.
the class IsFile method encode.
/**
* 仅对 URL 的文件名部分进行编码
* @param name
* @return
*/
private String encode(String name) {
String path;
int p = name.lastIndexOf("/");
if (p != -1) {
p += 1;
path = name.substring(0, p);
name = name.substring(p);
} else {
path = "";
}
try {
name = URLEncoder.encode(name, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new HongsExemption(e);
}
name = name.replace("+", "%20");
return path + name;
}
Aggregations