+ * The method recursively climbs up the type hierarchy of the provided feature type, until it finds AbstractFeatureType. Then, the GML version is + * determined by looking at the namespace URI. + *
+ * + *+ * Please note that this method does not differentiate between GML 2 and GML 3.1.1, but assumes that "http://www.opengis.net/gml" namespace always + * refers to GML 3.1.1. + *
+ * + * @param ftInfo the feature type info + * @return the GML version used in the feature type definition + * @throws IOException if the underlying datastore instance cannot be retrieved + */ + String findGmlVersion(FeatureTypeInfo ftInfo) throws IOException { + ProgressListener listener = new NullProgressListener(); + Name qName = ftInfo.getQualifiedName(); + FeatureType fType = ftInfo.getStore().getDataStore(listener).getSchema(qName); + return findFeatureTypeGmlVersion(fType); + } + + private String findFeatureTypeGmlVersion(AttributeType featureType) { + if (featureType == null) { + return null; + } + + if (isAbstractFeatureType(featureType)) { + String gmlNamespace = featureType.getName().getNamespaceURI(); + if (org.geotools.gml3.GML.NAMESPACE.equals(gmlNamespace)) { + // GML 3.1.1 + return "gml3"; + } else if (org.geotools.gml3.v3_2.GML.NAMESPACE.equals(gmlNamespace)) { + // GML 3.2 + return GML32OutputFormat.FORMATS.get(0); + } else { + // should never happen + LOGGER.log(Level.FINE, "Cannot determine GML version from AbstractFeatureType type"); + return null; + } + } + + // recursively check super types + AttributeType parent = featureType.getSuper(); + return findFeatureTypeGmlVersion(parent); + } + + private boolean isAbstractFeatureType(AttributeType type) { + if (type == null) { + return false; + } + + Name qName = type.getName(); + String localPart = qName.getLocalPart(); + String ns = qName.getNamespaceURI(); + if ("AbstractFeatureType".equals(localPart) && + (org.geotools.gml3.GML.NAMESPACE.equals(ns) || org.geotools.gml3.v3_2.GML.NAMESPACE + .equals(ns))) { + return true; + } else { + return false; + } + } + + String buildGmlLink(GMLOutputParams gmlParams) { + StringBuilder urlBuilder = new StringBuilder(); + urlBuilder.append(gmlParams.baseUrl).append("?"); + urlBuilder.append("service=WFS").append("&"); + urlBuilder.append("version=").append(gmlParams.wfsVersion).append("&"); + urlBuilder.append("request=GetFeature").append("&"); + urlBuilder.append("typeName=").append(getName()); + if (gmlParams.gmlVersion != null) { + urlBuilder.append("&"); + urlBuilder.append("outputFormat=").append(gmlParams.gmlVersion); + } + + return urlBuilder.toString(); + } + + class GMLOutputParams { + String wfsVersion; + String gmlVersion; + String baseUrl; + + private GMLOutputParams() { + // by default, use WFS 1.0.0 + wfsVersion = org.geotools.wfs.v1_0.WFS.getInstance().getVersion(); + // by default, infer GML version from WFS version + gmlVersion = null; + // by default, use virtual ows services + baseUrl = getBaseUrl("ows"); + } + } }