Search in sources :

Example 1 with XMLFilter

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());
}
Also used : Filter(org.opengis.filter.Filter) XMLFilter(org.geotoolkit.ogc.xml.XMLFilter) SimplifyingFilterVisitor(org.geotoolkit.filter.visitor.SimplifyingFilterVisitor)

Example 2 with XMLFilter

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);
}
Also used : Marshaller(javax.xml.bind.Marshaller) XMLFilter(org.geotoolkit.ogc.xml.XMLFilter) GMLMarshallerPool(org.geotoolkit.gml.xml.GMLMarshallerPool) FilterMarshallerPool(org.geotoolkit.ogc.xml.FilterMarshallerPool) MarshallerPool(org.apache.sis.xml.MarshallerPool) JTSWrapperMarshallerPool(org.geotoolkit.internal.jaxb.JTSWrapperMarshallerPool)

Example 3 with XMLFilter

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());
}
Also used : GetFeature(org.geotoolkit.wfs.xml.GetFeature) Marshaller(javax.xml.bind.Marshaller) Query(org.geotoolkit.wfs.xml.Query) QName(javax.xml.namespace.QName) OutputStream(java.io.OutputStream) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) XMLFilter(org.geotoolkit.ogc.xml.XMLFilter) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Aggregations

XMLFilter (org.geotoolkit.ogc.xml.XMLFilter)3 Marshaller (javax.xml.bind.Marshaller)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 ArrayList (java.util.ArrayList)1 JAXBException (javax.xml.bind.JAXBException)1 QName (javax.xml.namespace.QName)1 MarshallerPool (org.apache.sis.xml.MarshallerPool)1 SimplifyingFilterVisitor (org.geotoolkit.filter.visitor.SimplifyingFilterVisitor)1 GMLMarshallerPool (org.geotoolkit.gml.xml.GMLMarshallerPool)1 JTSWrapperMarshallerPool (org.geotoolkit.internal.jaxb.JTSWrapperMarshallerPool)1 FilterMarshallerPool (org.geotoolkit.ogc.xml.FilterMarshallerPool)1 GetFeature (org.geotoolkit.wfs.xml.GetFeature)1 Query (org.geotoolkit.wfs.xml.Query)1 Filter (org.opengis.filter.Filter)1