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);
}
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);
}
}
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();
}
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);
}
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);
}
Aggregations