1 16 package org.apache.cocoon.jcr; 17 18 import org.apache.avalon.framework.configuration.Configuration; 19 import org.apache.avalon.framework.configuration.ConfigurationException; 20 import org.apache.cocoon.components.source.SourceUtil; 21 import org.apache.commons.lang.SystemUtils; 22 import org.apache.excalibur.source.Source; 23 import org.apache.excalibur.source.SourceResolver; 24 import org.apache.excalibur.source.impl.FileSource; 25 import org.apache.jackrabbit.core.RepositoryImpl; 26 import org.apache.jackrabbit.core.config.RepositoryConfig; 27 import org.xml.sax.InputSource ; 28 29 51 public class JackrabbitRepository extends AbstractRepository { 52 53 public void configure(Configuration config) throws ConfigurationException { 54 super.configure(config); 55 if (SystemUtils.isJavaVersionAtLeast(140) == false) { 57 String message = "The jcr block needs at least a java VM version 1.4 to run properly. Please update to a newer java or exclude the jcr block from your Cocoon block configuration."; 58 getLogger().error(message); 59 throw new ConfigurationException(message); 60 } 61 62 String homeURI = config.getChild("home").getAttribute("src"); 63 String homePath; 64 String configURI = config.getChild("configuration").getAttribute("src"); 65 66 SourceResolver resolver = null; 68 try { 69 resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE); 70 71 Source homeSrc = resolver.resolveURI(homeURI); 73 try { 74 if (!(homeSrc instanceof FileSource)) { 75 throw new ConfigurationException("Home path '" + homeURI + "' should map to a file, at " + 76 config.getChild("home").getLocation()); 77 } 78 homePath = ((FileSource) homeSrc).getFile().getAbsolutePath(); 79 } finally { 80 resolver.release(homeSrc); 81 } 82 83 Source configSrc = resolver.resolveURI(configURI); 85 RepositoryConfig repoConfig; 86 try { 87 InputSource is = SourceUtil.getInputSource(configSrc); 88 repoConfig = RepositoryConfig.create(is, homePath); 89 } finally { 90 resolver.release(configSrc); 91 } 92 this.delegate = RepositoryImpl.create(repoConfig); 94 95 } catch (ConfigurationException ce) { 96 throw ce; 97 } catch (Exception e) { 98 throw new ConfigurationException("Cannot access configuration information at " + config.getLocation(), e); 99 } finally { 100 this.manager.release(resolver); 101 } 102 } 103 104 public void dispose() { 105 RepositoryImpl repo = (RepositoryImpl)delegate; 107 super.dispose(); 108 repo.shutdown(); 109 } 110 } 111 | Popular Tags |