[xwiki-devs] [XOO] Images in XWiki pages
Hi everybody! Sorry for bother you again with my questions, but I have a problem that blocks me. I need to know what images are internal (they are attached to the current page or other XWiki page) in order to download them with my XMLRPC client. Using the rendering module I get every ImageBlock [1] and I check the ImageType[2] of every Image[3] object. My problem is that this type is URL for both external and internal images and that's why I can't cast to the DocumentImage class. I've pasted bellow my code and the output for some inputs. Can somebody tell me what I am wrong? Is there any other solution for getting the associated attachments? My client has these methods for getting the attachment data: - Attachment<http://confluence.atlassian.com/display/DOC/Remote+API+Specification#RemoteAPISpecification-Attachment> getAttachment(String token, String pageId, String fileName, String versionNumber) - get information about an attachment. - byte[] getAttachmentData(String token, String pageId, String fileName, String versionNumber) - get the contents of an attachment. - byte[] getAttachmentData(Attachment attachment) - get the contents of an attachment. My code: // Parse Parser parser = ecm.lookup(Parser.class, syntax.toIdString()); XDOM xdom = parser.parse(new StringReader(source)); for (ImageBlock block : xdom.getChildrenByType(ImageBlock.class, true)) { Image image = block.getImage(); System.out.println(image.getType() + ""); System.out.println(image.getName() + ""); } Tests: Input: source: [[image:IMG3219.JPG]] image:http://www.balsamiq.com/images/xwiki_logo.png Syntax : XWIKI_2_0 Output: URL IMG3219.JPG URL http://www.balsamiq.com/images/xwiki_logo.png Input: source: <p><img src="IMG3219.JPG" alt="IMG3219.JPG"/><br/><br/><img src=" http://www.balsamiq.com/images/xwiki_logo.png" class="wikimodel-freestanding" alt=" http://www.balsamiq.com/images/xwiki_logo.png"/></p> syntax: XHTML_1_0 Output: URL IMG3219.JPG URL http://www.balsamiq.com/images/xwiki_logo.png Links: [1] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki... [2] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki... [3] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki... Best regards, Cristina
Hi Cristina, Unless you are in wiki mode you will always get URL. To be in wiki mode you need to provide an implementation of WikiModel component interface. On Thu, Aug 13, 2009 at 19:08, Cristina Scheau<[email protected]> wrote:
Hi everybody!
Sorry for bother you again with my questions, but I have a problem that blocks me. I need to know what images are internal (they are attached to the current page or other XWiki page) in order to download them with my XMLRPC client. Using the rendering module I get every ImageBlock [1] and I check the ImageType[2] of every Image[3] object. My problem is that this type is URL for both external and internal images and that's why I can't cast to the DocumentImage class. I've pasted bellow my code and the output for some inputs. Can somebody tell me what I am wrong? Is there any other solution for getting the associated attachments?
My client has these methods for getting the attachment data:
- Attachment<http://confluence.atlassian.com/display/DOC/Remote+API+Specification#RemoteAPISpecification-Attachment> getAttachment(String token, String pageId, String fileName, String versionNumber) - get information about an attachment. - byte[] getAttachmentData(String token, String pageId, String fileName, String versionNumber) - get the contents of an attachment. - byte[] getAttachmentData(Attachment attachment) - get the contents of an attachment.
My code:
// Parse Parser parser = ecm.lookup(Parser.class, syntax.toIdString()); XDOM xdom = parser.parse(new StringReader(source));
for (ImageBlock block : xdom.getChildrenByType(ImageBlock.class, true)) { Image image = block.getImage(); System.out.println(image.getType() + ""); System.out.println(image.getName() + ""); }
Tests: Input: source: [[image:IMG3219.JPG]]
image:http://www.balsamiq.com/images/xwiki_logo.png Syntax : XWIKI_2_0
Output:
URL IMG3219.JPG URL http://www.balsamiq.com/images/xwiki_logo.png
Input: source: <p><img src="IMG3219.JPG" alt="IMG3219.JPG"/><br/><br/><img src=" http://www.balsamiq.com/images/xwiki_logo.png" class="wikimodel-freestanding" alt=" http://www.balsamiq.com/images/xwiki_logo.png"/></p> syntax: XHTML_1_0
Output: URL IMG3219.JPG URL http://www.balsamiq.com/images/xwiki_logo.png
Links:
[1] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki... [2] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki... [3] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
Best regards, Cristina _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
On Aug 14, 2009, at 12:43 PM, Thomas Mortagne wrote:
Hi Cristina,
Unless you are in wiki mode you will always get URL.
To be in wiki mode you need to provide an implementation of WikiModel component interface.
See http://code.xwiki.org/xwiki/bin/view/Modules/RenderingModule (I've just updated it). The implementation of WikiModel is in xwiki-rendering-xwiki. Thanks -Vincent
On Thu, Aug 13, 2009 at 19:08, Cristina Scheau<[email protected]
wrote: Hi everybody!
Sorry for bother you again with my questions, but I have a problem that blocks me. I need to know what images are internal (they are attached to the current page or other XWiki page) in order to download them with my XMLRPC client. Using the rendering module I get every ImageBlock [1] and I check the ImageType[2] of every Image[3] object. My problem is that this type is URL for both external and internal images and that's why I can't cast to the DocumentImage class. I've pasted bellow my code and the output for some inputs. Can somebody tell me what I am wrong? Is there any other solution for getting the associated attachments?
My client has these methods for getting the attachment data:
- Attachment<http://confluence.atlassian.com/display/DOC/Remote+API+Specification#RemoteA...
getAttachment(String token, String pageId, String fileName, String versionNumber) - get information about an attachment. - byte[] getAttachmentData(String token, String pageId, String fileName, String versionNumber) - get the contents of an attachment. - byte[] getAttachmentData(Attachment attachment) - get the contents of an attachment.
My code:
// Parse Parser parser = ecm.lookup(Parser.class, syntax.toIdString()); XDOM xdom = parser.parse(new StringReader(source));
for (ImageBlock block : xdom.getChildrenByType(ImageBlock.class, true)) { Image image = block.getImage(); System.out.println(image.getType() + ""); System.out.println(image.getName() + ""); }
Tests: Input: source: [[image:IMG3219.JPG]]
image:http://www.balsamiq.com/images/xwiki_logo.png Syntax : XWIKI_2_0
Output:
URL IMG3219.JPG URL http://www.balsamiq.com/images/xwiki_logo.png
Input: source: <p><img src="IMG3219.JPG" alt="IMG3219.JPG"/><br/><br/
<img src=" http://www.balsamiq.com/images/xwiki_logo.png" class="wikimodel-freestanding" alt=" http://www.balsamiq.com/images/xwiki_logo.png"/></p> syntax: XHTML_1_0
Output: URL IMG3219.JPG URL http://www.balsamiq.com/images/xwiki_logo.png
Links:
[1] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki... [2] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki... [3] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
Best regards, Cristina
On Fri, Aug 14, 2009 at 12:51, Vincent Massol<[email protected]> wrote:
On Aug 14, 2009, at 12:43 PM, Thomas Mortagne wrote:
Hi Cristina,
Unless you are in wiki mode you will always get URL.
To be in wiki mode you need to provide an implementation of WikiModel component interface.
See http://code.xwiki.org/xwiki/bin/view/Modules/RenderingModule (I've just updated it).
The implementation of WikiModel is in xwiki-rendering-xwiki.
Actually i did not said to use it because the one in xwiki-rendering-xwiki depends on a DocumentAccessBridge so it's easier to implement just WikiMacro.
Thanks -Vincent
On Thu, Aug 13, 2009 at 19:08, Cristina Scheau<[email protected]
wrote: Hi everybody!
Sorry for bother you again with my questions, but I have a problem that blocks me. I need to know what images are internal (they are attached to the current page or other XWiki page) in order to download them with my XMLRPC client. Using the rendering module I get every ImageBlock [1] and I check the ImageType[2] of every Image[3] object. My problem is that this type is URL for both external and internal images and that's why I can't cast to the DocumentImage class. I've pasted bellow my code and the output for some inputs. Can somebody tell me what I am wrong? Is there any other solution for getting the associated attachments?
My client has these methods for getting the attachment data:
- Attachment<http://confluence.atlassian.com/display/DOC/Remote+API+Specification#RemoteA...
getAttachment(String token, String pageId, String fileName, String versionNumber) - get information about an attachment. - byte[] getAttachmentData(String token, String pageId, String fileName, String versionNumber) - get the contents of an attachment. - byte[] getAttachmentData(Attachment attachment) - get the contents of an attachment.
My code:
// Parse Parser parser = ecm.lookup(Parser.class, syntax.toIdString()); XDOM xdom = parser.parse(new StringReader(source));
for (ImageBlock block : xdom.getChildrenByType(ImageBlock.class, true)) { Image image = block.getImage(); System.out.println(image.getType() + ""); System.out.println(image.getName() + ""); }
Tests: Input: source: [[image:IMG3219.JPG]]
image:http://www.balsamiq.com/images/xwiki_logo.png Syntax : XWIKI_2_0
Output:
URL IMG3219.JPG URL http://www.balsamiq.com/images/xwiki_logo.png
Input: source: <p><img src="IMG3219.JPG" alt="IMG3219.JPG"/><br/><br/
<img src=" http://www.balsamiq.com/images/xwiki_logo.png" class="wikimodel-freestanding" alt=" http://www.balsamiq.com/images/xwiki_logo.png"/></p> syntax: XHTML_1_0
Output: URL IMG3219.JPG URL http://www.balsamiq.com/images/xwiki_logo.png
Links:
[1] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki... [2] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki... [3] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
Best regards, Cristina
devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
Hi! Thank you very much for answering me. The documentation and your suggestions were really useful for me. I've created a component that implements the XWikiModel interface and now the type of the Image is DOCUMENT as I expected to be. The problem is , when I cast the Image to the DocumentImage, the getDocumentName() method returns NULL, instead of the real document name. Should I implement something else to get the real value? Thank you for your help, Cristina On Fri, Aug 14, 2009 at 2:21 PM, Thomas Mortagne <[email protected]>wrote:
On Fri, Aug 14, 2009 at 12:51, Vincent Massol<[email protected]> wrote:
On Aug 14, 2009, at 12:43 PM, Thomas Mortagne wrote:
Hi Cristina,
Unless you are in wiki mode you will always get URL.
To be in wiki mode you need to provide an implementation of WikiModel component interface.
See http://code.xwiki.org/xwiki/bin/view/Modules/RenderingModule (I've just updated it).
The implementation of WikiModel is in xwiki-rendering-xwiki.
Actually i did not said to use it because the one in xwiki-rendering-xwiki depends on a DocumentAccessBridge so it's easier to implement just WikiMacro.
Thanks -Vincent
On Thu, Aug 13, 2009 at 19:08, Cristina Scheau<
wrote: Hi everybody!
Sorry for bother you again with my questions, but I have a problem that blocks me. I need to know what images are internal (they are attached to the current page or other XWiki page) in order to download them with my XMLRPC client. Using the rendering module I get every ImageBlock [1] and I check the ImageType[2] of every Image[3] object. My problem is that this type is URL for both external and internal images and that's why I can't cast to the DocumentImage class. I've pasted bellow my code and the output for some inputs. Can somebody tell me what I am wrong? Is there any other solution for getting the associated attachments?
My client has these methods for getting the attachment data:
- Attachment< http://confluence.atlassian.com/display/DOC/Remote+API+Specification#RemoteA...
getAttachment(String token, String pageId, String fileName, String versionNumber) - get information about an attachment. - byte[] getAttachmentData(String token, String pageId, String fileName, String versionNumber) - get the contents of an attachment. - byte[] getAttachmentData(Attachment attachment) - get the contents of an attachment.
My code:
// Parse Parser parser = ecm.lookup(Parser.class, syntax.toIdString()); XDOM xdom = parser.parse(new StringReader(source));
for (ImageBlock block : xdom.getChildrenByType(ImageBlock.class, true)) { Image image = block.getImage(); System.out.println(image.getType() + ""); System.out.println(image.getName() + ""); }
Tests: Input: source: [[image:IMG3219.JPG]]
image:http://www.balsamiq.com/images/xwiki_logo.png Syntax : XWIKI_2_0
Output:
URL IMG3219.JPG URL http://www.balsamiq.com/images/xwiki_logo.png
Input: source: <p><img src="IMG3219.JPG" alt="IMG3219.JPG"/><br/><br/
<img src=" http://www.balsamiq.com/images/xwiki_logo.png" class="wikimodel-freestanding" alt=" http://www.balsamiq.com/images/xwiki_logo.png"/></p> syntax: XHTML_1_0
Output: URL IMG3219.JPG URL http://www.balsamiq.com/images/xwiki_logo.png
Links:
[1]
http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
[2]
http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
[3]
http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
Best regards, Cristina
devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
The graphic for the updated http://code.xwiki.org/xwiki/bin/view/Modules/RenderingModule suggests that PDF is one of the outputs of the rendering module, although the document itself says "XWiki Syntax 2.0 (xwiki/2.0), XHTML (xhtml/1.0), Plain Text (plain/1.0)". Can the new rendering module be used to render a PNG, SVG, GIF, JPG, or Flash, instead of the above? Actually, I guess the best way to phrase this, is there a way to get the rendering module "out of the way" and allow a simple document containing a setContentType() declaration appropriate for the given image at the beginning, followed by a single call to the macro, which would output "binary data". Of course, "plain text" could be used, ultimately, for outputting PNG and xhtml/1.0 for SVG... Lets say I do some Query against all wiki documents, and instead of rendering the query "textually" I want to render it as a graphics image. Given it's capabilities, this might best be achievable with a groovy script. So assume a groovy script which creates, "in memory" a SVG, GIF, PNG, or JPG of the aforementioned query, via Java library calls, glued together with groovy. Lets say I used this example, which outputs SVG: http://www.jroller.com/aalmiray/entry/graphicsbuilder_update_on_svgrenderer how could the SVG get rendered from the groovy script and output directly to the document, rather than being written as an attachment to be included in the document as in is this hypothetical example: 1. def go = { 2. antialias true 3. rect( x: 50, y: 50, w: 100, h: 100, f: 'red', bc: 'darkRed' ) 4. rect( x: 10, y: 10, w: 100, h: 100, f: 'blue', bc: 'navy' ) 5. circle( cx: 150, cy: 150, r: 40, f: 'orange', bc: 'darkOrange' ) 6. star( cx: 100, cy: 100, or: 50, ir: 20, f: 'green', bc: 'darkGreen' ) 7. } 1. def sr = new SVGRenderer() 2. def stream new MemoryStream() /* MemoryStream() is my handwaving for some package that lets you simulate file IO without writing to disk */ 3. sr.renderToFile( stream, 200, 200, go ) 4. def targetDoc = xwiki.getDocument("Groovy.GroovyTest4") 5. targetDoc.addAttachment("PNGGraphicsAttachment", stream.getBytes()); 6. targetDoc.save() One of the reasons one might want to use a "document" to render an image is that if the computation to render took some time, the rest of the surrounding text would appear in the browser first, rather than holding up the whole render. I imagine the current behavior, if, hypothetically, the chart macro took a long time to render a huge dataset, or a TeX equation took long to render into HTML, one could achieve a performance improvement by having the equivalent rendered separately into the browser as an image. The text surrounding any long-running macros wouldn't need to be "held up" until the macro rendered. Streaming images, or even flash, could be used to handle asynchronous updates to this "active document/image." As corollary, wouldn't it be useful to have an additional parameter on macro creation which would allow macros to run as their own document/thread, and automatically insert an iframe for the "subdocument" if the output is HTML/rendered-wikitext, and an image if the output is GIF/JPG/PNG ? Niels http://nielsmayer.com PS: are there any "snippet" or coding examples of outputting "computed images" from Xwiki via groovy?
participants (4)
-
Cristina Scheau -
Niels Mayer -
Thomas Mortagne -
Vincent Massol