org.xwiki.rendering.internal.wiki.WikiModelProvider Maven / Gradle / Ivy
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.rendering.internal.wiki;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.xwiki.component.annotation.Component;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.rendering.wiki.WikiModel;
/**
* Helper provider to find out if the WikiModel implementation exists or not.
*
* @version $Id: 3ca81d8732a50a524732d8a1455fd55e8253edbb $
* @since 9.6RC1
*/
@Component
@Singleton
public class WikiModelProvider implements Provider
{
@Inject
@Named("context")
private Provider componentManagerProvider;
@Override
public WikiModel get()
{
WikiModel wikiModel;
// Try to find a WikiModel implementation and set it if it can be found. If not it means we're in
// non wiki mode and the reference parameter will have no effect.
try {
wikiModel = this.componentManagerProvider.get().getInstance(WikiModel.class);
} catch (ComponentLookupException e) {
// There's no WikiModel implementation available.
wikiModel = null;
}
return wikiModel;
}
}