📄 featuredescriptionparser.java
字号:
package com.esri.solutions.jitk.datasources.ogc.wfs.parsing;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;
import org.apache.log4j.Logger;
import com.esri.solutions.jitk.datasources.ogc.wfs.FeatureElement;
import com.esri.solutions.jitk.datasources.ogc.wfs.FeatureType;
import com.esri.solutions.jitk.datasources.ogc.wfs.FeatureTypeDescription;
import com.esri.solutions.jitk.datasources.ogc.wfs.parsing.stax.AttributeFinder;
import com.esri.solutions.jitk.datasources.ogc.wfs.parsing.stax.IElementParser;
public class FeatureDescriptionParser implements IElementParser {
private static final Logger _logger = Logger.getLogger(FeatureDescriptionParser.class);
protected Map<String, FeatureTypeDescription> _ftdTitleMap = null;
protected Map<String, FeatureType> _ft = null;
protected FeatureType _currentFt = null;
public FeatureDescriptionParser() {
_ft = new HashMap<String, FeatureType>();
}
public void setFeatureTypeDescriptions(Map<String, FeatureTypeDescription> ftd) {
_ftdTitleMap = ftd;
}
public String stripTypePostfix(String name) {
// ArcIMS WFSs use "_Type" to denote the FeatureDescriptionType
int typeIdx = name.indexOf("_Type");
// ArcGIS Server WFSs use "_Type" to denote the FeatureDescriptionType
if (typeIdx <= 0) {
typeIdx = name.indexOf("Type");
if (typeIdx <= 0) {
return name;
} else {
return name.substring(0, typeIdx);
}
}
else {
return name.substring(0, typeIdx);
}
}
@SuppressWarnings("unchecked")
protected boolean isFeatureDescription(XMLEvent event) {
AttributeFinder attribFinder = new AttributeFinder();
Iterator it = event.asStartElement().getAttributes();
String name = attribFinder.getAttributeValue(it, "name");
//Striping the "Type" text on the name is specific to the ArcGIS Server
//implimentation of WFS
name = stripTypePostfix(name);
if (name != null) {
if (_ftdTitleMap.containsKey(name)) {
return true;
} else {
for ( FeatureTypeDescription ftd : _ftdTitleMap.values()) {
if (ftd.getName().equalsIgnoreCase(name)) {
return true;
}
}
}
}
return false;
}
@SuppressWarnings("unchecked")
protected String getFeatureTypeName(XMLEvent event) {
AttributeFinder attribFinder = new AttributeFinder();
Iterator it = event.asStartElement().getAttributes();
return attribFinder.getAttributeValue(it, "name");
}
@SuppressWarnings("unchecked")
protected void parseElement(XMLEvent event) {
AttributeFinder attribFinder = new AttributeFinder();
Iterator it = event.asStartElement().getAttributes();
String name = attribFinder.getAttributeValue(it, "name");
if (name == null) {
return;
}
Iterator it2 = event.asStartElement().getAttributes();
String type = attribFinder.getAttributeValue(it2, "type");
if (type == null) {
type = "xsd:string";
}
Iterator it3 = event.asStartElement().getAttributes();
String minOccurs = attribFinder.getAttributeValue(it3, "minOccurs");
if (minOccurs == null) {
minOccurs = "1";
}
FeatureElement fe = new FeatureElement();
fe.setMinOccurances(Integer.parseInt(minOccurs));
fe.setName(name);
fe.setXsdType(type);
_currentFt.addFeatureElement(fe);
}
public Map<String, FeatureType> getFeatureTypes() {
return _ft;
}
@SuppressWarnings("unchecked")
public void parse(XMLEventReader xmler, XMLEvent currentEvent) throws XMLStreamException {
_logger.debug("Parsing complexType");
if (isFeatureDescription(currentEvent)) {
_logger.debug("complexType is a FeatureDescription");
int iInternalConplexTypes = 0;
String featureTypeName = getFeatureTypeName(currentEvent);
//Striping the "Type" text on the name is specific to the ArcGIS Server
//implimentation of WFS
featureTypeName = stripTypePostfix(featureTypeName);
_currentFt = new FeatureType();
_currentFt.setName(featureTypeName);
_ft.put(featureTypeName, _currentFt);
while (xmler.hasNext()) {
XMLEvent event = xmler.nextEvent();
if (event.isStartElement()) {
String currentElementName = event.asStartElement().getName().getLocalPart();
if (currentElementName.equals("complexType")) {
iInternalConplexTypes++;
}
if (currentElementName.equals("element")) {
parseElement(event);
}
}
if (event.isEndElement()) {
String endElement = event.asEndElement().getName().getLocalPart();
if (endElement.equals("complexType")) {
if (iInternalConplexTypes > 0) {
iInternalConplexTypes--;
}
else {
break;
}
}
}
}
}
else {
_logger.debug("complexType is NOT a FeatureDescription");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -