Example usage for org.apache.solr.schema IndexSchema getResourceName

List of usage examples for org.apache.solr.schema IndexSchema getResourceName

Introduction

In this page you can find the example usage for org.apache.solr.schema IndexSchema getResourceName.

Prototype

public String getResourceName() 

Source Link

Document

Gets the name of the resource used to instantiate this schema.

Usage

From source file:alba.components.FilteredShowFileRequestHandler.java

License:Apache License

public static boolean isHiddenFile(SolrQueryRequest req, SolrQueryResponse rsp, String fnameIn,
        boolean reportError, Set<String> hiddenFiles) {
    String fname = fnameIn.toUpperCase(Locale.ROOT);
    if (hiddenFiles.contains(fname) || hiddenFiles.contains("*")) {
        if (reportError) {
            log.error("Cannot access " + fname);
            rsp.setException(/*from   ww  w  .  j  av a  2s .  c o  m*/
                    new SolrException(SolrException.ErrorCode.FORBIDDEN, "Can not access: " + fnameIn));
        }
        return true;
    }

    // This is slightly off, a valid path is something like ./schema.xml. I don't think it's worth the effort though
    // to fix it to handle all possibilities though.
    if (fname.indexOf("..") >= 0 || fname.startsWith(".")) {
        if (reportError) {
            log.error("Invalid path: " + fname);
            rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN, "Invalid path: " + fnameIn));
        }
        return true;
    }

    // Make sure that if the schema is managed, we don't allow editing. Don't really want to put
    // this in the init since we're not entirely sure when the managed schema will get initialized relative to this
    // handler.
    SolrCore core = req.getCore();
    IndexSchema schema = core.getLatestSchema();
    if (schema instanceof ManagedIndexSchema) {
        String managed = schema.getResourceName();

        if (fname.equalsIgnoreCase(managed)) {
            return true;
        }
    }
    return false;
}

From source file:com.googlecode.solrgeonames.harvester.Harvester.java

License:Open Source License

/**
 * Start up an embedded Solr server.//w w  w .  j  av  a2  s. co m
 *
 * @param home: The path to the Solr home directory
 * @return EmbeddedSolrServer: The instantiated server
 * @throws Exception if any errors occur
 */
private EmbeddedSolrServer startSolr(String home) throws Exception {
    try {
        SolrConfig solrConfig = new SolrConfig(home, SOLR_CONFIG, null);
        IndexSchema schema = new IndexSchema(solrConfig, SOLR_SCHEMA, null);

        solrContainer = new CoreContainer(new SolrResourceLoader(SolrResourceLoader.locateSolrHome()));
        CoreDescriptor descriptor = new CoreDescriptor(solrContainer, "",
                solrConfig.getResourceLoader().getInstanceDir());
        descriptor.setConfigName(solrConfig.getResourceName());
        descriptor.setSchemaName(schema.getResourceName());

        solrCore = new SolrCore(null, solrConfig.getDataDir(), solrConfig, schema, descriptor);
        solrContainer.register("", solrCore, false);
        return new EmbeddedSolrServer(solrContainer, "");
    } catch (Exception ex) {
        log.error("\nFailed to start Solr server\n");
        throw ex;
    }
}

From source file:com.googlecode.solrgeonames.server.GeoContextListener.java

License:Open Source License

/**
 * Start up an embedded Solr server./*from www . j a v a 2s  .  co m*/
 *
 * @param home: The path to the Solr home directory
 * @return EmbeddedSolrServer: The instantiated server
 * @throws Exception if any errors occur
 */
private EmbeddedSolrServer startSolr(String home) throws Exception {
    SolrConfig solrConfig = new SolrConfig(home, SOLR_CONFIG, null);
    IndexSchema schema = new IndexSchema(solrConfig, SOLR_SCHEMA, null);

    solrContainer = new CoreContainer(new SolrResourceLoader(SolrResourceLoader.locateSolrHome()));
    CoreDescriptor descriptor = new CoreDescriptor(solrContainer, "",
            solrConfig.getResourceLoader().getInstanceDir());
    descriptor.setConfigName(solrConfig.getResourceName());
    descriptor.setSchemaName(schema.getResourceName());

    SolrCore solrCore = new SolrCore(null, solrConfig.getDataDir(), solrConfig, schema, descriptor);
    solrContainer.register("", solrCore, false);
    return new EmbeddedSolrServer(solrContainer, "");
}