[xwiki-users] Retrieve/modify page sections with Rest (or Java API)
Hi, I've installed XWiki Enterprise 4.5.3 to test the Restful API. I'd like to retrieve/modify only a section within a page. There is no direct means to do this using a Rest service as far as I could see. Am I right on this point ? How could I use the Java API to get a page's sections ? The plan would be to retrieve the wole page contents and then extract the sections I need using the Java API. Regards, Stephane Thibaudeau. -- View this message in context: http://xwiki.475771.n2.nabble.com/Retrieve-modify-page-sections-with-Rest-or... Sent from the XWiki- Users mailing list archive at Nabble.com.
On Fri, Apr 19, 2013 at 11:32 AM, sthibaudeau <stephane.thibaudeau@gmail.com> wrote:
Hi,
I've installed XWiki Enterprise 4.5.3 to test the Restful API.
I'd like to retrieve/modify only a section within a page. There is no direct means to do this using a Rest service as far as I could see. Am I right on this point ?
How could I use the Java API to get a page's sections ? The plan would be to retrieve the wole page contents and then extract the sections I need using the Java API.
See http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/org... and search for "section" in http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/org... Hope this helps, Marius
Regards, Stephane Thibaudeau.
-- View this message in context: http://xwiki.475771.n2.nabble.com/Retrieve-modify-page-sections-with-Rest-or... Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Hi Marius, Thanks for your answer. I've been explorer the XWikiDocument path but I wasn't able to easily extract the parser stuff and ended with almost all XWiki jars in my project build path. My goal is to keep a lightweight approach so I started looking at the XWikiParser classes. As for now I'm able to parse a page and know how many sections are in it. But I need to look at it more closely to be able to retrieve the whole sections contents without redefining every WemListener's methods. IWikiParser parser = new XWikiParser(); parser.parse(new StringReader(page), new EmptyWemListener() { @Override public void beginSection(int docLevel, int headerLevel, WikiParameters params) { System.out.println("section " + docLevel + "-" + headerLevel); System.out.println(params); } @Override public void beginSectionContent(int docLevel, int headerLevel, WikiParameters params) { System.out.println("sectioncontent " + docLevel + "-" + headerLevel); System.out.println(params); } }); If you have tips or advices, they're very welcome. Regards, Stephane -- View this message in context: http://xwiki.475771.n2.nabble.com/Retrieve-modify-page-sections-with-Rest-or... Sent from the XWiki- Users mailing list archive at Nabble.com.
On Mon, Apr 22, 2013 at 11:32 AM, sthibaudeau <stephane.thibaudeau@gmail.com> wrote:
Hi Marius,
Thanks for your answer. I've been explorer the XWikiDocument path but I wasn't able to easily extract the parser stuff and ended with almost all XWiki jars in my project build path.
My goal is to keep a lightweight approach so I started looking at the XWikiParser classes.
You mean the Rendering engine: http://rendering.xwiki.org/xwiki/bin/view/Main/WebHome
As for now I'm able to parse a page and know how many sections are in it. But I need to look at it more closely to be able to retrieve the whole sections contents without redefining every WemListener's methods.
IWikiParser parser = new XWikiParser(); parser.parse(new StringReader(page), new EmptyWemListener() {
@Override public void beginSection(int docLevel, int headerLevel, WikiParameters params) { System.out.println("section " + docLevel + "-" + headerLevel); System.out.println(params); }
@Override public void beginSectionContent(int docLevel, int headerLevel, WikiParameters params) { System.out.println("sectioncontent " + docLevel + "-" + headerLevel); System.out.println(params); }
});
If you have tips or advices, they're very welcome.
I'm not very familiar with the rendering code. Thomas or Vincent can help you with this.
Regards, Stephane
-- View this message in context: http://xwiki.475771.n2.nabble.com/Retrieve-modify-page-sections-with-Rest-or... Sent from the XWiki- Users mailing list archive at Nabble.com. _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Hi and thanks a lot ! Your link towards the rendering stuff helped me a lot ! Especially the getting started page (http://rendering.xwiki.org/xwiki/bin/view/Main/GettingStarted). Using this I was able to very quickly grab all JARs I needed and implement something as : // Parse XWiki 2.1 Syntax using a Parser. Parser parser = componentManager.getInstance(Parser.class, Syntax.XWIKI_2_1.toIdString()); XDOM xdom = parser.parse(new StringReader(pageContents)); for (Block block : xdom.getBlocks(new SectionByIdBlockMatcher("MySectionId"), Block.Axes.DESCENDANT)) { // Do my stuff } // Generate XWiki 2.1 Syntax as output for example WikiPrinter printer = new DefaultWikiPrinter(); BlockRenderer renderer = componentManager.getInstance(BlockRenderer.class, Syntax.XWIKI_2_1.toIdString()); renderer.render(xdom, printer); With the following helper BlockMatcher : private class SectionByIdBlockMatcher extends ClassBlockMatcher { private String sectionId; public SectionByIdBlockMatcher(String sectionId) { super(SectionBlock.class); this.sectionId = sectionId; } @Override public boolean match(Block block) { return (super.match(block) && sectionId.equals(getSectionId((SectionBlock)block))); } private String getSectionId(SectionBlock sectionBlock) { return sectionBlock.getHeaderBlock().getId(); } } Now I just have to transform my blocks as I need. Easy stuff ! Thanks a lot for your help, Stephane. -- View this message in context: http://xwiki.475771.n2.nabble.com/Retrieve-modify-page-sections-with-Rest-or... Sent from the XWiki- Users mailing list archive at Nabble.com.
participants (2)
-
Marius Dumitru Florea -
sthibaudeau