use of app.hongs.HongsException in project HongsCORE by ihongs.
the class SystemCmdlet method runCmd.
private static void runCmd(Date dt, File fo, Logger lg) throws HongsException {
Document doc;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder dbn = dbf.newDocumentBuilder();
doc = dbn.parse(fo);
} catch (ParserConfigurationException ex) {
throw new HongsException.Common(ex);
} catch (SAXException ex) {
throw new HongsException.Common(ex);
} catch (IOException ex) {
throw new HongsException.Common(ex);
}
NodeList l = doc.getChildNodes();
for (int i = 0; i < l.getLength(); i++) {
Node n = l.item(i);
if (n.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element e = (Element) n;
String t = e.getTagName();
if ("cmdlet".equals(t)) {
runCmd(e, dt, lg);
} else if ("action".equals(t)) {
runAct(e, dt, lg);
} else {
throw new HongsException.Common("Wrong tagName: " + t);
}
}
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class TableDeff method syncSlaver.
/**
* 同步从表结构
* @param slaver
* @param delExtraFields 删除多余的字段
* @throws app.hongs.HongsException
*/
public void syncSlaver(Table slaver, boolean delExtraFields) throws HongsException {
List<String> sqls = this.deffSlaver(slaver, delExtraFields);
DB sdb = slaver.db;
sdb.begin();
try {
for (String sql : sqls) {
sdb.execute(sql);
}
sdb.commit();
} catch (HongsException ex) {
sdb.revert();
throw ex;
}
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class SessFilter method doFilter.
@Override
public void doFilter(ServletRequest req, ServletResponse rsp, FilterChain flt) throws ServletException, IOException {
HttpServletRequest raq = (HttpServletRequest) req;
HttpServletResponse rzp = (HttpServletResponse) rsp;
/**
* 对于嵌套相同过滤, 不在内部重复执行;
* 如外部设置了忽略, 则跳过忽略的路径.
*/
if ((inside != null && Synt.declare(req.getAttribute(inside), false)) || (ignore != null && ignore.ignore(ActionDriver.getRecentPath(raq)))) {
flt.doFilter(req, rsp);
return;
}
try {
raq = new SessAccess(raq, rzp, this);
raq.setAttribute(inside, true);
flt.doFilter(raq, rzp);
} finally {
raq.removeAttribute(inside);
// 最终任务完成后对会话进行保存
HttpSession ses = raq.getSession(false);
if (null != ses && ses instanceof Sesion) {
try {
((Sesion) ses).close();
} catch (HongsException ex) {
throw new ServletException(ex);
}
}
}
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class FileAction method update.
@Override
@Action("update")
public void update(ActionHelper helper) throws HongsException {
CoreLocale lang = CoreLocale.getInstance("manage");
String path = helper.getParameter("path");
String dist = helper.getParameter("dist");
String text = helper.getParameter("text");
File file;
File dizt;
if (dist != null && dist.equals(path)) {
dist = null;
}
if (path == null) {
helper.fault(lang.translate("core.manage.file.path.required"));
return;
}
path = realPath(path);
if (path == null) {
helper.fault(lang.translate("core.manage.file.path.is.error"));
return;
}
file = new File(path);
if (!file.exists()) {
helper.fault(lang.translate("core.manage.file.path.is.not.exist"));
return;
}
if (isDenyFile(file)) {
helper.fault(lang.translate("core.manage.file.interdicted"));
return;
}
// 改名移动
if (dist != null) {
dist = realPath(dist);
if (dist == null) {
helper.fault(lang.translate("core.manage.file.path.is.error"));
return;
}
dizt = new File(dist);
if (dizt.exists()) {
helper.fault(lang.translate("core.manage.file.dist.is.exist"));
return;
}
if (isDenyFile(file)) {
helper.fault(lang.translate("core.manage.file.interdicted"));
return;
}
if (!file.renameTo(dizt)) {
helper.fault(lang.translate("core.manage.file.rename.failed"));
return;
}
if (text == null) {
return;
}
file = dizt;
}
// 写入文件
try {
saveFile(file, text);
} catch (Exception ex) {
CoreLogger.error(ex);
helper.fault(lang.translate("core.manage.file.update.failed"));
return;
}
helper.reply("");
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class Remote method buildPost.
/**
* 构建请求实体
*
* 采用键值对的数据结构,
* 当一个键对应多个值时,
* 值可以是数组或者集合.
*
* @param data
* @return
* @throws HongsException
*/
public static HttpEntity buildPost(Map<String, Object> data) throws HongsException {
List<NameValuePair> pair = new ArrayList();
for (Map.Entry<String, Object> et : data.entrySet()) {
String n = et.getKey();
Object o = et.getValue();
if (o == null) {
// continue;
} else if (o instanceof Object[]) {
// 针对 Servlet 参数格式
for (Object v : (Object[]) o) {
String s = String.valueOf(v);
pair.add(new BasicNameValuePair(n, s));
}
} else if (o instanceof Collection) {
// 针对 WebSocket 的格式
for (Object v : (Collection) o) {
String s = String.valueOf(v);
pair.add(new BasicNameValuePair(n, s));
}
} else {
String s = String.valueOf(o);
pair.add(new BasicNameValuePair(n, s));
}
}
try {
return new UrlEncodedFormEntity(pair, HTTP.UTF_8);
} catch (UnsupportedEncodingException ex) {
throw new HongsException.Common(ex);
}
}
Aggregations