If you want to reuse Wikistream/Filter then starting from an existing
XML does not make much sense. Indenting an XML is a pretty standard
thing using only XML APIs. You can look at what the XAR plugin is
doing at
https://github.com/xwiki/xwiki-commons/blob/master/xwiki-commons-tools/xwik….
I would not recommend using WikiStream/Filter for an extension anyway
unless you want your extension to work only starting with 6.2 or
trigger a lot of dependencies before 6.2 (all the API moved from
"wikistream" to "filter/filterstream" naming in 6.2 and also moved to
xwiki-commons).
Anyway for the record here is a solution with Filter in 6.2: from
Filter point of view it would be better to directly serialize the
document to XAR XML format. There is no real public API that takes
directly a XWikiDocument in input yet (not that it's really hard to
do, just did not had the use case yet) but there is one that gets a
document reference and then you can give a Writer for example to the
XAR module to get your XML:
In Java that would be something like:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@Inject
@Named(FilterStreamType.XWIKI_INSTANCE)
InputFilterStreamFactory inputFilterStreamFactory;
@Inject
@Named(FilterStreamType.XWIKI_XAR_11)
OutputFilterStreamFactory xarFilterStreamFactory;
[...]
/////////////
// Instance
DocumentInstanceInputProperties inputProperties = new
DocumentInstanceInputProperties();
// I gess you don't want any history
inputProperties.setWithJRCSRevisions(false);
inputProperties.setWithRevisions(false);
// Indicate which document you want in input
EntityReferenceSet entities = new EntityReferenceSet();
entities.includes(myDocumentReference);
inputProperties.setEntities(entities);
InputFilterStream inputFilterStream =
inputFilterStreamFactory.createInputFilterStream(inputProperties);
/////////////
// XAR
// It format by default but it's possible to disable it with setEncoding(false)
XAROutputProperties xarProperties = new XAROutputProperties();
// Set a writer as output
StringWriterOutputTarget target = new StringWriterOutputTarget();
xarProperties.setTarget(target);
OutputFilterStream outputFilterStream =
xarFilterStreamFactory.createOutputFilterStream(xarProperties);
/////////////
// Serialization
// Do the actual serialization
inputFilterStream.read(outputFilterStream.getFilter());
inputFilterStream.close();
outputFilterStream.close();
// You can use StringWriterOutputTarget#getBuffer() to access the written String
System.out.println(target.getBuffer())
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Note that it's not very hard to do all that in Velocity using the
"filter" script service (see
https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwi…).
On Sat, Sep 6, 2014 at 5:17 PM, Ludovic Dubost <ludovic(a)xwiki.com> wrote:
Hi,
I'd like to improve the GitHub app to perform the equivalent of mvn
xar:format, and I'm looking for the easiest way to do this using groovy in
an XWiki instance.
I've seen that the wikistream module is also indenting XML I think using
this code:
https://github.com/xwiki/xwiki-commons/blob/master/xwiki-commons-core/xwiki…
However I did not really understand how to use it. What I have initially is
the result of
doc.toXML()
What's the best way to do this ? Knowing that I will want to fallback to no
indenting on older XWiki versions.
Ludovic
-- <http://www.xwiki.com/>*Ludovic Dubost*
*Founder and CEO*
ludovic(a)xwiki.com
skype: ldubost
Blog:
http://blog.ludovic.orgXWiki SAS organise un petit déjeuner
<http://www.xwiki.com/lang/fr/BlogFr/PetitDejeunerXWikiOctobre2014> "retour
d'expérience client" le mardi 7 octobre 2014. Inscription gratuite
<http://info.xwiki.com/petit-dejeuner-XWiki-octobre-2014.html>.
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs
--
Thomas Mortagne