|
Author: adrianc
Date: Sun Jul 11 18:51:19 2010 New Revision: 963121 URL: http://svn.apache.org/viewvc?rev=963121&view=rev Log: Created a JCR repository factory class. This should be sufficient for client code to get a Repository instance and do whatever it wants with it. This code could be moved to the content component and then the jackrabbit component and container could be eliminated. Added: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.properties (with props) ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/RepositoryFactory.java (with props) Modified: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java Added: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.properties URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.properties?rev=963121&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.properties (added) +++ ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.properties Sun Jul 11 18:51:19 2010 @@ -0,0 +1,29 @@ +############################################################################### +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +############################################################################### + +#### +# OFBiz Content Repository properties File +#### + +# Settings for embedded Jackrabbit repository +jackrabbit.repHomeDir=runtime/data/jackrabbit/ +jackrabbit.configFilePath=framework/jackrabbit/config/jackrabbit.xml + +# URL of external JCR-compliant repository +#jndi.repository.url=jcr-jackrabbit://jackrabbit \ No newline at end of file Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.properties ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.properties ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java?rev=963121&r1=963120&r2=963121&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java (original) +++ ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java Sun Jul 11 18:51:19 2010 @@ -75,6 +75,7 @@ public class JackrabbitContainer impleme @Override public boolean start() throws ContainerException { repository = new TransientRepository(jackrabbitConfigFile, homeDir); +// repository = RepositoryFactory.getRepository(); try { Delegator delegator = DelegatorFactory.getDelegator("default"); GenericValue userLogin = delegator.findOne("UserLogin", true, "userLoginId", "system"); Added: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/RepositoryFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/RepositoryFactory.java?rev=963121&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/RepositoryFactory.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/RepositoryFactory.java Sun Jul 11 18:51:19 2010 @@ -0,0 +1,77 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.jackrabbit; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; + +import javax.jcr.Repository; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import org.apache.jackrabbit.core.TransientRepository; +import org.ofbiz.base.location.FlexibleLocation; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilValidate; + +public class RepositoryFactory { + + public static final String module = RepositoryFactory.class.getName(); + private static final Repository repository = createRepoInstance(); + + private static Repository createEmbedded() throws MalformedURLException, URISyntaxException { + String homeDirURL = UtilProperties.getPropertyValue("repository.properties", "jackrabbit.repHomeDir"); + String configFilePath = UtilProperties.getPropertyValue("repository.properties", "jackrabbit.configFilePath"); + File homeDir = new File(homeDirURL); + URL configUrl = FlexibleLocation.resolveLocation(configFilePath); + return new TransientRepository(new File(configUrl.toURI()), homeDir); + } + + private static Repository createRepoInstance() { + Repository result = null; + try { + result = createUsingJndi(); + } catch (Exception e) { + Debug.logError(e, module); + } + if (result == null) { + try { + result = createEmbedded(); + } catch (Exception e) { + Debug.logError(e, module); + } + } + return result; + } + + private static Repository createUsingJndi() throws NamingException { + String repoUrl = UtilProperties.getPropertyValue("repository.properties", "jndi.repository.url"); + if (UtilValidate.isEmpty(repoUrl)) { + return null; + } + return (Repository) new InitialContext().lookup(repoUrl); + } + + public static Repository getRepository() { + return repository; + } +} Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/RepositoryFactory.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/RepositoryFactory.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/RepositoryFactory.java ------------------------------------------------------------------------------ svn:mime-type = text/plain |
| Free forum by Nabble | Edit this page |
