List of usage examples for javax.xml.datatype XMLGregorianCalendar toGregorianCalendar
public abstract GregorianCalendar toGregorianCalendar();
From source file:it.txt.access.capability.revocation.test.RevocationServiceTest.java
@Test public void testPut() throws UnsupportedEncodingException, IOException, JAXBException { IoTTestForPUT test = new IoTTestForPUT(); System.out.println("**********************************************************"); System.out.println("* NPR400 : BAD NOTIFICATION (at least one missing element*"); System.out.println("**********************************************************"); StringEntity input0 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR400"))); String url0 = System.getProperty("URL_NPR400"); String result0 = test.testPut(url0, input0); assertEquals(StatusCode.NPR400, result0); System.out.println("**********************************************************"); System.out.println("* NPR404 : REVOCATION NOT FOUND *"); System.out.println("**********************************************************"); StringEntity input1 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR404"))); String url1 = System.getProperty("URL_NPR404"); String result1 = test.testPut(url1, input1); assertEquals(StatusCode.NPR404, result1); System.out.println("**********************************************************"); System.out.println("* NPR450 : BAD REVOCATION PROCESSING STATUS CODE *"); System.out.println("**********************************************************"); StringEntity input2 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR450"))); String url2 = System.getProperty("URL_NPR450"); String result2 = test.testPut(url2, input2); assertEquals(StatusCode.NPR450, result2); System.out.println("**********************************************************"); System.out.println("* NPR451 : BAD RESOLUTION ISTANT *"); System.out.println("**********************************************************"); StringEntity input3 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR451"))); String url3 = System.getProperty("URL_NPR451"); String result3 = test.testPut(url3, input3); assertEquals(StatusCode.NPR451, result3); System.out.println("**********************************************************"); System.out.println("* NPR452 : BAD REVOCATION PROCESSING STATUS *"); System.out.println("**********************************************************"); StringEntity input4 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR452"))); String url4 = System.getProperty("URL_NPR452"); String result4 = test.testPut(url4, input4); assertEquals(StatusCode.NPR452, result4); System.out.println("**********************************************************"); System.out.println("* NPR200 : OK *"); System.out.println("**********************************************************"); IoTTestForPOST testa = new IoTTestForPOST(); StringEntity inp = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP201"))); String res = testa.testPost(inp); assertNotNull(res);/* ww w . j ava2 s . co m*/ DataMapper delete = new DataMapper(); delete.clearPendingIndex(); StringEntity input5 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR200"))); String url5 = System.getProperty("URL_NPR200"); String result5 = test.testPut(url5, input5); assertEquals(StatusCode.NPR200, result5); ODatabaseDocumentTx capRevDb = new ODatabaseDocumentTx(Constants.revocationDBUrl).open(Constants.iUserName, Constants.iUserPassword); String querySelRev = "select statusCode, status, processedOn from " + Constants.REVOCATION_CLASS + " where " + Constants.REVOCATION_ID + " = '_e49af3ee828b03a32c39df493cf4c674'"; List<ODocument> rev = capRevDb.command(new OCommandSQL(querySelRev)).execute(); ODocument element = rev.get(0); assertEquals(element.field(Constants.STATUS), "ACCEPTED"); assertEquals(element.field(Constants.STATUS_CODE), StatusCode.NPR200); String processedOn = null; try { XMLGregorianCalendar cal = DatatypeFactory.newInstance() .newXMLGregorianCalendar("2012-03-30T09:35:58.011+02:00"); Date gCal = cal.toGregorianCalendar().getTime(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); processedOn = sdf.format(gCal.getTime()); } catch (Exception e) { } String date = null; try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); date = sdf.format(element.field(Constants.PROCESSED_ON)); } catch (Exception e) { } assertEquals(date, processedOn); }
From source file:mvm.rya.indexing.accumulo.temporal.AccumuloTemporalIndexer.java
/** * parse the literal dates from the object of a statement. * * @param statement//w w w.j a v a 2 s . c om * @param outputDateTimes */ private void extractDateTime(Statement statement, DateTime[] outputDateTimes) { if (!(statement.getObject() instanceof Literal)) // Error since it should already be tested by caller. throw new RuntimeException("Statement's object must be a literal: " + statement); // throws IllegalArgumentException NumberFormatException if can't parse String logThis = null; Literal literalValue = (Literal) statement.getObject(); // First attempt to parse a interval in the form "[date1,date2]" Matcher matcher = Pattern.compile("\\[(.*)\\,(.*)\\].*").matcher(literalValue.stringValue()); if (matcher.find()) { try { // Got a datetime pair, parse into an interval. outputDateTimes[0] = new DateTime(matcher.group(1)); outputDateTimes[1] = new DateTime(matcher.group(2)); return; } catch (java.lang.IllegalArgumentException e) { logThis = e.getMessage() + " " + logThis; outputDateTimes[0] = null; outputDateTimes[1] = null; } } try { XMLGregorianCalendar calendarValue = literalValue.calendarValue(); outputDateTimes[0] = new DateTime(calendarValue.toGregorianCalendar()); outputDateTimes[1] = null; return; } catch (java.lang.IllegalArgumentException e) { logThis = e.getMessage(); } // Try again using Joda Time DateTime.parse() try { outputDateTimes[0] = DateTime.parse(literalValue.stringValue()); outputDateTimes[1] = null; //System.out.println(">>>>>>>Joda parsed: "+literalValue.stringValue()); return; } catch (java.lang.IllegalArgumentException e) { logThis = e.getMessage() + " " + logThis; } logger.warn("TemporalIndexer is unable to parse the date/time from statement=" + statement.toString() + " " + logThis); return; }
From source file:com.microsoft.exchange.impl.ExchangeEventConverterImpl.java
/** * //from w w w .ja va 2 s. c o m * TimeZones. * * @param calendarItem * @param upn * @return * @throws ExchangeEventConverterException */ protected Pair<VEvent, ArrayList<VTimeZone>> convertCalendarItemType(CalendarItemType calendarItem, String upn) throws ExchangeEventConverterException { VEvent event = new VEvent(); ArrayList<VTimeZone> timeZones = new ArrayList<VTimeZone>(); if (calendarItem.getStart() == null) { throw new ExchangeEventConverterException("calendarItem must have a valid start time."); } if (calendarItem.getEnd() == null && calendarItem.getDuration() == null) { throw new ExchangeEventConverterException("calendarItem must have a valid end time or duration."); } //does this element have a timezone? XMLGregorianCalendar start = calendarItem.getStart(); DtStart dtStart = new DtStart(new DateTime(start.toGregorianCalendar().getTime())); DtEnd dtEnd = null; if (null != calendarItem.getEnd()) { dtEnd = new DtEnd(new DateTime(calendarItem.getEnd().toGregorianCalendar().getTime())); } //if all day event, must use Date if (null != calendarItem.isIsAllDayEvent() && calendarItem.isIsAllDayEvent()) { dtStart = new DtStart(new Date(start.toGregorianCalendar().getTime()), true); dtEnd = new DtEnd(new Date(calendarItem.getEnd().toGregorianCalendar().getTime()), true); log.debug("set to all day event"); } //this way no vtimezone is needed dtStart.setUtc(true); event.getProperties().add(dtStart); log.debug("added dtStart=" + dtStart); if (null != dtEnd) { dtEnd.setUtc(true); event.getProperties().add(dtEnd); log.debug("added dtEnd=" + dtEnd); } //in case dtEnd is not present but duration is. String duration = calendarItem.getDuration(); if (StringUtils.isNotBlank(duration) && event.getProperty(DtEnd.DTEND) == null) { Dur dur = new Dur(duration); Duration durationProperty = new Duration(dur); event.getProperties().add(durationProperty); event.getProperties().remove(DtEnd.DTEND); log.debug("dtend overridden with duration=" + durationProperty); } String uid = calendarItem.getUID(); if (StringUtils.isNotBlank(uid)) { Uid uidProperty = new Uid(uid); event.getProperties().add(uidProperty); log.debug("added Uid=" + uidProperty); } else { log.debug("could not generate Uid property."); } //should always set dtstamp, otherwise it's auto-generated and !veventCreatedNow.equals(veventCreatedLater); if (null != calendarItem.getDateTimeCreated()) { DtStamp dtstamp = new DtStamp( new DateTime(calendarItem.getDateTimeCreated().toGregorianCalendar().getTime())); dtstamp.setUtc(true); event.getProperties().remove(event.getProperty(DtStamp.DTSTAMP)); event.getProperties().add(dtstamp); log.debug("overide DtStamp=" + dtstamp); } else { log.debug("could not generate DtStamp, property will be autogenerated."); } String subject = calendarItem.getSubject(); if (StringUtils.isNotBlank(subject)) { Summary summaryProperty = new Summary(subject); event.getProperties().add(summaryProperty); log.debug("add summary=" + summaryProperty); } else { log.debug("could not generate Summary property"); } String location = calendarItem.getLocation(); if (StringUtils.isNotBlank(location)) { event.getProperties().add(new Location(location)); } else { log.debug("could not generate location property"); } LegacyFreeBusyType freeBusy = calendarItem.getLegacyFreeBusyStatus(); Transp transpProperty = Transp.OPAQUE; if (LegacyFreeBusyType.FREE.equals(freeBusy)) { transpProperty = Transp.TRANSPARENT; } event.getProperties().add(transpProperty); log.debug("added Transp=" + transpProperty); Status status = Status.VEVENT_CONFIRMED; if (BooleanUtils.isTrue(calendarItem.isIsCancelled())) { status = Status.VEVENT_CANCELLED; } event.getProperties().add(status); log.debug("added Status=" + status); boolean organizerIsSet = false; SingleRecipientType calendarItemOrganizer = calendarItem.getOrganizer(); if (null != calendarItemOrganizer) { Organizer organizer = convertToOrganizer(calendarItemOrganizer); if (null != organizer) { event.getProperties().add(organizer); organizerIsSet = true; log.debug("added Organizer=" + organizer); } else { log.debug("could not gernate Organizer. As a result, attendees will not be added."); } } else { log.debug("could not gernate Organizer. As a result, attendees will not be added."); } //only add RequiredAttendees, OptionalAttendees and Resources if and only if organizer present. if (organizerIsSet) { ResponseTypeType myResponseType = calendarItem.getMyResponseType(); //add RequiredAttendees NonEmptyArrayOfAttendeesType requiredAttendees = calendarItem.getRequiredAttendees(); if (null != requiredAttendees) { Set<Attendee> attendees = convertRequiredAttendees(requiredAttendees, myResponseType); for (Attendee attendee : attendees) { event.getProperties().add(attendee); } } else { log.debug("no required attendees."); } //add OptionalAttendees NonEmptyArrayOfAttendeesType optionalAttendees = calendarItem.getOptionalAttendees(); if (null != optionalAttendees) { Set<Attendee> attendees = convertOptionalAttendees(optionalAttendees, myResponseType); for (Attendee attendee : attendees) { event.getProperties().add(attendee); } } else { log.debug("no optional attendees"); } //add Resources NonEmptyArrayOfAttendeesType resourceAttendees = calendarItem.getResources(); if (null != resourceAttendees) { Set<Attendee> attendees = convertResourceAttendees(resourceAttendees, myResponseType); for (Attendee attendee : attendees) { event.getProperties().add(attendee); } } } CalendarItemTypeType calendarItemType = calendarItem.getCalendarItemType(); if (null != calendarItemType) { if (CalendarItemTypeType.EXCEPTION.equals(calendarItemType) || CalendarItemTypeType.RECURRING_MASTER.equals(calendarItemType)) { log.warn( "Recurring Event Detected! This implementation of ExchangeEventConverter does not expand recurrance. You should use a CalendarView to expand recurrence on the Exchagne server. --http://msdn.microsoft.com/en-us/library/office/aa564515(v=exchg.150).aspx"); } } //generate xproperties for standard item properties Collection<XProperty> itemXProperties = generateItemTypeXProperties(calendarItem); for (XProperty xp : itemXProperties) { event.getProperties().add(xp); } //generate XProperty's for ExtendedProperties... List<ExtendedPropertyType> extendedProperties = calendarItem.getExtendedProperties(); if (!CollectionUtils.isEmpty(extendedProperties)) { for (ExtendedPropertyType extendedProperty : extendedProperties) { Collection<XProperty> xProperties = convertExtendedPropertyType(extendedProperty); for (XProperty xp : xProperties) { event.getProperties().add(xp); } } } Pair<VEvent, ArrayList<VTimeZone>> pair = Pair.of(event, timeZones); return pair; }
From source file:icom.jpa.bdk.dao.VersionSeriesToDocumentDAO.java
public void copyObjectState(ManagedObjectProxy obj, Object bdkEntity, Projection proj) { //super.copyObjectState(obj, bdkEntity, proj); Document bdkDocument = null;//from w ww. jav a 2s.c o m WikiPage bdkWikiPage = null; if (bdkEntity instanceof Document) { bdkDocument = (Document) bdkEntity; } else { bdkWikiPage = (WikiPage) bdkEntity; } Persistent pojoPersistent = obj.getPojoObject(); PersistenceContext context = obj.getPersistenceContext(); if (isPartOfProjection(VersionSeriesInfo.Attributes.versionSeriesCheckedOut.name(), proj)) { try { Boolean versionSeriesCheckedOut = null; if (bdkDocument != null) { versionSeriesCheckedOut = bdkDocument.isCheckedOut(); } else { versionSeriesCheckedOut = bdkWikiPage.isCheckedOut(); } assignAttributeValue(pojoPersistent, VersionSeriesInfo.Attributes.versionSeriesCheckedOut.name(), versionSeriesCheckedOut); } catch (Exception ex) { // ignore } } if (isPartOfProjection(VersionSeriesInfo.Attributes.versionSeriesCheckedOutBy.name(), proj)) { try { Actor bdkVersionSeriesCheckedOutBy = null; if (bdkDocument != null) { bdkVersionSeriesCheckedOutBy = bdkDocument.getCheckedOutBy(); } else { bdkVersionSeriesCheckedOutBy = bdkWikiPage.getCheckedOutBy(); } if (bdkVersionSeriesCheckedOutBy != null) { ManagedIdentifiableProxy actorObj = getEntityProxy(context, bdkVersionSeriesCheckedOutBy); Persistent pojoVersionSeriesCheckedOutBy = actorObj.getPojoIdentifiable(); assignAttributeValue(pojoPersistent, VersionSeriesInfo.Attributes.versionSeriesCheckedOutBy.name(), pojoVersionSeriesCheckedOutBy); } } catch (Exception ex) { // ignore } } if (isPartOfProjection(VersionSeriesInfo.Attributes.versionSeriesCheckedOutOn.name(), proj)) { try { try { XMLGregorianCalendar bdkCheckedOutOn = null; if (bdkDocument != null) { bdkCheckedOutOn = bdkDocument.getCheckedOutOn(); } else { bdkCheckedOutOn = bdkWikiPage.getCheckedOutOn(); } if (bdkCheckedOutOn != null) { Date versionSeriesCheckedOutOn = bdkCheckedOutOn.toGregorianCalendar().getTime(); assignAttributeValue(pojoPersistent, VersionSeriesInfo.Attributes.versionSeriesCheckedOutOn.name(), versionSeriesCheckedOutOn); } } catch (Exception ex) { // ignore } } catch (Exception ex) { // ignore } } if (isPartOfProjection(VersionSeriesInfo.Attributes.versionSeriesCheckoutComment.name(), proj)) { try { String versionSeriesCheckoutComment = null; if (bdkDocument != null) { versionSeriesCheckoutComment = bdkDocument.getCheckoutComments(); } else { versionSeriesCheckoutComment = bdkWikiPage.getCheckoutComments(); } assignAttributeValue(pojoPersistent, VersionSeriesInfo.Attributes.versionSeriesCheckoutComment.name(), versionSeriesCheckoutComment); } catch (Exception ex) { // ignore } } if (isPartOfProjection(VersionSeriesInfo.Attributes.totalSize.name(), proj)) { try { Long totalSize = null; if (bdkDocument != null) { totalSize = bdkDocument.getTotalSize(); } else { totalSize = bdkWikiPage.getTotalSize(); } assignAttributeValue(pojoPersistent, VersionSeriesInfo.Attributes.totalSize.name(), totalSize); } catch (Exception ex) { // ignore } } if (isPartOfProjection(VersionSeriesInfo.Attributes.versionHistory.name(), proj)) { try { Collection<Version> bdkVersionHistory = null; if (bdkDocument != null) { bdkVersionHistory = bdkDocument.getVersionHistories(); } else { bdkVersionHistory = bdkWikiPage.getVersionHistories(); } Vector<Persistent> v = new Vector<Persistent>(bdkVersionHistory.size()); if (bdkVersionHistory != null) { for (Version bdkVersion : bdkVersionHistory) { ManagedIdentifiableProxy childObj = getEntityProxy(context, bdkVersion); v.add(childObj.getPojoIdentifiable()); } } assignAttributeValue(pojoPersistent, VersionSeriesInfo.Attributes.versionHistory.name(), v); assignAttributeValue(pojoPersistent, VersionSeriesInfo.Attributes.latestVersion.name(), v.lastElement()); } catch (Exception ex) { // ignore } } Object bdkLatestVersionableInHistory = null; if (isPartOfProjection(VersionSeriesInfo.Attributes.versionableHistory.name(), proj)) { try { Collection<Object> bdkVersionableHistory = null; if (bdkDocument != null) { bdkVersionableHistory = bdkDocument.getVersionableHistories(); } else { bdkVersionableHistory = bdkWikiPage.getVersionableHistories(); } Vector<Persistent> pojoVersionableHistory = new Vector<Persistent>(bdkVersionableHistory.size()); if (bdkVersionableHistory != null) { for (Object bdkVersionable : bdkVersionableHistory) { ManagedIdentifiableProxy childObj = getEntityProxy(context, bdkVersionable); pojoVersionableHistory.add(childObj.getPojoIdentifiable()); bdkLatestVersionableInHistory = bdkVersionable; } } assignAttributeValue(pojoPersistent, VersionSeriesInfo.Attributes.versionableHistory.name(), pojoVersionableHistory); } catch (Exception ex) { // ignore } } if (isPartOfProjection(VersionSeriesInfo.Attributes.latestVersionedCopy.name(), proj)) { try { Persistent pojoLatestVersionedCopy = null; Object bdkRepresentativeVersionable = null; if (bdkDocument != null) { bdkRepresentativeVersionable = bdkDocument.getRepresentativeVersionable(); } else { bdkRepresentativeVersionable = bdkWikiPage.getRepresentativeVersionable(); } if (bdkRepresentativeVersionable != null) { if (bdkLatestVersionableInHistory != null) { String bdkRepresentativeVersionableId = null; String bdkLatestVersionableInHistoryId = null; if (bdkRepresentativeVersionable instanceof Document || bdkRepresentativeVersionable instanceof WikiPage) { bdkRepresentativeVersionableId = ((Artifact) bdkRepresentativeVersionable).getCollabId() .getId(); } if (bdkLatestVersionableInHistory instanceof Document || bdkLatestVersionableInHistory instanceof WikiPage) { bdkLatestVersionableInHistoryId = ((Artifact) bdkLatestVersionableInHistory) .getCollabId().getId(); } if (bdkRepresentativeVersionableId.equals(bdkLatestVersionableInHistoryId)) { ManagedIdentifiableProxy childObj = getEntityProxy(context, bdkRepresentativeVersionable); pojoLatestVersionedCopy = childObj.getPojoIdentifiable(); } else { ManagedIdentifiableProxy childObj = getEntityProxy(context, bdkLatestVersionableInHistory); pojoLatestVersionedCopy = childObj.getPojoIdentifiable(); } } } assignAttributeValue(pojoPersistent, VersionSeriesInfo.Attributes.latestVersionedCopy.name(), pojoLatestVersionedCopy); } catch (Exception ex) { // ignore } } if (isPartOfProjection(VersionSeriesInfo.Attributes.privateWorkingCopy.name(), proj)) { try { Persistent pojoPrivateWorkingCopy = null; Object bdkRepresentativeVersionable = null; if (bdkDocument != null) { bdkRepresentativeVersionable = bdkDocument.getRepresentativeVersionable(); } else { bdkRepresentativeVersionable = bdkWikiPage.getRepresentativeVersionable(); } if (bdkRepresentativeVersionable != null) { if (bdkLatestVersionableInHistory != null) { String bdkRepresentativeVersionableId = null; String bdkLatestVersionableInHistoryId = null; if (bdkRepresentativeVersionable instanceof Document || bdkRepresentativeVersionable instanceof WikiPage) { bdkRepresentativeVersionableId = ((Artifact) bdkRepresentativeVersionable).getCollabId() .getId(); } if (bdkLatestVersionableInHistory instanceof Document || bdkLatestVersionableInHistory instanceof WikiPage) { bdkLatestVersionableInHistoryId = ((Artifact) bdkLatestVersionableInHistory) .getCollabId().getId(); } if (!bdkRepresentativeVersionableId.equals(bdkLatestVersionableInHistoryId)) { ManagedIdentifiableProxy childObj = getEntityProxy(context, bdkRepresentativeVersionable); pojoPrivateWorkingCopy = childObj.getPojoIdentifiable(); } } } assignAttributeValue(pojoPersistent, VersionSeriesInfo.Attributes.privateWorkingCopy.name(), pojoPrivateWorkingCopy); } catch (Exception ex) { // ignore } } if (isPartOfProjection(VersionSeriesInfo.Attributes.representativeCopy.name(), proj)) { try { Persistent pojoRepresentativeCopy = null; Object bdkFamilyVersionable = null; if (bdkDocument != null) { bdkFamilyVersionable = bdkDocument.getParentFamily(); } else { bdkFamilyVersionable = bdkWikiPage.getParentFamily(); } if (bdkFamilyVersionable != null) { ManagedIdentifiableProxy childObj = getEntityProxy(context, bdkFamilyVersionable); pojoRepresentativeCopy = childObj.getPojoIdentifiable(); } assignAttributeValue(pojoPersistent, VersionSeriesInfo.Attributes.representativeCopy.name(), pojoRepresentativeCopy); } catch (Exception ex) { // ignore } } }
From source file:be.fedict.eid.tsl.TrustServiceList.java
public Date getIssueDate() { if (null == this.trustStatusList) { return null; }//from w ww. j a v a 2 s.c om TSLSchemeInformationType tslSchemeInformation = this.trustStatusList.getSchemeInformation(); XMLGregorianCalendar xmlGregorianCalendar = tslSchemeInformation.getListIssueDateTime(); return xmlGregorianCalendar.toGregorianCalendar().getTime(); }
From source file:be.fedict.eid.tsl.TrustServiceList.java
public DateTime getNextUpdate() { if (null == this.trustStatusList) { return null; }/*from ww w.ja v a 2 s . c o m*/ TSLSchemeInformationType schemeInformation = this.trustStatusList.getSchemeInformation(); if (null == schemeInformation) { return null; } NextUpdateType nextUpdate = schemeInformation.getNextUpdate(); if (null == nextUpdate) { return null; } XMLGregorianCalendar nextUpdateXmlCalendar = nextUpdate.getDateTime(); DateTime nextUpdateDateTime = new DateTime(nextUpdateXmlCalendar.toGregorianCalendar()); return nextUpdateDateTime; }
From source file:org.motechproject.mobile.omp.manager.intellivr.IntellIVRBean.java
private Date toDate(XMLGregorianCalendar time) { return time == null ? null : time.toGregorianCalendar().getTime(); }
From source file:be.fedict.eid.tsl.TrustServiceList.java
public DateTime getListIssueDateTime() { if (null == this.trustStatusList) { return null; }//www . ja va 2s. co m TSLSchemeInformationType schemeInformation = this.trustStatusList.getSchemeInformation(); if (null == schemeInformation) { return null; } XMLGregorianCalendar listIssueDateTime = schemeInformation.getListIssueDateTime(); if (null == listIssueDateTime) { return null; } GregorianCalendar listIssueCalendar = listIssueDateTime.toGregorianCalendar(); DateTime dateTime = new DateTime(listIssueCalendar); return dateTime; }
From source file:eu.europa.ec.markt.dss.validation102853.xades.XAdESSignature.java
@Override public Date getSigningTime() { try {//from ww w . ja v a 2 s .c o m final Element signingTimeEl = DSSXMLUtils.getElement(signatureElement, XPATH_SIGNING_TIME); if (signingTimeEl == null) { return null; } final String text = signingTimeEl.getTextContent(); final DatatypeFactory factory = DatatypeFactory.newInstance(); final XMLGregorianCalendar cal = factory.newXMLGregorianCalendar(text); return cal.toGregorianCalendar().getTime(); } catch (DOMException e) { throw new RuntimeException(e); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } }
From source file:ddf.catalog.pubsub.PredicateTest.java
@Test public void testTemporalNullMetadata() throws Exception { String methodName = "testTemporalNullMetadata"; LOGGER.debug("*************** START: " + methodName + " *****************"); MockQuery query = new MockQuery(); DatatypeFactory df = DatatypeFactory.newInstance(); XMLGregorianCalendar start = df.newXMLGregorianCalendarDate(2011, 10, 25, 0); XMLGregorianCalendar end = df.newXMLGregorianCalendarDate(2011, 10, 27, 0); query.addTemporalFilter(start, end, Metacard.EFFECTIVE); SubscriptionFilterVisitor visitor = new SubscriptionFilterVisitor(); Predicate pred = (Predicate) query.getFilter().accept(visitor, null); LOGGER.debug("resulting predicate: " + pred); Filter filter = query.getFilter(); FilterTransformer transform = new FilterTransformer(); transform.setIndentation(2);// ww w. jav a 2s .c om String filterXml = transform.transform(filter); LOGGER.debug(filterXml); // input that passes temporal LOGGER.debug("\npass temporal.\n"); MetacardImpl metacard = new MetacardImpl(); metacard.setCreatedDate(new Date()); metacard.setExpirationDate(new Date()); metacard.setModifiedDate(new Date()); XMLGregorianCalendar cal = df.newXMLGregorianCalendarDate(2011, 10, 26, 0); Date effectiveDate = cal.toGregorianCalendar().getTime(); metacard.setEffectiveDate(effectiveDate); HashMap<String, Object> properties = new HashMap<>(); properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE); // no contextual map containing indexed contextual data properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard); Event testEvent = new Event("topic", properties); boolean b = pred.matches(testEvent); assertTrue(b); LOGGER.debug("*************** END: " + methodName + " *****************"); }