use of org.xwiki.component.embed.EmbeddableComponentManager in project OsmAnd-tools by osmandapp.
the class WikiDatabasePreparation method mainTest.
public static void mainTest(String[] args) throws ConversionException, ComponentLookupException, ParseException, IOException {
EmbeddableComponentManager cm = new EmbeddableComponentManager();
cm.initialize(WikiDatabasePreparation.class.getClassLoader());
Parser parser = cm.getInstance(Parser.class, Syntax.MEDIAWIKI_1_0.toIdString());
FileReader fr = new FileReader(new File("/Users/victorshcherb/Documents/b.src.html"));
BufferedReader br = new BufferedReader(fr);
String content = "";
String s;
while ((s = br.readLine()) != null) {
content += s;
}
content = removeMacroBlocks(content, new HashMap<>());
XDOM xdom = parser.parse(new StringReader(content));
// Find all links and make them italic
for (Block block : xdom.getBlocks(new ClassBlockMatcher(LinkBlock.class), Block.Axes.DESCENDANT)) {
Block parentBlock = block.getParent();
Block newBlock = new FormatBlock(Collections.<Block>singletonList(block), Format.ITALIC);
parentBlock.replaceChild(newBlock, block);
}
// for (Block block : xdom.getBlocks(new ClassBlockMatcher(ParagraphBlock.class), Block.Axes.DESCENDANT)) {
// ParagraphBlock b = (ParagraphBlock) block;
// block.getParent().removeBlock(block);
// }
WikiPrinter printer = new DefaultWikiPrinter();
// BlockRenderer renderer = cm.getInstance(BlockRenderer.class, Syntax.XHTML_1_0.toIdString());
// renderer.render(xdom, printer);
// System.out.println(printer.toString());
Converter converter = cm.getInstance(Converter.class);
// Convert input in XWiki Syntax 2.1 into XHTML. The result is stored in the printer.
printer = new DefaultWikiPrinter();
converter.convert(new FileReader(new File("/Users/victorshcherb/Documents/a.src.html")), Syntax.MEDIAWIKI_1_0, Syntax.XHTML_1_0, printer);
System.out.println(printer.toString());
final HTMLConverter nconverter = new HTMLConverter(false);
String lang = "be";
WikiModel wikiModel = new WikiModel("http://" + lang + ".wikipedia.com/wiki/${image}", "http://" + lang + ".wikipedia.com/wiki/${title}");
// String plainStr = wikiModel.render(nconverter, content);
// System.out.println(plainStr);
// downloadPage("https://be.m.wikipedia.org/wiki/%D0%93%D0%BE%D1%80%D0%B0%D0%B4_%D0%9C%D1%96%D0%BD%D1%81%D0%BA",
// "/Users/victorshcherb/Documents/a.wiki.html");
}
use of org.xwiki.component.embed.EmbeddableComponentManager in project xwiki-platform by xwiki.
the class InstallMojo method getModelFactory.
private ModelFactory getModelFactory() throws Exception {
// Initialize XWiki Component system
EmbeddableComponentManager ecm = new EmbeddableComponentManager();
ecm.initialize(this.getClass().getClassLoader());
return ecm.getInstance(ModelFactory.class);
}
use of org.xwiki.component.embed.EmbeddableComponentManager 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);
}
use of org.xwiki.component.embed.EmbeddableComponentManager in project xwiki-platform by xwiki.
the class AbstractTest method initializeSystem.
/**
* Used so that AllTests can set the persistent test context.
*/
public static void initializeSystem(PersistentTestContext context) throws Exception {
AbstractTest.context = context;
BaseElement.setContext(context);
TestUtils.setContext(context);
AbstractTest.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(AbstractTest.componentManager, AbstractTest.class.getClassLoader(), componentDeclarations);
TestUtils.initializeComponent(AbstractTest.componentManager);
}
use of org.xwiki.component.embed.EmbeddableComponentManager in project xwiki-platform by xwiki.
the class XWikiServletContextListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
// Initializes the Embeddable Component Manager
EmbeddableComponentManager ecm = new EmbeddableComponentManager();
// Initialize all the components. Note that this can fail with a Runtime Exception. This is done voluntarily so
// that the XWiki webapp will not be available if one component fails to load. It's better to fail-fast.
ecm.initialize(this.getClass().getClassLoader());
this.componentManager = ecm;
// This is a temporary bridge to allow non XWiki components to lookup XWiki components.
// We're putting the XWiki Component Manager instance in the Servlet Context so that it's
// available in the XWikiAction class which in turn puts it into the XWikiContext instance.
// Class that need to lookup then just need to get it from the XWikiContext instance.
// This is of course not necessary for XWiki components since they just need to implement
// the Composable interface to get access to the Component Manager or better they simply
// need to declare their components requirements using the @Inject annotation of the xwiki
// component manager together with a private class member, for automatic injection by the CM on init.
servletContextEvent.getServletContext().setAttribute(org.xwiki.component.manager.ComponentManager.class.getName(), this.componentManager);
// Use a Component Event Manager that stacks Component instance creation events till we tell it to flush them.
// The reason is that the Observation Manager used to send the events but we need the Application Context to
// be set up before we start sending events since there can be Observation Listener components that require
// the Application Context (this is the case for example for the Office Importer Lifecycle Listener).
StackingComponentEventManager eventManager = new StackingComponentEventManager();
this.componentManager.setComponentEventManager(eventManager);
// Initialize the Environment
try {
ServletEnvironment servletEnvironment = this.componentManager.getInstance(Environment.class);
servletEnvironment.setServletContext(servletContextEvent.getServletContext());
} catch (ComponentLookupException e) {
throw new RuntimeException("Failed to initialize the Servlet Environment", e);
}
// below in an Event Listener and move it to the legacy module.
try {
ServletContainerInitializer containerInitializer = this.componentManager.getInstance(ServletContainerInitializer.class);
containerInitializer.initializeApplicationContext(servletContextEvent.getServletContext());
} catch (ComponentLookupException e) {
throw new RuntimeException("Failed to initialize the Application Context", e);
}
// Send an Observation event to signal the XWiki application is started. This allows components who need to do
// something on startup to do it.
ObservationManager observationManager;
try {
observationManager = this.componentManager.getInstance(ObservationManager.class);
} catch (ComponentLookupException e) {
throw new RuntimeException("Failed to find the Observation Manager component", e);
}
// Now that the Application Context is set up, send the Component instance creation events we had stacked up.
eventManager.setObservationManager(observationManager);
eventManager.shouldStack(false);
eventManager.flushEvents();
// Make sure installed extensions are initialized before sending ApplicationStartedEvent
try {
this.componentManager.getInstance(ExtensionInitializer.class);
} catch (ComponentLookupException e) {
throw new RuntimeException("Failed to initialize installed extensions", e);
}
// Indicate to the various components that XWiki is ready
observationManager.notify(new ApplicationStartedEvent(), this);
}
Aggregations