From 3538e9e9737a9c97be8930112451a4c84035662c Mon Sep 17 00:00:00 2001 From: usbharu Date: Wed, 2 Oct 2024 12:21:42 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Kotlin=E3=81=AE=E3=82=AA=E3=83=96?= =?UTF-8?q?=E3=82=B8=E3=82=A7=E3=82=AF=E3=83=88=E3=81=AB=E8=A9=B0=E3=82=81?= =?UTF-8?q?=E8=BE=BC=E3=82=80=E9=83=A8=E5=88=86=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/deployment.xml | 14 +++++ .idea/gradle.xml | 3 +- .idea/misc.xml | 2 +- .../impl/builder/JsonLdBuilder.kt | 14 +++++ .../impl/builder/ObjectBuilder.kt | 13 ++++ .../impl/model/object/NoteImpl.kt | 60 ++++++++++--------- .../impl/type/BuilderContext.kt | 7 +++ .../impl/type/JsonObjectBuilder.kt | 6 ++ .../activitystreams/impl/type/TypeFactory.kt | 6 +- 9 files changed, 93 insertions(+), 32 deletions(-) create mode 100644 .idea/deployment.xml create mode 100644 src/main/kotlin/dev/usbharu/activitystreams/impl/builder/JsonLdBuilder.kt create mode 100644 src/main/kotlin/dev/usbharu/activitystreams/impl/builder/ObjectBuilder.kt create mode 100644 src/main/kotlin/dev/usbharu/activitystreams/impl/type/BuilderContext.kt create mode 100644 src/main/kotlin/dev/usbharu/activitystreams/impl/type/JsonObjectBuilder.kt diff --git a/.idea/deployment.xml b/.idea/deployment.xml new file mode 100644 index 0000000..5307b74 --- /dev/null +++ b/.idea/deployment.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 2a65317..885e852 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,8 +4,8 @@ + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index ee3319a..b9d0bed 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/src/main/kotlin/dev/usbharu/activitystreams/impl/builder/JsonLdBuilder.kt b/src/main/kotlin/dev/usbharu/activitystreams/impl/builder/JsonLdBuilder.kt new file mode 100644 index 0000000..23c0103 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/activitystreams/impl/builder/JsonLdBuilder.kt @@ -0,0 +1,14 @@ +package dev.usbharu.activitystreams.impl.builder + +import dev.usbharu.activitystreams.impl.type.BuilderContext +import dev.usbharu.activitystreams.impl.type.JsonObjectBuilder +import dev.usbharu.activitystreams.model.JsonLd +import java.net.URI + +open class JsonLdBuilder : JsonObjectBuilder { + override fun build(t: JsonLd, jsonObject: Map, builderContext: BuilderContext) { + t.value = jsonObject["@value"] + t.id = jsonObject["@id"]?.toString()?.let { URI.create(it) } + t.type = (jsonObject["@type"] as? List).orEmpty().map { URI.create(it) } + } +} \ No newline at end of file diff --git a/src/main/kotlin/dev/usbharu/activitystreams/impl/builder/ObjectBuilder.kt b/src/main/kotlin/dev/usbharu/activitystreams/impl/builder/ObjectBuilder.kt new file mode 100644 index 0000000..c8068d3 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/activitystreams/impl/builder/ObjectBuilder.kt @@ -0,0 +1,13 @@ +package dev.usbharu.activitystreams.impl.builder + +import dev.usbharu.activitystreams.impl.type.BuilderContext +import dev.usbharu.activitystreams.impl.type.JsonObjectBuilder +import dev.usbharu.activitystreams.model.JsonLd +import dev.usbharu.activitystreams.model.core.Object + +class ObjectBuilder : JsonObjectBuilder { + override fun build(t: Object, jsonObject: Map, builderContext: BuilderContext) { +// t.name = + } + +} \ No newline at end of file diff --git a/src/main/kotlin/dev/usbharu/activitystreams/impl/model/object/NoteImpl.kt b/src/main/kotlin/dev/usbharu/activitystreams/impl/model/object/NoteImpl.kt index 9062c36..648bb27 100644 --- a/src/main/kotlin/dev/usbharu/activitystreams/impl/model/object/NoteImpl.kt +++ b/src/main/kotlin/dev/usbharu/activitystreams/impl/model/object/NoteImpl.kt @@ -1,6 +1,7 @@ package dev.usbharu.activitystreams.impl.model.`object` import dev.usbharu.activitystreams.model.ImageOrLink +import dev.usbharu.activitystreams.model.JsonLdWrapper import dev.usbharu.activitystreams.model.ObjectOrLink import dev.usbharu.activitystreams.model.UriOrLink import dev.usbharu.activitystreams.model.core.Collection @@ -12,34 +13,35 @@ import java.time.Duration import java.time.OffsetDateTime class NoteImpl( - override var type: List, - override var attachment: List, - override var attributedTo: List, - override var audience: List, - override var content: LangString?, - override var context: List, - override var name: LangString?, - override var endTime: OffsetDateTime?, - override var generator: List, - override var icon: List, - override var image: List, - override var inReplyTo: List, - override var location: ObjectOrLink?, - override var preview: ObjectOrLink?, - override var published: OffsetDateTime?, - override var replies: Collection?, - override var startTime: OffsetDateTime?, - override var summary: LangString?, - override var tag: List, - override var updated: OffsetDateTime?, - override var url: List, - override var to: List, - override var bto: List, - override var cc: List, - override var bcc: List, - override var mediaType: MimeMediaType?, - override var duration: Duration?, - override var id: URI?, - override var source: ObjectOrLink? + override var type: List = emptyList(), + override var attachment: List = emptyList(), + override var attributedTo: List = emptyList(), + override var audience: List = emptyList(), + override var content: LangString? = null, + override var context: List = emptyList(), + override var name: LangString? = null, + override var endTime: JsonLdWrapper? = null, + override var generator: List = emptyList(), + override var icon: List = emptyList(), + override var image: List = emptyList(), + override var inReplyTo: List = emptyList(), + override var location: ObjectOrLink? = null, + override var preview: ObjectOrLink? = null, + override var published: JsonLdWrapper? = null, + override var replies: Collection? = null, + override var startTime: JsonLdWrapper? = null, + override var summary: LangString? = null, + override var tag: List = emptyList(), + override var updated: JsonLdWrapper? = null, + override var url: List = emptyList(), + override var to: List = emptyList(), + override var bto: List = emptyList(), + override var cc: List = emptyList(), + override var bcc: List = emptyList(), + override var mediaType: MimeMediaType? = null, + override var duration: JsonLdWrapper? = null, + override var id: URI? = null, + override var source: ObjectOrLink? = null, + override var value: Any? = null, ) : Note { } \ No newline at end of file diff --git a/src/main/kotlin/dev/usbharu/activitystreams/impl/type/BuilderContext.kt b/src/main/kotlin/dev/usbharu/activitystreams/impl/type/BuilderContext.kt new file mode 100644 index 0000000..aacc330 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/activitystreams/impl/type/BuilderContext.kt @@ -0,0 +1,7 @@ +package dev.usbharu.activitystreams.impl.type + +class BuilderContext { + fun getBuilder():JsonObjectBuilder{ + TODO() + } +} \ No newline at end of file diff --git a/src/main/kotlin/dev/usbharu/activitystreams/impl/type/JsonObjectBuilder.kt b/src/main/kotlin/dev/usbharu/activitystreams/impl/type/JsonObjectBuilder.kt new file mode 100644 index 0000000..83c64ca --- /dev/null +++ b/src/main/kotlin/dev/usbharu/activitystreams/impl/type/JsonObjectBuilder.kt @@ -0,0 +1,6 @@ +package dev.usbharu.activitystreams.impl.type + +interface JsonObjectBuilder { + fun build(t: T, jsonObject: Map, builderContext: BuilderContext) +} +// todo Abstract classでスーパークラスのjsonobjectbuilderを自動で呼び出す部分を作る \ No newline at end of file diff --git a/src/main/kotlin/dev/usbharu/activitystreams/impl/type/TypeFactory.kt b/src/main/kotlin/dev/usbharu/activitystreams/impl/type/TypeFactory.kt index 0dd2cf8..8df185a 100644 --- a/src/main/kotlin/dev/usbharu/activitystreams/impl/type/TypeFactory.kt +++ b/src/main/kotlin/dev/usbharu/activitystreams/impl/type/TypeFactory.kt @@ -1,13 +1,17 @@ package dev.usbharu.activitystreams.impl.type import dev.usbharu.activitystreams.impl.model.activity.CreateImpl +import dev.usbharu.activitystreams.impl.model.actor.PersonImpl +import dev.usbharu.activitystreams.impl.model.`object`.NoteImpl import dev.usbharu.activitystreams.model.JsonLd import java.net.URI class TypeFactory { val map = mutableMapOf JsonLd>( - URI.create("https://www.w3.org/ns/activitystreams#Create") to { CreateImpl() } + URI.create("https://www.w3.org/ns/activitystreams#Create") to { CreateImpl() }, + URI.create("https://www.w3.org/ns/activitystreams#Person") to { PersonImpl() }, + URI.create("https://www.w3.org/ns/activitystreams#Note") to { NoteImpl() }, ) fun factory(uri: URI): JsonLd? {