Search in sources :

Example 51 with Activate

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
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) Activate(org.osgi.service.component.annotations.Activate)

Example 52 with Activate

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();
        }
    }
}
Also used : Hashtable(java.util.Hashtable) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) EventHandler(org.osgi.service.event.EventHandler) Activate(org.osgi.service.component.annotations.Activate)

Example 53 with Activate

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();
        }
    }
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) LoginException(org.apache.sling.api.resource.LoginException) Activate(org.osgi.service.component.annotations.Activate)

Example 54 with Activate

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();
}
Also used : InputStream(java.io.InputStream) Attributes(java.util.jar.Attributes) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) Activate(org.osgi.service.component.annotations.Activate)

Example 55 with Activate

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));
        });
    }
}
Also used : Map(java.util.Map) Result(org.apache.sling.commons.messaging.Result) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

Activate (org.osgi.service.component.annotations.Activate)100 BundleContext (org.osgi.framework.BundleContext)13 File (java.io.File)8 OsgiWhiteboard (org.apache.jackrabbit.oak.osgi.OsgiWhiteboard)7 IOException (java.io.IOException)6 Hashtable (java.util.Hashtable)6 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)5 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)4 ArrayList (java.util.ArrayList)4 Properties (java.util.Properties)3 ServiceReference (org.osgi.framework.ServiceReference)3 PromiseFactory (org.osgi.util.promise.PromiseFactory)3 ServerStartupObserver (org.wso2.carbon.core.ServerStartupObserver)3 JsonObject (com.google.gson.JsonObject)2 Date (java.util.Date)2 Dictionary (java.util.Dictionary)2 ObjectName (javax.management.ObjectName)2 Whiteboard (org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard)2 WhiteboardExecutor (org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardExecutor)2 LoginException (org.apache.sling.api.resource.LoginException)2