📄 filterutil.java
字号:
package com.esri.solutions.jitk.web.tasks.filter;
import java.util.LinkedHashMap;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import java.util.ArrayList;
import java.util.Map;
import java.util.List;
import java.util.Iterator;
import java.util.SortedMap;
import java.util.TreeMap;
import com.esri.adf.web.data.GISResource;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebLayerInfo;
import com.esri.adf.web.data.query.PredefinedQueryCriteria;
import com.esri.adf.web.data.query.WebQuery;
import com.esri.adf.web.data.query.QueryResult;
import com.esri.adf.web.aims.data.AIMSMapResource;
import com.esri.adf.web.ags.data.AGSMapResource;
import com.esri.adf.web.ags.data.AGSMapFunctionality;
import com.esri.arcgisws.MapLayerInfo;
import com.esri.adf.web.aims.data.AIMSMapFunctionality;
import com.esri.aims.mtier.model.map.Layers;
/**
* MVS-045: Filter Support Class.
*/
public class FilterUtil{
private static Logger logger = Logger.getLogger(FilterUtil.class.getName());
private static final int maxSampleRecords = 100;
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.log(Priority.ERROR, "Unable to find layer name", e);
}
return null;
}
@SuppressWarnings("unchecked")
public static LinkedHashMap<String, String> getSampleList(WebQuery webQuery, String layerName, String attrName){
LinkedHashMap<String, String> sampleList = new LinkedHashMap<String, String>();
try
{
if (layerName == null) return sampleList;
String sql = "1 = 1";
PredefinedQueryCriteria pqc = new PredefinedQueryCriteria();
pqc.setMaxRecordCount(maxSampleRecords);
pqc.setWhereClause(sql);
List<QueryResult> searchResults = webQuery.query(pqc, FilterUtil.getWebLayerInfoList(webQuery.getQueryLayers(), layerName));
SortedMap sortList = new TreeMap();
for (int i = 0; i < searchResults.size(); i++) {
QueryResult result = (QueryResult)searchResults.get(i);
Map<String, ?> flds = result.getDetails();
Iterator it = flds.entrySet().iterator();
while (it.hasNext()){
Map.Entry entry = (Map.Entry)it.next();
String key = (String)entry.getKey();
if (key.equalsIgnoreCase(attrName)){
String value = "";
if (entry.getValue() instanceof Integer){
Integer valInt = (Integer)entry.getValue();
value = valInt.toString();
}
if (entry.getValue() instanceof String){
value = (String)entry.getValue();
}
if (entry.getValue() instanceof Double){
Double valDbl = (Double)entry.getValue();
value = valDbl.toString();
}
if (entry.getValue() instanceof Long){
Long valLong = (Long)entry.getValue();
value = valLong.toString();
}
sortList.put(value, value);
if (sortList.size() >= maxSampleRecords) break;
}
}
}
if (sortList.size() > 0){
Iterator it = sortList.entrySet().iterator();
while(it.hasNext()){
Map.Entry entry = (Map.Entry)it.next();
sampleList.put((String)entry.getKey(), (String)entry.getValue());
}
}
pqc = null;
searchResults = null;
}catch(Exception e){
logger.log(Priority.ERROR, "Unable to get sample list", e);
}
return sampleList;
}
public static List<WebLayerInfo> getWebLayerInfoList(List<WebLayerInfo> layerList, String webLayerName){
List<WebLayerInfo> list = null;
if(layerList!=null && layerList.size()>0) {
list = new ArrayList<WebLayerInfo>(1);
int index = 0;
for(Iterator<WebLayerInfo> iter = layerList.iterator(); iter.hasNext();index++) {
WebLayerInfo layer = (WebLayerInfo)iter.next();
if(layer.getName().equalsIgnoreCase(webLayerName)) {
list.add(layer);
return list;
}
}
}
return list;
}
public static LinkedHashMap<String, String> getLayerList(WebContext context){
try{
LinkedHashMap<String, String> newLayerList = new LinkedHashMap<String, String>();
if(context != null){
Map<String, GISResource> resources = context.getResources();
Object resource;
for(Iterator<String> iter = resources.keySet().iterator(); iter.hasNext();){
String id = (String)iter.next();
resource = resources.get(id);
if (resource instanceof AGSMapResource){
AGSMapResource tempAgsResource = (AGSMapResource)resource;
AGSInternetProxy agsProxy = new AGSInternetProxy();
LinkedHashMap<String, String> layerList = agsProxy.getServiceLayerList(tempAgsResource, id);
newLayerList.putAll(layerList);
}
}
}
return newLayerList;
}
catch(Exception e){
logger.log(Priority.ERROR, "Unable to get layer list", e);
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -