incubator-odf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian C <...@amham.net>
Subject Re: Finding all VariableField
Date Sat, 12 Oct 2013 11:10:57 GMT
Hi Torsten,

look at the way the TextExtractor in the common package works.

It uses the visitor pattern.

I wrote a similar thing to extract the styles being used in a document. It
took me a while to get my head around how it worked but it is very powerful.

Cheers,

Ian


On Sat, Oct 12, 2013 at 6:11 PM, Torsten Uhlmann <T.Uhlmann@agynamix.de>wrote:

> Got it.
>
> For the record or any other person looking this up, here's a small (Scala)
> snippet to read all variables and their default values.
> Please note that trying to do TextDocument.getVariableFieldByName always
> returns an empty field value…
>
> val container = template.getVariableContainerElement()
> val children = container.getElementsByTagName("text:user-field-decl")
> var length = children.getLength()-1
> for (i <- 0 to length) {
>   children.item(i) match {
>     case child: TextUserFieldDeclElement =>
>       println("Child Name : "+child.getTextNameAttribute())
>       println("Child Value: "+child.getOfficeStringValueAttribute())
>     case _ =>
>   }
> }
>
> Thanks,
> Torsten.
>
> Am 11.10.2013 um 18:06 schrieb Torsten Uhlmann <T.Uhlmann@agynamix.de>:
>
> > Hi,
> >
> > I'm trying to find a way in the Simple Api to iterate through all
> defined (Variable) Fields of an ODT text document.
> > I know there is the "getVariableFieldByName", but in my case I don't
> know the defined fields beforehand.
> > I want to read through all of them and replace them with a value from a
> data store.
> >
> > Sorry if there is an example or post already explaining this- didn't
> find anything.
> >
> > I'm using simple-odf 0.7-incubating.
> >
> > Thanks for your help,
> > Torsten.
>
>


-- 
Cheers,

Ian C

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message