List of usage examples for javax.xml.bind DatatypeConverter parseDate
public static java.util.Calendar parseDate(String lexicalXSDDate)
Converts the string argument into a Calendar value.
From source file:com.fluidops.iwb.api.ValueResolver.java
/** * Resolves a value string using a specified resolver (as string). * Can be extended on demand by new resolvers. Should not return * null./*from ww w.j a v a 2 s . c om*/ * * @param value * @param resolver * @return */ public static String resolve(Value value, ResolverType resolver) { if (resolver == null) resolver = ResolverType.DEFAULT; if (value == null) value = ValueFactoryImpl.getInstance().createLiteral(""); try { switch (resolver) { case MS_TIMESTAMP2DATE: return resolveDateFromTimestamp(value.stringValue(), 1); case S_TIMESTAMP2DATE: return resolveDateFromTimestamp(value.stringValue(), 1000); case DATE: return resolveCalendar(DatatypeConverter.parseDate(value.stringValue()), "MMM dd, yyyy"); case TIME: return resolveCalendar(DatatypeConverter.parseTime(value.stringValue()), "HH:mm:ss"); case DATETIME: return resolveCalendar(DatatypeConverter.parseDateTime(value.stringValue()), "MMM dd, yyyy HH:mm:ss"); case SYSDATE: return resolveSysDate(value.stringValue()); case IMAGE: return resolveImage(value); case THUMBNAIL: return resolveThumbnail(value, "20px"); case BIGTHUMBNAIL: return resolveThumbnail(value, "50px"); case DOUBLE2INT: return resolveDecimalFromDouble(Double.valueOf(value.stringValue())); case URL: return resolveURL(value.stringValue(), null); case HTML: return resolveHtml(value); case LOGINLINK: return resolveURL(value.stringValue(), "Login"); case BYTE2KB: return resolveByte2X(value.stringValue(), "KB"); case BYTE2MB: return resolveByte2X(value.stringValue(), "MB"); case BYTE2GB: return resolveByte2X(value.stringValue(), "GB"); case BYTE2TB: return resolveByte2X(value.stringValue(), "TB"); case KBYTE2MB: return resolveKByte2X(value.stringValue(), "MB"); case KBYTE2GB: return resolveKByte2X(value.stringValue(), "GB"); case KBYTE2TB: return resolveKByte2X(value.stringValue(), "TB"); case PERCENT: return resolvePercent(value.stringValue()); case PERCENT_NOCONVERT: return resolvePercentNoConvert(value.stringValue()); case ROUND_DOUBLE: return resolveNumber2Places(value.stringValue()); case CURRENCY_USD: return resolveCurrency(value.stringValue(), "USD"); case CURRENCY_EUR: return resolveCurrency(value.stringValue(), "EUR"); case CURRENCY_CNY: return resolveCurrency(value.stringValue(), "CNY"); case DEFAULT_NOERROR: return resolveDefaultNoError(value); case DEFAULT: default: return resolveDefault(value); } } catch (Exception e) { return resolveDefault(value); } }
From source file:microsoft.exchange.webservices.data.property.complex.TimeChange.java
/** * Tries to read element from XML.//from ww w.j a v a2s . c om * * @param reader accepts EwsServiceXmlReader * @return True if element was read * @throws Exception throws Exception */ @Override public boolean tryReadElementFromXml(EwsServiceXmlReader reader) throws Exception { if (reader.getLocalName().equalsIgnoreCase(XmlElementNames.Offset)) { this.offset = EwsUtilities.getXSDurationToTimeSpan(reader.readElementValue()); return true; } else if (reader.getLocalName().equalsIgnoreCase(XmlElementNames.RelativeYearlyRecurrence)) { this.recurrence = new TimeChangeRecurrence(); this.recurrence.loadFromXml(reader, reader.getLocalName()); return true; } else if (reader.getLocalName().equalsIgnoreCase(XmlElementNames.AbsoluteDate)) { Calendar cal = DatatypeConverter.parseDate(reader.readElementValue()); cal.setTimeZone(TimeZone.getTimeZone("UTC")); this.absoluteDate = cal.getTime(); return true; } else if (reader.getLocalName().equalsIgnoreCase(XmlElementNames.Time)) { Calendar cal = DatatypeConverter.parseTime(reader.readElementValue()); this.time = new Time(cal.getTime()); return true; } else { return false; } }
From source file:br.com.upic.camel.openedge.OpenEdgeEndpoint.java
@Override protected void onExchange(final Exchange exchange) throws Exception { try {/*from w w w .jav a 2 s .co m*/ LOG.info("Unmarshalling the request"); final Request req = (Request) unmarshaller.unmarshal(exchange.getIn().getBody(Document.class)); LOG.info("Setting the input params"); final List<JAXBElement<? extends Serializable>> reqParamElementList = req.getParamElementList(); final ParamArray proParams = new ParamArray(reqParamElementList.size()); for (final JAXBElement<? extends Serializable> reqParamElement : reqParamElementList) { final Serializable reqParam = reqParamElement.getValue(); if (reqParam instanceof CharArrayParam) { final CharArrayParam charArrayParam = (CharArrayParam) reqParam; final ParamMode mode = charArrayParam.getMode(); final int id = charArrayParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final List<String> value = new ArrayList<String>(); for (final JAXBElement<String> valueElement : charArrayParam.getValueElementList()) { if (!valueElement.isNil()) value.add(DatatypeConverter.parseString(valueElement.getValue())); else value.add(null); } proParams.addCharacterArray(id, value.toArray(new String[] {}), mode.value(), value.size()); } else { proParams.addCharacterArray(id, null, mode.value(), 0); } } else if (reqParam instanceof CharParam) { final CharParam charParam = (CharParam) reqParam; final ParamMode mode = charParam.getMode(); final int id = charParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) proParams.addCharacter(id, DatatypeConverter.parseString(charParam.getContent()), mode.value()); else proParams.addCharacter(id, null, mode.value()); } else if (reqParam instanceof DateArrayParam) { final DateArrayParam dateArrayParam = (DateArrayParam) reqParam; final ParamMode mode = dateArrayParam.getMode(); final int id = dateArrayParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final List<GregorianCalendar> value = new ArrayList<GregorianCalendar>(); for (final JAXBElement<String> valueElement : dateArrayParam.getValueElementList()) { if (!valueElement.isNil()) { final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(DatatypeConverter.parseDate(valueElement.getValue()).getTime()); value.add(cal); } else { value.add(null); } } proParams.addDateArray(id, value.toArray(new GregorianCalendar[] {}), mode.value(), value.size()); } else { proParams.addDateArray(id, null, mode.value(), 0); } } else if (reqParam instanceof DateParam) { final DateParam dateParam = (DateParam) reqParam; final ParamMode mode = dateParam.getMode(); final int id = dateParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(DatatypeConverter.parseDate(dateParam.getContent()).getTime()); proParams.addDate(id, cal, mode.value()); } else { proParams.addDate(id, null, mode.value()); } } else if (reqParam instanceof DateTimeArrayParam) { final DateTimeArrayParam dateTimeArrayParam = (DateTimeArrayParam) reqParam; final ParamMode mode = dateTimeArrayParam.getMode(); final int id = dateTimeArrayParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final List<GregorianCalendar> value = new ArrayList<GregorianCalendar>(); for (final JAXBElement<String> valueElement : dateTimeArrayParam.getValueElementList()) { if (!valueElement.isNil()) { final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(DatatypeConverter.parseDateTime(valueElement.getValue()).getTime()); value.add(cal); } else { value.add(null); } } proParams.addDatetimeArray(id, value.toArray(new GregorianCalendar[] {}), mode.value(), value.size()); } else { proParams.addDatetimeArray(id, null, mode.value(), 0); } } else if (reqParam instanceof DateTimeParam) { final DateTimeParam dateTimeParam = (DateTimeParam) reqParam; final ParamMode mode = dateTimeParam.getMode(); final int id = dateTimeParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(DatatypeConverter.parseDateTime(dateTimeParam.getContent()).getTime()); proParams.addDatetime(id, cal, mode.value()); } else { proParams.addDatetime(id, null, mode.value()); } } else if (reqParam instanceof DateTimeTZArrayParam) { final DateTimeTZArrayParam dateTimeTZArrayParam = (DateTimeTZArrayParam) reqParam; final ParamMode mode = dateTimeTZArrayParam.getMode(); final int id = dateTimeTZArrayParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final List<GregorianCalendar> value = new ArrayList<GregorianCalendar>(); for (final JAXBElement<String> valueElement : dateTimeTZArrayParam.getValueElementList()) { if (!valueElement.isNil()) { final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(DatatypeConverter.parseDateTime(valueElement.getValue()).getTime()); value.add(cal); } else { value.add(null); } } proParams.addDatetimeTZArray(id, value.toArray(new GregorianCalendar[] {}), mode.value(), value.size()); } else { proParams.addDatetimeTZArray(id, null, mode.value(), 0); } } else if (reqParam instanceof DateTimeTZParam) { final DateTimeTZParam dateTimeTZParam = (DateTimeTZParam) reqParam; final ParamMode mode = dateTimeTZParam.getMode(); final int id = dateTimeTZParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(DatatypeConverter.parseDateTime(dateTimeTZParam.getContent()).getTime()); proParams.addDatetimeTZ(id, cal, mode.value()); } else { proParams.addDatetimeTZ(id, null, mode.value()); } } else if (reqParam instanceof DecArrayParam) { final DecArrayParam decArrayParam = (DecArrayParam) reqParam; final ParamMode mode = decArrayParam.getMode(); final int id = decArrayParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final List<BigDecimal> value = new ArrayList<BigDecimal>(); for (final JAXBElement<String> valueElement : decArrayParam.getValueElementList()) { if (!valueElement.isNil()) value.add(DatatypeConverter.parseDecimal(valueElement.getValue())); else value.add(null); } proParams.addDecimalArray(id, value.toArray(new BigDecimal[] {}), mode.value(), value.size()); } else { proParams.addDecimalArray(id, null, mode.value(), 0); } } else if (reqParam instanceof DecParam) { final DecParam decParam = (DecParam) reqParam; final ParamMode mode = decParam.getMode(); final int id = decParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) proParams.addDecimal(id, DatatypeConverter.parseDecimal(decParam.getContent()), mode.value()); else proParams.addDecimal(id, null, mode.value()); } else if (reqParam instanceof IntArrayParam) { final IntArrayParam intArrayParam = (IntArrayParam) reqParam; final ParamMode mode = intArrayParam.getMode(); final int id = intArrayParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final List<Integer> value = new ArrayList<Integer>(); for (final JAXBElement<String> valueElement : intArrayParam.getValueElementList()) { if (!valueElement.isNil()) value.add(DatatypeConverter.parseInt(valueElement.getValue())); else value.add(null); } proParams.addIntegerArray(id, value.toArray(new Integer[] {}), mode.value(), value.size()); } else { proParams.addIntegerArray(id, (Integer[]) null, mode.value(), 0); } } else if (reqParam instanceof IntParam) { final IntParam intParam = (IntParam) reqParam; final ParamMode mode = intParam.getMode(); final int id = intParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) proParams.addInteger(id, new Integer(DatatypeConverter.parseInt(intParam.getContent())), mode.value()); else proParams.addInteger(id, null, mode.value()); } else if (reqParam instanceof LogArrayParam) { final LogArrayParam logArrayParam = (LogArrayParam) reqParam; final ParamMode mode = logArrayParam.getMode(); final int id = logArrayParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) { final List<Boolean> value = new ArrayList<Boolean>(); for (final JAXBElement<String> valueElement : logArrayParam.getValueElementList()) { if (!valueElement.isNil()) value.add(DatatypeConverter.parseBoolean(valueElement.getValue())); else value.add(null); } proParams.addLogicalArray(id, value.toArray(new Boolean[] {}), mode.value(), value.size()); } else { proParams.addLogicalArray(id, (Boolean[]) null, mode.value(), 0); } } else if (reqParam instanceof LogParam) { final LogParam logParam = (LogParam) reqParam; final ParamMode mode = logParam.getMode(); final int id = logParam.getId(); if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) proParams.addLogical(id, new Boolean(DatatypeConverter.parseBoolean(logParam.getContent())), mode.value()); else proParams.addLogical(id, null, mode.value()); } else if (reqParam instanceof ResultSetParam) { final ResultSetParam rsParam = (ResultSetParam) reqParam; final ParamMode mode = rsParam.getMode(); final int id = rsParam.getId(); final ResultSetMetaData rsMetaData = rsParam.getResultSetMetaData(); final List<Serializable> fieldMetaDataList = rsMetaData.getFieldMetaDataList(); final ProResultSetMetaDataImpl proRsMetaData = new ProResultSetMetaDataImpl( fieldMetaDataList.size()); for (final Serializable fieldMetaData : fieldMetaDataList) { if (fieldMetaData instanceof CharFieldMetaData) { final CharFieldMetaData charFieldMetaData = (CharFieldMetaData) fieldMetaData; proRsMetaData.setFieldMetaData(charFieldMetaData.getId(), charFieldMetaData.getName(), charFieldMetaData.getExtent(), Parameter.PRO_CHARACTER); } else if (fieldMetaData instanceof DateFieldMetaData) { final DateFieldMetaData dateFieldMetaData = (DateFieldMetaData) fieldMetaData; proRsMetaData.setFieldMetaData(dateFieldMetaData.getId(), dateFieldMetaData.getName(), dateFieldMetaData.getExtent(), Parameter.PRO_DATE); } else if (fieldMetaData instanceof DateTimeFieldMetaData) { final DateTimeFieldMetaData dateTimeFieldMetaData = (DateTimeFieldMetaData) fieldMetaData; proRsMetaData.setFieldMetaData(dateTimeFieldMetaData.getId(), dateTimeFieldMetaData.getName(), dateTimeFieldMetaData.getExtent(), Parameter.PRO_DATETIME); } else if (fieldMetaData instanceof DateTimeTZFieldMetaData) { final DateTimeTZFieldMetaData dateTimeTZFieldMetaData = (DateTimeTZFieldMetaData) fieldMetaData; proRsMetaData.setFieldMetaData(dateTimeTZFieldMetaData.getId(), dateTimeTZFieldMetaData.getName(), dateTimeTZFieldMetaData.getExtent(), Parameter.PRO_DATETIMETZ); } else if (fieldMetaData instanceof DecFieldMetaData) { final DecFieldMetaData decFieldMetaData = (DecFieldMetaData) fieldMetaData; proRsMetaData.setFieldMetaData(decFieldMetaData.getId(), decFieldMetaData.getName(), decFieldMetaData.getExtent(), Parameter.PRO_DECIMAL); } else if (fieldMetaData instanceof IntFieldMetaData) { final IntFieldMetaData intFieldMetaData = (IntFieldMetaData) fieldMetaData; proRsMetaData.setFieldMetaData(intFieldMetaData.getId(), intFieldMetaData.getName(), intFieldMetaData.getExtent(), Parameter.PRO_INTEGER); } else if (fieldMetaData instanceof LogFieldMetaData) { final LogFieldMetaData logFieldMetaData = (LogFieldMetaData) fieldMetaData; proRsMetaData.setFieldMetaData(logFieldMetaData.getId(), logFieldMetaData.getName(), logFieldMetaData.getExtent(), Parameter.PRO_LOGICAL); } } if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode)) && (!reqParamElement.isNil())) proParams.addTable(id, new OpenEdgeResultSet(rsParam.getRowList().iterator()), mode.value(), proRsMetaData); else proParams.addTable(id, null, mode.value(), proRsMetaData); } } LOG.info("Connecting to the AppServer"); if (SESSION_MODEL_MANAGED == sessionModel) RunTimeProperties.setSessionModel(0); else if (SESSION_MODEL_FREE == sessionModel) RunTimeProperties.setSessionModel(1); final OpenAppObject proAppObject = new OpenAppObject(url, user, password, null, null); proAppObject.runProc(req.getProgram(), proParams); LOG.info("Marshalling the response"); final Response res = OBJECT_FACTORY.createResponse(); res.setResult(proParams.getProcReturnString()); LOG.info("Setting the output params"); for (final JAXBElement<? extends Serializable> reqParamElement : reqParamElementList) { final Serializable reqParam = reqParamElement.getValue(); if (reqParam instanceof CharArrayParam) { final CharArrayParam reqCharArrayParam = (CharArrayParam) reqParam; if (ParamMode.INPUT != reqCharArrayParam.getMode()) { final JAXBElement<CharArrayParam> resParamElement = new JAXBElement<CharArrayParam>( new QName(NS, "CharArray"), CharArrayParam.class, null); final CharArrayParam resParam = OBJECT_FACTORY.createCharArrayParam(); resParam.setId(reqCharArrayParam.getId()); resParam.setName(reqCharArrayParam.getName()); final String[] proParam = (String[]) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { for (int i = 0; i < proParam.length; i++) { final JAXBElement<String> valueElement = new JAXBElement<String>( new QName(NS, "Value"), String.class, null); if (proParam[i] != null) valueElement.setValue(DatatypeConverter.printString(proParam[i])); else valueElement.setNil(true); resParam.getValueElementList().add(valueElement); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof CharParam) { final CharParam reqCharParam = (CharParam) reqParam; if (ParamMode.INPUT != reqCharParam.getMode()) { final JAXBElement<CharParam> resParamElement = new JAXBElement<CharParam>( new QName(NS, "Char"), CharParam.class, null); final CharParam resParam = OBJECT_FACTORY.createCharParam(); resParam.setId(reqCharParam.getId()); resParam.setName(reqCharParam.getName()); final String proParam = (String) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { resParam.setContent(DatatypeConverter.printString(proParam)); resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DateArrayParam) { final DateArrayParam reqDateArrayParam = (DateArrayParam) reqParam; if (ParamMode.INPUT != reqDateArrayParam.getMode()) { final JAXBElement<DateArrayParam> resParamElement = new JAXBElement<DateArrayParam>( new QName(NS, "DateArray"), DateArrayParam.class, null); final DateArrayParam resParam = OBJECT_FACTORY.createDateArrayParam(); resParam.setId(reqDateArrayParam.getId()); resParam.setName(reqDateArrayParam.getName()); final Date[] proParam = (Date[]) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { for (int i = 0; i < proParam.length; i++) { final JAXBElement<String> valueElement = new JAXBElement<String>( new QName(NS, "Value"), String.class, null); if (proParam[i] != null) { final Calendar cal = Calendar.getInstance(); cal.setTime(proParam[i]); valueElement.setValue(DatatypeConverter.printDate(cal)); } else { valueElement.setNil(true); } resParam.getValueElementList().add(valueElement); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DateParam) { final DateParam reqDateParam = (DateParam) reqParam; if (ParamMode.INPUT != reqDateParam.getMode()) { final JAXBElement<DateParam> resParamElement = new JAXBElement<DateParam>( new QName(NS, "Date"), DateParam.class, null); final DateParam resParam = OBJECT_FACTORY.createDateParam(); resParam.setId(reqDateParam.getId()); resParam.setName(reqDateParam.getName()); final Date proParam = (Date) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { final Calendar cal = Calendar.getInstance(); cal.setTime(proParam); resParam.setContent(DatatypeConverter.printDate(cal)); resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DateTimeArrayParam) { final DateTimeArrayParam reqDateTimeArrayParam = (DateTimeArrayParam) reqParam; if (ParamMode.INPUT != reqDateTimeArrayParam.getMode()) { final JAXBElement<DateTimeArrayParam> resParamElement = new JAXBElement<DateTimeArrayParam>( new QName(NS, "DateTimeArray"), DateTimeArrayParam.class, null); final DateTimeArrayParam resParam = OBJECT_FACTORY.createDateTimeArrayParam(); resParam.setId(reqDateTimeArrayParam.getId()); resParam.setName(reqDateTimeArrayParam.getName()); final GregorianCalendar[] proParam = (GregorianCalendar[]) proParams .getOutputParameter(resParam.getId()); if (proParam != null) { for (int i = 0; i < proParam.length; i++) { final JAXBElement<String> valueElement = new JAXBElement<String>( new QName(NS, "Value"), String.class, null); if (proParam[i] != null) valueElement.setValue(DatatypeConverter.printDateTime(proParam[i])); else valueElement.setNil(true); resParam.getValueElementList().add(valueElement); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DateTimeParam) { final DateTimeParam reqDateTimeParam = (DateTimeParam) reqParam; if (ParamMode.INPUT != reqDateTimeParam.getMode()) { final JAXBElement<DateTimeParam> resParamElement = new JAXBElement<DateTimeParam>( new QName(NS, "DateTime"), DateTimeParam.class, null); final DateTimeParam resParam = OBJECT_FACTORY.createDateTimeParam(); resParam.setId(reqDateTimeParam.getId()); resParam.setName(reqDateTimeParam.getName()); final GregorianCalendar proParam = (GregorianCalendar) proParams .getOutputParameter(resParam.getId()); if (proParam != null) { resParam.setContent(DatatypeConverter.printDateTime(proParam)); resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DateTimeTZArrayParam) { final DateTimeTZArrayParam reqDateTimeTZArrayParam = (DateTimeTZArrayParam) reqParam; if (ParamMode.INPUT != reqDateTimeTZArrayParam.getMode()) { final JAXBElement<DateTimeTZArrayParam> resParamElement = new JAXBElement<DateTimeTZArrayParam>( new QName(NS, "DateTimeTZArray"), DateTimeTZArrayParam.class, null); final DateTimeTZArrayParam resParam = OBJECT_FACTORY.createDateTimeTZArrayParam(); resParam.setId(reqDateTimeTZArrayParam.getId()); resParam.setName(reqDateTimeTZArrayParam.getName()); final GregorianCalendar[] proParam = (GregorianCalendar[]) proParams .getOutputParameter(resParam.getId()); if (proParam != null) { for (int i = 0; i < proParam.length; i++) { final JAXBElement<String> valueElement = new JAXBElement<String>( new QName(NS, "Value"), String.class, null); if (proParam[i] != null) valueElement.setValue(DatatypeConverter.printDateTime(proParam[i])); else valueElement.setNil(true); resParam.getValueElementList().add(valueElement); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DateTimeTZParam) { final DateTimeTZParam reqDateTimeTZParam = (DateTimeTZParam) reqParam; if (ParamMode.INPUT != reqDateTimeTZParam.getMode()) { final JAXBElement<DateTimeTZParam> resParamElement = new JAXBElement<DateTimeTZParam>( new QName(NS, "DateTimeTZ"), DateTimeTZParam.class, null); final DateTimeTZParam resParam = OBJECT_FACTORY.createDateTimeTZParam(); resParam.setId(reqDateTimeTZParam.getId()); resParam.setName(reqDateTimeTZParam.getName()); final GregorianCalendar proParam = (GregorianCalendar) proParams .getOutputParameter(resParam.getId()); if (proParam != null) { resParam.setContent(DatatypeConverter.printDateTime(proParam)); resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DecArrayParam) { final DecArrayParam reqDecArrayParam = (DecArrayParam) reqParam; if (ParamMode.INPUT != reqDecArrayParam.getMode()) { final JAXBElement<DecArrayParam> resParamElement = new JAXBElement<DecArrayParam>( new QName(NS, "DecArray"), DecArrayParam.class, null); final DecArrayParam resParam = OBJECT_FACTORY.createDecArrayParam(); resParam.setId(reqDecArrayParam.getId()); resParam.setName(reqDecArrayParam.getName()); final BigDecimal[] proParam = (BigDecimal[]) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { for (int i = 0; i < proParam.length; i++) { final JAXBElement<String> valueElement = new JAXBElement<String>( new QName(NS, "Value"), String.class, null); if (proParam[i] != null) valueElement.setValue(DatatypeConverter.printDecimal(proParam[i])); else valueElement.setNil(true); resParam.getValueElementList().add(valueElement); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof DecParam) { final DecParam reqDecParam = (DecParam) reqParam; if (ParamMode.INPUT != reqDecParam.getMode()) { final JAXBElement<DecParam> resParamElement = new JAXBElement<DecParam>( new QName(NS, "Dec"), DecParam.class, null); final DecParam resParam = OBJECT_FACTORY.createDecParam(); resParam.setId(reqDecParam.getId()); resParam.setName(reqDecParam.getName()); final BigDecimal proParam = (BigDecimal) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { resParam.setContent(DatatypeConverter.printDecimal(proParam)); resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof IntArrayParam) { final IntArrayParam reqIntArrayParam = (IntArrayParam) reqParam; if (ParamMode.INPUT != reqIntArrayParam.getMode()) { final JAXBElement<IntArrayParam> resParamElement = new JAXBElement<IntArrayParam>( new QName(NS, "IntArray"), IntArrayParam.class, null); final IntArrayParam resParam = OBJECT_FACTORY.createIntArrayParam(); resParam.setId(reqIntArrayParam.getId()); resParam.setName(reqIntArrayParam.getName()); final Integer[] proParam = (Integer[]) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { for (int i = 0; i < proParam.length; i++) { final JAXBElement<String> valueElement = new JAXBElement<String>( new QName(NS, "Value"), String.class, null); if (proParam[i] != null) valueElement.setValue(DatatypeConverter.printInt(proParam[i])); else valueElement.setNil(true); resParam.getValueElementList().add(valueElement); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof IntParam) { final IntParam reqIntParam = (IntParam) reqParam; if (ParamMode.INPUT != reqIntParam.getMode()) { final JAXBElement<IntParam> resParamElement = new JAXBElement<IntParam>( new QName(NS, "Int"), IntParam.class, null); final IntParam resParam = OBJECT_FACTORY.createIntParam(); resParam.setId(reqIntParam.getId()); resParam.setName(reqIntParam.getName()); final Integer proParam = (Integer) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { resParam.setContent(DatatypeConverter.printInt(proParam)); resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof LogArrayParam) { final LogArrayParam reqLogArrayParam = (LogArrayParam) reqParam; if (ParamMode.INPUT != reqLogArrayParam.getMode()) { final JAXBElement<LogArrayParam> resParamElement = new JAXBElement<LogArrayParam>( new QName(NS, "LogArray"), LogArrayParam.class, null); final LogArrayParam resParam = OBJECT_FACTORY.createLogArrayParam(); resParam.setId(reqLogArrayParam.getId()); resParam.setName(reqLogArrayParam.getName()); final Boolean[] proParam = (Boolean[]) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { for (int i = 0; i < proParam.length; i++) { final JAXBElement<String> valueElement = new JAXBElement<String>( new QName(NS, "Value"), String.class, null); if (proParam[i] != null) valueElement.setValue(DatatypeConverter.printBoolean(proParam[i])); else valueElement.setNil(true); resParam.getValueElementList().add(valueElement); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof LogParam) { final LogParam reqLogParam = (LogParam) reqParam; if (ParamMode.INPUT != reqLogParam.getMode()) { final JAXBElement<LogParam> resParamElement = new JAXBElement<LogParam>( new QName(NS, "Log"), LogParam.class, null); final LogParam resParam = OBJECT_FACTORY.createLogParam(); resParam.setId(reqLogParam.getId()); resParam.setName(reqLogParam.getName()); final Boolean proParam = (Boolean) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { resParam.setContent(DatatypeConverter.printBoolean(proParam)); resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } else if (reqParam instanceof ResultSetParam) { final ResultSetParam reqResultSetParam = (ResultSetParam) reqParam; if (ParamMode.INPUT != reqResultSetParam.getMode()) { final JAXBElement<ResultSetParam> resParamElement = new JAXBElement<ResultSetParam>( new QName(NS, "ResultSet"), ResultSetParam.class, null); final ResultSetParam resParam = OBJECT_FACTORY.createResultSetParam(); resParam.setId(reqResultSetParam.getId()); resParam.setName(reqResultSetParam.getName()); final ProResultSet proParam = (ProResultSet) proParams.getOutputParameter(resParam.getId()); if (proParam != null) { while (proParam.next()) { final Row row = OBJECT_FACTORY.createRow(); final ResultSetMetaData rsMetaData = reqResultSetParam.getResultSetMetaData(); for (final Serializable fieldMetaData : rsMetaData.getFieldMetaDataList()) { if (fieldMetaData instanceof CharFieldMetaData) { final CharFieldMetaData charFieldMetaData = (CharFieldMetaData) fieldMetaData; final int extent = charFieldMetaData.getExtent(); if (extent < 1) { final JAXBElement<CharField> fieldElement = new JAXBElement<CharField>( new QName(NS, "Char"), CharField.class, null); final CharField field = OBJECT_FACTORY.createCharField(); field.setId(charFieldMetaData.getId()); field.setName(charFieldMetaData.getName()); final String value = proParam.getString(field.getId()); if (value != null) { field.setContent(DatatypeConverter.printString(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } else { for (int i = 1; i <= extent; i++) { final JAXBElement<CharField> fieldElement = new JAXBElement<CharField>( new QName(NS, "Char"), CharField.class, null); final CharField field = OBJECT_FACTORY.createCharField(); field.setId(charFieldMetaData.getId()); field.setName(charFieldMetaData.getName()); final String value = proParam.getString(field.getId(), i); if (value != null) { field.setContent(DatatypeConverter.printString(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } } } else if (fieldMetaData instanceof DateFieldMetaData) { final DateFieldMetaData dateFieldMetaData = (DateFieldMetaData) fieldMetaData; final int extent = dateFieldMetaData.getExtent(); if (extent < 1) { final JAXBElement<DateField> fieldElement = new JAXBElement<DateField>( new QName(NS, "Date"), DateField.class, null); final DateField field = OBJECT_FACTORY.createDateField(); field.setId(dateFieldMetaData.getId()); field.setName(dateFieldMetaData.getName()); final Date value = proParam.getDate(field.getId()); if (value != null) { final Calendar cal = Calendar.getInstance(); cal.setTime(value); field.setContent(DatatypeConverter.printDate(cal)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } else { for (int i = 1; i <= extent; i++) { final JAXBElement<DateField> fieldElement = new JAXBElement<DateField>( new QName(NS, "Date"), DateField.class, null); final DateField field = OBJECT_FACTORY.createDateField(); field.setId(dateFieldMetaData.getId()); field.setName(dateFieldMetaData.getName()); final Date value = proParam.getDate(field.getId(), i); if (value != null) { final Calendar cal = Calendar.getInstance(); cal.setTime(value); field.setContent(DatatypeConverter.printDate(cal)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } } } else if (fieldMetaData instanceof DateTimeFieldMetaData) { final DateTimeFieldMetaData dateTimeFieldMetaData = (DateTimeFieldMetaData) fieldMetaData; final int extent = dateTimeFieldMetaData.getExtent(); if (extent < 1) { final JAXBElement<DateTimeField> fieldElement = new JAXBElement<DateTimeField>( new QName(NS, "DateTime"), DateTimeField.class, null); final DateTimeField field = OBJECT_FACTORY.createDateTimeField(); field.setId(dateTimeFieldMetaData.getId()); field.setName(dateTimeFieldMetaData.getName()); final GregorianCalendar value = (GregorianCalendar) proParam .getObject(field.getId()); if (value != null) { field.setContent(DatatypeConverter.printDateTime(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } else { for (int i = 1; i <= extent; i++) { final JAXBElement<DateTimeField> fieldElement = new JAXBElement<DateTimeField>( new QName(NS, "DateTime"), DateTimeField.class, null); final DateTimeField field = OBJECT_FACTORY.createDateTimeField(); field.setId(dateTimeFieldMetaData.getId()); field.setName(dateTimeFieldMetaData.getName()); final GregorianCalendar value = (GregorianCalendar) proParam .getObject(field.getId(), i); if (value != null) { field.setContent(DatatypeConverter.printDateTime(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } } } else if (fieldMetaData instanceof DateTimeTZFieldMetaData) { final DateTimeTZFieldMetaData dateTimeTZFieldMetaData = (DateTimeTZFieldMetaData) fieldMetaData; final int extent = dateTimeTZFieldMetaData.getExtent(); if (extent < 1) { final JAXBElement<DateTimeTZField> fieldElement = new JAXBElement<DateTimeTZField>( new QName(NS, "DateTimeTZ"), DateTimeTZField.class, null); final DateTimeTZField field = OBJECT_FACTORY.createDateTimeTZField(); field.setId(dateTimeTZFieldMetaData.getId()); field.setName(dateTimeTZFieldMetaData.getName()); final GregorianCalendar value = (GregorianCalendar) proParam .getObject(field.getId()); if (value != null) { field.setContent(DatatypeConverter.printDateTime(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } else { for (int i = 1; i <= extent; i++) { final JAXBElement<DateTimeTZField> fieldElement = new JAXBElement<DateTimeTZField>( new QName(NS, "DateTimeTZ"), DateTimeTZField.class, null); final DateTimeTZField field = OBJECT_FACTORY .createDateTimeTZField(); field.setId(dateTimeTZFieldMetaData.getId()); field.setName(dateTimeTZFieldMetaData.getName()); final GregorianCalendar value = (GregorianCalendar) proParam .getObject(field.getId(), i); if (value != null) { field.setContent(DatatypeConverter.printDateTime(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } } } else if (fieldMetaData instanceof DecFieldMetaData) { final DecFieldMetaData decFieldMetaData = (DecFieldMetaData) fieldMetaData; final int extent = decFieldMetaData.getExtent(); if (extent < 1) { final JAXBElement<DecField> fieldElement = new JAXBElement<DecField>( new QName(NS, "Dec"), DecField.class, null); final DecField field = OBJECT_FACTORY.createDecField(); field.setId(decFieldMetaData.getId()); field.setName(decFieldMetaData.getName()); final BigDecimal value = proParam.getBigDecimal(field.getId()); if (value != null) { field.setContent(DatatypeConverter.printDecimal(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } else { for (int i = 1; i <= extent; i++) { final JAXBElement<DecField> fieldElement = new JAXBElement<DecField>( new QName(NS, "Dec"), DecField.class, null); final DecField field = OBJECT_FACTORY.createDecField(); field.setId(decFieldMetaData.getId()); field.setName(decFieldMetaData.getName()); final BigDecimal value = proParam.getBigDecimal(field.getId(), i, 0); if (value != null) { field.setContent(DatatypeConverter.printDecimal(value)); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } } } else if (fieldMetaData instanceof IntFieldMetaData) { final IntFieldMetaData intFieldMetaData = (IntFieldMetaData) fieldMetaData; final int extent = intFieldMetaData.getExtent(); if (extent < 1) { final JAXBElement<IntField> fieldElement = new JAXBElement<IntField>( new QName(NS, "Int"), IntField.class, null); final IntField field = OBJECT_FACTORY.createIntField(); field.setId(intFieldMetaData.getId()); field.setName(intFieldMetaData.getName()); final String value = proParam.getString(field.getId()); if (value != null) { field.setContent( DatatypeConverter.printInt(Integer.parseInt(value))); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } else { for (int i = 1; i <= extent; i++) { final JAXBElement<IntField> fieldElement = new JAXBElement<IntField>( new QName(NS, "Int"), IntField.class, null); final IntField field = OBJECT_FACTORY.createIntField(); field.setId(intFieldMetaData.getId()); field.setName(intFieldMetaData.getName()); final String value = proParam.getString(field.getId(), i); if (value != null) { field.setContent( DatatypeConverter.printInt(Integer.parseInt(value))); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } } } else if (fieldMetaData instanceof LogFieldMetaData) { final LogFieldMetaData logFieldMetaData = (LogFieldMetaData) fieldMetaData; final int extent = logFieldMetaData.getExtent(); if (extent < 1) { final JAXBElement<LogField> fieldElement = new JAXBElement<LogField>( new QName(NS, "Log"), LogField.class, null); final LogField field = OBJECT_FACTORY.createLogField(); field.setId(logFieldMetaData.getId()); field.setName(logFieldMetaData.getName()); final String value = proParam.getString(field.getId()); if (value != null) { field.setContent( DatatypeConverter.printBoolean(Boolean.valueOf(value))); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } else { for (int i = 1; i <= extent; i++) { final JAXBElement<LogField> fieldElement = new JAXBElement<LogField>( new QName(NS, "Log"), LogField.class, null); final LogField field = OBJECT_FACTORY.createLogField(); field.setId(logFieldMetaData.getId()); field.setName(logFieldMetaData.getName()); final String value = proParam.getString(field.getId(), i); if (value != null) { field.setContent( DatatypeConverter.printBoolean(Boolean.valueOf(value))); fieldElement.setValue(field); } else { fieldElement.setNil(true); } row.getFieldElementList().add(fieldElement); } } } } resParam.getRowList().add(row); } resParamElement.setValue(resParam); } else { resParamElement.setNil(true); } res.getParamElementList().add(resParamElement); } } } final Document doc = builder.newDocument(); marshaller.marshal(res, doc); exchange.getOut().setBody(doc); } catch (final RunTime4GLErrorException e) { LOG.error(e.getProcReturnString(), e); throw new OpenEdgeException(e.getProcReturnString(), e); } }
From source file:com.bluexml.xforms.controller.mapping.MappingToolCommon.java
/** * Gets the date time from date and time. * // ww w. j a v a 2 s .c om * @param date * the date * @param time * the time * @return the date time from date and time */ protected String getDateTimeFromDateAndTime(String date, String time) { DateTime rdate = new DateTime(DatatypeConverter.parseDate(date)); DateTime rtime = new DateTime(DatatypeConverter.parseTime(time)); long millis = rdate.getMillis() - rdate.getMillisOfDay() + rtime.getMillisOfDay(); return DateTimeConverter.convert_XFormsToAlfresco_DateTime(millis); }
From source file:de.escidoc.core.test.EscidocTestBase.java
/** * Gets the last-modification-date attribute of the root element from the document. * //w w w. j a va 2 s . c o m * @param document * The document to retrieve the value from. * @return Returns the attribute value. * @throws Exception * If anything fails. */ public static DateTime getLastModificationDateValue2(final Document document) throws Exception { String dateString = getRootElementAttributeValue(document, "last-modification-date"); if (dateString == null) { return null; } final Calendar calendar = DatatypeConverter.parseDate(dateString); return new DateTime(calendar.getTimeInMillis(), DateTimeZone.forTimeZone(calendar.getTimeZone())); }
From source file:org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.AbstractFeatureConverter.java
protected Date parseDateFromXml(HierarchicalStreamReader reader) { Date date = null;// w w w . j a v a 2 s. com boolean processingChildNode = false; if (reader.hasMoreChildren()) { reader.moveDown(); processingChildNode = true; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("node name: {}", reader.getNodeName()); LOGGER.debug("value: {}", reader.getValue()); } if (StringUtils.isBlank(reader.getValue())) { date = null; if (processingChildNode) { reader.moveUp(); } return date; } try { // trying to parse xsd:date date = DatatypeConverter.parseDate(reader.getValue()).getTime(); } catch (IllegalArgumentException e) { LOGGER.debug("Unable to parse date, attempting to parse as xsd:dateTime, Exception was {}", e); try { // try to parse it as a xsd:dateTime date = DatatypeConverter.parseDateTime(reader.getValue()).getTime(); } catch (IllegalArgumentException ie) { LOGGER.debug("Unable to parse date from XML; defaulting \"{}\" to current datetime. Exception {}", reader.getNodeName(), ie); date = new Date(); } } if (processingChildNode) { reader.moveUp(); processingChildNode = false; } LOGGER.debug("node name: {}", reader.getNodeName()); return date; }
From source file:org.codice.ddf.spatial.ogc.wfs.transformer.handlebars.HandlebarsWfsFeatureTransformer.java
private Serializable getValueForAttributeFormat(AttributeType.AttributeFormat attributeFormat, final String value) { Serializable serializable = null; switch (attributeFormat) { case BOOLEAN: serializable = Boolean.valueOf(value); break;/*from ww w . ja v a 2 s . c om*/ case DOUBLE: serializable = Double.valueOf(value); break; case FLOAT: serializable = Float.valueOf(value); break; case INTEGER: serializable = Integer.valueOf(value); break; case LONG: serializable = Long.valueOf(value); break; case SHORT: serializable = Short.valueOf(value); break; case XML: case STRING: serializable = value; break; case GEOMETRY: LOGGER.trace("Unescape the geometry: {}", value); String newValue = StringEscapeUtils.unescapeXml(value); LOGGER.debug("Geometry value after it has been xml unescaped: {}", newValue); String wkt = getWktFromGeometry(newValue); LOGGER.debug("String wkt value: {}", wkt); serializable = wkt; break; case BINARY: serializable = value.getBytes(StandardCharsets.UTF_8); break; case DATE: try { serializable = DatatypeConverter.parseDate(value).getTime(); } catch (IllegalArgumentException e) { LOGGER.debug("Error converting value to a date. value: '{}'", value, e); } break; default: break; } return serializable; }
From source file:org.eclipse.skalli.core.rest.JSONRestReader.java
@Override public Calendar valueDate() throws IOException { assertNotFinal();/*w w w .ja v a 2s . c o m*/ skipKey(); Calendar value = json.peek() != JsonToken.NULL ? DatatypeConverter.parseDate(valueString()) : null; sequenceState = EXPECT_KEY; return value; }
From source file:org.kalypso.zml.core.base.request.MetadataRequestHandler.java
private Date getFromMetadata(final MetadataList metadata, final String url) { final RETokenizer tokenizer = new RETokenizer(PATTERN_METADATA_DATE, url); final String key = tokenizer.nextToken(); final String property = metadata.getProperty(key); if (StringUtils.isEmpty(property)) return null; final Calendar calendar = DatatypeConverter.parseDate(property); return calendar.getTime(); }
From source file:org.kalypso.zml.core.diagram.base.ZmlLayerProviders.java
public static Date getMetadataDate(final String key, final MetadataList metadata) { final RETokenizer tokenizer = new RETokenizer(PATTERN_METADATE_DATE, key); final String mdKey = tokenizer.nextToken(); // FIXME: error handling if property is missing final String property = metadata.getProperty(mdKey); if (StringUtils.isBlank(property)) return null; final Calendar calendar = DatatypeConverter.parseDate(property); return calendar.getTime(); }