Package org.compass.core.config

Examples of org.compass.core.config.CompassConfiguration


  public void remove() {
    table.remove(siteId);
  }
 
  public void init() throws Exception {
    CompassConfiguration compassConfiguration = new CompassConfiguration();
    JpaConnection jpaConnection = JpaConnection.getInstance();
    if (ApplicationGlobal.isCompassDatabaseStore()) {
      compassConfiguration.setSetting(CompassEnvironment.CONNECTION, "jdbc://" + jpaConnection.getUrl());
      compassConfiguration.setSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.CLASS, C3P0DataSourceProvider.class.getName());
      compassConfiguration.setSetting(LuceneEnvironment.JdbcStore.Connection.DRIVER_CLASS, jpaConnection.getDriver());
      compassConfiguration.setSetting(LuceneEnvironment.JdbcStore.Connection.USERNAME, jpaConnection.getUser());
      compassConfiguration.setSetting(LuceneEnvironment.JdbcStore.Connection.PASSWORD, jpaConnection.getPassword());
    }
    else {
      String directory = ApplicationGlobal.getWorkingDirectory();
      if (!directory.endsWith("/") && !directory.endsWith("\\")) {
        directory += "/";
      }
      directory += "compass";
      File file = new File(directory);
      if (!file.exists()) {
        if (!file.mkdir()) {
          logger.error("Unable to create index directory: " + directory);
        }
      }
      compassConfiguration.setSetting(CompassEnvironment.CONNECTION, directory);
    }
    compassConfiguration.addResource("compass/Content.cpm.xml");
    compassConfiguration.addResource("compass/ContentLanguage.cpm.xml");
    compassConfiguration.addResource("compass/Item.cpm.xml");
    compassConfiguration.addResource("compass/ItemLanguage.cpm.xml");
   
    compass = compassConfiguration.buildCompass();
  }
View Full Code Here


    private CompassGps gps = null;

    @PostConstruct
    public void initialiser() {
        CompassConfiguration conf = new CompassAnnotationsConfiguration();
        conf.configure(getClass().getClassLoader().getResource("compass.cfg.xml"));
        conf.addClass(Location.class);

        compass = conf.buildCompass();
        gps = new SingleCompassGps(compass);

        // Création du composant JPA
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("EvasionPU");
        JpaGpsDevice jpaDevice = new JpaGpsDevice("jpa", emf);
View Full Code Here

    private CompassGps gps = null;

    @PostConstruct
    public void initialiser() {
        CompassConfiguration conf = new CompassAnnotationsConfiguration();
        conf.configure(getClass().getClassLoader().getResource("compass.cfg.xml"));
        conf.addClass(Location.class);

        compass = conf.buildCompass();
        gps = new SingleCompassGps(compass);

        // Création du composant JPA
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("EvasionPU");
        JpaGpsDevice jpaDevice = new JpaGpsDevice("jpa", emf);
View Full Code Here

    public void setCompassConfiguration(CompassConfiguration config) {
        this.config = config;
    }

    public void afterPropertiesSet() throws Exception {
        CompassConfiguration config = this.config;
        if (config == null) {
            config = newConfiguration();
        }

        if (classLoader != null) {
            config.setClassLoader(getClassLoader());
        }

        if (this.configLocation != null) {
            config.configure(this.configLocation.getURL());
        }

        if (this.configLocations != null) {
            for (Resource configLocation1 : configLocations) {
                config.configure(configLocation1.getURL());
            }
        }

        if (this.mappingScan != null) {
            config.addScan(this.mappingScan);
        }

        if (this.compassSettings != null) {
            config.getSettings().addSettings(this.compassSettings);
        }

        if (this.settings != null) {
            config.getSettings().addSettings(this.settings);
        }

        if (resourceLocations != null) {
            for (Resource resourceLocation : resourceLocations) {
                config.addInputStream(resourceLocation.getInputStream(), resourceLocation.getFilename());
            }
        }

        if (resourceJarLocations != null && !"".equals(resourceJarLocations.trim())) {
            log.info("开始执行apdplat对compass的定制修改2");
            log.info("compass resourceJarLocations:" + resourceJarLocations);
            String[] jars = resourceJarLocations.split(",");
            for (String jar : jars) {
                try {
                    FileSystemResource resource = new FileSystemResource(FileUtils.getAbsolutePath(jar));
                    config.addJar(resource.getFile());
                    log.info("compass resourceJarLocations  find:" + jar);
                } catch (Exception e) {
                    log.info("compass resourceJarLocations not exists:" + jar);
                }
            }
        }

        if (classMappings != null) {
            for (String classMapping : classMappings) {
                config.addClass(ClassUtils.forName(classMapping, getClassLoader()));
            }
        }

        if (resourceDirectoryLocations != null && !"".equals(resourceDirectoryLocations.trim())) {
            log.info("开始执行apdplat对compass的定制修改3");
            log.info("compass resourceDirectoryLocations:" + resourceDirectoryLocations);
            String[] dirs = resourceDirectoryLocations.split(",");
            for (String dir : dirs) {
                ClassPathResource resource = new ClassPathResource(dir);
                try {
                    File file = resource.getFile();
                    if (!file.isDirectory()) {
                        log.info("Resource directory location ["
                                + dir + "] does not denote a directory");
                    } else {
                        config.addDirectory(file);
                    }
                    log.info("compass resourceDirectoryLocations find:" + dir);
                } catch (Exception e) {
                    log.info("compass resourceDirectoryLocations not exists:" + dir);
                }
            }
        }

        if (mappingResolvers != null) {
            for (InputStreamMappingResolver mappingResolver : mappingResolvers) {
                config.addMappingResolver(mappingResolver);
            }
        }

        if (dataSource != null) {
            ExternalDataSourceProvider.setDataSource(dataSource);
            if (config.getSettings().getSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.CLASS) == null) {
                config.getSettings().setSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.CLASS,
                        ExternalDataSourceProvider.class.getName());
            }
        }

        String compassTransactionFactory = config.getSettings().getSetting(CompassEnvironment.Transaction.FACTORY);
        if (compassTransactionFactory == null && transactionManager != null) {
            // if the transaciton manager is set and a transcation factory is not set, default to the SpringSync one.
            config.getSettings().setSetting(CompassEnvironment.Transaction.FACTORY, SpringSyncTransactionFactory.class.getName());
        }
        if (compassTransactionFactory != null && compassTransactionFactory.equals(SpringSyncTransactionFactory.class.getName())) {
            if (transactionManager == null) {
                throw new IllegalArgumentException("When using SpringSyncTransactionFactory the transactionManager property must be set");
            }
        }
        SpringSyncTransactionFactory.setTransactionManager(transactionManager);

        if (convertersByName != null) {
            for (Map.Entry<String, Converter> entry : convertersByName.entrySet()) {
                config.registerConverter(entry.getKey(), entry.getValue());
            }
        }
        if (config.getSettings().getSetting(CompassEnvironment.NAME) == null) {
            config.getSettings().setSetting(CompassEnvironment.NAME, beanName);
        }

        if (config.getSettings().getSetting(CompassEnvironment.CONNECTION) == null && connection != null) {
            config.getSettings().setSetting(CompassEnvironment.CONNECTION, connection.getFile().getAbsolutePath());
        }

        if (applicationContext != null) {
            String[] names = applicationContext.getBeanNamesForType(PropertyPlaceholderConfigurer.class);
            for (String name : names) {
                try {
                    PropertyPlaceholderConfigurer propConfigurer = (PropertyPlaceholderConfigurer) applicationContext.getBean(name);
                    Method method = findMethod(propConfigurer.getClass(), "mergeProperties");
                    method.setAccessible(true);
                    Properties props = (Properties) method.invoke(propConfigurer);
                    method = findMethod(propConfigurer.getClass(), "convertProperties", Properties.class);
                    method.setAccessible(true);
                    method.invoke(propConfigurer, props);
                    method = findMethod(propConfigurer.getClass(), "parseStringValue", String.class, Properties.class, Set.class);
                    method.setAccessible(true);
                    String nullValue = null;
                    try {
                        Field field = propConfigurer.getClass().getDeclaredField("nullValue");
                        field.setAccessible(true);
                        nullValue = (String) field.get(propConfigurer);
                    } catch (NoSuchFieldException e) {
                        // no field (old spring version)
                    }
                    for (Map.Entry entry : config.getSettings().getProperties().entrySet()) {
                        String key = (String) entry.getKey();
                        String value = (String) entry.getValue();
                        value = (String) method.invoke(propConfigurer, value, props, new HashSet());
                        config.getSettings().setSetting(key, value.equals(nullValue) ? null : value);
                    }
                } catch (Exception e) {
                    log.debug("Failed to apply property placeholder defined in bean [" + name + "]", e);
                }
            }
View Full Code Here

  /**
   * Erzeugt eine neue CompassBean. Die Eigenschaft <i>compass</i> wird mit
   * einem neuen Compass-Objekt initialisiert.
   */
  public CompassBean() {
    CompassConfiguration conf = new CompassConfiguration().configure();
    conf.addClass(Archivale.class);
    conf.addClass(Dokumentart.class);
    conf.addClass(Name.class);
    conf.addClass(Körperschaft.class);
    conf.addClass(Schlagwort.class);
    compass = conf.buildCompass();
  }
View Full Code Here

        try {
        AltdatenKonverter me = new AltdatenKonverter(file.getInputstream());

        me.extractArchivale();

        CompassConfiguration conf = new CompassConfiguration().configure();
        conf.addClass(Archivale.class);
        conf.addClass(Dokumentart.class);
        conf.addClass(Name.class);
        conf.addClass(Körperschaft.class);
        conf.addClass(Schlagwort.class);
        Compass compass = conf.buildCompass();

        CompassGps gps = new SingleCompassGps(compass);
        CompassGpsDevice jpaDevice = new JpaGpsDevice("jpa", entityManagerFactory);
        gps.addGpsDevice(jpaDevice);
        gps.start();
View Full Code Here

    AltdatenKonverter me = new AltdatenKonverter(new FileInputStream(
        "altdaten/Archivdatenbank.xml"));

    me.extractArchivale();

    CompassConfiguration conf = new CompassConfiguration().configure();
    conf.addClass(Archivale.class);
    conf.addClass(Dokumentart.class);
    conf.addClass(Name.class);
    conf.addClass(Körperschaft.class);
    conf.addClass(Schlagwort.class);
    Compass compass = conf.buildCompass();

    CompassGps gps = new SingleCompassGps(compass);
    CompassGpsDevice jpaDevice = new JpaGpsDevice("jpa", emf);
    gps.addGpsDevice(jpaDevice);
    gps.start();
View Full Code Here

    }

    private void buildCompass() {
        LOG.debug("Building new Compass");

        CompassConfiguration configuration = CompassConfigurationFactory.newConfiguration();

        // TODO find a better place for this
        // register custom converters
        Map converters = new HashMap();
        Map context = new HashMap();
        context.put("customConverters", converters);

        Converter converter = new StringMapConverter();
        configuration.registerConverter(StringMapConverter.CONVERTER_NAME, converter);
        converters.put(StringMapConverter.CONVERTER_NAME, converter);

        // register analyzers used internally
        configuration.getSettings().setSetting("compass.engine.analyzer.searchableplugin_whitespace.type", "whitespace");
        configuration.getSettings().setSetting("compass.engine.analyzer.searchableplugin_simple.type", "simple");

        // add reference to Spring in Compass
        configuration.getSettings().setObjectSetting(ApplicationContext.class.getName() + ".INSTANCE", applicationContext);

        searchableCompassConfigurator.configure(configuration, context);

        compass = configuration.buildCompass();

        LOG.debug("Done building Compass");
    }
View Full Code Here

TOP

Related Classes of org.compass.core.config.CompassConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.