Class JsonReader

  • All Implemented Interfaces:
    ContentReader
    Direct Known Subclasses:
    OrderedJsonReader

    public class JsonReader
    extends Object
    implements ContentReader
    The 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": "*"
             }
         }
       }
    
     
    • Field Detail

      • ignoredNames

        protected static final Set<String> ignoredNames
    • Constructor Detail

      • JsonReader

        public JsonReader()
    • Method Detail

      • parse

        public void parse​(InputStream ins,
                          ContentCreator contentCreator)
                   throws IOException,
                          javax.jcr.RepositoryException
        Description copied from interface: ContentReader
        Read the content from the input stream and create the content using the provided content creator.
        Specified by:
        parse in interface ContentReader
        Parameters:
        ins - the input stream.
        Throws:
        IOException - If anything goes wrong.
        javax.jcr.RepositoryException
      • handleSecurity

        protected boolean handleSecurity​(String n,
                                         Object o,
                                         ContentCreator contentCreator)
                                  throws javax.jcr.RepositoryException
        Throws:
        javax.jcr.RepositoryException
      • writeChildren

        protected void writeChildren​(jakarta.json.JsonObject obj,
                                     ContentCreator contentCreator)
                              throws javax.jcr.RepositoryException
        Throws:
        javax.jcr.RepositoryException
      • createNode

        protected void createNode​(String name,
                                  jakarta.json.JsonObject obj,
                                  ContentCreator contentCreator)
                           throws javax.jcr.RepositoryException
        Throws:
        javax.jcr.RepositoryException
      • createProperty

        protected void createProperty​(String name,
                                      Object value,
                                      ContentCreator contentCreator)
                               throws javax.jcr.RepositoryException
        Throws:
        javax.jcr.RepositoryException
      • createPrincipals

        protected void createPrincipals​(Object obj,
                                        ContentCreator contentCreator)
                                 throws javax.jcr.RepositoryException
        Create or update one or more user and/or groups { "security:principals" : [ { "name":"owner", "isgroup":"true", "members":[], "dynamic":"true" } ], }
        Parameters:
        obj - Object
        contentCreator - Content creator
        Throws:
        javax.jcr.RepositoryException - Repository exception
      • toSrMap

        protected Map<String,​org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinition> toSrMap​(javax.jcr.Node parentNode)
                                                                                                                            throws javax.jcr.RepositoryException
        Calculate a map of restriction names to the restriction definition
        Parameters:
        parentNode - the node the restrictions are for
        Throws:
        javax.jcr.RepositoryException
      • toLocalRestrictions

        protected Set<LocalRestriction> toLocalRestrictions​(jakarta.json.JsonObject allowOrDenyObj,
                                                            Map<String,​org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinition> srMap,
                                                            javax.jcr.ValueFactory vf)
                                                     throws javax.jcr.RepositoryException
        Construct a LocalRestriction using data from the json object
        Parameters:
        allowOrDenyObj - the json object
        srMap - map of restriction names to the restriction definition
        vf - the ValueFactory
        Throws:
        javax.jcr.RepositoryException