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);
}
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();
}
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;
}
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;
}
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;
}
Aggregations