Created
June 7, 2010 15:17
-
-
Save namutaka/428787 to your computer and use it in GitHub Desktop.
Grails ical4j サンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // grails-app/controllers/cal/CalendarController.groovy | |
| package cal | |
| import net.fortuna.ical4j.data.* | |
| import net.fortuna.ical4j.model.* | |
| import net.fortuna.ical4j.model.property.* | |
| class CalendarController { | |
| def index = { | |
| params.max = Math.min( params.max ? params.max.toInteger() : 10, 100) | |
| def events = Event.list( params ) | |
| def builder = new ContentBuilder() | |
| def calendar = builder.calendar() { | |
| calscale('GREGORIAN') | |
| method('PUBLISH') | |
| xproperty('X-WR-CALNAME').setValue('My Calendar') | |
| version('2.0') | |
| for(event in events) { | |
| vevent() { | |
| if(event.isDay) { | |
| dtstart(new DtStart(new Date(event.start))) | |
| dtend(new DtEnd(new Date(event.end))) | |
| } else { | |
| dtstart(new DtStart(new DateTime(event.start))) | |
| dtend(new DtEnd(new DateTime(event.end))) | |
| } | |
| summary(event.title) | |
| if(event.description) { | |
| description(event.description) | |
| } | |
| } | |
| } | |
| } | |
| render(contentType: 'text/calendar', text: calendar) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // grails-app/domain/cal/Event.groovy | |
| package cal | |
| import javax.persistence.*; | |
| @Entity | |
| class Event implements Serializable { | |
| @Id | |
| @GeneratedValue(strategy = GenerationType.IDENTITY) | |
| Long id | |
| static constraints = { | |
| id visible:false | |
| } | |
| String title | |
| String description | |
| Date start | |
| Date end | |
| Boolean isDay = false | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment