protected void unsetConfigurationContextService( ConfigurationContextService configurationContextService) { if (log.isDebugEnabled()) { log.debug("Un-setting ConfigurationContextService"); } EmailSenderDataHolder.getInstance().setConfigurationContextService(null); }
private void registerServices(ComponentContext componentContext) { if (log.isDebugEnabled()) { log.debug("Registering email sender service"); } EmailSenderService emailServiceProvider = new EmailSenderServiceImpl(); EmailSenderDataHolder.getInstance().setEmailServiceProvider(emailServiceProvider); componentContext .getBundleContext() .registerService(EmailSenderService.class, emailServiceProvider, null); }
private void setupEmailTemplates() throws EmailSenderConfigurationFailedException { File templateDir = new File( CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "resources" + File.separator + "email-templates"); if (!templateDir.exists()) { if (log.isDebugEnabled()) { log.debug( "The directory that is expected to use as the container for all email templates is not " + "available. Therefore, no template is uploaded to the registry"); } } if (templateDir.canRead()) { File[] templates = templateDir.listFiles( new FilenameFilter() { @Override public boolean accept(File dir, String name) { name = name.toLowerCase(); return name.endsWith(".vm"); } }); try { Registry registry = EmailSenderDataHolder.getInstance().getRegistryService().getConfigSystemRegistry(); if (!registry.resourceExists(EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH)) { Collection collection = registry.newCollection(); registry.put(EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH, collection); for (File template : templates) { Resource resource = registry.newResource(); String contents = FileUtils.readFileToString(template); resource.setContent(contents.getBytes()); registry.put( EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH + "/" + template.getName(), resource); } } else { /* Existence of a given resource is not checked consciously, before performing registry.put() below. * The rationale is that, the only less expensive way that one can check if a resource exists is * that through registry.resourceExists(), which only checks if 'some' resource exists at the given * registry path. However, this does not capture scenarios where there can be updated contents to * the same resource of which the path hasn't changed after it has been initialized for the first * time. Therefore, whenever the server starts-up, all email templates are updated just to avoid * the aforementioned problem */ for (File template : templates) { Resource resource = registry.newResource(); String contents = FileUtils.readFileToString(template); resource.setContent(contents.getBytes()); registry.put( EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH + "/" + template.getName(), resource); } } } catch (RegistryException e) { throw new EmailSenderConfigurationFailedException( "Error occurred while setting up email templates", e); } catch (FileNotFoundException e) { throw new EmailSenderConfigurationFailedException( "Error occurred while writing template file " + "contents as an input stream of a resource", e); } catch (IOException e) { throw new EmailSenderConfigurationFailedException( "Error occurred while serializing file " + "contents to a string", e); } } }
/** * Unsets Registry Service. * * @param registryService An instance of RegistryService */ protected void unsetRegistryService(RegistryService registryService) { if (log.isDebugEnabled()) { log.debug("Un setting Registry Service"); } EmailSenderDataHolder.getInstance().setRegistryService(null); }