Aathi
Aathi

Reputation: 43

how to parse ics file manually in java?

Hi i am new to java.I wish to parse the ics (outlook calendar file) manually.With out using third party api how to parse ics file in java?

Upvotes: 3

Views: 6822

Answers (2)

I'm_Pratik
I'm_Pratik

Reputation: 561

You can refer API Documentation of iCal4j http://ical4j.sourceforge.net/introduction.html

This might help you for parsing you can refer this code :

{
    Properties prop = new Properties();

            prop.put("mail.smtp.auth", "true");
            prop.put("mail.smtp.starttls.enable", "true");
            prop.put("mail.smtp.host", "smtp.gmail.com");
            prop.put("mail.smtp.port", "587");
            final String username = "xx@xx"; //your email id
            final String password = "password"; //your password
            System.out.println(meeting);
             try {
                 Session session = Session.getInstance(prop, new javax.mail.Authenticator() {
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(username, password);
                        }
                    });

                    MimeMessage mimeMessage = new MimeMessage(session);
        Multipart multipart = new MimeMultipart("alternative");
        if (calendar != null) {
                        // Another part for the calendar invite
                        MimeBodyPart invite = new MimeBodyPart();
                        invite.setHeader("Content-Class", "urn:content-  classes:calendarmessage");
                        invite.setHeader("Content-ID", "calendar_message");
                        invite.setHeader("Content-Disposition", "inline");
                        invite.setContent(calendar.toString(), "text/calendar");
                        multipart.addBodyPart(invite);
                    }

                    mimeMessage.setContent(multipart);

                    Transport.send(mimeMessage);
}

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1500525

Without using any third party libraries, you'll have basically have to write your own iCalendar (see RFC 5545) parser, reproducing the work of those third party libraries. It won't be fun.

Admittedly my own experiences with iCal4j haven't been terribly pleasant - but I wouldn't start writing my own parser from scratch using java.util.Date and java.util.Calendar. You may find it's worth writing an iCalendar parser using Joda Time to represent the various aspects ("a date", "a time" etc) as that's a much nicer API to work with than the built-in ones... but equally you may find that iCal4j is good enough for your purposes.

Upvotes: 5

Related Questions