use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class DefaultResourceReferenceResolver method resolve.
@Override
public ResourceReference resolve(ExtendedURL extendedURL, ResourceType type, Map<String, Object> parameters) throws CreateResourceReferenceException, UnsupportedResourceReferenceException {
ResourceReferenceResolver resolver;
// Step 1: Look for a URL-scheme-specific Resolver (a general one that is independent of the passed
// Resource Type). This allows URL-scheme implementation to completely override handling of any
// Resource Type if they wish.
DefaultParameterizedType parameterizedType = new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class);
String hint = this.configuration.getURLFormatId();
if (this.componentManager.hasComponent(parameterizedType, hint)) {
try {
resolver = this.componentManager.getInstance(parameterizedType, hint);
} catch (ComponentLookupException e) {
throw new CreateResourceReferenceException(String.format("Failed to create Resource Reference for [%s].", extendedURL.getWrappedURL()), e);
}
} else {
// Step 2: If not found, use the Generic Resolver, which tries to find a Resolver registered for the
// specific Resource Type.
resolver = this.genericResourceReferenceResolver;
}
return resolver.resolve(extendedURL, type, parameters);
}
use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class DefaultStringResourceTypeResolver method resolve.
@Override
public ResourceType resolve(String type, Map<String, Object> parameters) throws CreateResourceTypeException {
ResourceTypeResolver resolver;
DefaultParameterizedType parameterizedType = new DefaultParameterizedType(null, ResourceTypeResolver.class, String.class);
String hint = this.configuration.getURLFormatId();
if (this.componentManager.hasComponent(parameterizedType, hint)) {
try {
resolver = this.componentManager.getInstance(parameterizedType, hint);
} catch (ComponentLookupException e) {
throw new CreateResourceTypeException(String.format("Failed to convert Resource Type from String [%s] to [%s]", type, ResourceType.class.getSimpleName()), e);
}
} else {
// No specific String Resource Type Resolver for the Scheme URL, use the generic one!
resolver = this.genericResourceTypeResolver;
}
return resolver.resolve(type, parameters);
}
use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class DefaultMandatoryDocumentInitializerManager method getMandatoryDocumentInitializer.
@Override
public MandatoryDocumentInitializer getMandatoryDocumentInitializer(DocumentReference documentReference) {
ComponentManager componentManager = this.componentManagerProvider.get();
String fullReference = this.serializer.serialize(documentReference);
try {
if (componentManager.hasComponent(MandatoryDocumentInitializer.class, fullReference)) {
return componentManager.getInstance(MandatoryDocumentInitializer.class, fullReference);
} else {
String localReference = this.localSerializer.serialize(documentReference);
if (componentManager.hasComponent(MandatoryDocumentInitializer.class, localReference)) {
return componentManager.getInstance(MandatoryDocumentInitializer.class, localReference);
}
}
} catch (ComponentLookupException e) {
this.logger.error("Failed to initialize component [{}] for document", MandatoryDocumentInitializer.class, documentReference, e);
}
return null;
}
use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class XWikiAttachment method loadAttachmentContent.
public void loadAttachmentContent(XWikiContext xcontext) throws XWikiException {
if (this.content == null) {
WikiReference currentWiki = xcontext.getWikiReference();
try {
// Make sure we work on the attachment's wiki
WikiReference attachmentWiki = getReference().getDocumentReference().getWikiReference();
if (attachmentWiki != null) {
xcontext.setWikiReference(attachmentWiki);
}
try {
XWikiAttachmentStoreInterface store = getAttachmentContentStore(xcontext);
store.loadAttachmentContent(this, xcontext, true);
} catch (ComponentLookupException e) {
throw new XWikiException("Failed to find store for attachment [" + getReference() + "]", e);
}
} finally {
if (currentWiki != null) {
xcontext.setWikiReference(currentWiki);
}
}
}
}
use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class Utils method getComponent.
/**
* Lookup a XWiki component by role and hint.
*
* @param roleType the class (aka role) that the component implements
* @param roleHint a value to differentiate different component implementations for the same role
* @return the component's instance
* @throws RuntimeException if the component cannot be found/initialized, or if the component manager is not
* initialized
* @deprecated starting with 4.1M2 use the Component Script Service instead
*/
@Deprecated
public static <T> T getComponent(Type roleType, String roleHint) {
T component;
ComponentManager componentManager = getContextComponentManager();
if (componentManager != null) {
try {
component = componentManager.getInstance(roleType, roleHint);
} catch (ComponentLookupException e) {
throw new RuntimeException("Failed to load component for type [" + roleType + "] for hint [" + roleHint + "]", e);
}
} else {
throw new RuntimeException("Component manager has not been initialized before lookup for [" + roleType + "] for hint [" + roleHint + "]");
}
return component;
}
Aggregations