use of app.hongs.HongsException in project HongsCORE by ihongs.
the class NaviMap method imports.
@Override
protected void imports() throws HongsException {
InputStream is;
String fn;
try {
fn = Core.CONF_PATH + File.separator + name + Cnst.NAVI_EXT + ".xml";
is = new FileInputStream(fn);
} catch (FileNotFoundException ex) {
fn = name.contains(".") || name.contains("/") ? name + Cnst.NAVI_EXT + ".xml" : "app/hongs/conf/" + name + Cnst.NAVI_EXT + ".xml";
is = this.getClass().getClassLoader().getResourceAsStream(fn);
if (is == null) {
throw new HongsException(0x10e0, "Can not find the config file '" + name + Cnst.NAVI_EXT + ".xml'.");
}
}
Element root;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder dbn = dbf.newDocumentBuilder();
Document doc = dbn.parse(is);
root = doc.getDocumentElement();
// 角色会话名称
NodeList list = root.getElementsByTagName("rsname");
if (list.getLength() != 0) {
session = list.item(0).getTextContent();
}
} catch (IOException ex) {
throw new HongsException(0x10e1, "Read '" + name + Cnst.NAVI_EXT + ".xml error'", ex);
} catch (SAXException ex) {
throw new HongsException(0x10e1, "Parse '" + name + Cnst.NAVI_EXT + ".xml error'", ex);
} catch (ParserConfigurationException ex) {
throw new HongsException(0x10e1, "Parse '" + name + Cnst.NAVI_EXT + ".xml error'", ex);
}
this.menus = new LinkedHashMap();
this.manus = new HashMap();
this.roles = new HashMap();
this.actions = new HashSet();
this.imports = new HashSet();
this.parse(root, this.menus, this.manus, this.roles, this.imports, this.actions, new HashSet());
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class LuceneRecord method init.
// ** 事务方法 **/
/**
* 初始化读操作
* @throws HongsException
*/
public void init() throws HongsException {
if (reader != null) {
return;
}
String path = getDataPath();
try {
// 索引目录不存在则先写入一个并删除
if (!(new File(path)).exists()) {
String id = Core.newIdentity();
Map rd = new HashMap();
rd.put(Cnst.ID_KEY, id);
addDoc(map2Doc(rd));
delDoc(id);
commit();
}
Directory dir = FSDirectory.open(Paths.get(path));
reader = DirectoryReader.open(dir);
finder = new IndexSearcher(reader);
} catch (IOException x) {
throw new HongsException.Common(x);
}
if (0 < Core.DEBUG && 4 != (4 & Core.DEBUG)) {
CoreLogger.trace("Open the lucene reader from " + getDataName());
}
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class LuceneRecord method getDoc.
public Document getDoc(String id) throws HongsException {
IndexSearcher ff = getFinder();
try {
Query qq = new TermQuery(new Term(Cnst.ID_KEY, id));
TopDocs tt = ff.search(qq, 1);
ScoreDoc[] hh = tt.scoreDocs;
if (0 != hh.length) {
return ff.doc(hh[0].doc);
} else {
return null;
}
} catch (IOException ex) {
throw new HongsException.Common(ex);
}
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class LuceneRecord method permit.
/**
* 确保操作合法
* @param rd
* @param ids
* @param ern
* @throws HongsException
*/
protected void permit(Map rd, Set ids, int ern) throws HongsException {
if (rd == null) {
throw new NullPointerException("rd can not be null");
}
if (ids == null || ids.isEmpty()) {
throw new NullPointerException("ids can not be empty");
}
Map wh = new HashMap();
if (rd.containsKey(Cnst.AR_KEY)) {
wh.put(Cnst.AR_KEY, rd.get(Cnst.AR_KEY));
}
if (rd.containsKey(Cnst.OR_KEY)) {
wh.put(Cnst.OR_KEY, rd.get(Cnst.OR_KEY));
}
if (wh.isEmpty()) {
return;
}
// 组织查询
wh.put(Cnst.ID_KEY, ids);
wh.put(Cnst.RB_KEY, Cnst.ID_KEY);
Set idz = new HashSet();
Loop rs = search(rd, 0, 0);
while (rs.hasNext()) {
Map ro = rs.next();
idz.add(ro.get(Cnst.ID_KEY).toString());
}
// 对比数量, 取出多余的部分作为错误消息抛出
if (ids.size() != idz.size()) {
Set zd = new HashSet(ids);
zd.removeAll(idz);
String er = zd.toString();
if (ern == 0x1096) {
throw new HongsException(ern, "Can not update by id: " + er);
} else if (ern == 0x1097) {
throw new HongsException(ern, "Can not delete by id: " + er);
} else {
throw new HongsException(ern, "Can not search by id: " + er);
}
}
}
use of app.hongs.HongsException in project HongsCORE by ihongs.
the class LuceneRecord method open.
/**
* 连接写数据库
* @throws HongsException
*/
public void open() throws HongsException {
if (writer != null && writer.isOpen()) {
return;
}
String path = getDataPath();
try {
IndexWriterConfig iwc = new IndexWriterConfig(getAnalyzer());
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
Directory dir = FSDirectory.open(Paths.get(path));
writer = new IndexWriter(dir, iwc);
} catch (IOException x) {
throw new HongsException.Common(x);
}
if (0 < Core.DEBUG && 4 != (4 & Core.DEBUG)) {
CoreLogger.trace("Open the lucene writer from " + getDataName());
}
}
Aggregations