# Wiki source code of AjaxMacro

Last modified by etvc developer on 2019/09/21 01:41
Export
Office Formats
Export as PDF
Other Formats
Export as HTML

Show last authors

author | version | line-number | content
--- | --- | --- | ---
1 | {{groovy}}
2 | import org.xwiki.rendering.block.*;
3 |
4 | def findAjaxMacro(pagedoc, pagecontextdoc, parentblock) {
5 | def bid = ""
6 | try {
7 | bid = parentblock.getId();
8 | } catch (e2) {}
9 | // println "Searching for ajax macro ${request.id} in doc ${pagedoc.fullName} in block ${parentblock} ${bid}"
10 | def macroBlocks = null;
11 | try {
12 | macroBlocks = parentblock.getChildrenByType(MacroBlock.class, true)
13 | for (MacroBlock macroBlock : macroBlocks) {
14 | def id = macroBlock.getId();
15 | if (id.equals("ajax")) {
16 | // println "Found ajax macro ${macroBlock.getParameter("id")}"
17 | if (macroBlock.getParameter("id").equals(request.id)) {
18 | def content = macroBlock.getContent();
19 | // println "Ready to parse content: ${content}";
20 | println pagecontextdoc.getRenderedContent(content, "xwiki/2.0")
21 | }
22 | } else if (id.equals("include")) {
23 | def includecontext = macroBlock.getParameter("context");
24 | def includedocname = macroBlock.getParameter("document");
25 | def includedoc = xwiki.getDocument(includedocname)
26 | if ((includecontext!=null) && includecontext=="new")
27 | findAjaxMacro(includedoc, includedoc, includedoc.document.getXDOM())
28 | else
29 | findAjaxMacro(includedoc, pagedoc, includedoc.document.getXDOM())
30 | } else {
31 | findAjaxMacro(pagedoc, pagecontextdoc, macroBlock);
32 | }
33 | }
34 | } catch (Exception e) {
35 | println "Exception in macro ${bid}: ${e}"
36 | }
37 | }
38 |
39 | if(request.page) {
40 | def pagedoc = xwiki.getDocument(request.page)
41 | def contextpagedoc = pagedoc
42 | if (request.contextpage && request.contextpage!="") {
43 | contextpagedoc = xwiki.getDocument(request.contextpage)
44 | }
45 | if (!request.id||request.id=="")
46 | println contextpagedoc.getRenderedContent(pagedoc.getContent(), "xwiki/2.0")
47 | else {
48 | findAjaxMacro(pagedoc, pagedoc, pagedoc.document.getXDOM());
49 | }
50 | } else {
51 | println """
52 | Ajax Macro. See sample at [[AjaxMacroSample]]
53 | """
54 | }
55 | {{/groovy}}

# Applications

# Tips

Jump to any page in the wiki with Ctrl+G or Meta+G.
See more shortcuts.

# Need help?

If you need help with XWiki you can contact:

- Community Support
- Professional Support

XWiki Debian 11.5