Search in sources :

Example 61 with Activate

use of org.apache.felix.scr.annotations.Activate in project acs-aem-commons by Adobe-Consulting-Services.

the class SyslogAppender method activate.

@Activate
@SuppressWarnings("squid:S1149")
protected void activate(ComponentContext ctx) {
    final Dictionary<?, ?> properties = ctx.getProperties();
    final String[] loggers = PropertiesUtil.toStringArray(properties.get(PROP_LOGGERS), new String[] { ROOT });
    final String suffixPattern = PropertiesUtil.toString(properties.get(PROP_SUFFIX_PATTERN), DEFAULT_SUFFIX_PATTERN);
    final int port = PropertiesUtil.toInteger(properties.get(PROP_PORT), DEFAULT_PORT);
    final String host = PropertiesUtil.toString(properties.get(PROP_HOST), null);
    final String facility = PropertiesUtil.toString(properties.get(PROP_FACILITY), DEFAULT_FACILITY);
    final String stackTracePattern = PropertiesUtil.toString(properties.get(PROP_STACK_TRACE_PATTERN), null);
    final boolean throwableExcluded = PropertiesUtil.toBoolean(properties.get(PROP_THROWABLE_EXCLUDED), DEFAULT_THROWABLE_EXCLUDED);
    if (host == null || port == -1) {
        throw new IllegalArgumentException("Syslog Appender not configured correctly. Both host and port need to be provided.");
    }
    // throws a descriptive IllegalArgumentException if facility is not valid.
    SyslogAppenderBase.facilityStringToint(facility);
    final BundleContext bundleContext = ctx.getBundleContext();
    appender = new ch.qos.logback.classic.net.SyslogAppender();
    appender.setSyslogHost(host);
    appender.setPort(port);
    appender.setFacility(facility);
    appender.setSuffixPattern(suffixPattern);
    if (StringUtils.isNotEmpty(stackTracePattern)) {
        appender.setStackTracePattern(stackTracePattern);
    }
    appender.setThrowableExcluded(throwableExcluded);
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put("loggers", loggers);
    appenderRegistration = bundleContext.registerService(Appender.class.getName(), appender, props);
}
Also used : Hashtable(java.util.Hashtable) BundleContext(org.osgi.framework.BundleContext) Activate(org.apache.felix.scr.annotations.Activate)

Example 62 with Activate

use of org.apache.felix.scr.annotations.Activate in project acs-aem-commons by Adobe-Consulting-Services.

the class VersionedClientlibsTransformerFactory method activate.

@Activate
@SuppressWarnings("squid:S1149")
protected void activate(ComponentContext componentContext) {
    final BundleContext bundleContext = componentContext.getBundleContext();
    final Dictionary<?, ?> props = componentContext.getProperties();
    final int size = PropertiesUtil.toInteger(props.get(PROP_MD5_CACHE_SIZE), DEFAULT_MD5_CACHE_SIZE);
    this.md5Cache = CacheBuilder.newBuilder().recordStats().maximumSize(size).build();
    this.disableVersioning = PropertiesUtil.toBoolean(props.get(PROP_DISABLE_VERSIONING), DEFAULT_DISABLE_VERSIONING);
    this.enforceMd5 = PropertiesUtil.toBoolean(props.get(PROP_ENFORCE_MD5), DEFAULT_ENFORCE_MD5);
    if (enforceMd5) {
        Dictionary<String, Object> filterProps = new Hashtable<String, Object>();
        filterProps.put("sling.filter.scope", "REQUEST");
        filterProps.put("service.ranking", Integer.valueOf(0));
        filterReg = bundleContext.registerService(Filter.class.getName(), new BadMd5VersionedClientLibsFilter(), filterProps);
    }
}
Also used : Hashtable(java.util.Hashtable) BundleContext(org.osgi.framework.BundleContext) Activate(org.apache.felix.scr.annotations.Activate)

Example 63 with Activate

use of org.apache.felix.scr.annotations.Activate in project acs-aem-commons by Adobe-Consulting-Services.

the class CustomPollingImporterListServlet method activate.

@Activate
protected void activate(ComponentContext ctx) throws InvalidSyntaxException {
    final BundleContext bundleContext = ctx.getBundleContext();
    StringBuilder builder = new StringBuilder();
    builder.append("(&(");
    builder.append(Constants.OBJECTCLASS).append("=").append(Importer.SERVICE_NAME).append(")");
    builder.append("(displayName=*))");
    Filter filter = bundleContext.createFilter(builder.toString());
    this.tracker = new ServiceTracker(bundleContext, filter, null);
    this.tracker.open();
}
Also used : Filter(org.osgi.framework.Filter) ServiceTracker(org.osgi.util.tracker.ServiceTracker) BundleContext(org.osgi.framework.BundleContext) Activate(org.apache.felix.scr.annotations.Activate)

Example 64 with Activate

use of org.apache.felix.scr.annotations.Activate in project acs-aem-commons by Adobe-Consulting-Services.

the class PageRootProviderConfig method activate.

@Activate
protected void activate(Map<String, Object> props) {
    List<Pattern> patterns = new ArrayList<Pattern>();
    String[] regexes = PropertiesUtil.toStringArray(props.get(PAGE_ROOT_PATH), new String[] { DEFAULT_PAGE_ROOT_PATH });
    for (String regex : regexes) {
        try {
            Pattern p = Pattern.compile("^(" + regex + ")(|/.*)$");
            patterns.add(p);
            log.debug("Added Page Root Pattern [ {} ] to PageRootProvider", p.toString());
        } catch (Exception e) {
            log.error("Could not compile regex [ {} ] to pattern. Skipping...", regex, e);
        }
    }
    this.pageRootPatterns = Collections.unmodifiableList(patterns);
}
Also used : Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) Activate(org.apache.felix.scr.annotations.Activate)

Example 65 with Activate

use of org.apache.felix.scr.annotations.Activate in project stanbol by apache.

the class KuromojiNlpEngine method activate.

/**
 * Activate and read the properties. Configures and initialises a POSTagger for each language configured in
 * CONFIG_LANGUAGES.
 *
 * @param ce the {@link org.osgi.service.component.ComponentContext}
 */
@Activate
protected void activate(ComponentContext ce) throws ConfigurationException, IOException {
    log.info("activating smartcn tokenizing engine");
    super.activate(ce);
    // init the Solr ResourceLoader used for initialising the components
    // first a ResourceLoader for this classloader, 2nd one using the commons.solr.core classloader
    // and third the parentResourceLoader (if present).
    resourceLoader = new StanbolResourceLoader(KuromojiNlpEngine.class.getClassLoader(), new StanbolResourceLoader(parentResourceLoader));
    tokenizerFactory = new JapaneseTokenizerFactory(TOKENIZER_FACTORY_CONFIG);
    ((ResourceLoaderAware) tokenizerFactory).inform(resourceLoader);
    // base form filter
    TokenFilterFactory baseFormFilterFactory = new JapaneseBaseFormFilterFactory(BASE_FORM_FILTER_CONFIG);
    filterFactories.add(baseFormFilterFactory);
    // POS filter
    TokenFilterFactory posFilterFactory = new JapanesePartOfSpeechStopFilterFactory(POS_FILTER_CONFIG);
    ((ResourceLoaderAware) posFilterFactory).inform(resourceLoader);
    filterFactories.add(posFilterFactory);
    // Stemming
    TokenFilterFactory stemmFilterFactory = new JapaneseKatakanaStemFilterFactory(STEMM_FILTER_CONFIG);
    filterFactories.add(stemmFilterFactory);
}
Also used : StanbolResourceLoader(org.apache.stanbol.commons.solr.utils.StanbolResourceLoader) JapaneseTokenizerFactory(org.apache.lucene.analysis.ja.JapaneseTokenizerFactory) JapanesePartOfSpeechStopFilterFactory(org.apache.lucene.analysis.ja.JapanesePartOfSpeechStopFilterFactory) JapaneseKatakanaStemFilterFactory(org.apache.lucene.analysis.ja.JapaneseKatakanaStemFilterFactory) ResourceLoaderAware(org.apache.lucene.analysis.util.ResourceLoaderAware) JapaneseBaseFormFilterFactory(org.apache.lucene.analysis.ja.JapaneseBaseFormFilterFactory) TokenFilterFactory(org.apache.lucene.analysis.util.TokenFilterFactory) Activate(org.apache.felix.scr.annotations.Activate)

Aggregations

Activate (org.apache.felix.scr.annotations.Activate)153 ConfigurationException (org.osgi.service.cm.ConfigurationException)31 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 BundleContext (org.osgi.framework.BundleContext)19 File (java.io.File)15 OsgiWhiteboard (org.apache.jackrabbit.oak.osgi.OsgiWhiteboard)12 URL (java.net.URL)11 Hashtable (java.util.Hashtable)11 ServiceReference (org.osgi.framework.ServiceReference)11 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)9 HashSet (java.util.HashSet)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 Map (java.util.Map)6 Session (javax.jcr.Session)5 StandardMBean (javax.management.StandardMBean)5 Whiteboard (org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard)5 Filter (org.osgi.framework.Filter)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4