jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephane Landelle (JIRA)" <j...@apache.org>
Subject [jira] Created: (JCR-1861) Support classpath config
Date Mon, 17 Nov 2008 09:08:44 GMT
Support classpath config
------------------------

                 Key: JCR-1861
                 URL: https://issues.apache.org/jira/browse/JCR-1861
             Project: Jackrabbit
          Issue Type: Improvement
          Components: config
            Reporter: Stephane Landelle
             Fix For: 1.5.0


It's possible (and even handy) not to have config resources as Files but as classpath resources,
so they can be bundled into the binaries.
For example, org.apache.jackrabbit.jca.JCARepositoryManager is able to resolve the repository
config file as a classpath resource if it's prefixed with "classpath:".

However, other config files such as the indexing configuration can't currently be resolved
this way. IMHO, this is particularly a problem when using a connector, which should operate
as a standalone bundle without requiring deploying additional resources on the filesystem.

Concerning the indexing configuration, I've modified org.apache.jackrabbit.core.query.lucene.SearchIndex.getIndexingConfigurationDOM()
so it resolves indexingConfiguration as a classpath resource if it's prefixed with "classpath:":

   protected Element getIndexingConfigurationDOM() {
        if (indexingConfiguration != null) {
            return indexingConfiguration;
        }
        if (indexingConfigPath == null) {
            return null;
        }
        try {
        	 DocumentBuilderFactory factory =
             DocumentBuilderFactory.newInstance();
        	 DocumentBuilder builder = factory.newDocumentBuilder();
        	 builder.setEntityResolver(new IndexingConfigurationEntityResolver());

	        if (indexingConfigPath.startsWith(CLASSPATH_CONFIG_PREFIX)) {
                ClassLoader cl = Thread.currentThread().getContextClassLoader();
                if (cl == null) {
                    cl = this.getClass().getClassLoader();
                }
	        	InputStream config = cl.getResourceAsStream(indexingConfigPath.substring(CLASSPATH_CONFIG_PREFIX.length()));
	        	if (config == null) {
		            log.warn("Classpath resource does not exist: {}", indexingConfigPath);
		            return null;
	        	}
	        	indexingConfiguration = builder.parse(config).getDocumentElement();
	        	log.info("indexingConfigPath '{}' resolved as classpath resource", indexingConfigPath);

	        } else {
		        File config = new File(indexingConfigPath);
		        if (!config.exists()) {
		            log.warn("File does not exist: {}", indexingConfigPath);
		            return null;
		        } else if (!config.canRead()) {
		            log.warn("Cannot read file: {}", indexingConfigPath);
		            return null;
		        }
		        indexingConfiguration = builder.parse(config).getDocumentElement();
	        }
           
            
        } catch (ParserConfigurationException e) {
            log.warn("Unable to create XML parser", e);
        } catch (IOException e) {
            log.warn("Exception parsing " + indexingConfigPath, e);
        } catch (SAXException e) {
            log.warn("Exception parsing " + indexingConfigPath, e);
        }
        return indexingConfiguration;
    }

Would it be possible to commit this in the trunk?

Best regards,

St├ęphane Landelle

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message