📄 querybuilderutil.java
字号:
package com.esri.solutions.jitk.web.tasks.query.querybuilder;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.log4j.Logger;
import com.esri.adf.web.ags.data.AGSMapFunctionality;
import com.esri.adf.web.ags.data.AGSMapResource;
import com.esri.adf.web.aims.data.AIMSMapFunctionality;
import com.esri.adf.web.aims.data.AIMSMapResource;
import com.esri.adf.web.data.WebLayerInfo;
import com.esri.adf.web.data.query.PredefinedQueryCriteria;
import com.esri.adf.web.data.query.QueryResult;
import com.esri.adf.web.data.query.WebQuery;
import com.esri.aims.mtier.model.map.Layers;
import com.esri.arcgisws.MapLayerInfo;
import com.esri.solutions.jitk.web.wfs.data.WFSMapResource;
public class QueryBuilderUtil {
private static Logger logger = Logger.getLogger(QueryBuilderUtil.class.getName());
public static String checkWhereClause(Object resource, String sql){
try {
if(resource instanceof AIMSMapResource) {
sql = sql.replaceAll("&", "&s;");
sql = sql.replaceAll("\"", """);
sql = sql.replaceAll("'", "'");
sql = sql.replaceAll("<","<");
sql = sql.replaceAll(">", ">");
return sql;
}
} catch(Exception e) {
logger.error("Unable to check where clause", e);
}
return sql;
}
public static String findLayerName(Object resource, String lyrId){
try {
String layerName = null;
if(resource instanceof AIMSMapResource) {
AIMSMapResource aimsMapResource = (AIMSMapResource)resource;
AIMSMapFunctionality aimsMapFunc = (AIMSMapFunctionality)(aimsMapResource).getFunctionality("map");
Layers aimsLayers = aimsMapFunc.getMap().getLayers();
for(int i=0; i<aimsLayers.getCount(); i++) {
if(i == Integer.parseInt(lyrId)) {
layerName = aimsLayers.item(i).getName();
break;
}
}
}
if(resource instanceof AGSMapResource){
AGSMapResource agsMapResource = (AGSMapResource)resource;
AGSMapFunctionality agsMapFunc = (AGSMapFunctionality)(agsMapResource).getFunctionality("map");
MapLayerInfo mapLayer = agsMapFunc.getLayerInfo(Integer.parseInt(lyrId));
layerName = mapLayer.getName();
}
return layerName;
} catch(Exception e) {
logger.error("Unable to find layer name", e);
}
return null;
}
public static String findLayerIndex(Object resource, String layerName){
String index = null;
if(resource instanceof AIMSMapResource) {
AIMSMapResource aimsMapResource = (AIMSMapResource)resource;
AIMSMapFunctionality aimsMapFunc = (AIMSMapFunctionality)(aimsMapResource).getFunctionality("map");
Layers aimsLayers = aimsMapFunc.getMap().getLayers();
for(int i=0; i<aimsLayers.getCount(); i++) {
if(aimsLayers.item(i).getName().equals(layerName)) {
index = Integer.toString(i);
break;
}
}
} else if(resource instanceof AGSMapResource) {
AGSMapResource agsMapResource = (AGSMapResource)resource;
AGSMapFunctionality agsMapFunc = (AGSMapFunctionality)(agsMapResource).getFunctionality("map");
MapLayerInfo[] mapLayers = agsMapFunc.getLayerInfos();
for(MapLayerInfo mlInfo : mapLayers){
if (mlInfo.isIsFeatureLayer() && mlInfo.getName().equals(layerName)){
index = Integer.toString(mlInfo.getLayerID());
break;
}
}
} else if(resource instanceof WFSMapResource) {
WFSMapResource wfsResource = (WFSMapResource) resource;
int webLayerInfoIndex = wfsResource.getLayerInfoIndexFromLayerName(layerName);
if (webLayerInfoIndex != -1) {
index = Integer.toString(webLayerInfoIndex);
}
}
return index;
}
@SuppressWarnings("unchecked")
public static LinkedHashMap<String, String> getSampleList(WebQuery webQuery, String layerName, String attrName, String whereClause, int maxSampleRecords) {
LinkedHashMap<String, String> sampleList = new LinkedHashMap<String, String>();
try {
if(layerName == null) return sampleList;
PredefinedQueryCriteria pqc = new PredefinedQueryCriteria();
pqc.setMaxRecordCount(maxSampleRecords);
pqc.setWhereClause(whereClause);
List<WebLayerInfo> wlList = QueryBuilderTaskUtil.getWebLayerInfoList(webQuery.getQueryLayers(), layerName);
List<QueryResult> searchResults = webQuery.query(pqc, wlList);
SortedMap<String, String> sortList = new TreeMap<String, String>();
for(int i = 0; i < searchResults.size(); i++) {
QueryResult result = (QueryResult)searchResults.get(i);
for(Iterator it = result.getDetails().entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry)it.next();
if(entry.getKey().toString().equalsIgnoreCase(attrName)) {
Object value = entry.getValue();
if(value != null) {
sortList.put(value.toString(), value.toString());
}
if(sortList.size() >= maxSampleRecords) break;
}
}
}
if(sortList.size() > 0) {
for(Iterator<Map.Entry<String, String>> it = sortList.entrySet().iterator(); it.hasNext();) {
Map.Entry<String, String> entry = (Map.Entry<String, String>) it.next();
sampleList.put((String)entry.getKey(), (String)entry.getValue());
}
}
pqc = null;
searchResults = null;
return sampleList;
} catch(Exception e) {
logger.error("Unable to get sample list", e);
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -