Search in sources :

Example 41 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class CompositeWikiConfigurationSource method initializeWikiSources.

private synchronized List<ConfigurationSource> initializeWikiSources() {
    if (this.wikiInitialized) {
        return this.sources;
    }
    XWikiContext xcontext = this.xcontextProvider.get();
    // If context is not ready don't do anything
    if (xcontext == null) {
        return Collections.emptyList();
    }
    // Inject registered configuration sources
    List<ConfigurationSource> newSources = new ArrayList<>(this.sources.size() + this.wikiHints.size());
    for (String wikiHint : this.wikiHints) {
        try {
            newSources.add(this.componentManager.getInstance(ConfigurationSource.class, wikiHint));
        } catch (ComponentLookupException e) {
            this.logger.error("Failed to lookup configuration source with hint [%s]. It won't be used.", wikiHint, e);
        }
    }
    this.sources = newSources;
    return this.sources;
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 42 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class InstanceInputFilterStreamFactory method initialize.

@Override
public void initialize() throws InitializationException {
    super.initialize();
    List<InstanceInputEventGenerator> eventGenerators;
    try {
        eventGenerators = this.componentManagerProvider.get().getInstanceList(InstanceInputEventGenerator.class);
    } catch (ComponentLookupException e) {
        throw new InitializationException("Failed to get registered instance of InstanceInputEventGenerator components", e);
    }
    FilterStreamDescriptor[] descriptors = new FilterStreamDescriptor[eventGenerators.size() + 1];
    descriptors[0] = this.descriptor;
    for (int i = 0; i < eventGenerators.size(); ++i) {
        descriptors[i + 1] = eventGenerators.get(i).getDescriptor();
    }
    setDescriptor(new CompositeFilterStreamDescriptor(this.descriptor.getName(), this.descriptor.getDescription(), descriptors));
}
Also used : CompositeFilterStreamDescriptor(org.xwiki.filter.descriptor.CompositeFilterStreamDescriptor) CompositeFilterStreamDescriptor(org.xwiki.filter.descriptor.CompositeFilterStreamDescriptor) FilterStreamDescriptor(org.xwiki.filter.descriptor.FilterStreamDescriptor) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) InitializationException(org.xwiki.component.phase.InitializationException) InstanceInputEventGenerator(org.xwiki.filter.instance.input.InstanceInputEventGenerator)

Example 43 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class AbstractWikiObjectPropertyReader method readObjectProperty.

public WikiObjectProperty readObjectProperty(XMLStreamReader xmlReader, XARInputProperties properties, WikiClass wikiClass) throws XMLStreamException, FilterException {
    xmlReader.nextTag();
    WikiObjectProperty property = new WikiObjectProperty();
    property.name = xmlReader.getLocalName();
    String type;
    if (wikiClass != null) {
        WikiClassProperty classProperty = wikiClass.properties.get(property.name);
        type = classProperty != null ? classProperty.type : null;
    } else {
        type = properties.getObjectPropertyType();
    }
    try {
        property.value = this.propertySerializerManager.getPropertySerializer(type).read(xmlReader);
    } catch (ComponentLookupException e) {
        throw new FilterException("Failed to get a property parser", e);
    }
    property.parameters.put(WikiObjectPropertyFilter.PARAMETER_TYPE, type);
    xmlReader.nextTag();
    return property;
}
Also used : ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) FilterException(org.xwiki.filter.FilterException) WikiClassProperty(org.xwiki.filter.xar.internal.input.ClassPropertyReader.WikiClassProperty)

Example 44 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class DocumentTranslationBundleFactory method createOnDemandDocumentBundle.

private OnDemandDocumentTranslationBundle createOnDemandDocumentBundle(DocumentReference documentReference, String uid) throws TranslationBundleDoesNotExistsException {
    XWikiContext context = this.xcontextProvider.get();
    XWikiDocument document;
    try {
        document = context.getWiki().getDocument(documentReference, context);
    } catch (XWikiException e) {
        throw new TranslationBundleDoesNotExistsException("Failed to get translation document", e);
    }
    if (document.isNew()) {
        throw new TranslationBundleDoesNotExistsException(String.format("Document [%s] does not exists", documentReference));
    }
    OnDemandDocumentTranslationBundle documentBundle;
    try {
        documentBundle = new OnDemandDocumentTranslationBundle(ID_PREFIX, document.getDocumentReference(), this.componentManagerProvider.get(), this.translationParser, this, uid);
    } catch (ComponentLookupException e) {
        throw new TranslationBundleDoesNotExistsException("Failed to create document bundle", e);
    }
    return documentBundle;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) TranslationBundleDoesNotExistsException(org.xwiki.localization.TranslationBundleDoesNotExistsException) XWikiException(com.xpn.xwiki.XWikiException)

Example 45 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class LocalizationScriptService method render.

/**
 * @param keys the translations keys to try one by one
 * @param syntax the syntax in which to render the translation message
 * @param parameters the translation parameters
 * @param locale the {@link Locale} for which this translation is searched. The result might me associated to a
 *            different {@link Locale} (for example getting the {@code fr} translation when asking for the
 *            {@code fr_FR} one).
 * @return the rendered translation message, the key if no translation can be found and null if the rendering failed
 * @since 10.2
 */
public String render(Collection<String> keys, Syntax syntax, Collection<?> parameters, Locale locale) {
    if (CollectionUtils.isEmpty(keys)) {
        return null;
    }
    Translation translation = null;
    for (String key : keys) {
        if (key != null) {
            translation = this.localization.getTranslation(key, locale);
            if (translation != null) {
                break;
            }
        }
    }
    String result;
    if (translation != null) {
        Block block = parameters != null ? translation.render(locale, parameters.toArray()) : translation.render(locale);
        try {
            BlockRenderer renderer = this.componentManager.get().getInstance(BlockRenderer.class, syntax.toIdString());
            DefaultWikiPrinter wikiPrinter = new DefaultWikiPrinter();
            renderer.render(block, wikiPrinter);
            result = wikiPrinter.toString();
        } catch (ComponentLookupException e) {
            // TODO set current error
            result = null;
        }
    } else {
        result = null;
        for (String key : keys) {
            if (key != null) {
                result = key;
            }
        }
    }
    return result;
}
Also used : Translation(org.xwiki.localization.Translation) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) Block(org.xwiki.rendering.block.Block) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) BlockRenderer(org.xwiki.rendering.renderer.BlockRenderer)

Aggregations

ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)104 ComponentManager (org.xwiki.component.manager.ComponentManager)24 Test (org.junit.Test)15 DocumentReference (org.xwiki.model.reference.DocumentReference)12 XWikiContext (com.xpn.xwiki.XWikiContext)10 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)10 InitializationException (org.xwiki.component.phase.InitializationException)8 ArrayList (java.util.ArrayList)7 XWikiException (com.xpn.xwiki.XWikiException)5 HashMap (java.util.HashMap)5 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)5 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)5 FilterException (org.xwiki.filter.FilterException)5 ExtendedURL (org.xwiki.url.ExtendedURL)5 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 Type (java.lang.reflect.Type)4 HashSet (java.util.HashSet)4 WikiComponentException (org.xwiki.component.wiki.WikiComponentException)4 ExecutionContext (org.xwiki.context.ExecutionContext)4 WikiReference (org.xwiki.model.reference.WikiReference)4