Skip to content

Commit

Permalink
Extended namespace validation for WFS-T replace
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Watermeyer authored and Andreas Watermeyer committed Apr 21, 2015
1 parent c8c4f47 commit 0b9487d
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/wfs/src/main/java/org/geoserver/wfs/WFSWorkspaceQualifier.java
Expand Up @@ -29,6 +29,7 @@
import org.geoserver.wfs.request.Lock;
import org.geoserver.wfs.request.LockFeatureRequest;
import org.geoserver.wfs.request.Query;
import org.geoserver.wfs.request.Replace;
import org.geoserver.wfs.request.TransactionElement;
import org.geoserver.wfs.request.TransactionRequest;
import org.opengis.feature.Feature;
Expand Down Expand Up @@ -153,20 +154,39 @@ protected void qualifyRequest(WorkspaceInfo workspace, LayerInfo layer, Operatio
Insert in = (Insert) el;
//in the insert case the objects are gt feature types which are not mutable
// so we just check them and throw an exception if a name does not match
for (Iterator j = in.getFeatures().iterator(); j.hasNext(); ) {
Feature f = (Feature) j.next();
Name n = f.getType().getName();
if (n.getNamespaceURI() != null && !ns.getURI().equals(n.getNamespaceURI())) {
throw new WFSException(t, "No such feature type " + n);
}
}
List features = in.getFeatures();
ensureFeatureNamespaceUriMatches(features, ns, t);
}
else if(el instanceof Replace){
Replace rep = (Replace) el;
//in the replace case the objects are gt feature types which are not mutable
// so we just check them and throw an exception if a name does not match
List features = rep.getFeatures();
ensureFeatureNamespaceUriMatches(features, ns, t);
}
else {
el.setTypeName(qualifyTypeName(el.getTypeName(), workspace, ns));
}
}
}
}

/**
* Iterates the given features and ensures their namespaceURI matches the given namespace
* @param features
* @param ns
* @param t
*/
private void ensureFeatureNamespaceUriMatches(List features,
NamespaceInfo ns, TransactionRequest t) {
for (Iterator j = features.iterator(); j.hasNext(); ) {
Feature f = (Feature) j.next();
Name n = f.getType().getName();
if (n.getNamespaceURI() != null && !ns.getURI().equals(n.getNamespaceURI())) {
throw new WFSException(t, "No such feature type " + n);
}
}
}

void qualifyTypeNames(List names, WorkspaceInfo ws, NamespaceInfo ns) {
for (int i = 0; i < names.size(); i++) {
Expand Down

0 comments on commit 0b9487d

Please sign in to comment.