Search in sources :

Example 46 with ComponentManager

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

the class ScriptMimeMessageTest method setUp.

@Before
public void setUp() throws Exception {
    Execution execution = mock(Execution.class);
    ComponentManager componentManager = mock(ComponentManager.class);
    this.scriptMessage = new ScriptMimeMessage(execution, componentManager);
}
Also used : Execution(org.xwiki.context.Execution) ComponentManager(org.xwiki.component.manager.ComponentManager) Before(org.junit.Before)

Example 47 with ComponentManager

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

the class PropertyClassOutputFilterStream method beginWikiClassProperty.

// Events
@Override
public void beginWikiClassProperty(String name, String type, FilterEventParameters parameters) throws FilterException {
    if (this.enabled) {
        ComponentManager componentManager = this.componentManagerProvider.get();
        this.currentClassPropertyMeta = null;
        PropertyClassProvider provider;
        // First try to use the specified class type as hint.
        try {
            if (componentManager.hasComponent(PropertyClassProvider.class, type)) {
                provider = componentManager.getInstance(PropertyClassProvider.class, type);
            } else {
                // In previous versions the class type was the full Java class name of the property class
                // implementation. Extract the hint by removing the Java package prefix and the Class suffix.
                String classType = StringUtils.removeEnd(StringUtils.substringAfterLast(type, "."), "Class");
                if (componentManager.hasComponent(PropertyClassProvider.class, classType)) {
                    provider = componentManager.getInstance(PropertyClassProvider.class, classType);
                } else {
                    this.logger.warn("Unknown property type [{}]", type);
                    return;
                }
            }
        } catch (ComponentLookupException e) {
            throw new FilterException(String.format("Failed to get instance of the property class provider for type [%s]", type), e);
        }
        this.currentClassPropertyMeta = provider.getDefinition();
        if (this.entity == null) {
            // We should use PropertyClassInterface (instead of PropertyClass, its default implementation) but it
            // doesn't have the set methods and adding them would breaks the backwards compatibility. We make the
            // assumption that all property classes extend PropertyClass.
            this.entity = (PropertyClass) provider.getInstance();
        }
        this.entity.setName(name);
        this.entity.setObject(this.currentXClass);
    }
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) FilterException(org.xwiki.filter.FilterException) PropertyClassProvider(com.xpn.xwiki.internal.objects.classes.PropertyClassProvider)

Example 48 with ComponentManager

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

the class XWikiDocumentOutputFilterStream method begin.

private void begin(FilterEventParameters parameters) throws FilterException {
    DocumentReference documentReference = this.documentEntityResolver.resolve(this.currentEntityReference, getDefaultDocumentReference());
    if (this.entity == null) {
        this.entity = new XWikiDocument(documentReference, this.currentLocale);
    } else {
        this.entity.setDocumentReference(documentReference);
        this.entity.setLocale(this.currentLocale);
    }
    // Find default author
    DocumentReference defaultAuthorReference;
    if (this.properties.isAuthorSet()) {
        defaultAuthorReference = this.properties.getAuthor();
    } else {
        XWikiContext xcontext = xcontextProvider.get();
        defaultAuthorReference = xcontext != null ? xcontext.getUserReference() : null;
    }
    this.entity.setCreationDate(getDate(WikiDocumentFilter.PARAMETER_CREATION_DATE, this.currentLocaleParameters, null));
    this.entity.setCreatorReference(getUserReference(WikiDocumentFilter.PARAMETER_CREATION_AUTHOR, this.currentLocaleParameters, defaultAuthorReference));
    this.entity.setDefaultLocale(this.currentDefaultLocale);
    this.entity.setSyntax(getSyntax(WikiDocumentFilter.PARAMETER_SYNTAX, parameters, null));
    this.entity.setParentReference(getEntityReference(WikiDocumentFilter.PARAMETER_PARENT, parameters, null));
    this.entity.setCustomClass(getString(WikiDocumentFilter.PARAMETER_CUSTOMCLASS, parameters, null));
    this.entity.setTitle(getString(WikiDocumentFilter.PARAMETER_TITLE, parameters, null));
    this.entity.setDefaultTemplate(getString(WikiDocumentFilter.PARAMETER_DEFAULTTEMPLATE, parameters, null));
    this.entity.setValidationScript(getString(WikiDocumentFilter.PARAMETER_VALIDATIONSCRIPT, parameters, null));
    this.entity.setHidden(getBoolean(WikiDocumentFilter.PARAMETER_HIDDEN, parameters, false));
    this.entity.setMinorEdit(getBoolean(WikiDocumentFilter.PARAMETER_REVISION_MINOR, parameters, false));
    this.entity.setAuthorReference(getUserReference(WikiDocumentFilter.PARAMETER_REVISION_AUTHOR, parameters, defaultAuthorReference));
    this.entity.setContentAuthorReference(getUserReference(WikiDocumentFilter.PARAMETER_CONTENT_AUTHOR, parameters, defaultAuthorReference));
    String revisions = getString(XWikiWikiDocumentFilter.PARAMETER_JRCSREVISIONS, this.currentLocaleParameters, null);
    if (revisions != null) {
        try {
            this.entity.setDocumentArchive(revisions);
        } catch (XWikiException e) {
            throw new FilterException("Failed to set document archive", e);
        }
    }
    if (this.currentVersion != null && this.properties.isVersionPreserved()) {
        if (VALID_VERSION.matcher(this.currentVersion).matches()) {
            this.entity.setVersion(this.currentVersion);
        } else if (NumberUtils.isDigits(this.currentVersion)) {
            this.entity.setVersion(this.currentVersion + ".1");
        } else {
        // TODO: log something, probably a warning
        }
    }
    this.entity.setDate(getDate(WikiDocumentFilter.PARAMETER_REVISION_DATE, parameters, new Date()));
    this.entity.setComment(getString(WikiDocumentFilter.PARAMETER_REVISION_COMMENT, parameters, ""));
    this.entity.setContentUpdateDate(getDate(WikiDocumentFilter.PARAMETER_CONTENT_DATE, parameters, new Date()));
    if (this.contentListener != null) {
        // Remember the current rendering context target syntax
        this.previousTargetSyntax = this.renderingContext.getTargetSyntax();
    }
    if (parameters.containsKey(WikiDocumentFilter.PARAMETER_CONTENT)) {
        this.entity.setContent(getString(WikiDocumentFilter.PARAMETER_CONTENT, parameters, null));
        if (this.contentListener != null) {
            // Cancel any existing content listener
            this.currentWikiPrinter = null;
            this.contentListener.setWrappedListener(null);
        }
    } else if (this.contentListener != null) {
        if (this.properties != null && this.properties.getDefaultSyntax() != null) {
            this.entity.setSyntax(this.properties.getDefaultSyntax());
        } else {
            // Make sure to set the default syntax if none were provided
            this.entity.setSyntax(this.entity.getSyntax());
        }
        ComponentManager componentManager = this.componentManagerProvider.get();
        String syntaxString = this.entity.getSyntax().toIdString();
        if (componentManager.hasComponent(PrintRendererFactory.class, syntaxString)) {
            PrintRendererFactory rendererFactory;
            try {
                rendererFactory = componentManager.getInstance(PrintRendererFactory.class, syntaxString);
            } catch (ComponentLookupException e) {
                throw new FilterException(String.format("Failed to find PrintRendererFactory for syntax [%s]", this.entity.getSyntax()), e);
            }
            this.currentWikiPrinter = new DefaultWikiPrinter();
            ((MutableRenderingContext) this.renderingContext).setTargetSyntax(rendererFactory.getSyntax());
            this.contentListener.setWrappedListener(rendererFactory.createRenderer(this.currentWikiPrinter));
        }
    }
    // Initialize the class
    getBaseClassOutputFilterStream().setEntity(this.entity.getXClass());
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) ComponentManager(org.xwiki.component.manager.ComponentManager) XWikiContext(com.xpn.xwiki.XWikiContext) FilterException(org.xwiki.filter.FilterException) PrintRendererFactory(org.xwiki.rendering.renderer.PrintRendererFactory) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException) Date(java.util.Date)

Example 49 with ComponentManager

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

the class DefaultExtendedRenderingConfigurationTest method configure.

@Before
public void configure() throws Exception {
    Provider<ComponentManager> contextComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(contextComponentManagerProvider.get()).thenReturn(this.mocker);
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Provider(javax.inject.Provider) Before(org.junit.Before)

Example 50 with ComponentManager

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

the class AbstractHttpTest method initializeSystem.

public static void initializeSystem() throws Exception {
    ComponentManager componentManager = new EmbeddableComponentManager();
    // Only load the minimal number of components required for the test framework, for both performance reasons
    // and for avoiding having to declare dependencies such as HttpServletRequest.
    ComponentAnnotationLoader loader = new ComponentAnnotationLoader();
    List<ComponentDeclaration> componentDeclarations = new ArrayList<>();
    componentDeclarations.add(new ComponentDeclaration(DefaultStringEntityReferenceResolver.class.getName()));
    componentDeclarations.add(new ComponentDeclaration(DefaultStringEntityReferenceSerializer.class.getName()));
    componentDeclarations.add(new ComponentDeclaration(RelativeStringEntityReferenceResolver.class.getName()));
    componentDeclarations.add(new ComponentDeclaration(DefaultEntityReferenceProvider.class.getName()));
    componentDeclarations.add(new ComponentDeclaration(DefaultModelConfiguration.class.getName()));
    componentDeclarations.add(new ComponentDeclaration(DefaultSymbolScheme.class.getName()));
    loader.initialize(componentManager, AbstractTest.class.getClassLoader(), componentDeclarations);
    TestUtils.initializeComponent(componentManager);
}
Also used : AbstractTest(org.xwiki.test.ui.AbstractTest) ComponentDeclaration(org.xwiki.component.annotation.ComponentDeclaration) EmbeddableComponentManager(org.xwiki.component.embed.EmbeddableComponentManager) ComponentManager(org.xwiki.component.manager.ComponentManager) ArrayList(java.util.ArrayList) EmbeddableComponentManager(org.xwiki.component.embed.EmbeddableComponentManager) ComponentAnnotationLoader(org.xwiki.component.annotation.ComponentAnnotationLoader)

Aggregations

ComponentManager (org.xwiki.component.manager.ComponentManager)76 Test (org.junit.Test)34 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)23 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)18 DocumentReference (org.xwiki.model.reference.DocumentReference)17 Provider (javax.inject.Provider)14 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)12 Before (org.junit.Before)11 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)11 XWikiContext (com.xpn.xwiki.XWikiContext)9 Expectations (org.jmock.Expectations)9 WikiReference (org.xwiki.model.reference.WikiReference)9 HashMap (java.util.HashMap)7 Execution (org.xwiki.context.Execution)7 SpaceReference (org.xwiki.model.reference.SpaceReference)7 XWiki (com.xpn.xwiki.XWiki)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)6 ArrayList (java.util.ArrayList)6 ExecutionContext (org.xwiki.context.ExecutionContext)6 MimeMessage (javax.mail.internet.MimeMessage)5