use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class CascadingVfsPermissionChecker method checkPermission.
@Override
public void checkPermission(VfsResourceReference resourceReference) throws VfsException {
// Prevent using a VFS scheme that correspond to the hint of this component
String scheme = resourceReference.getURI().getScheme();
if (HINT.equals(scheme)) {
throw new VfsException(String.format("[%s] is a reserved VFS URI scheme and cannot be used.", HINT));
}
// Look for a scheme-specific permission checker
VfsPermissionChecker resolvedChecker;
ComponentManager componentManager = this.componentManagerProvider.get();
try {
resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class, scheme);
} catch (ComponentLookupException e) {
// Use the Generic permission checker
try {
resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class);
} catch (ComponentLookupException ee) {
throw new VfsException(String.format("No VFS Permission Checked has been found in the system. " + "Refusing access to VFS URI scheme [%s]", scheme), ee);
}
}
resolvedChecker.checkPermission(resourceReference);
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class JobRootResourceReferenceHandler method handleChild.
private void handleChild(ParentResourceReference reference) throws ResourceReferenceHandlerException {
if (StringUtils.isNotEmpty(reference.getChild())) {
ComponentManager componentManager = this.componentManagerProvider.get();
if (componentManager.hasComponent(JobResourceReferenceHandler.class, reference.getChild())) {
JobResourceReferenceHandler child;
try {
child = componentManager.getInstance(JobResourceReferenceHandler.class, reference.getChild());
} catch (ComponentLookupException e) {
throw new ResourceReferenceHandlerException("Failed to initialize job resource handler with hint [" + reference.getChild() + "]");
}
child.handle(reference);
} else {
throw new ResourceReferenceHandlerException("Unknow job resource handler with hint [" + reference.getChild() + "]");
}
} else {
// TODO: put some explanation about the various services provided by the job resource handler
}
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class DocumentTreeNode method initialize.
@Override
public void initialize() throws InitializationException {
String[] nonLeafChildNodeTypes = new String[] { "translations", "attachments", "classProperties", "objects" };
ComponentManager contextComponentManager = this.contextComponentManagerProvider.get();
try {
for (String nonLeafChildNodeType : nonLeafChildNodeTypes) {
TreeNode treeNode = contextComponentManager.getInstance(TreeNode.class, nonLeafChildNodeType);
this.nonLeafChildNodes.put(nonLeafChildNodeType, treeNode);
}
} catch (ComponentLookupException e) {
throw new InitializationException("Failed to lookup the child components.", e);
}
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class DefaultNotificationFilterManagerTest method setUp.
@Before
public void setUp() throws Exception {
componentManager = mocker.registerMockComponent(ComponentManager.class);
wikiDescriptorManager = mocker.registerMockComponent(WikiDescriptorManager.class);
modelBridge = mocker.registerMockComponent(ModelBridge.class, "cached");
testUser = new DocumentReference("wiki", "test", "user");
testProvider = mock(NotificationFilterPreferenceProvider.class);
when(componentManager.getInstanceList(NotificationFilterPreferenceProvider.class)).thenReturn(Collections.singletonList(testProvider));
// Set a default comportment for the wikiDescriptorManager
when(wikiDescriptorManager.getMainWikiId()).thenReturn("wiki");
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("currentWikiId");
when(wikiDescriptorManager.getAllIds()).thenReturn(Arrays.asList("wiki", "currentWikiId"));
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class DefaultDocumentRevisionProvider method getRevision.
@Override
public XWikiDocument getRevision(DocumentReference reference, String revision) throws XWikiException {
// Parse the version
String revisionPrefix = null;
if (revision != null) {
int revisionPrefixIndex = revision.indexOf(':');
if (revisionPrefixIndex > 0) {
revisionPrefix = revision.substring(0, revisionPrefixIndex);
}
}
String shortRevision;
if (revisionPrefix != null) {
shortRevision = revision.substring(revisionPrefix.length() + 1);
} else {
shortRevision = revision;
}
// Find the provider
DocumentRevisionProvider provider = this.databaseDocumentRevisionProvider;
if (revisionPrefix != null) {
ComponentManager componentManager = this.componentManagerProvider.get();
if (componentManager.hasComponent(DocumentRevisionProvider.class, revisionPrefix)) {
try {
provider = componentManager.getInstance(DocumentRevisionProvider.class, revisionPrefix);
} catch (ComponentLookupException e) {
throw new XWikiException("Failed to get revision provider for revision [" + revision + "]", e);
}
}
}
// Load the document revision
return provider.getRevision(reference, shortRevision);
}
Aggregations