use of org.geotoolkit.ogc.xml.XMLFilter in project geotoolkit by Geomatys.
the class AbstractGetFeature method prepareFilter.
protected Optional<XMLFilter> prepareFilter() {
if (filter == null || Filter.include().equals(filter)) {
return Optional.empty();
}
final SimplifyingFilterVisitor visitor;
String namespace = typeName == null ? null : typeName.getNamespaceURI();
if (namespace != null && !namespace.isEmpty()) {
String prefix = typeName.getPrefix();
if (prefix == null || prefix.trim().isEmpty()) {
namespace += ":";
prefix = "";
}
visitor = new PrefixSwitchVisitor();
((PrefixSwitchVisitor) visitor).setPrefix(namespace, prefix);
} else {
visitor = SimplifyingFilterVisitor.INSTANCE;
}
final Object result = visitor.visit(filter);
if (result == null || Filter.include().equals(result)) {
return Optional.empty();
} else if (result instanceof Filter) {
return Optional.of(FilterMarshallerPool.transform((Filter) result, getFilterVersion()));
}
throw new IllegalStateException("Filter visit resulted in an unexpected object: " + result.getClass());
}
use of org.geotoolkit.ogc.xml.XMLFilter in project geotoolkit by Geomatys.
the class JAXPStreamTransactionWriter method writeFilter.
private static void writeFilter(Filter filter, final FilterVersion outputVersion, final XMLStreamWriter output) throws JAXBException {
if (filter == null || filter == Filter.include()) {
return;
}
final XMLFilter toWrite;
if (filter instanceof XMLFilter) {
toWrite = (XMLFilter) filter;
} else {
toWrite = FilterMarshallerPool.transform(filter, outputVersion);
}
final MarshallerPool pool = FilterMarshallerPool.getInstance(outputVersion);
final Marshaller marsh = pool.acquireMarshaller();
marsh.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marsh.marshal(toWrite, output);
pool.recycle(marsh);
}
use of org.geotoolkit.ogc.xml.XMLFilter in project geotoolkit by Geomatys.
the class AbstractGetFeature method getResponseStream.
/**
* {@inheritDoc }
*/
@Override
public InputStream getResponseStream() throws IOException {
final List<QName> typeNames = new ArrayList<>();
final List<String> propNames;
if (typeName != null) {
typeNames.add(typeName);
propNames = preparePropertyNames(typeName.getPrefix(), typeName.getNamespaceURI()).collect(Collectors.toList());
} else {
propNames = preparePropertyNames(null, null).collect(Collectors.toList());
}
final XMLFilter xmlFilter = prepareFilter().orElse(null);
final Query query = WFSXmlFactory.buildQuery(version.getCode(), xmlFilter, typeNames, null, null, null, propNames);
final GetFeature request = WFSXmlFactory.buildGetFeature(version.getCode(), "WFS", null, null, maxFeatures, query, ResultTypeType.RESULTS, outputFormat);
final URL url = new URL(serverURL);
URLConnection conec = url.openConnection();
conec = security.secure(conec);
conec.setDoOutput(true);
conec.setRequestProperty("Content-Type", "text/xml");
OutputStream stream = conec.getOutputStream();
stream = security.encrypt(stream);
try (final OutputStream toClose = stream) {
Marshaller marshaller = WFSMarshallerPool.getInstance(version).acquireMarshaller();
marshaller.marshal(request, stream);
WFSMarshallerPool.getInstance().recycle(marshaller);
} catch (JAXBException ex) {
throw new IOException(ex);
}
return security.decrypt(conec.getInputStream());
}
Aggregations