XPath xpath = XPathFactory.newInstance().newXPath();
// catalog configuration
Node ndCat = (Node) xpath.evaluate("catalog", root, XPathConstants.NODE);
if (ndCat != null) {
CatalogConfiguration cfg = appConfig.getCatalogConfiguration();
cfg.getParameters().clear();
ImsService publish = cfg.getArcImsCatalog().getPublishService();
ImsService browse = cfg.getArcImsCatalog().getBrowseService();
cfg.setTablePrefix(Val.chkStr(xpath.evaluate("@gptTablePrefix", ndCat),"GPT_"));
cfg.setMvsTablePrefix(Val.chkStr(xpath.evaluate("@mvsTablePrefix", ndCat),"MVS_"));
publish.setServerUrl(xpath.evaluate("@metadataServerUrl", ndCat));
publish.setServiceName(Val.chkStr(xpath.evaluate("@metadataServerPublishService",ndCat), "GPT_Publish_Metadata"));
publish.setTimeoutMillisecs(Val.chkInt(xpath.evaluate("@metadataServerTimeoutMillisecs", ndCat), 0));
browse.setServerUrl(publish.getServerUrl());
browse.setServiceName(Val.chkStr(xpath.evaluate("@metadataServerBrowseService", ndCat),"GPT_Browse_Metadata"));
browse.setTimeoutMillisecs(publish.getTimeoutMillisecs());
// additional parameters
populateParameters(cfg.getParameters(), ndCat);
//load dcat fields
if(cfg.getParameters().containsKey("dcat.mappings")){
loadDcatMappings(cfg.getDcatSchemas(),cfg.getParameters().get("dcat.mappings").getValue());
}
// parse http timeouts
String connectionTimeout = cfg.getParameters().getValue("httpClientRequest.connectionTimeout");
String responseTimeout = cfg.getParameters().getValue("httpClientRequest.responseTimeout");
// set http timeouts
cfg.setConnectionTimeMs((int)parsePeriod(connectionTimeout, HttpClientRequest.DEFAULT_CONNECTION_TIMEOUT).getValue());
cfg.setResponseTimeOutMs((int)parsePeriod(responseTimeout , HttpClientRequest.DEFAULT_RESPONSE_TIMEOUT).getValue());
}
// search configuration
Node ndSearch = (Node) xpath.evaluate("catalog/search", root,
XPathConstants.NODE);
SearchConfig sCfg = appConfig.getCatalogConfiguration().getSearchConfig();
sCfg.setSearchConfigNode(ndSearch);
if (ndSearch != null) {
sCfg.setResultsReviewsShown(
Val.chkStr(xpath.evaluate("@searchResultsReviewsShown", ndSearch)));
sCfg.setResultsPerPage(xpath.evaluate("@searchResultsPerPage", ndSearch));
sCfg.setMaxSavedSearches(xpath.evaluate("@maxSavedSearches", ndSearch));
sCfg.setCswProfile(
Val.chkStr(xpath.evaluate("@cswServletUrlProfile", ndSearch),"urn:ogc:CSW:2.0.2:HTTP:OGCCORE:ESRI:GPT"));
sCfg.setSearchUri(xpath.evaluate("@cswServletUrl", ndSearch));
sCfg.setTimeOut(xpath.evaluate("@searchTimeoutMillisecs", ndSearch));
sCfg.setDistributedSearchMaxSelectedSites(
Val.chkStr(xpath.evaluate("@distributedSearchMaxSelectedSites",
ndSearch)));
sCfg.setDistributedSearchTimeoutMillisecs(
Val.chkStr(xpath.evaluate("@distributedSearchTimeoutMillisecs",
ndSearch)));
sCfg.setAllowExternalSearch(Val.chkBool(xpath.evaluate(
"@allowExternalSiteSearch", ndSearch), false));
sCfg.setAllowTemporalSearch(Val.chkBool(xpath.evaluate("@allowTemporalSearch",ndSearch),false));
sCfg.setJsfSuffix(Val.chkStr(xpath.evaluate(
"@jsfSuffix", ndSearch)));
sCfg.setGptToCswXsltPath(xpath.evaluate("@gpt2cswXslt", ndSearch));
sCfg.setMapViewerUrl(Val.chkStr(xpath.evaluate("@mapViewerUrl", ndSearch),""));
sCfg.validate();
}
NodeList nodes = (NodeList) xpath.evaluate(
"catalog/search/repositories/repository",
root, XPathConstants.NODESET);
NodeList nodeList = nodes;
LinkedHashMap<String, Map<String, String>> sFactory =
new LinkedHashMap<String, Map<String, String>>();
Map<String, String> attributes =
new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
/*attributes.put("key", "local");
attributes.put("class", "com.esri.gpt.catalog.search.SearchEngineLocal");
attributes.put("resourceKey", "catalog.search.searchSite.defaultsite");
attributes.put("labelResourceKey", "catalog.search.searchSite.defaultsite");
attributes.put("abstractResourceKey", "catalog.search.searchSite.defaultsite.abstract");
sFactory.put("local", attributes);*/
for (int i = 0; nodeList != null && i < nodeList.getLength(); i++) {
ndSearch = nodeList.item(i);
attributes =
new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
NamedNodeMap nnm = ndSearch.getAttributes();
for (int j = 0; nnm != null && j < nnm.getLength(); j++) {
Node nd = nnm.item(j);
String key = Val.chkStr(nd.getNodeName());
String value = Val.chkStr(nd.getNodeValue());
attributes.put(key, value);
if (key.equalsIgnoreCase("RESOURCEKEY")) {
attributes.put("RESOURCEKEY", value);
}
if (key.equalsIgnoreCase("labelResourceKey")) {
attributes.put("labelResourceKey", value);
}
if (key.equalsIgnoreCase("abstractResourceKey")) {
attributes.put("abstractResourceKey", value);
}
}
NodeList params = (NodeList) xpath.evaluate("parameter",
ndSearch, XPathConstants.NODESET);
for (int k = 0; params != null && k < params.getLength(); k++) {
String key = xpath.evaluate("@key", params.item(k));
String value = xpath.evaluate("@value", params.item(k));
attributes.put(Val.chkStr(key), Val.chkStr(value));
}
String key = Val.chkStr(xpath.evaluate("@key", ndSearch));
sFactory.put(key, attributes);
}
sCfg.setSearchFactoryRepos(sFactory);
// Mapviewer
ArrayList<MapViewerConfigs> mapViewerConfigs =
new ArrayList<MapViewerConfigs>();
nodes = (NodeList) xpath.evaluate("catalog/mapViewer/instance", root,
XPathConstants.NODESET);
for (int j = 0; nodes != null && j < nodes.getLength(); j++) {
MapViewerConfigs mvConfigs = new MapViewerConfigs();
Node nd = nodes.item(j);
mvConfigs.setClassName(Val.chkStr(xpath.evaluate("@className", nd),"com.esri.gpt.catalog.search.MapViewerFlex"));
mvConfigs.setUrl(xpath.evaluate("@url", nd));
NodeList pNodeList = (NodeList) xpath.evaluate("parameter", nd, XPathConstants.NODESET);
for (int k = 0; pNodeList != null && k < pNodeList.getLength(); k++) {
String key = xpath.evaluate("@key", pNodeList.item(k));
String value = xpath.evaluate("@value", pNodeList.item(k));
if (key != null || value != null) {
mvConfigs.addParameter(key, value);
}
}
mapViewerConfigs.add(mvConfigs);
}
sCfg.setMapViewerInstances(mapViewerConfigs);
// Lucene configuration
Node ndLucene = (Node) xpath.evaluate("catalog/lucene", root, XPathConstants.NODE);
if (ndLucene != null) {
CatalogConfiguration cfg = appConfig.getCatalogConfiguration();
cfg.getLuceneConfig().setIndexLocation(
xpath.evaluate("@indexLocation", ndLucene));
cfg.getLuceneConfig().setWriteLockTimeout(
Val.chkInt(xpath.evaluate("@writeLockTimeout", ndLucene), -1));
cfg.getLuceneConfig().setUseNativeFSLockFactory(
Val.chkStr(xpath.evaluate("@useNativeFSLockFactory", ndLucene)).equalsIgnoreCase("true"));
cfg.getLuceneConfig().setAnalyzerClassName(
xpath.evaluate("@analyzerClassName", ndLucene));
cfg.getLuceneConfig().setUseConstantScoreQuery(
Val.chkBool(xpath.evaluate("@useConstantScoreQuery", ndLucene), false));
cfg.getLuceneConfig().setMaxClauseCount(
Val.chkInt(xpath.evaluate("@maxClauseCount", ndLucene), BooleanQuery.getMaxClauseCount()));
ParserAdaptorInfos infos = new ParserAdaptorInfos();
NodeList ndLstProxies = (NodeList) xpath.evaluate("adaptor", ndLucene,
XPathConstants.NODESET);
for (int i = 0; i < ndLstProxies.getLength(); i++) {
Node ndProxy = ndLstProxies.item(i);
String proxyName = xpath.evaluate("@name", ndProxy);
String proxyClassName = xpath.evaluate("@className", ndProxy);
ParserAdaptorInfo info = new ParserAdaptorInfo();
info.setName(proxyName);
info.setClassName(proxyClassName);
NodeList ndListProps = (NodeList) xpath.evaluate("attribute", ndProxy,
XPathConstants.NODESET);
for (int p = 0; p < ndListProps.getLength(); p++) {
Node ndProp = ndListProps.item(p);
String key = xpath.evaluate("@key", ndProp);
String value = xpath.evaluate("@value", ndProp);
info.getAttributes().set(key, value);
}
infos.add(info);
}
cfg.getLuceneConfig().setParserProxies(infos.createParserProxies());
NodeList ndObservers = (NodeList) xpath.evaluate("observer", ndLucene, XPathConstants.NODESET);
for (Node ndObserver: new NodeListAdapter(ndObservers)) {
LuceneIndexObserverInfo info = new LuceneIndexObserverInfo();
info.setClassName(Val.chkStr(xpath.evaluate("@className", ndObserver)));
NodeList ndListProps = (NodeList) xpath.evaluate("attribute", ndObserver, XPathConstants.NODESET);
for (Node ndAttribute: new NodeListAdapter(ndListProps)) {
String key = xpath.evaluate("@key", ndAttribute);
String value = xpath.evaluate("@value", ndAttribute);
info.getAttributes().set(key, value);
}
LuceneIndexObserver observer = info.createObserver();
if (observer!=null) {
cfg.getLuceneConfig().getObservers().add(observer);
}
}
}