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);
}
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);
}
}
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());
}
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);
}
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);
}
Aggregations