Skip to content

Commit e48828a

Browse files
committed
Add many more test feeds and manifests.
1 parent f1b412a commit e48828a

40 files changed

+12297
-83
lines changed

org.thepalaceproject.webpub.core/src/main/kotlin/org/thepalaceproject/webpub/core/WPMBelongsTo.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ data class WPMBelongsTo(
1212
@JsonProperty(
1313
value = "collection"
1414
)
15-
val collection : WPMContributor?,
15+
val collection : WPMContributorOrString?,
1616

1717
@JsonProperty(
1818
value = "series"
1919
)
20-
val series : WPMContributor?,
20+
val series : WPMContributorOrString?,
2121
)

org.thepalaceproject.webpub.core/src/main/kotlin/org/thepalaceproject/webpub/core/WPMContributor.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import java.net.URI
1111
@JsonIgnoreProperties(ignoreUnknown = true)
1212
data class WPMContributor(
1313
@JsonProperty(
14-
value = "name",
15-
required = true
14+
value = "name"
1615
)
17-
val name : String,
16+
val name : String?,
1817

1918
@JsonProperty(
2019
value = "identifier"
@@ -45,4 +44,4 @@ data class WPMContributor(
4544
value = "links"
4645
)
4746
val links: List<WPMLink> = listOf()
48-
) : WPMElement()
47+
) : WPMContributorOrString()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.thepalaceproject.webpub.core
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
4+
import com.fasterxml.jackson.annotation.JsonProperty
5+
import java.net.URI
6+
7+
/**
8+
* @see "https://github.com/readium/webpub-manifest/blob/master/schema/contributor-object.schema.json"
9+
*/
10+
11+
@JsonIgnoreProperties(ignoreUnknown = true)
12+
sealed class WPMContributorOrString() : WPMElement() {
13+
data class WPMContributorString(
14+
val value: String
15+
): WPMContributorOrString()
16+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.thepalaceproject.webpub.core
2+
3+
import com.fasterxml.jackson.core.JsonParser
4+
import com.fasterxml.jackson.core.JsonToken
5+
import com.fasterxml.jackson.databind.DeserializationContext
6+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
7+
import java.time.OffsetDateTime
8+
9+
class WPMContributorOrStringDeserializer :
10+
StdDeserializer<WPMContributorOrString>(WPMContributorOrString::class.java) {
11+
12+
override fun deserialize(
13+
parser : JsonParser,
14+
context : DeserializationContext
15+
) : WPMContributorOrString {
16+
return when (val currentToken = parser.currentToken()) {
17+
JsonToken.VALUE_STRING -> {
18+
WPMContributorOrString.WPMContributorString(parser.text)
19+
}
20+
21+
JsonToken.START_OBJECT -> {
22+
context.readValue(parser, WPMContributor::class.java)
23+
}
24+
25+
else -> {
26+
context.handleUnexpectedToken(
27+
OffsetDateTime::class.java,
28+
currentToken,
29+
parser,
30+
"Expected an object or a string (Received ${currentToken})."
31+
)
32+
TODO("Unreachable code.")
33+
}
34+
}
35+
}
36+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.thepalaceproject.webpub.core
2+
3+
import com.fasterxml.jackson.core.JsonGenerator
4+
import com.fasterxml.jackson.core.JsonParser
5+
import com.fasterxml.jackson.core.JsonToken
6+
import com.fasterxml.jackson.databind.DeserializationContext
7+
import com.fasterxml.jackson.databind.SerializerProvider
8+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
9+
import com.fasterxml.jackson.databind.ser.std.StdSerializer
10+
import java.time.OffsetDateTime
11+
12+
class WPMContributorOrStringSerializer :
13+
StdSerializer<WPMContributorOrString>(WPMContributorOrString::class.java) {
14+
override fun serialize(
15+
value : WPMContributorOrString,
16+
gen : JsonGenerator,
17+
provider : SerializerProvider
18+
) {
19+
when (value) {
20+
is WPMContributor -> {
21+
gen.writeStartObject()
22+
23+
value.name?.let { text ->
24+
gen.writeFieldName("name")
25+
gen.writeString(text)
26+
}
27+
value.identifier?.let { text ->
28+
gen.writeFieldName("identifier")
29+
gen.writeString(text.toString())
30+
}
31+
value.altIdentifier?.let { text ->
32+
gen.writeFieldName("altIdentifier")
33+
gen.writeString(text.toString())
34+
}
35+
value.sortAs?.let { text ->
36+
gen.writeFieldName("sortAs")
37+
gen.writeString(text)
38+
}
39+
value.position?.let { text ->
40+
gen.writeFieldName("position")
41+
gen.writeNumber(text.toDouble())
42+
}
43+
if (value.links.isNotEmpty()) {
44+
gen.writeFieldName("links")
45+
value.links.forEach { link -> gen.writeObject(link) }
46+
}
47+
if (!value.role.isEmpty()) {
48+
gen.writeFieldName("role")
49+
gen.writeArray(value.role.toTypedArray(), 0, value.role.size)
50+
}
51+
52+
gen.writeEndObject()
53+
}
54+
is WPMContributorOrString.WPMContributorString ->
55+
gen.writeString(value.value)
56+
}
57+
}
58+
}

org.thepalaceproject.webpub.core/src/main/kotlin/org/thepalaceproject/webpub/core/WPMLinkSerializer.kt

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonGenerator
44
import com.fasterxml.jackson.databind.SerializerProvider
55
import com.fasterxml.jackson.databind.ser.std.StdSerializer
66
import one.irradia.mime.api.MIMEType
7+
import java.math.BigInteger
78

89
class WPMLinkSerializer : StdSerializer<WPMLink>(WPMLink::class.java) {
910
override fun serialize(
@@ -18,27 +19,7 @@ class WPMLinkSerializer : StdSerializer<WPMLink>(WPMLink::class.java) {
1819
generator.writeFieldName("href")
1920
generator.writeString(value.href.toString())
2021

21-
value.title?.let { text ->
22-
generator.writeFieldName("title")
23-
generator.writeString(text)
24-
}
25-
value.type?.let { type ->
26-
this.writeType(type, generator)
27-
}
28-
29-
if (value.relation.size == 1) {
30-
generator.writeFieldName("rel")
31-
generator.writeString(value.relation[0])
32-
} else if (value.relation.size > 1) {
33-
generator.writeFieldName("rel")
34-
generator.writeArray(value.relation.toTypedArray(), 0, value.relation.size)
35-
}
36-
37-
value.properties?.let { properties ->
38-
generator.writeFieldName("properties")
39-
generator.writeObject(properties)
40-
}
41-
22+
this.writeProperties(value, generator)
4223
generator.writeEndObject()
4324
}
4425
is WPMLinkTemplated -> {
@@ -50,30 +31,57 @@ class WPMLinkSerializer : StdSerializer<WPMLink>(WPMLink::class.java) {
5031
generator.writeFieldName("templated")
5132
generator.writeBoolean(true)
5233

53-
value.title?.let { text ->
54-
generator.writeFieldName("title")
55-
generator.writeString(text)
56-
}
57-
value.type?.let { type ->
58-
this.writeType(type, generator)
59-
}
60-
61-
if (value.relation.size == 1) {
62-
generator.writeFieldName("rel")
63-
generator.writeString(value.relation[0])
64-
} else if (value.relation.size > 1) {
65-
generator.writeFieldName("rel")
66-
generator.writeArray(value.relation.toTypedArray(), 0, value.relation.size)
67-
}
34+
this.writeProperties(value, generator)
35+
generator.writeEndObject()
36+
}
37+
}
38+
}
6839

69-
value.properties?.let { properties ->
70-
generator.writeFieldName("properties")
71-
generator.writeObject(properties)
72-
}
40+
private fun writeProperties(
41+
value : WPMLink,
42+
generator : JsonGenerator
43+
) {
44+
value.title?.let { text ->
45+
generator.writeFieldName("title")
46+
generator.writeString(text)
47+
}
48+
value.type?.let { type ->
49+
this.writeType(type, generator)
50+
}
7351

74-
generator.writeEndObject()
52+
value.width?.let { n ->
53+
generator.writeFieldName("width")
54+
generator.writeNumber(n)
55+
}
56+
value.height?.let { n ->
57+
generator.writeFieldName("height")
58+
generator.writeNumber(n)
59+
}
60+
value.bitrate?.let { n ->
61+
generator.writeFieldName("bitrate")
62+
if (n is Int || n is Long || n is BigInteger) {
63+
generator.writeNumber(n.toLong())
64+
} else {
65+
generator.writeNumber(n.toDouble())
7566
}
7667
}
68+
69+
if (value.relation.size == 1) {
70+
generator.writeFieldName("rel")
71+
generator.writeString(value.relation[0])
72+
} else if (value.relation.size > 1) {
73+
generator.writeFieldName("rel")
74+
generator.writeArray(
75+
value.relation.toTypedArray(),
76+
0,
77+
value.relation.size
78+
)
79+
}
80+
81+
value.properties?.let { properties ->
82+
generator.writeFieldName("properties")
83+
generator.writeObject(properties)
84+
}
7785
}
7886

7987
private fun writeType(

org.thepalaceproject.webpub.core/src/main/kotlin/org/thepalaceproject/webpub/core/WPMMetadata.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ data class WPMMetadata @JsonCreator constructor(
110110
@JsonProperty(
111111
value = "author"
112112
)
113-
val author : WPMContributor? = null,
113+
val author : List<WPMContributorOrString> = listOf(),
114114

115115
/**
116116
* The translator of the publication.
@@ -119,7 +119,7 @@ data class WPMMetadata @JsonCreator constructor(
119119
@JsonProperty(
120120
value = "translator"
121121
)
122-
val translator : WPMContributor? = null,
122+
val translator : List<WPMContributorOrString> = listOf(),
123123

124124
/**
125125
* The editor of the publication.
@@ -128,7 +128,7 @@ data class WPMMetadata @JsonCreator constructor(
128128
@JsonProperty(
129129
value = "editor"
130130
)
131-
val editor : WPMContributor? = null,
131+
val editor : List<WPMContributorOrString> = listOf(),
132132

133133
/**
134134
* The artist of the publication.
@@ -137,7 +137,7 @@ data class WPMMetadata @JsonCreator constructor(
137137
@JsonProperty(
138138
value = "artist"
139139
)
140-
val artist : WPMContributor? = null,
140+
val artist : List<WPMContributorOrString> = listOf(),
141141

142142
/**
143143
* The illustrator of the publication.
@@ -146,7 +146,7 @@ data class WPMMetadata @JsonCreator constructor(
146146
@JsonProperty(
147147
value = "illustrator"
148148
)
149-
val illustrator : WPMContributor? = null,
149+
val illustrator : List<WPMContributorOrString> = listOf(),
150150

151151
/**
152152
* The letterer of the publication.
@@ -155,7 +155,7 @@ data class WPMMetadata @JsonCreator constructor(
155155
@JsonProperty(
156156
value = "letterer"
157157
)
158-
val letterer : WPMContributor? = null,
158+
val letterer : List<WPMContributorOrString> = listOf(),
159159

160160
/**
161161
* The penciler of the publication.
@@ -164,7 +164,7 @@ data class WPMMetadata @JsonCreator constructor(
164164
@JsonProperty(
165165
value = "penciler"
166166
)
167-
val penciler : WPMContributor? = null,
167+
val penciler : List<WPMContributorOrString> = listOf(),
168168

169169
/**
170170
* The colorist of the publication.
@@ -173,7 +173,7 @@ data class WPMMetadata @JsonCreator constructor(
173173
@JsonProperty(
174174
value = "colorist"
175175
)
176-
val colorist : WPMContributor? = null,
176+
val colorist : List<WPMContributorOrString> = listOf(),
177177

178178
/**
179179
* The inker of the publication.
@@ -182,7 +182,7 @@ data class WPMMetadata @JsonCreator constructor(
182182
@JsonProperty(
183183
value = "inker"
184184
)
185-
val inker : WPMContributor? = null,
185+
val inker : List<WPMContributorOrString> = listOf(),
186186

187187
/**
188188
* The narrator of the publication.
@@ -191,7 +191,7 @@ data class WPMMetadata @JsonCreator constructor(
191191
@JsonProperty(
192192
value = "narrator"
193193
)
194-
val narrator : WPMContributor? = null,
194+
val narrator : List<WPMContributorOrString> = listOf(),
195195

196196
/**
197197
* The contributor of the publication.
@@ -200,7 +200,7 @@ data class WPMMetadata @JsonCreator constructor(
200200
@JsonProperty(
201201
value = "contributor"
202202
)
203-
val contributor : WPMContributor? = null,
203+
val contributor : List<WPMContributorOrString> = listOf(),
204204

205205
/**
206206
* The publisher of the publication.
@@ -209,7 +209,7 @@ data class WPMMetadata @JsonCreator constructor(
209209
@JsonProperty(
210210
value = "publisher"
211211
)
212-
val publisher : WPMContributor? = null,
212+
val publisher : List<WPMContributorOrString> = listOf(),
213213

214214
/**
215215
* The imprint of the publication.
@@ -218,7 +218,7 @@ data class WPMMetadata @JsonCreator constructor(
218218
@JsonProperty(
219219
value = "imprint"
220220
)
221-
val imprint : WPMContributor? = null,
221+
val imprint : List<WPMContributorOrString> = listOf(),
222222

223223
/**
224224
* The subjects that apply to the publication.
@@ -227,7 +227,7 @@ data class WPMMetadata @JsonCreator constructor(
227227
@JsonProperty(
228228
value = "subject"
229229
)
230-
val subjects : List<WPMSubject> = listOf(),
230+
val subjects : List<WPMSubjectOrString> = listOf(),
231231

232232
/**
233233
* The layout of the publication.

0 commit comments

Comments
 (0)