📄 querybuildertaskwfsutil.java
字号:
package com.esri.solutions.jitk.web.tasks.query.querybuilder;
import com.esri.adf.web.data.WebLayerInfo;
import com.esri.adf.web.data.query.PredefinedQueryCriteria;
import com.esri.adf.web.data.query.QueryFunctionality;
import com.esri.adf.web.data.query.QueryResult;
import com.esri.adf.web.data.query.WebQuery;
import com.esri.solutions.jitk.datasources.ogc.wfs.FeatureElement;
import com.esri.solutions.jitk.datasources.ogc.wfs.FeatureType;
import com.esri.solutions.jitk.web.wfs.data.WFSMapResource;
import com.esri.solutions.jitk.web.wfs.data.WFSWebLayerInfo;
import com.esri.solutions.jitk.web.wfs.data.query.WFSPredefinedQueryCriteriaHandler;
import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
public class QueryBuilderTaskWfsUtil {
private static final Logger _logger = Logger.getLogger(QueryBuilderTaskWfsUtil.class);
// attributeList is a LinkedHashMap<String, String>
// key = <Field Name>!<EsriFieldType>
// value = <Field Alias>
public static LinkedHashMap<String, String> getWfsFieldList(
WFSMapResource resource, int layerId) {
LinkedHashMap<String, String> fieldList = new LinkedHashMap<String, String>();
WFSMapResource wfsMapResource = (WFSMapResource) resource;
WFSWebLayerInfo layers = wfsMapResource.getLayerInfoByIndex(layerId);
FeatureType ft = layers.getFeatureType();
List<FeatureElement> feList = ft.getFeatureElements();
FeatureElement shapeFeatureElement = ft.getShapeElement();
for (FeatureElement fe : feList) {
if (fe != shapeFeatureElement) {
fe.getName();
fe.getXsdType();
String key = fe.getName() + "!" +
getFieldType(fe.getXsdType());
String value = fe.getName();
fieldList.put(key, value);
}
}
return fieldList;
}
protected static int getFieldType(String xsdType) {
final String stringType = "xsd:string";
int fieldType = 4;
if (xsdType.equalsIgnoreCase(stringType)) {
fieldType = 12;
}
return fieldType;
}
public static LinkedHashMap<String, String> getServiceLayerList(
WFSMapResource wfsMapResource, String resourceId,
List<WebLayerInfo> queryLayerList) throws Exception {
LinkedHashMap<String, String> newLayerList = new LinkedHashMap<String, String>();
try {
List<WFSWebLayerInfo> layers = wfsMapResource.getLayers();
String mapSourceName = wfsMapResource.getAlias();
for (WebLayerInfo webLayerInfo : layers) {
String layerName = webLayerInfo.getName();
if (layerName != null) {
String key = resourceId + "!" + webLayerInfo.getId();
String value = mapSourceName + "." + layerName;
newLayerList.put(key, value);
} else {
_logger.warn(
"null layer name encountered for WFS service, ignoring");
}
}
} catch (Exception ex) {
_logger.error("Unable to get WFS service layer list", ex);
}
return newLayerList;
}
public static List<QueryResult> doQuery(Object objResource,
WebQuery webQuery, QueryBuilderCriteria qbc, WebLayerInfo webLayerInfo) {
List<QueryResult> results = null;
WFSMapResource resource = null;
QueryFunctionality qf = null;
WFSPredefinedQueryCriteriaHandler qHandler = null;
List<WebLayerInfo> layerList = null;
PredefinedQueryCriteria qc = null;
if (objResource == null) {
throw new NullPointerException("Resource cannot be null");
}
if (!(objResource instanceof WFSMapResource)) {
_logger.warn("Resource is not of type: " +
WFSMapResource.class.getName());
return results;
}
resource = (WFSMapResource) objResource;
qf = (QueryFunctionality) resource.getFunctionality("query");
layerList = new ArrayList<WebLayerInfo>();
layerList.add(webLayerInfo);
qc = new PredefinedQueryCriteria();
qc.setMaxRecordCount(qbc.getMaxRecordCount());
qc.setWhereClause(qbc.getWhereClause());
qc.setFetchResultDetails(true);
qHandler = new WFSPredefinedQueryCriteriaHandler();
results = qHandler.handleCriteria(qc, layerList, webQuery, qf,
qbc.getWebGeometry());
return results;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -