#1095 : ICalGenerator.kt
projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/ical/ICalGenerator.kt Classe Kotlin, projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/ical/ICalGenerator.kt 118 lignes · 71 code · 33 commentaires · 14 vides
Objectif : Fichier source : business/teamcal/ical/ICalGenerator.kt. ICalGenerator.kt fait partie de l'application open-source de gestion de projet ProjectForge.
Source (100 premières lignes)
/////////////////////////////////////////////////////////////////////////////
//
// Projet ProjectForge Community Edition
// www.projectforge.org
//
// Copyright (C) 2001-2026 Micromata GmbH, Allemagne (www.micromata.com)
//
// ProjectForge est sous double licence.
//
// Cette édition communautaire est un logiciel libre ; vous pouvez la redistribuer et/ou
// la modifier selon les termes de la GNU General Public License telle que publiée
// par la Free Software Foundation ; version 3 de la Licence.
//
// Cette édition communautaire est distribuée dans l'espoir qu'elle sera utile,
// mais SANS AUCUNE GARANTIE ; sans même la garantie implicite de
// QUALITÉ MARCHANDE ou d'ADÉQUATION À UN USAGE PARTICULIER. Voir la GNU General
// Public License pour plus de détails.
//
// Vous devriez avoir reçu une copie de la GNU General Public License avec
// ce programme ; sinon, consultez http://www.gnu.org/licenses/.
//
/////////////////////////////////////////////////////////////////////////////
package org.projectforge.business.teamcal.ical
import mu.KotlinLogging
import net.fortuna.ical4j.data.CalendarOutputter
import net.fortuna.ical4j.model.Calendar
import net.fortuna.ical4j.model.component.VEvent
import org.projectforge.ProjectForgeVersion
import org.projectforge.business.calendar.event.model.ICalendarEvent
import org.projectforge.business.teamcal.event.model.TeamEventDO
import java.io.ByteArrayOutputStream
import java.io.IOException
import java.io.OutputStream
import java.time.LocalDate
import java.util.*
private val log = KotlinLogging.logger {}
/**
* Écrit les événements au format ics.
*/
class ICalGenerator @JvmOverloads constructor(val exportVAlarms: Boolean = true, val editable: Boolean = false) {
var empty: Boolean = true
private set
// Crée un objet calendrier
private val calendar = Calendar()
.withProdId("-//${ProjectForgeVersion.APP_ID} ${ProjectForgeVersion.VERSION_NUMBER}//Générateur iCal//FR")
.withDefaults() // add(GREGORIAN).add(VERSION_2_0)
/**
* Garantit au moins un événement de configuration.
*/
fun ensureNotEmpty() {
if (empty) {
calendar.withComponent(VEventUtils.createSetupEvent())
}
}
fun add(events: List<TeamEventDO>) {
// Convertit TeamEventDO en VEvent et l'ajoute au calendrier
events.forEach { event ->
add(event)
}
}
fun add(event: ICalendarEvent) {
val vEvent = VEventUtils.convertToVEvent(event)
// Ajoute l'événement au calendrier
calendar.withComponent(vEvent)
empty = false
}
fun addAllDayEvent(startDay: LocalDate, endDay: LocalDate?, title: String, uid: String): VEvent {
val vEvent = VEventUtils.createAllDayEvent(startDay, endDay ?: startDay, title, uid)
// Ajoute l'événement au calendrier
calendar.withComponent(vEvent)
empty = false
return vEvent
}
fun addEvent(startDate: Date, endDate: Date, title: String, uid: String): VEvent {
val vEvent = VEventUtils.createEvent(startDate, endDate, title, uid)
// Ajoute l'événement au calendrier
calendar.withComponent(vEvent)
empty = false
return vEvent
}
val asByteArray: ByteArray?
get() {
try {
ByteArrayOutputStream().use { stream ->
val outputter = CalendarOutputter()
outputter.output(this.calendar.fluentTarget, stream)
return stream.toByteArray()
}
} catch (ex: IOException) {
Historique Git
868d6abb7 2025 -> 2026
63081666f En-têtes des fichiers source : 2024 -> 2025.
c193e8288 Ical4j : migration... (tous les tests OK)
868d6abb7
2025 -> 2026868d6abb75cd191a892911ac8e45058932cf9074
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/ical/ICalGenerator.kt b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/ical/ICalGenerator.kt
index 7692ab96d..88113b38c 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/ical/ICalGenerator.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/ical/ICalGenerator.kt
@@ -3,7 +3,7 @@
// Projet ProjectForge Community Edition
// www.projectforge.org
//
-// Copyright (C) 2001-2025 Micromata GmbH, Allemagne (www.micromata.com)
+// Copyright (C) 2001-2026 Micromata GmbH, Allemagne (www.micromata.com)
//
// ProjectForge est sous double licence.
//
63081666f
En-têtes des fichiers source : 2024 -> 2025.63081666f620fb87315f01b817e560e0b2f6a33a
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/ical/ICalGenerator.kt b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/ical/ICalGenerator.kt
index e7df854e5..7692ab96d 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/ical/ICalGenerator.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/ical/ICalGenerator.kt
@@ -3,7 +3,7 @@
// Projet ProjectForge Community Edition
// www.projectforge.org
//
-// Copyright (C) 2001-2024 Micromata GmbH, Allemagne (www.micromata.com)
+// Copyright (C) 2001-2025 Micromata GmbH, Allemagne (www.micromata.com)
//
// ProjectForge est sous double licence.
//
c193e8288
Ical4j : migration... (tous les tests OK)c193e8288c03be35a08171e2319957a6080381b9
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/ical/ICalGenerator.kt b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/ical/ICalGenerator.kt
new file mode 100644
index 000000000..e7df854e5
--- /dev/null
+++ b/projectforge-business/src/main/kotlin/org/projectforge/business/teamcal/ical/ICalGenerator.kt
@@ -0,0 +1,118 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// Projet ProjectForge Community Edition
+// www.projectforge.org
+//
+// Copyright (C) 2001-2024 Micromata GmbH, Allemagne (www.micromata.com)
+//
+// ProjectForge est sous double licence.
+//
+// Cette édition communautaire est un logiciel libre ; vous pouvez la redistribuer et/ou
+// la modifier selon les termes de la GNU General Public License telle que publiée
+// par la Free Software Foundation ; version 3 de la Licence.
+//
+// Cette édition communautaire est distribuée dans l'espoir qu'elle sera utile,
+// mais SANS AUCUNE GARANTIE ; sans même la garantie implicite de
+// QUALITÉ MARCHANDE ou d'ADÉQUATION À UN USAGE PARTICULIER. Voir la GNU General
+// Public License pour plus de détails.
+//
+// Vous devriez avoir reçu une copie de la GNU General Public License avec
+// ce programme ; sinon, consultez http://www.gnu.org/licenses/.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+package org.projectforge.business.teamcal.ical
+
+import mu.KotlinLogging
+import net.fortuna.ical4j.data.CalendarOutputter
+import net.fortuna.ical4j.model.Calendar
+import net.fortuna.ical4j.model.component.VEvent
+import org.projectforge.ProjectForgeVersion
+import org.projectforge.business.calendar.event.model.ICalendarEvent
+import org.projectforge.business.teamcal.event.model.TeamEventDO
+import java.io.ByteArrayOutputStream
+import java.io.IOException
+import java.io.OutputStream
+import java.time.LocalDate
+import java.util.*
+
+private val log = KotlinLogging.logger {}
+
+/**
+ * Écrit les événements au format ics.
+ */
+class ICalGenerator @JvmOverloads constructor(val exportVAlarms: Boolean = true, val editable: Boolean = false) {
+ var empty: Boolean = true
+ private set
+
+ // Crée un objet calendrier
+ private val calendar = Calendar()
+ .withProdId("-//${ProjectForgeVersion.APP_ID} ${ProjectForgeVersion.VERSION_NUMBER}//Générateur iCal//FR")
+ .withDefaults() // add(GREGORIAN).add(VERSION_2_0)
+
+ /**