Search in sources :

Example 21 with HongsException

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());
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) LinkedHashMap(java.util.LinkedHashMap) HongsException(app.hongs.HongsException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 22 with HongsException

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());
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HongsException(app.hongs.HongsException) IOException(java.io.IOException) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Example 23 with HongsException

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);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) HongsException(app.hongs.HongsException) Term(org.apache.lucene.index.Term) IOException(java.io.IOException) ScoreDoc(org.apache.lucene.search.ScoreDoc)

Example 24 with HongsException

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);
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) FormSet(app.hongs.action.FormSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HongsException(app.hongs.HongsException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 25 with HongsException

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());
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) HongsException(app.hongs.HongsException) IOException(java.io.IOException) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Aggregations

HongsException (app.hongs.HongsException)89 Map (java.util.Map)42 HashMap (java.util.HashMap)34 IOException (java.io.IOException)21 ArrayList (java.util.ArrayList)15 HashSet (java.util.HashSet)15 LinkedHashMap (java.util.LinkedHashMap)15 Set (java.util.Set)15 List (java.util.List)13 File (java.io.File)11 SQLException (java.sql.SQLException)10 FileNotFoundException (java.io.FileNotFoundException)9 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)9 PreparedStatement (java.sql.PreparedStatement)8 Iterator (java.util.Iterator)8 DocumentBuilder (javax.xml.parsers.DocumentBuilder)8 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)8 HongsExpedient (app.hongs.HongsExpedient)7 FormSet (app.hongs.action.FormSet)7 Table (app.hongs.db.Table)7