Search in sources :

Example 26 with ComponentLookupException

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

the class XWiki method initXWiki.

/**
 * Initialize all xwiki subsystems.
 *
 * @param config the object holding the XWiki configuration read from {@code xwiki.cfg}
 * @param context see {@link XWikiContext}
 * @param engineContext the XWiki object wrapping the {@link javax.servlet.ServletContext} and which allows to set
 *            data that live on as long as the XWiki webapp is not stopped in the Servlet Container
 * @param noupdate true if the whole initialization should be done (create mandatory xlcasses, initialize stats
 *            service), i.e. if this is not an update, and false otherwise
 * @throws XWikiException if an error happened during initialization (failure to initialize some cache for example)
 * @deprecated since 6.1M2, use {@link #initXWiki(XWikiContext, XWikiEngineContext, boolean)} instead
 */
@Deprecated
public void initXWiki(XWikiConfig config, XWikiContext context, XWikiEngineContext engineContext, boolean noupdate) throws XWikiException {
    getProgress().pushLevelProgress(4, this);
    try {
        getProgress().startStep(this);
        setDatabase(context.getMainXWiki());
        setEngineContext(engineContext);
        context.setWiki(this);
        // "Pre-initialize" XWikiStubContextProvider with a XWikiContext containing a XWiki instance as soon as
        // possible
        Utils.<XWikiStubContextProvider>getComponent(XWikiStubContextProvider.class).initialize(context);
        // Prepare the store
        if (config != null) {
            setConfig(config);
        }
        try {
            initializeStores();
        } catch (ComponentLookupException e) {
            throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, "Failed to initialize stores", e);
        }
        setCriteriaService((XWikiCriteriaService) createClassFromConfig("xwiki.criteria.class", "com.xpn.xwiki.criteria.impl.XWikiCriteriaServiceImpl", context));
        // "Pre-initialize" XWikiStubContextProvider so that rendering engine, plugins or listeners reacting to
        // potential document changes can use it
        Utils.<XWikiStubContextProvider>getComponent(XWikiStubContextProvider.class).initialize(context);
        getProgress().endStep(this);
        getProgress().startStep(this);
        // Make sure these classes exists
        if (noupdate) {
            initializeMandatoryDocuments(context);
            getStatsService(context);
        }
        getProgress().endStep(this);
        getProgress().startStep(this);
        // Prepare the Plugin Engine
        preparePlugins(context);
        getProgress().endStep(this);
        getProgress().startStep(this);
        String ro = getConfiguration().getProperty("xwiki.readonly", "no");
        this.isReadOnly = ("yes".equalsIgnoreCase(ro) || "true".equalsIgnoreCase(ro) || "1".equalsIgnoreCase(ro));
        // Save the configured syntaxes
        String syntaxes = getConfiguration().getProperty("xwiki.rendering.syntaxes", "xwiki/1.0");
        this.configuredSyntaxes = Arrays.asList(StringUtils.split(syntaxes, " ,"));
        getObservationManager().addListener(this);
    } finally {
        getProgress().popLevelProgress(this);
    }
}
Also used : XWikiStubContextProvider(com.xpn.xwiki.util.XWikiStubContextProvider) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)

Example 27 with ComponentLookupException

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

the class AbstractPanelsUIExtensionManager method get.

@Override
public List<UIExtension> get(String extensionPointId) {
    List<UIExtension> panels = new ArrayList<UIExtension>();
    String panelConfigurationString = getConfiguration();
    // Verify that there's a panel configuration property defined, and if not don't return any panel extension.
    if (!StringUtils.isEmpty(panelConfigurationString)) {
        List<String> panelSerializedReferences = new ArrayList<String>();
        for (String serializedReference : getConfiguration().split(",")) {
            panelSerializedReferences.add(serializer.serialize(resolver.resolve(serializedReference.trim())));
        }
        try {
            List<UIExtension> allExtensions = contextComponentManagerProvider.get().getInstanceList(UIExtension.class);
            for (String panelSerializedReference : panelSerializedReferences) {
                for (UIExtension extension : allExtensions) {
                    if (extension.getId().equals(panelSerializedReference)) {
                        panels.add(extension);
                    }
                }
            }
        } catch (ComponentLookupException e) {
            logger.error("Failed to lookup Panels instances, error: [{}]", e);
        }
    }
    return panels;
}
Also used : UIExtension(org.xwiki.uiextension.UIExtension) ArrayList(java.util.ArrayList) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 28 with ComponentLookupException

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

the class PanelWikiUIExtensionComponentBuilder method buildComponents.

@Override
public List<WikiComponent> buildComponents(BaseObject baseObject) throws WikiComponentException {
    String content = baseObject.getStringValue("content");
    Syntax syntax = baseObject.getOwnerDocument().getSyntax();
    DocumentReference documentReference = baseObject.getOwnerDocument().getDocumentReference();
    DocumentReference authorReference = baseObject.getOwnerDocument().getAuthorReference();
    XDOM xdom = this.parser.parse(content, syntax, documentReference);
    try {
        return Collections.<WikiComponent>singletonList(new PanelWikiUIExtension(baseObject.getReference(), authorReference, xdom, syntax, this.componentManager));
    } catch (ComponentLookupException e) {
        throw new WikiComponentException(String.format("Failed to initialize Panel UI extension [%s]", baseObject), e);
    }
}
Also used : WikiComponentException(org.xwiki.component.wiki.WikiComponentException) XDOM(org.xwiki.rendering.block.XDOM) WikiComponent(org.xwiki.component.wiki.WikiComponent) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) Syntax(org.xwiki.rendering.syntax.Syntax) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 29 with ComponentLookupException

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

the class DefaultRestURLGenerator method getURL.

@Override
public URL getURL(EntityReference entityReference) throws XWikiRestException {
    try {
        ParameterizedType type = new DefaultParameterizedType(null, ParametrizedRestURLGenerator.class, entityReference.getClass());
        ParametrizedRestURLGenerator parametrizedRestURLGenerator = componentManager.getInstance(type);
        return parametrizedRestURLGenerator.getURL(entityReference);
    } catch (ComponentLookupException e) {
        throw new XWikiRestException(String.format("Unsupported entity type: [%s]", entityReference.getClass()), e);
    }
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) ParametrizedRestURLGenerator(org.xwiki.rest.url.ParametrizedRestURLGenerator) XWikiRestException(org.xwiki.rest.XWikiRestException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Example 30 with ComponentLookupException

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

the class UIExtensionScriptService method getExtensions.

/**
 * Retrieves the list of {@link UIExtension} for a given Extension Point.
 *
 * Examples:
 * <ul>
 * <li>Get only the {@link UIExtension}s with the given IDs for the Extension Point "platform.example"
 * <pre>$services.uix.getExtensions('platform.example', {'select' : 'id1, id2, id3'})</pre></li>
 * <li>Get all the {@link UIExtension}s for the Extension Point "platform.example" except the
 * {@link UIExtension}s with the IDs "id2" and "id3"
 * <pre>$services.uix.getExtensions('platform.example', {'exclude' : 'id2, id3'})</pre></li>
 * <li>Get all the {@link UIExtension}s for the Extension Point "platform.example" and order them by one of their
 * parameter
 * <pre>$services.uix.getExtensions('platform.example', {'sortByParameter' : 'parameterKey'})</pre></li>
 * <li>Get only the {@link UIExtension}s with the given IDs for the Extension Point "platform.example" and order
 * them by one of their parameter
 * <pre>$services.uix.getExtensions('platform.example',
 * {'select' : 'id1, id2, id3', 'sortByParameter' : 'parameterKey'})</pre></li>
 * </ul>
 *
 * @param extensionPointId The ID of the Extension Point to retrieve the {@link UIExtension}s for
 * @param filters Optional filters to apply before retrieving the list
 * @return the list of {@link UIExtension} for the given Extension Point
 */
public List<UIExtension> getExtensions(String extensionPointId, Map<String, String> filters) {
    List<UIExtension> extensions = getExtensions(extensionPointId);
    for (Map.Entry<String, String> entry : filters.entrySet()) {
        String filterHint = entry.getKey();
        try {
            UIExtensionFilter filter = contextComponentManagerProvider.get().getInstance(UIExtensionFilter.class, filterHint);
            extensions = filter.filter(extensions, this.parseFilterParameters(entry.getValue()));
        } catch (ComponentLookupException e) {
            logger.warn("Unable to find a UIExtensionFilter for hint [{}] " + "while getting UIExtensions for extension point [{}]", filterHint, extensionPointId);
        }
    }
    return extensions;
}
Also used : UIExtensionFilter(org.xwiki.uiextension.UIExtensionFilter) UIExtension(org.xwiki.uiextension.UIExtension) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) Map(java.util.Map)

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