de.tsl2.nano.scanner.ICSCalendarReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tsl2.nano.common Show documentation
Show all versions of tsl2.nano.common Show documentation
TSL2 Framework Commons (Collections, Actions/Excecution, Readers, Xml, Print, Mail, FuzzyFinder, Proxies, Network-Structure)
/*
* File: $HeadURL$
* Id : $Id$
*
* created by: Tom
* created on: 12.03.2016
*
* Copyright: (c) Thomas Schneider 2016, all rights reserved
*/
package de.tsl2.nano.scanner;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import de.tsl2.nano.core.ICallback;
import de.tsl2.nano.core.ManagedException;
import de.tsl2.nano.core.util.FileUtil;
/**
* Provides a stream of calendar entries to be consumed by a callback.
*
* @author Tom
* @version $Revision$
*/
public class ICSCalendarReader {
static final String BLOCK = "(?m)BEGIN[:]VEVENT.*END[:]VEVENT";
public static final String START = "DTSTART";
public static final String END = "DTEND";
public static final String SUMMARY = "SUMMARY";
public static final String CATEGORY = "CATEGORIES";
public static final String CLASS = "CLASS";
static final SimpleDateFormat DF = new SimpleDateFormat("yyyyMMdd");
static final SimpleDateFormat TF = new SimpleDateFormat("HHmmss");
/**
* forEach
*
* @param icsFile
* @param callback
* @return loop count
*/
public static List> forEach(String icsFile, final ICallback> callback) {
return FieldReader.forEach(FileUtil.getFile(icsFile), BLOCK, ":", new ICallback