Example usage for java.util GregorianCalendar setTime

List of usage examples for java.util GregorianCalendar setTime

Introduction

In this page you can find the example usage for java.util GregorianCalendar setTime.

Prototype

public final void setTime(Date date) 

Source Link

Document

Sets this Calendar's time with the given Date.

Usage

From source file:be.fedict.eid.dss.ws.DSSUtil.java

/**
 * Adds a DSS Verification Report to specified optional output element from
 * the specified list of {@link SignatureInfo}'s
 * //ww w  .jav a 2  s .co  m
 * @param optionalOutput
 *            optional output to add verification report to
 * @param signatureInfos
 *            signature infos to use in verification report.
 */
public static void addVerificationReport(AnyType optionalOutput, List<SignatureInfo> signatureInfos) {

    LOG.debug("return verification report");
    VerificationReportType verificationReport = vrObjectFactory.createVerificationReportType();
    List<IndividualReportType> individualReports = verificationReport.getIndividualReport();
    for (SignatureInfo signatureInfo : signatureInfos) {
        X509Certificate signerCertificate = signatureInfo.getSigner();
        IndividualReportType individualReport = vrObjectFactory.createIndividualReportType();
        individualReports.add(individualReport);

        SignedObjectIdentifierType signedObjectIdentifier = vrObjectFactory.createSignedObjectIdentifierType();
        individualReport.setSignedObjectIdentifier(signedObjectIdentifier);
        SignedPropertiesType signedProperties = vrObjectFactory.createSignedPropertiesType();
        signedObjectIdentifier.setSignedProperties(signedProperties);
        SignedSignaturePropertiesType signedSignatureProperties = vrObjectFactory
                .createSignedSignaturePropertiesType();
        signedProperties.setSignedSignatureProperties(signedSignatureProperties);
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(signatureInfo.getSigningTime());
        signedSignatureProperties.setSigningTime(datatypeFactory.newXMLGregorianCalendar(calendar));

        be.fedict.eid.dss.ws.profile.vr.jaxb.dss.Result individualResult = vrDssObjectFactory.createResult();
        individualReport.setResult(individualResult);
        individualResult.setResultMajor(DSSConstants.RESULT_MAJOR_SUCCESS);
        individualResult.setResultMinor(DSSConstants.RESULT_MINOR_VALID_SIGNATURE);

        be.fedict.eid.dss.ws.profile.vr.jaxb.dss.AnyType details = vrDssObjectFactory.createAnyType();
        individualReport.setDetails(details);

        DetailedSignatureReportType detailedSignatureReport = vrObjectFactory
                .createDetailedSignatureReportType();
        details.getAny().add(vrObjectFactory.createDetailedSignatureReport(detailedSignatureReport));
        VerificationResultType formatOKVerificationResult = vrObjectFactory.createVerificationResultType();
        formatOKVerificationResult.setResultMajor(DSSConstants.VR_RESULT_MAJOR_VALID);
        detailedSignatureReport.setFormatOK(formatOKVerificationResult);

        SignatureValidityType signatureOkSignatureValidity = vrObjectFactory.createSignatureValidityType();
        detailedSignatureReport.setSignatureOK(signatureOkSignatureValidity);
        VerificationResultType sigMathOkVerificationResult = vrObjectFactory.createVerificationResultType();
        signatureOkSignatureValidity.setSigMathOK(sigMathOkVerificationResult);
        sigMathOkVerificationResult.setResultMajor(DSSConstants.VR_RESULT_MAJOR_VALID);

        if (null != signatureInfo.getRole()) {
            PropertiesType properties = vrObjectFactory.createPropertiesType();
            detailedSignatureReport.setProperties(properties);
            SignedPropertiesType vrSignedProperties = vrObjectFactory.createSignedPropertiesType();
            properties.setSignedProperties(vrSignedProperties);
            SignedSignaturePropertiesType vrSignedSignatureProperties = vrObjectFactory
                    .createSignedSignaturePropertiesType();
            vrSignedProperties.setSignedSignatureProperties(vrSignedSignatureProperties);
            vrSignedSignatureProperties.setSigningTime(datatypeFactory.newXMLGregorianCalendar(calendar));
            SignerRoleType signerRole = vrObjectFactory.createSignerRoleType();
            vrSignedSignatureProperties.setSignerRole(signerRole);
            ClaimedRolesListType claimedRolesList = vrXadesObjectFactory.createClaimedRolesListType();
            signerRole.setClaimedRoles(claimedRolesList);
            be.fedict.eid.dss.ws.profile.vr.jaxb.xades.AnyType claimedRoleAny = vrXadesObjectFactory
                    .createAnyType();
            claimedRolesList.getClaimedRole().add(claimedRoleAny);
            claimedRoleAny.getContent().add(signatureInfo.getRole());
        }

        CertificatePathValidityType certificatePathValidity = vrObjectFactory
                .createCertificatePathValidityType();
        detailedSignatureReport.setCertificatePathValidity(certificatePathValidity);

        VerificationResultType certPathVerificationResult = vrObjectFactory.createVerificationResultType();
        certPathVerificationResult.setResultMajor(DSSConstants.VR_RESULT_MAJOR_VALID);
        certificatePathValidity.setPathValiditySummary(certPathVerificationResult);

        X509IssuerSerialType certificateIdentifier = vrXmldsigObjectFactory.createX509IssuerSerialType();
        certificatePathValidity.setCertificateIdentifier(certificateIdentifier);
        certificateIdentifier.setX509IssuerName(signerCertificate.getIssuerX500Principal().toString());
        certificateIdentifier.setX509SerialNumber(signerCertificate.getSerialNumber());

        CertificatePathValidityVerificationDetailType certificatePathValidityVerificationDetail = vrObjectFactory
                .createCertificatePathValidityVerificationDetailType();
        certificatePathValidity.setPathValidityDetail(certificatePathValidityVerificationDetail);
        CertificateValidityType certificateValidity = vrObjectFactory.createCertificateValidityType();
        certificatePathValidityVerificationDetail.getCertificateValidity().add(certificateValidity);
        certificateValidity.setCertificateIdentifier(certificateIdentifier);
        certificateValidity.setSubject(signerCertificate.getSubjectX500Principal().toString());

        VerificationResultType chainingOkVerificationResult = vrObjectFactory.createVerificationResultType();
        certificateValidity.setChainingOK(chainingOkVerificationResult);
        chainingOkVerificationResult.setResultMajor(DSSConstants.VR_RESULT_MAJOR_VALID);

        VerificationResultType validityPeriodOkVerificationResult = vrObjectFactory
                .createVerificationResultType();
        certificateValidity.setValidityPeriodOK(validityPeriodOkVerificationResult);
        validityPeriodOkVerificationResult.setResultMajor(DSSConstants.VR_RESULT_MAJOR_VALID);

        VerificationResultType extensionsOkVerificationResult = vrObjectFactory.createVerificationResultType();
        certificateValidity.setExtensionsOK(extensionsOkVerificationResult);
        extensionsOkVerificationResult.setResultMajor(DSSConstants.VR_RESULT_MAJOR_VALID);

        try {
            certificateValidity.setCertificateValue(signerCertificate.getEncoded());
        } catch (CertificateEncodingException e) {
            throw new RuntimeException("X509 encoding error: " + e.getMessage(), e);
        }

        certificateValidity.setSignatureOK(signatureOkSignatureValidity);

        CertificateStatusType certificateStatus = vrObjectFactory.createCertificateStatusType();
        certificateValidity.setCertificateStatus(certificateStatus);
        VerificationResultType certStatusOkVerificationResult = vrObjectFactory.createVerificationResultType();
        certificateStatus.setCertStatusOK(certStatusOkVerificationResult);
        certStatusOkVerificationResult.setResultMajor(DSSConstants.VR_RESULT_MAJOR_VALID);
    }

    Document newDocument = documentBuilder.newDocument();
    Element newElement = newDocument.createElement("newNode");
    try {
        vrMarshaller.marshal(vrObjectFactory.createVerificationReport(verificationReport), newElement);
    } catch (JAXBException e) {
        throw new RuntimeException("JAXB error: " + e.getMessage(), e);
    }
    Element verificationReportElement = (Element) newElement.getFirstChild();
    optionalOutput.getAny().add(verificationReportElement);
}

From source file:cd.education.data.collector.android.utilities.WebUtils.java

private static final void setOpenRosaHeaders(HttpRequest req) {
    req.setHeader(OPEN_ROSA_VERSION_HEADER, OPEN_ROSA_VERSION);
    GregorianCalendar g = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    g.setTime(new Date());
    req.setHeader(DATE_HEADER, DateFormat.format("E, dd MMM yyyy hh:mm:ss zz", g).toString());
}

From source file:org.apache.lens.regression.util.Util.java

public static XMLGregorianCalendar getGregorianCalendar(String date, String format)
        throws ParseException, DatatypeConfigurationException {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(new SimpleDateFormat(format).parse(date));
    cal.setTimeZone(TimeZone.getTimeZone("UTC"));
    XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
    return calendar;
}

From source file:org.apache.lens.regression.util.Util.java

public static XMLGregorianCalendar getXMLGregorianCalendar(Date d) {
    if (d == null) {
        return null;
    }/*  w w  w  .  j a v a 2  s . c  o  m*/

    GregorianCalendar c1 = new GregorianCalendar();
    c1.setTime(d);
    try {
        return DatatypeFactory.newInstance().newXMLGregorianCalendar(c1);
    } catch (DatatypeConfigurationException e) {
        log.info("Error converting date " + d, e);
        return null;
    }
}

From source file:dao.Graficos.java

public static Date dia_inicial_final_semana(boolean isPrimeiro) {
    //Seta a data atual.
    Date dataAtual = new Date();
    GregorianCalendar calendar = new GregorianCalendar();
    //Define que a semana comea no domingo.
    calendar.setFirstDayOfWeek(Calendar.SUNDAY);
    //Define a data atual.
    calendar.setTime(dataAtual);
    if (isPrimeiro) {
        calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    } else {/*from   w w  w. jav a 2 s. co  m*/
        calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
    }
    return calendar.getTime();
}

From source file:com.apextom.util.DateUtil.java

/**
 * //from w  ww  .ja va2s  .  com
 *
 * @return
 */
public static String getFirstDay(boolean isNeedHH24MISS) {
    SimpleDateFormat df = new SimpleDateFormat(YYYY_MM_DD);
    Calendar calendar = Calendar.getInstance();
    Date theDate = calendar.getTime();
    GregorianCalendar gcLast = (GregorianCalendar) Calendar.getInstance();
    gcLast.setTime(theDate);
    gcLast.set(Calendar.DAY_OF_MONTH, 1);
    String day_first = df.format(gcLast.getTime());
    StringBuffer str = new StringBuffer().append(day_first);
    if (isNeedHH24MISS) {
        str.append(" 00:00:00");
    }
    return str.toString();
}

From source file:org.nuclos.common2.DateUtils.java

public static Date calc(String calculation) {
    calculation = calculation.toUpperCase();
    GregorianCalendar result = new GregorianCalendar();
    result.setTime(today());

    StringBuffer operand = new StringBuffer();
    CalcFunction cf = null;//from w  ww.j  a  v  a2  s .  c o  m
    for (int i = 0; i < calculation.length(); i++) {
        char c = calculation.charAt(i);

        switch (c) {
        case '+':
        case '-':
        case '.':
            if (cf != null) {
                calc(result, cf, getCalcPair(operand.toString()));
                operand = new StringBuffer();
            }
            break;
        }

        switch (c) {
        case '+':
            cf = CalcFunction.ADD;
            break;
        case '-':
            cf = CalcFunction.SUBTRACT;
            break;
        case '.':
            cf = CalcFunction.SET;
            break;
        default:
            operand.append(c);
        }
    }

    if (operand.length() > 0 && cf != null) {
        calc(result, cf, getCalcPair(operand.toString()));
    }

    return result.getTime();
}

From source file:simpleserver.thread.AutoBackup.java

private static long dateMillis(File file) throws ParseException {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date(file));
    return cal.getTimeInMillis();
}

From source file:com.hybridbpm.core.util.HybridbpmCoreUtil.java

public static LocalDateTime toLocalDateTime(Date date) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date);
    ZonedDateTime zdt = cal.toZonedDateTime();
    return zdt.toLocalDateTime();
}

From source file:org.tsm.concharto.util.TimeRangeFormat.java

private static GregorianCalendar getCalendar(Date date) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date);
    return cal;/*from   ww  w.ja  va2 s  .  c  om*/
}