19 package org.turro.jpa.search;
22 import java.io.IOException;
23 import java.io.Serializable;
24 import java.util.LinkedHashMap;
25 import java.util.List;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import org.turro.string.Strings;
29 import org.jdom.Document;
30 import org.jdom.Element;
31 import org.jdom.JDOMException;
32 import org.jdom.input.SAXBuilder;
33 import org.turro.elephant.context.ElephantContext;
39 public class DaoSearch extends LinkedHashMap<String, DaoSearchKey> implements Serializable {
41 protected String
sclass, root,
template;
65 private void readItems(String name) {
66 File confFile =
new File(
ElephantContext.
getRealPath(
"/WEB-INF/elephant/conf/dao-search" + name.replaceAll(
"\\/",
"-") +
".xml"));
67 if(confFile.exists()) {
70 SAXBuilder builder =
new SAXBuilder();
72 doc = builder.build(confFile);
73 conf = doc.getRootElement();
75 addItems(conf.getChild(
"dao-search"));
77 }
catch (JDOMException | IOException ex) {
78 Logger.getLogger(
DaoSearch.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
83 private void addItems(Element daoSearch) {
85 if(daoSearch !=
null) {
86 sclass = daoSearch.getAttributeValue(
"class");
87 root = daoSearch.getAttributeValue(
"root");
88 template = daoSearch.getAttributeValue(
"template");
89 for(Element item : (List<Element>) daoSearch.getChildren()) {
90 String name = item.getAttributeValue(
"name");
91 if(!Strings.isBlank(name)) {
92 String type = item.getAttributeValue(
"type");
93 if(Strings.isBlank(type)) {
96 DaoSearchKey dsk =
new DaoSearchKey(name, type);
100 name =
"#" + item.getName() + count++;
101 DaoSearchKey dsk =
new DaoSearchKey(name,
null);
static String getRealPath(String path)