List of usage examples for javax.xml.datatype XMLGregorianCalendar toGregorianCalendar
public abstract GregorianCalendar toGregorianCalendar();
From source file:edu.cornell.mannlib.semservices.util.DateConverter.java
/** * Convert the specified input object into an output object of the specified * type./*from w w w. j av a 2 s . com*/ * * @param type * XMLGregorianCalendar type to which this value should be * converted * @param value * The input value to be converted * * @exception ConversionException * if conversion cannot be performed successfully */ @SuppressWarnings({ "unchecked", "deprecation" }) public Object convert(Class type, Object value) { String dateValue = value.toString(); if (value instanceof Date) { return (value); } else { try { JSONObject jsonObj = JSONObject.fromObject(value.toString()); dateValue = jsonObj.optString("Date" /* Date.class.toString() */); } catch (JSONException e) { /* empty, could fail.. */ LOG.debug("no date object found in the json"); } } XMLGregorianCalendar calendar = (XMLGregorianCalendar) converter.convert(type, dateValue); Object result = null; try { result = calendar.toGregorianCalendar().getTime(); } catch (Exception exception) { /* * empty, had some error parsing the * time */ LOG.debug("Error converting the time"); if (result == null) { try { result = new Date(Date.parse(dateValue)); } catch (IllegalArgumentException argException) { // last chance result = java.sql.Date.valueOf(dateValue); } } } if (result != null && (result instanceof Date) && type.equals(java.sql.Date.class)) { result = new java.sql.Date(((Date) result).getTime()); } return result; }
From source file:edu.harvard.i2b2.crc.dao.setfinder.querybuilder.DateConstrainHandler.java
public String constructDateConstrainClause(String fromDateField, String toDateField, InclusiveType fromInclusiveType, InclusiveType toInclusiveType, XMLGregorianCalendar fromDate, XMLGregorianCalendar toDate) { String dateConstrainSql = null; String sqlOperator = null;//from w w w . jav a 2 s. c o m if (fromDate != null) { dateFormat.setTimeZone(fromDate.toGregorianCalendar().getTimeZone()); String fromDateString = dateFormat.format(fromDate.toGregorianCalendar().getTime()); if (fromInclusiveType != null && fromInclusiveType.name().equals(InclusiveType.NO.name())) { sqlOperator = " > "; } else { sqlOperator = " >= "; } if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.ORACLE)) { dateConstrainSql = fromDateField + sqlOperator + "to_date('" + fromDateString + "','DD-MON-YYYY HH24:MI:SS')"; } else if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.SQLSERVER) || dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.POSTGRESQL)) { // {ts '2005-06-27 00:00:00'} dateConstrainSql = fromDateField + sqlOperator + " '" + fromDateString + "'"; } } if (toDate != null) { sqlOperator = null; dateFormat.setTimeZone(toDate.toGregorianCalendar().getTimeZone()); String toDateString = dateFormat.format(toDate.toGregorianCalendar().getTime()); if (toInclusiveType != null && toInclusiveType.name().equals(InclusiveType.NO.name())) { sqlOperator = " < "; } else { sqlOperator = " <= "; } if (dateConstrainSql != null) { dateConstrainSql += " AND "; } if (dateConstrainSql == null) { dateConstrainSql = " "; } if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.ORACLE)) { dateConstrainSql += (toDateField + sqlOperator + "to_date('" + toDateString + "','DD-MON-YYYY HH24:MI:SS')"); } else if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.SQLSERVER) || dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.POSTGRESQL)) { dateConstrainSql += (toDateField + sqlOperator + " '" + toDateString + "'"); } } return dateConstrainSql; }
From source file:name.persistent.behaviours.DomainSupport.java
protected void setHeader(HttpResponse resp, String name, XMLGregorianCalendar value) { if (value != null && !resp.containsHeader(name)) { Date time = value.toGregorianCalendar().getTime(); resp.setHeader(name, dateformat.format(time)); }/*from w w w .ja v a 2 s.c om*/ }
From source file:edu.harvard.i2b2.crc.dao.pdo.input.DateConstrainHandler.java
public String constructDateConstrainClause(String fromDateField, String toDateField, InclusiveType fromInclusiveType, InclusiveType toInclusiveType, XMLGregorianCalendar fromDate, XMLGregorianCalendar toDate) throws I2B2Exception { String dateConstrainSql = null; String sqlOperator = null;// w w w .j a v a2 s . c o m if (fromDate != null) { String fromDateString = dateFormat.format(fromDate.toGregorianCalendar().getTime()); if (fromInclusiveType != null && fromInclusiveType.name().equals(InclusiveType.NO.name())) { sqlOperator = " > "; } else { sqlOperator = " >= "; } if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.ORACLE)) { dateConstrainSql = fromDateField + sqlOperator + "to_date('" + fromDateString + "','DD-MON-YYYY HH24:MI:SS')"; } else if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.SQLSERVER) || dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.POSTGRESQL)) { // {ts '2005-06-27 00:00:00'} dateConstrainSql = fromDateField + sqlOperator + " '" + fromDateString + "'"; } } if (toDate != null) { sqlOperator = null; String toDateString = dateFormat.format(toDate.toGregorianCalendar().getTime()); if (toInclusiveType != null && toInclusiveType.name().equals(InclusiveType.NO.name())) { sqlOperator = " < "; } else { sqlOperator = " <= "; } if (dateConstrainSql != null) { dateConstrainSql += " AND "; } if (dateConstrainSql == null) { dateConstrainSql = " "; } if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.ORACLE)) { dateConstrainSql += (toDateField + sqlOperator + "to_date('" + toDateString + "','DD-MON-YYYY HH24:MI:SS')"); } else if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.SQLSERVER) || dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.POSTGRESQL)) { dateConstrainSql += (toDateField + sqlOperator + " '" + toDateString + "'"); } } return dateConstrainSql; }
From source file:com.quest.keycloak.protocol.wsfed.builders.RequestSecurityTokenResponseBuilder.java
public RequestSecurityTokenResponse build() throws ConfigurationException, ProcessingException { RequestSecurityTokenResponse response = new RequestSecurityTokenResponse(); response.setContext(StringEscapeUtils.escapeXml11(context)); XMLGregorianCalendar issueInstance = XMLTimeUtil.getIssueInstant(); response.setLifetime(new Lifetime(issueInstance.toGregorianCalendar(), XMLTimeUtil.add(issueInstance, tokenExpiration * 1000).toGregorianCalendar())); response.setAppliesTo(new AppliesTo()); EndpointReferenceType ert = new EndpointReferenceType(); ert.setAddress(new AttributedURIType()); ert.getAddress().setValue(requestIssuer); response.getAppliesTo().addAny(ert); response.setRequestedSecurityToken(new RequestedSecurityTokenType()); response.setRequestType(URI.create("http://schemas.xmlsoap.org/ws/2005/02/trust/Issue")); if (samlToken != null) { //Sign token Document doc = AssertionUtil.asDocument(samlToken); doc = signAssertion(doc);//from w ww . j a va 2 s. c o m response.getRequestedSecurityToken().add(doc.getDocumentElement()); response.setRequestedUnattachedReference(new RequestedReferenceType()); response.getRequestedUnattachedReference().setSecurityTokenReference(new SecurityTokenReferenceType()); KeyIdentifierType ki = new KeyIdentifierType(); ki.setValue(IDGenerator.create("ID_")); ki.setValueType("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLID"); response.getRequestedUnattachedReference().getSecurityTokenReference().addAny(ki); response.setTokenType( URI.create("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0")); } else if (jwt != null) { BinarySecurityTokenType bstt = new BinarySecurityTokenType(); bstt.setValue(Base64.encodeBytes(jwt.getBytes())); bstt.setId(IDGenerator.create("ID_")); bstt.setValueType("urn:ietf:params:oauth:token-type:jwt"); bstt.setEncodingType( "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"); response.getRequestedSecurityToken().add(bstt); response.setTokenType(URI.create("urn:ietf:params:oauth:token-type:jwt")); } else { throw new ConfigurationException("SAML or JWT must be set."); } return response; }
From source file:edu.harvard.i2b2.fhir.FhirUtil.java
public static ca.uhn.fhir.model.api.Bundle fhirBundleToHapiBundle(Bundle b) throws Exception { ca.uhn.fhir.model.api.Bundle hb = new ca.uhn.fhir.model.api.Bundle(); // IdDt idb = new IdDt(); // idb.setValue(b.getId().getValue()); // id.setValue(fhirBase + UUID.randomUUID().toString()); // hb.setId(idb); String fhirBase = "b.getBase().toString()"; for (BundleEntry be : b.getEntry()) { ResourceContainer rc = be.getResource(); Resource r = getResourceFromContainer(rc); for (Class c : getResourceClassList()) { if (c.isInstance(r)) { ca.uhn.fhir.model.api.BundleEntry entry = new ca.uhn.fhir.model.api.BundleEntry(); IdDt ide = new IdDt(); ide.setValue(r.getId().getValue()); entry.setId(ide);// w ww . ja va 2 s .c om XMLGregorianCalendar lastUpdated = null; try { lastUpdated = null; } catch (Exception ex) { } if (lastUpdated != null) { Date d = lastUpdated.toGregorianCalendar().getTime(); InstantDt dt = new InstantDt(); dt.setValue(d); // entry.setUpdated(dt); } // entry.addExtension("http://www.w3.org/2005/Atom","published",null).setText(new // Date().toGMTString()); // theLinkSelf StringDt theLinkSelf = new StringDt(); theLinkSelf.setValue(fhirBase + r.getId()); entry.setLinkSelf(theLinkSelf); IResource theResource = WrapperHapi.resourceXmlToIResource(JAXBUtil.toXml(r)); entry.setResource(theResource); hb.addEntry(entry); } } } return hb; }
From source file:fr.mael.microrss.xml.AtomFeedParser.java
private Article readEntry(EntryType entry, FeedType feedType) { Article article = new Article(); // String author = XMLUtil.readComplexProperty("author", entry.getAuthorOrCategoryOrContent(), "getValue"); // if (StringUtils.isEmpty(author)) { String author = readFeedAuthor(feedType); // }/* ww w . ja va2 s .co m*/ article.setAuthor(author); article.setGuid(XMLUtil.readComplexProperty("id", entry.getAuthorOrCategoryOrContent(), "getValue")); article.setContent(XMLUtil.readContentType("content", entry.getAuthorOrCategoryOrContent())); article.setOverview(XMLUtil.readTextType("summary", entry.getAuthorOrCategoryOrContent())); if (article.getContent() == null && article.getOverview() != null) { article.setContent(article.getOverview()); } else if (article.getContent() == null && article.getOverview() == null) { LOG.error("article with guid " + article.getGuid() + " has empty content and summary"); article.setContent(""); } article.setTitle(XMLUtil.readTextType("title", entry.getAuthorOrCategoryOrContent())); article.setUrl(XMLUtil.readLinkType("link", entry.getAuthorOrCategoryOrContent())); XMLGregorianCalendar published = XMLUtil.readDateTimeType("published", entry.getAuthorOrCategoryOrContent()); if (published == null) { published = XMLUtil.readDateTimeType("updated", entry.getAuthorOrCategoryOrContent()); } article.setCreated(published.toGregorianCalendar().getTime()); return article; }
From source file:it.cnr.icar.eric.server.persistence.rdb.SubscriptionDAO.java
/** * Returns the SQL fragment string needed by insert or update statements * within insert or update method of sub-classes. This is done to avoid code * duplication./* w ww. ja v a2s . co m*/ */ protected String getSQLStatementFragment(Object ro) throws RegistryException { SubscriptionType subscription = (SubscriptionType) ro; String stmtFragment = null; String selector = subscription.getSelector(); XMLGregorianCalendar endTime = subscription.getEndTime(); String endTimeAsString = null; if (endTime != null) { endTimeAsString = " '" + (new Timestamp(endTime.toGregorianCalendar().getTimeInMillis())) + "'"; } Duration notificationInterval = subscription.getNotificationInterval(); String notificationIntervalString = ""; if (notificationInterval != null) { notificationIntervalString = "'" + notificationInterval.toString() + "'"; } // xxx 120203 pa fix for missing XJC/JAXB generated default value for // duration else { notificationIntervalString = "'P1D'"; } XMLGregorianCalendar startTime = subscription.getStartTime(); String startTimeAsString = null; if (startTime != null) { startTimeAsString = " '" + (new Timestamp(startTime.toGregorianCalendar().getTimeInMillis())) + "'"; } if (action == DAO_ACTION_INSERT) { stmtFragment = "INSERT INTO Subscription " + super.getSQLStatementFragment(ro) + ", '" + selector + "', " + endTimeAsString + ", " + notificationIntervalString + ", " + startTimeAsString + " ) "; } else if (action == DAO_ACTION_UPDATE) { stmtFragment = "UPDATE Subscription SET " + super.getSQLStatementFragment(ro) + ", selector='" + selector + "', endTime=" + endTimeAsString + ", notificationInterval=" + notificationIntervalString + ", startTime=" + startTimeAsString + " WHERE id = '" + ((RegistryObjectType) ro).getId() + "' "; } else if (action == DAO_ACTION_DELETE) { stmtFragment = super.getSQLStatementFragment(ro); } return stmtFragment; }
From source file:name.persistent.behaviours.MirroredDomainSupport.java
@Override public void purlSetEntityHeaders(HttpResponse resp) { Object by = getPurlMirroredBy(); if (by instanceof RemoteGraph) { RemoteGraph graph = (RemoteGraph) by; XMLGregorianCalendar validated = graph.getPurlLastValidated(); long now = System.currentTimeMillis(); long date = validated.toGregorianCalendar().getTimeInMillis(); int age = (int) ((now - date) / 1000); String via = graph.getPurlVia(); setHeader(resp, "Via", via == null ? VIA : via + "," + VIA); resp.setHeader("Age", Integer.toString(age)); setHeader(resp, "Date", validated); setHeader(resp, "Cache-Control", graph.getPurlCacheControl()); setHeader(resp, "ETag", graph.getPurlEtag()); setHeader(resp, "Last-Modified", graph.getPurlLastModified()); if (!graph.isFresh()) { resp.addHeader("Warning", WARN_110); }//www . j a v a2 s.c o m if (graph instanceof Unresolvable) { resp.addHeader("Warning", WARN_111); } resp.addHeader("Warning", WARN_199); } else { super.purlSetEntityHeaders(resp); } }
From source file:icom.jpa.bdk.dao.LabelApplicationDAO.java
public void copyObjectState(ManagedObjectProxy obj, Object bdkIdentifiable, Projection proj) { LabelApplication bdkLabelApplication = (LabelApplication) bdkIdentifiable; Persistent pojoIdentifiable = obj.getPojoObject(); if ( /* !isPartOfProjection(TagApplicationInfo.Attributes.taggedEntity.name(), lastLoadedProjection) && */ isPartOfProjection(TagApplicationInfo.Attributes.attachedEntity.name(), proj)) { try {/* ww w. java 2 s . c o m*/ Entity bdkLabeledEntity = bdkLabelApplication.getLabeledEntity(); marshallAssignEntity(obj, TagApplicationInfo.Attributes.attachedEntity.name(), bdkLabeledEntity); } catch (Exception ex) { // ignore } } if ( /* !isPartOfProjection(TagApplicationInfo.Attributes.tag.name(), lastLoadedProjection) && */ isPartOfProjection(TagApplicationInfo.Attributes.tag.name(), proj)) { try { Label bdkLabel = bdkLabelApplication.getLabel(); marshallAssignEntity(obj, TagApplicationInfo.Attributes.tag.name(), bdkLabel); } catch (Exception ex) { // ignore } } if ( /* !isPartOfProjection(BeehiveTagApplicationInfo.Attributes.type.name(), lastLoadedProjection) && */ isPartOfProjection(BeehiveTagApplicationInfo.Attributes.type.name(), proj)) { try { LabelApplicationType bdkLabelApplicationType = bdkLabelApplication.getLabelApplicationType(); String labelApplicationTypeName = null; if (bdkLabelApplicationType != null) { labelApplicationTypeName = bdkLabelApplicationType.name(); } assignEnumConstant(pojoIdentifiable, BeehiveTagApplicationInfo.Attributes.type.name(), BeehiveBeanEnumeration.BeehiveTagApplicationType.getPackageName(), BeehiveBeanEnumeration.BeehiveTagApplicationType.name(), labelApplicationTypeName); } catch (Exception ex) { // ignore } } if ( /*!isPartOfProjection(TagApplicationInfo.Attributes.appliedBy.name(), lastLoadedProjection) && */ isPartOfProjection(TagApplicationInfo.Attributes.appliedBy.name(), proj)) { try { Actor bdkActor = bdkLabelApplication.getAppliedBy(); marshallAssignEntity(obj, TagApplicationInfo.Attributes.appliedBy.name(), bdkActor); } catch (Exception ex) { // ignore } } if ( /* !isPartOfProjection(TagApplicationInfo.Attributes.appliedOn.name(), lastLoadedProjection) && */ isPartOfProjection(TagApplicationInfo.Attributes.applicationDate.name(), proj)) { try { XMLGregorianCalendar xdate = bdkLabelApplication.getAppliedOn(); if (xdate != null) { Date date = xdate.toGregorianCalendar().getTime(); assignAttributeValue(pojoIdentifiable, TagApplicationInfo.Attributes.applicationDate.name(), date); } else { assignAttributeValue(pojoIdentifiable, TagApplicationInfo.Attributes.applicationDate.name(), null); } } catch (Exception ex) { // ignore } } }