Example usage for org.apache.solr.core SolrResourceLoader getClassLoader

List of usage examples for org.apache.solr.core SolrResourceLoader getClassLoader

Introduction

In this page you can find the example usage for org.apache.solr.core SolrResourceLoader getClassLoader.

Prototype

public ClassLoader getClassLoader() 

Source Link

Document

EXPERT

The underlying class loader.

Usage

From source file:alba.components.FilteredShowFileRequestHandler.java

License:Apache License

public static File getAdminFileFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp,
        Set<String> hiddenFiles) {
    File adminFile = null;//  www  .ja v a 2 s  .  com
    final SolrResourceLoader loader = req.getCore().getResourceLoader();
    File configdir = new File(loader.getConfigDir());
    if (!configdir.exists()) {
        // TODO: maybe we should just open it this way to start with?
        try {
            configdir = new File(loader.getClassLoader().getResource(loader.getConfigDir()).toURI());
        } catch (URISyntaxException e) {
            log.error("Can not access configuration directory!");
            rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN,
                    "Can not access configuration directory!", e));
            return null;
        }
    }
    String fname = req.getParams().get("file", null);
    if (fname == null) {
        adminFile = configdir;
    } else {
        fname = fname.replace('\\', '/'); // normalize slashes
        if (hiddenFiles.contains(fname.toUpperCase(Locale.ROOT))) {
            log.error("Can not access: " + fname);
            rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN, "Can not access: " + fname));
            return null;
        }
        if (fname.indexOf("..") >= 0) {
            log.error("Invalid path: " + fname);
            rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN, "Invalid path: " + fname));
            return null;
        }
        adminFile = new File(configdir, fname);
    }
    return adminFile;
}

From source file:jp.aegif.nemaki.util.impl.PropertyManagerImpl.java

License:Open Source License

/**
 * Override is not supported for update//from w  w w . j  a  va  2s .  c o  m
 */
@Override
public void modifyValue(String key, String value) {
    config.setProperty(key, value);

    SolrResourceLoader loader = new SolrResourceLoader(null);
    ClassLoader classLoader = loader.getClassLoader();
    URL url = classLoader.getResource(propertiesFile);

    try {
        if (url == null) {
            config.store(new FileOutputStream(new File(loader.locateSolrHome() + "/conf/" + propertiesFile)),
                    null);
        } else {
            config.store(new FileOutputStream(new File(url.toURI())), null);
        }
    } catch (Exception e) {
        logger.error("Error occurred during modification of porperty value.", e);
    }

}