org.apache.sling.jcr.contentloader.internal
Class DefaultContentCreator

java.lang.Object
  extended by org.apache.sling.jcr.contentloader.internal.DefaultContentCreator
All Implemented Interfaces:
ContentCreator

public class DefaultContentCreator
extends Object
implements ContentCreator

The ContentLoader creates the nodes and properties.

Since:
2.0.4

Constructor Summary
DefaultContentCreator(JcrContentHelper jcrContentHelper)
          Constructor.
 
Method Summary
 void clear()
          Clear the content loader.
 void createAce(String principalId, String[] grantedPrivilegeNames, String[] deniedPrivilegeNames, String order)
          Creates an Access Control Entry for the current node for the specified principal and privileges.
 void createFileAndResourceNode(String name, InputStream data, String mimeType, long lastModified)
          Create a file and a resource node.
 void createGroup(String name, String[] members, Map<String,Object> extraProperties)
          Create a Group in the jackrabbit UserManager
 void createNode(String name, String primaryNodeType, String[] mixinNodeTypes)
          Create a new node.
 void createProperty(String name, int propertyType, String value)
          Create a new property to the current node.
 void createProperty(String name, int propertyType, String[] values)
          Create a new multi value property to the current node.
 void createProperty(String name, Object value)
          Add a new property to the current node.
 void createProperty(String name, Object[] values)
          Add a new multi value property to the current node.
 void createUser(String name, String password, Map<String,Object> extraProperties)
          Create a User in the jackrabbit UserManager
protected  javax.jcr.Value createValue(javax.jcr.ValueFactory factory, Object value)
           
static String digest(String algorithm, byte[] data)
          Digest the plain string using the given algorithm.
 void finishNode()
          Indicates that a node is finished.
 javax.jcr.Node getCreatedRootNode()
          Get the created root node.
 ImportProvider getImportProvider(String name)
          Return the import provider for the name
 String getImportProviderExtension(String name)
          Get the extension of the file name.
 Map<String,ImportProvider> getImportProviders()
          Get all active import providers.
 List<javax.jcr.Node> getVersionables()
          Get the list of versionable nodes.
protected  String hashPath(String item)
           
 void init(ImportOptions pathEntry, Map<String,ImportProvider> defaultImportProviders, List<String> createdNodes, ContentImportListener importListener)
          Initialize this component.
 void prepareParsing(javax.jcr.Node parentNode, String defaultName)
          If the defaultName is null, we are in PARENT_NODE import mode.
 void setIgnoreOverwriteFlag(boolean flag)
          Set the ignore overwrite flag.
 boolean switchCurrentNode(String subPath, String newNodeType)
          Switch the current node to the path (which must be relative to the current node).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultContentCreator

public DefaultContentCreator(JcrContentHelper jcrContentHelper)
Constructor.

Parameters:
jcrContentHelper - Helper class to get the mime type of a file
Method Detail

init

public void init(ImportOptions pathEntry,
                 Map<String,ImportProvider> defaultImportProviders,
                 List<String> createdNodes,
                 ContentImportListener importListener)
Initialize this component.

Parameters:
pathEntry - The configuration for this import.
defaultImportProviders - List of all import providers.
createdNodes - Optional list to store new nodes (for uninstall)

prepareParsing

public void prepareParsing(javax.jcr.Node parentNode,
                           String defaultName)
If the defaultName is null, we are in PARENT_NODE import mode.

Parameters:
parentNode -
defaultName -

getVersionables

public List<javax.jcr.Node> getVersionables()
Get the list of versionable nodes.


clear

public void clear()
Clear the content loader.


setIgnoreOverwriteFlag

public void setIgnoreOverwriteFlag(boolean flag)
Set the ignore overwrite flag.

Parameters:
flag -

getCreatedRootNode

public javax.jcr.Node getCreatedRootNode()
Get the created root node.


getImportProviders

public Map<String,ImportProvider> getImportProviders()
Get all active import providers.

Returns:
A map of providers

getImportProvider

public ImportProvider getImportProvider(String name)
Return the import provider for the name

Parameters:
name - The file name.
Returns:
The provider or null

getImportProviderExtension

public String getImportProviderExtension(String name)
Get the extension of the file name.

Parameters:
name - The file name.
Returns:
The extension a provider is registered for - or null

createNode

public void createNode(String name,
                       String primaryNodeType,
                       String[] mixinNodeTypes)
                throws javax.jcr.RepositoryException
Description copied from interface: ContentCreator
Create a new node. To add properties to this node, one of the createProperty() methods should be called. To add child nodes, this method should be called to create a new child node. If all properties and child nodes have been added ContentCreator.finishNode() must be called.

Specified by:
createNode in interface ContentCreator
Parameters:
name - The name of the node.
primaryNodeType - The primary node type or null.
mixinNodeTypes - The mixin node types or null.
Throws:
javax.jcr.RepositoryException - If anything goes wrong.
See Also:
ContentCreator.createNode(java.lang.String, java.lang.String, java.lang.String[])

createProperty

public void createProperty(String name,
                           int propertyType,
                           String value)
                    throws javax.jcr.RepositoryException
Description copied from interface: ContentCreator
Create a new property to the current node.

Specified by:
createProperty in interface ContentCreator
Parameters:
name - The property name.
propertyType - The type of the property.
value - The string value.
Throws:
javax.jcr.RepositoryException
See Also:
ContentCreator.createProperty(java.lang.String, int, java.lang.String)

createProperty

public void createProperty(String name,
                           int propertyType,
                           String[] values)
                    throws javax.jcr.RepositoryException
Description copied from interface: ContentCreator
Create a new multi value property to the current node.

Specified by:
createProperty in interface ContentCreator
Parameters:
name - The property name.
propertyType - The type of the property.
values - The string values.
Throws:
javax.jcr.RepositoryException
See Also:
ContentCreator.createProperty(java.lang.String, int, java.lang.String[])

createValue

protected javax.jcr.Value createValue(javax.jcr.ValueFactory factory,
                                      Object value)

createProperty

public void createProperty(String name,
                           Object value)
                    throws javax.jcr.RepositoryException
Description copied from interface: ContentCreator
Add a new property to the current node.

Specified by:
createProperty in interface ContentCreator
Parameters:
name - The property name.
value - The value.
Throws:
javax.jcr.RepositoryException
See Also:
ContentCreator.createProperty(java.lang.String, java.lang.Object)

createProperty

public void createProperty(String name,
                           Object[] values)
                    throws javax.jcr.RepositoryException
Description copied from interface: ContentCreator
Add a new multi value property to the current node.

Specified by:
createProperty in interface ContentCreator
Parameters:
name - The property name.
values - The values.
Throws:
javax.jcr.RepositoryException
See Also:
ContentCreator.createProperty(java.lang.String, java.lang.Object[])

finishNode

public void finishNode()
                throws javax.jcr.RepositoryException
Description copied from interface: ContentCreator
Indicates that a node is finished. The parent node of the current node becomes the current node.

Specified by:
finishNode in interface ContentCreator
Throws:
javax.jcr.RepositoryException
See Also:
ContentCreator.finishNode()

createFileAndResourceNode

public void createFileAndResourceNode(String name,
                                      InputStream data,
                                      String mimeType,
                                      long lastModified)
                               throws javax.jcr.RepositoryException
Description copied from interface: ContentCreator
Create a file and a resource node. After the nodes have been created, the current node is the resource node. So this method call should be followed by two calls to ContentCreator.finishNode() to be on the same level as before the file creation.

Specified by:
createFileAndResourceNode in interface ContentCreator
Parameters:
name - The name of the file node
data - The data of the file
mimeType - The mime type or null
lastModified - The last modified or -1
Throws:
javax.jcr.RepositoryException
See Also:
ContentCreator.createFileAndResourceNode(java.lang.String, java.io.InputStream, java.lang.String, long)

switchCurrentNode

public boolean switchCurrentNode(String subPath,
                                 String newNodeType)
                          throws javax.jcr.RepositoryException
Description copied from interface: ContentCreator
Switch the current node to the path (which must be relative to the current node). If the path does not exist and a node type is supplied, the nodes are created with the given node type. If the path does not exist and node type is null, false is returned. When the changes to the node are finished, ContentCreator.finishNode() must be callsed.

Specified by:
switchCurrentNode in interface ContentCreator
Parameters:
subPath - The relative path
newNodeType - Node typ for newly created nodes.
Throws:
javax.jcr.RepositoryException
See Also:
ContentCreator.switchCurrentNode(java.lang.String, java.lang.String)

createGroup

public void createGroup(String name,
                        String[] members,
                        Map<String,Object> extraProperties)
                 throws javax.jcr.RepositoryException
Description copied from interface: ContentCreator
Create a Group in the jackrabbit UserManager

Specified by:
createGroup in interface ContentCreator
Parameters:
name - the name of the group
members - the members of the group (principal names)
extraProperties - extra properties to assign to the created group
Throws:
javax.jcr.RepositoryException

createUser

public void createUser(String name,
                       String password,
                       Map<String,Object> extraProperties)
                throws javax.jcr.RepositoryException
Description copied from interface: ContentCreator
Create a User in the jackrabbit UserManager

Specified by:
createUser in interface ContentCreator
Parameters:
name - the name of the user
password - the password of the user
extraProperties - extra properties to assign to the created user
Throws:
javax.jcr.RepositoryException

hashPath

protected String hashPath(String item)
                   throws javax.jcr.RepositoryException
Parameters:
item -
Returns:
a parent path fragment for the item.
Throws:
javax.jcr.RepositoryException

createAce

public void createAce(String principalId,
                      String[] grantedPrivilegeNames,
                      String[] deniedPrivilegeNames,
                      String order)
               throws javax.jcr.RepositoryException
Description copied from interface: ContentCreator
Creates an Access Control Entry for the current node for the specified principal and privileges.

Specified by:
createAce in interface ContentCreator
Parameters:
principalId - the user or group id for the ACE
grantedPrivilegeNames - the set of privileges to grant the principal
deniedPrivilegeNames - the set of privileges to deny the principal (for users only)
order - specifies the position of the ACE in the containing ACL. (may be null) Value should be one of these:
firstPlace the target ACE as the first amongst its siblings
lastPlace the target ACE as the last amongst its siblings
before xyzPlace the target ACE immediately before the sibling whose name is xyz
after xyzPlace the target ACE immediately after the sibling whose name is xyz
numericPlace the target ACE at the specified index
Throws:
javax.jcr.RepositoryException

digest

public static String digest(String algorithm,
                            byte[] data)
                     throws NoSuchAlgorithmException
Digest the plain string using the given algorithm.

Parameters:
algorithm - The alogrithm for the digest. This algorithm must be supported by the MessageDigest class.
data - the data to digest with the given algorithm
Returns:
The digested plain text String represented as Hex digits.
Throws:
NoSuchAlgorithmException - if the desired algorithm is not supported by the MessageDigest class.


Copyright © 2007-2013 The Apache Software Foundation. All Rights Reserved.