[Template ODT] NewLine

846 views
Skip to first unread message

JMD

unread,
Dec 28, 2009, 11:03:25 AM12/28/09
to jOpenDocument
Hi !

Thanks for helping me !
I'm french, and that would explain the number of english errors in
this little text :D

I'm trying to edit a template like the "test.odt".

I'm building a ArrayList to make a OOo list. It's working, but the
char "newline" (\n\r or \r\n I never know...) don't create a newline
in the output ODT.
I check the "content.xml" file in the output file, and the newline
char isn't replaced by a tag for end+begin of the line...

Quote content.xml :
<text:list-item><text:p text:style-name="P1"><text:span
text:description="item.getContent()">Line1
Line2
Line3</text:span></text:p></text:list-item>

How can I make a new line ?

Thanks for all !

JMD

J David Eisenberg

unread,
Dec 28, 2009, 12:22:15 PM12/28/09
to jopend...@googlegroups.com

XML "normalizes" whitespace, so putting in a \r or \n won't help. You
need to add a <text:line-break> element.

See http://books.evc-cit.info/odbook/ch03.html#whitespace-section

JMD

unread,
Dec 28, 2009, 4:04:06 PM12/28/09
to jOpenDocument
And how do I add this element ?
I tried :
List<Step> steps = new ArrayList<Step>();
Iterator<Step> iter = recette.getSteps().iterator();
while(iter.hasNext()) {
Step myStep = iter.next();
myStep.setContent(myStep.getContent().replaceAll("\n", "<text:line-
break>"));
steps.add(myStep);
}
template.setField("steps", steps);

And in my ODT, I have "<text:line-break>" and not a new line :(

Thanks !

On 28 déc, 18:22, J David Eisenberg <jdavid.eisenb...@gmail.com>
wrote:


> On Mon, Dec 28, 2009 at 8:03 AM, JMD <jeanmatthie...@gmail.com> wrote:
> > Hi !
>
> > Thanks for helping me !
> > I'm french, and that would explain the number of english errors in
> > this little text :D
>
> > I'm trying to edit a template like the "test.odt".
>
> > I'm building a ArrayList to make a OOo list. It's working, but the
> > char "newline" (\n\r or \r\n I never know...) don't create a newline
> > in the output ODT.
> > I check the "content.xml" file in the output file, and the newline
> > char isn't replaced by a tag for end+begin of the line...
>
> > Quote content.xml :
> > <text:list-item><text:p text:style-name="P1"><text:span
> > text:description="item.getContent()">Line1
> > Line2
> > Line3</text:span></text:p></text:list-item>
>
> > How can I make a new line ?
>
> XML "normalizes" whitespace, so putting in a \r or \n won't help. You
> need to add a <text:line-break> element.
>

> Seehttp://books.evc-cit.info/odbook/ch03.html#whitespace-section

J David Eisenberg

unread,
Dec 28, 2009, 5:58:25 PM12/28/09
to jopend...@googlegroups.com
On Mon, Dec 28, 2009 at 1:04 PM, JMD <jeanmat...@gmail.com> wrote:
> And how do I add this element ?
> I tried :
> List<Step> steps = new ArrayList<Step>();
>                        Iterator<Step> iter = recette.getSteps().iterator();
>                        while(iter.hasNext()) {
>                                Step myStep = iter.next();
>                                myStep.setContent(myStep.getContent().replaceAll("\n", "<text:line-
> break>"));
>                                steps.add(myStep);
>                        }
>                        template.setField("steps", steps);
>
> And in my ODT, I have "<text:line-break>" and not a new line :(

To create true elements, don't you need to use a class like
org.jopendocument.model.text.TextLineBreak ? (I don't know; I haven't
used jOpenDocument much.) You're just putting a string into the
content; that doesn't create a real element.

JMD

unread,
Dec 28, 2009, 6:21:49 PM12/28/09
to jOpenDocument
I found it but I really don't know how to use it in the
template.setField(). Maybe i can try to modify the content.xml, but
without an example...

On 28 déc, 23:58, J David Eisenberg <jdavid.eisenb...@gmail.com>
wrote:

JMD

unread,
Dec 28, 2009, 6:26:07 PM12/28/09
to jOpenDocument
lol the class TextLineBreak is empty

JMD

unread,
Dec 28, 2009, 7:02:20 PM12/28/09
to jOpenDocument
Youuuuuhouuuuuuuuuuuuuuuuu

I look at the src, with breakpoints everywhere, and the answer is to
add "%enc:" before the expression of the label in the ODT.
For exemple, for a repeated list of items, my expression became
"%enc:m.getContent()".

Thanks for your help !

Reply all
Reply to author
Forward
0 new messages