Search in sources :

Example 6 with TranslationBundle

use of org.xwiki.localization.TranslationBundle in project xwiki-platform by xwiki.

the class DefaultTranslationBundleContext method initializeCurrentBundles.

private SortedSet<TranslationBundle> initializeCurrentBundles() {
    SortedSet<TranslationBundle> currentBundles = new TreeSet<>();
    try {
        ComponentManager componentManager = this.componentManagerProvider.get();
        List<TranslationBundle> availableBundles = componentManager.<TranslationBundle>getInstanceList(TranslationBundle.class);
        currentBundles.addAll(availableBundles);
    } catch (ComponentLookupException e) {
        this.logger.error("Failed to lookup Bundle components", e);
    }
    return currentBundles;
}
Also used : TranslationBundle(org.xwiki.localization.TranslationBundle) TreeSet(java.util.TreeSet) ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 7 with TranslationBundle

use of org.xwiki.localization.TranslationBundle in project xwiki-platform by xwiki.

the class DefaultLocalizationManager method use.

@Override
public void use(String bundleType, String bundleId) throws TranslationBundleDoesNotExistsException, TranslationBundleFactoryDoesNotExistsException {
    TranslationBundle bundle = getTranslationBundle(bundleType, bundleId);
    this.bundleContext.addBundle(bundle);
}
Also used : TranslationBundle(org.xwiki.localization.TranslationBundle)

Example 8 with TranslationBundle

use of org.xwiki.localization.TranslationBundle in project xwiki-platform by xwiki.

the class JARTranslationBundleFactoryListener method extensionDeleted.

/**
 * @param extension the installed extension
 * @param namespace the namespace where the extension has been installed
 */
private void extensionDeleted(InstalledExtension extension, String namespace) {
    try {
        ComponentDescriptor<TranslationBundle> descriptor = createComponentDescriptor(extension);
        ComponentManager componentManager = this.componentManagerManager.getComponentManager(namespace, false);
        componentManager.unregisterComponent(descriptor);
    } catch (Exception e) {
        this.logger.error("Failed to create TranslationBundle descriptor for extension [{}]", extension, e);
    }
}
Also used : TranslationBundle(org.xwiki.localization.TranslationBundle) ComponentManager(org.xwiki.component.manager.ComponentManager) InitializationException(org.xwiki.component.phase.InitializationException) MalformedURLException(java.net.MalformedURLException)

Example 9 with TranslationBundle

use of org.xwiki.localization.TranslationBundle in project xwiki-platform by xwiki.

the class JARTranslationBundleFactoryListener method extensionAdded.

/**
 * @param extension the uninstalled extension
 * @param namespace the namespace from where the extension has been uninstalled
 */
private void extensionAdded(InstalledExtension extension, String namespace) {
    try {
        File jarFile = new File(extension.getFile().getAbsolutePath());
        ComponentManager componentManager = this.componentManagerManager.getComponentManager(namespace, false);
        if (componentManager == null) {
            componentManager = this.rootComponentManager;
        }
        JARFileTranslationBundle bundle = new JARFileTranslationBundle(jarFile, componentManager, this.translationParser);
        ComponentDescriptor<TranslationBundle> descriptor = createComponentDescriptor(jarFile.toURI().toURL());
        componentManager.registerComponent(descriptor, bundle);
    } catch (Exception e) {
        this.logger.error("Failed to register a TranslationBundle component for extension [{}] on namespace [{}]", extension, namespace, e);
    }
}
Also used : TranslationBundle(org.xwiki.localization.TranslationBundle) ComponentManager(org.xwiki.component.manager.ComponentManager) File(java.io.File) InitializationException(org.xwiki.component.phase.InitializationException) MalformedURLException(java.net.MalformedURLException)

Example 10 with TranslationBundle

use of org.xwiki.localization.TranslationBundle in project xwiki-platform by xwiki.

the class DocumentTranslationBundleFactory method getOnDemandDocumentBundle.

/**
 * Get non-component bundle.
 */
private TranslationBundle getOnDemandDocumentBundle(DocumentReference documentReference) throws TranslationBundleDoesNotExistsException {
    String uid = this.uidSerializer.serialize(documentReference);
    TranslationBundle bundle = this.onDemandBundleCache.get(uid);
    if (bundle == null) {
        synchronized (this.onDemandBundleCache) {
            bundle = this.onDemandBundleCache.get(uid);
            if (bundle == null) {
                bundle = createOnDemandDocumentBundle(documentReference, uid);
                this.onDemandBundleCache.set(uid, bundle);
            }
        }
    }
    return bundle;
}
Also used : TranslationBundle(org.xwiki.localization.TranslationBundle)

Aggregations

TranslationBundle (org.xwiki.localization.TranslationBundle)11 ComponentManager (org.xwiki.component.manager.ComponentManager)4 Test (org.junit.Test)3 MalformedURLException (java.net.MalformedURLException)2 InitializationException (org.xwiki.component.phase.InitializationException)2 Scope (org.xwiki.localization.wiki.internal.TranslationDocumentModel.Scope)2 File (java.io.File)1 Locale (java.util.Locale)1 TreeSet (java.util.TreeSet)1 Expectations (org.jmock.Expectations)1 Mockery (org.jmock.Mockery)1 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 LocalizationContext (org.xwiki.localization.LocalizationContext)1 LocalizationManager (org.xwiki.localization.LocalizationManager)1 Translation (org.xwiki.localization.Translation)1 WikiReference (org.xwiki.model.reference.WikiReference)1 Block (org.xwiki.rendering.block.Block)1 WordBlock (org.xwiki.rendering.block.WordBlock)1