use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class MimeTypeServiceImpl method activate.
// ---------- SCR implementation -------------------------------------------
@Activate
protected void activate(final BundleContext context, final Config config) {
context.addBundleListener(this);
// register core and default sling mime types
Bundle bundle = context.getBundle();
registerMimeType(bundle.getEntry(CORE_MIME_TYPES));
registerMimeType(bundle.getEntry(MIME_TYPES));
// register maps of existing bundles
Bundle[] bundles = context.getBundles();
for (int i = 0; i < bundles.length; i++) {
if ((bundles[i].getState() & (Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING)) != 0 && bundles[i].getBundleId() != bundle.getBundleId()) {
this.registerMimeType(bundles[i].getEntry(MIME_TYPES));
}
}
// register configuration properties
if (config.mime_types() != null) {
for (final String configType : config.mime_types()) {
registerMimeType(configType);
}
}
try {
MimeTypeWebConsolePlugin plugin = new MimeTypeWebConsolePlugin(this);
Dictionary<String, String> props = new Hashtable<>();
props.put("felix.webconsole.label", MimeTypeWebConsolePlugin.LABEL);
props.put("felix.webconsole.title", MimeTypeWebConsolePlugin.TITLE);
props.put("felix.webconsole.category", "Sling");
props.put("felix.webconsole.css", MimeTypeWebConsolePlugin.CSS_REFS);
webConsolePluginService = context.registerService("javax.servlet.Servlet", plugin, props);
} catch (Throwable t) {
// don't care, we thus don't have the console plugin
}
}
use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class ResourceValidationModelProviderImpl method activate.
@Activate
protected void activate(ComponentContext componentContext) throws LoginException {
ResourceResolver rr = null;
try {
rr = rrf.getServiceResourceResolver(null);
StringBuilder sb = new StringBuilder("(");
String[] searchPaths = rr.getSearchPath();
if (searchPaths.length > 1) {
sb.append("|");
}
for (String searchPath : searchPaths) {
sb.append("(path=").append(searchPath + "*").append(")");
}
sb.append(")");
Dictionary<String, Object> eventHandlerProperties = new Hashtable<String, Object>();
eventHandlerProperties.put(EventConstants.EVENT_TOPIC, TOPICS);
eventHandlerProperties.put(EventConstants.EVENT_FILTER, sb.toString());
eventHandlerRegistration = componentContext.getBundleContext().registerService(EventHandler.class, this, eventHandlerProperties);
LOG.debug("Registered event handler for validation models in {}", sb.toString());
} finally {
if (rr != null) {
rr.close();
}
}
}
use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class ValidationServiceImpl method activate.
@Activate
protected void activate(ValidationServiceConfiguration configuration) {
this.configuration = configuration;
ResourceResolver rr = null;
try {
rr = rrf.getServiceResourceResolver(null);
searchPaths = Arrays.asList(rr.getSearchPath());
} catch (LoginException e) {
throw new IllegalStateException("Could not get service resource resolver to figure out search paths", e);
} finally {
if (rr != null) {
rr.close();
}
}
}
use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class SightlyEngineConfiguration method activate.
@Activate
protected void activate(Configuration configuration) {
InputStream ins = null;
try {
ins = getClass().getResourceAsStream("/META-INF/MANIFEST.MF");
if (ins != null) {
Manifest manifest = new Manifest(ins);
Attributes attrs = manifest.getMainAttributes();
String version = attrs.getValue("ScriptEngine-Version");
if (version != null) {
engineVersion = version;
}
String symbolicName = attrs.getValue("Bundle-SymbolicName");
if (StringUtils.isNotEmpty(symbolicName)) {
bundleSymbolicName = symbolicName;
}
}
} catch (IOException ioe) {
} finally {
if (ins != null) {
try {
ins.close();
} catch (IOException ignore) {
}
}
}
keepGenerated = configuration.keepGenerated();
}
use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class MessageSender method activate.
@Activate
public void activate() throws ExecutionException, InterruptedException {
logger.info("activate()");
for (int i = 0; i < 10; i++) {
final String message = "a simple text message";
final String recipient = "form@fling";
final String subject = String.format("message number %s", i);
final Map configuration = Collections.singletonMap("mail.subject", subject);
final CompletableFuture<Result> future = messageService.send(message, recipient, Collections.singletonMap("mail", configuration));
future.thenAccept(result -> {
final byte[] bytes = (byte[]) result.getMessage();
logger.debug("message sent: {}", new String(bytes, StandardCharsets.UTF_8));
});
}
}
Aggregations