I have 2 options to create the jackrabbit repository 1>Using JNDI options 2>
Using TransientRepository
1>Using JNDI options
Repository repository =
RepositoryFactory.getInstance(applicationPath,"login",
repositoryPath).getRepository();
private RepositoryFactory(String applicationPath, String type, String
repositoryPath) throws RepositoryException {
if(applicationPath==null){
applicationPath = AppContextLoader.getApplicationPath();
jackRabbitLogger.info("Application Path RepositoryFactory "+
applicationPath);
}
String configFile = applicationPath +
Declarations.JACKRABBIT_REPOSITORY_XML_FILE_PATH;
jackRabbitLogger.info("config file value -> "+ configFile);
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
env.put(Context.PROVIDER_URL, "localhost");
try {
ctx = new InitialContext(env);
/*if(type.equalsIgnoreCase("init")){*/
createRepository(configFile,repositoryPath);
} catch (NamingException e) {
// TODO Auto-generated catch block
jackRabbitLogger.error(e.getMessage(), e);
}
}
private void createRepository(String configFile,String repHomeDir){
try{
RegistryHelper.registerRepository(ctx, "repo",
configFile,repHomeDir,
true);
} catch (NamingException e) {
// TODO Auto-generated catch block
jackRabbitLogger.error(e.getMessage(), e);
}
catch (RepositoryException e) {
// TODO Auto-generated catch block
jackRabbitLogger.error(e.getMessage(), e);
}
}
public static synchronized RepositoryFactory getInstance(String
applicationPath,String type, String repositoryPath) throws
RepositoryException {
if (null == factory) {
factory = new RepositoryFactory(applicationPath,type,
repositoryPath);
}
return factory;
}
public Repository getRepository() {
Repository repo = null;
try {
repo = (Repository) ctx.lookup("repo");
} catch (NamingException e) {
jackRabbitLogger.error(e.getMessage(), e);
}
return repo;
}
session = repository.login(new
SimpleCredentials("userName","password".toCharArray()));
RepoUtilities.RegisterCustomNodeTypes(session,applicationPath
+ Declarations.JACKRABBIT_NODETYPE_FILEPATH);
public static void RegisterCustomNodeTypes(Session session,
String cndFileName) { // Read in the CND file
Workspace ws = session.getWorkspace();
FileReader fileReader;
try {
//ws.getNamespaceRegistry().registerNamespace("test1","http://mail-archives.apache.org/mod_mbox");
fileReader = new FileReader(cndFileName);
// Create a CompactNodeTypeDefReader
CompactNodeTypeDefReader cndReader;
cndReader = new CompactNodeTypeDefReader(fileReader,
cndFileName);
List ntdList = cndReader.getNodeTypeDefs(); // Get the
NodeTypeManager from the Workspace.
// Note that it
must be cast from the generic JCR NodeTypeManager to the
//
Jackrabbit-specific implementation.
NodeTypeManagerImpl ntmgr = (NodeTypeManagerImpl)
ws.getNodeTypeManager(); // Acquire the NodeTypeRegistry
NodeTypeRegistry ntreg = ntmgr.getNodeTypeRegistry(); // Loop
through the prepared NodeTypeDefs
for (Iterator i = ntdList.iterator(); i.hasNext();) { // Get the
NodeTypeDef...
NodeTypeDef ntd = (NodeTypeDef) i.next(); // ...and register
it
try{
ntreg.registerNodeType(ntd);
}catch (InvalidNodeTypeDefException e) {
try{
jackRabbitLogger.info("node goes for re
registration");
ntreg.reregisterNodeType(ntd);
}catch(InvalidNodeTypeDefException ie){
jackRabbitLogger.error(ie.getMessage());
}
}
}
} catch (ParseException e) {
jackRabbitLogger.error(e.getMessage(), e);
} catch (FileNotFoundException e) {
jackRabbitLogger.error(e.getMessage(), e);
} catch (RepositoryException e) {
jackRabbitLogger.error(e.getMessage(), e);
// TODO Auto-generated catch block
}
}
Node rootNode = session.getRootNode();
if(!rootNode.hasNode(Declarations.ORIGINAL_DOCS) &&
!rootNode.hasNode(Declarations.PROCESSED_DOCS) &&
!rootNode.hasNode(Declarations.UPLOADS) &&
!rootNode.hasNode(Declarations.DISCUSSION_FORUM)){
rootNode.addNode(Declarations.ORIGINAL_DOCS);
rootNode.addNode(Declarations.PROCESSED_DOCS);
rootNode.addNode(Declarations.UPLOADS);
rootNode.addNode(Declarations.DISCUSSION_FORUM);
rootNode.addNode(Declarations.Reports);
session.save();
commonLogger.info(" Initial repository created");
}
Contains of NodeTypes.cnd file
JACKRABBIT_NODETYPE_FILEPATH
/* orig.namespaces */
<mix = 'http://www.jcp.org/jcr/mix/1.0'>
<nt = 'http://www.jcp.org/jcr/nt/1.0'>
<jcr = 'http://www.jcp.org/jcr/1.0'>
[nt:document] > nt:file
- jcr:description (string)
- jcr:versionComment (string)
- jcr:creationDate (date)
- jcr:lastModified (date)
- jcr:attachedFileName (string)
- jcr:attachedFileSize (string)
- jcr:creator (string)
- jcr:modifier (string)
- jcr:checkedOutBy (string)
- jcr:title (string)
- jcr:discussionComment (string)
- jcr:commentBy (string)2> Using TransientRepository
In this option i have not registered the node type that i do in option 1
what is the advantage of using option 1 as compared to option 2. since i
have not registered the node type i have seen that custom_nodetypes.xml was
not getting created in Repo\repository\nodetypes folder of the repository
what is the disadvantage of not having this file in the repository folder
content of the custom_nodetypes.xml file that gets created in option1 is as
under<?xml version="1.0" encoding="UTF-8"?><nodeTypes
xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:rep="internal"
xmlns:sv="http://www.jcp.org/jcr/sv/1.0"><nodeType
hasOrderableChildNodes="false" isMixin="false" name="nt:document"
primaryItemName=""><supertypes><supertype>nt:file</supertype></supertypes><propertyDefinition
autoCreated="false" mandatory="false" multiple="false" name="jcr:commentBy"
onParentVersion="COPY" protected="false"
requiredType="String"/><propertyDefinition autoCreated="false"
mandatory="false" multiple="false" name="jcr:discussionComment"
onParentVersion="COPY" protected="false"
requiredType="String"/><propertyDefinition autoCreated="false"
mandatory="false" multiple="false" name="jcr:title" onParentVersion="COPY"
protected="false" requiredType="String"/><propertyDefinition
autoCreated="false" mandatory="false" multiple="false"
name="jcr:checkedOutBy" onParentVersion="COPY" protected="false"
requiredType="String"/><propertyDefinition autoCreated="false"
mandatory="false" multiple="false" name="jcr:modifier"
onParentVersion="COPY" protected="false"
requiredType="String"/><propertyDefinition autoCreated="false"
mandatory="false" multiple="false" name="jcr:creator" onParentVersion="COPY"
protected="false" requiredType="String"/><propertyDefinition
autoCreated="false" mandatory="false" multiple="false"
name="jcr:attachedFileSize" onParentVersion="COPY" protected="false"
requiredType="String"/><propertyDefinition autoCreated="false"
mandatory="false" multiple="false" name="jcr:attachedFileName"
onParentVersion="COPY" protected="false"
requiredType="String"/><propertyDefinition autoCreated="false"
mandatory="false" multiple="false" name="jcr:lastModified"
onParentVersion="COPY" protected="false"
requiredType="Date"/><propertyDefinition autoCreated="false"
mandatory="false" multiple="false" name="jcr:creationDate"
onParentVersion="COPY" protected="false"
requiredType="Date"/><propertyDefinition autoCreated="false"
mandatory="false" multiple="false" name="jcr:versionComment"
onParentVersion="COPY" protected="false"
requiredType="String"/><propertyDefinition autoCreated="false"
mandatory="false" multiple="false" name="jcr:description"
onParentVersion="COPY" protected="false"
requiredType="String"/></nodeType></nodeTypes>
Option 2>
public static Session session;
public static Session getSession() {
return session;
}
public void destroy() {
session.logout();
}
public static void main(String[] args) {
try {
System.setProperty("org.apache.jackrabbit.repository.home",
"D:/Repo");
Repository repository = new TransientRepository();
session = repository.login(new SimpleCredentials("username",
"password".toCharArray()));
Node rootNode = session.getRootNode();
for(int i=100; i < 201; i++){
rootNode.addNode(""+i);
}
session.save();
} catch (LoginException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (RepositoryException e) {
e.printStackTrace();
}
}
Please help me to know the option so that i can start working
--
View this message in context:
http://www.nabble.com/Help-required-to-create-jackrabbit-repository-from-the-options-available-to-me-tp22133562p22133562.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.