List of usage examples for java.util GregorianCalendar setTimeZone
@Override public void setTimeZone(TimeZone zone)
From source file:be.fedict.eid.tsl.TrustServiceList.java
public void setNextUpdate(DateTime nextUpdateDateTime) { TSLSchemeInformationType schemeInformation = getSchemeInformation(); GregorianCalendar nextUpdateCalendar = nextUpdateDateTime.toGregorianCalendar(); nextUpdateCalendar.setTimeZone(TimeZone.getTimeZone("Z")); NextUpdateType nextUpdate = schemeInformation.getNextUpdate(); if (null == nextUpdate) { nextUpdate = this.objectFactory.createNextUpdateType(); schemeInformation.setNextUpdate(nextUpdate); }/*from w ww . ja v a 2 s.com*/ nextUpdate.setDateTime(this.datatypeFactory.newXMLGregorianCalendar(nextUpdateCalendar)); }
From source file:be.fedict.eid.tsl.TrustServiceList.java
public void addXadesBes(XMLSignatureFactory signatureFactory, Document document, String signatureId, X509Certificate signingCertificate, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { LOG.debug("preSign"); // QualifyingProperties QualifyingPropertiesType qualifyingProperties = this.xadesObjectFactory.createQualifyingPropertiesType(); qualifyingProperties.setTarget("#" + signatureId); // SignedProperties SignedPropertiesType signedProperties = this.xadesObjectFactory.createSignedPropertiesType(); String signedPropertiesId = signatureId + "-xades"; signedProperties.setId(signedPropertiesId); qualifyingProperties.setSignedProperties(signedProperties); // SignedSignatureProperties SignedSignaturePropertiesType signedSignatureProperties = this.xadesObjectFactory .createSignedSignaturePropertiesType(); signedProperties.setSignedSignatureProperties(signedSignatureProperties); // SigningTime GregorianCalendar signingTime = new GregorianCalendar(); signingTime.setTimeZone(TimeZone.getTimeZone("Z")); XMLGregorianCalendar xmlSigningTime = this.datatypeFactory.newXMLGregorianCalendar(signingTime); xmlSigningTime.setMillisecond(DatatypeConstants.FIELD_UNDEFINED); signedSignatureProperties.setSigningTime(xmlSigningTime); // SigningCertificate CertIDListType signingCertificates = this.xadesObjectFactory.createCertIDListType(); CertIDType signingCertificateId = this.xadesObjectFactory.createCertIDType(); X509IssuerSerialType issuerSerial = this.xmldsigObjectFactory.createX509IssuerSerialType(); issuerSerial.setX509IssuerName(signingCertificate.getIssuerX500Principal().toString()); issuerSerial.setX509SerialNumber(signingCertificate.getSerialNumber()); signingCertificateId.setIssuerSerial(issuerSerial); DigestAlgAndValueType certDigest = this.xadesObjectFactory.createDigestAlgAndValueType(); DigestMethodType jaxbDigestMethod = this.xmldsigObjectFactory.createDigestMethodType(); jaxbDigestMethod.setAlgorithm(DigestMethod.SHA256); certDigest.setDigestMethod(jaxbDigestMethod); MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); byte[] digestValue; try {// w w w. j ava 2 s .c o m digestValue = messageDigest.digest(signingCertificate.getEncoded()); } catch (CertificateEncodingException e) { throw new RuntimeException("certificate encoding error: " + e.getMessage(), e); } certDigest.setDigestValue(digestValue); signingCertificateId.setCertDigest(certDigest); signingCertificates.getCert().add(signingCertificateId); signedSignatureProperties.setSigningCertificate(signingCertificates); // marshall XAdES QualifyingProperties Node qualifyingPropertiesNode = marshallQualifyingProperties(document, qualifyingProperties); // add XAdES ds:Object List<XMLStructure> xadesObjectContent = new LinkedList<XMLStructure>(); xadesObjectContent.add(new DOMStructure(qualifyingPropertiesNode)); XMLObject xadesObject = signatureFactory.newXMLObject(xadesObjectContent, null, null, null); objects.add(xadesObject); // add XAdES ds:Reference DigestMethod digestMethod = signatureFactory.newDigestMethod(DigestMethod.SHA256, null); List<Transform> transforms = new LinkedList<Transform>(); Transform exclusiveTransform = signatureFactory.newTransform(CanonicalizationMethod.EXCLUSIVE, (TransformParameterSpec) null); transforms.add(exclusiveTransform); Reference reference = signatureFactory.newReference("#" + signedPropertiesId, digestMethod, transforms, XADES_TYPE, null); references.add(reference); }
From source file:org.eclipse.uomo.util.impl.Iso8601Date.java
/** * get the date specified as a Date.//from w w w. j ava2s . c o m * * @param timezone * - REQUIRED, IF_PRESENT or IGNORE * @throws OHFException */ public Date getAsDate(int timezone) throws UOMoException { GregorianCalendar cal = new GregorianCalendar(); cal.clear(); if (year != -1) cal.set(Calendar.YEAR, year); if (month != -1) cal.set(Calendar.MONTH, month - 1); // Calendar month start with 0 if (day != -1) cal.set(Calendar.DAY_OF_MONTH, day); if (hour != -1) cal.set(Calendar.HOUR_OF_DAY, hour); if (minute != -1) cal.set(Calendar.MINUTE, minute); if (second != -1) cal.set(Calendar.SECOND, second); if (milli != -1) cal.set(Calendar.MILLISECOND, milli); if (timezone == REQUIRED || timezone == IF_PRESENT || timezone == OPTIONAL) { if (timezone == REQUIRED && tzNegative == null) throw new UOMoException(Messages.Iso8601Date_TZ_NOT_DEFINED); if (tzNegative != null) { TimeZone tzMsg = TimeZone.getTimeZone(Messages.Iso8601Date_GMT + prepTimezone()); cal.setTimeZone(tzMsg); } } return cal.getTime(); }
From source file:net.darkmist.clf.LogParser.java
private Date parseDate(String[] parts) throws LogFormatException { /*/*from w ww . j av a2s . c om*/ dateStr = matcher.group(4); try { return dateFormat.parse(dateStr); } catch(ParseException e) { throw new LogFormatException("Unable to parse date: " + dateStr, e); } */ int year; int mon; int day; int hour; int min; int sec; TimeZone tz; GregorianCalendar cal; String dateStr; Date ret; dateStr = parts[PART_TIME]; /* if((ret = dateCache.get(dateStr))!=null) return ret; */ if (lastDateStr != null && dateStr.equals(lastDateStr) && lastDate != null) return lastDate; if (cachedDateMatcher == null) cachedDateMatcher = PATTERN_DATE.matcher(dateStr); else cachedDateMatcher.reset(dateStr); if (!cachedDateMatcher.matches()) throw new LogFormatException("Time stamp " + dateStr + " does not match regex."); day = parse2DigitInt(cachedDateMatcher.group(1)); mon = parseMonth(cachedDateMatcher.group(2)); year = parse4DigitInt(cachedDateMatcher.group(3)); hour = parse2DigitInt(cachedDateMatcher.group(4)); min = parse2DigitInt(cachedDateMatcher.group(5)); sec = parse2DigitInt(cachedDateMatcher.group(6)); tz = parseTimeZone(cachedDateMatcher.group(7)); /* year = parse4DigitInt(parts[PART_YEAR]); mon = parseMonth(parts[PART_MON]); day = parse2DigitInt(parts[PART_DAY]); hour = parse2DigitInt(parts[PART_HOUR]); min = parse2DigitInt(parts[PART_MIN]); sec = parse2DigitInt(parts[PART_SEC]); tz = parseTimeZone(parts[PART_TZ]); */ // build cal = new GregorianCalendar(year, mon, day, hour, min, sec); cal.setTimeZone(tz); ret = cal.getTime(); //dateCache.put(dateStr, ret); lastDateStr = dateStr; lastDate = ret; return ret; }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.SystemPropertiesTests.java
public void testLookupDeserializesCreateAtToDate() throws Throwable { final String responseContent = "{\"id\":\"an id\",\"__createdAt\":\"2000-01-01T07:59:59.000Z\"}"; MobileServiceClient client = null;//from w w w.j a v a 2 s .c o m try { client = new MobileServiceClient(appUrl, appKey, getInstrumentation().getTargetContext()); } catch (MalformedURLException e) { e.printStackTrace(); } // Add a filter to handle the request and create a new json // object with an id defined client = client.withFilter(getTestFilter(responseContent)); // Create get the MobileService table MobileServiceTable<CreatedAtType> msTable = client.getTable(CreatedAtType.class); try { // Call the lookUp method CreatedAtType entity = msTable.lookUp("an id").get(); // Asserts if (entity == null) { fail("Expected result"); } else { assertTrue(entity instanceof CreatedAtType); GregorianCalendar calendar = new GregorianCalendar(2000, 00, 01, 07, 59, 59); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); assertEquals("an id", entity.Id); assertEquals(calendar.getTime(), entity.CreatedAt); } } catch (Exception exception) { fail(exception.getMessage()); } }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.SystemPropertiesTests.java
public void testLookupDeserializesUpdateAtToDate() throws Throwable { final String responseContent = "{\"id\":\"an id\",\"__updatedAt\":\"2000-01-01T07:59:59.000Z\"}"; MobileServiceClient client = null;/*from w w w . j a v a 2s. co m*/ try { client = new MobileServiceClient(appUrl, appKey, getInstrumentation().getTargetContext()); } catch (MalformedURLException e) { e.printStackTrace(); } // Add a filter to handle the request and create a new json // object with an id defined client = client.withFilter(getTestFilter(responseContent)); // Create get the MobileService table MobileServiceTable<UpdatedAtType> msTable = client.getTable(UpdatedAtType.class); try { // Call the lookUp method UpdatedAtType entity = msTable.lookUp("an id").get(); // Asserts if (entity == null) { fail("Expected result"); } else { assertTrue(entity instanceof UpdatedAtType); GregorianCalendar calendar = new GregorianCalendar(2000, 00, 01, 07, 59, 59); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); assertEquals("an id", entity.Id); assertEquals(calendar.getTime(), entity.UpdatedAt); } } catch (Exception exception) { fail(exception.getMessage()); } }