Example usage for java.util GregorianCalendar setTimeZone

List of usage examples for java.util GregorianCalendar setTimeZone

Introduction

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

Prototype

@Override
    public void setTimeZone(TimeZone zone) 

Source Link

Usage

From source file:org.apache.tika.parser.exiftool.ExifToolImageParserTest.java

public void testJPEGIPTC() throws Exception {
    Metadata metadata = new Metadata();
    metadata.set(Metadata.CONTENT_TYPE, "image/jpeg");
    InputStream stream = getClass().getResourceAsStream("/test-documents/testJPEG_IPTC_EXT.jpg");
    parser.parse(stream, new DefaultHandler(), metadata, new ParseContext());

    assertEquals("Washington", metadata.get(IPTC.CITY));
    assertEquals("United States", metadata.get(IPTC.COUNTRY));
    assertEquals("US", metadata.get(IPTC.COUNTRY_CODE));

    assertEquals(// w  w w  .jav  a 2  s .c om
            "A stream bank in Rock Creek Park Washington DC during a photo bike tour with ASPP DC/South chapter.",
            metadata.get(IPTC.DESCRIPTION));
    assertEquals(
            "A stream bank in Rock Creek Park Washington DC during a photo bike tour with ASPP DC/South chapter.",
            metadata.get(Metadata.DESCRIPTION));

    assertEquals("Rock Creek Park", metadata.get(IPTC.HEADLINE));
    assertEquals("Downstream", metadata.get(Metadata.TITLE));

    assertEquals("intellectual genre", metadata.get(IPTC.INTELLECTUAL_GENRE));

    List<String> iptcKeywords = Arrays.asList(metadata.getValues(IPTC.KEYWORDS));
    assertTrue(iptcKeywords.contains("stream"));
    assertTrue(iptcKeywords.contains("park"));
    assertTrue(iptcKeywords.contains("bank"));
    assertEquals(5, iptcKeywords.size());
    List<String> tikaKeywords = Arrays.asList(metadata.getValues(Metadata.KEYWORDS));
    assertTrue(Arrays.toString(tikaKeywords.toArray()).contains("stream"));
    assertTrue(Arrays.toString(tikaKeywords.toArray()).contains("park"));
    assertTrue(Arrays.toString(tikaKeywords.toArray()).contains("bank"));
    assertEquals(5, tikaKeywords.size());

    assertEquals("DC", metadata.get(IPTC.PROVINCE_OR_STATE));

    List<String> iptcSceneCode = Arrays.asList(metadata.getValues(IPTC.SCENE_CODE));
    assertEquals(2, iptcSceneCode.size());
    assertTrue(Arrays.toString(iptcSceneCode.toArray()).contains("iptc scene 1"));
    assertTrue(Arrays.toString(iptcSceneCode.toArray()).contains("iptc scene 2"));

    List<String> iptcSubjectCode = Arrays.asList(metadata.getValues(IPTC.SUBJECT_CODE));
    assertEquals(2, iptcSubjectCode.size());
    assertTrue(Arrays.toString(iptcSubjectCode.toArray()).contains("iptc subject code 1"));
    assertTrue(Arrays.toString(iptcSubjectCode.toArray()).contains("iptc subject code 2"));

    assertEquals("Rock Creek Park", metadata.get(IPTC.SUBLOCATION));

    GregorianCalendar calendar = new GregorianCalendar();
    calendar.set(Calendar.YEAR, 2011);
    calendar.set(Calendar.MONTH, 7);
    calendar.set(Calendar.DATE, 31);
    calendar.set(Calendar.HOUR_OF_DAY, 12);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    assertEquals(calendar.getTime(), metadata.getDate(IPTC.DATE_CREATED));

    assertEquals("Ray Gauss II", metadata.get(IPTC.DESCRIPTION_WRITER));
    assertEquals("instructions", metadata.get(IPTC.INSTRUCTIONS));
    assertEquals("job identifier", metadata.get(IPTC.JOB_ID));
    assertEquals("Downstream", metadata.get(IPTC.TITLE));
    assertTrue(metadata.get(IPTC.COPYRIGHT_NOTICE).contains("Ray Gauss II"));

    List<String> creators = Arrays.asList(metadata.getValues(IPTC.CREATOR));
    assertTrue(Arrays.toString(creators.toArray()).contains("Ray Gauss II"));

    assertEquals("DAM Architect", metadata.get(IPTC.CREATORS_JOB_TITLE));
    assertEquals("provider", metadata.get(IPTC.CREDIT_LINE));
    assertEquals("rights usage terms", metadata.get(IPTC.RIGHTS_USAGE_TERMS));
    assertEquals("source", metadata.get(IPTC.SOURCE));
    assertEquals("1234 Some Road", metadata.get(IPTC.CONTACT_INFO_ADDRESS));
    assertEquals("Atlanta", metadata.get(IPTC.CONTACT_INFO_CITY));
    assertEquals("US", metadata.get(IPTC.CONTACT_INFO_COUNTRY));

    List<String> ciWorkEmails = Arrays.asList(metadata.getValues(IPTC.CONTACT_INFO_EMAIL));
    // Photoshop does not support true multi-value here
    assertTrue(Arrays.toString(ciWorkEmails.toArray()).contains("info@alfresco.com"));
    assertTrue(Arrays.toString(ciWorkEmails.toArray()).contains("other@example.com"));

    List<String> ciWorkTels = Arrays.asList(metadata.getValues(IPTC.CONTACT_INFO_PHONE));
    // Photoshop does not support true multi-value here
    assertTrue(Arrays.toString(ciWorkTels.toArray()).contains("555-1234"));
    assertTrue(Arrays.toString(ciWorkTels.toArray()).contains("555-4321"));

    assertEquals("30339", metadata.get(IPTC.CONTACT_INFO_POSTAL_CODE));
    assertEquals("GA", metadata.get(IPTC.CONTACT_INFO_STATE_PROVINCE));

    List<String> ciWorkUrls = Arrays.asList(metadata.getValues(IPTC.CONTACT_INFO_WEB_URL));
    // Photoshop does not support true multi-value here
    assertTrue(Arrays.toString(ciWorkUrls.toArray()).contains("http://alfresco.com"));
    assertTrue(Arrays.toString(ciWorkUrls.toArray()).contains("http://example.com"));

    assertEquals("rocky 1 and rocky 2 are big", metadata.get(IPTC.ADDITIONAL_MODEL_INFO));

    List<String> orgCodes = Arrays.asList(metadata.getValues(IPTC.ORGANISATION_CODE));
    assertEquals(2, orgCodes.size());
    assertEquals("ASPP", orgCodes.get(0));
    assertEquals("OTHER_ORG", orgCodes.get(1));

    // List<String> cvTerms = Arrays.asList(metadata.getValues(IPTC.CONTROLLED_VOCABULARY_TERM));

    List<String> modelAges = Arrays.asList(metadata.getValues(IPTC.MODEL_AGE));
    assertEquals(2, modelAges.size());
    assertEquals("1000", modelAges.get(0));
    assertEquals("1001", modelAges.get(1));

    List<String> orgNames = Arrays.asList(metadata.getValues(IPTC.ORGANISATION_NAME));
    assertEquals(2, orgNames.size());
    assertEquals("ASPP", orgNames.get(0));
    assertEquals("Other Org", orgNames.get(1));

    List<String> peopleShown = Arrays.asList(metadata.getValues(IPTC.PERSON));
    assertEquals(2, peopleShown.size());
    assertEquals("rocky 1", peopleShown.get(0));
    assertEquals("rocky 2", peopleShown.get(1));

    assertEquals("http://cv.iptc.org/newscodes/digitalsourcetype/digitalCapture",
            metadata.get(IPTC.DIGITAL_SOURCE_TYPE));
    assertEquals("Photo Bike Tour", metadata.get(IPTC.EVENT));

    assertEquals("RGAUSS", metadata.get(IPTC.IMAGE_SUPPLIER_ID));
    assertEquals("Ray Gauss II", metadata.get(IPTC.IMAGE_SUPPLIER_NAME));
    assertEquals("supplier image ID", metadata.get(IPTC.IMAGE_SUPPLIER_IMAGE_ID));
    assertEquals("3456", metadata.get(IPTC.MAX_AVAIL_HEIGHT));
    assertEquals("5184", metadata.get(IPTC.MAX_AVAIL_WIDTH));
    assertEquals("1.2.0", metadata.get(IPTC.PLUS_VERSION));

    List<String> copyrightOwnerIds = Arrays.asList(metadata.getValues(IPTC.COPYRIGHT_OWNER_ID));
    assertEquals(1, copyrightOwnerIds.size());
    assertEquals("RGAUSS", copyrightOwnerIds.get(0));
    // assertEquals("", copyrightOwnerIds.get(1)); // TODO: Get ExifTool to preserve empty values

    List<String> copyrightOwnerNames = Arrays.asList(metadata.getValues(IPTC.COPYRIGHT_OWNER_NAME));
    assertEquals(2, copyrightOwnerNames.size());
    assertEquals("Ray Gauss II", copyrightOwnerNames.get(0));
    assertEquals("GG", copyrightOwnerNames.get(1));

    List<String> imageCreatorIds = Arrays.asList(metadata.getValues(IPTC.IMAGE_CREATOR_ID));
    assertEquals(1, imageCreatorIds.size());
    assertEquals("RGAUSS", imageCreatorIds.get(0));
    // assertEquals("", imageCreatorIds.get(1)); // TODO: Get ExifTool to preserve empty values

    assertTrue(metadata.isMultiValued(IPTC.IMAGE_CREATOR_NAME));
    List<String> imageCreatorNames = Arrays.asList(metadata.getValues(IPTC.IMAGE_CREATOR_NAME));
    assertEquals(2, imageCreatorNames.size());
    assertEquals("Ray Gauss II", imageCreatorNames.get(0));
    assertEquals("GG", imageCreatorNames.get(1));

    List<String> licensorIds = Arrays.asList(metadata.getValues(IPTC.LICENSOR_ID));
    assertEquals("RGAUSS", licensorIds.get(0));

    assertTrue(metadata.isMultiValued(IPTC.LICENSOR_NAME));
    List<String> licensorNames = Arrays.asList(metadata.getValues(IPTC.LICENSOR_NAME));
    assertEquals(2, licensorNames.size());
    assertEquals("Ray Gauss II", licensorNames.get(0));
    assertEquals("GG", licensorNames.get(1));

    // Photoshop does not support licensor addresses, cities, or countries

    List<String> licensorEmails = Arrays.asList(metadata.getValues(IPTC.LICENSOR_EMAIL));
    assertEquals("r@example.com", licensorEmails.get(0));
    // assertEquals("", licensorEmails.get(1)); // TODO: Get ExifTool to preserve empty values
    List<String> licensorTel1 = Arrays.asList(metadata.getValues(IPTC.LICENSOR_TELEPHONE_1));
    assertEquals("555-5555", licensorTel1.get(0));
    // assertEquals("", licensorTel1.get(1)); // TODO: Get ExifTool to preserve empty values
    List<String> licensorTel2 = Arrays.asList(metadata.getValues(IPTC.LICENSOR_TELEPHONE_2));
    assertEquals("555-4444", licensorTel2.get(0));
    // assertEquals("", licensorTel2.get(1)); // TODO: Get ExifTool to preserve empty values
    List<String> licensorUrls = Arrays.asList(metadata.getValues(IPTC.LICENSOR_URL));
    assertEquals("http://rgauss.com", licensorUrls.get(0));
    // assertEquals("", licensorUrls.get(1)); // TODO: Get ExifTool to preserve empty values

    assertEquals("Age Unknown", metadata.get(IPTC.MINOR_MODEL_AGE_DISCLOSURE));
    List<String> modelReleaseIds = Arrays.asList(metadata.getValues(IPTC.MODEL_RELEASE_ID));
    assertEquals("model release id 1", modelReleaseIds.get(0));
    assertEquals("model release id 2", modelReleaseIds.get(1));
    assertEquals("Not Applicable", metadata.get(IPTC.MODEL_RELEASE_STATUS));

    List<String> propertyReleaseIds = Arrays.asList(metadata.getValues(IPTC.PROPERTY_RELEASE_ID));
    assertEquals("prop release id 1", propertyReleaseIds.get(0));
    assertEquals("prop release id 2", propertyReleaseIds.get(1));
    assertEquals("Not Applicable", metadata.get(IPTC.PROPERTY_RELEASE_STATUS));

    List<String> aoCopyright = Arrays
            .asList(metadata.getValues(IPTC.ARTWORK_OR_OBJECT_DETAIL_COPYRIGHT_NOTICE));
    assertEquals("Ray Gauss II", aoCopyright.get(0));
    // assertEquals("", aoCopyright.get(1)); // TODO: Get ExifTool to preserve empty values
    // assertEquals("", aoCopyright.get(2)); // TODO: Get ExifTool to preserve empty values
    List<String> aoCreator = Arrays.asList(metadata.getValues(IPTC.ARTWORK_OR_OBJECT_DETAIL_CREATOR));
    assertEquals("Mother Nature", aoCreator.get(0));
    assertEquals("Man", aoCreator.get(1));
    assertEquals("Mother Nature", aoCreator.get(2));
    List<String> aoDateCreated = Arrays.asList(metadata.getValues(IPTC.ARTWORK_OR_OBJECT_DETAIL_DATE_CREATED));
    assertEquals("1890:01:01", aoDateCreated.get(0));
    // assertEquals("", aoDateCreated.get(1)); // TODO: Get ExifTool to preserve empty values
    assertEquals("1901:02:01", aoDateCreated.get(1));
    // assertEquals("", aoDateCreated.get(2)); // TODO: Get ExifTool to preserve empty values
    List<String> aoSource = Arrays.asList(metadata.getValues(IPTC.ARTWORK_OR_OBJECT_DETAIL_SOURCE));
    assertEquals("National Park Service", aoSource.get(0));
    // assertEquals("", aoSource.get(1)); // TODO: Get ExifTool to preserve empty values
    // assertEquals("", aoSource.get(2)); // TODO: Get ExifTool to preserve empty values
    List<String> aoSourceInventoryNum = Arrays
            .asList(metadata.getValues(IPTC.ARTWORK_OR_OBJECT_DETAIL_SOURCE_INVENTORY_NUMBER));
    assertEquals("123456", aoSourceInventoryNum.get(0));
    // assertEquals("", aoSourceInventoryNum.get(1)); // TODO: Get ExifTool to preserve empty values
    assertEquals("654321", aoSourceInventoryNum.get(1)); // This should be index 2, TODO: Get ExifTool to preserve empty values
    List<String> aoSourceTitles = Arrays.asList(metadata.getValues(IPTC.ARTWORK_OR_OBJECT_DETAIL_TITLE));
    assertEquals("Rock Creek Stream Bank", aoSourceTitles.get(0));
    assertEquals("Pollution", aoSourceTitles.get(1));
    assertEquals("Some Tree", aoSourceTitles.get(2));

    List<String> locationShownCity = Arrays.asList(metadata.getValues(IPTC.LOCATION_SHOWN_CITY));
    assertEquals("Washington", locationShownCity.get(0));
    // assertEquals("", locationShownCity.get(1)); // TODO: Get ExifTool to preserve empty values
    List<String> locationShownCountryCode = Arrays.asList(metadata.getValues(IPTC.LOCATION_SHOWN_COUNTRY_CODE));
    assertEquals("US", locationShownCountryCode.get(0));
    // assertEquals("", locationShownCountryCode.get(1)); // TODO: Get ExifTool to preserve empty values
    List<String> locationShownCountryName = Arrays.asList(metadata.getValues(IPTC.LOCATION_SHOWN_COUNTRY_NAME));
    assertEquals("United States", locationShownCountryName.get(0));
    // assertEquals("", locationShownCountryName.get(1)); // TODO: Get ExifTool to preserve empty values
    List<String> locationShownState = Arrays.asList(metadata.getValues(IPTC.LOCATION_SHOWN_PROVINCE_OR_STATE));
    assertEquals("D.C.", locationShownState.get(0));
    // assertEquals("", locationShownState.get(1)); // TODO: Get ExifTool to preserve empty values
    List<String> locationShownSublocation = Arrays.asList(metadata.getValues(IPTC.LOCATION_SHOWN_SUBLOCATION));
    assertEquals("Rock Creek Park Sub", locationShownSublocation.get(0));
    assertEquals("Stream Section", locationShownSublocation.get(1));
    List<String> locationShownWorldRegion = Arrays.asList(metadata.getValues(IPTC.LOCATION_SHOWN_WORLD_REGION));
    assertEquals("North America", locationShownWorldRegion.get(0));
    // assertEquals("", locationShownWorldRegion.get(1)); // TODO: Get ExifTool to preserve empty values

    assertEquals("Washington", metadata.get(IPTC.LOCATION_CREATED_CITY));
    assertEquals("US", metadata.get(IPTC.LOCATION_CREATED_COUNTRY_CODE));
    assertEquals("United States", metadata.get(IPTC.LOCATION_CREATED_COUNTRY_NAME));
    assertEquals("D.C.", metadata.get(IPTC.LOCATION_CREATED_PROVINCE_OR_STATE));
    assertEquals("Rock Creek Park", metadata.get(IPTC.LOCATION_CREATED_SUBLOCATION));
    assertEquals("North America", metadata.get(IPTC.LOCATION_CREATED_WORLD_REGION));

    assertTrue(IPTC.REGISTRY_ENTRY_CREATED_ORGANISATION_ID.isMultiValuePermitted());
    assertTrue(metadata.isMultiValued(IPTC.REGISTRY_ENTRY_CREATED_ORGANISATION_ID));
    List<String> registryEntryOrgIds = Arrays
            .asList(metadata.getValues(IPTC.REGISTRY_ENTRY_CREATED_ORGANISATION_ID));
    assertEquals(2, registryEntryOrgIds.size());
    assertEquals("PLUS", registryEntryOrgIds.get(0));
    // assertEquals("", registryEntryOrgIds.get(1)); // TODO: Get ExifTool to preserve empty values
    assertEquals("ORG 2", registryEntryOrgIds.get(1)); // This should be index 2, TODO: Get ExifTool to preserve empty values

    assertTrue(IPTC.REGISTRY_ENTRY_CREATED_ORGANISATION_ID.isMultiValuePermitted());
    assertTrue(metadata.isMultiValued(IPTC.REGISTRY_ENTRY_CREATED_ITEM_ID));
    List<String> registryEntryItemIds = Arrays.asList(metadata.getValues(IPTC.REGISTRY_ENTRY_CREATED_ITEM_ID));
    assertEquals(registryEntryItemIds.size(), 3);
    assertEquals("100-ABC-ABC-555", registryEntryItemIds.get(0));
    assertEquals("11223344", registryEntryItemIds.get(1));
    assertEquals("55667788", registryEntryItemIds.get(2));

}

From source file:be.fedict.eid.tsl.TrustService.java

public void addServiceHistory(String serviceTypeIdentifier, String serviceName, String servicePreviousStatus,
        DateTime statusPreviousStartingDate, X509Certificate... certificates) {

    ServiceHistoryType serviceHistoryType;
    ServiceHistoryInstanceType serviceHistoryInstanceType;

    if (this.tspService.getServiceHistory() == null) {
        serviceHistoryType = this.objectFactory.createServiceHistoryType();
        this.tspService.setServiceHistory(serviceHistoryType);
    } else {//from  w w w . jav  a  2s  .  c  om
        serviceHistoryType = this.tspService.getServiceHistory();
    }

    serviceHistoryInstanceType = this.objectFactory.createServiceHistoryInstanceType();

    serviceHistoryInstanceType.setServiceTypeIdentifier(serviceTypeIdentifier);

    InternationalNamesType i18nServiceName = this.objectFactory.createInternationalNamesType();
    List<MultiLangNormStringType> serviceNames = i18nServiceName.getName();
    MultiLangNormStringType serviceNameJaxb = this.objectFactory.createMultiLangNormStringType();
    serviceNames.add(serviceNameJaxb);
    serviceNameJaxb.setLang(Locale.ENGLISH.getLanguage());
    X509Certificate certificate = certificates[0];
    if (null == serviceName) {
        serviceNameJaxb.setValue(certificate.getSubjectX500Principal().toString());
    } else {
        serviceNameJaxb.setValue(serviceName);
    }
    serviceHistoryInstanceType.setServiceName(i18nServiceName);

    DigitalIdentityListType digitalIdentityList = createDigitalIdentityList(certificates);
    serviceHistoryInstanceType.setServiceDigitalIdentity(digitalIdentityList);

    serviceHistoryInstanceType.setServiceStatus(servicePreviousStatus);

    GregorianCalendar statusStartingCalendar;
    if (null == this.statusStartingDate) {
        statusStartingCalendar = new DateTime(certificate.getNotBefore()).toGregorianCalendar();
    } else {
        statusStartingCalendar = this.statusStartingDate.toGregorianCalendar();
    }
    statusStartingCalendar.setTimeZone(TimeZone.getTimeZone("Z"));
    XMLGregorianCalendar statusStartingTime = this.datatypeFactory
            .newXMLGregorianCalendar(statusStartingCalendar);
    serviceHistoryInstanceType.setStatusStartingTime(statusStartingTime);

    serviceHistoryType.getServiceHistoryInstance().add(serviceHistoryInstanceType);

}

From source file:be.fedict.eid.tsl.TrustService.java

public TrustService(String serviceName, String serviceTypeIdentifier, String serviceStatus,
        DateTime statusStartingDate, X509Certificate... certificates) {
    this.serviceName = serviceName;
    this.statusStartingDate = statusStartingDate;
    this.objectFactory = new ObjectFactory();
    try {//from  w  w  w  .j  a va  2s .  c o m
        this.datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException("datatype config error: " + e.getMessage(), e);
    }
    this.eccObjectFactory = new be.fedict.eid.tsl.jaxb.ecc.ObjectFactory();
    this.xadesObjectFactory = new be.fedict.eid.tsl.jaxb.xades.ObjectFactory();

    this.tspService = this.objectFactory.createTSPServiceType();
    TSPServiceInformationType tspServiceInformation = this.objectFactory.createTSPServiceInformationType();
    this.tspService.setServiceInformation(tspServiceInformation);
    tspServiceInformation.setServiceTypeIdentifier(serviceTypeIdentifier);
    InternationalNamesType i18nServiceName = this.objectFactory.createInternationalNamesType();
    List<MultiLangNormStringType> serviceNames = i18nServiceName.getName();
    MultiLangNormStringType serviceNameJaxb = this.objectFactory.createMultiLangNormStringType();
    serviceNames.add(serviceNameJaxb);
    serviceNameJaxb.setLang(Locale.ENGLISH.getLanguage());
    X509Certificate certificate = certificates[0];
    if (null == this.serviceName) {
        serviceNameJaxb.setValue(certificate.getSubjectX500Principal().toString());
    } else {
        serviceNameJaxb.setValue(this.serviceName);
    }
    tspServiceInformation.setServiceName(i18nServiceName);

    DigitalIdentityListType digitalIdentityList = createDigitalIdentityList(certificates);
    tspServiceInformation.setServiceDigitalIdentity(digitalIdentityList);

    tspServiceInformation.setServiceStatus(serviceStatus);

    GregorianCalendar statusStartingCalendar;
    if (null == this.statusStartingDate) {
        statusStartingCalendar = new DateTime(certificate.getNotBefore()).toGregorianCalendar();
    } else {
        statusStartingCalendar = this.statusStartingDate.toGregorianCalendar();
    }
    statusStartingCalendar.setTimeZone(TimeZone.getTimeZone("Z"));
    XMLGregorianCalendar statusStartingTime = this.datatypeFactory
            .newXMLGregorianCalendar(statusStartingCalendar);
    tspServiceInformation.setStatusStartingTime(statusStartingTime);
    /*
    if (null != serviceHistoryStatus){
       this.tspService.setServiceHistory(serviceHistoryStatus);
    }
    */
}

From source file:com.openkm.cmis.CmisRepository.java

/**
 * Converts milliseconds into a calendar object.
 *//*  www .  j ava  2  s.c o m*/
private static GregorianCalendar millisToCalendar(long millis) {
    GregorianCalendar result = new GregorianCalendar();
    result.setTimeZone(TimeZone.getTimeZone("GMT"));
    result.setTimeInMillis((long) (Math.ceil((double) millis / 1000) * 1000));

    return result;
}

From source file:io.n7.calendar.caldav.CalDAVService.java

private long parseDateTimeToMillis(String date, String tzid) {
    GregorianCalendar cal = new GregorianCalendar(Integer.parseInt(date.substring(0, 4)),
            Integer.parseInt(date.substring(4, 6)) - 1, Integer.parseInt(date.substring(6, 8)),
            Integer.parseInt(date.substring(9, 11)), Integer.parseInt(date.substring(11, 13)),
            Integer.parseInt(date.substring(13, 15)));
    TimeZone tz = TimeZone.getTimeZone(tzid);
    cal.setTimeZone(tz);
    return cal.getTimeInMillis();
}

From source file:net.sourceforge.eclipsetrader.yahoo.Feed.java

private void update() {
    // Builds the url for quotes download
    String host = "quote.yahoo.com"; //$NON-NLS-1$
    StringBuffer url = new StringBuffer("http://" + host + "/download/javasoft.beans?symbols="); //$NON-NLS-1$ //$NON-NLS-2$
    for (Iterator iter = map.values().iterator(); iter.hasNext();)
        url = url.append((String) iter.next() + "+"); //$NON-NLS-1$
    if (url.charAt(url.length() - 1) == '+')
        url.deleteCharAt(url.length() - 1);
    url.append("&format=sl1d1t1c1ohgvbap"); //$NON-NLS-1$
    log.debug(url.toString());//from  w  ww  . j  av a  2s .  co  m

    // Read the last prices
    String line = ""; //$NON-NLS-1$
    try {
        HttpClient client = new HttpClient();
        client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);

        BundleContext context = YahooPlugin.getDefault().getBundle().getBundleContext();
        ServiceReference reference = context.getServiceReference(IProxyService.class.getName());
        if (reference != null) {
            IProxyService proxy = (IProxyService) context.getService(reference);
            IProxyData data = proxy.getProxyDataForHost(host, IProxyData.HTTP_PROXY_TYPE);
            if (data != null) {
                if (data.getHost() != null)
                    client.getHostConfiguration().setProxy(data.getHost(), data.getPort());
                if (data.isRequiresAuthentication())
                    client.getState().setProxyCredentials(AuthScope.ANY,
                            new UsernamePasswordCredentials(data.getUserId(), data.getPassword()));
            }
        }

        HttpMethod method = new GetMethod(url.toString());
        method.setFollowRedirects(true);
        client.executeMethod(method);

        BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
        while ((line = in.readLine()) != null) {
            String[] item = line.split(","); //$NON-NLS-1$
            if (line.indexOf(";") != -1) //$NON-NLS-1$
                item = line.split(";"); //$NON-NLS-1$

            Double open = null, high = null, low = null, close = null;
            Quote quote = new Quote();

            // 2 = Date
            // 3 = Time
            try {
                GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("EST"), Locale.US); //$NON-NLS-1$
                usDateTimeParser.setTimeZone(c.getTimeZone());
                usDateParser.setTimeZone(c.getTimeZone());
                usTimeParser.setTimeZone(c.getTimeZone());

                String date = stripQuotes(item[2]);
                if (date.indexOf("N/A") != -1) //$NON-NLS-1$
                    date = usDateParser.format(Calendar.getInstance().getTime());
                String time = stripQuotes(item[3]);
                if (time.indexOf("N/A") != -1) //$NON-NLS-1$
                    time = usTimeParser.format(Calendar.getInstance().getTime());
                c.setTime(usDateTimeParser.parse(date + " " + time)); //$NON-NLS-1$
                c.setTimeZone(TimeZone.getDefault());
                quote.setDate(c.getTime());
            } catch (Exception e) {
                log.error(e.getMessage() + ": " + line); //$NON-NLS-1$
            }
            // 1 = Last price or N/A
            if (item[1].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$
                quote.setLast(numberFormat.parse(item[1]).doubleValue());
            // 4 = Change
            // 5 = Open
            if (item[5].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$
                open = new Double(numberFormat.parse(item[5]).doubleValue());
            // 6 = Maximum
            if (item[6].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$
                high = new Double(numberFormat.parse(item[6]).doubleValue());
            // 7 = Minimum
            if (item[7].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$
                low = new Double(numberFormat.parse(item[7]).doubleValue());
            // 8 = Volume
            if (item[8].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$
                quote.setVolume(numberFormat.parse(item[8]).intValue());
            // 9 = Bid Price
            if (item[9].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$
                quote.setBid(numberFormat.parse(item[9]).doubleValue());
            // 10 = Ask Price
            if (item[10].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$
                quote.setAsk(numberFormat.parse(item[10]).doubleValue());
            // 11 = Close Price
            if (item[11].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$
                close = new Double(numberFormat.parse(item[11]).doubleValue());

            // 0 = Code
            String symbol = stripQuotes(item[0]);
            for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
                Security security = (Security) iter.next();
                if (symbol.equalsIgnoreCase((String) map.get(security))) {
                    security.setQuote(quote, open, high, low, close);
                }
            }
        }
        in.close();
    } catch (Exception e) {
        log.error(e);
    }
}

From source file:org.sakaiproject.time.impl.BasicTimeService.java

/**
 * {@inheritDoc}//from   w  ww.j  a  v  a  2 s  .  com
 */
public GregorianCalendar getCalendar(TimeZone zone, int year, int month, int day, int hour, int min, int sec,
        int ms) {
    GregorianCalendar rv = new GregorianCalendar(year, month, day, hour, min, sec);
    rv.setTimeZone(zone);
    rv.set(GregorianCalendar.MILLISECOND, ms);

    return rv;
}

From source file:net.sourceforge.eclipsetrader.opentick.Feed.java

public void snapshot() {
    SimpleDateFormat usDateTimeParser = new SimpleDateFormat("MM/dd/yyyy h:mma");
    SimpleDateFormat usDateParser = new SimpleDateFormat("MM/dd/yyyy");
    SimpleDateFormat usTimeParser = new SimpleDateFormat("h:mma");
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);

    // Builds the url for quotes download
    String host = "quote.yahoo.com";
    StringBuffer url = new StringBuffer("http://" + host + "/download/javasoft.beans?symbols=");
    for (Iterator iter = subscribedSecurities.iterator(); iter.hasNext();) {
        Security security = (Security) iter.next();
        url = url.append(security.getCode() + "+");
    }/*  w  w w  . ja  v a2  s . com*/
    if (url.charAt(url.length() - 1) == '+')
        url.deleteCharAt(url.length() - 1);
    url.append("&format=sl1d1t1c1ohgvbap");

    // Read the last prices
    String line = "";
    try {
        HttpClient client = new HttpClient();
        client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);

        BundleContext context = OpenTickPlugin.getDefault().getBundle().getBundleContext();
        ServiceReference reference = context.getServiceReference(IProxyService.class.getName());
        if (reference != null) {
            IProxyService proxy = (IProxyService) context.getService(reference);
            IProxyData data = proxy.getProxyDataForHost(host, IProxyData.HTTP_PROXY_TYPE);
            if (data != null) {
                if (data.getHost() != null)
                    client.getHostConfiguration().setProxy(data.getHost(), data.getPort());
                if (data.isRequiresAuthentication())
                    client.getState().setProxyCredentials(AuthScope.ANY,
                            new UsernamePasswordCredentials(data.getUserId(), data.getPassword()));
            }
        }

        HttpMethod method = new GetMethod(url.toString());
        method.setFollowRedirects(true);
        client.executeMethod(method);

        BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
        while ((line = in.readLine()) != null) {
            String[] item = line.split(",");
            if (line.indexOf(";") != -1)
                item = line.split(";");

            Double open = null, high = null, low = null, close = null;
            Quote quote = new Quote();

            // 2 = Date
            // 3 = Time
            try {
                GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("EST"), Locale.US);
                usDateTimeParser.setTimeZone(c.getTimeZone());
                usDateParser.setTimeZone(c.getTimeZone());
                usTimeParser.setTimeZone(c.getTimeZone());

                String date = stripQuotes(item[2]);
                if (date.indexOf("N/A") != -1)
                    date = usDateParser.format(Calendar.getInstance().getTime());
                String time = stripQuotes(item[3]);
                if (time.indexOf("N/A") != -1)
                    time = usTimeParser.format(Calendar.getInstance().getTime());
                c.setTime(usDateTimeParser.parse(date + " " + time));
                c.setTimeZone(TimeZone.getDefault());
                quote.setDate(c.getTime());
            } catch (Exception e) {
                System.out.println(e.getMessage() + ": " + line);
            }
            // 1 = Last price or N/A
            if (item[1].equalsIgnoreCase("N/A") == false)
                quote.setLast(numberFormat.parse(item[1]).doubleValue());
            // 4 = Change
            // 5 = Open
            if (item[5].equalsIgnoreCase("N/A") == false)
                open = new Double(numberFormat.parse(item[5]).doubleValue());
            // 6 = Maximum
            if (item[6].equalsIgnoreCase("N/A") == false)
                high = new Double(numberFormat.parse(item[6]).doubleValue());
            // 7 = Minimum
            if (item[7].equalsIgnoreCase("N/A") == false)
                low = new Double(numberFormat.parse(item[7]).doubleValue());
            // 8 = Volume
            if (item[8].equalsIgnoreCase("N/A") == false)
                quote.setVolume(numberFormat.parse(item[8]).intValue());
            // 9 = Bid Price
            if (item[9].equalsIgnoreCase("N/A") == false)
                quote.setBid(numberFormat.parse(item[9]).doubleValue());
            // 10 = Ask Price
            if (item[10].equalsIgnoreCase("N/A") == false)
                quote.setAsk(numberFormat.parse(item[10]).doubleValue());
            // 11 = Close Price
            if (item[11].equalsIgnoreCase("N/A") == false)
                close = new Double(numberFormat.parse(item[11]).doubleValue());

            // 0 = Code
            String symbol = stripQuotes(item[0]);
            for (Iterator iter = subscribedSecurities.iterator(); iter.hasNext();) {
                Security security = (Security) iter.next();
                if (symbol.equalsIgnoreCase(security.getCode()))
                    security.setQuote(quote, open, high, low, close);
            }
        }
        in.close();
    } catch (Exception e) {
        System.out.println(e.getMessage() + ": " + line);
        e.printStackTrace();
    }
}

From source file:stg.utils.immutable.Day.java

private GregorianCalendar getCalendarInstance(TimeZone zone) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.clear();//from   www.j a va2s.  co  m
    calendar.setLenient(false);
    calendar.setTimeZone(zone);
    return calendar;
}

From source file:be.fedict.eid.tsl.TrustServiceList.java

public void setListIssueDateTime(DateTime listIssueDateTime) {
    TSLSchemeInformationType schemeInformation = getSchemeInformation();
    GregorianCalendar listIssueCalendar = listIssueDateTime.toGregorianCalendar();
    listIssueCalendar.setTimeZone(TimeZone.getTimeZone("Z"));
    schemeInformation.setListIssueDateTime(this.datatypeFactory.newXMLGregorianCalendar(listIssueCalendar));
}