summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/ICSParser.java')
-rw-r--r--src/ICSParser.java99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/ICSParser.java b/src/ICSParser.java
new file mode 100644
index 0000000..ac4f96d
--- /dev/null
+++ b/src/ICSParser.java
@@ -0,0 +1,99 @@
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+import java.security.MessageDigest;
+
+import java.net.URL;
+
+public class ICSParser
+{
+
+ public static void parse
+ (
+ final String url,
+ final Group group,
+ final boolean lazy,
+ final boolean uid_override
+ )
+ throws Exception
+ {
+ final BufferedReader reader;
+ final StringBuilder sb;
+
+ boolean should_record, has_id, ignore_line;
+ String line;
+ String class_name;
+ String hash_seed;
+ int length;
+ sb = new StringBuilder();
+ reader =
+ new BufferedReader(new InputStreamReader((new URL(url)).openStream()));
+
+ class_name = "unknown";
+ should_record = false;
+ ignore_line = false;
+
+ hash_seed = "";
+ has_id = false;
+
+ while ((line = reader.readLine()) != null)
+ {
+ if (line.startsWith("END:VEVENT"))
+ {
+ if (!has_id)
+ {
+ sb.append("UID:noid_");
+ sb.append(hash_seed.hashCode());
+ sb.append("\r\n");
+ }
+
+ sb.append(line);
+ sb.append("\r\n");
+
+ should_record = false;
+
+ group.add_ICS_fragment(sb.toString(), class_name, lazy);
+ sb.setLength(0);
+ }
+ else if (line.startsWith("BEGIN:VEVENT"))
+ {
+ should_record = true;
+ has_id = false;
+ hash_seed = "";
+ }
+ else if (line.startsWith("DTSTART:"))
+ {
+ hash_seed += line;
+ }
+ else if (line.startsWith("SUMMARY:"))
+ {
+ class_name = line.substring(8, line.length());
+ hash_seed += line;
+ }
+ else if (line.startsWith("UID"))
+ {
+ if (uid_override)
+ {
+ ignore_line = true;
+ }
+ else
+ {
+ has_id = true;
+ }
+ }
+
+ if (line.matches("\\w+:.*") && should_record)
+ {
+ if (!ignore_line)
+ {
+ sb.append(line);
+ sb.append("\r\n");
+ }
+
+ ignore_line = false;
+ }
+ }
+
+ reader.close();
+ }
+}