Search in sources :

Example 1 with XmlDateTime

use of org.apache.xmlbeans.XmlDateTime in project hale by halestudio.

the class WFSFeatureCollectionWriter method writeAdditionalElements.

@Override
protected void writeAdditionalElements(XMLStreamWriter writer, TypeDefinition containerDefinition, IOReporter reporter) throws XMLStreamException {
    // write additional needed attributes for WFS 2.0
    boolean requiresCount = requiresCount();
    boolean skipCount = getParameter(PARAM_SKIP_COUNT).as(Boolean.class, false);
    if (requiresCount) {
        String countString = null;
        InstanceCollection source = getInstances();
        if (source.hasSize()) {
            // no iteration needed
            countString = String.valueOf(source.size());
        } else if (!skipCount) {
            // count features
            int count = 0;
            // need to iterate collection to determine size
            try (ResourceIterator<Instance> it = source.iterator()) {
                while (it.hasNext()) {
                    Instance candidate = it.next();
                    if (GmlWriterUtil.isFeatureType(candidate.getDefinition())) {
                        count++;
                    }
                }
            }
            countString = String.valueOf(count);
        }
        // numberMatched
        if (countString != null) {
            writer.writeAttribute("numberMatched", countString);
        } else {
            writer.writeAttribute("numberMatched", "unknown");
        }
        // numberReturned
        if (countString != null) {
            writer.writeAttribute("numberReturned", countString);
        } else {
            writer.writeAttribute("numberReturned", "0");
        }
        // timestamp
        XmlDateTime result = XmlDateTime.Factory.newInstance();
        result.setDateValue(new Date());
        writer.writeAttribute("timeStamp", result.getStringValue());
    }
    super.writeAdditionalElements(writer, containerDefinition, reporter);
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) XmlDateTime(org.apache.xmlbeans.XmlDateTime) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) ResourceIterator(eu.esdihumboldt.hale.common.instance.model.ResourceIterator) Date(java.util.Date)

Example 2 with XmlDateTime

use of org.apache.xmlbeans.XmlDateTime in project hale by halestudio.

the class SimpleTypeUtil method convertToXml.

/**
 * Convert a simple type value to a string
 *
 * @param <T> the type of the value
 * @param value the value
 * @param type the type definition of the simple type
 * @return the string representation of the value or <code>null</code> if
 *         the value is <code>null</code>
 */
public static <T> String convertToXml(T value, TypeDefinition type) {
    if (value == null) {
        return null;
    }
    ConversionService conversionService = HalePlatform.getService(ConversionService.class);
    Class<? extends XmlAnySimpleType> simpleType = getSimpleType(type);
    if (simpleType != null) {
        try {
            XmlAnySimpleType simpleTypeValue = conversionService.convert(value, simpleType);
            if (simpleTypeValue instanceof XmlDateTime) {
                XmlDateTime xmlDateTime = (XmlDateTime) simpleTypeValue;
                // use Zulu time to have a reproducable result
                // (as the old Java Date types always assume the current
                // time zone!)
                // 
                // XXX this should be removed when time/date types are used
                // that are timezone aware
                Calendar calendar = xmlDateTime.getCalendarValue();
                GDateBuilder builder = new GDateBuilder(calendar);
                builder.normalizeToTimeZone(0);
                GDate gdate = builder.toGDate();
                xmlDateTime.setGDateValue(gdate);
            }
            if (simpleTypeValue != null) {
                return simpleTypeValue.getStringValue();
            }
        } catch (ConversionException e) {
        // ignore
        }
    }
    // try to convert to string
    try {
        String stringValue = conversionService.convert(value, String.class);
        if (stringValue != null) {
            return stringValue;
        }
    } catch (ConversionException e) {
    // ignore
    }
    // fall-back
    return value.toString();
}
Also used : XmlAnySimpleType(org.apache.xmlbeans.XmlAnySimpleType) ConversionException(org.springframework.core.convert.ConversionException) XmlDateTime(org.apache.xmlbeans.XmlDateTime) ConversionService(org.springframework.core.convert.ConversionService) Calendar(java.util.Calendar) GDateBuilder(org.apache.xmlbeans.GDateBuilder) GDate(org.apache.xmlbeans.GDate)

Example 3 with XmlDateTime

use of org.apache.xmlbeans.XmlDateTime in project hale by halestudio.

the class DateToXmlDateTime method convert.

/**
 * @see Converter#convert(Object)
 */
@Override
public XmlDateTime convert(Date value) {
    XmlDateTime result = XmlDateTime.Factory.newInstance();
    result.setDateValue(value);
    return result;
}
Also used : XmlDateTime(org.apache.xmlbeans.XmlDateTime)

Example 4 with XmlDateTime

use of org.apache.xmlbeans.XmlDateTime in project hale by halestudio.

the class StringToXmlDateTime method convert.

/**
 * @see Converter#convert(Object)
 */
@Override
public XmlDateTime convert(String value) {
    if (value == null) {
        return null;
    }
    XmlDateTime result = XmlDateTime.Factory.newInstance();
    result.setStringValue(value);
    return result;
}
Also used : XmlDateTime(org.apache.xmlbeans.XmlDateTime)

Example 5 with XmlDateTime

use of org.apache.xmlbeans.XmlDateTime in project arctic-sea by 52North.

the class SweCommonEncoderv101 method createTime.

private Time createTime(SweTime component) throws EncodingException {
    Time xml = Time.Factory.newInstance(getXmlOptions());
    if (component.isSetValue()) {
        XmlDateTime xbDateTime = createDateTime(component.getValue());
        xml.setValue(xbDateTime);
    }
    if (component.isSetUom()) {
        if (component.getUom().startsWith(URN) || component.getUom().startsWith(HTTP)) {
            xml.addNewUom().setHref(component.getUom());
        } else {
            xml.addNewUom().setCode(component.getUom());
        }
    }
    if (component.isSetQuality()) {
        xml.setQuality(createQuality(component.getQuality())[0]);
    }
    if (component.isSetContstraint()) {
        createConstraint(xml.getConstraint(), component.getConstraint());
    }
    return xml;
}
Also used : XmlDateTime(org.apache.xmlbeans.XmlDateTime) Time(net.opengis.swe.x101.TimeDocument.Time) XmlDateTime(org.apache.xmlbeans.XmlDateTime) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) DateTime(org.joda.time.DateTime)

Aggregations

XmlDateTime (org.apache.xmlbeans.XmlDateTime)6 GDateBuilder (org.apache.xmlbeans.GDateBuilder)2 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)1 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)1 ResourceIterator (eu.esdihumboldt.hale.common.instance.model.ResourceIterator)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 Time (net.opengis.swe.x101.TimeDocument.Time)1 GDate (org.apache.xmlbeans.GDate)1 XmlAnySimpleType (org.apache.xmlbeans.XmlAnySimpleType)1 DateTime (org.joda.time.DateTime)1 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)1 ConversionException (org.springframework.core.convert.ConversionException)1 ConversionService (org.springframework.core.convert.ConversionService)1