]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.lib.json/src/org/argeo/cms/acr/json/AcrJsonUtils.java
1 package org
.argeo
.cms
.acr
.json
;
3 import javax
.xml
.namespace
.QName
;
5 import org
.argeo
.api
.acr
.Content
;
6 import org
.argeo
.api
.acr
.DName
;
7 import org
.argeo
.api
.acr
.NamespaceUtils
;
8 import org
.argeo
.api
.acr
.QNamed
;
10 import jakarta
.json
.stream
.JsonGenerator
;
12 /** Utilities around ACR and the JSON format. */
13 public class AcrJsonUtils
{
14 public static void writeAttr(JsonGenerator g
, Content content
, String attr
) {
15 writeAttr(g
, content
, NamespaceUtils
.parsePrefixedName(attr
));
18 public static void writeAttr(JsonGenerator g
, Content content
, QNamed attr
) {
19 writeAttr(g
, content
, attr
.qName());
22 public static void writeAttr(JsonGenerator g
, Content content
, QName attr
) {
23 // String value = content.attr(attr);
24 Object value
= content
.get(attr
);
26 // TODO specify NamespaceContext
27 String key
= NamespaceUtils
.toPrefixedName(attr
);
28 if (value
instanceof Double v
)
30 else if (value
instanceof Long v
)
32 else if (value
instanceof Integer v
)
34 else if (value
instanceof Boolean v
)
37 g
.write(key
, value
.toString());
42 private AcrJsonUtils() {
45 // private final QName JCR_CREATED = NamespaceUtils.parsePrefixedName("jcr:created");
47 // private final QName JCR_LAST_MODIFIED = NamespaceUtils.parsePrefixedName("jcr:lastModified");
49 public static void writeTimeProperties(JsonGenerator g
, Content content
) {
50 String creationDate
= content
.attr(DName
.creationdate
);
51 // if (creationDate == null)
52 // creationDate = content.attr(JCR_CREATED);
53 if (creationDate
!= null)
54 g
.write(DName
.creationdate
.get(), creationDate
);
55 String lastModified
= content
.attr(DName
.getlastmodified
);
56 // if (lastModified == null)
57 // lastModified = content.attr(JCR_LAST_MODIFIED);
58 if (lastModified
!= null)
59 g
.write(DName
.getlastmodified
.get(), lastModified
);