All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.tsl2.nano.h5.ICSCalendarImport Maven / Gradle / Ivy

Go to download

TSL2 Framework Html5 Extensions (WebServer, Html5Presentation, RuleCover, BeanConfigurator, LogicTable-Sheet, Expression-Descriptors for Actions, Rules, URLs, Queries)

There is a newer version: 2.5.2
Show newest version
/*
 * File: $HeadURL$
 * Id  : $Id$
 * 
 * created by: Tom, Thomas Schneider
 * created on: 12.03.2016
 * 
 * Copyright: (c) Thomas Schneider 2016, all rights reserved
 */
package de.tsl2.nano.h5;

import java.text.SimpleDateFormat;
import java.util.Collection;

import de.tsl2.nano.core.ENV;
import de.tsl2.nano.core.ICallback;
import de.tsl2.nano.core.util.NetUtil;
import de.tsl2.nano.core.util.Period;
import de.tsl2.nano.scanner.ICSCalendarReader;

/**
 * imports a holiday ics calendar from "http://www.kayaposoft.com/enrico/ics/v1.0?country=deu&fromDate=01-01-2016&toDate=31-12-2016®ion=Bavaria".
 * 
 * @author Tom, Thomas Schneider
 * @version $Revision$
 */
public class ICSCalendarImport {
    private static final SimpleDateFormat SDF = new SimpleDateFormat("dd-MM-yyyy");
    
    /**
     * importCalendar into Charge
     * 
     * @param country
     * @param region
     * @param period
     * @return count of entries
     */
    protected  Collection importCalendar(String country, String region, Period period, ICallback callback) {
        String holServiceURL = ENV.get("app.holiday.service.url",
            "http://www.kayaposoft.com/enrico/ics/v1.0") 
                + "?country=" + country + "&fromDate=" + SDF.format(period.getStart()) + "&toDate=" + SDF.format(period.getEnd()) + "®ion=" + region;
        NetUtil.download(holServiceURL, ENV.getTempPathRel());
        String file = getDownloadFile(country, region, period);
        return (Collection) ICSCalendarReader.forEach(file, callback);
    }

    protected String getDownloadFile(String country, String region, Period period) {
        return ENV.getTempPathRel() + country + " (" + region + ").ics";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy