use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class DefaultModelConfiguration method getDefaultReferenceValue.
@Override
public String getDefaultReferenceValue(EntityType type) {
String name;
try {
// TODO: For the moment we only look in the XWiki properties file since otherwise looking into
// Wiki, Space and User preferences cause some cyclic dependencies (we'll be able to do that when all
// code has been migrated to use References instead of Strings).
ConfigurationSource configuration = this.componentManager.getInstance(ConfigurationSource.class, "xwikiproperties");
name = configuration.getProperty(PREFIX + "reference.default." + type.toString().toLowerCase(), DEFAULT_VALUES.get(type));
} catch (ComponentLookupException e) {
// Failed to load the component, use default values
this.logger.debug("Failed to load [" + ConfigurationSource.class.getName() + "]. Using default Model values", e);
name = DEFAULT_VALUES.get(type);
}
return name;
}
use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class ConfiguredQueryExecutorProvider method init.
/**
* Switch the queryExecutor based on what main store is being used. This is called lazily because the XWikiContext
* might not yet exist when this class is instantiated.
*/
private void init() {
final XWikiContext context;
try {
context = (XWikiContext) this.exec.getContext().getProperty("xwikicontext");
} catch (NullPointerException e) {
this.logger.warn("The QueryExecutor was called without an XWikiContext available. " + "This means the old core (and likely the storage engine) is probably " + "not yet initialized. The default QueryExecutor will be returned.", e);
return;
}
final String storeName = context.getWiki().Param("xwiki.store.main.hint", "default");
try {
this.queryExecutor = this.manager.getInstance(QueryExecutor.class, storeName);
} catch (ComponentLookupException e) {
this.logger.warn("Could not find a QueryExecutor with hint [{}] which is the hint for the storage engine, " + "defined in your XWiki configuration under the [xwiki.store.main.hint] property. " + "The default QueryExecutor will be used instead. Reason: [{}]", storeName, ExceptionUtils.getRootCauseMessage(e));
}
this.initialized = true;
}
use of org.xwiki.component.manager.ComponentLookupException 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.ComponentLookupException 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.ComponentLookupException in project xwiki-platform by xwiki.
the class CodeMacro method highlight.
/**
* Return a highlighted version of the provided content.
*
* @param parameters the code macro parameters.
* @param content the content to highlight.
* @return the highlighted version of the provided content.
* @throws ParseException the highlight parser failed.
* @throws ComponentLookupException failed to find highlight parser for provided language.
*/
protected List<Block> highlight(CodeMacroParameters parameters, String content) throws ParseException, ComponentLookupException {
HighlightParser parser;
if (parameters.getLanguage() != null) {
if (this.componentManager.hasComponent(HighlightParser.class, parameters.getLanguage())) {
try {
parser = this.componentManager.getInstance(HighlightParser.class, parameters.getLanguage());
return parser.highlight(parameters.getLanguage(), new StringReader(content));
} catch (ComponentLookupException e) {
this.logger.error("Faild to load highlighting parser for language [{}]", parameters.getLanguage(), e);
}
}
}
this.logger.debug("Can't find any specific highlighting parser for language [{}]. Trying the default highlighting parser.", parameters.getLanguage());
parser = this.componentManager.getInstance(HighlightParser.class, "default");
return parser.highlight(parameters.getLanguage(), new StringReader(content));
}
Aggregations