}
}
if ((nsUri == null) || (nsUri.length() == 0)) {
String msg = "The namespace must follow the following pattern:";
msg += " xmlns(pfx1=uri1),xmlns(pfx2=uri2),...";
throw new OwsException(OwsException.OWSCODE_InvalidParameterValue,"namespace",msg);
} else {
if (nsUri.equals("http://www.opengis.net/cat/csw/")) {
hasCswUri = true;
if ((nsPfx != null) && (nsPfx.length() > 0)) {
hasCswPfx = true;
cswPfx = nsPfx;
}
}
nsUri = Val.escapeXml(nsUri);
if ((nsPfx == null) || (nsPfx.length() == 0)) {
nsBuffer.append(" xmlns=\"").append(nsUri).append("\"");
} else {
nsBuffer.append(" xmlns:").append(nsPfx).append("=\"").append(nsUri).append("\"");
}
}
}
}
// use ogc as the default namespace if no namespace parameter was supplied
if (nsBuffer.length() == 0) {
nsBuffer.append(" xmlns=\"http://www.opengis.net/ogc\"");
}
// build the constraint XML
StringBuilder sbXml = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
if (hasCswUri && hasCswPfx) {
cswPfx = cswPfx+":";
} else if (hasCswUri) {
cswPfx = "";
} else {
cswPfx = "csw:";
nsBuffer.append(" xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\"");
}
sbXml.append("\r\n<").append(cswPfx).append("Constraint");
if (nsBuffer.length() > 0) {
sbXml.append(" ").append(nsBuffer);
}
sbXml.append(">");
sbXml.append("\r\n").append(constraintFilter);
sbXml.append("\r\n</").append(cswPfx).append("Constraint>");
// make the dom, find the ogc:Filter node
try {
Document dom = DomUtil.makeDomFromString(sbXml.toString(),true);
CswNamespaces ns = new CswNamespaces();
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(ns.makeNamespaceContext());
Node ndFilter = null;
Node ndConstraint = (Node)xpath.evaluate("csw:Constraint",dom,XPathConstants.NODE);
if (ndConstraint != null) {
ndFilter = (Node)xpath.evaluate("ogc:Filter",ndConstraint,XPathConstants.NODE);;
}
if (ndFilter == null) {
String msg = "The supplied constraint was not a valid ogc:Filter.";
throw new OwsException(OwsException.OWSCODE_NoApplicableCode,"constraint",msg);
} else {
return ndFilter;
}
} catch (SAXException e) {
String msg = "The supplied namespace/constraint pairs were not well-formed xml: ";
msg += " "+e.toString();
throw new OwsException(OwsException.OWSCODE_NoApplicableCode,"constraint",msg);
}
}