Example usage for javax.xml.datatype XMLGregorianCalendar toString

List of usage examples for javax.xml.datatype XMLGregorianCalendar toString

Introduction

In this page you can find the example usage for javax.xml.datatype XMLGregorianCalendar toString.

Prototype

@Override
public String toString() 

Source Link

Document

Returns a String representation of this XMLGregorianCalendar Object .

Usage

From source file:com.athena.peacock.common.core.util.XMLGregorialCalendarUtil.java

/**
 * <pre>// w ww . j  a va  2  s  . c om
 * YYYYMMDDHH24MISS? ?? ??   XMLGregorialCalendar ? GMT(GMT+09:00) ? .
 * </pre>
 * @param dateString
 * @return
 */
public static String convertFormattedStringToXmlGregorianCalendarStr(String dateString) {
    Assert.notNull(dateString, "dateString must not be null.");

    if (dateString.length() < 14) {
        dateString = StringUtils.rightPad(dateString, 14, '0');
    }

    Assert.isTrue(dateString.length() == 14, "dateString's length must be 14.");

    GregorianCalendar cal = null;
    XMLGregorianCalendar calender = null;
    try {
        cal = convertTimezone(getDate(dateString), TimeZone.getTimeZone("ROK"));
        calender = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);

        return calender.toString();
    } catch (Exception e) {
        throw new IllegalArgumentException(
                "    . : [Date : " + dateString + " ]");
    }
}

From source file:com.funambol.exchange.util.DateTools.java

public static String convertEwsCalToDateTime(XMLGregorianCalendar xmlCal) {
    return xmlCal.toString().replaceAll("-", "").replaceAll(":", "");
}

From source file:com.att.ajsc.csilogging.util.UtilLib.java

public static String getStartTimestamp(String epoch) {
    long stime = Long.parseLong((String) epoch);
    XmlCalendar cal = new XmlCalendar(new Date(stime));
    XMLGregorianCalendar initTime = null;
    try {//w ww  .  j  ava 2s  .  c  o  m
        initTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal.get(Calendar.YEAR),
                cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY),
                cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND),
                Math.round(cal.get(Calendar.ZONE_OFFSET) / 1000 / 60));
    } catch (Exception ex) {
        initTime = null;
    }
    if (initTime == null)
        return null;
    else
        return initTime.toString();
}

From source file:com.flexoodb.engines.FlexJAXBMappedDBDataEngine.java

private void updatePreparedStatement(String tablename, Hashtable<String, Object[]> fieldswithcontent,
        PreparedStatement ps) throws Exception {

    Enumeration en = fieldswithcontent.keys();
    int i = 0;//w ww  .j av  a2  s .c  om
    while (en.hasMoreElements()) {
        i++;

        try {
            String field = (String) en.nextElement();
            Object[] o2 = fieldswithcontent.get(field);

            String type = (String) o2[0];
            Object o = o2[1];

            //System.out.println(field+" "+type+" "+o);
            if (type.equals("string")) {
                ps.setString(i, (String) o);
            } else if (type.equals("byte[]") || type.equals("base64Binary")) {
                ps.setBinaryStream(i, new ByteArrayInputStream((byte[]) o));
            } else if (type.equals("dateTime")) {
                XMLGregorianCalendar cal = (XMLGregorianCalendar) o;
                Date d = null;

                if (cal.toString().indexOf("0003-11-30") > -1) {
                    ps.setString(i, "0000-00-00 00:00:00");
                } else {
                    d = (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S")).parse(cal.toString());
                    ps.setTimestamp(i, new java.sql.Timestamp(d.getTime()));
                }
            } else if (type.equals("date")) {
                XMLGregorianCalendar cal = (XMLGregorianCalendar) o;
                Date d1 = (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S")).parse(cal.toString());
                ps.setDate(i, java.sql.Date.valueOf(new SimpleDateFormat("yyyy-MM-dd").format(d1)));
            } else if (type.equals("time")) {
                XMLGregorianCalendar cal = (XMLGregorianCalendar) o;
                String c = cal.toString();
                c = c.replaceFirst("0003-11-30", "0000-00-00");
                Date d1 = (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S")).parse(c);
                ps.setTime(i, new java.sql.Time(d1.getTime()));

            } else if (type.equals("integer")) {
                ps.setInt(i, ((BigInteger) o).intValue());
            } else if (type.equals("double")) {
                ps.setDouble(i, (Double) o);
            } else if (type.equals("float")) {
                ps.setFloat(i, (Float) o);
            } else if (type.equals("long")) {
                ps.setLong(i, (Long) o);
            } else {
                throw new Exception("unknown type [" + type + "] for field [" + field
                        + "] encountered while trying to update table [" + tablename + "].");
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }

    }
}

From source file:org.apache.juddi.v3.tck.UDDI_150_CustodyTransferIntegrationTest.java

/**
 * tests a user to user transfer on the same node
 *
 * @throws Exception//from ww  w  . ja  v a 2  s.c  o m
 */
@Test
public void ValidTransfer() throws Exception {
    Assume.assumeTrue(TckPublisher.isEnabled());
    System.out.println("ValidTransfer");
    DatatypeFactory df = DatatypeFactory.newInstance();
    GregorianCalendar gcal = new GregorianCalendar();
    gcal.setTimeInMillis(System.currentTimeMillis());
    XMLGregorianCalendar xcal = df.newXMLGregorianCalendar(gcal);

    BusinessEntity myBusEntity = new BusinessEntity();
    Name myBusName = new Name();
    myBusName.setLang("en");
    myBusName.setValue("ValidTransfer UDDI's Business" + " " + xcal.toString());
    myBusEntity.getName().add(myBusName);
    myBusEntity.setBusinessServices(new BusinessServices());
    myBusEntity.getBusinessServices().getBusinessService().add(CreateBusiness("UDDI"));
    SaveBusiness sb = new SaveBusiness();
    sb.getBusinessEntity().add(myBusEntity);
    sb.setAuthInfo(authInfoJoe);
    BusinessDetail bd = publishJoe.saveBusiness(sb);

    String keyJoeBiz = bd.getBusinessEntity().get(0).getBusinessKey();
    //String keyJoeBizSvc = bd.getBusinessEntity().get(0).getBusinessServices().getBusinessService().get(0).getServiceKey();

    myBusEntity = new BusinessEntity();
    myBusName = new Name();
    myBusName.setLang("en");
    myBusName.setValue("ValidTransfer Root's Business" + " " + xcal.toString());
    myBusEntity.getName().add(myBusName);
    myBusEntity.setBusinessServices(new BusinessServices());
    myBusEntity.getBusinessServices().getBusinessService().add(CreateBusiness("root"));
    sb = new SaveBusiness();
    sb.getBusinessEntity().add(myBusEntity);
    sb.setAuthInfo(authInfoSam);
    bd = publishSam.saveBusiness(sb);

    String keySamBiz = bd.getBusinessEntity().get(0).getBusinessKey();
    //String keySamBizSvc = bd.getBusinessEntity().get(0).getBusinessServices().getBusinessService().get(0).getServiceKey();

    //transfers from Joe to Sam
    KeyBag kb = new KeyBag();
    kb.getKey().add(keyJoeBiz);

    Holder<String> nodeidOUT = new Holder<String>();
    Holder<XMLGregorianCalendar> expiresOUT = new Holder<XMLGregorianCalendar>();
    Holder<byte[]> tokenOUT = new Holder<byte[]>();
    custodyTransferPortTypeJoe.getTransferToken(authInfoJoe, kb, nodeidOUT, expiresOUT, tokenOUT);

    //sam accepts
    TransferEntities te = new TransferEntities();
    te.setAuthInfo(authInfoSam);
    te.setKeyBag(kb);
    TransferToken tt = new TransferToken();
    tt.setExpirationTime(expiresOUT.value);
    tt.setNodeID(nodeidOUT.value);
    tt.setOpaqueToken(tokenOUT.value);
    te.setTransferToken(tt);

    custodyTransferPortTypeSam.transferEntities(te);

    //confirm the transfer
    GetOperationalInfo go = new GetOperationalInfo();
    go.setAuthInfo(authInfoSam);
    go.getEntityKey().add(keySamBiz);
    go.getEntityKey().add(keyJoeBiz);
    OperationalInfos operationalInfo = inquirySam.getOperationalInfo(go);

    for (int i = 0; i < operationalInfo.getOperationalInfo().size(); i++) {
        if (operationalInfo.getOperationalInfo().get(i).getEntityKey().equalsIgnoreCase(keyJoeBiz)) {
            Assert.assertEquals(operationalInfo.getOperationalInfo().get(i).getAuthorizedName(),
                    (TckPublisher.getSamPublisherId()));

        }
    }
    System.out.println("Business Entity transfered successfull");

    //note, we transfered ownership here so sam has to delete both of them
    TckCommon.DeleteBusiness(keyJoeBiz, authInfoSam, publishSam);
    TckCommon.DeleteBusiness(keySamBiz, authInfoSam, publishSam);

}

From source file:org.apache.juddi.v3.tck.UDDI_150_CustodyTransferIntegrationTest.java

@Test
public void InvalidTransferTokenEmptyNullAuthToken() {
    Assume.assumeTrue(TckPublisher.isEnabled());
    String keyJoeBiz = null;//w w  w  .  j a  va  2s  .c om
    try {
        DatatypeFactory df = DatatypeFactory.newInstance();
        GregorianCalendar gcal = new GregorianCalendar();
        gcal.setTimeInMillis(System.currentTimeMillis());
        XMLGregorianCalendar xcal = df.newXMLGregorianCalendar(gcal);

        BusinessEntity myBusEntity = new BusinessEntity();
        Name myBusName = new Name();
        myBusName.setLang("en");
        myBusName.setValue("InvalidTransferTokenEmptyNullAuthToken UDDI's Business" + " " + xcal.toString());
        myBusEntity.getName().add(myBusName);
        myBusEntity.setBusinessServices(new BusinessServices());
        myBusEntity.getBusinessServices().getBusinessService().add(CreateBusiness("UDDI"));
        SaveBusiness sb = new SaveBusiness();
        sb.getBusinessEntity().add(myBusEntity);
        sb.setAuthInfo(authInfoJoe);
        BusinessDetail bd = publishJoe.saveBusiness(sb);

        keyJoeBiz = bd.getBusinessEntity().get(0).getBusinessKey();

        //transfers from Joe to Sam
        KeyBag kb = new KeyBag();
        kb.getKey().add(keyJoeBiz);

        Holder<String> nodeidOUT = new Holder<String>();
        Holder<XMLGregorianCalendar> expiresOUT = new Holder<XMLGregorianCalendar>();
        Holder<byte[]> tokenOUT = new Holder<byte[]>();
        custodyTransferPortTypeJoe.getTransferToken(null, kb, nodeidOUT, expiresOUT, tokenOUT);

        Assert.fail();
    } catch (Exception ex) {
        logger.info("Expected exception: " + ex.getMessage());

    } finally {
        TckCommon.DeleteBusiness(keyJoeBiz, authInfoJoe, publishJoe);

    }

}

From source file:org.apache.juddi.v3.tck.UDDI_150_CustodyTransferIntegrationTest.java

/**
 * a valid transfer token issued, then modified out of band, this should
 * fail/*w  ww.  jav a  2s.co  m*/
 */
@Test
public void InvalidTransferTokenModified() {
    Assume.assumeTrue(TckPublisher.isEnabled());
    String keySamBiz = null;
    String keyJoeBiz = null;
    try {
        DatatypeFactory df = DatatypeFactory.newInstance();
        GregorianCalendar gcal = new GregorianCalendar();
        gcal.setTimeInMillis(System.currentTimeMillis());
        XMLGregorianCalendar xcal = df.newXMLGregorianCalendar(gcal);

        BusinessEntity myBusEntity = new BusinessEntity();
        Name myBusName = new Name();
        myBusName.setLang("en");
        myBusName.setValue("InvalidTransferTokenModified UDDI's Business" + " " + xcal.toString());
        myBusEntity.getName().add(myBusName);
        myBusEntity.setBusinessServices(new BusinessServices());
        myBusEntity.getBusinessServices().getBusinessService().add(CreateBusiness("UDDI"));
        SaveBusiness sb = new SaveBusiness();
        sb.getBusinessEntity().add(myBusEntity);
        sb.setAuthInfo(authInfoJoe);
        BusinessDetail bd = publishJoe.saveBusiness(sb);

        keyJoeBiz = bd.getBusinessEntity().get(0).getBusinessKey();

        myBusEntity = new BusinessEntity();
        myBusName = new Name();
        myBusName.setLang("en");
        myBusName.setValue("Root's Business" + " " + xcal.toString());
        myBusEntity.getName().add(myBusName);
        myBusEntity.setBusinessServices(new BusinessServices());
        myBusEntity.getBusinessServices().getBusinessService().add(CreateBusiness("root"));
        sb = new SaveBusiness();
        sb.getBusinessEntity().add(myBusEntity);
        sb.setAuthInfo(authInfoSam);
        bd = publishSam.saveBusiness(sb);

        keySamBiz = bd.getBusinessEntity().get(0).getBusinessKey();
        //String keySamBizSvc = bd.getBusinessEntity().get(0).getBusinessServices().getBusinessService().get(0).getServiceKey();

        //transfers from Joe to Sam
        KeyBag kb = new KeyBag();
        kb.getKey().add(keyJoeBiz);

        Holder<String> nodeidOUT = new Holder<String>();
        Holder<XMLGregorianCalendar> expiresOUT = new Holder<XMLGregorianCalendar>();
        Holder<byte[]> tokenOUT = new Holder<byte[]>();
        custodyTransferPortTypeJoe.getTransferToken(authInfoJoe, kb, nodeidOUT, expiresOUT, tokenOUT);

        //sam accepts
        TransferEntities te = new TransferEntities();
        te.setAuthInfo(authInfoSam);
        te.setKeyBag(kb);
        te.getKeyBag().getKey().add("uddi:uddi.joepublisher.com:" + UUID.randomUUID().toString());
        TransferToken tt = new TransferToken();
        tt.setExpirationTime(expiresOUT.value);
        tt.setNodeID(nodeidOUT.value);
        tt.setOpaqueToken(tokenOUT.value);
        te.setTransferToken(tt);

        custodyTransferPortTypeSam.transferEntities(te);
        Assert.fail();
    } catch (Exception ex) {
        //  HandleException(ex);
        logger.info("Expected exception: " + ex.getMessage());
    } finally {
        TckCommon.DeleteBusiness(keyJoeBiz, authInfoJoe, publishJoe);
        TckCommon.DeleteBusiness(keySamBiz, authInfoSam, publishSam);
    }

}

From source file:org.atricore.idbus.capabilities.sso.main.sp.producers.AssertionConsumerProducer.java

private void validateAssertionConditions(ResponseType response, ConditionsType conditions)
        throws SSOException, SSOResponseException {

    if (conditions == null)
        return;// w w  w  . java  2s .  c om

    long tolerance = ((AbstractSSOMediator) channel.getIdentityMediator()).getTimestampValidationTolerance();
    Calendar utcCalendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

    if (conditions.getConditionOrAudienceRestrictionOrOneTimeUse() == null && conditions.getNotBefore() == null
            && conditions.getNotOnOrAfter() == null) {
        return;
    }

    logger.debug("Current time (UTC): " + utcCalendar.toString());

    XMLGregorianCalendar notBeforeUTC = null;
    XMLGregorianCalendar notOnOrAfterUTC = null;

    if (conditions.getNotBefore() != null) {
        //normalize to UTC         
        logger.debug("Conditions.NotBefore: " + conditions.getNotBefore());

        notBeforeUTC = conditions.getNotBefore().normalize();
        logger.debug("Conditions.NotBefore normalized: " + notBeforeUTC.toString());

        if (!notBeforeUTC.isValid()) {
            throw new SSOResponseException(response, StatusCode.TOP_REQUESTER,
                    StatusCode.INVALID_ATTR_NAME_OR_VALUE, StatusDetails.INVALID_UTC_VALUE,
                    notBeforeUTC.toString());
        } else {

            Calendar notBefore = notBeforeUTC.toGregorianCalendar();
            notBefore.add(Calendar.MILLISECOND, (int) tolerance * -1);

            if (utcCalendar.before(notBefore))

                throw new SSOResponseException(response, StatusCode.TOP_REQUESTER,
                        StatusCode.INVALID_ATTR_NAME_OR_VALUE, StatusDetails.NOT_BEFORE_VIOLATED,
                        notBeforeUTC.toString());
        }
    }

    // Make sure that the NOT ON OR AFTER is not violated, give a five minutes tolerance (should be configurable)
    if (conditions.getNotOnOrAfter() != null) {
        //normalize to UTC
        logger.debug("Conditions.NotOnOrAfter: " + conditions.getNotOnOrAfter().toString());
        notOnOrAfterUTC = conditions.getNotOnOrAfter().normalize();
        logger.debug("Conditions.NotOnOrAfter normalized: " + notOnOrAfterUTC.toString());
        if (!notOnOrAfterUTC.isValid()) {
            throw new SSOResponseException(response, StatusCode.TOP_REQUESTER,
                    StatusCode.INVALID_ATTR_NAME_OR_VALUE, StatusDetails.INVALID_UTC_VALUE,
                    notOnOrAfterUTC.toString());

        } else {

            // diff in millis
            Calendar notOnOrAfter = notOnOrAfterUTC.toGregorianCalendar();
            notOnOrAfter.add(Calendar.MILLISECOND, (int) tolerance);

            if (utcCalendar.after(notOnOrAfter))
                throw new SSOResponseException(response, StatusCode.TOP_REQUESTER,
                        StatusCode.INVALID_ATTR_NAME_OR_VALUE, StatusDetails.NOT_ONORAFTER_VIOLATED,
                        notOnOrAfterUTC.toString());
        }
    }

    if (notBeforeUTC != null && notOnOrAfterUTC != null && notOnOrAfterUTC.compare(notBeforeUTC) <= 0) {

        throw new SSOResponseException(response, StatusCode.TOP_REQUESTER,
                StatusCode.INVALID_ATTR_NAME_OR_VALUE, StatusDetails.INVALID_CONDITION,
                "'Not On or After' earlier that 'Not Before'");
    }

    // Our SAMLR2 Enityt ID should be part of the audience
    CircleOfTrustMemberDescriptor sp = this.getCotMemberDescriptor();
    MetadataEntry spMd = sp.getMetadata();

    if (spMd == null || spMd.getEntry() == null)
        throw new SSOException("No metadata descriptor found for SP " + sp);

    EntityDescriptorType md = null;
    if (spMd.getEntry() instanceof EntityDescriptorType) {
        md = (EntityDescriptorType) spMd.getEntry();
    } else
        throw new SSOException("Unsupported Metadata type " + md + ", SAML 2 Metadata expected");

    if (conditions.getConditionOrAudienceRestrictionOrOneTimeUse() != null) {
        boolean audienceRestrictionValid = false;
        boolean spInAllAudiences = false;
        boolean initState = true;
        for (ConditionAbstractType conditionAbs : conditions.getConditionOrAudienceRestrictionOrOneTimeUse()) {
            if (conditionAbs instanceof AudienceRestrictionType) {
                AudienceRestrictionType audienceRestriction = (AudienceRestrictionType) conditionAbs;
                if (audienceRestriction.getAudience() != null) {
                    boolean spInAudience = false;
                    for (String audience : audienceRestriction.getAudience()) {
                        if (audience.equals(md.getEntityID())) {
                            spInAudience = true;
                            break;
                        }
                    }
                    spInAllAudiences = (initState ? spInAudience : spInAllAudiences && spInAudience);
                    initState = false;
                }
            }
            audienceRestrictionValid = audienceRestrictionValid || spInAllAudiences;
        }
        if (!audienceRestrictionValid) {
            logger.error("SP is not in Audience list.");
            throw new SSOResponseException(response, StatusCode.TOP_REQUESTER,
                    StatusCode.INVALID_ATTR_NAME_OR_VALUE, StatusDetails.NOT_IN_AUDIENCE);
        }
    }

}

From source file:org.orcid.core.security.DefaultPermissionChecker.java

private void performUserChecks(OAuth2Authentication oAuth2Authentication, ScopePathType requiredScope,
        OrcidMessage orcidMessage, String orcid) {
    ProfileEntity principal = (ProfileEntity) oAuth2Authentication.getPrincipal();
    String userOrcid = principal.getId();
    if (orcidMessage != null && orcidMessage.getOrcidProfile() != null
            && orcidMessage.getOrcidProfile().getOrcidIdentifier() != null && StringUtils.isNotBlank(orcid)) {
        String messageOrcid = orcidMessage.getOrcidProfile().getOrcidIdentifier().getPath();
        // First check that this is a valid call. If these don't match then
        // the request is invalid
        if (!messageOrcid.equals(orcid)) {
            throw new IllegalArgumentException("The ORCID in the body and the URI do not match. Body ORCID: "
                    + messageOrcid + " URI ORCID: " + orcid + " do NOT match.");
        }//  w ww. j  av a  2  s  .  c  o  m
    }
    // Is this the owner making the call? If it is, then let 'em on
    // through
    if (userOrcid.equals(orcid)) {
        return;
    } else {
        // Have they been granted permission?
        if (profileEntityManager.hasBeenGivenPermissionTo(orcid, userOrcid)) {
            // TODO: We will need to parse both incoming and existing to
            // make sure they're not trying to
            // update private information.
            return;
        } else if (profileDao.isProfileDeprecated(orcid)) {
            ProfileEntity entity = profileEntityCacheManager.retrieve(orcid);
            Map<String, String> params = new HashMap<String, String>();
            StringBuffer primary = new StringBuffer(baseUrl).append("/")
                    .append(entity.getPrimaryRecord().getId());
            params.put(OrcidDeprecatedException.ORCID, primary.toString());
            if (entity.getDeprecatedDate() != null) {
                XMLGregorianCalendar calendar = DateUtils
                        .convertToXMLGregorianCalendar(entity.getDeprecatedDate());
                params.put(OrcidDeprecatedException.DEPRECATED_DATE, calendar.toString());
            }
            throw new OrcidDeprecatedException(params);
        }
    }
    throw new AccessControlException("You do not have the required permissions.");
}