Search in sources :

Example 1 with AttributeDescriptorComparator

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.AttributeDescriptorComparator in project ddf by codice.

the class GenericFeatureConverter method marshal.

/**
     * This method will convert a {@link Metacard} instance into xml that will validate against the
     * GML 2.1.2 AbstractFeatureType.
     *
     * @param value   the {@link Metacard} to convert
     * @param writer  the stream writer responsible for writing this xml doc
     * @param context a reference back to the Xstream marshalling context. Allows you to call
     *                "convertAnother" which will lookup other registered converters.
     */
@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    Metacard metacard = (Metacard) value;
    // TODO when we have a reference to the MCT we can get the namespace too
    QName qname = WfsQnameBuilder.buildQName(metacard.getMetacardType().getName(), metacard.getContentTypeName());
    writer.startNode(qname.getPrefix() + ":" + qname.getLocalPart());
    // Add the "fid" attribute if we have an ID
    String fid = (String) metacard.getAttribute(Metacard.ID).getValue();
    if (fid != null) {
        writer.addAttribute(FID, fid);
    }
    if (null != metacard.getLocation()) {
        Geometry geo = XmlNode.readGeometry(metacard.getLocation());
        if (geo != null && !geo.isEmpty()) {
            XmlNode.writeEnvelope(WfsConstants.GML_PREFIX + ":" + "boundedBy", context, writer, geo.getEnvelopeInternal());
        }
    }
    Set<AttributeDescriptor> descriptors = new TreeSet<AttributeDescriptor>(new AttributeDescriptorComparator());
    descriptors.addAll(metacard.getMetacardType().getAttributeDescriptors());
    for (AttributeDescriptor attributeDescriptor : descriptors) {
        Attribute attribute = metacard.getAttribute(attributeDescriptor.getName());
        if (attribute != null) {
            writeAttributeToXml(attribute, qname, attributeDescriptor.getType().getAttributeFormat(), context, writer);
        }
    }
    writer.endNode();
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QName(javax.xml.namespace.QName) TreeSet(java.util.TreeSet) AttributeDescriptorComparator(org.codice.ddf.spatial.ogc.wfs.catalog.common.AttributeDescriptorComparator) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor)

Example 2 with AttributeDescriptorComparator

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.AttributeDescriptorComparator in project ddf by codice.

the class GenericFeatureConverterWfs20 method marshal.

/**
     * This method will convert a {@link Metacard} instance into xml that will validate against the
     * GML 2.1.2 AbstractFeatureType.
     *
     * @param value
     *            the {@link Metacard} to convert
     * @param writer
     *            the stream writer responsible for writing this xml doc
     * @param context
     *            a reference back to the Xstream marshalling context. Allows you to call
     *            "convertAnother" which will lookup other registered converters.
     */
@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    Metacard metacard = (Metacard) value;
    // TODO when we have a reference to the MCT we can get the namespace too
    QName qname = WfsQnameBuilder.buildQName(metacard.getMetacardType().getName(), metacard.getContentTypeName());
    writer.startNode(qname.getPrefix() + ":" + qname.getLocalPart());
    // Add the "id" attribute if we have an ID
    if (metacard.getAttribute(Metacard.ID).getValue() != null) {
        String id = (String) metacard.getAttribute(Metacard.ID).getValue();
        writer.addAttribute(ID, id);
    }
    if (null != metacard.getLocation()) {
        Geometry geo = XmlNode.readGeometry(metacard.getLocation());
        if (geo != null && !geo.isEmpty()) {
            XmlNode.writeEnvelope(WfsConstants.GML_PREFIX + ":" + "boundedBy", context, writer, geo.getEnvelopeInternal());
        }
    }
    Set<AttributeDescriptor> descriptors = new TreeSet<AttributeDescriptor>(new AttributeDescriptorComparator());
    descriptors.addAll(metacard.getMetacardType().getAttributeDescriptors());
    for (AttributeDescriptor attributeDescriptor : descriptors) {
        Attribute attribute = metacard.getAttribute(attributeDescriptor.getName());
        if (attribute != null) {
            writeAttributeToXml(attribute, qname, attributeDescriptor.getType().getAttributeFormat(), context, writer);
        }
    }
    writer.endNode();
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QName(javax.xml.namespace.QName) TreeSet(java.util.TreeSet) AttributeDescriptorComparator(org.codice.ddf.spatial.ogc.wfs.catalog.common.AttributeDescriptorComparator) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor)

Aggregations

Geometry (com.vividsolutions.jts.geom.Geometry)2 Attribute (ddf.catalog.data.Attribute)2 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)2 Metacard (ddf.catalog.data.Metacard)2 TreeSet (java.util.TreeSet)2 QName (javax.xml.namespace.QName)2 AttributeDescriptorComparator (org.codice.ddf.spatial.ogc.wfs.catalog.common.AttributeDescriptorComparator)2