@Service @Property(name="extensions",value="json") @Property(name="contentTypes",value="application/json") public class JsonReader extends Object implements ContentReader
JsonReader Parses a Json document on content load and creates the
corresponding node structure with properties. Will not update protected nodes and
properties like rep:Policy and children.
Nodes, Properties and in fact complete subtrees may be described in JSON files
using the following skeleton structure (see http://www.json.org for information
on the syntax of JSON) :
# the name of the node is taken from the name of the file without the .json ext.
{
# optional primary node type, default "nt:unstructured"
"jcr:primaryType":"sling:ScriptedComponent",
# optional mixin node types as array
"jcr:mixinTypes": [ ],
# "properties" are added as key value pairs, the name of the key being the name
# of the property. The value is either the string property value, array for
# multi-values or an object whose value[s] property denotes the property
# value(s) and whose type property denotes the property type
"sling:contentClass": "com.day.sling.jcr.test.Test",
"sampleMulti": [ "v1", "v2" ],
"sampleStruct": 1,
"sampleStructMulti": [ 1, 2, 3 ],
# reference properties start with jcr:reference
"jcr:reference:sampleReference": "/test/content",
# path propertie start with jcr:path
"jcr:path:sampleReference": "/test/path",
# nested nodes are added as nested maps.
"sling:scripts": {
"jcr:primaryType": "sling:ScriptList",
"script1" :{
"primaryNodeType": "sling:Script",
"sling:name": "/test/content/jsp/start.jsp",
"sling:type": "jsp",
"sling:glob": "*"
}
}
}
| Modifier and Type | Field and Description |
|---|---|
protected static Set<String> |
ignoredNames |
PROPERTY_EXTENSIONS, PROPERTY_TYPES| Constructor and Description |
|---|
JsonReader() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
createNode(String name,
javax.json.JsonObject obj,
ContentCreator contentCreator) |
protected void |
createPrincipals(Object obj,
ContentCreator contentCreator)
Create or update one or more user and/or groups
{
"security:principals" : [
{
"name":"owner",
"isgroup":"true",
"members":[],
"dynamic":"true"
}
],
}
|
protected void |
createProperty(String name,
Object value,
ContentCreator contentCreator) |
protected boolean |
handleSecurity(String n,
Object o,
ContentCreator contentCreator) |
void |
parse(InputStream ins,
ContentCreator contentCreator)
Read the content from the input stream and create the
content using the provided content creator.
|
void |
parse(URL url,
ContentCreator contentCreator)
Read the content from the URL and create the
content using the provided content creator.
|
protected void |
writeChildren(javax.json.JsonObject obj,
ContentCreator contentCreator) |
public void parse(URL url, ContentCreator contentCreator) throws IOException, javax.jcr.RepositoryException
ContentReaderparse in interface ContentReaderurl - The input stream.IOExceptionjavax.jcr.RepositoryExceptionContentReader.parse(java.net.URL, org.apache.sling.jcr.contentloader.ContentCreator)public void parse(InputStream ins, ContentCreator contentCreator) throws IOException, javax.jcr.RepositoryException
ContentReaderparse in interface ContentReaderins - the input stream.IOExceptionjavax.jcr.RepositoryExceptionprotected boolean handleSecurity(String n, Object o, ContentCreator contentCreator) throws javax.jcr.RepositoryException
javax.jcr.RepositoryExceptionprotected void writeChildren(javax.json.JsonObject obj,
ContentCreator contentCreator)
throws javax.jcr.RepositoryException
javax.jcr.RepositoryExceptionprotected void createNode(String name, javax.json.JsonObject obj, ContentCreator contentCreator) throws javax.jcr.RepositoryException
javax.jcr.RepositoryExceptionprotected void createProperty(String name, Object value, ContentCreator contentCreator) throws javax.jcr.RepositoryException
javax.jcr.RepositoryExceptionprotected void createPrincipals(Object obj, ContentCreator contentCreator) throws javax.jcr.RepositoryException
{
"security:principals" : [
{
"name":"owner",
"isgroup":"true",
"members":[],
"dynamic":"true"
}
],
}
obj - ObjectcontentCreator - Content creatorjavax.jcr.RepositoryException - Repository exceptionCopyright © 2007–2017 The Apache Software Foundation. All rights reserved.