Search in sources :

Example 1 with ResClassLoader

use of org.talend.designer.core.ITisLocalProviderService.ResClassLoader in project tdi-studio-se by Talend.

the class ComponentsFactory method getComponentResourceBundle.

private ResourceBundle getComponentResourceBundle(IComponent currentComp, String source, String cachedPathSource, AbstractComponentsProvider provider) {
    try {
        AbstractComponentsProvider currentProvider = provider;
        if (currentProvider == null) {
            ComponentsProviderManager componentsProviderManager = ComponentsProviderManager.getInstance();
            Collection<AbstractComponentsProvider> providers = componentsProviderManager.getProviders();
            for (AbstractComponentsProvider curProvider : providers) {
                String path = new Path(curProvider.getInstallationFolder().toString()).toPortableString();
                if (source.startsWith(path)) {
                    // fix for TDI-19889 and TDI-20507 to get the correct component provider
                    if (cachedPathSource != null) {
                        if (path.contains(cachedPathSource)) {
                            currentProvider = curProvider;
                            break;
                        }
                    } else {
                        currentProvider = curProvider;
                        break;
                    }
                }
            }
        }
        String installPath = currentProvider.getInstallationFolder().toString();
        String label = ComponentFilesNaming.getInstance().getBundleName(currentComp.getName(), installPath.substring(installPath.lastIndexOf(IComponentsFactory.COMPONENTS_INNER_FOLDER)));
        if (currentProvider.isUseLocalProvider()) {
            // if the component use local provider as storage (for user / ecosystem components)
            // then get the bundle resource from the current main component provider.
            // note: code here to review later, service like this shouldn't be used...
            ResourceBundle bundle = null;
            IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
            if (brandingService.isPoweredOnlyCamel()) {
                bundle = currentProvider.getResourceBundle(label);
            } else {
                ITisLocalProviderService service = (ITisLocalProviderService) GlobalServiceRegister.getDefault().getService(ITisLocalProviderService.class);
                bundle = service.getResourceBundle(label);
            }
            return bundle;
        } else {
            ResourceBundle bundle = ResourceBundle.getBundle(label, Locale.getDefault(), new ResClassLoader(currentProvider.getClass().getClassLoader()));
            return bundle;
        }
    } catch (IOException e) {
        ExceptionHandler.process(e);
    }
    return null;
}
Also used : AbstractComponentsProvider(org.talend.core.model.components.AbstractComponentsProvider) Path(org.eclipse.core.runtime.Path) ComponentBundleToPath(org.talend.designer.core.model.components.ComponentBundleToPath) ResClassLoader(org.talend.designer.core.ITisLocalProviderService.ResClassLoader) ITisLocalProviderService(org.talend.designer.core.ITisLocalProviderService) ResourceBundle(java.util.ResourceBundle) IBrandingService(org.talend.core.ui.branding.IBrandingService) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 ResourceBundle (java.util.ResourceBundle)1 Path (org.eclipse.core.runtime.Path)1 AbstractComponentsProvider (org.talend.core.model.components.AbstractComponentsProvider)1 IBrandingService (org.talend.core.ui.branding.IBrandingService)1 ITisLocalProviderService (org.talend.designer.core.ITisLocalProviderService)1 ResClassLoader (org.talend.designer.core.ITisLocalProviderService.ResClassLoader)1 ComponentBundleToPath (org.talend.designer.core.model.components.ComponentBundleToPath)1