xref: /AOO41X/main/sw/qa/complex/writer/TextPortionEnumerationTest.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package complex.writer;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
31*cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
32*cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
33*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
34*cdf0e10cSrcweir import com.sun.star.lang.XComponent;
35*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
36*cdf0e10cSrcweir import com.sun.star.lang.NoSupportException;
37*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
38*cdf0e10cSrcweir import com.sun.star.beans.XPropertySetInfo;
39*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
40*cdf0e10cSrcweir import com.sun.star.beans.Pair;
41*cdf0e10cSrcweir import com.sun.star.beans.StringPair;
42*cdf0e10cSrcweir import com.sun.star.container.XNamed;
43*cdf0e10cSrcweir import com.sun.star.container.XChild;
44*cdf0e10cSrcweir import com.sun.star.container.XIndexAccess;
45*cdf0e10cSrcweir import com.sun.star.container.XNameAccess;
46*cdf0e10cSrcweir import com.sun.star.container.XContentEnumerationAccess;
47*cdf0e10cSrcweir import com.sun.star.container.XEnumerationAccess;
48*cdf0e10cSrcweir import com.sun.star.container.XEnumeration;
49*cdf0e10cSrcweir import com.sun.star.container.NoSuchElementException;
50*cdf0e10cSrcweir import com.sun.star.frame.XStorable;
51*cdf0e10cSrcweir import com.sun.star.util.XCloseable;
52*cdf0e10cSrcweir import com.sun.star.text.XText;
53*cdf0e10cSrcweir import com.sun.star.text.XTextContent;
54*cdf0e10cSrcweir import com.sun.star.text.XTextDocument;
55*cdf0e10cSrcweir import com.sun.star.text.XTextRange;
56*cdf0e10cSrcweir import com.sun.star.text.XTextCursor;
57*cdf0e10cSrcweir import com.sun.star.text.XWordCursor;
58*cdf0e10cSrcweir import com.sun.star.text.XSentenceCursor;
59*cdf0e10cSrcweir import com.sun.star.text.XParagraphCursor;
60*cdf0e10cSrcweir import com.sun.star.text.XFootnote;
61*cdf0e10cSrcweir import com.sun.star.text.XTextField;
62*cdf0e10cSrcweir import com.sun.star.text.XBookmarksSupplier;
63*cdf0e10cSrcweir import com.sun.star.text.XTextSectionsSupplier;
64*cdf0e10cSrcweir import com.sun.star.text.XDocumentIndexesSupplier;
65*cdf0e10cSrcweir import com.sun.star.text.TextContentAnchorType;
66*cdf0e10cSrcweir import static com.sun.star.text.TextContentAnchorType.*;
67*cdf0e10cSrcweir import static com.sun.star.text.ControlCharacter.*;
68*cdf0e10cSrcweir import com.sun.star.rdf.XMetadatable;
69*cdf0e10cSrcweir import com.sun.star.rdf.Statement;
70*cdf0e10cSrcweir import com.sun.star.rdf.XDocumentRepository;
71*cdf0e10cSrcweir import com.sun.star.rdf.XRepositorySupplier;
72*cdf0e10cSrcweir import org.junit.After;
73*cdf0e10cSrcweir import org.junit.AfterClass;
74*cdf0e10cSrcweir import org.junit.Before;
75*cdf0e10cSrcweir import org.junit.BeforeClass;
76*cdf0e10cSrcweir import org.junit.Test;
77*cdf0e10cSrcweir import org.openoffice.test.OfficeConnection;
78*cdf0e10cSrcweir import static org.junit.Assert.*;
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir import java.util.Map;
81*cdf0e10cSrcweir import java.util.HashMap;
82*cdf0e10cSrcweir import java.util.List;
83*cdf0e10cSrcweir import java.util.ArrayList;
84*cdf0e10cSrcweir import java.util.Stack;
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir class TreeNodeEnum
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir     private Object[] m_Elements;
90*cdf0e10cSrcweir     private int m_Pos;
91*cdf0e10cSrcweir     TreeNodeEnum(Object[] Elements) { m_Elements = Elements; m_Pos = 0; }
92*cdf0e10cSrcweir     boolean hasNext() { return m_Pos < m_Elements.length; }
93*cdf0e10cSrcweir     TreeNode next() { return (TreeNode) m_Elements[m_Pos++]; }
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir /** base class for tree nodes. only instance: root of tree. */
97*cdf0e10cSrcweir class TreeNode
98*cdf0e10cSrcweir {
99*cdf0e10cSrcweir     private List<TreeNode> m_Children;
100*cdf0e10cSrcweir     String getType() { return "__ROOT__"; }
101*cdf0e10cSrcweir     boolean hasContent() { return false; }
102*cdf0e10cSrcweir     boolean isNesting() { return false; }
103*cdf0e10cSrcweir     TreeNode dup() { throw new RuntimeException("TreeNode.dup"); }
104*cdf0e10cSrcweir     TreeNodeEnum createEnumeration() {
105*cdf0e10cSrcweir         return new TreeNodeEnum(m_Children.toArray());
106*cdf0e10cSrcweir     }
107*cdf0e10cSrcweir     TreeNode() { m_Children = new ArrayList<TreeNode>(); }
108*cdf0e10cSrcweir     TreeNode appendChild(TreeNode child)
109*cdf0e10cSrcweir     { m_Children.add(child); return this; }
110*cdf0e10cSrcweir     public String toString() {
111*cdf0e10cSrcweir         return "<" + getType() + ">";
112*cdf0e10cSrcweir     }
113*cdf0e10cSrcweir }
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir abstract class MarkNode extends TreeNode
116*cdf0e10cSrcweir {
117*cdf0e10cSrcweir     boolean m_isPoint;
118*cdf0e10cSrcweir     boolean m_isStart = false;
119*cdf0e10cSrcweir     String m_Name;
120*cdf0e10cSrcweir     boolean isPoint() { return m_isPoint; }
121*cdf0e10cSrcweir     boolean isStart() { return m_isStart; }
122*cdf0e10cSrcweir     String getName() { return m_Name; }
123*cdf0e10cSrcweir     MarkNode(String name) { m_Name = name; m_isPoint = true; }
124*cdf0e10cSrcweir     boolean equals(MarkNode other) {
125*cdf0e10cSrcweir         return (other.m_Name.equals(m_Name)) && (other.m_isPoint == m_isPoint)
126*cdf0e10cSrcweir             && (other.m_isStart == m_isStart);
127*cdf0e10cSrcweir     }
128*cdf0e10cSrcweir     public String toString() {
129*cdf0e10cSrcweir         return super.toString() + "\tname: " + m_Name +
130*cdf0e10cSrcweir             "\tisPoint: " + m_isPoint + "\tisStart: " + m_isStart;
131*cdf0e10cSrcweir     }
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir class BookmarkNode extends MarkNode
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir     private StringPair m_XmlId;
137*cdf0e10cSrcweir     StringPair getXmlId() { return m_XmlId; }
138*cdf0e10cSrcweir     BookmarkNode dup() { return new BookmarkNode(getName(), getXmlId()); }
139*cdf0e10cSrcweir     BookmarkNode(String name) { this(name, new StringPair());  }
140*cdf0e10cSrcweir     BookmarkNode(String name, StringPair xmlid) {
141*cdf0e10cSrcweir         super(name); m_XmlId = xmlid;
142*cdf0e10cSrcweir     }
143*cdf0e10cSrcweir     String getType() { return "Bookmark"; }
144*cdf0e10cSrcweir     public boolean equals(Object other) {
145*cdf0e10cSrcweir         return (other instanceof BookmarkNode)
146*cdf0e10cSrcweir             && super.equals((MarkNode) other)
147*cdf0e10cSrcweir             && MetaNode.eq(((BookmarkNode) other).m_XmlId, m_XmlId);
148*cdf0e10cSrcweir     }
149*cdf0e10cSrcweir     public String toString() {
150*cdf0e10cSrcweir         return super.toString()
151*cdf0e10cSrcweir             + "\txmlid: " + m_XmlId.First + "#" + m_XmlId.Second;
152*cdf0e10cSrcweir     }
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir class BookmarkStartNode extends BookmarkNode
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir     BookmarkStartNode dup() { return new BookmarkStartNode(getName()); }
158*cdf0e10cSrcweir     BookmarkStartNode(String name) { this(name, new StringPair()); }
159*cdf0e10cSrcweir     BookmarkStartNode(String name, StringPair xmlid) {
160*cdf0e10cSrcweir         super(name, xmlid); m_isPoint = false; m_isStart = true;
161*cdf0e10cSrcweir     }
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir class BookmarkEndNode extends BookmarkNode
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir     BookmarkEndNode dup() { return new BookmarkEndNode(getName()); }
167*cdf0e10cSrcweir     BookmarkEndNode(String name) { this(name, new StringPair()); }
168*cdf0e10cSrcweir     BookmarkEndNode(String name, StringPair xmlid) {
169*cdf0e10cSrcweir         super(name, xmlid); m_isPoint = false; m_isStart = false;
170*cdf0e10cSrcweir     }
171*cdf0e10cSrcweir }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir class ReferenceMarkNode extends MarkNode
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir     ReferenceMarkNode dup() { return new ReferenceMarkNode(getName()); }
176*cdf0e10cSrcweir     ReferenceMarkNode(String name) { super(name); }
177*cdf0e10cSrcweir     String getType() { return "ReferenceMark"; }
178*cdf0e10cSrcweir     public boolean equals(Object other) {
179*cdf0e10cSrcweir         return (other instanceof ReferenceMarkNode)
180*cdf0e10cSrcweir             && super.equals((MarkNode) other);
181*cdf0e10cSrcweir     }
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir class ReferenceMarkStartNode extends ReferenceMarkNode
185*cdf0e10cSrcweir {
186*cdf0e10cSrcweir     ReferenceMarkStartNode dup()
187*cdf0e10cSrcweir     { return new ReferenceMarkStartNode(getName()); }
188*cdf0e10cSrcweir     ReferenceMarkStartNode(String name) {
189*cdf0e10cSrcweir         super(name); m_isPoint = false; m_isStart = true;
190*cdf0e10cSrcweir     }
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir class ReferenceMarkEndNode extends ReferenceMarkNode
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir     ReferenceMarkEndNode dup()
196*cdf0e10cSrcweir     { return new ReferenceMarkEndNode(getName()); }
197*cdf0e10cSrcweir     ReferenceMarkEndNode(String name) {
198*cdf0e10cSrcweir         super(name); m_isPoint = false; m_isStart = false;
199*cdf0e10cSrcweir     }
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir class DocumentIndexMarkNode extends MarkNode
203*cdf0e10cSrcweir {
204*cdf0e10cSrcweir     DocumentIndexMarkNode dup()
205*cdf0e10cSrcweir     { return new DocumentIndexMarkNode(getName()); }
206*cdf0e10cSrcweir     DocumentIndexMarkNode(String name) { super(name); }
207*cdf0e10cSrcweir     String getType() { return "DocumentIndexMark"; }
208*cdf0e10cSrcweir     public boolean equals(Object other) {
209*cdf0e10cSrcweir         return (other instanceof DocumentIndexMarkNode)
210*cdf0e10cSrcweir             && super.equals((MarkNode) other);
211*cdf0e10cSrcweir     }
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir class DocumentIndexMarkStartNode extends DocumentIndexMarkNode
215*cdf0e10cSrcweir {
216*cdf0e10cSrcweir     DocumentIndexMarkStartNode dup()
217*cdf0e10cSrcweir     { return new DocumentIndexMarkStartNode(getName()); }
218*cdf0e10cSrcweir     DocumentIndexMarkStartNode(String name) {
219*cdf0e10cSrcweir         super(name); m_isPoint = false; m_isStart = true;
220*cdf0e10cSrcweir     }
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir class DocumentIndexMarkEndNode extends DocumentIndexMarkNode
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir     DocumentIndexMarkEndNode dup()
226*cdf0e10cSrcweir     { return new DocumentIndexMarkEndNode(getName()); }
227*cdf0e10cSrcweir     DocumentIndexMarkEndNode(String name) {
228*cdf0e10cSrcweir         super(name); m_isPoint = false; m_isStart = false;
229*cdf0e10cSrcweir     }
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir abstract class ContentNode extends TreeNode
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir     private String m_Content;
235*cdf0e10cSrcweir     String getContent() { return m_Content; }
236*cdf0e10cSrcweir     boolean hasContent() { return true; }
237*cdf0e10cSrcweir     ContentNode(String content) {
238*cdf0e10cSrcweir         m_Content = content;
239*cdf0e10cSrcweir     }
240*cdf0e10cSrcweir     TreeNode appendChild(TreeNode t) {
241*cdf0e10cSrcweir         throw new RuntimeException("ContentNode.appendChild");
242*cdf0e10cSrcweir     }
243*cdf0e10cSrcweir     public String toString() {
244*cdf0e10cSrcweir         return super.toString() + "\tcontent: " + m_Content;
245*cdf0e10cSrcweir     }
246*cdf0e10cSrcweir     boolean equals(ContentNode other) {
247*cdf0e10cSrcweir         return (other.m_Content.equals(m_Content));
248*cdf0e10cSrcweir     }
249*cdf0e10cSrcweir }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir class TextNode extends ContentNode
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir     TextNode dup() { return new TextNode(getContent()); }
254*cdf0e10cSrcweir     TextNode(String content) { super(content); }
255*cdf0e10cSrcweir     String getType() { return "Text"; }
256*cdf0e10cSrcweir     public boolean equals(Object other) {
257*cdf0e10cSrcweir         return (other instanceof TextNode) && super.equals((ContentNode) other);
258*cdf0e10cSrcweir     }
259*cdf0e10cSrcweir }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir class TextFieldNode extends ContentNode
262*cdf0e10cSrcweir {
263*cdf0e10cSrcweir     TextFieldNode dup() { return new TextFieldNode(getContent()); }
264*cdf0e10cSrcweir     TextFieldNode(String content) { super(content); }
265*cdf0e10cSrcweir     String getType() { return "TextField"; }
266*cdf0e10cSrcweir     public boolean equals(Object other) {
267*cdf0e10cSrcweir         return (other instanceof TextFieldNode)
268*cdf0e10cSrcweir             && super.equals((ContentNode) other);
269*cdf0e10cSrcweir     }
270*cdf0e10cSrcweir }
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir class FrameNode extends TreeNode
273*cdf0e10cSrcweir {
274*cdf0e10cSrcweir     private String m_Name;
275*cdf0e10cSrcweir     private TextContentAnchorType m_Anchor;
276*cdf0e10cSrcweir     String getName() { return m_Name; }
277*cdf0e10cSrcweir     TextContentAnchorType getAnchor() { return m_Anchor; }
278*cdf0e10cSrcweir     FrameNode dup() { return new FrameNode(getName(), getAnchor()); }
279*cdf0e10cSrcweir     FrameNode(String name, TextContentAnchorType anchor) {
280*cdf0e10cSrcweir         m_Name = name; m_Anchor = anchor;
281*cdf0e10cSrcweir     }
282*cdf0e10cSrcweir     String getType() { return "Frame"; }
283*cdf0e10cSrcweir     public boolean equals(Object other) {
284*cdf0e10cSrcweir         return (other instanceof FrameNode)
285*cdf0e10cSrcweir             && (((FrameNode) other).m_Name.equals(m_Name))
286*cdf0e10cSrcweir             && (((FrameNode) other).m_Anchor == m_Anchor);
287*cdf0e10cSrcweir     }
288*cdf0e10cSrcweir     public String toString() {
289*cdf0e10cSrcweir         return super.toString()
290*cdf0e10cSrcweir             + "\tname: " + m_Name + "\tanchor: " + toString(m_Anchor);
291*cdf0e10cSrcweir     }
292*cdf0e10cSrcweir     static String toString(TextContentAnchorType anchor) {
293*cdf0e10cSrcweir         switch (anchor.getValue()) {
294*cdf0e10cSrcweir             case AS_CHARACTER_value: return "AS_CHARACTER";
295*cdf0e10cSrcweir             case AT_CHARACTER_value: return "AT_CHARACTER";
296*cdf0e10cSrcweir             case AT_PARAGRAPH_value: return "AT_PARAGRAPH";
297*cdf0e10cSrcweir             case AT_PAGE_value:      return "AT_PAGE";
298*cdf0e10cSrcweir             case AT_FRAME_value:     return "AT_FRAME";
299*cdf0e10cSrcweir             default: throw new RuntimeException("unknown anchor");
300*cdf0e10cSrcweir         }
301*cdf0e10cSrcweir     }
302*cdf0e10cSrcweir }
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir class FootnoteNode extends TreeNode
305*cdf0e10cSrcweir {
306*cdf0e10cSrcweir     private String m_Label;
307*cdf0e10cSrcweir     String getLabel() { return m_Label; }
308*cdf0e10cSrcweir     FootnoteNode dup() { return new FootnoteNode(getLabel()); }
309*cdf0e10cSrcweir     FootnoteNode(String label) { m_Label = label; }
310*cdf0e10cSrcweir     String getType() { return "Footnote"; }
311*cdf0e10cSrcweir     public boolean equals(Object other) {
312*cdf0e10cSrcweir         return (other instanceof FootnoteNode)
313*cdf0e10cSrcweir             && (((FootnoteNode) other).m_Label.equals(m_Label));
314*cdf0e10cSrcweir     }
315*cdf0e10cSrcweir     public String toString() {
316*cdf0e10cSrcweir         return super.toString() + "\tlabel: " + m_Label;
317*cdf0e10cSrcweir     }
318*cdf0e10cSrcweir }
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir class ControlCharacterNode extends TreeNode
321*cdf0e10cSrcweir {
322*cdf0e10cSrcweir     private short m_Char;
323*cdf0e10cSrcweir     short getChar() { return m_Char; }
324*cdf0e10cSrcweir     ControlCharacterNode dup() { return new ControlCharacterNode(getChar()); }
325*cdf0e10cSrcweir     ControlCharacterNode(short c) { m_Char = c; }
326*cdf0e10cSrcweir     String getType() { return "ControlCharacter"; }
327*cdf0e10cSrcweir     public boolean equals(Object other) {
328*cdf0e10cSrcweir         return (other instanceof ControlCharacterNode)
329*cdf0e10cSrcweir             && (((ControlCharacterNode) other).m_Char == m_Char);
330*cdf0e10cSrcweir     }
331*cdf0e10cSrcweir     public String toString() {
332*cdf0e10cSrcweir         return super.toString() + "\tchar: " + m_Char;
333*cdf0e10cSrcweir     }
334*cdf0e10cSrcweir }
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir class SoftPageBreakNode extends TreeNode
337*cdf0e10cSrcweir {
338*cdf0e10cSrcweir     String getType() { return "SoftPageBreak"; }
339*cdf0e10cSrcweir     public boolean equals(Object other) {
340*cdf0e10cSrcweir         return (other instanceof SoftPageBreakNode);
341*cdf0e10cSrcweir     }
342*cdf0e10cSrcweir }
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir class HyperlinkNode extends TreeNode
345*cdf0e10cSrcweir {
346*cdf0e10cSrcweir     private String m_URL;
347*cdf0e10cSrcweir     String getURL() { return m_URL; }
348*cdf0e10cSrcweir     HyperlinkNode dup() { return new HyperlinkNode(getURL()); }
349*cdf0e10cSrcweir     HyperlinkNode(String url) {
350*cdf0e10cSrcweir         if (url.length() == 0) throw new RuntimeException("HyperlinkNode");
351*cdf0e10cSrcweir         m_URL = url;
352*cdf0e10cSrcweir     }
353*cdf0e10cSrcweir     String getType() { return "Hyperlink"; }
354*cdf0e10cSrcweir     boolean isNesting() { return true; }
355*cdf0e10cSrcweir     public boolean equals(Object other) {
356*cdf0e10cSrcweir         return (other instanceof HyperlinkNode)
357*cdf0e10cSrcweir             && (((HyperlinkNode) other).m_URL.equals(m_URL));
358*cdf0e10cSrcweir     }
359*cdf0e10cSrcweir     public String toString() {
360*cdf0e10cSrcweir         return super.toString() + "\turl: " + m_URL;
361*cdf0e10cSrcweir     }
362*cdf0e10cSrcweir }
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir class RubyNode extends TreeNode
365*cdf0e10cSrcweir {
366*cdf0e10cSrcweir     private String m_Ruby;
367*cdf0e10cSrcweir     String getRubyText() { return m_Ruby; }
368*cdf0e10cSrcweir     RubyNode dup() { return new RubyNode(getRubyText()); }
369*cdf0e10cSrcweir     RubyNode(String ruby) {
370*cdf0e10cSrcweir         if (ruby.length() == 0) throw new RuntimeException("RubyNode");
371*cdf0e10cSrcweir         m_Ruby = ruby;
372*cdf0e10cSrcweir     }
373*cdf0e10cSrcweir     String getType() { return "Ruby"; }
374*cdf0e10cSrcweir     boolean isNesting() { return true; }
375*cdf0e10cSrcweir     public boolean equals(Object other) {
376*cdf0e10cSrcweir         return (other instanceof RubyNode)
377*cdf0e10cSrcweir             && (((RubyNode) other).m_Ruby.equals(m_Ruby));
378*cdf0e10cSrcweir     }
379*cdf0e10cSrcweir     public String toString() {
380*cdf0e10cSrcweir         return super.toString() + "\trubytext: " + m_Ruby;
381*cdf0e10cSrcweir     }
382*cdf0e10cSrcweir }
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir class MetaNode extends TreeNode
385*cdf0e10cSrcweir {
386*cdf0e10cSrcweir     private StringPair m_XmlId;
387*cdf0e10cSrcweir     StringPair getXmlId() { return m_XmlId; }
388*cdf0e10cSrcweir     MetaNode dup() { return new MetaNode(getXmlId()); }
389*cdf0e10cSrcweir     MetaNode (StringPair xmlid) { m_XmlId = xmlid; }
390*cdf0e10cSrcweir     String getType() { return "InContentMetadata"; }
391*cdf0e10cSrcweir     boolean isNesting() { return true; }
392*cdf0e10cSrcweir     public boolean equals(Object other) {
393*cdf0e10cSrcweir         return (other instanceof MetaNode)
394*cdf0e10cSrcweir             && eq(((MetaNode) other).m_XmlId, m_XmlId);
395*cdf0e10cSrcweir     }
396*cdf0e10cSrcweir     static boolean eq(StringPair left, StringPair right)
397*cdf0e10cSrcweir     {
398*cdf0e10cSrcweir         return left.First.equals(right.First)
399*cdf0e10cSrcweir             && left.Second.equals(right.Second);
400*cdf0e10cSrcweir     }
401*cdf0e10cSrcweir     public String toString() {
402*cdf0e10cSrcweir         return super.toString()
403*cdf0e10cSrcweir             + "\txmlid: " + m_XmlId.First + "#" + m_XmlId.Second;
404*cdf0e10cSrcweir     }
405*cdf0e10cSrcweir }
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir class MetaFieldNode extends MetaNode
408*cdf0e10cSrcweir {
409*cdf0e10cSrcweir     MetaFieldNode dup() { return new MetaFieldNode(getXmlId()); }
410*cdf0e10cSrcweir     MetaFieldNode (StringPair xmlid) { super(xmlid); }
411*cdf0e10cSrcweir     String getType() { return "MetadataField"; }
412*cdf0e10cSrcweir }
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir class Range
415*cdf0e10cSrcweir {
416*cdf0e10cSrcweir     private short m_Start;
417*cdf0e10cSrcweir     private short m_End;
418*cdf0e10cSrcweir     private TreeNode m_Node;
419*cdf0e10cSrcweir     short getStart()    { return m_Start; }
420*cdf0e10cSrcweir     short getEnd()      { return m_End  ; }
421*cdf0e10cSrcweir     short getExtent()   { return (short) (m_End - m_Start); }
422*cdf0e10cSrcweir     TreeNode getNode()  { return m_Node; }
423*cdf0e10cSrcweir     Range(int start, int end, TreeNode node)
424*cdf0e10cSrcweir     { m_Start = (short) start; m_End = (short) end; m_Node = node; }
425*cdf0e10cSrcweir }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir //----------------------------------------------------------------------
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir /* this is where we nail the pudding to the wall */
430*cdf0e10cSrcweir class FuzzyTester
431*cdf0e10cSrcweir {
432*cdf0e10cSrcweir     private long m_DiffContent = 0;
433*cdf0e10cSrcweir     private long m_DiffMissing = 0;
434*cdf0e10cSrcweir     private long m_DiffNesting = 0;
435*cdf0e10cSrcweir     private long m_DiffSpuriousEmptyText = 0;
436*cdf0e10cSrcweir     private long m_DiffSequence = 0; // ignored?
437*cdf0e10cSrcweir     private Stack<Pair<TreeNode, TreeNodeEnum>> m_StackExpected;
438*cdf0e10cSrcweir     private Stack<Pair<TreeNode, TreeNodeEnum>> m_StackActual;
439*cdf0e10cSrcweir     private List<TreeNode> m_BufferExpected;
440*cdf0e10cSrcweir     private List<TreeNode> m_BufferActual;
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir     FuzzyTester() {
443*cdf0e10cSrcweir         m_BufferExpected = new ArrayList<TreeNode>();
444*cdf0e10cSrcweir         m_BufferActual = new ArrayList<TreeNode>();
445*cdf0e10cSrcweir         m_StackExpected = new Stack<Pair<TreeNode, TreeNodeEnum>>();
446*cdf0e10cSrcweir         m_StackActual = new Stack<Pair<TreeNode, TreeNodeEnum>>();
447*cdf0e10cSrcweir     }
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir     /** idea: traverse both trees, enumerate nodes, stopping at content nodes.
450*cdf0e10cSrcweir         then compare buffers. */
451*cdf0e10cSrcweir     void doTest(TreeNode expected, TreeNode actual)
452*cdf0e10cSrcweir     {
453*cdf0e10cSrcweir         assertEquals("__ROOT__", expected.getType());
454*cdf0e10cSrcweir         assertEquals("__ROOT__", actual.getType());
455*cdf0e10cSrcweir         m_StackExpected.push(new Pair(expected, expected.createEnumeration()));
456*cdf0e10cSrcweir         m_StackActual.push(new Pair(actual, actual.createEnumeration()));
457*cdf0e10cSrcweir         do {
458*cdf0e10cSrcweir             traverse(m_StackExpected, m_BufferExpected);
459*cdf0e10cSrcweir             traverse(m_StackActual, m_BufferActual);
460*cdf0e10cSrcweir         //??? root?
461*cdf0e10cSrcweir             testBuffer();
462*cdf0e10cSrcweir         } while (!m_StackExpected.empty() || !m_StackActual.empty());
463*cdf0e10cSrcweir         if (m_DiffSequence != 0) {
464*cdf0e10cSrcweir             System.out.println("warning: " +  m_DiffSequence
465*cdf0e10cSrcweir                     + " differences in sequence");
466*cdf0e10cSrcweir         }
467*cdf0e10cSrcweir         if (m_DiffSpuriousEmptyText != 0) {
468*cdf0e10cSrcweir             System.out.println("warning: " +  m_DiffSpuriousEmptyText
469*cdf0e10cSrcweir                     + " spurious empty text nodes");
470*cdf0e10cSrcweir         }
471*cdf0e10cSrcweir         if (m_DiffNesting != 0) {
472*cdf0e10cSrcweir             System.out.println("WARNING: " +  m_DiffNesting
473*cdf0e10cSrcweir                     + " differences in nesting");
474*cdf0e10cSrcweir         }
475*cdf0e10cSrcweir         assertEquals(0, m_DiffContent);
476*cdf0e10cSrcweir         assertEquals(0, m_DiffMissing);
477*cdf0e10cSrcweir     }
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir     private void traverse(Stack<Pair<TreeNode, TreeNodeEnum>> stack,
480*cdf0e10cSrcweir                   List<TreeNode> buffer)
481*cdf0e10cSrcweir     {
482*cdf0e10cSrcweir         while (!stack.empty()) {
483*cdf0e10cSrcweir             TreeNodeEnum topEnum = stack.peek().Second;
484*cdf0e10cSrcweir             if (topEnum.hasNext()) {
485*cdf0e10cSrcweir                 TreeNode node = topEnum.next();
486*cdf0e10cSrcweir                 buffer.add(node);
487*cdf0e10cSrcweir                 TreeNodeEnum nodeEnum = node.createEnumeration();
488*cdf0e10cSrcweir                 if (nodeEnum.hasNext()) {
489*cdf0e10cSrcweir                     stack.push(new Pair(node, nodeEnum));
490*cdf0e10cSrcweir                 }
491*cdf0e10cSrcweir                 if (node.hasContent()) {
492*cdf0e10cSrcweir                     if (!((node instanceof TextNode) // spurious empty text?
493*cdf0e10cSrcweir                         && ((TextNode) node).getContent().length() == 0)) {
494*cdf0e10cSrcweir                             return; // break here
495*cdf0e10cSrcweir                     }
496*cdf0e10cSrcweir                 }
497*cdf0e10cSrcweir             } else {
498*cdf0e10cSrcweir                 buffer.add(stack.peek().First);
499*cdf0e10cSrcweir                 stack.pop();
500*cdf0e10cSrcweir             }
501*cdf0e10cSrcweir         }
502*cdf0e10cSrcweir     }
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir     private void testTerminatingNode()
505*cdf0e10cSrcweir     {
506*cdf0e10cSrcweir         int lenExpected = m_BufferExpected.size();
507*cdf0e10cSrcweir         int lenActual   = m_BufferActual.size();
508*cdf0e10cSrcweir         if (lenExpected == 0 || lenActual == 0)
509*cdf0e10cSrcweir             return;
510*cdf0e10cSrcweir         TreeNode expected = m_BufferExpected.get(lenExpected - 1);
511*cdf0e10cSrcweir         TreeNode actual = m_BufferActual.get(lenActual - 1);
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir         boolean eRoot = expected.getType().equals("__ROOT__");
514*cdf0e10cSrcweir         boolean aRoot = actual.getType().equals("__ROOT__");
515*cdf0e10cSrcweir         if (eRoot || aRoot) {
516*cdf0e10cSrcweir             if (!(eRoot && aRoot)) {
517*cdf0e10cSrcweir                 if (aRoot) printMissing(expected);
518*cdf0e10cSrcweir                 else       printUnexpected(actual);
519*cdf0e10cSrcweir                 m_DiffMissing++;
520*cdf0e10cSrcweir             }
521*cdf0e10cSrcweir             return;
522*cdf0e10cSrcweir         }
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir         testContentNode((ContentNode) expected, (ContentNode) actual);
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir         m_BufferExpected.set(lenExpected - 1, null);
527*cdf0e10cSrcweir         m_BufferActual.set(lenActual - 1, null);
528*cdf0e10cSrcweir     }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir     private void testContentNode(ContentNode expected, ContentNode actual)
531*cdf0e10cSrcweir     {
532*cdf0e10cSrcweir         String contentExpected = expected.getContent();
533*cdf0e10cSrcweir         String contentActual = actual.getContent();
534*cdf0e10cSrcweir         if (!expected.equals(actual)) {
535*cdf0e10cSrcweir             printDiff("text content differs", contentExpected, contentActual);
536*cdf0e10cSrcweir             m_DiffContent++;
537*cdf0e10cSrcweir         }
538*cdf0e10cSrcweir     }
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir     private void testBuffer()
541*cdf0e10cSrcweir     {
542*cdf0e10cSrcweir         int lenExpected = m_BufferExpected.size();
543*cdf0e10cSrcweir         int lenActual   = m_BufferActual.size();
544*cdf0e10cSrcweir         for (int i = 0; i < lenExpected - 1; i++ )
545*cdf0e10cSrcweir         {
546*cdf0e10cSrcweir             TreeNode node = m_BufferExpected.get(i);
547*cdf0e10cSrcweir             int j = m_BufferActual.indexOf(node);
548*cdf0e10cSrcweir             if (j >= 0) {
549*cdf0e10cSrcweir                 TreeNode other = m_BufferActual.get(j);
550*cdf0e10cSrcweir                 if (j != i)
551*cdf0e10cSrcweir                 {
552*cdf0e10cSrcweir                     //FIXME how bad is this?
553*cdf0e10cSrcweir                     printDiff("position differs",
554*cdf0e10cSrcweir                             String.valueOf(i), String.valueOf(j));
555*cdf0e10cSrcweir                     // a hacky hack
556*cdf0e10cSrcweir                     int min = Math.min(i,j);
557*cdf0e10cSrcweir                     int max = Math.max(Math.min(lenActual - 1, i),j);
558*cdf0e10cSrcweir                     for (int k = min; k != max; k ++) {
559*cdf0e10cSrcweir                         TreeNode tmp = m_BufferActual.get(k);
560*cdf0e10cSrcweir                         if (tmp != null && tmp.isNesting()) {
561*cdf0e10cSrcweir                             printNesting(node, tmp);
562*cdf0e10cSrcweir                             m_DiffNesting++;
563*cdf0e10cSrcweir                         }
564*cdf0e10cSrcweir                     }
565*cdf0e10cSrcweir                     m_DiffSequence++;
566*cdf0e10cSrcweir                 }
567*cdf0e10cSrcweir                 m_BufferActual.set(j, null);
568*cdf0e10cSrcweir             } else {
569*cdf0e10cSrcweir //System.out.println("testBuffer:");
570*cdf0e10cSrcweir                 printMissing(node);
571*cdf0e10cSrcweir                 m_DiffMissing++;
572*cdf0e10cSrcweir             }
573*cdf0e10cSrcweir         }
574*cdf0e10cSrcweir         for (int j = 0; j < lenActual - 1; j++)
575*cdf0e10cSrcweir         {
576*cdf0e10cSrcweir             TreeNode node = m_BufferActual.get(j);
577*cdf0e10cSrcweir             if (node != null)
578*cdf0e10cSrcweir             {
579*cdf0e10cSrcweir //System.out.println("testBuffer:");
580*cdf0e10cSrcweir                 printUnexpected(node);
581*cdf0e10cSrcweir                 if ((node instanceof TextNode) &&
582*cdf0e10cSrcweir                         ((TextNode) node).getContent().length() == 0) {
583*cdf0e10cSrcweir                     m_DiffSpuriousEmptyText++;
584*cdf0e10cSrcweir                 } else {
585*cdf0e10cSrcweir                     m_DiffMissing++;
586*cdf0e10cSrcweir                 }
587*cdf0e10cSrcweir             }
588*cdf0e10cSrcweir         }
589*cdf0e10cSrcweir         testTerminatingNode();
590*cdf0e10cSrcweir         m_BufferExpected.clear();
591*cdf0e10cSrcweir         m_BufferActual.clear();
592*cdf0e10cSrcweir     }
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir     void printDiff(String prefix, String expected, String actual)
595*cdf0e10cSrcweir     {
596*cdf0e10cSrcweir         System.out.println(prefix +
597*cdf0e10cSrcweir                 ":\texpected: " + expected + "\tactual: " + actual);
598*cdf0e10cSrcweir     }
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir     void printNesting(TreeNode node, TreeNode nesting)
601*cdf0e10cSrcweir     {
602*cdf0e10cSrcweir         System.out.println("node: " + node.toString()
603*cdf0e10cSrcweir                 + " possibly moved across nesting " + nesting.toString());
604*cdf0e10cSrcweir     }
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir     void printMissing(TreeNode node)
607*cdf0e10cSrcweir     {
608*cdf0e10cSrcweir         System.out.println("   missing node: " + node.toString());
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir     }
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir     void printUnexpected(TreeNode node)
613*cdf0e10cSrcweir     {
614*cdf0e10cSrcweir         System.out.println("unexpected node: " + node.toString());
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir     }
617*cdf0e10cSrcweir }
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir //----------------------------------------------------------------------
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir class EnumConverter
623*cdf0e10cSrcweir {
624*cdf0e10cSrcweir     private Stack<TreeNode> m_Stack;
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir     EnumConverter() {
627*cdf0e10cSrcweir         m_Stack = new Stack<TreeNode>();
628*cdf0e10cSrcweir     }
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir     TreeNode convert(XEnumeration xEnum) throws Exception
631*cdf0e10cSrcweir     {
632*cdf0e10cSrcweir         TreeNode root = new TreeNode();
633*cdf0e10cSrcweir         m_Stack.push(root);
634*cdf0e10cSrcweir         TreeNode ret = convertChildren(xEnum);
635*cdf0e10cSrcweir         assertTrue("EnumConverter.convert: stack", m_Stack.empty());
636*cdf0e10cSrcweir         return ret;
637*cdf0e10cSrcweir     }
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir     TreeNode convertChildren(XEnumeration xEnum) throws Exception
640*cdf0e10cSrcweir     {
641*cdf0e10cSrcweir         while (xEnum.hasMoreElements()) {
642*cdf0e10cSrcweir             TreeNode node;
643*cdf0e10cSrcweir             Object xElement = xEnum.nextElement();
644*cdf0e10cSrcweir             XTextRange xPortion = (XTextRange)
645*cdf0e10cSrcweir                 UnoRuntime.queryInterface(XTextRange.class, xElement);
646*cdf0e10cSrcweir             XPropertySet xPropSet = (XPropertySet)
647*cdf0e10cSrcweir                 UnoRuntime.queryInterface(XPropertySet.class, xPortion);
648*cdf0e10cSrcweir             String type = (String) xPropSet.getPropertyValue("TextPortionType");
649*cdf0e10cSrcweir             if (type.equals("Text")) {
650*cdf0e10cSrcweir                 String text = xPortion.getString();
651*cdf0e10cSrcweir                 node = new TextNode(text);
652*cdf0e10cSrcweir                 String url = (String) xPropSet.getPropertyValue("HyperLinkURL");
653*cdf0e10cSrcweir                 if (url.length() > 0) {
654*cdf0e10cSrcweir                     TreeNode temp = node;
655*cdf0e10cSrcweir                     node = new HyperlinkNode(url);
656*cdf0e10cSrcweir                     node.appendChild(temp);
657*cdf0e10cSrcweir                 }
658*cdf0e10cSrcweir             } else if (type.equals("TextField")) {
659*cdf0e10cSrcweir                 Object xField = xPropSet.getPropertyValue("TextField");
660*cdf0e10cSrcweir                 XServiceInfo xService = (XServiceInfo)
661*cdf0e10cSrcweir                     UnoRuntime.queryInterface(XServiceInfo.class, xField);
662*cdf0e10cSrcweir                 if (xService.supportsService(
663*cdf0e10cSrcweir                         "com.sun.star.text.textfield.MetadataField"))
664*cdf0e10cSrcweir                 {
665*cdf0e10cSrcweir                     XMetadatable xMeta = (XMetadatable)
666*cdf0e10cSrcweir                         UnoRuntime.queryInterface(XMetadatable.class, xField);
667*cdf0e10cSrcweir                     StringPair xmlid = xMeta.getMetadataReference();
668*cdf0e10cSrcweir                     node = new MetaFieldNode(xmlid);
669*cdf0e10cSrcweir                     m_Stack.push(node);
670*cdf0e10cSrcweir                     XEnumerationAccess xEA = (XEnumerationAccess)
671*cdf0e10cSrcweir                         UnoRuntime.queryInterface(XEnumerationAccess.class,
672*cdf0e10cSrcweir                         xMeta);
673*cdf0e10cSrcweir                     XEnumeration xEnumChildren = xEA.createEnumeration();
674*cdf0e10cSrcweir                     TreeNode node2 = convertChildren(xEnumChildren);
675*cdf0e10cSrcweir                     assertSame("stack error: meta-field", node2, node);
676*cdf0e10cSrcweir                 } else {
677*cdf0e10cSrcweir                     XPropertySet xFieldPropSet = (XPropertySet)
678*cdf0e10cSrcweir                         UnoRuntime.queryInterface(XPropertySet.class, xField);
679*cdf0e10cSrcweir                     String content = (String)
680*cdf0e10cSrcweir                         xFieldPropSet.getPropertyValue("Content");
681*cdf0e10cSrcweir                     boolean isFixed = (Boolean)
682*cdf0e10cSrcweir                         xFieldPropSet.getPropertyValue("IsFixed");
683*cdf0e10cSrcweir                     assertTrue("field not fixed?", isFixed);
684*cdf0e10cSrcweir                     node = new TextFieldNode(content);
685*cdf0e10cSrcweir                 }
686*cdf0e10cSrcweir             } else if (type.equals("Footnote")) {
687*cdf0e10cSrcweir                 Object xNote = xPropSet.getPropertyValue("Footnote");
688*cdf0e10cSrcweir                 XFootnote xFootnote = (XFootnote)
689*cdf0e10cSrcweir                     UnoRuntime.queryInterface(XFootnote.class, xNote);
690*cdf0e10cSrcweir                 String label = xFootnote.getLabel();
691*cdf0e10cSrcweir                 node = new FootnoteNode(label);
692*cdf0e10cSrcweir             } else if (type.equals("Frame")) {
693*cdf0e10cSrcweir                 XContentEnumerationAccess xCEA = (XContentEnumerationAccess)
694*cdf0e10cSrcweir                     UnoRuntime.queryInterface(XContentEnumerationAccess.class,
695*cdf0e10cSrcweir                         xPortion);
696*cdf0e10cSrcweir                 XEnumeration xContentEnum = xCEA.createContentEnumeration("");
697*cdf0e10cSrcweir                 while (xContentEnum.hasMoreElements()) {
698*cdf0e10cSrcweir                     Object xFrame = xContentEnum.nextElement();
699*cdf0e10cSrcweir                     XPropertySet xFramePropSet = (XPropertySet)
700*cdf0e10cSrcweir                         UnoRuntime.queryInterface(XPropertySet.class, xFrame);
701*cdf0e10cSrcweir                     TextContentAnchorType anchor = (TextContentAnchorType)
702*cdf0e10cSrcweir                         xFramePropSet.getPropertyValue("AnchorType");
703*cdf0e10cSrcweir                     XNamed xNamed = (XNamed)
704*cdf0e10cSrcweir                         UnoRuntime.queryInterface(XNamed.class, xFrame);
705*cdf0e10cSrcweir                     String name = xNamed.getName();
706*cdf0e10cSrcweir                     node = new FrameNode(name, anchor);
707*cdf0e10cSrcweir                     m_Stack.peek().appendChild(node);
708*cdf0e10cSrcweir                 }
709*cdf0e10cSrcweir                 continue;
710*cdf0e10cSrcweir             } else if (type.equals("ControlCharacter")) {
711*cdf0e10cSrcweir                 short c = (Short)
712*cdf0e10cSrcweir                     xPropSet.getPropertyValue("ControlCharacter");
713*cdf0e10cSrcweir                 node = new ControlCharacterNode(c);
714*cdf0e10cSrcweir             } else if (type.equals("Bookmark")) {
715*cdf0e10cSrcweir                 Object xMark = xPropSet.getPropertyValue("Bookmark");
716*cdf0e10cSrcweir                 XNamed xNamed = (XNamed)
717*cdf0e10cSrcweir                     UnoRuntime.queryInterface(XNamed.class, xMark);
718*cdf0e10cSrcweir                 String name = xNamed.getName();
719*cdf0e10cSrcweir                 XMetadatable xMetadatable = (XMetadatable)
720*cdf0e10cSrcweir                     UnoRuntime.queryInterface(XMetadatable.class, xMark);
721*cdf0e10cSrcweir                 StringPair xmlid = xMetadatable.getMetadataReference();
722*cdf0e10cSrcweir                 boolean isCollapsed = (Boolean)
723*cdf0e10cSrcweir                     xPropSet.getPropertyValue("IsCollapsed");
724*cdf0e10cSrcweir                 if (isCollapsed) {
725*cdf0e10cSrcweir                     node = new BookmarkNode(name, xmlid);
726*cdf0e10cSrcweir                 } else {
727*cdf0e10cSrcweir                     boolean isStart = (Boolean)
728*cdf0e10cSrcweir                         xPropSet.getPropertyValue("IsStart");
729*cdf0e10cSrcweir                     if (isStart) {
730*cdf0e10cSrcweir                         node = new BookmarkStartNode(name, xmlid);
731*cdf0e10cSrcweir                     } else {
732*cdf0e10cSrcweir                         node = new BookmarkEndNode(name, xmlid);
733*cdf0e10cSrcweir                     }
734*cdf0e10cSrcweir                 }
735*cdf0e10cSrcweir             } else if (type.equals("ReferenceMark")) {
736*cdf0e10cSrcweir                 Object xMark = xPropSet.getPropertyValue("ReferenceMark");
737*cdf0e10cSrcweir                 XNamed xNamed = (XNamed)
738*cdf0e10cSrcweir                     UnoRuntime.queryInterface(XNamed.class, xMark);
739*cdf0e10cSrcweir                 String name = xNamed.getName();
740*cdf0e10cSrcweir                 boolean isCollapsed = (Boolean)
741*cdf0e10cSrcweir                     xPropSet.getPropertyValue("IsCollapsed");
742*cdf0e10cSrcweir                 if (isCollapsed) {
743*cdf0e10cSrcweir                     node = new ReferenceMarkNode(name);
744*cdf0e10cSrcweir                 } else {
745*cdf0e10cSrcweir                     boolean isStart = (Boolean)
746*cdf0e10cSrcweir                         xPropSet.getPropertyValue("IsStart");
747*cdf0e10cSrcweir                     if (isStart) {
748*cdf0e10cSrcweir                         node = new ReferenceMarkStartNode(name);
749*cdf0e10cSrcweir                     } else {
750*cdf0e10cSrcweir                         node = new ReferenceMarkEndNode(name);
751*cdf0e10cSrcweir                     }
752*cdf0e10cSrcweir                 }
753*cdf0e10cSrcweir             } else if (type.equals("DocumentIndexMark")) {
754*cdf0e10cSrcweir                 Object xMark = xPropSet.getPropertyValue("DocumentIndexMark");
755*cdf0e10cSrcweir                 XPropertySet xMarkSet = (XPropertySet)
756*cdf0e10cSrcweir                     UnoRuntime.queryInterface(XPropertySet.class, xMark);
757*cdf0e10cSrcweir                 String name = (String) xMarkSet.getPropertyValue("PrimaryKey");
758*cdf0e10cSrcweir                 boolean isCollapsed = (Boolean)
759*cdf0e10cSrcweir                     xPropSet.getPropertyValue("IsCollapsed");
760*cdf0e10cSrcweir                 if (isCollapsed) {
761*cdf0e10cSrcweir                     node = new DocumentIndexMarkNode(name);
762*cdf0e10cSrcweir                 } else {
763*cdf0e10cSrcweir                     boolean isStart = (Boolean)
764*cdf0e10cSrcweir                         xPropSet.getPropertyValue("IsStart");
765*cdf0e10cSrcweir                     if (isStart) {
766*cdf0e10cSrcweir                         node = new DocumentIndexMarkStartNode(name);
767*cdf0e10cSrcweir                     } else {
768*cdf0e10cSrcweir                         node = new DocumentIndexMarkEndNode(name);
769*cdf0e10cSrcweir                     }
770*cdf0e10cSrcweir                 }
771*cdf0e10cSrcweir             } else if (type.equals("SoftPageBreak")) {
772*cdf0e10cSrcweir                 node = new SoftPageBreakNode();
773*cdf0e10cSrcweir             } else if (type.equals("Ruby")) {
774*cdf0e10cSrcweir                 boolean isStart = (Boolean)
775*cdf0e10cSrcweir                     xPropSet.getPropertyValue("IsStart");
776*cdf0e10cSrcweir                 if (isStart) {
777*cdf0e10cSrcweir                     // ARRGH!!! stupid api...
778*cdf0e10cSrcweir                     // the text is ONLY at the start!
779*cdf0e10cSrcweir                     String ruby = (String)
780*cdf0e10cSrcweir                         xPropSet.getPropertyValue("RubyText");
781*cdf0e10cSrcweir                     node = new RubyNode(ruby);
782*cdf0e10cSrcweir                     m_Stack.push(node);
783*cdf0e10cSrcweir                     continue;
784*cdf0e10cSrcweir                 } else {
785*cdf0e10cSrcweir                     node = m_Stack.pop();
786*cdf0e10cSrcweir                     assertTrue("stack error: Ruby expected; is: " +
787*cdf0e10cSrcweir                                node.toString(), node instanceof RubyNode);
788*cdf0e10cSrcweir                 }
789*cdf0e10cSrcweir             } else if (type.equals("InContentMetadata")) {
790*cdf0e10cSrcweir                 Object xMeta = xPropSet.getPropertyValue("InContentMetadata");
791*cdf0e10cSrcweir                 XMetadatable xMetadatable = (XMetadatable)
792*cdf0e10cSrcweir                     UnoRuntime.queryInterface(XMetadatable.class, xMeta);
793*cdf0e10cSrcweir                 StringPair xmlid = xMetadatable.getMetadataReference();
794*cdf0e10cSrcweir                 node = new MetaNode(xmlid);
795*cdf0e10cSrcweir                 m_Stack.push(node);
796*cdf0e10cSrcweir                 XEnumerationAccess xEA = (XEnumerationAccess)
797*cdf0e10cSrcweir                     UnoRuntime.queryInterface(XEnumerationAccess.class, xMeta);
798*cdf0e10cSrcweir                 XEnumeration xEnumChildren = xEA.createEnumeration();
799*cdf0e10cSrcweir                 TreeNode node2 = convertChildren(xEnumChildren);
800*cdf0e10cSrcweir                 assertSame("stack error: meta", node2, node);
801*cdf0e10cSrcweir             } else {
802*cdf0e10cSrcweir                 throw new RuntimeException("unexpected type: " + type);
803*cdf0e10cSrcweir             }
804*cdf0e10cSrcweir             m_Stack.peek().appendChild(node);
805*cdf0e10cSrcweir         }
806*cdf0e10cSrcweir         TreeNode ret = m_Stack.pop();
807*cdf0e10cSrcweir         return ret;
808*cdf0e10cSrcweir     }
809*cdf0e10cSrcweir }
810*cdf0e10cSrcweir 
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir //----------------------------------------------------------------------
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir abstract class Inserter
815*cdf0e10cSrcweir {
816*cdf0e10cSrcweir     private XMultiServiceFactory m_xDocFactory;
817*cdf0e10cSrcweir     XText m_xText;
818*cdf0e10cSrcweir     XParagraphCursor m_xCursor;
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir     Inserter(XTextDocument xDoc)
821*cdf0e10cSrcweir     {
822*cdf0e10cSrcweir         m_xDocFactory = (XMultiServiceFactory)
823*cdf0e10cSrcweir             UnoRuntime.queryInterface(XMultiServiceFactory.class, xDoc);
824*cdf0e10cSrcweir         m_xText = xDoc.getText();
825*cdf0e10cSrcweir         XTextCursor xCursor = m_xText.createTextCursor();
826*cdf0e10cSrcweir         m_xCursor = (XParagraphCursor)
827*cdf0e10cSrcweir             UnoRuntime.queryInterface(XParagraphCursor.class, xCursor);
828*cdf0e10cSrcweir     }
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir     void initParagraph() throws Exception
831*cdf0e10cSrcweir     {
832*cdf0e10cSrcweir         m_xCursor.gotoStartOfParagraph(false);
833*cdf0e10cSrcweir         m_xText.insertControlCharacter(m_xCursor, PARAGRAPH_BREAK, false);
834*cdf0e10cSrcweir         // we split the first (empty) paragraph, and then insert into the
835*cdf0e10cSrcweir         // second (empty) paragraph; this ensures first is always empty!
836*cdf0e10cSrcweir     }
837*cdf0e10cSrcweir 
838*cdf0e10cSrcweir     void insertControlCharacter(XTextCursor xCursor, short cchar)
839*cdf0e10cSrcweir         throws Exception
840*cdf0e10cSrcweir     {
841*cdf0e10cSrcweir         m_xText.insertControlCharacter(xCursor, cchar, false);
842*cdf0e10cSrcweir     }
843*cdf0e10cSrcweir 
844*cdf0e10cSrcweir     void insertText(XTextCursor xCursor, String text)
845*cdf0e10cSrcweir     {
846*cdf0e10cSrcweir         xCursor.setString(text);
847*cdf0e10cSrcweir     }
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir     void insertTextField(XTextCursor xCursor, String content) throws Exception
850*cdf0e10cSrcweir     {
851*cdf0e10cSrcweir         XTextContent xContent = makeTextField(content);
852*cdf0e10cSrcweir         xContent.attach(xCursor);
853*cdf0e10cSrcweir     }
854*cdf0e10cSrcweir 
855*cdf0e10cSrcweir     XTextContent makeTextField(String content)
856*cdf0e10cSrcweir         throws Exception
857*cdf0e10cSrcweir     {
858*cdf0e10cSrcweir         Object xField =
859*cdf0e10cSrcweir             m_xDocFactory.createInstance("com.sun.star.text.textfield.Author");
860*cdf0e10cSrcweir         XTextContent xContent = (XTextContent)
861*cdf0e10cSrcweir             UnoRuntime.queryInterface(XTextContent.class, xField);
862*cdf0e10cSrcweir         XPropertySet xPropSet = (XPropertySet)
863*cdf0e10cSrcweir             UnoRuntime.queryInterface(XPropertySet.class, xField);
864*cdf0e10cSrcweir         xPropSet.setPropertyValue("IsFixed", true);
865*cdf0e10cSrcweir         xPropSet.setPropertyValue("FullName", false);
866*cdf0e10cSrcweir         xPropSet.setPropertyValue("Content", content);
867*cdf0e10cSrcweir         return xContent;
868*cdf0e10cSrcweir     }
869*cdf0e10cSrcweir 
870*cdf0e10cSrcweir     void insertFrame(XTextRange xCursor, String name,
871*cdf0e10cSrcweir             TextContentAnchorType anchor) throws Exception
872*cdf0e10cSrcweir     {
873*cdf0e10cSrcweir         XTextContent xContent = makeFrame(name, anchor);
874*cdf0e10cSrcweir         xContent.attach(xCursor);
875*cdf0e10cSrcweir     }
876*cdf0e10cSrcweir 
877*cdf0e10cSrcweir     XTextContent makeFrame(String name, TextContentAnchorType anchor)
878*cdf0e10cSrcweir         throws Exception
879*cdf0e10cSrcweir     {
880*cdf0e10cSrcweir         Object xFrame =
881*cdf0e10cSrcweir             m_xDocFactory.createInstance("com.sun.star.text.TextFrame");
882*cdf0e10cSrcweir         XTextContent xContent = (XTextContent)
883*cdf0e10cSrcweir             UnoRuntime.queryInterface(XTextContent.class, xFrame);
884*cdf0e10cSrcweir         XPropertySet xPropSet = (XPropertySet)
885*cdf0e10cSrcweir             UnoRuntime.queryInterface(XPropertySet.class, xFrame);
886*cdf0e10cSrcweir         xPropSet.setPropertyValue("AnchorType", anchor);
887*cdf0e10cSrcweir         XNamed xNamed = (XNamed)
888*cdf0e10cSrcweir             UnoRuntime.queryInterface(XNamed.class, xContent);
889*cdf0e10cSrcweir         xNamed.setName(name);
890*cdf0e10cSrcweir         return xContent;
891*cdf0e10cSrcweir     }
892*cdf0e10cSrcweir 
893*cdf0e10cSrcweir     void insertFootnote(XTextCursor xCursor, String label) throws Exception
894*cdf0e10cSrcweir     {
895*cdf0e10cSrcweir         XTextContent xContent = makeFootnote(label);
896*cdf0e10cSrcweir         xContent.attach(xCursor);
897*cdf0e10cSrcweir     }
898*cdf0e10cSrcweir 
899*cdf0e10cSrcweir     XTextContent makeFootnote(String label) throws Exception
900*cdf0e10cSrcweir     {
901*cdf0e10cSrcweir         Object xNote =
902*cdf0e10cSrcweir             m_xDocFactory.createInstance("com.sun.star.text.Footnote");
903*cdf0e10cSrcweir         XTextContent xContent = (XTextContent)
904*cdf0e10cSrcweir             UnoRuntime.queryInterface(XTextContent.class, xNote);
905*cdf0e10cSrcweir         XFootnote xFootnote = (XFootnote)
906*cdf0e10cSrcweir             UnoRuntime.queryInterface(XFootnote.class, xNote);
907*cdf0e10cSrcweir         xFootnote.setLabel(label);
908*cdf0e10cSrcweir         return xContent;
909*cdf0e10cSrcweir     }
910*cdf0e10cSrcweir 
911*cdf0e10cSrcweir     void insertBookmark(XTextCursor xCursor, String name, StringPair xmlid)
912*cdf0e10cSrcweir         throws Exception
913*cdf0e10cSrcweir     {
914*cdf0e10cSrcweir         XTextContent xContent = makeBookmark(name);
915*cdf0e10cSrcweir         xContent.attach(xCursor);
916*cdf0e10cSrcweir         if (!xmlid.First.equals(""))
917*cdf0e10cSrcweir         {
918*cdf0e10cSrcweir             XMetadatable xMetadatable = (XMetadatable)
919*cdf0e10cSrcweir                 UnoRuntime.queryInterface(XMetadatable.class, xContent);
920*cdf0e10cSrcweir             xMetadatable.setMetadataReference(xmlid);
921*cdf0e10cSrcweir         }
922*cdf0e10cSrcweir     }
923*cdf0e10cSrcweir 
924*cdf0e10cSrcweir     XTextContent makeBookmark(String name) throws Exception
925*cdf0e10cSrcweir     {
926*cdf0e10cSrcweir         Object xBookmark =
927*cdf0e10cSrcweir             m_xDocFactory.createInstance("com.sun.star.text.Bookmark");
928*cdf0e10cSrcweir         XTextContent xContent = (XTextContent)
929*cdf0e10cSrcweir             UnoRuntime.queryInterface(XTextContent.class, xBookmark);
930*cdf0e10cSrcweir         XNamed xNamed = (XNamed)
931*cdf0e10cSrcweir             UnoRuntime.queryInterface(XNamed.class, xContent);
932*cdf0e10cSrcweir         xNamed.setName(name);
933*cdf0e10cSrcweir         return xContent;
934*cdf0e10cSrcweir     }
935*cdf0e10cSrcweir 
936*cdf0e10cSrcweir     void insertReferenceMark(XTextCursor xCursor, String name) throws Exception
937*cdf0e10cSrcweir     {
938*cdf0e10cSrcweir         XTextContent xContent = makeReferenceMark(name);
939*cdf0e10cSrcweir         xContent.attach(xCursor);
940*cdf0e10cSrcweir     }
941*cdf0e10cSrcweir 
942*cdf0e10cSrcweir     XTextContent makeReferenceMark(String name) throws Exception
943*cdf0e10cSrcweir     {
944*cdf0e10cSrcweir         Object xMark =
945*cdf0e10cSrcweir             m_xDocFactory.createInstance("com.sun.star.text.ReferenceMark");
946*cdf0e10cSrcweir         XTextContent xContent = (XTextContent)
947*cdf0e10cSrcweir             UnoRuntime.queryInterface(XTextContent.class, xMark);
948*cdf0e10cSrcweir         XNamed xNamed = (XNamed)
949*cdf0e10cSrcweir             UnoRuntime.queryInterface(XNamed.class, xContent);
950*cdf0e10cSrcweir         xNamed.setName(name);
951*cdf0e10cSrcweir         return xContent;
952*cdf0e10cSrcweir     }
953*cdf0e10cSrcweir 
954*cdf0e10cSrcweir     void insertDocumentIndexMark(XTextCursor xCursor, String key)
955*cdf0e10cSrcweir         throws Exception
956*cdf0e10cSrcweir     {
957*cdf0e10cSrcweir         XTextContent xContent = makeDocumentIndexMark(key);
958*cdf0e10cSrcweir         xContent.attach(xCursor);
959*cdf0e10cSrcweir     }
960*cdf0e10cSrcweir 
961*cdf0e10cSrcweir     XTextContent makeDocumentIndexMark(String key) throws Exception
962*cdf0e10cSrcweir     {
963*cdf0e10cSrcweir         Object xMark =
964*cdf0e10cSrcweir             m_xDocFactory.createInstance("com.sun.star.text.DocumentIndexMark");
965*cdf0e10cSrcweir         XTextContent xContent = (XTextContent)
966*cdf0e10cSrcweir             UnoRuntime.queryInterface(XTextContent.class, xMark);
967*cdf0e10cSrcweir         XPropertySet xPropSet = (XPropertySet)
968*cdf0e10cSrcweir             UnoRuntime.queryInterface(XPropertySet.class, xMark);
969*cdf0e10cSrcweir         xPropSet.setPropertyValue("PrimaryKey", key);
970*cdf0e10cSrcweir         return xContent;
971*cdf0e10cSrcweir     }
972*cdf0e10cSrcweir 
973*cdf0e10cSrcweir     void insertHyperlink(XTextCursor xCursor, String url) throws Exception
974*cdf0e10cSrcweir     {
975*cdf0e10cSrcweir         XPropertySet xPropSet = (XPropertySet)
976*cdf0e10cSrcweir             UnoRuntime.queryInterface(XPropertySet.class, xCursor);
977*cdf0e10cSrcweir         xPropSet.setPropertyValue("HyperLinkURL", url);
978*cdf0e10cSrcweir     }
979*cdf0e10cSrcweir 
980*cdf0e10cSrcweir     void insertRuby(XTextCursor xCursor, String rubytext) throws Exception
981*cdf0e10cSrcweir     {
982*cdf0e10cSrcweir         XPropertySet xPropSet = (XPropertySet)
983*cdf0e10cSrcweir             UnoRuntime.queryInterface(XPropertySet.class, xCursor);
984*cdf0e10cSrcweir         xPropSet.setPropertyValue("RubyText", rubytext);
985*cdf0e10cSrcweir     }
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir     XTextContent insertMeta(XTextCursor xCursor, StringPair xmlid)
988*cdf0e10cSrcweir         throws Exception
989*cdf0e10cSrcweir     {
990*cdf0e10cSrcweir         XTextContent xContent = makeMeta();
991*cdf0e10cSrcweir         xContent.attach(xCursor);
992*cdf0e10cSrcweir         XMetadatable xMetadatable = (XMetadatable)
993*cdf0e10cSrcweir             UnoRuntime.queryInterface(XMetadatable.class, xContent);
994*cdf0e10cSrcweir         xMetadatable.setMetadataReference(xmlid);
995*cdf0e10cSrcweir         return xContent;
996*cdf0e10cSrcweir     }
997*cdf0e10cSrcweir 
998*cdf0e10cSrcweir     XTextContent makeMeta() throws Exception
999*cdf0e10cSrcweir     {
1000*cdf0e10cSrcweir         Object xMeta = m_xDocFactory.createInstance(
1001*cdf0e10cSrcweir                 "com.sun.star.text.InContentMetadata");
1002*cdf0e10cSrcweir         XTextContent xContent = (XTextContent)
1003*cdf0e10cSrcweir             UnoRuntime.queryInterface(XTextContent.class, xMeta);
1004*cdf0e10cSrcweir         return xContent;
1005*cdf0e10cSrcweir     }
1006*cdf0e10cSrcweir 
1007*cdf0e10cSrcweir     XTextField insertMetaField(XTextCursor xCursor, StringPair xmlid)
1008*cdf0e10cSrcweir         throws Exception
1009*cdf0e10cSrcweir     {
1010*cdf0e10cSrcweir         XTextField xContent = makeMetaField();
1011*cdf0e10cSrcweir         xContent.attach(xCursor);
1012*cdf0e10cSrcweir         XMetadatable xMetadatable = (XMetadatable)
1013*cdf0e10cSrcweir             UnoRuntime.queryInterface(XMetadatable.class, xContent);
1014*cdf0e10cSrcweir         xMetadatable.setMetadataReference(xmlid);
1015*cdf0e10cSrcweir         return xContent;
1016*cdf0e10cSrcweir     }
1017*cdf0e10cSrcweir 
1018*cdf0e10cSrcweir     XTextField makeMetaField() throws Exception
1019*cdf0e10cSrcweir     {
1020*cdf0e10cSrcweir         Object xMeta = m_xDocFactory.createInstance(
1021*cdf0e10cSrcweir                 "com.sun.star.text.textfield.MetadataField");
1022*cdf0e10cSrcweir         XTextField xContent = (XTextField)
1023*cdf0e10cSrcweir             UnoRuntime.queryInterface(XTextField.class, xMeta);
1024*cdf0e10cSrcweir         return xContent;
1025*cdf0e10cSrcweir     }
1026*cdf0e10cSrcweir 
1027*cdf0e10cSrcweir }
1028*cdf0e10cSrcweir 
1029*cdf0e10cSrcweir class TreeInserter extends Inserter
1030*cdf0e10cSrcweir {
1031*cdf0e10cSrcweir     private Map<String, XTextRange> m_BookmarkStarts;
1032*cdf0e10cSrcweir     private Map<String, XTextRange> m_ReferenceMarkStarts;
1033*cdf0e10cSrcweir     private Map<String, XTextRange> m_DocumentIndexMarkStarts;
1034*cdf0e10cSrcweir     private List<Pair<XTextRange, FrameNode>> m_FrameHints;
1035*cdf0e10cSrcweir 
1036*cdf0e10cSrcweir     TreeInserter(XTextDocument xDoc)
1037*cdf0e10cSrcweir     {
1038*cdf0e10cSrcweir         super(xDoc);
1039*cdf0e10cSrcweir         m_BookmarkStarts = new HashMap<String, XTextRange>();
1040*cdf0e10cSrcweir         m_ReferenceMarkStarts = new HashMap<String, XTextRange>();
1041*cdf0e10cSrcweir         m_DocumentIndexMarkStarts = new HashMap<String, XTextRange>();
1042*cdf0e10cSrcweir         m_FrameHints = new ArrayList<Pair<XTextRange, FrameNode>>();
1043*cdf0e10cSrcweir     }
1044*cdf0e10cSrcweir 
1045*cdf0e10cSrcweir     void insertTree(TreeNode tree) throws Exception
1046*cdf0e10cSrcweir     {
1047*cdf0e10cSrcweir         if (!tree.getType().equals("__ROOT__"))
1048*cdf0e10cSrcweir             throw new RuntimeException("insertTree: test error: no root");
1049*cdf0e10cSrcweir         initParagraph();
1050*cdf0e10cSrcweir         insertChildren(tree.createEnumeration());
1051*cdf0e10cSrcweir         for (int i = 0; i < m_FrameHints.size(); ++i) {
1052*cdf0e10cSrcweir             Pair<XTextRange, FrameNode> p = m_FrameHints.get(i);
1053*cdf0e10cSrcweir             insertFrame(p.First, p.Second.getName(), p.Second.getAnchor());
1054*cdf0e10cSrcweir         }
1055*cdf0e10cSrcweir     }
1056*cdf0e10cSrcweir 
1057*cdf0e10cSrcweir     void insertChildren(TreeNodeEnum children) throws Exception
1058*cdf0e10cSrcweir     {
1059*cdf0e10cSrcweir         while (children.hasNext()) {
1060*cdf0e10cSrcweir             m_xCursor.gotoEndOfParagraph(false);
1061*cdf0e10cSrcweir             TreeNode node = children.next();
1062*cdf0e10cSrcweir             String type = node.getType();
1063*cdf0e10cSrcweir             if (type.equals("Bookmark")) {
1064*cdf0e10cSrcweir                 BookmarkNode bkmk = (BookmarkNode) node;
1065*cdf0e10cSrcweir                 String name = bkmk.getName();
1066*cdf0e10cSrcweir                 StringPair id = bkmk.getXmlId();
1067*cdf0e10cSrcweir                 if (bkmk.isPoint()) {
1068*cdf0e10cSrcweir                     insertBookmark(m_xCursor, name, id);
1069*cdf0e10cSrcweir                 } else if (bkmk.isStart()) {
1070*cdf0e10cSrcweir                     m_BookmarkStarts.put(name, m_xCursor.getStart());
1071*cdf0e10cSrcweir                 } else {
1072*cdf0e10cSrcweir                     XTextRange xRange = m_BookmarkStarts.get(name);
1073*cdf0e10cSrcweir                     XParagraphCursor xCursor = mkCursor(xRange);
1074*cdf0e10cSrcweir                     insertBookmark(xCursor, name, id);
1075*cdf0e10cSrcweir                 }
1076*cdf0e10cSrcweir             } else if (type.equals("ReferenceMark")) {
1077*cdf0e10cSrcweir                 ReferenceMarkNode mark = (ReferenceMarkNode) node;
1078*cdf0e10cSrcweir                 String name = mark.getName();
1079*cdf0e10cSrcweir                 if (mark.isPoint()) {
1080*cdf0e10cSrcweir                     insertReferenceMark(m_xCursor, name);
1081*cdf0e10cSrcweir                 } else if (mark.isStart()) {
1082*cdf0e10cSrcweir                     m_ReferenceMarkStarts.put(name, m_xCursor.getStart());
1083*cdf0e10cSrcweir                 } else {
1084*cdf0e10cSrcweir                     XTextRange xRange = m_ReferenceMarkStarts.get(name);
1085*cdf0e10cSrcweir                     XParagraphCursor xCursor = mkCursor(xRange);
1086*cdf0e10cSrcweir                     insertReferenceMark(xCursor, name);
1087*cdf0e10cSrcweir                 }
1088*cdf0e10cSrcweir             } else if (type.equals("DocumentIndexMark")) {
1089*cdf0e10cSrcweir                 DocumentIndexMarkNode mark = (DocumentIndexMarkNode) node;
1090*cdf0e10cSrcweir                 String name = mark.getName();
1091*cdf0e10cSrcweir                 if (mark.isPoint()) {
1092*cdf0e10cSrcweir                     insertDocumentIndexMark(m_xCursor, name);
1093*cdf0e10cSrcweir                 } else if (mark.isStart()) {
1094*cdf0e10cSrcweir                     m_DocumentIndexMarkStarts.put(name, m_xCursor.getStart());
1095*cdf0e10cSrcweir                 } else {
1096*cdf0e10cSrcweir                     XTextRange xRange = m_DocumentIndexMarkStarts.get(name);
1097*cdf0e10cSrcweir                     XParagraphCursor xCursor = mkCursor(xRange);
1098*cdf0e10cSrcweir                     insertDocumentIndexMark(xCursor, name);
1099*cdf0e10cSrcweir                 }
1100*cdf0e10cSrcweir             } else if (type.equals("Hyperlink")) {
1101*cdf0e10cSrcweir                 HyperlinkNode href = (HyperlinkNode) node;
1102*cdf0e10cSrcweir                 XTextRange xRange = m_xCursor.getStart();
1103*cdf0e10cSrcweir                 insertChildren(href.createEnumeration());
1104*cdf0e10cSrcweir                 XParagraphCursor xCursor = mkCursor(xRange);
1105*cdf0e10cSrcweir                 insertHyperlink(xCursor, href.getURL());
1106*cdf0e10cSrcweir             } else if (type.equals("Ruby")) {
1107*cdf0e10cSrcweir                 RubyNode ruby = (RubyNode) node;
1108*cdf0e10cSrcweir                 XTextRange xRange = m_xCursor.getStart();
1109*cdf0e10cSrcweir                 insertChildren(ruby.createEnumeration());
1110*cdf0e10cSrcweir                 XParagraphCursor xCursor = mkCursor(xRange);
1111*cdf0e10cSrcweir                 insertRuby(xCursor, ruby.getRubyText());
1112*cdf0e10cSrcweir             } else if (type.equals("InContentMetadata")) {
1113*cdf0e10cSrcweir                 MetaNode meta = (MetaNode) node;
1114*cdf0e10cSrcweir                 XTextRange xRange = m_xCursor.getStart();
1115*cdf0e10cSrcweir                 insertChildren(meta.createEnumeration());
1116*cdf0e10cSrcweir                 XParagraphCursor xCursor = mkCursor(xRange);
1117*cdf0e10cSrcweir                 insertMeta(xCursor, meta.getXmlId());
1118*cdf0e10cSrcweir             } else if (type.equals("MetadataField")) {
1119*cdf0e10cSrcweir                 MetaFieldNode meta = (MetaFieldNode) node;
1120*cdf0e10cSrcweir                 XTextRange xRange = m_xCursor.getStart();
1121*cdf0e10cSrcweir                 insertChildren(meta.createEnumeration());
1122*cdf0e10cSrcweir                 XParagraphCursor xCursor = mkCursor(xRange);
1123*cdf0e10cSrcweir                 insertMetaField(xCursor, meta.getXmlId());
1124*cdf0e10cSrcweir             } else if (type.equals("Text")) {
1125*cdf0e10cSrcweir                 TextNode text = (TextNode) node;
1126*cdf0e10cSrcweir                 insertText(m_xCursor, text.getContent());
1127*cdf0e10cSrcweir             } else if (type.equals("TextField")) {
1128*cdf0e10cSrcweir                 TextFieldNode field = (TextFieldNode) node;
1129*cdf0e10cSrcweir                 insertTextField(m_xCursor, field.getContent());
1130*cdf0e10cSrcweir             } else if (type.equals("Footnote")) {
1131*cdf0e10cSrcweir                 FootnoteNode note = (FootnoteNode) node;
1132*cdf0e10cSrcweir                 insertFootnote(m_xCursor, note.getLabel());
1133*cdf0e10cSrcweir             } else if (type.equals("Frame")) {
1134*cdf0e10cSrcweir                 FrameNode frame = (FrameNode) node;
1135*cdf0e10cSrcweir                 if (frame.getAnchor() == AT_CHARACTER) {
1136*cdf0e10cSrcweir                     m_FrameHints.add( new Pair(m_xCursor.getStart(), frame) );
1137*cdf0e10cSrcweir                 } else {
1138*cdf0e10cSrcweir                     insertFrame(m_xCursor, frame.getName(), frame.getAnchor());
1139*cdf0e10cSrcweir                 }
1140*cdf0e10cSrcweir             } else if (type.equals("ControlCharacter")) {
1141*cdf0e10cSrcweir                 ControlCharacterNode cchar = (ControlCharacterNode) node;
1142*cdf0e10cSrcweir                 insertControlCharacter(m_xCursor, cchar.getChar());
1143*cdf0e10cSrcweir             } else if (type.equals("SoftPageBreak")) {
1144*cdf0e10cSrcweir                 SoftPageBreakNode spbk = (SoftPageBreakNode) node;
1145*cdf0e10cSrcweir                 throw new RuntimeException("sorry, cannot test SoftPageBreak");
1146*cdf0e10cSrcweir             } else {
1147*cdf0e10cSrcweir                 throw new RuntimeException("unexpected type: " + type);
1148*cdf0e10cSrcweir             }
1149*cdf0e10cSrcweir         }
1150*cdf0e10cSrcweir     }
1151*cdf0e10cSrcweir 
1152*cdf0e10cSrcweir     XParagraphCursor mkCursor(XTextRange xRange)
1153*cdf0e10cSrcweir     {
1154*cdf0e10cSrcweir         XTextCursor xCursor = m_xText.createTextCursorByRange(xRange);
1155*cdf0e10cSrcweir         XParagraphCursor xParaCursor = (XParagraphCursor)
1156*cdf0e10cSrcweir             UnoRuntime.queryInterface(XParagraphCursor.class, xCursor);
1157*cdf0e10cSrcweir         xParaCursor.gotoEndOfParagraph(true);
1158*cdf0e10cSrcweir         return xParaCursor;
1159*cdf0e10cSrcweir     }
1160*cdf0e10cSrcweir }
1161*cdf0e10cSrcweir 
1162*cdf0e10cSrcweir 
1163*cdf0e10cSrcweir // FIXME: this does not account for inserted dummy characters!
1164*cdf0e10cSrcweir class RangeInserter extends Inserter
1165*cdf0e10cSrcweir {
1166*cdf0e10cSrcweir     RangeInserter(XTextDocument xDoc) throws Exception
1167*cdf0e10cSrcweir     { super(xDoc); initParagraph(); }
1168*cdf0e10cSrcweir 
1169*cdf0e10cSrcweir     /*
1170*cdf0e10cSrcweir     void insertText(int pos, String text)
1171*cdf0e10cSrcweir     {
1172*cdf0e10cSrcweir         m_xCursor.gotoStartOfParagraph(false);
1173*cdf0e10cSrcweir         m_xCursor.goRight((short) pos, false);
1174*cdf0e10cSrcweir         insertText(m_xCursor, text);
1175*cdf0e10cSrcweir     }
1176*cdf0e10cSrcweir     */
1177*cdf0e10cSrcweir 
1178*cdf0e10cSrcweir     XTextContent insertRange(Range range) throws Exception
1179*cdf0e10cSrcweir     {
1180*cdf0e10cSrcweir         m_xCursor.gotoStartOfParagraph(false);
1181*cdf0e10cSrcweir         m_xCursor.goRight(range.getStart(), false);
1182*cdf0e10cSrcweir         m_xCursor.goRight(range.getExtent(), true);
1183*cdf0e10cSrcweir         return insertNode(m_xCursor, range.getNode());
1184*cdf0e10cSrcweir     }
1185*cdf0e10cSrcweir 
1186*cdf0e10cSrcweir     XTextContent insertNode(XParagraphCursor xCursor, TreeNode node)
1187*cdf0e10cSrcweir         throws Exception
1188*cdf0e10cSrcweir     {
1189*cdf0e10cSrcweir         String type = node.getType();
1190*cdf0e10cSrcweir         if (type.equals("Bookmark")) {
1191*cdf0e10cSrcweir             BookmarkNode bkmk = (BookmarkNode) node;
1192*cdf0e10cSrcweir             if (bkmk.isPoint()) throw new RuntimeException("range only");
1193*cdf0e10cSrcweir             insertBookmark(xCursor, bkmk.getName(), bkmk.getXmlId());
1194*cdf0e10cSrcweir         } else if (type.equals("ReferenceMark")) {
1195*cdf0e10cSrcweir             ReferenceMarkNode mark = (ReferenceMarkNode) node;
1196*cdf0e10cSrcweir             if (mark.isPoint()) throw new RuntimeException("range only");
1197*cdf0e10cSrcweir             insertReferenceMark(xCursor, mark.getName());
1198*cdf0e10cSrcweir         } else if (type.equals("DocumentIndexMark")) {
1199*cdf0e10cSrcweir             DocumentIndexMarkNode mark = (DocumentIndexMarkNode) node;
1200*cdf0e10cSrcweir             if (mark.isPoint()) throw new RuntimeException("range only");
1201*cdf0e10cSrcweir             insertDocumentIndexMark(xCursor, mark.getName());
1202*cdf0e10cSrcweir         } else if (type.equals("Hyperlink")) {
1203*cdf0e10cSrcweir             HyperlinkNode href = (HyperlinkNode) node;
1204*cdf0e10cSrcweir             insertHyperlink(xCursor, href.getURL());
1205*cdf0e10cSrcweir         } else if (type.equals("Ruby")) {
1206*cdf0e10cSrcweir             RubyNode ruby = (RubyNode) node;
1207*cdf0e10cSrcweir             insertRuby(xCursor, ruby.getRubyText());
1208*cdf0e10cSrcweir         } else if (type.equals("InContentMetadata")) {
1209*cdf0e10cSrcweir             MetaNode meta = (MetaNode) node;
1210*cdf0e10cSrcweir             return insertMeta(xCursor, meta.getXmlId());
1211*cdf0e10cSrcweir         } else if (type.equals("MetadataField")) {
1212*cdf0e10cSrcweir             MetaFieldNode meta = (MetaFieldNode) node;
1213*cdf0e10cSrcweir             return insertMetaField(xCursor, meta.getXmlId());
1214*cdf0e10cSrcweir         } else if (type.equals("Text")) {
1215*cdf0e10cSrcweir             TextNode text = (TextNode) node;
1216*cdf0e10cSrcweir             insertText(xCursor, text.getContent());
1217*cdf0e10cSrcweir         } else if (type.equals("TextField")) {
1218*cdf0e10cSrcweir             TextFieldNode field = (TextFieldNode) node;
1219*cdf0e10cSrcweir             insertTextField(m_xCursor, field.getContent());
1220*cdf0e10cSrcweir         } else if (type.equals("Footnote")) {
1221*cdf0e10cSrcweir             FootnoteNode note = (FootnoteNode) node;
1222*cdf0e10cSrcweir             insertFootnote(m_xCursor, note.getLabel());
1223*cdf0e10cSrcweir         } else if (type.equals("Frame")) {
1224*cdf0e10cSrcweir             FrameNode frame = (FrameNode) node;
1225*cdf0e10cSrcweir             insertFrame(xCursor, frame.getName(), frame.getAnchor());
1226*cdf0e10cSrcweir         } else if (type.equals("ControlCharacter")) {
1227*cdf0e10cSrcweir             ControlCharacterNode cchar = (ControlCharacterNode) node;
1228*cdf0e10cSrcweir             insertControlCharacter(m_xCursor, cchar.getChar());
1229*cdf0e10cSrcweir         } else if (type.equals("SoftPageBreak")) {
1230*cdf0e10cSrcweir             throw new RuntimeException("sorry, cannot test SoftPageBreak");
1231*cdf0e10cSrcweir         } else {
1232*cdf0e10cSrcweir             throw new RuntimeException("unexpected type: " + type);
1233*cdf0e10cSrcweir         }
1234*cdf0e10cSrcweir         return null;
1235*cdf0e10cSrcweir     }
1236*cdf0e10cSrcweir }
1237*cdf0e10cSrcweir 
1238*cdf0e10cSrcweir 
1239*cdf0e10cSrcweir //----------------------------------------------------------------------
1240*cdf0e10cSrcweir 
1241*cdf0e10cSrcweir public class TextPortionEnumerationTest
1242*cdf0e10cSrcweir {
1243*cdf0e10cSrcweir     private XMultiServiceFactory m_xMSF = null;
1244*cdf0e10cSrcweir     private XComponentContext m_xContext = null;
1245*cdf0e10cSrcweir     private XTextDocument m_xDoc = null;
1246*cdf0e10cSrcweir     private String m_TmpDir = null;
1247*cdf0e10cSrcweir 
1248*cdf0e10cSrcweir     private int m_Count = 1;
1249*cdf0e10cSrcweir 
1250*cdf0e10cSrcweir     @Before public void before() throws Exception
1251*cdf0e10cSrcweir     {
1252*cdf0e10cSrcweir         m_xMSF = UnoRuntime.queryInterface(
1253*cdf0e10cSrcweir             XMultiServiceFactory.class,
1254*cdf0e10cSrcweir             connection.getComponentContext().getServiceManager());
1255*cdf0e10cSrcweir         XPropertySet xPropertySet = (XPropertySet)
1256*cdf0e10cSrcweir             UnoRuntime.queryInterface(XPropertySet.class, m_xMSF);
1257*cdf0e10cSrcweir         Object defaultCtx = xPropertySet.getPropertyValue("DefaultContext");
1258*cdf0e10cSrcweir         m_xContext = (XComponentContext)
1259*cdf0e10cSrcweir             UnoRuntime.queryInterface(XComponentContext.class, defaultCtx);
1260*cdf0e10cSrcweir         assertNotNull("could not get component context.", m_xContext);
1261*cdf0e10cSrcweir         m_xDoc = util.WriterTools.createTextDoc(m_xMSF);
1262*cdf0e10cSrcweir         m_TmpDir = util.utils.getOfficeTemp/*Dir*/(m_xMSF);
1263*cdf0e10cSrcweir         System.out.println("tempdir: " + m_TmpDir);
1264*cdf0e10cSrcweir     }
1265*cdf0e10cSrcweir 
1266*cdf0e10cSrcweir     @After public void after()
1267*cdf0e10cSrcweir     {
1268*cdf0e10cSrcweir         util.DesktopTools.closeDoc(m_xDoc);
1269*cdf0e10cSrcweir     }
1270*cdf0e10cSrcweir 
1271*cdf0e10cSrcweir     @Test public void testText() throws Exception
1272*cdf0e10cSrcweir     {
1273*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1274*cdf0e10cSrcweir         TreeNode text = new TextNode("abc");
1275*cdf0e10cSrcweir         root.appendChild(text);
1276*cdf0e10cSrcweir         doTest(root);
1277*cdf0e10cSrcweir     }
1278*cdf0e10cSrcweir 
1279*cdf0e10cSrcweir     @Test public void testTextField() throws Exception
1280*cdf0e10cSrcweir     {
1281*cdf0e10cSrcweir         String name = mkName("ruby");
1282*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1283*cdf0e10cSrcweir         TreeNode txtf = new TextFieldNode("abc");
1284*cdf0e10cSrcweir         root.appendChild(txtf);
1285*cdf0e10cSrcweir         doTest(root);
1286*cdf0e10cSrcweir     }
1287*cdf0e10cSrcweir 
1288*cdf0e10cSrcweir     /*@Test*/ public void testControlChar() throws Exception
1289*cdf0e10cSrcweir     {
1290*cdf0e10cSrcweir //FIXME this is converted to a text portion: ControlCharacter is obsolete
1291*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1292*cdf0e10cSrcweir         TreeNode cchr = new ControlCharacterNode(HARD_HYPHEN);
1293*cdf0e10cSrcweir         root.appendChild(cchr);
1294*cdf0e10cSrcweir         doTest(root);
1295*cdf0e10cSrcweir     }
1296*cdf0e10cSrcweir 
1297*cdf0e10cSrcweir     /*@Test*/ public void testSoftPageBreak() throws Exception
1298*cdf0e10cSrcweir     {
1299*cdf0e10cSrcweir //FIXME: insert a soft page break: not done
1300*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1301*cdf0e10cSrcweir         TreeNode spbk = new SoftPageBreakNode();
1302*cdf0e10cSrcweir         TreeNode text = new TextNode("abc");
1303*cdf0e10cSrcweir         root.appendChild(spbk);
1304*cdf0e10cSrcweir         root.appendChild(text);
1305*cdf0e10cSrcweir         doTest(root);
1306*cdf0e10cSrcweir     }
1307*cdf0e10cSrcweir 
1308*cdf0e10cSrcweir     @Test public void testFootnote() throws Exception
1309*cdf0e10cSrcweir     {
1310*cdf0e10cSrcweir         String name = mkName("ftn");
1311*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1312*cdf0e10cSrcweir         TreeNode ftnd = new FootnoteNode(name);
1313*cdf0e10cSrcweir         root.appendChild(ftnd);
1314*cdf0e10cSrcweir         doTest(root);
1315*cdf0e10cSrcweir     }
1316*cdf0e10cSrcweir 
1317*cdf0e10cSrcweir     @Test public void testFrameAs() throws Exception
1318*cdf0e10cSrcweir     {
1319*cdf0e10cSrcweir         String name = mkName("frame");
1320*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1321*cdf0e10cSrcweir         TreeNode fram = new FrameNode(name, AS_CHARACTER);
1322*cdf0e10cSrcweir         root.appendChild(fram);
1323*cdf0e10cSrcweir         doTest(root);
1324*cdf0e10cSrcweir     }
1325*cdf0e10cSrcweir 
1326*cdf0e10cSrcweir     @Test public void testFrameAt() throws Exception
1327*cdf0e10cSrcweir     {
1328*cdf0e10cSrcweir         String name = mkName("frame");
1329*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1330*cdf0e10cSrcweir //        TreeNode text = new TextNode(""); // necessary?
1331*cdf0e10cSrcweir         TreeNode fram = new FrameNode(name, AT_CHARACTER);
1332*cdf0e10cSrcweir //        root.appendChild(text);
1333*cdf0e10cSrcweir         root.appendChild(fram);
1334*cdf0e10cSrcweir         doTest(root);
1335*cdf0e10cSrcweir     }
1336*cdf0e10cSrcweir 
1337*cdf0e10cSrcweir     @Test public void testBookmarkPoint() throws Exception
1338*cdf0e10cSrcweir     {
1339*cdf0e10cSrcweir         String name = mkName("mark");
1340*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1341*cdf0e10cSrcweir         TreeNode bkmk = new BookmarkNode(name);
1342*cdf0e10cSrcweir         TreeNode text = new TextNode("abc");
1343*cdf0e10cSrcweir         root.appendChild(bkmk);
1344*cdf0e10cSrcweir         root.appendChild(text);
1345*cdf0e10cSrcweir         doTest(root);
1346*cdf0e10cSrcweir     }
1347*cdf0e10cSrcweir 
1348*cdf0e10cSrcweir     @Test public void testBookmark() throws Exception
1349*cdf0e10cSrcweir     {
1350*cdf0e10cSrcweir         String name = mkName("mark");
1351*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1352*cdf0e10cSrcweir         TreeNode bkm1 = new BookmarkStartNode(name);
1353*cdf0e10cSrcweir         TreeNode text = new TextNode("abc");
1354*cdf0e10cSrcweir         TreeNode bkm2 = new BookmarkEndNode(name);
1355*cdf0e10cSrcweir         root.appendChild(bkm1);
1356*cdf0e10cSrcweir         root.appendChild(text);
1357*cdf0e10cSrcweir         root.appendChild(bkm2);
1358*cdf0e10cSrcweir         doTest(root);
1359*cdf0e10cSrcweir     }
1360*cdf0e10cSrcweir 
1361*cdf0e10cSrcweir     @Test public void testBookmarkPointXmlId() throws Exception
1362*cdf0e10cSrcweir     {
1363*cdf0e10cSrcweir         String name = mkName("mark");
1364*cdf0e10cSrcweir         StringPair id = mkId("id");
1365*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1366*cdf0e10cSrcweir         TreeNode bkmk = new BookmarkNode(name, id);
1367*cdf0e10cSrcweir         TreeNode text = new TextNode("abc");
1368*cdf0e10cSrcweir         root.appendChild(bkmk);
1369*cdf0e10cSrcweir         root.appendChild(text);
1370*cdf0e10cSrcweir         doTest(root);
1371*cdf0e10cSrcweir     }
1372*cdf0e10cSrcweir 
1373*cdf0e10cSrcweir     @Test public void testBookmarkXmlId() throws Exception
1374*cdf0e10cSrcweir     {
1375*cdf0e10cSrcweir         String name = mkName("mark");
1376*cdf0e10cSrcweir         StringPair id = mkId("id");
1377*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1378*cdf0e10cSrcweir         TreeNode bkm1 = new BookmarkStartNode(name, id);
1379*cdf0e10cSrcweir         TreeNode text = new TextNode("abc");
1380*cdf0e10cSrcweir         TreeNode bkm2 = new BookmarkEndNode(name, id);
1381*cdf0e10cSrcweir         root.appendChild(bkm1);
1382*cdf0e10cSrcweir         root.appendChild(text);
1383*cdf0e10cSrcweir         root.appendChild(bkm2);
1384*cdf0e10cSrcweir         doTest(root);
1385*cdf0e10cSrcweir     }
1386*cdf0e10cSrcweir 
1387*cdf0e10cSrcweir     @Test public void testRefmarkPoint() throws Exception
1388*cdf0e10cSrcweir     {
1389*cdf0e10cSrcweir         String name = mkName("refmark");
1390*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1391*cdf0e10cSrcweir         TreeNode rfmk = new ReferenceMarkNode(name);
1392*cdf0e10cSrcweir         TreeNode text = new TextNode("abc");
1393*cdf0e10cSrcweir         root.appendChild(rfmk);
1394*cdf0e10cSrcweir         root.appendChild(text);
1395*cdf0e10cSrcweir         doTest(root);
1396*cdf0e10cSrcweir     }
1397*cdf0e10cSrcweir 
1398*cdf0e10cSrcweir     @Test public void testRefmark() throws Exception
1399*cdf0e10cSrcweir     {
1400*cdf0e10cSrcweir         String name = mkName("refmark");
1401*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1402*cdf0e10cSrcweir         TreeNode rfm1 = new ReferenceMarkStartNode(name);
1403*cdf0e10cSrcweir         TreeNode text = new TextNode("abc");
1404*cdf0e10cSrcweir         TreeNode rfm2 = new ReferenceMarkEndNode(name);
1405*cdf0e10cSrcweir         root.appendChild(rfm1);
1406*cdf0e10cSrcweir         root.appendChild(text);
1407*cdf0e10cSrcweir         root.appendChild(rfm2);
1408*cdf0e10cSrcweir         doTest(root);
1409*cdf0e10cSrcweir     }
1410*cdf0e10cSrcweir 
1411*cdf0e10cSrcweir     @Test public void testToxmarkPoint() throws Exception
1412*cdf0e10cSrcweir     {
1413*cdf0e10cSrcweir         String name = mkName("toxmark");
1414*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1415*cdf0e10cSrcweir         TreeNode txmk = new DocumentIndexMarkNode(name);
1416*cdf0e10cSrcweir         TreeNode text = new TextNode("abc");
1417*cdf0e10cSrcweir         root.appendChild(txmk);
1418*cdf0e10cSrcweir         root.appendChild(text);
1419*cdf0e10cSrcweir         doTest(root);
1420*cdf0e10cSrcweir     }
1421*cdf0e10cSrcweir 
1422*cdf0e10cSrcweir     @Test public void testToxmark() throws Exception
1423*cdf0e10cSrcweir     {
1424*cdf0e10cSrcweir         String name = mkName("toxmark");
1425*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1426*cdf0e10cSrcweir         TreeNode txm1 = new DocumentIndexMarkStartNode(name);
1427*cdf0e10cSrcweir         TreeNode text = new TextNode("abc");
1428*cdf0e10cSrcweir         TreeNode txm2 = new DocumentIndexMarkEndNode(name);
1429*cdf0e10cSrcweir         root.appendChild(txm1);
1430*cdf0e10cSrcweir         root.appendChild(text);
1431*cdf0e10cSrcweir         root.appendChild(txm2);
1432*cdf0e10cSrcweir         doTest(root);
1433*cdf0e10cSrcweir     }
1434*cdf0e10cSrcweir 
1435*cdf0e10cSrcweir     @Test public void testHyperlink() throws Exception
1436*cdf0e10cSrcweir     {
1437*cdf0e10cSrcweir         String name = mkName("url");
1438*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1439*cdf0e10cSrcweir         TreeNode href = new HyperlinkNode(name);
1440*cdf0e10cSrcweir         TreeNode text = new TextNode("abc");
1441*cdf0e10cSrcweir         href.appendChild(text);
1442*cdf0e10cSrcweir         root.appendChild(href);
1443*cdf0e10cSrcweir         doTest(root);
1444*cdf0e10cSrcweir     }
1445*cdf0e10cSrcweir 
1446*cdf0e10cSrcweir     @Test public void testHyperlinkEmpty() throws Exception
1447*cdf0e10cSrcweir     {
1448*cdf0e10cSrcweir         String name = mkName("url");
1449*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1450*cdf0e10cSrcweir         TreeNode href = new HyperlinkNode(name);
1451*cdf0e10cSrcweir         TreeNode text = new TextNode("");
1452*cdf0e10cSrcweir         href.appendChild(text);
1453*cdf0e10cSrcweir         root.appendChild(href);
1454*cdf0e10cSrcweir         doTest(root);
1455*cdf0e10cSrcweir     }
1456*cdf0e10cSrcweir 
1457*cdf0e10cSrcweir     @Test public void testRuby() throws Exception
1458*cdf0e10cSrcweir     {
1459*cdf0e10cSrcweir         String name = mkName("ruby");
1460*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1461*cdf0e10cSrcweir         TreeNode ruby = new RubyNode(name);
1462*cdf0e10cSrcweir         TreeNode text = new TextNode("abc");
1463*cdf0e10cSrcweir         ruby.appendChild(text);
1464*cdf0e10cSrcweir         root.appendChild(ruby);
1465*cdf0e10cSrcweir         doTest(root);
1466*cdf0e10cSrcweir     }
1467*cdf0e10cSrcweir 
1468*cdf0e10cSrcweir     @Test public void testRubyEmpty() throws Exception
1469*cdf0e10cSrcweir     {
1470*cdf0e10cSrcweir         // BUG: #i91534#
1471*cdf0e10cSrcweir         String name = mkName("ruby");
1472*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1473*cdf0e10cSrcweir         TreeNode ruby = new RubyNode(name);
1474*cdf0e10cSrcweir         root.appendChild(ruby);
1475*cdf0e10cSrcweir         doTest(root);
1476*cdf0e10cSrcweir     }
1477*cdf0e10cSrcweir 
1478*cdf0e10cSrcweir     @Test public void testMeta() throws Exception
1479*cdf0e10cSrcweir     {
1480*cdf0e10cSrcweir         StringPair id = new StringPair("content.xml", mkName("id"));
1481*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1482*cdf0e10cSrcweir         TreeNode meta = new MetaNode(id);
1483*cdf0e10cSrcweir         TreeNode text = new TextNode("abc");
1484*cdf0e10cSrcweir         root.appendChild(new TextNode("123"));
1485*cdf0e10cSrcweir         meta.appendChild(text);
1486*cdf0e10cSrcweir         root.appendChild(meta);
1487*cdf0e10cSrcweir         doTest(root);
1488*cdf0e10cSrcweir     }
1489*cdf0e10cSrcweir 
1490*cdf0e10cSrcweir     @Test public void testMetaEmpty() throws Exception
1491*cdf0e10cSrcweir     {
1492*cdf0e10cSrcweir         StringPair id = new StringPair("content.xml", mkName("id"));
1493*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1494*cdf0e10cSrcweir         TreeNode meta = new MetaNode(id);
1495*cdf0e10cSrcweir //        TreeNode text = new TextNode("");
1496*cdf0e10cSrcweir //        meta.appendChild(text);
1497*cdf0e10cSrcweir         root.appendChild(meta);
1498*cdf0e10cSrcweir         doTest(root);
1499*cdf0e10cSrcweir     }
1500*cdf0e10cSrcweir 
1501*cdf0e10cSrcweir     @Test public void testMetaField() throws Exception
1502*cdf0e10cSrcweir     {
1503*cdf0e10cSrcweir         StringPair id = new StringPair("content.xml", mkName("id"));
1504*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1505*cdf0e10cSrcweir         TreeNode meta = new MetaFieldNode(id);
1506*cdf0e10cSrcweir         TreeNode text = new TextNode("abc");
1507*cdf0e10cSrcweir         root.appendChild(new TextNode("123"));
1508*cdf0e10cSrcweir         meta.appendChild(text);
1509*cdf0e10cSrcweir         root.appendChild(meta);
1510*cdf0e10cSrcweir         doTest(root);
1511*cdf0e10cSrcweir     }
1512*cdf0e10cSrcweir 
1513*cdf0e10cSrcweir     @Test public void testMetaFieldEmpty() throws Exception
1514*cdf0e10cSrcweir     {
1515*cdf0e10cSrcweir         StringPair id = new StringPair("content.xml", mkName("id"));
1516*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1517*cdf0e10cSrcweir         TreeNode meta = new MetaFieldNode(id);
1518*cdf0e10cSrcweir //        TreeNode text = new TextNode("");
1519*cdf0e10cSrcweir //        meta.appendChild(text);
1520*cdf0e10cSrcweir         root.appendChild(meta);
1521*cdf0e10cSrcweir         doTest(root);
1522*cdf0e10cSrcweir     }
1523*cdf0e10cSrcweir 
1524*cdf0e10cSrcweir     @Test public void testBookmark1() throws Exception
1525*cdf0e10cSrcweir     {
1526*cdf0e10cSrcweir         String name1 = mkName("mark");
1527*cdf0e10cSrcweir         String name2 = mkName("mark");
1528*cdf0e10cSrcweir         String name3 = mkName("mark");
1529*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1530*cdf0e10cSrcweir         root.appendChild( new BookmarkStartNode(name1) );
1531*cdf0e10cSrcweir         root.appendChild( new BookmarkNode(name2) );
1532*cdf0e10cSrcweir         root.appendChild( new BookmarkStartNode(name3) );
1533*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1534*cdf0e10cSrcweir         root.appendChild( new BookmarkEndNode(name1) );
1535*cdf0e10cSrcweir         root.appendChild( new TextNode("de") );
1536*cdf0e10cSrcweir         root.appendChild( new BookmarkEndNode(name3) );
1537*cdf0e10cSrcweir         doTest(root);
1538*cdf0e10cSrcweir     }
1539*cdf0e10cSrcweir 
1540*cdf0e10cSrcweir     @Test public void testBookmark2() throws Exception
1541*cdf0e10cSrcweir     {
1542*cdf0e10cSrcweir         String name1 = mkName("mark");
1543*cdf0e10cSrcweir         String name2 = mkName("mark");
1544*cdf0e10cSrcweir         String name3 = mkName("mark");
1545*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1546*cdf0e10cSrcweir         root.appendChild( new BookmarkStartNode(name1) );
1547*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1548*cdf0e10cSrcweir         root.appendChild( new BookmarkNode(name2) );
1549*cdf0e10cSrcweir         root.appendChild( new BookmarkStartNode(name3) );
1550*cdf0e10cSrcweir         root.appendChild( new BookmarkEndNode(name1) );
1551*cdf0e10cSrcweir         root.appendChild( new TextNode("de") );
1552*cdf0e10cSrcweir         root.appendChild( new BookmarkEndNode(name3) );
1553*cdf0e10cSrcweir         doTest(root);
1554*cdf0e10cSrcweir     }
1555*cdf0e10cSrcweir 
1556*cdf0e10cSrcweir     @Test public void testRefMark2() throws Exception
1557*cdf0e10cSrcweir     {
1558*cdf0e10cSrcweir         String name1 = mkName("refmark");
1559*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1560*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkStartNode(name1) );
1561*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1562*cdf0e10cSrcweir         // BUG: #i102541# (this is actually not unoportenum's fault)
1563*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkEndNode(name1) );
1564*cdf0e10cSrcweir         root.appendChild( new TextNode("de") );
1565*cdf0e10cSrcweir         doTest(root);
1566*cdf0e10cSrcweir     }
1567*cdf0e10cSrcweir 
1568*cdf0e10cSrcweir     @Test public void testRefMark3() throws Exception
1569*cdf0e10cSrcweir     {
1570*cdf0e10cSrcweir         // BUG: #i107672# (non-deterministic; depends on pointer ordering)
1571*cdf0e10cSrcweir         String name1 = mkName("refmark");
1572*cdf0e10cSrcweir         String name2 = mkName("refmark");
1573*cdf0e10cSrcweir         String name3 = mkName("refmark");
1574*cdf0e10cSrcweir         String name4 = mkName("refmark");
1575*cdf0e10cSrcweir         String name5 = mkName("refmark");
1576*cdf0e10cSrcweir         String name6 = mkName("refmark");
1577*cdf0e10cSrcweir         String name7 = mkName("refmark");
1578*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1579*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkStartNode(name1) );
1580*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkStartNode(name2) );
1581*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkStartNode(name3) );
1582*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkStartNode(name4) );
1583*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkStartNode(name5) );
1584*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkStartNode(name6) );
1585*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkStartNode(name7) );
1586*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1587*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkEndNode(name7) );
1588*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkEndNode(name6) );
1589*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkEndNode(name5) );
1590*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkEndNode(name4) );
1591*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkEndNode(name3) );
1592*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkEndNode(name2) );
1593*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkEndNode(name1) );
1594*cdf0e10cSrcweir         root.appendChild( new TextNode("de") );
1595*cdf0e10cSrcweir         doTest(root);
1596*cdf0e10cSrcweir     }
1597*cdf0e10cSrcweir 
1598*cdf0e10cSrcweir     @Test public void testToxMark2() throws Exception
1599*cdf0e10cSrcweir     {
1600*cdf0e10cSrcweir         String name1 = mkName("toxmark");
1601*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1602*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkStartNode(name1) );
1603*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1604*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkEndNode(name1) );
1605*cdf0e10cSrcweir         root.appendChild( new TextNode("de") );
1606*cdf0e10cSrcweir         doTest(root);
1607*cdf0e10cSrcweir     }
1608*cdf0e10cSrcweir 
1609*cdf0e10cSrcweir     @Test public void testToxMark3() throws Exception
1610*cdf0e10cSrcweir     {
1611*cdf0e10cSrcweir         // BUG: #i107672# (non-deterministic; depends on pointer ordering)
1612*cdf0e10cSrcweir         String name1 = mkName("toxmark");
1613*cdf0e10cSrcweir         String name2 = mkName("toxmark");
1614*cdf0e10cSrcweir         String name3 = mkName("toxmark");
1615*cdf0e10cSrcweir         String name4 = mkName("toxmark");
1616*cdf0e10cSrcweir         String name5 = mkName("toxmark");
1617*cdf0e10cSrcweir         String name6 = mkName("toxmark");
1618*cdf0e10cSrcweir         String name7 = mkName("toxmark");
1619*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1620*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkStartNode(name1) );
1621*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkStartNode(name2) );
1622*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkStartNode(name3) );
1623*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkStartNode(name4) );
1624*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkStartNode(name5) );
1625*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkStartNode(name6) );
1626*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkStartNode(name7) );
1627*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1628*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkEndNode(name7) );
1629*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkEndNode(name6) );
1630*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkEndNode(name5) );
1631*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkEndNode(name4) );
1632*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkEndNode(name3) );
1633*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkEndNode(name2) );
1634*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkEndNode(name1) );
1635*cdf0e10cSrcweir         root.appendChild( new TextNode("de") );
1636*cdf0e10cSrcweir         doTest(root);
1637*cdf0e10cSrcweir     }
1638*cdf0e10cSrcweir 
1639*cdf0e10cSrcweir     @Test public void testMarks1() throws Exception
1640*cdf0e10cSrcweir     {
1641*cdf0e10cSrcweir         String name1 = mkName("bookmark");
1642*cdf0e10cSrcweir         String name2 = mkName("toxmark");
1643*cdf0e10cSrcweir         String name3 = mkName("refmark");
1644*cdf0e10cSrcweir         String name4 = mkName("toxmark");
1645*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1646*cdf0e10cSrcweir         root.appendChild( new BookmarkStartNode(name1) );
1647*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkNode(name2) );
1648*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkStartNode(name3) );
1649*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1650*cdf0e10cSrcweir         root.appendChild( new BookmarkEndNode(name1) );
1651*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkStartNode(name4) );
1652*cdf0e10cSrcweir         root.appendChild( new TextNode("de") );
1653*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkEndNode(name4) );
1654*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkEndNode(name3) );
1655*cdf0e10cSrcweir         doTest(root);
1656*cdf0e10cSrcweir     }
1657*cdf0e10cSrcweir 
1658*cdf0e10cSrcweir     @Test public void testMarks2() throws Exception
1659*cdf0e10cSrcweir     {
1660*cdf0e10cSrcweir         String name1 = mkName("bookmark");
1661*cdf0e10cSrcweir         String name2 = mkName("refmark");
1662*cdf0e10cSrcweir         String name3 = mkName("refmark");
1663*cdf0e10cSrcweir         String name4 = mkName("toxmark");
1664*cdf0e10cSrcweir         String name5 = mkName("refmark");
1665*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1666*cdf0e10cSrcweir         root.appendChild( new BookmarkStartNode(name1) );
1667*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkNode(name2) );
1668*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkStartNode(name3) );
1669*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1670*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkStartNode(name4) );
1671*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkStartNode(name5) );
1672*cdf0e10cSrcweir         // BUG: #i102541# (this is actually not unoportenum's fault)
1673*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkEndNode(name3) );
1674*cdf0e10cSrcweir         root.appendChild( new TextNode("de") );
1675*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkEndNode(name4) );
1676*cdf0e10cSrcweir         root.appendChild( new BookmarkEndNode(name1) );
1677*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkEndNode(name5) );
1678*cdf0e10cSrcweir         doTest(root);
1679*cdf0e10cSrcweir     }
1680*cdf0e10cSrcweir 
1681*cdf0e10cSrcweir     @Test public void testMarks3() throws Exception
1682*cdf0e10cSrcweir     {
1683*cdf0e10cSrcweir         String name1 = mkName("bookmark");
1684*cdf0e10cSrcweir         String name2 = mkName("refmark");
1685*cdf0e10cSrcweir         String name3 = mkName("refmark");
1686*cdf0e10cSrcweir         String name4 = mkName("toxmark");
1687*cdf0e10cSrcweir         String name5 = mkName("refmark");
1688*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1689*cdf0e10cSrcweir         root.appendChild( new BookmarkStartNode(name1) );
1690*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkNode(name2) );
1691*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkStartNode(name3) );
1692*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1693*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkStartNode(name4) );
1694*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkStartNode(name5) );
1695*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkEndNode(name3) );
1696*cdf0e10cSrcweir         root.appendChild( new TextNode("de") );
1697*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkEndNode(name4) );
1698*cdf0e10cSrcweir         root.appendChild( new BookmarkEndNode(name1) );
1699*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkEndNode(name5) );
1700*cdf0e10cSrcweir         doTest(root);
1701*cdf0e10cSrcweir     }
1702*cdf0e10cSrcweir 
1703*cdf0e10cSrcweir     @Test public void testFrameMark1() throws Exception
1704*cdf0e10cSrcweir     {
1705*cdf0e10cSrcweir         String name1 = mkName("bookmark");
1706*cdf0e10cSrcweir         String name2 = mkName("frame");
1707*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1708*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1709*cdf0e10cSrcweir         root.appendChild( new BookmarkNode(name1) );
1710*cdf0e10cSrcweir         root.appendChild( new TextNode("de") );
1711*cdf0e10cSrcweir         root.appendChild( new FrameNode(name2, AS_CHARACTER) );
1712*cdf0e10cSrcweir         doTest(root);
1713*cdf0e10cSrcweir     }
1714*cdf0e10cSrcweir 
1715*cdf0e10cSrcweir     @Test public void testFrameMark2() throws Exception
1716*cdf0e10cSrcweir     {
1717*cdf0e10cSrcweir         // BUG: #i98530#
1718*cdf0e10cSrcweir         String name1 = mkName("bookmark");
1719*cdf0e10cSrcweir         String name2 = mkName("frame");
1720*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1721*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1722*cdf0e10cSrcweir         root.appendChild( new BookmarkNode(name1) );
1723*cdf0e10cSrcweir         root.appendChild( new TextNode("de") );
1724*cdf0e10cSrcweir         root.appendChild( new FrameNode(name2, AT_CHARACTER) );
1725*cdf0e10cSrcweir         doTest(root);
1726*cdf0e10cSrcweir     }
1727*cdf0e10cSrcweir 
1728*cdf0e10cSrcweir     @Test public void testFrameMark3() throws Exception
1729*cdf0e10cSrcweir     {
1730*cdf0e10cSrcweir         String name1 = mkName("frame");
1731*cdf0e10cSrcweir         String name2 = mkName("bookmark");
1732*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1733*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1734*cdf0e10cSrcweir         root.appendChild( new FrameNode(name1, AS_CHARACTER) );
1735*cdf0e10cSrcweir         root.appendChild( new TextNode("de") );
1736*cdf0e10cSrcweir         root.appendChild( new BookmarkNode(name2) );
1737*cdf0e10cSrcweir         doTest(root);
1738*cdf0e10cSrcweir     }
1739*cdf0e10cSrcweir 
1740*cdf0e10cSrcweir     @Test public void testFrameMark4() throws Exception
1741*cdf0e10cSrcweir     {
1742*cdf0e10cSrcweir         String name1 = mkName("frame");
1743*cdf0e10cSrcweir         String name2 = mkName("bookmark");
1744*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1745*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1746*cdf0e10cSrcweir         root.appendChild( new FrameNode(name1, AT_CHARACTER) );
1747*cdf0e10cSrcweir         root.appendChild( new TextNode("de") );
1748*cdf0e10cSrcweir         root.appendChild( new BookmarkNode(name2) );
1749*cdf0e10cSrcweir         doTest(root);
1750*cdf0e10cSrcweir     }
1751*cdf0e10cSrcweir 
1752*cdf0e10cSrcweir     @Test public void testFrames1() throws Exception
1753*cdf0e10cSrcweir     {
1754*cdf0e10cSrcweir         String name1 = mkName("frame");
1755*cdf0e10cSrcweir         String name2 = mkName("frame");
1756*cdf0e10cSrcweir         String name3 = mkName("frame");
1757*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1758*cdf0e10cSrcweir         root.appendChild( new FrameNode(name1, AT_CHARACTER) );
1759*cdf0e10cSrcweir         root.appendChild( new FrameNode(name2, AT_CHARACTER) );
1760*cdf0e10cSrcweir         root.appendChild( new FrameNode(name3, AT_CHARACTER) );
1761*cdf0e10cSrcweir         doTest(root);
1762*cdf0e10cSrcweir     }
1763*cdf0e10cSrcweir 
1764*cdf0e10cSrcweir     @Test public void testFrames2() throws Exception
1765*cdf0e10cSrcweir     {
1766*cdf0e10cSrcweir         String name1 = mkName("frame");
1767*cdf0e10cSrcweir         String name2 = mkName("frame");
1768*cdf0e10cSrcweir         String name3 = mkName("frame");
1769*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1770*cdf0e10cSrcweir         root.appendChild( new FrameNode(name1, AS_CHARACTER) );
1771*cdf0e10cSrcweir         root.appendChild( new FrameNode(name2, AS_CHARACTER) );
1772*cdf0e10cSrcweir         root.appendChild( new FrameNode(name3, AS_CHARACTER) );
1773*cdf0e10cSrcweir         doTest(root);
1774*cdf0e10cSrcweir     }
1775*cdf0e10cSrcweir 
1776*cdf0e10cSrcweir     @Test public void testFrames3() throws Exception
1777*cdf0e10cSrcweir     {
1778*cdf0e10cSrcweir         String name1 = mkName("frame");
1779*cdf0e10cSrcweir         String name2 = mkName("frame");
1780*cdf0e10cSrcweir         String name3 = mkName("frame");
1781*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1782*cdf0e10cSrcweir         root.appendChild( new FrameNode(name1, AT_CHARACTER) );
1783*cdf0e10cSrcweir         root.appendChild( new FrameNode(name2, AS_CHARACTER) );
1784*cdf0e10cSrcweir         root.appendChild( new FrameNode(name3, AT_CHARACTER) );
1785*cdf0e10cSrcweir         doTest(root);
1786*cdf0e10cSrcweir     }
1787*cdf0e10cSrcweir 
1788*cdf0e10cSrcweir     @Test public void testFrames4() throws Exception
1789*cdf0e10cSrcweir     {
1790*cdf0e10cSrcweir         String name1 = mkName("frame");
1791*cdf0e10cSrcweir         String name2 = mkName("frame");
1792*cdf0e10cSrcweir         String name3 = mkName("frame");
1793*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1794*cdf0e10cSrcweir         root.appendChild( new FrameNode(name1, AT_CHARACTER) );
1795*cdf0e10cSrcweir         root.appendChild( new FrameNode(name2, AT_CHARACTER) );
1796*cdf0e10cSrcweir         root.appendChild( new FrameNode(name3, AS_CHARACTER) );
1797*cdf0e10cSrcweir         doTest(root);
1798*cdf0e10cSrcweir     }
1799*cdf0e10cSrcweir 
1800*cdf0e10cSrcweir     @Test public void testFrames5() throws Exception
1801*cdf0e10cSrcweir     {
1802*cdf0e10cSrcweir         String name1 = mkName("frame");
1803*cdf0e10cSrcweir         String name2 = mkName("frame");
1804*cdf0e10cSrcweir         String name3 = mkName("frame");
1805*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1806*cdf0e10cSrcweir         root.appendChild( new FrameNode(name1, AS_CHARACTER) );
1807*cdf0e10cSrcweir         root.appendChild( new FrameNode(name2, AT_CHARACTER) );
1808*cdf0e10cSrcweir         root.appendChild( new FrameNode(name3, AT_CHARACTER) );
1809*cdf0e10cSrcweir         doTest(root);
1810*cdf0e10cSrcweir     }
1811*cdf0e10cSrcweir 
1812*cdf0e10cSrcweir     @Test public void testRubyHyperlink1() throws Exception
1813*cdf0e10cSrcweir     {
1814*cdf0e10cSrcweir         String name1 = mkName("ruby");
1815*cdf0e10cSrcweir         String name2 = mkName("url");
1816*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1817*cdf0e10cSrcweir         TreeNode ruby = new RubyNode(name1);
1818*cdf0e10cSrcweir         TreeNode href = new HyperlinkNode(name2);
1819*cdf0e10cSrcweir         href.appendChild( new TextNode("abc") );
1820*cdf0e10cSrcweir         ruby.appendChild(href);
1821*cdf0e10cSrcweir         root.appendChild(ruby);
1822*cdf0e10cSrcweir         doTest(root);
1823*cdf0e10cSrcweir     }
1824*cdf0e10cSrcweir 
1825*cdf0e10cSrcweir     @Test public void testRubyHyperlink2() throws Exception
1826*cdf0e10cSrcweir     {
1827*cdf0e10cSrcweir         String name1 = mkName("url");
1828*cdf0e10cSrcweir         String name2 = mkName("ruby");
1829*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1830*cdf0e10cSrcweir         TreeNode href = new HyperlinkNode(name1);
1831*cdf0e10cSrcweir         TreeNode ruby = new RubyNode(name2);
1832*cdf0e10cSrcweir         ruby.appendChild( new TextNode("abc") );
1833*cdf0e10cSrcweir         href.appendChild(ruby);
1834*cdf0e10cSrcweir         root.appendChild(href);
1835*cdf0e10cSrcweir         doTest(root);
1836*cdf0e10cSrcweir     }
1837*cdf0e10cSrcweir 
1838*cdf0e10cSrcweir     @Test public void testEnd1() throws Exception
1839*cdf0e10cSrcweir     {
1840*cdf0e10cSrcweir         String name1 = mkName("bookmark");
1841*cdf0e10cSrcweir         String name2 = mkName("toxmark");
1842*cdf0e10cSrcweir         String name3 = mkName("refmark");
1843*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1844*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1845*cdf0e10cSrcweir         root.appendChild( new BookmarkNode(name1) );
1846*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkNode(name2) );
1847*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkNode(name3) );
1848*cdf0e10cSrcweir         doTest(root);
1849*cdf0e10cSrcweir     }
1850*cdf0e10cSrcweir 
1851*cdf0e10cSrcweir     @Test public void testEnd2() throws Exception
1852*cdf0e10cSrcweir     {
1853*cdf0e10cSrcweir         String name1 = mkName("bookmark");
1854*cdf0e10cSrcweir         String name2 = mkName("frame");
1855*cdf0e10cSrcweir         String name3 = mkName("refmark");
1856*cdf0e10cSrcweir         String name4 = mkName("frame");
1857*cdf0e10cSrcweir         String name5 = mkName("frame");
1858*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1859*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1860*cdf0e10cSrcweir         root.appendChild( new BookmarkNode(name1) );
1861*cdf0e10cSrcweir         root.appendChild( new FrameNode(name2, AT_CHARACTER) );
1862*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkNode(name3) );
1863*cdf0e10cSrcweir         root.appendChild( new FrameNode(name4, AT_CHARACTER) );
1864*cdf0e10cSrcweir         root.appendChild( new FrameNode(name5, AT_CHARACTER) );
1865*cdf0e10cSrcweir         doTest(root);
1866*cdf0e10cSrcweir     }
1867*cdf0e10cSrcweir 
1868*cdf0e10cSrcweir     @Test public void testEnd3() throws Exception
1869*cdf0e10cSrcweir     {
1870*cdf0e10cSrcweir         String name1 = mkName("ftn");
1871*cdf0e10cSrcweir         String name2 = mkName("toxmark");
1872*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1873*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1874*cdf0e10cSrcweir         root.appendChild( new FootnoteNode(name1) );
1875*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkNode(name2) );
1876*cdf0e10cSrcweir         doTest(root);
1877*cdf0e10cSrcweir     }
1878*cdf0e10cSrcweir 
1879*cdf0e10cSrcweir     @Test public void testEnd4() throws Exception
1880*cdf0e10cSrcweir     {
1881*cdf0e10cSrcweir         String name1 = mkName("bookmark");
1882*cdf0e10cSrcweir         String name2 = mkName("frame");
1883*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1884*cdf0e10cSrcweir         root.appendChild( new BookmarkStartNode(name1) );
1885*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1886*cdf0e10cSrcweir         root.appendChild( new FrameNode(name2, AS_CHARACTER) );
1887*cdf0e10cSrcweir         root.appendChild( new BookmarkEndNode(name1) );
1888*cdf0e10cSrcweir         doTest(root);
1889*cdf0e10cSrcweir     }
1890*cdf0e10cSrcweir 
1891*cdf0e10cSrcweir     @Test public void testEnd5() throws Exception
1892*cdf0e10cSrcweir     {
1893*cdf0e10cSrcweir         String name1 = mkName("refmark");
1894*cdf0e10cSrcweir         String name2 = mkName("ruby");
1895*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1896*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkStartNode(name1) );
1897*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1898*cdf0e10cSrcweir         TreeNode ruby = new RubyNode(name2);
1899*cdf0e10cSrcweir         ruby.appendChild( new TextFieldNode("de") );
1900*cdf0e10cSrcweir         root.appendChild(ruby);
1901*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkEndNode(name1) );
1902*cdf0e10cSrcweir         doTest(root);
1903*cdf0e10cSrcweir     }
1904*cdf0e10cSrcweir 
1905*cdf0e10cSrcweir     @Test public void testEmpty1() throws Exception
1906*cdf0e10cSrcweir     {
1907*cdf0e10cSrcweir         String name1 = mkName("refmark");
1908*cdf0e10cSrcweir         String name2 = mkName("toxmark");
1909*cdf0e10cSrcweir         String name3 = mkName("bookmark");
1910*cdf0e10cSrcweir         String name4 = mkName("frame");
1911*cdf0e10cSrcweir         String name7 = mkName("refmark");
1912*cdf0e10cSrcweir         String name8 = mkName("toxmark");
1913*cdf0e10cSrcweir         String name9 = mkName("bookmark");
1914*cdf0e10cSrcweir         String nameA = mkName("frame");
1915*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1916*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkNode(name1) );
1917*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkNode(name2) );
1918*cdf0e10cSrcweir         root.appendChild( new BookmarkNode(name3) );
1919*cdf0e10cSrcweir         root.appendChild( new FrameNode(name4, AT_CHARACTER) );
1920*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkNode(name7) );
1921*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkNode(name8) );
1922*cdf0e10cSrcweir         root.appendChild( new BookmarkNode(name9) );
1923*cdf0e10cSrcweir         root.appendChild( new FrameNode(nameA, AT_CHARACTER) );
1924*cdf0e10cSrcweir         doTest(root);
1925*cdf0e10cSrcweir     }
1926*cdf0e10cSrcweir 
1927*cdf0e10cSrcweir     @Test public void testEmpty2() throws Exception
1928*cdf0e10cSrcweir     {
1929*cdf0e10cSrcweir         String name3 = mkName("bookmark");
1930*cdf0e10cSrcweir         String name4 = mkName("frame");
1931*cdf0e10cSrcweir         String name9 = mkName("bookmark");
1932*cdf0e10cSrcweir         String nameA = mkName("frame");
1933*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1934*cdf0e10cSrcweir         root.appendChild( new BookmarkNode(name3) );
1935*cdf0e10cSrcweir         root.appendChild( new FrameNode(name4, AT_CHARACTER) );
1936*cdf0e10cSrcweir         root.appendChild( new BookmarkNode(name9) );
1937*cdf0e10cSrcweir         root.appendChild( new FrameNode(nameA, AT_CHARACTER) );
1938*cdf0e10cSrcweir         doTest(root);
1939*cdf0e10cSrcweir     }
1940*cdf0e10cSrcweir 
1941*cdf0e10cSrcweir     @Test public void testEmpty3() throws Exception
1942*cdf0e10cSrcweir     {
1943*cdf0e10cSrcweir         String name1 = mkName("refmark");
1944*cdf0e10cSrcweir         String name2 = mkName("toxmark");
1945*cdf0e10cSrcweir         String name3 = mkName("bookmark");
1946*cdf0e10cSrcweir         String name4 = mkName("frame");
1947*cdf0e10cSrcweir         String name5 = mkName("url");
1948*cdf0e10cSrcweir         String name6 = mkName("ruby");
1949*cdf0e10cSrcweir         String name7 = mkName("refmark");
1950*cdf0e10cSrcweir         String name8 = mkName("toxmark");
1951*cdf0e10cSrcweir         String name9 = mkName("bookmark");
1952*cdf0e10cSrcweir         String nameA = mkName("frame");
1953*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1954*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkNode(name1) );
1955*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkNode(name2) );
1956*cdf0e10cSrcweir         root.appendChild( new BookmarkNode(name3) );
1957*cdf0e10cSrcweir         root.appendChild( new FrameNode(name4, AT_CHARACTER) );
1958*cdf0e10cSrcweir         /* currently empty hyperlinks may get eaten...
1959*cdf0e10cSrcweir         TreeNode href = new HyperlinkNode(name5);
1960*cdf0e10cSrcweir         href.appendChild( new TextNode("") );
1961*cdf0e10cSrcweir         root.appendChild(href);
1962*cdf0e10cSrcweir         */
1963*cdf0e10cSrcweir         TreeNode ruby = new RubyNode(name6);
1964*cdf0e10cSrcweir         root.appendChild(ruby);
1965*cdf0e10cSrcweir         root.appendChild( new ReferenceMarkNode(name7) );
1966*cdf0e10cSrcweir         root.appendChild( new DocumentIndexMarkNode(name8) );
1967*cdf0e10cSrcweir         root.appendChild( new BookmarkNode(name9) );
1968*cdf0e10cSrcweir         root.appendChild( new FrameNode(nameA, AT_CHARACTER) );
1969*cdf0e10cSrcweir         doTest(root);
1970*cdf0e10cSrcweir     }
1971*cdf0e10cSrcweir 
1972*cdf0e10cSrcweir     @Test public void test1() throws Exception
1973*cdf0e10cSrcweir     {
1974*cdf0e10cSrcweir         String name1 = mkName("frame");
1975*cdf0e10cSrcweir         String name2 = mkName("bookmark");
1976*cdf0e10cSrcweir         String name3 = mkName("ruby");
1977*cdf0e10cSrcweir         String name4 = mkName("ftn");
1978*cdf0e10cSrcweir         String name5 = mkName("frame");
1979*cdf0e10cSrcweir         TreeNode root = new TreeNode();
1980*cdf0e10cSrcweir         root.appendChild( new FrameNode(name1, AT_CHARACTER) );
1981*cdf0e10cSrcweir         root.appendChild( new BookmarkStartNode(name2) );
1982*cdf0e10cSrcweir         root.appendChild( new TextNode("abc") );
1983*cdf0e10cSrcweir         TreeNode ruby = new RubyNode(name3);
1984*cdf0e10cSrcweir         ruby.appendChild( new TextNode("de") );
1985*cdf0e10cSrcweir         ruby.appendChild( new FootnoteNode(name4) );
1986*cdf0e10cSrcweir         ruby.appendChild( new BookmarkEndNode(name2) );
1987*cdf0e10cSrcweir         root.appendChild(ruby);
1988*cdf0e10cSrcweir         root.appendChild( new TextNode("fg") );
1989*cdf0e10cSrcweir         root.appendChild( new FrameNode(name5, AT_CHARACTER) );
1990*cdf0e10cSrcweir         root.appendChild( new TextFieldNode("h") );
1991*cdf0e10cSrcweir         doTest(root);
1992*cdf0e10cSrcweir     }
1993*cdf0e10cSrcweir 
1994*cdf0e10cSrcweir     /* some range tests for the insertion: these are for the current
1995*cdf0e10cSrcweir        API which treats hyperlinks and rubys not as entities, but as formatting
1996*cdf0e10cSrcweir        attributes; if these ever become entities, they should not be split!
1997*cdf0e10cSrcweir      */
1998*cdf0e10cSrcweir 
1999*cdf0e10cSrcweir     @Test public void testRange1() throws Exception
2000*cdf0e10cSrcweir     {
2001*cdf0e10cSrcweir         String name1 = mkName("url");
2002*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2003*cdf0e10cSrcweir         TreeNode text = new TextNode("12345");
2004*cdf0e10cSrcweir         inserter.insertRange(new Range(0, 0, text));
2005*cdf0e10cSrcweir         TreeNode url1 = new HyperlinkNode(name1);
2006*cdf0e10cSrcweir         Range range1 = new Range(0, 5, url1);
2007*cdf0e10cSrcweir         inserter.insertRange(range1);
2008*cdf0e10cSrcweir         TreeNode root = new TreeNode();
2009*cdf0e10cSrcweir         root.appendChild( url1 );
2010*cdf0e10cSrcweir         url1.appendChild( text );
2011*cdf0e10cSrcweir         doTest(root, false);
2012*cdf0e10cSrcweir     }
2013*cdf0e10cSrcweir 
2014*cdf0e10cSrcweir     @Test public void testRangeHyperlinkHyperlink() throws Exception
2015*cdf0e10cSrcweir     {
2016*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2017*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2018*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2019*cdf0e10cSrcweir         TreeNode url1 = new HyperlinkNode( mkName("url") );
2020*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 4, url1) );
2021*cdf0e10cSrcweir         // overlap left
2022*cdf0e10cSrcweir         TreeNode url2 = new HyperlinkNode( mkName("url") );
2023*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 2, url2) );
2024*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2025*cdf0e10cSrcweir             .appendChild( url2.dup().appendChild( new TextNode("12") ) )
2026*cdf0e10cSrcweir             .appendChild( url1.dup().appendChild( new TextNode("34") ) )
2027*cdf0e10cSrcweir             .appendChild( new TextNode("56789") );
2028*cdf0e10cSrcweir         doTest(root, false);
2029*cdf0e10cSrcweir         // overlap right
2030*cdf0e10cSrcweir         TreeNode url3 = new HyperlinkNode( mkName("url") );
2031*cdf0e10cSrcweir         inserter.insertRange( new Range(3, 7, url3) );
2032*cdf0e10cSrcweir         root = new TreeNode()
2033*cdf0e10cSrcweir             .appendChild( url2.dup().appendChild( new TextNode("12") ) )
2034*cdf0e10cSrcweir             .appendChild( url1.dup().appendChild( new TextNode("3") ) )
2035*cdf0e10cSrcweir             .appendChild( url3.dup().appendChild( new TextNode("4567") ) )
2036*cdf0e10cSrcweir             .appendChild( new TextNode("89") );
2037*cdf0e10cSrcweir         doTest(root, false);
2038*cdf0e10cSrcweir         // around
2039*cdf0e10cSrcweir         TreeNode url4 = new HyperlinkNode( mkName("url") );
2040*cdf0e10cSrcweir         inserter.insertRange( new Range(3, 7, url4) );
2041*cdf0e10cSrcweir         root = new TreeNode()
2042*cdf0e10cSrcweir             .appendChild( url2.dup().appendChild( new TextNode("12") ) )
2043*cdf0e10cSrcweir             .appendChild( url1.dup().appendChild( new TextNode("3") ) )
2044*cdf0e10cSrcweir             .appendChild( url4.dup().appendChild( new TextNode("4567") ) )
2045*cdf0e10cSrcweir             .appendChild( new TextNode("89") );
2046*cdf0e10cSrcweir         doTest(root, false);
2047*cdf0e10cSrcweir         // inside
2048*cdf0e10cSrcweir         TreeNode url5 = new HyperlinkNode( mkName("url") );
2049*cdf0e10cSrcweir         inserter.insertRange( new Range(4, 6, url5) );
2050*cdf0e10cSrcweir         root = new TreeNode()
2051*cdf0e10cSrcweir             .appendChild( url2.dup().appendChild( new TextNode("12") ) )
2052*cdf0e10cSrcweir             .appendChild( url1.dup().appendChild( new TextNode("3") ) )
2053*cdf0e10cSrcweir             .appendChild( url4.dup().appendChild( new TextNode("4") ) )
2054*cdf0e10cSrcweir             .appendChild( url5.dup().appendChild( new TextNode("56") ) )
2055*cdf0e10cSrcweir             .appendChild( url4.dup().appendChild( new TextNode("7") ) )
2056*cdf0e10cSrcweir             .appendChild( new TextNode("89") );
2057*cdf0e10cSrcweir         doTest(root, false);
2058*cdf0e10cSrcweir         // empty
2059*cdf0e10cSrcweir         TreeNode url6 = new HyperlinkNode( mkName("url") );
2060*cdf0e10cSrcweir         inserter.insertRange( new Range(7, 7, url6) );
2061*cdf0e10cSrcweir         root = new TreeNode()
2062*cdf0e10cSrcweir             .appendChild( url2.dup().appendChild( new TextNode("12") ) )
2063*cdf0e10cSrcweir             .appendChild( url1.dup().appendChild( new TextNode("3") ) )
2064*cdf0e10cSrcweir             .appendChild( url4.dup().appendChild( new TextNode("4") ) )
2065*cdf0e10cSrcweir             .appendChild( url5.dup().appendChild( new TextNode("56") ) )
2066*cdf0e10cSrcweir             .appendChild( url4.dup().appendChild( new TextNode("7") ) )
2067*cdf0e10cSrcweir // this one gets eaten, but we still need to test inserting it (#i106930#)
2068*cdf0e10cSrcweir //            .appendChild( url6.dup().appendChild( new TextNode("") ) )
2069*cdf0e10cSrcweir             .appendChild( new TextNode("89") );
2070*cdf0e10cSrcweir         doTest(root, false);
2071*cdf0e10cSrcweir     }
2072*cdf0e10cSrcweir 
2073*cdf0e10cSrcweir     @Test public void testRangeHyperlinkRuby() throws Exception
2074*cdf0e10cSrcweir     {
2075*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2076*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2077*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2078*cdf0e10cSrcweir         TreeNode url1 = new HyperlinkNode( mkName("url") );
2079*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 4, url1) );
2080*cdf0e10cSrcweir         // overlap left
2081*cdf0e10cSrcweir         TreeNode rby2 = new RubyNode( mkName("ruby") );
2082*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 2, rby2) );
2083*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2084*cdf0e10cSrcweir             .appendChild( rby2.dup()
2085*cdf0e10cSrcweir                 .appendChild( new TextNode("1") )
2086*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2087*cdf0e10cSrcweir             .appendChild( url1.dup().appendChild( new TextNode("34") ) )
2088*cdf0e10cSrcweir             .appendChild( new TextNode("56789") );
2089*cdf0e10cSrcweir         doTest(root, false);
2090*cdf0e10cSrcweir         // overlap right
2091*cdf0e10cSrcweir         TreeNode rby3 = new RubyNode( mkName("ruby") );
2092*cdf0e10cSrcweir         inserter.insertRange( new Range(3, 5, rby3) );
2093*cdf0e10cSrcweir         root = new TreeNode()
2094*cdf0e10cSrcweir             .appendChild( rby2.dup()
2095*cdf0e10cSrcweir                 .appendChild( new TextNode("1") )
2096*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2097*cdf0e10cSrcweir             .appendChild( url1.dup().appendChild( new TextNode("3") ) )
2098*cdf0e10cSrcweir             .appendChild( rby3.dup()
2099*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("4") ) )
2100*cdf0e10cSrcweir                 .appendChild( new TextNode("5") ) )
2101*cdf0e10cSrcweir             .appendChild( new TextNode("6789") );
2102*cdf0e10cSrcweir         doTest(root, false);
2103*cdf0e10cSrcweir         // around
2104*cdf0e10cSrcweir         TreeNode rby4 = new RubyNode( mkName("ruby") );
2105*cdf0e10cSrcweir         inserter.insertRange( new Range(2, 3, rby4) );
2106*cdf0e10cSrcweir         root = new TreeNode()
2107*cdf0e10cSrcweir             .appendChild( rby2.dup()
2108*cdf0e10cSrcweir                 .appendChild( new TextNode("1") )
2109*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2110*cdf0e10cSrcweir             .appendChild( rby4.dup()
2111*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("3") ) ) )
2112*cdf0e10cSrcweir             .appendChild( rby3.dup()
2113*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("4") ) )
2114*cdf0e10cSrcweir                 .appendChild( new TextNode("5") ) )
2115*cdf0e10cSrcweir             .appendChild( new TextNode("6789") );
2116*cdf0e10cSrcweir         doTest(root, false);
2117*cdf0e10cSrcweir         // inside
2118*cdf0e10cSrcweir         TreeNode url5 = new HyperlinkNode( mkName("url") );
2119*cdf0e10cSrcweir         inserter.insertRange( new Range(6, 9, url5) );
2120*cdf0e10cSrcweir         TreeNode rby6 = new RubyNode( mkName("ruby") );
2121*cdf0e10cSrcweir         inserter.insertRange( new Range(7, 8, rby6) );
2122*cdf0e10cSrcweir         root = new TreeNode()
2123*cdf0e10cSrcweir             .appendChild( rby2.dup()
2124*cdf0e10cSrcweir                 .appendChild( new TextNode("1") )
2125*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2126*cdf0e10cSrcweir             .appendChild( rby4.dup()
2127*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("3") ) ) )
2128*cdf0e10cSrcweir             .appendChild( rby3.dup()
2129*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("4") ) )
2130*cdf0e10cSrcweir                 .appendChild( new TextNode("5") ) )
2131*cdf0e10cSrcweir             .appendChild( new TextNode("6") )
2132*cdf0e10cSrcweir             .appendChild( url5.dup().appendChild( new TextNode("7") ) )
2133*cdf0e10cSrcweir             .appendChild( rby6.dup()
2134*cdf0e10cSrcweir                 .appendChild( url5.dup().appendChild( new TextNode("8") ) ) )
2135*cdf0e10cSrcweir             .appendChild( url5.dup().appendChild( new TextNode("9") ) );
2136*cdf0e10cSrcweir         doTest(root, false);
2137*cdf0e10cSrcweir     }
2138*cdf0e10cSrcweir 
2139*cdf0e10cSrcweir     @Test public void testRangeRubyHyperlink() throws Exception
2140*cdf0e10cSrcweir     {
2141*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2142*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2143*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2144*cdf0e10cSrcweir         TreeNode rby1 = new RubyNode( mkName("ruby") );
2145*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 6, rby1) );
2146*cdf0e10cSrcweir         // overlap left
2147*cdf0e10cSrcweir         TreeNode url2 = new HyperlinkNode( mkName("url") );
2148*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 3, url2) );
2149*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2150*cdf0e10cSrcweir             .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2151*cdf0e10cSrcweir             .appendChild( rby1.dup()
2152*cdf0e10cSrcweir                 .appendChild( url2.dup().appendChild( new TextNode("23") ) )
2153*cdf0e10cSrcweir                 .appendChild( new TextNode("456") ) )
2154*cdf0e10cSrcweir             .appendChild( new TextNode("789") );
2155*cdf0e10cSrcweir         doTest(root, false);
2156*cdf0e10cSrcweir         // overlap right
2157*cdf0e10cSrcweir         TreeNode url3 = new HyperlinkNode( mkName("url") );
2158*cdf0e10cSrcweir         inserter.insertRange( new Range(5, 7, url3) );
2159*cdf0e10cSrcweir         root = new TreeNode()
2160*cdf0e10cSrcweir             .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2161*cdf0e10cSrcweir             .appendChild( rby1.dup()
2162*cdf0e10cSrcweir                 .appendChild( url2.dup().appendChild( new TextNode("23") ) )
2163*cdf0e10cSrcweir                 .appendChild( new TextNode("45") )
2164*cdf0e10cSrcweir                 .appendChild( url3.dup().appendChild( new TextNode("6") ) ) )
2165*cdf0e10cSrcweir             .appendChild( url3.dup().appendChild( new TextNode("7") ) )
2166*cdf0e10cSrcweir             .appendChild( new TextNode("89") );
2167*cdf0e10cSrcweir         doTest(root, false);
2168*cdf0e10cSrcweir         // around (not quite, due to API)
2169*cdf0e10cSrcweir         TreeNode url4 = new HyperlinkNode( mkName("url") );
2170*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 8, url4) );
2171*cdf0e10cSrcweir         root = new TreeNode()
2172*cdf0e10cSrcweir             .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2173*cdf0e10cSrcweir             .appendChild( rby1.dup()
2174*cdf0e10cSrcweir                 .appendChild( url4.dup()
2175*cdf0e10cSrcweir                     .appendChild( new TextNode("23456") ) ) )
2176*cdf0e10cSrcweir             .appendChild( url4.dup().appendChild( new TextNode("78") ) )
2177*cdf0e10cSrcweir             .appendChild( new TextNode("9") );
2178*cdf0e10cSrcweir         doTest(root, false);
2179*cdf0e10cSrcweir         // inside
2180*cdf0e10cSrcweir         TreeNode url5 = new HyperlinkNode( mkName("url") );
2181*cdf0e10cSrcweir         inserter.insertRange( new Range(3, 5, url5) );
2182*cdf0e10cSrcweir         root = new TreeNode()
2183*cdf0e10cSrcweir             .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2184*cdf0e10cSrcweir             .appendChild( rby1.dup()
2185*cdf0e10cSrcweir                 .appendChild( url4.dup()
2186*cdf0e10cSrcweir                     .appendChild( new TextNode("23") ) )
2187*cdf0e10cSrcweir                 .appendChild( url5.dup()
2188*cdf0e10cSrcweir                     .appendChild( new TextNode("45") ) )
2189*cdf0e10cSrcweir                 .appendChild( url4.dup()
2190*cdf0e10cSrcweir                     .appendChild( new TextNode("6") ) ) )
2191*cdf0e10cSrcweir             .appendChild( url4.dup().appendChild( new TextNode("78") ) )
2192*cdf0e10cSrcweir             .appendChild( new TextNode("9") );
2193*cdf0e10cSrcweir         doTest(root, false);
2194*cdf0e10cSrcweir     }
2195*cdf0e10cSrcweir 
2196*cdf0e10cSrcweir     @Test public void testRangeRubyRuby() throws Exception
2197*cdf0e10cSrcweir     {
2198*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2199*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2200*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2201*cdf0e10cSrcweir         TreeNode rby1 = new RubyNode( mkName("ruby") );
2202*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 4, rby1) );
2203*cdf0e10cSrcweir         // overlap left
2204*cdf0e10cSrcweir         TreeNode rby2 = new RubyNode( mkName("ruby") );
2205*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 2, rby2) );
2206*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2207*cdf0e10cSrcweir             .appendChild( rby2.dup().appendChild( new TextNode("12") ) )
2208*cdf0e10cSrcweir             .appendChild( rby1.dup().appendChild( new TextNode("34") ) )
2209*cdf0e10cSrcweir             .appendChild( new TextNode("56789") );
2210*cdf0e10cSrcweir         doTest(root, false);
2211*cdf0e10cSrcweir         // overlap right
2212*cdf0e10cSrcweir         TreeNode rby3 = new RubyNode( mkName("ruby") );
2213*cdf0e10cSrcweir         inserter.insertRange( new Range(3, 7, rby3) );
2214*cdf0e10cSrcweir         root = new TreeNode()
2215*cdf0e10cSrcweir             .appendChild( rby2.dup().appendChild( new TextNode("12") ) )
2216*cdf0e10cSrcweir             .appendChild( rby1.dup().appendChild( new TextNode("3") ) )
2217*cdf0e10cSrcweir             .appendChild( rby3.dup().appendChild( new TextNode("4567") ) )
2218*cdf0e10cSrcweir             .appendChild( new TextNode("89") );
2219*cdf0e10cSrcweir         doTest(root, false);
2220*cdf0e10cSrcweir         // around
2221*cdf0e10cSrcweir         TreeNode rby4 = new RubyNode( mkName("ruby") );
2222*cdf0e10cSrcweir         inserter.insertRange( new Range(3, 7, rby4) );
2223*cdf0e10cSrcweir         root = new TreeNode()
2224*cdf0e10cSrcweir             .appendChild( rby2.dup().appendChild( new TextNode("12") ) )
2225*cdf0e10cSrcweir             .appendChild( rby1.dup().appendChild( new TextNode("3") ) )
2226*cdf0e10cSrcweir             .appendChild( rby4.dup().appendChild( new TextNode("4567") ) )
2227*cdf0e10cSrcweir             .appendChild( new TextNode("89") );
2228*cdf0e10cSrcweir         doTest(root, false);
2229*cdf0e10cSrcweir         // inside
2230*cdf0e10cSrcweir         TreeNode rby5 = new RubyNode( mkName("ruby") );
2231*cdf0e10cSrcweir         inserter.insertRange( new Range(4, 6, rby5) );
2232*cdf0e10cSrcweir         root = new TreeNode()
2233*cdf0e10cSrcweir             .appendChild( rby2.dup().appendChild( new TextNode("12") ) )
2234*cdf0e10cSrcweir             .appendChild( rby1.dup().appendChild( new TextNode("3") ) )
2235*cdf0e10cSrcweir             .appendChild( rby4.dup().appendChild( new TextNode("4") ) )
2236*cdf0e10cSrcweir             .appendChild( rby5.dup().appendChild( new TextNode("56") ) )
2237*cdf0e10cSrcweir             .appendChild( rby4.dup().appendChild( new TextNode("7") ) )
2238*cdf0e10cSrcweir             .appendChild( new TextNode("89") );
2239*cdf0e10cSrcweir         doTest(root, false);
2240*cdf0e10cSrcweir     }
2241*cdf0e10cSrcweir 
2242*cdf0e10cSrcweir     @Test public void testRangeHyperlinkMeta() throws Exception
2243*cdf0e10cSrcweir     {
2244*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2245*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2246*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2247*cdf0e10cSrcweir         TreeNode url1 = new HyperlinkNode( mkName("url") );
2248*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 4, url1) );
2249*cdf0e10cSrcweir         // overlap left
2250*cdf0e10cSrcweir         TreeNode met2 = new MetaNode( mkId("id") );
2251*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 2, met2) );
2252*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2253*cdf0e10cSrcweir             .appendChild( met2.dup()
2254*cdf0e10cSrcweir                 .appendChild( new TextNode("1") )
2255*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2256*cdf0e10cSrcweir             .appendChild( url1.dup().appendChild( new TextNode("34") ) )
2257*cdf0e10cSrcweir             .appendChild( new TextNode("56789") );
2258*cdf0e10cSrcweir         doTest(root, false);
2259*cdf0e10cSrcweir         // overlap right
2260*cdf0e10cSrcweir         TreeNode met3 = new MetaNode( mkId("id") );
2261*cdf0e10cSrcweir         inserter.insertRange( new Range(4/*-1*/, 6/*-1*/, met3) );
2262*cdf0e10cSrcweir         root = new TreeNode()
2263*cdf0e10cSrcweir             .appendChild( met2.dup()
2264*cdf0e10cSrcweir                 .appendChild( new TextNode("1") )
2265*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2266*cdf0e10cSrcweir             .appendChild( url1.dup().appendChild( new TextNode("3") ) )
2267*cdf0e10cSrcweir             .appendChild( met3.dup()
2268*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("4") ) )
2269*cdf0e10cSrcweir                 .appendChild( new TextNode("5") ) )
2270*cdf0e10cSrcweir             .appendChild( new TextNode("6789") );
2271*cdf0e10cSrcweir         doTest(root, false);
2272*cdf0e10cSrcweir         // around
2273*cdf0e10cSrcweir         TreeNode met4 = new MetaNode( mkId("id") );
2274*cdf0e10cSrcweir         inserter.insertRange( new Range(3/*-1*/, 4/*-1*/, met4) );
2275*cdf0e10cSrcweir         root = new TreeNode()
2276*cdf0e10cSrcweir             .appendChild( met2.dup()
2277*cdf0e10cSrcweir                 .appendChild( new TextNode("1") )
2278*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2279*cdf0e10cSrcweir             .appendChild( met4.dup()
2280*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("3") ) ) )
2281*cdf0e10cSrcweir             .appendChild( met3.dup()
2282*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("4") ) )
2283*cdf0e10cSrcweir                 .appendChild( new TextNode("5") ) )
2284*cdf0e10cSrcweir             .appendChild( new TextNode("6789") );
2285*cdf0e10cSrcweir         doTest(root, false);
2286*cdf0e10cSrcweir         // inside
2287*cdf0e10cSrcweir         TreeNode url5 = new HyperlinkNode( mkName("url") );
2288*cdf0e10cSrcweir         inserter.insertRange( new Range(9/*-3*/, 12/*-3*/, url5) );
2289*cdf0e10cSrcweir         TreeNode met6 = new MetaNode( mkId("id") );
2290*cdf0e10cSrcweir         inserter.insertRange( new Range(10/*-3*/, 11/*-3*/, met6) );
2291*cdf0e10cSrcweir         root = new TreeNode()
2292*cdf0e10cSrcweir             .appendChild( met2.dup()
2293*cdf0e10cSrcweir                 .appendChild( new TextNode("1") )
2294*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2295*cdf0e10cSrcweir             .appendChild( met4.dup()
2296*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("3") ) ) )
2297*cdf0e10cSrcweir             .appendChild( met3.dup()
2298*cdf0e10cSrcweir                 .appendChild( url1.dup().appendChild( new TextNode("4") ) )
2299*cdf0e10cSrcweir                 .appendChild( new TextNode("5") ) )
2300*cdf0e10cSrcweir             .appendChild( new TextNode("6") )
2301*cdf0e10cSrcweir             .appendChild( url5.dup().appendChild( new TextNode("7") ) )
2302*cdf0e10cSrcweir             .appendChild( met6.dup()
2303*cdf0e10cSrcweir                 .appendChild( url5.dup().appendChild( new TextNode("8") ) ) )
2304*cdf0e10cSrcweir             .appendChild( url5.dup().appendChild( new TextNode("9") ) );
2305*cdf0e10cSrcweir         doTest(root, false);
2306*cdf0e10cSrcweir     }
2307*cdf0e10cSrcweir 
2308*cdf0e10cSrcweir     @Test public void testRangeRubyMeta() throws Exception
2309*cdf0e10cSrcweir     {
2310*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2311*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2312*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2313*cdf0e10cSrcweir         TreeNode rby1 = new RubyNode( mkName("ruby") );
2314*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 4, rby1) );
2315*cdf0e10cSrcweir         // overlap left
2316*cdf0e10cSrcweir         TreeNode met2 = new MetaNode( mkId("id") );
2317*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 2, met2) );
2318*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2319*cdf0e10cSrcweir             .appendChild( met2.dup()
2320*cdf0e10cSrcweir                 .appendChild( new TextNode("1") )
2321*cdf0e10cSrcweir                 .appendChild( rby1.dup().appendChild( new TextNode("2") ) ) )
2322*cdf0e10cSrcweir             .appendChild( rby1.dup().appendChild( new TextNode("34") ) )
2323*cdf0e10cSrcweir             .appendChild( new TextNode("56789") );
2324*cdf0e10cSrcweir         doTest(root, false);
2325*cdf0e10cSrcweir         // overlap right
2326*cdf0e10cSrcweir         TreeNode met3 = new MetaNode( mkId("id") );
2327*cdf0e10cSrcweir         inserter.insertRange( new Range(4/*-1*/, 6/*-1*/, met3) );
2328*cdf0e10cSrcweir         root = new TreeNode()
2329*cdf0e10cSrcweir             .appendChild( met2.dup()
2330*cdf0e10cSrcweir                 .appendChild( new TextNode("1") )
2331*cdf0e10cSrcweir                 .appendChild( rby1.dup().appendChild( new TextNode("2") ) ) )
2332*cdf0e10cSrcweir             .appendChild( rby1.dup().appendChild( new TextNode("3") ) )
2333*cdf0e10cSrcweir             .appendChild( met3.dup()
2334*cdf0e10cSrcweir                 .appendChild( rby1.dup().appendChild( new TextNode("4") ) )
2335*cdf0e10cSrcweir                 .appendChild( new TextNode("5") ) )
2336*cdf0e10cSrcweir             .appendChild( new TextNode("6789") );
2337*cdf0e10cSrcweir         doTest(root, false);
2338*cdf0e10cSrcweir         // around
2339*cdf0e10cSrcweir         TreeNode met4 = new MetaNode( mkId("id") );
2340*cdf0e10cSrcweir         inserter.insertRange( new Range(3/*-1*/, 4/*-1*/, met4) );
2341*cdf0e10cSrcweir         root = new TreeNode()
2342*cdf0e10cSrcweir             .appendChild( met2.dup()
2343*cdf0e10cSrcweir                 .appendChild( new TextNode("1") )
2344*cdf0e10cSrcweir                 .appendChild( rby1.dup().appendChild( new TextNode("2") ) ) )
2345*cdf0e10cSrcweir             .appendChild( met4.dup()
2346*cdf0e10cSrcweir                 .appendChild( rby1.dup().appendChild( new TextNode("3") ) ) )
2347*cdf0e10cSrcweir             .appendChild( met3.dup()
2348*cdf0e10cSrcweir                 .appendChild( rby1.dup().appendChild( new TextNode("4") ) )
2349*cdf0e10cSrcweir                 .appendChild( new TextNode("5") ) )
2350*cdf0e10cSrcweir             .appendChild( new TextNode("6789") );
2351*cdf0e10cSrcweir         doTest(root, false);
2352*cdf0e10cSrcweir         // inside
2353*cdf0e10cSrcweir         TreeNode rby5 = new RubyNode( mkName("ruby") );
2354*cdf0e10cSrcweir         inserter.insertRange( new Range(9/*-3*/, 12/*-3*/, rby5) );
2355*cdf0e10cSrcweir         TreeNode met6 = new MetaNode( mkId("id") );
2356*cdf0e10cSrcweir         inserter.insertRange( new Range(10/*-3*/, 11/*-3*/, met6) );
2357*cdf0e10cSrcweir         root = new TreeNode()
2358*cdf0e10cSrcweir             .appendChild( met2.dup()
2359*cdf0e10cSrcweir                 .appendChild( new TextNode("1") )
2360*cdf0e10cSrcweir                 .appendChild( rby1.dup().appendChild( new TextNode("2") ) ) )
2361*cdf0e10cSrcweir             .appendChild( met4.dup()
2362*cdf0e10cSrcweir                 .appendChild( rby1.dup().appendChild( new TextNode("3") ) ) )
2363*cdf0e10cSrcweir             .appendChild( met3.dup()
2364*cdf0e10cSrcweir                 .appendChild( rby1.dup().appendChild( new TextNode("4") ) )
2365*cdf0e10cSrcweir                 .appendChild( new TextNode("5") ) )
2366*cdf0e10cSrcweir             .appendChild( new TextNode("6") )
2367*cdf0e10cSrcweir             .appendChild( rby5.dup()
2368*cdf0e10cSrcweir                 .appendChild( new TextNode("7") )
2369*cdf0e10cSrcweir                 .appendChild( met6.dup()
2370*cdf0e10cSrcweir                     .appendChild( new TextNode("8") ) )
2371*cdf0e10cSrcweir                 .appendChild( new TextNode("9") ) );
2372*cdf0e10cSrcweir         doTest(root, false);
2373*cdf0e10cSrcweir     }
2374*cdf0e10cSrcweir 
2375*cdf0e10cSrcweir     @Test public void testRangeMetaHyperlink() throws Exception
2376*cdf0e10cSrcweir     {
2377*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2378*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2379*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2380*cdf0e10cSrcweir         TreeNode met1 = new MetaNode( mkId("id") );
2381*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 6, met1) );
2382*cdf0e10cSrcweir         // overlap left
2383*cdf0e10cSrcweir         TreeNode url2 = new HyperlinkNode( mkName("url") );
2384*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 4/*-1*/, url2) );
2385*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2386*cdf0e10cSrcweir             .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2387*cdf0e10cSrcweir             .appendChild( met1.dup()
2388*cdf0e10cSrcweir                 .appendChild( url2.dup().appendChild( new TextNode("23") ) )
2389*cdf0e10cSrcweir                 .appendChild( new TextNode("456") ) )
2390*cdf0e10cSrcweir             .appendChild( new TextNode("789") );
2391*cdf0e10cSrcweir         doTest(root, false);
2392*cdf0e10cSrcweir         // overlap right
2393*cdf0e10cSrcweir         TreeNode url3 = new HyperlinkNode( mkName("url") );
2394*cdf0e10cSrcweir         inserter.insertRange( new Range(6/*-1*/, 8/*-1*/, url3) );
2395*cdf0e10cSrcweir         root = new TreeNode()
2396*cdf0e10cSrcweir             .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2397*cdf0e10cSrcweir             .appendChild( met1.dup()
2398*cdf0e10cSrcweir                 .appendChild( url2.dup().appendChild( new TextNode("23") ) )
2399*cdf0e10cSrcweir                 .appendChild( new TextNode("45") )
2400*cdf0e10cSrcweir                 .appendChild( url3.dup().appendChild( new TextNode("6") ) ) )
2401*cdf0e10cSrcweir             .appendChild( url3.dup().appendChild( new TextNode("7") ) )
2402*cdf0e10cSrcweir             .appendChild( new TextNode("89") );
2403*cdf0e10cSrcweir         doTest(root, false);
2404*cdf0e10cSrcweir         // around (not quite, due to API)
2405*cdf0e10cSrcweir         TreeNode url4 = new HyperlinkNode( mkName("url") );
2406*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 9/*-1*/, url4) );
2407*cdf0e10cSrcweir         root = new TreeNode()
2408*cdf0e10cSrcweir             .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2409*cdf0e10cSrcweir             .appendChild( met1.dup()
2410*cdf0e10cSrcweir                 .appendChild( url4.dup()
2411*cdf0e10cSrcweir                     .appendChild( new TextNode("23456") ) ) )
2412*cdf0e10cSrcweir             .appendChild( url4.dup().appendChild( new TextNode("78") ) )
2413*cdf0e10cSrcweir             .appendChild( new TextNode("9") );
2414*cdf0e10cSrcweir         doTest(root, false);
2415*cdf0e10cSrcweir         // inside
2416*cdf0e10cSrcweir         TreeNode url5 = new HyperlinkNode( mkName("url") );
2417*cdf0e10cSrcweir         inserter.insertRange( new Range(4/*-1*/, 6/*-1*/, url5) );
2418*cdf0e10cSrcweir         root = new TreeNode()
2419*cdf0e10cSrcweir             .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2420*cdf0e10cSrcweir             .appendChild( met1.dup()
2421*cdf0e10cSrcweir                 .appendChild( url4.dup()
2422*cdf0e10cSrcweir                     .appendChild( new TextNode("23") ) )
2423*cdf0e10cSrcweir                 .appendChild( url5.dup()
2424*cdf0e10cSrcweir                     .appendChild( new TextNode("45") ) )
2425*cdf0e10cSrcweir                 .appendChild( url4.dup()
2426*cdf0e10cSrcweir                     .appendChild( new TextNode("6") ) ) )
2427*cdf0e10cSrcweir             .appendChild( url4.dup().appendChild( new TextNode("78") ) )
2428*cdf0e10cSrcweir             .appendChild( new TextNode("9") );
2429*cdf0e10cSrcweir         doTest(root, false);
2430*cdf0e10cSrcweir     }
2431*cdf0e10cSrcweir 
2432*cdf0e10cSrcweir     @Test public void testRangeMetaRuby() throws Exception
2433*cdf0e10cSrcweir     {
2434*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2435*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2436*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2437*cdf0e10cSrcweir         TreeNode met1 = new MetaNode( mkId("id") );
2438*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 5, met1) );
2439*cdf0e10cSrcweir         // overlap left
2440*cdf0e10cSrcweir         TreeNode rby2 = new RubyNode( mkName("ruby") );
2441*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 3/*-1*/, rby2) );
2442*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2443*cdf0e10cSrcweir             .appendChild( rby2.dup().appendChild( new TextNode("1") ) )
2444*cdf0e10cSrcweir             .appendChild( met1.dup()
2445*cdf0e10cSrcweir                 .appendChild( rby2.dup().appendChild( new TextNode("2") ) )
2446*cdf0e10cSrcweir                 .appendChild( new TextNode("345") ) )
2447*cdf0e10cSrcweir             .appendChild( new TextNode("6789") );
2448*cdf0e10cSrcweir         doTest(root, false);
2449*cdf0e10cSrcweir         // overlap right
2450*cdf0e10cSrcweir         TreeNode rby3 = new RubyNode( mkName("ruby") );
2451*cdf0e10cSrcweir         inserter.insertRange( new Range(5/*-1*/, 7/*-1*/, rby3) );
2452*cdf0e10cSrcweir         root = new TreeNode()
2453*cdf0e10cSrcweir             .appendChild( rby2.dup().appendChild( new TextNode("1") ) )
2454*cdf0e10cSrcweir             .appendChild( met1.dup()
2455*cdf0e10cSrcweir                 .appendChild( rby2.dup().appendChild( new TextNode("2") ) )
2456*cdf0e10cSrcweir                 .appendChild( new TextNode("34") )
2457*cdf0e10cSrcweir                 .appendChild( rby3.dup().appendChild( new TextNode("5") ) ) )
2458*cdf0e10cSrcweir             .appendChild( rby3.dup().appendChild( new TextNode("6") ) )
2459*cdf0e10cSrcweir             .appendChild( new TextNode("789") );
2460*cdf0e10cSrcweir         doTest(root, false);
2461*cdf0e10cSrcweir         // around
2462*cdf0e10cSrcweir         TreeNode rby4 = new RubyNode( mkName("ruby") );
2463*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 7/*-1*/, rby4) );
2464*cdf0e10cSrcweir         root = new TreeNode()
2465*cdf0e10cSrcweir             .appendChild( rby2.dup().appendChild( new TextNode("1") ) )
2466*cdf0e10cSrcweir             .appendChild( rby4.dup()
2467*cdf0e10cSrcweir                 .appendChild( met1.dup()
2468*cdf0e10cSrcweir                     .appendChild( new TextNode("2345") ) )
2469*cdf0e10cSrcweir                 .appendChild( new TextNode("6") ) )
2470*cdf0e10cSrcweir             .appendChild( new TextNode("789") );
2471*cdf0e10cSrcweir         doTest(root, false);
2472*cdf0e10cSrcweir         // inside
2473*cdf0e10cSrcweir         TreeNode met5 = new MetaNode( mkId("id") );
2474*cdf0e10cSrcweir         inserter.insertRange( new Range(7/*-1*/, 9/*-1*/, met5) );
2475*cdf0e10cSrcweir         TreeNode rby6 = new RubyNode( mkName("ruby") );
2476*cdf0e10cSrcweir         inserter.insertRange( new Range(9/*-2*/, 10/*-2*/, rby6) );
2477*cdf0e10cSrcweir         root = new TreeNode()
2478*cdf0e10cSrcweir             .appendChild( rby2.dup().appendChild( new TextNode("1") ) )
2479*cdf0e10cSrcweir             .appendChild( rby4.dup()
2480*cdf0e10cSrcweir                 .appendChild( met1.dup()
2481*cdf0e10cSrcweir                     .appendChild( new TextNode("2345") ) )
2482*cdf0e10cSrcweir                 .appendChild( new TextNode("6") ) )
2483*cdf0e10cSrcweir             .appendChild( met5.dup()
2484*cdf0e10cSrcweir                 .appendChild( new TextNode("7") )
2485*cdf0e10cSrcweir                 .appendChild( rby6.dup()
2486*cdf0e10cSrcweir                     .appendChild( new TextNode("8") ) ) )
2487*cdf0e10cSrcweir             .appendChild( new TextNode("9") );
2488*cdf0e10cSrcweir         doTest(root, false);
2489*cdf0e10cSrcweir         // inside, with invalid range that includes the dummy char
2490*cdf0e10cSrcweir         TreeNode rby7 = new RubyNode( mkName("ruby") );
2491*cdf0e10cSrcweir         inserter.insertRange( new Range(7/*-1*/, 9/*-2*/, rby7) );
2492*cdf0e10cSrcweir         root = new TreeNode()
2493*cdf0e10cSrcweir             .appendChild( rby2.dup().appendChild( new TextNode("1") ) )
2494*cdf0e10cSrcweir             .appendChild( rby4.dup()
2495*cdf0e10cSrcweir                 .appendChild( met1.dup()
2496*cdf0e10cSrcweir                     .appendChild( new TextNode("2345") ) )
2497*cdf0e10cSrcweir                 .appendChild( new TextNode("6") ) )
2498*cdf0e10cSrcweir             .appendChild( met5.dup()
2499*cdf0e10cSrcweir                 .appendChild( rby7.dup()
2500*cdf0e10cSrcweir                     .appendChild( new TextNode("7") ) )
2501*cdf0e10cSrcweir                 .appendChild( rby6.dup()
2502*cdf0e10cSrcweir                     .appendChild( new TextNode("8") ) ) )
2503*cdf0e10cSrcweir             .appendChild( new TextNode("9") );
2504*cdf0e10cSrcweir         doTest(root, false);
2505*cdf0e10cSrcweir         // around, at same position as meta
2506*cdf0e10cSrcweir         TreeNode rby8 = new RubyNode( mkName("ruby") );
2507*cdf0e10cSrcweir         inserter.insertRange( new Range(7/*-1*/, 10/*-2*/, rby8) );
2508*cdf0e10cSrcweir         root = new TreeNode()
2509*cdf0e10cSrcweir             .appendChild( rby2.dup().appendChild( new TextNode("1") ) )
2510*cdf0e10cSrcweir             .appendChild( rby4.dup()
2511*cdf0e10cSrcweir                 .appendChild( met1.dup()
2512*cdf0e10cSrcweir                     .appendChild( new TextNode("2345") ) )
2513*cdf0e10cSrcweir                 .appendChild( new TextNode("6") ) )
2514*cdf0e10cSrcweir             .appendChild( rby8.dup()
2515*cdf0e10cSrcweir                 .appendChild( met5.dup()
2516*cdf0e10cSrcweir                     .appendChild( new TextNode("78") ) ) )
2517*cdf0e10cSrcweir             .appendChild( new TextNode("9") );
2518*cdf0e10cSrcweir         doTest(root, false);
2519*cdf0e10cSrcweir     }
2520*cdf0e10cSrcweir 
2521*cdf0e10cSrcweir     @Test public void testRangeMetaMeta() throws Exception
2522*cdf0e10cSrcweir     {
2523*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2524*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2525*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2526*cdf0e10cSrcweir         TreeNode met1 = new MetaNode( mkId("id") );
2527*cdf0e10cSrcweir         inserter.insertRange( new Range(3, 6, met1) );
2528*cdf0e10cSrcweir         // overlap left
2529*cdf0e10cSrcweir         TreeNode met2 = new MetaNode( mkId("id") );
2530*cdf0e10cSrcweir         try {
2531*cdf0e10cSrcweir             inserter.insertRange( new Range(0, 4, met2) );
2532*cdf0e10cSrcweir             fail("testRangeMetaMeta: overlap left allowed");
2533*cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
2534*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2535*cdf0e10cSrcweir             .appendChild( new TextNode("123") )
2536*cdf0e10cSrcweir             .appendChild( met1.dup().appendChild( new TextNode("456") ) )
2537*cdf0e10cSrcweir             .appendChild( new TextNode("789") );
2538*cdf0e10cSrcweir         doTest(root, false);
2539*cdf0e10cSrcweir         // overlap right
2540*cdf0e10cSrcweir         TreeNode met3 = new MetaNode( mkId("id") );
2541*cdf0e10cSrcweir         try {
2542*cdf0e10cSrcweir             inserter.insertRange( new Range(5/*-1*/, 8/*-1*/, met3) );
2543*cdf0e10cSrcweir             fail("testRangeMetaMeta: overlap right allowed");
2544*cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
2545*cdf0e10cSrcweir         root = new TreeNode()
2546*cdf0e10cSrcweir             .appendChild( new TextNode("123") )
2547*cdf0e10cSrcweir             .appendChild( met1.dup().appendChild( new TextNode("456") ) )
2548*cdf0e10cSrcweir             .appendChild( new TextNode("789") );
2549*cdf0e10cSrcweir         doTest(root, false);
2550*cdf0e10cSrcweir         // around
2551*cdf0e10cSrcweir         TreeNode met4 = new MetaNode( mkId("id") );
2552*cdf0e10cSrcweir         inserter.insertRange( new Range(3, 7/*-1*/, met4) );
2553*cdf0e10cSrcweir         root = new TreeNode()
2554*cdf0e10cSrcweir             .appendChild( new TextNode("123") )
2555*cdf0e10cSrcweir             .appendChild( met4.dup()
2556*cdf0e10cSrcweir                 .appendChild( met1.dup().appendChild( new TextNode("456") ) ) )
2557*cdf0e10cSrcweir             .appendChild( new TextNode("789") );
2558*cdf0e10cSrcweir         doTest(root, false);
2559*cdf0e10cSrcweir         // inside
2560*cdf0e10cSrcweir         TreeNode met5 = new MetaNode( mkId("id") );
2561*cdf0e10cSrcweir         inserter.insertRange( new Range(6/*-2*/, 8/*-2*/, met5) );
2562*cdf0e10cSrcweir         root = new TreeNode()
2563*cdf0e10cSrcweir             .appendChild( new TextNode("123") )
2564*cdf0e10cSrcweir             .appendChild( met4.dup()
2565*cdf0e10cSrcweir                 .appendChild( met1.dup()
2566*cdf0e10cSrcweir                     .appendChild( new TextNode("4") )
2567*cdf0e10cSrcweir                     .appendChild( met5.dup()
2568*cdf0e10cSrcweir                         .appendChild( new TextNode("56") ) ) ) )
2569*cdf0e10cSrcweir             .appendChild( new TextNode("789") );
2570*cdf0e10cSrcweir         doTest(root, false);
2571*cdf0e10cSrcweir     }
2572*cdf0e10cSrcweir 
2573*cdf0e10cSrcweir     @Test public void testRange2() throws Exception
2574*cdf0e10cSrcweir     {
2575*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2576*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2577*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2578*cdf0e10cSrcweir         TreeNode met1 = new MetaNode( mkId("id") );
2579*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 8, met1) );
2580*cdf0e10cSrcweir         TreeNode met2 = new MetaNode( mkId("id") );
2581*cdf0e10cSrcweir         inserter.insertRange( new Range(3/*-1*/, 8/*-1*/, met2) );
2582*cdf0e10cSrcweir         TreeNode met3 = new MetaNode( mkId("id") );
2583*cdf0e10cSrcweir         inserter.insertRange( new Range(5/*-2*/, 8/*-2*/, met3) );
2584*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2585*cdf0e10cSrcweir             .appendChild( new TextNode("1") )
2586*cdf0e10cSrcweir             .appendChild( met1.dup()
2587*cdf0e10cSrcweir                 .appendChild( new TextNode("2") )
2588*cdf0e10cSrcweir                 .appendChild( met2.dup()
2589*cdf0e10cSrcweir                     .appendChild( new TextNode("3") )
2590*cdf0e10cSrcweir                     .appendChild( met3.dup()
2591*cdf0e10cSrcweir                         .appendChild( new TextNode("456") ) )
2592*cdf0e10cSrcweir                     .appendChild( new TextNode("7") ) )
2593*cdf0e10cSrcweir                 .appendChild( new TextNode("8") ) )
2594*cdf0e10cSrcweir             .appendChild( new TextNode("9") );
2595*cdf0e10cSrcweir         doTest(root, false);
2596*cdf0e10cSrcweir         // split ruby at every meta start!
2597*cdf0e10cSrcweir         TreeNode rby4 = new RubyNode( mkName("ruby") );
2598*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 7/*-3*/, rby4) );
2599*cdf0e10cSrcweir         root = new TreeNode()
2600*cdf0e10cSrcweir             .appendChild( rby4.dup()
2601*cdf0e10cSrcweir                 .appendChild( new TextNode("1") ) )
2602*cdf0e10cSrcweir             .appendChild( met1.dup()
2603*cdf0e10cSrcweir                 .appendChild( rby4.dup()
2604*cdf0e10cSrcweir                     .appendChild( new TextNode("2") ) )
2605*cdf0e10cSrcweir                 .appendChild( met2.dup()
2606*cdf0e10cSrcweir                     .appendChild( rby4.dup()
2607*cdf0e10cSrcweir                         .appendChild( new TextNode("3") ) )
2608*cdf0e10cSrcweir                     .appendChild( met3.dup()
2609*cdf0e10cSrcweir                         .appendChild( rby4.dup()
2610*cdf0e10cSrcweir                             .appendChild( new TextNode("4") ) )
2611*cdf0e10cSrcweir                         .appendChild( new TextNode("56") ) )
2612*cdf0e10cSrcweir                     .appendChild( new TextNode("7") ) )
2613*cdf0e10cSrcweir                 .appendChild( new TextNode("8") ) )
2614*cdf0e10cSrcweir             .appendChild( new TextNode("9") );
2615*cdf0e10cSrcweir         doTest(root, false);
2616*cdf0e10cSrcweir         // split ruby at every meta end!
2617*cdf0e10cSrcweir         TreeNode rby5 = new RubyNode( mkName("ruby") );
2618*cdf0e10cSrcweir         inserter.insertRange( new Range(8/*-3*/, 12/*-3*/, rby5) );
2619*cdf0e10cSrcweir         root = new TreeNode()
2620*cdf0e10cSrcweir             .appendChild( rby4.dup()
2621*cdf0e10cSrcweir                 .appendChild( new TextNode("1") ) )
2622*cdf0e10cSrcweir             .appendChild( met1.dup()
2623*cdf0e10cSrcweir                 .appendChild( rby4.dup()
2624*cdf0e10cSrcweir                     .appendChild( new TextNode("2") ) )
2625*cdf0e10cSrcweir                 .appendChild( met2.dup()
2626*cdf0e10cSrcweir                     .appendChild( rby4.dup()
2627*cdf0e10cSrcweir                         .appendChild( new TextNode("3") ) )
2628*cdf0e10cSrcweir                     .appendChild( met3.dup()
2629*cdf0e10cSrcweir                         .appendChild( rby4.dup()
2630*cdf0e10cSrcweir                             .appendChild( new TextNode("4") ) )
2631*cdf0e10cSrcweir                         .appendChild( new TextNode("5") )
2632*cdf0e10cSrcweir                         .appendChild( rby5.dup()
2633*cdf0e10cSrcweir                             .appendChild( new TextNode("6") ) ) )
2634*cdf0e10cSrcweir                     .appendChild( rby5.dup()
2635*cdf0e10cSrcweir                         .appendChild( new TextNode("7") ) ) )
2636*cdf0e10cSrcweir                 .appendChild( rby5.dup()
2637*cdf0e10cSrcweir                     .appendChild( new TextNode("8") ) ) )
2638*cdf0e10cSrcweir             .appendChild( rby5.dup()
2639*cdf0e10cSrcweir                 .appendChild( new TextNode("9") ) );
2640*cdf0e10cSrcweir         doTest(root, false);
2641*cdf0e10cSrcweir     }
2642*cdf0e10cSrcweir 
2643*cdf0e10cSrcweir     @Test public void testRange3() throws Exception
2644*cdf0e10cSrcweir     {
2645*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2646*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2647*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2648*cdf0e10cSrcweir         TreeNode rby1 = new RubyNode( mkName("ruby") );
2649*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 9, rby1) );
2650*cdf0e10cSrcweir         TreeNode met2 = new MetaNode( mkId("id") );
2651*cdf0e10cSrcweir         inserter.insertRange( new Range(2, 7, met2) );
2652*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2653*cdf0e10cSrcweir             .appendChild( rby1.dup()
2654*cdf0e10cSrcweir                 .appendChild( new TextNode("12") )
2655*cdf0e10cSrcweir                 .appendChild( met2.dup()
2656*cdf0e10cSrcweir                     .appendChild( new TextNode("34567") ) )
2657*cdf0e10cSrcweir                 .appendChild( new TextNode("89") ) );
2658*cdf0e10cSrcweir         doTest(root, false);
2659*cdf0e10cSrcweir         // overwrite outer ruby, split remains at inner meta!
2660*cdf0e10cSrcweir         TreeNode rby3 = new RubyNode( mkName("ruby") );
2661*cdf0e10cSrcweir         inserter.insertRange( new Range(5/*-1*/, 6/*-1*/, rby3) );
2662*cdf0e10cSrcweir         root = new TreeNode()
2663*cdf0e10cSrcweir             .appendChild( rby1.dup()
2664*cdf0e10cSrcweir                 .appendChild( new TextNode("12") ) )
2665*cdf0e10cSrcweir             .appendChild( met2.dup()
2666*cdf0e10cSrcweir                 .appendChild( rby1.dup()
2667*cdf0e10cSrcweir                     .appendChild( new TextNode("34") ) )
2668*cdf0e10cSrcweir                 .appendChild( rby3.dup()
2669*cdf0e10cSrcweir                     .appendChild( new TextNode("5") ) )
2670*cdf0e10cSrcweir                 .appendChild( rby1.dup()
2671*cdf0e10cSrcweir                     .appendChild( new TextNode("67") ) ) )
2672*cdf0e10cSrcweir             .appendChild( rby1.dup()
2673*cdf0e10cSrcweir                 .appendChild( new TextNode("89") ) );
2674*cdf0e10cSrcweir         doTest(root, false);
2675*cdf0e10cSrcweir     }
2676*cdf0e10cSrcweir 
2677*cdf0e10cSrcweir     @Test public void testRange4() throws Exception
2678*cdf0e10cSrcweir     {
2679*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2680*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2681*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2682*cdf0e10cSrcweir         TreeNode rby1 = new RubyNode( mkName("ruby") );
2683*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 9, rby1) );
2684*cdf0e10cSrcweir         TreeNode met2 = new MetaNode( mkId("id") );
2685*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 8, met2) );
2686*cdf0e10cSrcweir         TreeNode met3 = new MetaNode( mkId("id") );
2687*cdf0e10cSrcweir         inserter.insertRange( new Range(3/*-1*/, 8/*-1*/, met3) );
2688*cdf0e10cSrcweir         TreeNode met4 = new MetaNode( mkId("id") );
2689*cdf0e10cSrcweir         inserter.insertRange( new Range(5/*-2*/, 8/*-2*/, met4) );
2690*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2691*cdf0e10cSrcweir             .appendChild( rby1.dup()
2692*cdf0e10cSrcweir                 .appendChild( new TextNode("1") )
2693*cdf0e10cSrcweir                 .appendChild( met2.dup()
2694*cdf0e10cSrcweir                     .appendChild( new TextNode("2") )
2695*cdf0e10cSrcweir                     .appendChild( met3.dup()
2696*cdf0e10cSrcweir                         .appendChild( new TextNode("3") )
2697*cdf0e10cSrcweir                         .appendChild( met4.dup()
2698*cdf0e10cSrcweir                             .appendChild( new TextNode("456") ) )
2699*cdf0e10cSrcweir                         .appendChild( new TextNode("7") ) )
2700*cdf0e10cSrcweir                     .appendChild( new TextNode("8") ) )
2701*cdf0e10cSrcweir                 .appendChild( new TextNode("9") ) );
2702*cdf0e10cSrcweir         doTest(root, false);
2703*cdf0e10cSrcweir         // overwrite outer ruby, split remains at every inner meta!
2704*cdf0e10cSrcweir         TreeNode rby5 = new RubyNode( mkName("ruby") );
2705*cdf0e10cSrcweir         inserter.insertRange( new Range(7/*-3*/, 8/*-3*/, rby5) );
2706*cdf0e10cSrcweir         root = new TreeNode()
2707*cdf0e10cSrcweir             .appendChild( rby1.dup()
2708*cdf0e10cSrcweir                 .appendChild( new TextNode("1") ) )
2709*cdf0e10cSrcweir             .appendChild( met2.dup()
2710*cdf0e10cSrcweir                 .appendChild( rby1.dup()
2711*cdf0e10cSrcweir                     .appendChild( new TextNode("2") ) )
2712*cdf0e10cSrcweir                 .appendChild( met3.dup()
2713*cdf0e10cSrcweir                     .appendChild( rby1.dup()
2714*cdf0e10cSrcweir                         .appendChild( new TextNode("3") ) )
2715*cdf0e10cSrcweir                     .appendChild( met4.dup()
2716*cdf0e10cSrcweir                         .appendChild( rby1.dup()
2717*cdf0e10cSrcweir                             .appendChild( new TextNode("4") ) )
2718*cdf0e10cSrcweir                         .appendChild( rby5.dup()
2719*cdf0e10cSrcweir                             .appendChild( new TextNode("5") ) )
2720*cdf0e10cSrcweir                         .appendChild( rby1.dup()
2721*cdf0e10cSrcweir                             .appendChild( new TextNode("6") ) ) )
2722*cdf0e10cSrcweir                     .appendChild( rby1.dup()
2723*cdf0e10cSrcweir                         .appendChild( new TextNode("7") ) ) )
2724*cdf0e10cSrcweir                 .appendChild( rby1.dup()
2725*cdf0e10cSrcweir                     .appendChild( new TextNode("8") ) ) )
2726*cdf0e10cSrcweir             .appendChild( rby1.dup()
2727*cdf0e10cSrcweir                 .appendChild( new TextNode("9") ) );
2728*cdf0e10cSrcweir         doTest(root, false);
2729*cdf0e10cSrcweir     }
2730*cdf0e10cSrcweir 
2731*cdf0e10cSrcweir     @Test public void testRange5() throws Exception
2732*cdf0e10cSrcweir     {
2733*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2734*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2735*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2736*cdf0e10cSrcweir         TreeNode rby1 = new RubyNode( mkName("ruby") );
2737*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 9, rby1) );
2738*cdf0e10cSrcweir         TreeNode met2 = new MetaNode( mkId("id") );
2739*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 3, met2) );
2740*cdf0e10cSrcweir         TreeNode met3 = new MetaNode( mkId("id") );
2741*cdf0e10cSrcweir         inserter.insertRange( new Range(5/*-1*/, 6/*-1*/, met3) );
2742*cdf0e10cSrcweir         TreeNode met4 = new MetaNode( mkId("id") );
2743*cdf0e10cSrcweir         inserter.insertRange( new Range(8/*-2*/, 10/*-2*/, met4) );
2744*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2745*cdf0e10cSrcweir             .appendChild( rby1.dup()
2746*cdf0e10cSrcweir                 .appendChild( new TextNode("1") )
2747*cdf0e10cSrcweir                 .appendChild( met2.dup().appendChild( new TextNode("23") ) )
2748*cdf0e10cSrcweir                 .appendChild( new TextNode("4") )
2749*cdf0e10cSrcweir                 .appendChild( met3.dup().appendChild( new TextNode("5") ) )
2750*cdf0e10cSrcweir                 .appendChild( new TextNode("6") )
2751*cdf0e10cSrcweir                 .appendChild( met4.dup().appendChild( new TextNode("78") ) )
2752*cdf0e10cSrcweir                 .appendChild( new TextNode("9") ) );
2753*cdf0e10cSrcweir         doTest(root, false);
2754*cdf0e10cSrcweir         // overwrite outer ruby, but split at inner metas!
2755*cdf0e10cSrcweir         TreeNode rby5 = new RubyNode( mkName("ruby") );
2756*cdf0e10cSrcweir         inserter.insertRange( new Range(3/*-1*/, 10/*-3*/, rby5) );
2757*cdf0e10cSrcweir         root = new TreeNode()
2758*cdf0e10cSrcweir             .appendChild( rby1.dup()
2759*cdf0e10cSrcweir                 .appendChild( new TextNode("1") ) )
2760*cdf0e10cSrcweir             .appendChild( met2.dup()
2761*cdf0e10cSrcweir                 .appendChild( rby1.dup()
2762*cdf0e10cSrcweir                     .appendChild( new TextNode("2") ) )
2763*cdf0e10cSrcweir                 .appendChild( rby5.dup()
2764*cdf0e10cSrcweir                     .appendChild( new TextNode("3") ) ) )
2765*cdf0e10cSrcweir             .appendChild( rby5.dup()
2766*cdf0e10cSrcweir                 .appendChild( new TextNode("4") )
2767*cdf0e10cSrcweir                 .appendChild( met3.dup()
2768*cdf0e10cSrcweir                     .appendChild( new TextNode("5") ) )
2769*cdf0e10cSrcweir                 .appendChild( new TextNode("6") ) )
2770*cdf0e10cSrcweir             .appendChild( met4.dup()
2771*cdf0e10cSrcweir                 .appendChild( rby5.dup()
2772*cdf0e10cSrcweir                     .appendChild( new TextNode("7") ) )
2773*cdf0e10cSrcweir                 .appendChild( rby1.dup()
2774*cdf0e10cSrcweir                     .appendChild( new TextNode("8") ) ) )
2775*cdf0e10cSrcweir             .appendChild( rby1.dup()
2776*cdf0e10cSrcweir                 .appendChild( new TextNode("9") ) );
2777*cdf0e10cSrcweir         doTest(root, false);
2778*cdf0e10cSrcweir     }
2779*cdf0e10cSrcweir 
2780*cdf0e10cSrcweir     @Test public void testRange6() throws Exception
2781*cdf0e10cSrcweir     {
2782*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2783*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2784*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2785*cdf0e10cSrcweir         TreeNode met1 = new MetaNode( mkId("id") );
2786*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 5, met1) );
2787*cdf0e10cSrcweir         TreeNode met2 = new MetaNode( mkId("id") );
2788*cdf0e10cSrcweir         inserter.insertRange( new Range(3/*-1*/, 6/*-1*/, met2) );
2789*cdf0e10cSrcweir         TreeNode met3 = new MetaNode( mkId("id") );
2790*cdf0e10cSrcweir         inserter.insertRange( new Range(5/*-2*/, 7/*-2*/, met3) );
2791*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2792*cdf0e10cSrcweir             .appendChild( new TextNode("1") )
2793*cdf0e10cSrcweir             .appendChild( met1.dup()
2794*cdf0e10cSrcweir                 .appendChild( new TextNode("2") )
2795*cdf0e10cSrcweir                 .appendChild( met2.dup()
2796*cdf0e10cSrcweir                     .appendChild( new TextNode("3") )
2797*cdf0e10cSrcweir                     .appendChild( met3.dup()
2798*cdf0e10cSrcweir                         .appendChild( new TextNode("45") ) ) ) )
2799*cdf0e10cSrcweir             .appendChild( new TextNode("6789") );
2800*cdf0e10cSrcweir         doTest(root, false);
2801*cdf0e10cSrcweir         // split at 3 metas, all at same position
2802*cdf0e10cSrcweir         TreeNode rby4 = new RubyNode( mkName("ruby") );
2803*cdf0e10cSrcweir         inserter.insertRange( new Range(7/*-3*/, 10/*-3*/, rby4) );
2804*cdf0e10cSrcweir         root = new TreeNode()
2805*cdf0e10cSrcweir             .appendChild( new TextNode("1") )
2806*cdf0e10cSrcweir             .appendChild( met1.dup()
2807*cdf0e10cSrcweir                 .appendChild( new TextNode("2") )
2808*cdf0e10cSrcweir                 .appendChild( met2.dup()
2809*cdf0e10cSrcweir                     .appendChild( new TextNode("3") )
2810*cdf0e10cSrcweir                     .appendChild( met3.dup()
2811*cdf0e10cSrcweir                         .appendChild( new TextNode("4") )
2812*cdf0e10cSrcweir                         .appendChild( rby4.dup()
2813*cdf0e10cSrcweir                             .appendChild( new TextNode("5") ) ) ) ) )
2814*cdf0e10cSrcweir             .appendChild( rby4.dup()
2815*cdf0e10cSrcweir                 .appendChild( new TextNode("67") ) )
2816*cdf0e10cSrcweir             .appendChild( new TextNode("89") );
2817*cdf0e10cSrcweir         doTest(root, false);
2818*cdf0e10cSrcweir     }
2819*cdf0e10cSrcweir 
2820*cdf0e10cSrcweir     @Test public void testRange7() throws Exception
2821*cdf0e10cSrcweir     {
2822*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2823*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2824*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2825*cdf0e10cSrcweir         TreeNode url1 = new HyperlinkNode( mkName("url") );
2826*cdf0e10cSrcweir         inserter.insertRange( new Range(1, 5, url1) );
2827*cdf0e10cSrcweir         TreeNode met2 = new MetaNode( mkId("id") );
2828*cdf0e10cSrcweir         inserter.insertRange( new Range(3, 5, met2) );
2829*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2830*cdf0e10cSrcweir             .appendChild( new TextNode("1") )
2831*cdf0e10cSrcweir             .appendChild( url1.dup()
2832*cdf0e10cSrcweir                 .appendChild( new TextNode("23") ) )
2833*cdf0e10cSrcweir             .appendChild( met2.dup()
2834*cdf0e10cSrcweir                 .appendChild( url1.dup()
2835*cdf0e10cSrcweir                     .appendChild( new TextNode("45") ) ) )
2836*cdf0e10cSrcweir             .appendChild( new TextNode("6789") );
2837*cdf0e10cSrcweir         doTest(root, false);
2838*cdf0e10cSrcweir         // this should result in not splitting the hyperlink, but due to API
2839*cdf0e10cSrcweir         // we can't tell :(
2840*cdf0e10cSrcweir         TreeNode rby3 = new RubyNode( mkName("ruby") );
2841*cdf0e10cSrcweir         inserter.insertRange( new Range(5/*-1*/, 8/*-1*/, rby3) );
2842*cdf0e10cSrcweir         root = new TreeNode()
2843*cdf0e10cSrcweir             .appendChild( new TextNode("1") )
2844*cdf0e10cSrcweir             .appendChild( url1.dup()
2845*cdf0e10cSrcweir                 .appendChild( new TextNode("23") ) )
2846*cdf0e10cSrcweir             .appendChild( met2.dup()
2847*cdf0e10cSrcweir                 .appendChild( url1.dup()
2848*cdf0e10cSrcweir                     .appendChild( new TextNode("4") ) )
2849*cdf0e10cSrcweir                 .appendChild( rby3.dup()
2850*cdf0e10cSrcweir                     .appendChild( url1.dup()
2851*cdf0e10cSrcweir                         .appendChild( new TextNode("5") ) ) ) )
2852*cdf0e10cSrcweir             .appendChild( rby3.dup()
2853*cdf0e10cSrcweir                 .appendChild( new TextNode("67") ) )
2854*cdf0e10cSrcweir             .appendChild( new TextNode("89") );
2855*cdf0e10cSrcweir         doTest(root, false);
2856*cdf0e10cSrcweir     }
2857*cdf0e10cSrcweir 
2858*cdf0e10cSrcweir     /* TODO: test partial selection, test UNDO/REDO */
2859*cdf0e10cSrcweir 
2860*cdf0e10cSrcweir     // #i109601# NestedTextContent and XChild
2861*cdf0e10cSrcweir     @Test public void testMetaXChild() throws Exception
2862*cdf0e10cSrcweir     {
2863*cdf0e10cSrcweir         StringPair id1 = new StringPair("content.xml", mkName("id"));
2864*cdf0e10cSrcweir         StringPair id2 = new StringPair("content.xml", mkName("id"));
2865*cdf0e10cSrcweir         StringPair id3 = new StringPair("content.xml", mkName("id"));
2866*cdf0e10cSrcweir         StringPair id4 = new StringPair("content.xml", mkName("id"));
2867*cdf0e10cSrcweir         StringPair id5 = new StringPair("content.xml", mkName("id"));
2868*cdf0e10cSrcweir         StringPair id6 = new StringPair("content.xml", mkName("id"));
2869*cdf0e10cSrcweir         TreeNode meta1 = new MetaNode(id1);
2870*cdf0e10cSrcweir         TreeNode meta2 = new MetaNode(id2);
2871*cdf0e10cSrcweir         TreeNode meta3 = new MetaFieldNode(id3);
2872*cdf0e10cSrcweir         TreeNode meta4 = new MetaNode(id4);
2873*cdf0e10cSrcweir         TreeNode meta5 = new MetaNode(id5);
2874*cdf0e10cSrcweir         TreeNode meta6 = new MetaFieldNode(id6);
2875*cdf0e10cSrcweir         TreeNode root = new TreeNode()
2876*cdf0e10cSrcweir             .appendChild( meta1.dup()
2877*cdf0e10cSrcweir                 .appendChild( new TextNode("1") ) )
2878*cdf0e10cSrcweir             .appendChild( new TextNode("2") )
2879*cdf0e10cSrcweir             .appendChild( meta2.dup()
2880*cdf0e10cSrcweir                 .appendChild( meta3.dup()
2881*cdf0e10cSrcweir                     .appendChild( new TextNode("34") )
2882*cdf0e10cSrcweir                     .appendChild( meta4.dup()
2883*cdf0e10cSrcweir                         .appendChild( new TextNode("56") ) )
2884*cdf0e10cSrcweir                     .appendChild( meta5.dup() )
2885*cdf0e10cSrcweir                     .appendChild( new TextNode("7") ) ) )
2886*cdf0e10cSrcweir             .appendChild( new TextNode("8") )
2887*cdf0e10cSrcweir             .appendChild( meta6.dup()
2888*cdf0e10cSrcweir                 .appendChild( new TextNode("9") ) );
2889*cdf0e10cSrcweir 
2890*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2891*cdf0e10cSrcweir         TreeNode text = new TextNode("123456789");
2892*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2893*cdf0e10cSrcweir         XTextContent xMeta1 = inserter.insertRange( new Range(0, 1, meta1) );
2894*cdf0e10cSrcweir         XTextContent xMeta2 = inserter.insertRange( new Range(3, 8, meta2) );
2895*cdf0e10cSrcweir         XTextContent xMeta3 = inserter.insertRange( new Range(4, 9, meta3) );
2896*cdf0e10cSrcweir         XTextContent xMeta4 = inserter.insertRange( new Range(7, 9, meta4) );
2897*cdf0e10cSrcweir         XTextContent xMeta5 = inserter.insertRange( new Range(10, 10, meta5) );
2898*cdf0e10cSrcweir         XTextContent xMeta6 = inserter.insertRange( new Range(13, 14, meta6) );
2899*cdf0e10cSrcweir 
2900*cdf0e10cSrcweir         doTest(root, false);
2901*cdf0e10cSrcweir 
2902*cdf0e10cSrcweir         XText xDocText = m_xDoc.getText();
2903*cdf0e10cSrcweir         XTextCursor xDocTextCursor = xDocText.createTextCursor();
2904*cdf0e10cSrcweir         XParagraphCursor xParagraphCursor = (XParagraphCursor)
2905*cdf0e10cSrcweir             UnoRuntime.queryInterface(XParagraphCursor.class, xDocTextCursor);
2906*cdf0e10cSrcweir         xParagraphCursor.gotoNextParagraph(false); // second paragraph
2907*cdf0e10cSrcweir         // X12XX34X56X78X9
2908*cdf0e10cSrcweir         // 1  23  4  5  6
2909*cdf0e10cSrcweir         //  1       452  6
2910*cdf0e10cSrcweir         //            3
2911*cdf0e10cSrcweir         StringPair [] nestedTextContent = new StringPair[] {
2912*cdf0e10cSrcweir             null,
2913*cdf0e10cSrcweir             id1,
2914*cdf0e10cSrcweir             id1,
2915*cdf0e10cSrcweir             null,
2916*cdf0e10cSrcweir             id2,
2917*cdf0e10cSrcweir             id3,
2918*cdf0e10cSrcweir             id3,
2919*cdf0e10cSrcweir             id3,
2920*cdf0e10cSrcweir             id4,
2921*cdf0e10cSrcweir             id4,
2922*cdf0e10cSrcweir             id4,
2923*cdf0e10cSrcweir             id5,
2924*cdf0e10cSrcweir             id3,
2925*cdf0e10cSrcweir             null,
2926*cdf0e10cSrcweir             id6,
2927*cdf0e10cSrcweir             id6,
2928*cdf0e10cSrcweir         };
2929*cdf0e10cSrcweir         XPropertySet xPropertySet = (XPropertySet)
2930*cdf0e10cSrcweir             UnoRuntime.queryInterface(XPropertySet.class, xDocTextCursor);
2931*cdf0e10cSrcweir         for (int i = 0; i < nestedTextContent.length; ++i) {
2932*cdf0e10cSrcweir             Object oNTC = xPropertySet.getPropertyValue("NestedTextContent");
2933*cdf0e10cSrcweir             XTextContent xNTC = (XTextContent)
2934*cdf0e10cSrcweir                 UnoRuntime.queryInterface(XTextContent.class, oNTC);
2935*cdf0e10cSrcweir             if (null == nestedTextContent[i]) {
2936*cdf0e10cSrcweir                 assertNull("unexpected NestedTextContent at: " + i, xNTC);
2937*cdf0e10cSrcweir             } else {
2938*cdf0e10cSrcweir                 XMetadatable xMetadatable = (XMetadatable)
2939*cdf0e10cSrcweir                     UnoRuntime.queryInterface(XMetadatable.class, xNTC);
2940*cdf0e10cSrcweir                 StringPair xmlid = xMetadatable.getMetadataReference();
2941*cdf0e10cSrcweir                 assertTrue("wrong NestedTextContent at: " + i,
2942*cdf0e10cSrcweir                     MetaNode.eq(nestedTextContent[i], xmlid));
2943*cdf0e10cSrcweir             }
2944*cdf0e10cSrcweir             xDocTextCursor.goRight((short)1, false);
2945*cdf0e10cSrcweir         }
2946*cdf0e10cSrcweir 
2947*cdf0e10cSrcweir         XChild xChild1 = (XChild)
2948*cdf0e10cSrcweir             UnoRuntime.queryInterface(XChild.class, xMeta1);
2949*cdf0e10cSrcweir         XChild xChild2 = (XChild)
2950*cdf0e10cSrcweir             UnoRuntime.queryInterface(XChild.class, xMeta2);
2951*cdf0e10cSrcweir         XChild xChild3 = (XChild)
2952*cdf0e10cSrcweir             UnoRuntime.queryInterface(XChild.class, xMeta3);
2953*cdf0e10cSrcweir         XChild xChild4 = (XChild)
2954*cdf0e10cSrcweir             UnoRuntime.queryInterface(XChild.class, xMeta4);
2955*cdf0e10cSrcweir         XChild xChild5 = (XChild)
2956*cdf0e10cSrcweir             UnoRuntime.queryInterface(XChild.class, xMeta5);
2957*cdf0e10cSrcweir         XChild xChild6 = (XChild)
2958*cdf0e10cSrcweir             UnoRuntime.queryInterface(XChild.class, xMeta6);
2959*cdf0e10cSrcweir         try {
2960*cdf0e10cSrcweir             xChild1.setParent(xChild4);
2961*cdf0e10cSrcweir             fail("setParent(): allowed?");
2962*cdf0e10cSrcweir         } catch (NoSupportException e) { /* expected */ }
2963*cdf0e10cSrcweir         assertNull("getParent(): not null", xChild1.getParent());
2964*cdf0e10cSrcweir         assertNull("getParent(): not null", xChild2.getParent());
2965*cdf0e10cSrcweir         assertNull("getParent(): not null", xChild6.getParent());
2966*cdf0e10cSrcweir         {
2967*cdf0e10cSrcweir             Object xParent3 = xChild3.getParent();
2968*cdf0e10cSrcweir             assertNotNull("getParent(): null", xParent3);
2969*cdf0e10cSrcweir             XMetadatable xMetadatable = (XMetadatable)
2970*cdf0e10cSrcweir                 UnoRuntime.queryInterface(XMetadatable.class, xParent3);
2971*cdf0e10cSrcweir             StringPair xmlid = xMetadatable.getMetadataReference();
2972*cdf0e10cSrcweir             assertTrue("getParent(): wrong", MetaNode.eq(xmlid, id2));
2973*cdf0e10cSrcweir         }{
2974*cdf0e10cSrcweir             Object xParent4 = xChild4.getParent();
2975*cdf0e10cSrcweir             assertNotNull("getParent(): null", xParent4);
2976*cdf0e10cSrcweir             XMetadatable xMetadatable = (XMetadatable)
2977*cdf0e10cSrcweir                 UnoRuntime.queryInterface(XMetadatable.class, xParent4);
2978*cdf0e10cSrcweir             StringPair xmlid = xMetadatable.getMetadataReference();
2979*cdf0e10cSrcweir             assertTrue("getParent(): wrong", MetaNode.eq(xmlid, id3));
2980*cdf0e10cSrcweir         }{
2981*cdf0e10cSrcweir             Object xParent5 = xChild5.getParent();
2982*cdf0e10cSrcweir             assertNotNull("getParent(): null", xParent5);
2983*cdf0e10cSrcweir             XMetadatable xMetadatable = (XMetadatable)
2984*cdf0e10cSrcweir                 UnoRuntime.queryInterface(XMetadatable.class, xParent5);
2985*cdf0e10cSrcweir             StringPair xmlid = xMetadatable.getMetadataReference();
2986*cdf0e10cSrcweir             assertTrue("getParent(): wrong", MetaNode.eq(xmlid, id3));
2987*cdf0e10cSrcweir         }
2988*cdf0e10cSrcweir     }
2989*cdf0e10cSrcweir 
2990*cdf0e10cSrcweir     /** test SwXMeta XText interface */
2991*cdf0e10cSrcweir     @Test public void testMetaXText() throws Exception
2992*cdf0e10cSrcweir     {
2993*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
2994*cdf0e10cSrcweir         TreeNode text = new TextNode("12AB6789");
2995*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
2996*cdf0e10cSrcweir         MetaNode meta = new MetaNode( mkId("id") );
2997*cdf0e10cSrcweir //        inserter.insertRange( new Range(3, 5, met2) );
2998*cdf0e10cSrcweir         XTextContent xMeta = inserter.makeMeta();
2999*cdf0e10cSrcweir 
3000*cdf0e10cSrcweir         XText xDocText = m_xDoc.getText();
3001*cdf0e10cSrcweir         XTextCursor xDocTextCursor = xDocText.createTextCursor();
3002*cdf0e10cSrcweir         xDocTextCursor.goRight((short)3, false);
3003*cdf0e10cSrcweir         xDocTextCursor.goRight((short)2, true);
3004*cdf0e10cSrcweir         xDocText.insertTextContent(xDocTextCursor, xMeta, true);
3005*cdf0e10cSrcweir //        xMeta.attach(xDocTextCursor);
3006*cdf0e10cSrcweir 
3007*cdf0e10cSrcweir         XMetadatable xMetadatable = (XMetadatable)
3008*cdf0e10cSrcweir             UnoRuntime.queryInterface(XMetadatable.class, xMeta);
3009*cdf0e10cSrcweir         xMetadatable.setMetadataReference(meta.getXmlId());
3010*cdf0e10cSrcweir         XText xText = (XText) UnoRuntime.queryInterface(XText.class, xMeta);
3011*cdf0e10cSrcweir 
3012*cdf0e10cSrcweir         XText xParentText = xText.getText();
3013*cdf0e10cSrcweir         assertNotNull("getText(): no parent", xParentText);
3014*cdf0e10cSrcweir 
3015*cdf0e10cSrcweir         XTextRange xStart = xText.getStart();
3016*cdf0e10cSrcweir         assertNotNull("getStart(): no start", xStart);
3017*cdf0e10cSrcweir 
3018*cdf0e10cSrcweir         XTextRange xEnd = xText.getEnd();
3019*cdf0e10cSrcweir         assertNotNull("getEnd(): no end", xEnd);
3020*cdf0e10cSrcweir 
3021*cdf0e10cSrcweir         xText.setString("45");
3022*cdf0e10cSrcweir 
3023*cdf0e10cSrcweir         {
3024*cdf0e10cSrcweir             String string = xText.getString();
3025*cdf0e10cSrcweir             assertEquals("getString(): invalid string returned",
3026*cdf0e10cSrcweir                          "45", string);
3027*cdf0e10cSrcweir         }
3028*cdf0e10cSrcweir 
3029*cdf0e10cSrcweir         XTextCursor xTextCursor = xText.createTextCursor();
3030*cdf0e10cSrcweir         assertNotNull("createTextCursor(): failed", xTextCursor);
3031*cdf0e10cSrcweir 
3032*cdf0e10cSrcweir         try {
3033*cdf0e10cSrcweir             xText.createTextCursorByRange(null);
3034*cdf0e10cSrcweir             fail("createTextCursorByRange(): null allowed?");
3035*cdf0e10cSrcweir         } catch (RuntimeException e) { /* expected */ }
3036*cdf0e10cSrcweir 
3037*cdf0e10cSrcweir         XTextCursor xTextCursorStart = xText.createTextCursorByRange(xStart);
3038*cdf0e10cSrcweir         assertNotNull("createTextCursorByRange(): failed for start",
3039*cdf0e10cSrcweir                       xTextCursorStart);
3040*cdf0e10cSrcweir 
3041*cdf0e10cSrcweir         XTextCursor xTextCursorEnd = xText.createTextCursorByRange(xEnd);
3042*cdf0e10cSrcweir         assertNotNull("createTextCursorByRange(): failed for end",
3043*cdf0e10cSrcweir                       xTextCursorEnd);
3044*cdf0e10cSrcweir 
3045*cdf0e10cSrcweir         // move outside meta
3046*cdf0e10cSrcweir         xDocTextCursor.gotoStart(false);
3047*cdf0e10cSrcweir 
3048*cdf0e10cSrcweir         try {
3049*cdf0e10cSrcweir             xText.insertString(null, "foo", false);
3050*cdf0e10cSrcweir             fail("insertString(): null allowed?");
3051*cdf0e10cSrcweir         } catch (RuntimeException e) { /* expected */ }
3052*cdf0e10cSrcweir 
3053*cdf0e10cSrcweir         try {
3054*cdf0e10cSrcweir             xText.insertString(xDocTextCursor, "foo", false);
3055*cdf0e10cSrcweir             fail("insertString(): cursor outside allowed?");
3056*cdf0e10cSrcweir         } catch (RuntimeException e) { /* expected */ }
3057*cdf0e10cSrcweir 
3058*cdf0e10cSrcweir         xStart = xText.getStart();
3059*cdf0e10cSrcweir         xText.insertString(xStart, "A", false);
3060*cdf0e10cSrcweir         {
3061*cdf0e10cSrcweir             String string = xText.getString();
3062*cdf0e10cSrcweir             assertEquals("getString(): invalid string returned",
3063*cdf0e10cSrcweir                          "A45", string);
3064*cdf0e10cSrcweir         }
3065*cdf0e10cSrcweir 
3066*cdf0e10cSrcweir         xText.insertString(xEnd, "B", false);
3067*cdf0e10cSrcweir         {
3068*cdf0e10cSrcweir             String string = xText.getString();
3069*cdf0e10cSrcweir             assertEquals("getString(): invalid string returned",
3070*cdf0e10cSrcweir                          "A45B", string);
3071*cdf0e10cSrcweir         }
3072*cdf0e10cSrcweir 
3073*cdf0e10cSrcweir         try {
3074*cdf0e10cSrcweir             xText.insertControlCharacter(null, HARD_HYPHEN, false);
3075*cdf0e10cSrcweir             fail("insertControlCharacter(): null allowed?");
3076*cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
3077*cdf0e10cSrcweir 
3078*cdf0e10cSrcweir         xStart = xText.getStart();
3079*cdf0e10cSrcweir         try {
3080*cdf0e10cSrcweir             xText.insertControlCharacter(xDocTextCursor, HARD_HYPHEN, false);
3081*cdf0e10cSrcweir             fail("insertControlCharacter(): cursor outside allowed?");
3082*cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
3083*cdf0e10cSrcweir 
3084*cdf0e10cSrcweir         xText.insertControlCharacter(xStart, HARD_HYPHEN, false);
3085*cdf0e10cSrcweir         {
3086*cdf0e10cSrcweir             String string = xText.getString();
3087*cdf0e10cSrcweir             assertEquals("getString(): invalid string returned",
3088*cdf0e10cSrcweir                          '\u2011' + "A45B", string);
3089*cdf0e10cSrcweir         }
3090*cdf0e10cSrcweir 
3091*cdf0e10cSrcweir         xText.insertControlCharacter(xEnd, HARD_HYPHEN, false);
3092*cdf0e10cSrcweir         {
3093*cdf0e10cSrcweir             String string = xText.getString();
3094*cdf0e10cSrcweir             assertEquals("getString(): invalid string returned",
3095*cdf0e10cSrcweir                          '\u2011' + "A45B" + '\u2011', string);
3096*cdf0e10cSrcweir         }
3097*cdf0e10cSrcweir 
3098*cdf0e10cSrcweir         xText.setString("45");
3099*cdf0e10cSrcweir 
3100*cdf0e10cSrcweir         try {
3101*cdf0e10cSrcweir             xText.insertTextContent(null, xMeta, false);
3102*cdf0e10cSrcweir             fail("insertTextContent(): null range allowed?");
3103*cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
3104*cdf0e10cSrcweir 
3105*cdf0e10cSrcweir         try {
3106*cdf0e10cSrcweir             xText.insertTextContent(xStart, null, false);
3107*cdf0e10cSrcweir             fail("insertTextContent(): null content allowed?");
3108*cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
3109*cdf0e10cSrcweir 
3110*cdf0e10cSrcweir         try {
3111*cdf0e10cSrcweir             xText.insertTextContent(xDocTextCursor, xMeta, false);
3112*cdf0e10cSrcweir             fail("insertTextContent(): cursor outside allowed?");
3113*cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
3114*cdf0e10cSrcweir 
3115*cdf0e10cSrcweir         TextFieldNode field1 = new TextFieldNode( "f1" );
3116*cdf0e10cSrcweir         TextFieldNode field2 = new TextFieldNode( "f2" );
3117*cdf0e10cSrcweir         XTextContent xField1 = inserter.makeTextField(field1.getContent());
3118*cdf0e10cSrcweir         XTextContent xField2 = inserter.makeTextField(field2.getContent());
3119*cdf0e10cSrcweir 
3120*cdf0e10cSrcweir         xStart = xText.getStart();
3121*cdf0e10cSrcweir         xText.insertTextContent(xStart, xField1, false);
3122*cdf0e10cSrcweir 
3123*cdf0e10cSrcweir         TreeNode root = new TreeNode()
3124*cdf0e10cSrcweir             .appendChild( new TextNode("12") )
3125*cdf0e10cSrcweir             .appendChild( meta.dup()
3126*cdf0e10cSrcweir                 .appendChild( field1.dup() )
3127*cdf0e10cSrcweir                 .appendChild( new TextNode("45") ) )
3128*cdf0e10cSrcweir             .appendChild( new TextNode("6789") );
3129*cdf0e10cSrcweir         doTest(root, false);
3130*cdf0e10cSrcweir 
3131*cdf0e10cSrcweir         xText.insertTextContent(xEnd, xField2, false);
3132*cdf0e10cSrcweir 
3133*cdf0e10cSrcweir         root = new TreeNode()
3134*cdf0e10cSrcweir             .appendChild( new TextNode("12") )
3135*cdf0e10cSrcweir             .appendChild( meta.dup()
3136*cdf0e10cSrcweir                 .appendChild( field1.dup() )
3137*cdf0e10cSrcweir                 .appendChild( new TextNode("45") )
3138*cdf0e10cSrcweir                 .appendChild( field2.dup() ) )
3139*cdf0e10cSrcweir             .appendChild( new TextNode("6789") );
3140*cdf0e10cSrcweir         doTest(root, false);
3141*cdf0e10cSrcweir 
3142*cdf0e10cSrcweir         try {
3143*cdf0e10cSrcweir             xText.removeTextContent(null);
3144*cdf0e10cSrcweir             fail("removeTextContent(): null content allowed?");
3145*cdf0e10cSrcweir         } catch (RuntimeException e) { /* expected */ }
3146*cdf0e10cSrcweir 
3147*cdf0e10cSrcweir         xText.removeTextContent(xField1);
3148*cdf0e10cSrcweir 
3149*cdf0e10cSrcweir         XTextRange xAnchor = xMeta.getAnchor();
3150*cdf0e10cSrcweir         assertNotNull("getAnchor(): null", xAnchor);
3151*cdf0e10cSrcweir 
3152*cdf0e10cSrcweir         // evil test case: insert ruby around meta
3153*cdf0e10cSrcweir         RubyNode ruby = new RubyNode( mkName("ruby") );
3154*cdf0e10cSrcweir         inserter.insertRange( new Range(2, 6, ruby) );
3155*cdf0e10cSrcweir 
3156*cdf0e10cSrcweir         /* prevent caching...
3157*cdf0e10cSrcweir         root = new TreeNode()
3158*cdf0e10cSrcweir             .appendChild( new TextNode("12") )
3159*cdf0e10cSrcweir             .appendChild( ruby.dup()
3160*cdf0e10cSrcweir                 .appendChild( meta.dup()
3161*cdf0e10cSrcweir                     .appendChild( new TextNode("45") )
3162*cdf0e10cSrcweir                     .appendChild( field2.dup() ) ) )
3163*cdf0e10cSrcweir             .appendChild( new TextNode("6789") );
3164*cdf0e10cSrcweir         doTest(root, false);
3165*cdf0e10cSrcweir         */
3166*cdf0e10cSrcweir 
3167*cdf0e10cSrcweir         XEnumerationAccess xEA = (XEnumerationAccess)
3168*cdf0e10cSrcweir             UnoRuntime.queryInterface(XEnumerationAccess.class, xMeta);
3169*cdf0e10cSrcweir         XEnumeration xEnum = xEA.createEnumeration();
3170*cdf0e10cSrcweir         assertNotNull("createEnumeration(): returns null", xEnum);
3171*cdf0e10cSrcweir         {
3172*cdf0e10cSrcweir             assertTrue("hasNext(): first missing", xEnum.hasMoreElements());
3173*cdf0e10cSrcweir             Object xElement = xEnum.nextElement();
3174*cdf0e10cSrcweir             XTextRange xPortion = (XTextRange)
3175*cdf0e10cSrcweir                 UnoRuntime.queryInterface(XTextRange.class, xElement);
3176*cdf0e10cSrcweir             XPropertySet xPropSet = (XPropertySet)
3177*cdf0e10cSrcweir                 UnoRuntime.queryInterface(XPropertySet.class, xPortion);
3178*cdf0e10cSrcweir             String type = (String) xPropSet.getPropertyValue("TextPortionType");
3179*cdf0e10cSrcweir             assertEquals("first: not text", "Text", type);
3180*cdf0e10cSrcweir             String txt = xPortion.getString();
3181*cdf0e10cSrcweir             assertEquals("first: text differs", "45", txt);
3182*cdf0e10cSrcweir         }
3183*cdf0e10cSrcweir         {
3184*cdf0e10cSrcweir             assertTrue("hasNext(): second missing", xEnum.hasMoreElements());
3185*cdf0e10cSrcweir             Object xElement = xEnum.nextElement();
3186*cdf0e10cSrcweir             XTextRange xPortion = (XTextRange)
3187*cdf0e10cSrcweir                 UnoRuntime.queryInterface(XTextRange.class, xElement);
3188*cdf0e10cSrcweir             XPropertySet xPropSet = (XPropertySet)
3189*cdf0e10cSrcweir                 UnoRuntime.queryInterface(XPropertySet.class, xPortion);
3190*cdf0e10cSrcweir             String type = (String) xPropSet.getPropertyValue("TextPortionType");
3191*cdf0e10cSrcweir             assertEquals("second: not text", "TextField", type);
3192*cdf0e10cSrcweir         }
3193*cdf0e10cSrcweir         // no ruby end here!!!
3194*cdf0e10cSrcweir         assertFalse("hasNext(): more elements?", xEnum.hasMoreElements());
3195*cdf0e10cSrcweir 
3196*cdf0e10cSrcweir         XComponent xComponent = (XComponent)
3197*cdf0e10cSrcweir             UnoRuntime.queryInterface(XComponent.class, xMeta);
3198*cdf0e10cSrcweir         xComponent.dispose();
3199*cdf0e10cSrcweir 
3200*cdf0e10cSrcweir         try {
3201*cdf0e10cSrcweir             XTextCursor xCursor = xText.createTextCursor();
3202*cdf0e10cSrcweir             assertNull("createTextCursor(): succeeds on disposed object?",
3203*cdf0e10cSrcweir                        xCursor);
3204*cdf0e10cSrcweir         } catch (RuntimeException e) { /* expected */ }
3205*cdf0e10cSrcweir     }
3206*cdf0e10cSrcweir 
3207*cdf0e10cSrcweir     /** check that cursor move methods move to positions in the meta,
3208*cdf0e10cSrcweir         but do not move to positions outside the meta. */
3209*cdf0e10cSrcweir     @Test public void testMetaXTextCursor() throws Exception
3210*cdf0e10cSrcweir     {
3211*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
3212*cdf0e10cSrcweir         TreeNode text = new TextNode("Text. 12 More text here.");
3213*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
3214*cdf0e10cSrcweir         MetaNode met1 = new MetaNode( mkId("id") );
3215*cdf0e10cSrcweir         XTextContent xMeta = inserter.makeMeta();
3216*cdf0e10cSrcweir 
3217*cdf0e10cSrcweir         XText xDocText = m_xDoc.getText();
3218*cdf0e10cSrcweir         XTextCursor xDocTextCursor = xDocText.createTextCursor();
3219*cdf0e10cSrcweir         xDocTextCursor.goRight((short)7, false);
3220*cdf0e10cSrcweir         xDocTextCursor.goRight((short)2, true);
3221*cdf0e10cSrcweir         xDocText.insertTextContent(xDocTextCursor, xMeta, true);
3222*cdf0e10cSrcweir         xDocTextCursor.gotoStart(true);
3223*cdf0e10cSrcweir 
3224*cdf0e10cSrcweir         XMetadatable xMetadatable = (XMetadatable)
3225*cdf0e10cSrcweir             UnoRuntime.queryInterface(XMetadatable.class, xMeta);
3226*cdf0e10cSrcweir         xMetadatable.setMetadataReference(met1.getXmlId());
3227*cdf0e10cSrcweir         XText xText = (XText) UnoRuntime.queryInterface(XText.class, xMeta);
3228*cdf0e10cSrcweir 
3229*cdf0e10cSrcweir         XTextRange xStart = xText.getStart();
3230*cdf0e10cSrcweir         assertNotNull("getStart(): no start", xStart);
3231*cdf0e10cSrcweir         XTextRange xEnd = xText.getEnd();
3232*cdf0e10cSrcweir         assertNotNull("getEnd(): no end", xEnd);
3233*cdf0e10cSrcweir 
3234*cdf0e10cSrcweir         XTextCursor xTextCursor = xText.createTextCursor();
3235*cdf0e10cSrcweir         assertNotNull("createTextCursor(): no cursor", xTextCursor);
3236*cdf0e10cSrcweir 
3237*cdf0e10cSrcweir         // XTextCursor
3238*cdf0e10cSrcweir         boolean bSuccess = false;
3239*cdf0e10cSrcweir         xTextCursor.gotoStart(false);
3240*cdf0e10cSrcweir         xTextCursor.gotoEnd(false);
3241*cdf0e10cSrcweir         bSuccess = xTextCursor.goLeft((short)1, false);
3242*cdf0e10cSrcweir         assertTrue("goLeft(): failed", bSuccess);
3243*cdf0e10cSrcweir         bSuccess = xTextCursor.goLeft((short)1000, false);
3244*cdf0e10cSrcweir         assertFalse("goLeft(): succeeded", bSuccess);
3245*cdf0e10cSrcweir         bSuccess = xTextCursor.goRight((short)1, false);
3246*cdf0e10cSrcweir         assertTrue("goRight(): failed", bSuccess);
3247*cdf0e10cSrcweir         bSuccess = xTextCursor.goRight((short)1000, false);
3248*cdf0e10cSrcweir         assertFalse("goRight(): succeeded", bSuccess);
3249*cdf0e10cSrcweir         xTextCursor.gotoRange(xStart, false);
3250*cdf0e10cSrcweir         xTextCursor.gotoRange(xEnd, false);
3251*cdf0e10cSrcweir         try {
3252*cdf0e10cSrcweir             xTextCursor.gotoRange(xDocTextCursor, false);
3253*cdf0e10cSrcweir             fail("gotoRange(): succeeded");
3254*cdf0e10cSrcweir         } catch (RuntimeException e) { /* expected */ }
3255*cdf0e10cSrcweir 
3256*cdf0e10cSrcweir         // XWordCursor
3257*cdf0e10cSrcweir         xText.setString("Two words");
3258*cdf0e10cSrcweir         xTextCursor.gotoStart(false);
3259*cdf0e10cSrcweir         XWordCursor xWordCursor = (XWordCursor)
3260*cdf0e10cSrcweir             UnoRuntime.queryInterface(XWordCursor.class, xTextCursor);
3261*cdf0e10cSrcweir 
3262*cdf0e10cSrcweir         bSuccess = xWordCursor.gotoNextWord(true);
3263*cdf0e10cSrcweir         assertTrue("gotoNextWord(): failed", bSuccess);
3264*cdf0e10cSrcweir         {
3265*cdf0e10cSrcweir             String string = xTextCursor.getString();
3266*cdf0e10cSrcweir             assertEquals("gotoNextWord(): wrong string",
3267*cdf0e10cSrcweir                          "Two ", string);
3268*cdf0e10cSrcweir         }
3269*cdf0e10cSrcweir         bSuccess = xWordCursor.gotoNextWord(false);
3270*cdf0e10cSrcweir         assertFalse("gotoNextWord(): succeeded", bSuccess);
3271*cdf0e10cSrcweir         xTextCursor.collapseToEnd();
3272*cdf0e10cSrcweir         bSuccess = xWordCursor.gotoPreviousWord(true);
3273*cdf0e10cSrcweir         assertTrue("gotoPreviousWord(): failed", bSuccess);
3274*cdf0e10cSrcweir         {
3275*cdf0e10cSrcweir             String string = xTextCursor.getString();
3276*cdf0e10cSrcweir             assertEquals("gotoPreviousWord(): wrong string",
3277*cdf0e10cSrcweir                          "words", string);
3278*cdf0e10cSrcweir         }
3279*cdf0e10cSrcweir         bSuccess = xWordCursor.gotoPreviousWord(false);
3280*cdf0e10cSrcweir         assertFalse("gotoPreviousWord(): succeeded", bSuccess);
3281*cdf0e10cSrcweir         bSuccess = xWordCursor.gotoEndOfWord(true);
3282*cdf0e10cSrcweir         assertTrue("gotoEndOfWord(): failed", bSuccess);
3283*cdf0e10cSrcweir         {
3284*cdf0e10cSrcweir             String string = xTextCursor.getString();
3285*cdf0e10cSrcweir             assertEquals("gotoEndOfWord(): wrong string",
3286*cdf0e10cSrcweir                          "Two", string);
3287*cdf0e10cSrcweir         }
3288*cdf0e10cSrcweir         xTextCursor.gotoEnd(false);
3289*cdf0e10cSrcweir         bSuccess = xWordCursor.gotoStartOfWord(true);
3290*cdf0e10cSrcweir         assertTrue("gotoStartOfWord(): failed", bSuccess);
3291*cdf0e10cSrcweir         {
3292*cdf0e10cSrcweir             String string = xTextCursor.getString();
3293*cdf0e10cSrcweir             assertEquals("gotoStartOfWord(): wrong string",
3294*cdf0e10cSrcweir                          "words", string);
3295*cdf0e10cSrcweir         }
3296*cdf0e10cSrcweir         xText.setString("");
3297*cdf0e10cSrcweir         bSuccess = xWordCursor.gotoEndOfWord(false);
3298*cdf0e10cSrcweir         assertFalse("gotoEndOfWord(): succeeded", bSuccess);
3299*cdf0e10cSrcweir         bSuccess = xWordCursor.gotoStartOfWord(false);
3300*cdf0e10cSrcweir         assertFalse("gotoStartOfWord(): succeeded", bSuccess);
3301*cdf0e10cSrcweir 
3302*cdf0e10cSrcweir         // XSentenceCursor
3303*cdf0e10cSrcweir         xText.setString("This is a sentence. Another sentence.");
3304*cdf0e10cSrcweir         xTextCursor.gotoStart(false);
3305*cdf0e10cSrcweir         XSentenceCursor xSentenceCursor = (XSentenceCursor)
3306*cdf0e10cSrcweir             UnoRuntime.queryInterface(XSentenceCursor.class, xTextCursor);
3307*cdf0e10cSrcweir 
3308*cdf0e10cSrcweir         bSuccess = xSentenceCursor.gotoNextSentence(true);
3309*cdf0e10cSrcweir         assertTrue("gotoNextSentence(): failed", bSuccess);
3310*cdf0e10cSrcweir         {
3311*cdf0e10cSrcweir             String string = xTextCursor.getString();
3312*cdf0e10cSrcweir             assertEquals("gotoNextSentence(): wrong string",
3313*cdf0e10cSrcweir                          "This is a sentence. ", string);
3314*cdf0e10cSrcweir         }
3315*cdf0e10cSrcweir         bSuccess = xSentenceCursor.gotoNextSentence(false);
3316*cdf0e10cSrcweir         assertFalse("gotoNextSentence(): succeeded", bSuccess);
3317*cdf0e10cSrcweir         // FIXME:
3318*cdf0e10cSrcweir         // the sentence cursor seems to work differently than the word cursor
3319*cdf0e10cSrcweir         xText.setString("This is a sentence. Another sentence. Sentence 3.");
3320*cdf0e10cSrcweir         xTextCursor.gotoEnd(false);
3321*cdf0e10cSrcweir         bSuccess = xSentenceCursor.gotoPreviousSentence(true);
3322*cdf0e10cSrcweir         assertTrue("gotoPreviousSentence(): failed", bSuccess);
3323*cdf0e10cSrcweir         {
3324*cdf0e10cSrcweir             String string = xTextCursor.getString();
3325*cdf0e10cSrcweir             assertEquals("gotoPreviousSentence(): wrong string",
3326*cdf0e10cSrcweir                          "Another sentence. Sentence 3.", string);
3327*cdf0e10cSrcweir         }
3328*cdf0e10cSrcweir         bSuccess = xSentenceCursor.gotoPreviousSentence(false);
3329*cdf0e10cSrcweir         assertFalse("gotoPreviousSentence(): succeeded", bSuccess);
3330*cdf0e10cSrcweir         bSuccess = xSentenceCursor.gotoEndOfSentence(true);
3331*cdf0e10cSrcweir         assertTrue("gotoEndOfSentence(): failed", bSuccess);
3332*cdf0e10cSrcweir         {
3333*cdf0e10cSrcweir             String string = xTextCursor.getString();
3334*cdf0e10cSrcweir             assertEquals("gotoEndOfSentence(): wrong string",
3335*cdf0e10cSrcweir                          "This is a sentence.", string);
3336*cdf0e10cSrcweir         }
3337*cdf0e10cSrcweir         xTextCursor.gotoEnd(false);
3338*cdf0e10cSrcweir         bSuccess = xSentenceCursor.gotoStartOfSentence(true);
3339*cdf0e10cSrcweir         assertTrue("gotoStartOfSentence(): failed", bSuccess);
3340*cdf0e10cSrcweir         {
3341*cdf0e10cSrcweir             String string = xTextCursor.getString();
3342*cdf0e10cSrcweir             assertEquals("gotoStartOfSentence(): wrong string",
3343*cdf0e10cSrcweir                          "Sentence 3.", string);
3344*cdf0e10cSrcweir         }
3345*cdf0e10cSrcweir         xText.setString("");
3346*cdf0e10cSrcweir         bSuccess = xSentenceCursor.gotoEndOfSentence(false);
3347*cdf0e10cSrcweir         assertFalse("gotoEndOfSentence(): succeeded", bSuccess);
3348*cdf0e10cSrcweir         bSuccess = xSentenceCursor.gotoStartOfSentence(false);
3349*cdf0e10cSrcweir         assertFalse("gotoStartOfSentence(): succeeded", bSuccess);
3350*cdf0e10cSrcweir 
3351*cdf0e10cSrcweir         XParagraphCursor xParagraphCursor = (XParagraphCursor)
3352*cdf0e10cSrcweir             UnoRuntime.queryInterface(XParagraphCursor.class, xTextCursor);
3353*cdf0e10cSrcweir 
3354*cdf0e10cSrcweir         // XParagraphCursor (does not make sense)
3355*cdf0e10cSrcweir         bSuccess = xParagraphCursor.gotoNextParagraph(false);
3356*cdf0e10cSrcweir         assertFalse("gotoNextParagraph(): succeeded", bSuccess);
3357*cdf0e10cSrcweir         bSuccess = xParagraphCursor.gotoPreviousParagraph(false);
3358*cdf0e10cSrcweir         assertFalse("gotoPreviousParagraph(): succeeded", bSuccess);
3359*cdf0e10cSrcweir         bSuccess = xParagraphCursor.gotoStartOfParagraph(false);
3360*cdf0e10cSrcweir         assertFalse("gotoStartOfParagraph(): succeeded", bSuccess);
3361*cdf0e10cSrcweir         bSuccess = xParagraphCursor.gotoEndOfParagraph(false);
3362*cdf0e10cSrcweir         assertFalse("gotoEndOfParagraph(): succeeded", bSuccess);
3363*cdf0e10cSrcweir     }
3364*cdf0e10cSrcweir 
3365*cdf0e10cSrcweir 
3366*cdf0e10cSrcweir     abstract class AttachHelper
3367*cdf0e10cSrcweir     {
3368*cdf0e10cSrcweir         abstract boolean isAttribute();
3369*cdf0e10cSrcweir         abstract TreeNode mkTreeNode();
3370*cdf0e10cSrcweir         abstract XTextContent mkTextContent(Inserter inserter, TreeNode node)
3371*cdf0e10cSrcweir             throws Exception;
3372*cdf0e10cSrcweir         void postInserted(TreeNode node, XTextContent xContent)
3373*cdf0e10cSrcweir             throws Exception { }
3374*cdf0e10cSrcweir     }
3375*cdf0e10cSrcweir 
3376*cdf0e10cSrcweir     @Test public void testMetaXTextAttachToxMark() throws Exception
3377*cdf0e10cSrcweir     {
3378*cdf0e10cSrcweir         doMetaXTextAttach( new AttachHelper()
3379*cdf0e10cSrcweir             {
3380*cdf0e10cSrcweir                 boolean isAttribute() { return true; }
3381*cdf0e10cSrcweir                 TreeNode mkTreeNode() {
3382*cdf0e10cSrcweir                     return new DocumentIndexMarkNode( mkName("toxmark") );
3383*cdf0e10cSrcweir                 }
3384*cdf0e10cSrcweir                 XTextContent mkTextContent(Inserter inserter, TreeNode node)
3385*cdf0e10cSrcweir                         throws Exception {
3386*cdf0e10cSrcweir                     return inserter.makeDocumentIndexMark(
3387*cdf0e10cSrcweir                         ((DocumentIndexMarkNode)node).getName());
3388*cdf0e10cSrcweir                 }
3389*cdf0e10cSrcweir             });
3390*cdf0e10cSrcweir     }
3391*cdf0e10cSrcweir 
3392*cdf0e10cSrcweir     @Test public void testMetaXTextAttachRefMark() throws Exception
3393*cdf0e10cSrcweir     {
3394*cdf0e10cSrcweir         doMetaXTextAttach( new AttachHelper()
3395*cdf0e10cSrcweir             {
3396*cdf0e10cSrcweir                 boolean isAttribute() { return true; }
3397*cdf0e10cSrcweir                 TreeNode mkTreeNode() {
3398*cdf0e10cSrcweir                     return new ReferenceMarkNode( mkName("refmark") );
3399*cdf0e10cSrcweir                 }
3400*cdf0e10cSrcweir                 XTextContent mkTextContent(Inserter inserter, TreeNode node)
3401*cdf0e10cSrcweir                         throws Exception {
3402*cdf0e10cSrcweir                     return inserter.makeReferenceMark(
3403*cdf0e10cSrcweir                         ((ReferenceMarkNode)node).getName());
3404*cdf0e10cSrcweir                 }
3405*cdf0e10cSrcweir             });
3406*cdf0e10cSrcweir     }
3407*cdf0e10cSrcweir 
3408*cdf0e10cSrcweir     @Test public void testMetaXTextAttachTextField() throws Exception
3409*cdf0e10cSrcweir     {
3410*cdf0e10cSrcweir         doMetaXTextAttach( new AttachHelper()
3411*cdf0e10cSrcweir             {
3412*cdf0e10cSrcweir                 boolean isAttribute() { return false; }
3413*cdf0e10cSrcweir                 TreeNode mkTreeNode() {
3414*cdf0e10cSrcweir                     return new TextFieldNode( mkName("field") );
3415*cdf0e10cSrcweir                 }
3416*cdf0e10cSrcweir                 XTextContent mkTextContent(Inserter inserter, TreeNode node)
3417*cdf0e10cSrcweir                         throws Exception {
3418*cdf0e10cSrcweir                     return inserter.makeTextField(
3419*cdf0e10cSrcweir                         ((TextFieldNode)node).getContent());
3420*cdf0e10cSrcweir                 }
3421*cdf0e10cSrcweir             });
3422*cdf0e10cSrcweir     }
3423*cdf0e10cSrcweir 
3424*cdf0e10cSrcweir     @Test public void testMetaXTextAttachFootnote() throws Exception
3425*cdf0e10cSrcweir     {
3426*cdf0e10cSrcweir         doMetaXTextAttach( new AttachHelper()
3427*cdf0e10cSrcweir             {
3428*cdf0e10cSrcweir                 boolean isAttribute() { return false; }
3429*cdf0e10cSrcweir                 TreeNode mkTreeNode() {
3430*cdf0e10cSrcweir                     return new FootnoteNode( mkName("ftn") );
3431*cdf0e10cSrcweir                 }
3432*cdf0e10cSrcweir                 XTextContent mkTextContent(Inserter inserter, TreeNode node)
3433*cdf0e10cSrcweir                         throws Exception {
3434*cdf0e10cSrcweir                     return inserter.makeFootnote(
3435*cdf0e10cSrcweir                         ((FootnoteNode)node).getLabel());
3436*cdf0e10cSrcweir                 }
3437*cdf0e10cSrcweir             });
3438*cdf0e10cSrcweir     }
3439*cdf0e10cSrcweir 
3440*cdf0e10cSrcweir     @Test public void testMetaXTextAttachMeta() throws Exception
3441*cdf0e10cSrcweir     {
3442*cdf0e10cSrcweir         doMetaXTextAttach( new AttachHelper()
3443*cdf0e10cSrcweir             {
3444*cdf0e10cSrcweir                 boolean isAttribute() { return true; }
3445*cdf0e10cSrcweir                 TreeNode mkTreeNode() {
3446*cdf0e10cSrcweir                     return new MetaNode( mkId("id") );
3447*cdf0e10cSrcweir                 }
3448*cdf0e10cSrcweir                 XTextContent mkTextContent(Inserter inserter, TreeNode node)
3449*cdf0e10cSrcweir                         throws Exception {
3450*cdf0e10cSrcweir                     return inserter.makeMeta();
3451*cdf0e10cSrcweir                 }
3452*cdf0e10cSrcweir                 void postInserted(TreeNode node, XTextContent xContent)
3453*cdf0e10cSrcweir                         throws Exception {
3454*cdf0e10cSrcweir                     XMetadatable xMetadatable = (XMetadatable)
3455*cdf0e10cSrcweir                         UnoRuntime.queryInterface(XMetadatable.class, xContent);
3456*cdf0e10cSrcweir                     xMetadatable.setMetadataReference(
3457*cdf0e10cSrcweir                             ((MetaNode)node).getXmlId());
3458*cdf0e10cSrcweir                 }
3459*cdf0e10cSrcweir             });
3460*cdf0e10cSrcweir     }
3461*cdf0e10cSrcweir 
3462*cdf0e10cSrcweir     void doMetaXTextAttach(AttachHelper helper) throws Exception
3463*cdf0e10cSrcweir     {
3464*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
3465*cdf0e10cSrcweir         TreeNode text = new TextNode("12AB6789");
3466*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
3467*cdf0e10cSrcweir         MetaNode met1 = new MetaNode( mkId("id") );
3468*cdf0e10cSrcweir         XTextContent xMeta = inserter.makeMeta();
3469*cdf0e10cSrcweir 
3470*cdf0e10cSrcweir         XText xDocText = m_xDoc.getText();
3471*cdf0e10cSrcweir         XTextCursor xDocTextCursor = xDocText.createTextCursor();
3472*cdf0e10cSrcweir         xDocTextCursor.goRight((short)3, false);
3473*cdf0e10cSrcweir         xDocTextCursor.goRight((short)2, true);
3474*cdf0e10cSrcweir         xDocText.insertTextContent(xDocTextCursor, xMeta, true);
3475*cdf0e10cSrcweir 
3476*cdf0e10cSrcweir         XMetadatable xMetadatable = (XMetadatable)
3477*cdf0e10cSrcweir             UnoRuntime.queryInterface(XMetadatable.class, xMeta);
3478*cdf0e10cSrcweir         xMetadatable.setMetadataReference(met1.getXmlId());
3479*cdf0e10cSrcweir         XText xText = (XText) UnoRuntime.queryInterface(XText.class, xMeta);
3480*cdf0e10cSrcweir         XTextRange xStart = null;
3481*cdf0e10cSrcweir         XTextRange xEnd = null;
3482*cdf0e10cSrcweir 
3483*cdf0e10cSrcweir         {
3484*cdf0e10cSrcweir             xStart = xText.getStart();
3485*cdf0e10cSrcweir             xEnd = xText.getEnd();
3486*cdf0e10cSrcweir 
3487*cdf0e10cSrcweir             TreeNode nod1 = helper.mkTreeNode();
3488*cdf0e10cSrcweir             TreeNode nod2 = helper.mkTreeNode();
3489*cdf0e10cSrcweir             XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
3490*cdf0e10cSrcweir             XTextContent xContent2 = helper.mkTextContent(inserter, nod2);
3491*cdf0e10cSrcweir 
3492*cdf0e10cSrcweir             // insertTextContent with meta getStart()/getEnd()
3493*cdf0e10cSrcweir             xText.insertTextContent(xStart, xContent1, false);
3494*cdf0e10cSrcweir             xText.insertTextContent(xEnd  , xContent2, false);
3495*cdf0e10cSrcweir 
3496*cdf0e10cSrcweir             helper.postInserted(nod1, xContent1);
3497*cdf0e10cSrcweir             helper.postInserted(nod2, xContent2);
3498*cdf0e10cSrcweir 
3499*cdf0e10cSrcweir             TreeNode root = new TreeNode()
3500*cdf0e10cSrcweir                 .appendChild( new TextNode("12") )
3501*cdf0e10cSrcweir                 .appendChild( met1.dup()
3502*cdf0e10cSrcweir                     .appendChild( nod1.dup() )
3503*cdf0e10cSrcweir                     .appendChild( new TextNode("AB") )
3504*cdf0e10cSrcweir                     .appendChild( nod2.dup() ) )
3505*cdf0e10cSrcweir                 .appendChild( new TextNode("6789") );
3506*cdf0e10cSrcweir             doTest(root, false);
3507*cdf0e10cSrcweir         }
3508*cdf0e10cSrcweir         {
3509*cdf0e10cSrcweir             xText.setString("AB");
3510*cdf0e10cSrcweir             xStart = xText.getStart();
3511*cdf0e10cSrcweir             xEnd = xText.getEnd();
3512*cdf0e10cSrcweir 
3513*cdf0e10cSrcweir             TreeNode nod1 = helper.mkTreeNode();
3514*cdf0e10cSrcweir             TreeNode nod2 = helper.mkTreeNode();
3515*cdf0e10cSrcweir             XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
3516*cdf0e10cSrcweir             XTextContent xContent2 = helper.mkTextContent(inserter, nod2);
3517*cdf0e10cSrcweir 
3518*cdf0e10cSrcweir             XTextCursor xTextCursor = xText.createTextCursor();
3519*cdf0e10cSrcweir             xTextCursor.gotoStart(false);
3520*cdf0e10cSrcweir 
3521*cdf0e10cSrcweir             // insertTextContent with meta cursor
3522*cdf0e10cSrcweir             xText.insertTextContent(xTextCursor, xContent1, false);
3523*cdf0e10cSrcweir             xTextCursor.gotoEnd(false);
3524*cdf0e10cSrcweir             xText.insertTextContent(xTextCursor, xContent2, false);
3525*cdf0e10cSrcweir 
3526*cdf0e10cSrcweir             helper.postInserted(nod1, xContent1);
3527*cdf0e10cSrcweir             helper.postInserted(nod2, xContent2);
3528*cdf0e10cSrcweir 
3529*cdf0e10cSrcweir             TreeNode root = new TreeNode()
3530*cdf0e10cSrcweir                 .appendChild( new TextNode("12") )
3531*cdf0e10cSrcweir                 .appendChild( met1.dup()
3532*cdf0e10cSrcweir                     .appendChild( nod1.dup() )
3533*cdf0e10cSrcweir                     .appendChild( new TextNode("AB") )
3534*cdf0e10cSrcweir                     .appendChild( nod2.dup() ) )
3535*cdf0e10cSrcweir                 .appendChild( new TextNode("6789") );
3536*cdf0e10cSrcweir             doTest(root, false);
3537*cdf0e10cSrcweir         }
3538*cdf0e10cSrcweir         if (!helper.isAttribute())
3539*cdf0e10cSrcweir         {
3540*cdf0e10cSrcweir //            xText.setString("AB");
3541*cdf0e10cSrcweir             xStart = xText.getStart();
3542*cdf0e10cSrcweir             xEnd = xText.getEnd();
3543*cdf0e10cSrcweir 
3544*cdf0e10cSrcweir             TreeNode nod1 = helper.mkTreeNode();
3545*cdf0e10cSrcweir             TreeNode nod2 = helper.mkTreeNode();
3546*cdf0e10cSrcweir             XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
3547*cdf0e10cSrcweir             XTextContent xContent2 = helper.mkTextContent(inserter, nod2);
3548*cdf0e10cSrcweir 
3549*cdf0e10cSrcweir             XTextCursor xTextCursor = xText.createTextCursor();
3550*cdf0e10cSrcweir             xTextCursor.gotoStart(false);
3551*cdf0e10cSrcweir             xTextCursor.goRight((short)1, true);
3552*cdf0e10cSrcweir 
3553*cdf0e10cSrcweir             // insertTextContent with meta cursor and absorb
3554*cdf0e10cSrcweir             xText.insertTextContent(xTextCursor, xContent1, true);
3555*cdf0e10cSrcweir             xTextCursor.gotoEnd(false);
3556*cdf0e10cSrcweir             xTextCursor.goLeft((short)1, true);
3557*cdf0e10cSrcweir             xText.insertTextContent(xTextCursor, xContent2, true);
3558*cdf0e10cSrcweir 
3559*cdf0e10cSrcweir             helper.postInserted(nod1, xContent1);
3560*cdf0e10cSrcweir             helper.postInserted(nod2, xContent2);
3561*cdf0e10cSrcweir 
3562*cdf0e10cSrcweir             TreeNode root = new TreeNode()
3563*cdf0e10cSrcweir                 .appendChild( new TextNode("12") )
3564*cdf0e10cSrcweir                 .appendChild( met1.dup()
3565*cdf0e10cSrcweir                     .appendChild( nod1.dup() )
3566*cdf0e10cSrcweir                     .appendChild( new TextNode("AB") )
3567*cdf0e10cSrcweir                     .appendChild( nod2.dup() ) )
3568*cdf0e10cSrcweir                 .appendChild( new TextNode("6789") );
3569*cdf0e10cSrcweir             doTest(root, false);
3570*cdf0e10cSrcweir         }
3571*cdf0e10cSrcweir         {
3572*cdf0e10cSrcweir             xText.setString("AB");
3573*cdf0e10cSrcweir             xStart = xText.getStart();
3574*cdf0e10cSrcweir             xEnd = xText.getEnd();
3575*cdf0e10cSrcweir 
3576*cdf0e10cSrcweir             TreeNode nod1 = helper.mkTreeNode();
3577*cdf0e10cSrcweir             TreeNode nod2 = helper.mkTreeNode();
3578*cdf0e10cSrcweir             XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
3579*cdf0e10cSrcweir             XTextContent xContent2 = helper.mkTextContent(inserter, nod2);
3580*cdf0e10cSrcweir 
3581*cdf0e10cSrcweir             xDocTextCursor.gotoRange(xStart, false);
3582*cdf0e10cSrcweir 
3583*cdf0e10cSrcweir             // insertTextContent with document cursor
3584*cdf0e10cSrcweir             xText.insertTextContent(xDocTextCursor, xContent1, false);
3585*cdf0e10cSrcweir             xDocTextCursor.gotoRange(xEnd, false);
3586*cdf0e10cSrcweir             xText.insertTextContent(xDocTextCursor, xContent2, false);
3587*cdf0e10cSrcweir 
3588*cdf0e10cSrcweir             helper.postInserted(nod1, xContent1);
3589*cdf0e10cSrcweir             helper.postInserted(nod2, xContent2);
3590*cdf0e10cSrcweir 
3591*cdf0e10cSrcweir             TreeNode root = new TreeNode()
3592*cdf0e10cSrcweir                 .appendChild( new TextNode("12") )
3593*cdf0e10cSrcweir                 .appendChild( met1.dup()
3594*cdf0e10cSrcweir                     .appendChild( nod1.dup() )
3595*cdf0e10cSrcweir                     .appendChild( new TextNode("AB") )
3596*cdf0e10cSrcweir                     .appendChild( nod2.dup() ) )
3597*cdf0e10cSrcweir                 .appendChild( new TextNode("6789") );
3598*cdf0e10cSrcweir             doTest(root, false);
3599*cdf0e10cSrcweir         }
3600*cdf0e10cSrcweir         if (!helper.isAttribute())
3601*cdf0e10cSrcweir         {
3602*cdf0e10cSrcweir //            xText.setString("AB");
3603*cdf0e10cSrcweir             xStart = xText.getStart();
3604*cdf0e10cSrcweir             xEnd = xText.getEnd();
3605*cdf0e10cSrcweir 
3606*cdf0e10cSrcweir             TreeNode nod1 = helper.mkTreeNode();
3607*cdf0e10cSrcweir             TreeNode nod2 = helper.mkTreeNode();
3608*cdf0e10cSrcweir             XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
3609*cdf0e10cSrcweir             XTextContent xContent2 = helper.mkTextContent(inserter, nod2);
3610*cdf0e10cSrcweir 
3611*cdf0e10cSrcweir             xDocTextCursor.gotoRange(xStart, false);
3612*cdf0e10cSrcweir             xDocTextCursor.goRight((short)1, true);
3613*cdf0e10cSrcweir 
3614*cdf0e10cSrcweir             // insertTextContent with document cursor and absorb
3615*cdf0e10cSrcweir             xText.insertTextContent(xDocTextCursor, xContent1, true);
3616*cdf0e10cSrcweir             xDocTextCursor.gotoRange(xEnd, false);
3617*cdf0e10cSrcweir             xDocTextCursor.goLeft((short)1, true);
3618*cdf0e10cSrcweir             xText.insertTextContent(xDocTextCursor, xContent2, true);
3619*cdf0e10cSrcweir 
3620*cdf0e10cSrcweir             helper.postInserted(nod1, xContent1);
3621*cdf0e10cSrcweir             helper.postInserted(nod2, xContent2);
3622*cdf0e10cSrcweir 
3623*cdf0e10cSrcweir             TreeNode root = new TreeNode()
3624*cdf0e10cSrcweir                 .appendChild( new TextNode("12") )
3625*cdf0e10cSrcweir                 .appendChild( met1.dup()
3626*cdf0e10cSrcweir                     .appendChild( nod1.dup() )
3627*cdf0e10cSrcweir                     .appendChild( new TextNode("AB") )
3628*cdf0e10cSrcweir                     .appendChild( nod2.dup() ) )
3629*cdf0e10cSrcweir                 .appendChild( new TextNode("6789") );
3630*cdf0e10cSrcweir             doTest(root, false);
3631*cdf0e10cSrcweir         }
3632*cdf0e10cSrcweir         {
3633*cdf0e10cSrcweir             xText.setString("AB");
3634*cdf0e10cSrcweir             xStart = xText.getStart();
3635*cdf0e10cSrcweir             xEnd = xText.getEnd();
3636*cdf0e10cSrcweir 
3637*cdf0e10cSrcweir             TreeNode nod1 = helper.mkTreeNode();
3638*cdf0e10cSrcweir             TreeNode nod2 = helper.mkTreeNode();
3639*cdf0e10cSrcweir             XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
3640*cdf0e10cSrcweir             XTextContent xContent2 = helper.mkTextContent(inserter, nod2);
3641*cdf0e10cSrcweir 
3642*cdf0e10cSrcweir             // attach to range from meta getStart()/getEnd()
3643*cdf0e10cSrcweir             xContent1.attach(xStart);
3644*cdf0e10cSrcweir             xContent2.attach(xEnd);
3645*cdf0e10cSrcweir 
3646*cdf0e10cSrcweir             helper.postInserted(nod1, xContent1);
3647*cdf0e10cSrcweir             helper.postInserted(nod2, xContent2);
3648*cdf0e10cSrcweir 
3649*cdf0e10cSrcweir             TreeNode root = new TreeNode()
3650*cdf0e10cSrcweir                 .appendChild( new TextNode("12") )
3651*cdf0e10cSrcweir                 .appendChild( met1.dup()
3652*cdf0e10cSrcweir                     .appendChild( nod1.dup() )
3653*cdf0e10cSrcweir                     .appendChild( new TextNode("AB") )
3654*cdf0e10cSrcweir                     .appendChild( nod2.dup() ) )
3655*cdf0e10cSrcweir                 .appendChild( new TextNode("6789") );
3656*cdf0e10cSrcweir             doTest(root, false);
3657*cdf0e10cSrcweir         }
3658*cdf0e10cSrcweir         {
3659*cdf0e10cSrcweir             xText.setString("AB");
3660*cdf0e10cSrcweir             xStart = xText.getStart();
3661*cdf0e10cSrcweir             xEnd = xText.getEnd();
3662*cdf0e10cSrcweir 
3663*cdf0e10cSrcweir             TreeNode nod1 = helper.mkTreeNode();
3664*cdf0e10cSrcweir             TreeNode nod2 = helper.mkTreeNode();
3665*cdf0e10cSrcweir             XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
3666*cdf0e10cSrcweir             XTextContent xContent2 = helper.mkTextContent(inserter, nod2);
3667*cdf0e10cSrcweir 
3668*cdf0e10cSrcweir             XTextCursor xTextCursor = xText.createTextCursor();
3669*cdf0e10cSrcweir             xTextCursor.gotoStart(false);
3670*cdf0e10cSrcweir 
3671*cdf0e10cSrcweir             // attach to cursor from meta XText
3672*cdf0e10cSrcweir             xContent1.attach(xTextCursor);
3673*cdf0e10cSrcweir             xTextCursor.gotoEnd(false);
3674*cdf0e10cSrcweir             xContent2.attach(xTextCursor);
3675*cdf0e10cSrcweir 
3676*cdf0e10cSrcweir             helper.postInserted(nod1, xContent1);
3677*cdf0e10cSrcweir             helper.postInserted(nod2, xContent2);
3678*cdf0e10cSrcweir 
3679*cdf0e10cSrcweir             TreeNode root = new TreeNode()
3680*cdf0e10cSrcweir                 .appendChild( new TextNode("12") )
3681*cdf0e10cSrcweir                 .appendChild( met1.dup()
3682*cdf0e10cSrcweir                     .appendChild( nod1.dup() )
3683*cdf0e10cSrcweir                     .appendChild( new TextNode("AB") )
3684*cdf0e10cSrcweir                     .appendChild( nod2.dup() ) )
3685*cdf0e10cSrcweir                 .appendChild( new TextNode("6789") );
3686*cdf0e10cSrcweir             doTest(root, false);
3687*cdf0e10cSrcweir         }
3688*cdf0e10cSrcweir     }
3689*cdf0e10cSrcweir 
3690*cdf0e10cSrcweir     @Test public void testMetaFieldXTextField() throws Exception
3691*cdf0e10cSrcweir     {
3692*cdf0e10cSrcweir         com.sun.star.rdf.XRepositorySupplier xModel =
3693*cdf0e10cSrcweir             (com.sun.star.rdf.XRepositorySupplier) UnoRuntime.queryInterface(
3694*cdf0e10cSrcweir                 com.sun.star.rdf.XRepositorySupplier.class, m_xDoc);
3695*cdf0e10cSrcweir         com.sun.star.rdf.XRepository xRepo = xModel.getRDFRepository();
3696*cdf0e10cSrcweir         // for testing just add it to the first graph
3697*cdf0e10cSrcweir         com.sun.star.rdf.XURI[] Graphs = xRepo.getGraphNames();
3698*cdf0e10cSrcweir         com.sun.star.rdf.XNamedGraph xGraph = xRepo.getGraph(Graphs[0]);
3699*cdf0e10cSrcweir         com.sun.star.rdf.XURI xOdfPrefix =
3700*cdf0e10cSrcweir             com.sun.star.rdf.URI.createKnown(m_xContext,
3701*cdf0e10cSrcweir                 com.sun.star.rdf.URIs.ODF_PREFIX);
3702*cdf0e10cSrcweir         com.sun.star.rdf.XURI xOdfSuffix =
3703*cdf0e10cSrcweir             com.sun.star.rdf.URI.createKnown(m_xContext,
3704*cdf0e10cSrcweir                 com.sun.star.rdf.URIs.ODF_SUFFIX);
3705*cdf0e10cSrcweir         com.sun.star.rdf.XNode xPrefix =
3706*cdf0e10cSrcweir             com.sun.star.rdf.Literal.create(m_xContext, "foo");
3707*cdf0e10cSrcweir         com.sun.star.rdf.XNode xSuffix =
3708*cdf0e10cSrcweir             com.sun.star.rdf.Literal.create(m_xContext, "bar");
3709*cdf0e10cSrcweir 
3710*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
3711*cdf0e10cSrcweir         TreeNode text = new TextNode("abc");
3712*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
3713*cdf0e10cSrcweir         XText xDocText = m_xDoc.getText();
3714*cdf0e10cSrcweir         XTextCursor xDocTextCursor = xDocText.createTextCursor();
3715*cdf0e10cSrcweir         xDocTextCursor.goRight((short)1, false);
3716*cdf0e10cSrcweir         xDocTextCursor.goRight((short)3, true);
3717*cdf0e10cSrcweir 
3718*cdf0e10cSrcweir         XTextField xMetaField = inserter.makeMetaField();
3719*cdf0e10cSrcweir 
3720*cdf0e10cSrcweir         xDocText.insertTextContent(xDocTextCursor, xMetaField, true);
3721*cdf0e10cSrcweir 
3722*cdf0e10cSrcweir         XMetadatable xMetadatable = (XMetadatable)
3723*cdf0e10cSrcweir             UnoRuntime.queryInterface(XMetadatable.class, xMetaField);
3724*cdf0e10cSrcweir         xMetadatable.ensureMetadataReference();
3725*cdf0e10cSrcweir 
3726*cdf0e10cSrcweir         xGraph.addStatement(xMetadatable, xOdfPrefix, xPrefix);
3727*cdf0e10cSrcweir         xGraph.addStatement(xMetadatable, xOdfSuffix, xSuffix);
3728*cdf0e10cSrcweir         assertEquals("getPresentation(): wrong",
3729*cdf0e10cSrcweir                      "fooabcbar", xMetaField.getPresentation(false));
3730*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
3731*cdf0e10cSrcweir     }
3732*cdf0e10cSrcweir 
3733*cdf0e10cSrcweir     @Test public void testMetaFieldXPropertySet() throws Exception
3734*cdf0e10cSrcweir     {
3735*cdf0e10cSrcweir         RangeInserter inserter = new RangeInserter(m_xDoc);
3736*cdf0e10cSrcweir         TreeNode text = new TextNode("123");
3737*cdf0e10cSrcweir         inserter.insertRange( new Range(0, 0, text) );
3738*cdf0e10cSrcweir         XText xDocText = m_xDoc.getText();
3739*cdf0e10cSrcweir         XTextCursor xDocTextCursor = xDocText.createTextCursor();
3740*cdf0e10cSrcweir         xDocTextCursor.goRight((short)1, false);
3741*cdf0e10cSrcweir         xDocTextCursor.goRight((short)3, true);
3742*cdf0e10cSrcweir 
3743*cdf0e10cSrcweir         XTextField xMetaField = inserter.makeMetaField();
3744*cdf0e10cSrcweir 
3745*cdf0e10cSrcweir         xDocText.insertTextContent(xDocTextCursor, xMetaField, true);
3746*cdf0e10cSrcweir 
3747*cdf0e10cSrcweir         XPropertySet xPropertySet = (XPropertySet)
3748*cdf0e10cSrcweir             UnoRuntime.queryInterface(XPropertySet.class, xMetaField);
3749*cdf0e10cSrcweir         assertNotNull("PropertySet: not supported?", xPropertySet);
3750*cdf0e10cSrcweir         XPropertySetInfo xPropertySetInfo = xPropertySet.getPropertySetInfo();
3751*cdf0e10cSrcweir         assertTrue("hasPropertyByName(\"NumberFormat\"):",
3752*cdf0e10cSrcweir                    xPropertySetInfo.hasPropertyByName("NumberFormat"));
3753*cdf0e10cSrcweir         assertTrue("hasPropertyByName(\"IsFixedLanguage\"):",
3754*cdf0e10cSrcweir                    xPropertySetInfo.hasPropertyByName("IsFixedLanguage"));
3755*cdf0e10cSrcweir 
3756*cdf0e10cSrcweir         int def = (Integer) xPropertySet.getPropertyValue("NumberFormat");
3757*cdf0e10cSrcweir         System.out.println("NumberFormat: default is " + def);
3758*cdf0e10cSrcweir         short INT = com.sun.star.i18n.NumberFormatIndex.NUMBER_INT;
3759*cdf0e10cSrcweir         xPropertySet.setPropertyValue("NumberFormat", INT);
3760*cdf0e10cSrcweir         xPropertySet.setPropertyValue("IsFixedLanguage", true);
3761*cdf0e10cSrcweir         int format = (Integer) xPropertySet.getPropertyValue("NumberFormat");
3762*cdf0e10cSrcweir         assertEquals("NumberFormat: failed", INT, format);
3763*cdf0e10cSrcweir         boolean isFixed = (Boolean)
3764*cdf0e10cSrcweir             xPropertySet.getPropertyValue("IsFixedLanguage");
3765*cdf0e10cSrcweir         assertTrue("IsFixedLanguage: failed", isFixed);
3766*cdf0e10cSrcweir     }
3767*cdf0e10cSrcweir 
3768*cdf0e10cSrcweir     @Test public void testLoadStore() throws Exception
3769*cdf0e10cSrcweir     {
3770*cdf0e10cSrcweir         XTextDocument xComp = null;
3771*cdf0e10cSrcweir         String filename = "TESTMETA.odt";
3772*cdf0e10cSrcweir         String file;
3773*cdf0e10cSrcweir         try {
3774*cdf0e10cSrcweir             file = TestDocument.getUrl(filename);
3775*cdf0e10cSrcweir             xComp = doLoad(file);
3776*cdf0e10cSrcweir             if (xComp != null)
3777*cdf0e10cSrcweir             {
3778*cdf0e10cSrcweir                 checkLoadMeta(xComp);
3779*cdf0e10cSrcweir                 file = m_TmpDir + filename;
3780*cdf0e10cSrcweir                 doStore(xComp, file);
3781*cdf0e10cSrcweir                 close(xComp);
3782*cdf0e10cSrcweir                 xComp = doLoad(file);
3783*cdf0e10cSrcweir                 checkLoadMeta(xComp);
3784*cdf0e10cSrcweir             }
3785*cdf0e10cSrcweir         } finally {
3786*cdf0e10cSrcweir             close(xComp);
3787*cdf0e10cSrcweir         }
3788*cdf0e10cSrcweir     }
3789*cdf0e10cSrcweir 
3790*cdf0e10cSrcweir     private void doStore(XComponent xComp, String file) throws Exception
3791*cdf0e10cSrcweir     {
3792*cdf0e10cSrcweir         System.out.println("Storing test document...");
3793*cdf0e10cSrcweir 
3794*cdf0e10cSrcweir         XStorable xStor = (XStorable) UnoRuntime.queryInterface(
3795*cdf0e10cSrcweir                     XStorable.class, xComp);
3796*cdf0e10cSrcweir 
3797*cdf0e10cSrcweir         xStor.storeToURL(file, new PropertyValue[0]);
3798*cdf0e10cSrcweir 
3799*cdf0e10cSrcweir         System.out.println("...done");
3800*cdf0e10cSrcweir     }
3801*cdf0e10cSrcweir 
3802*cdf0e10cSrcweir     public XTextDocument doLoad(String file) throws Exception
3803*cdf0e10cSrcweir     {
3804*cdf0e10cSrcweir         XComponent xComp = null;
3805*cdf0e10cSrcweir 
3806*cdf0e10cSrcweir         System.out.println("Loading test document...");
3807*cdf0e10cSrcweir 
3808*cdf0e10cSrcweir         PropertyValue[] loadProps = new PropertyValue[1];
3809*cdf0e10cSrcweir         loadProps[0] = new PropertyValue();
3810*cdf0e10cSrcweir         loadProps[0].Name = "Hidden";
3811*cdf0e10cSrcweir         loadProps[0].Value = new Boolean(true);
3812*cdf0e10cSrcweir 
3813*cdf0e10cSrcweir         xComp = util.DesktopTools.loadDoc(m_xMSF, file, loadProps);
3814*cdf0e10cSrcweir //        xComp =  util.DesktopTools.getCLoader(m_xMSF).loadComponentFromURL(file, "_blank", 0, loadProps);
3815*cdf0e10cSrcweir 
3816*cdf0e10cSrcweir         XTextDocument xTextDoc = (XTextDocument)
3817*cdf0e10cSrcweir             UnoRuntime.queryInterface(XTextDocument.class, xComp);
3818*cdf0e10cSrcweir 
3819*cdf0e10cSrcweir         assertNotNull("cannot load: " + file, xTextDoc);
3820*cdf0e10cSrcweir 
3821*cdf0e10cSrcweir         System.out.println("...done");
3822*cdf0e10cSrcweir 
3823*cdf0e10cSrcweir         return xTextDoc;
3824*cdf0e10cSrcweir     }
3825*cdf0e10cSrcweir 
3826*cdf0e10cSrcweir     public void checkLoadMeta(XTextDocument xTextDoc) throws Exception
3827*cdf0e10cSrcweir     {
3828*cdf0e10cSrcweir         XText xText = xTextDoc.getText();
3829*cdf0e10cSrcweir 
3830*cdf0e10cSrcweir         System.out.println("Checking meta(-field)s in loaded test document...");
3831*cdf0e10cSrcweir 
3832*cdf0e10cSrcweir         TreeNode root = new TreeNode()
3833*cdf0e10cSrcweir             .appendChild( new RubyNode("ruby1")
3834*cdf0e10cSrcweir                 .appendChild( new TextNode("1") ) )
3835*cdf0e10cSrcweir             .appendChild( new MetaNode(mkId_("id1"))
3836*cdf0e10cSrcweir                 .appendChild( new TextNode("2") ) )
3837*cdf0e10cSrcweir             .appendChild( new MetaFieldNode(mkId_("id2"))
3838*cdf0e10cSrcweir                 .appendChild( new TextNode("3") ) )
3839*cdf0e10cSrcweir             .appendChild( new RubyNode("ruby2")
3840*cdf0e10cSrcweir                 .appendChild( new MetaNode(mkId_("id3"))
3841*cdf0e10cSrcweir                     .appendChild( new TextNode("4") ) ) )
3842*cdf0e10cSrcweir             .appendChild( new RubyNode("ruby3")
3843*cdf0e10cSrcweir                 .appendChild( new MetaFieldNode(mkId_("id4"))
3844*cdf0e10cSrcweir                     .appendChild( new TextNode("5") ) ) )
3845*cdf0e10cSrcweir             .appendChild( new MetaNode(mkId_("id5"))
3846*cdf0e10cSrcweir                 .appendChild( new RubyNode("ruby4")
3847*cdf0e10cSrcweir                     .appendChild( new TextNode("6") ) ) )
3848*cdf0e10cSrcweir             .appendChild( new MetaFieldNode(mkId_("id6"))
3849*cdf0e10cSrcweir                 .appendChild( new RubyNode("ruby5")
3850*cdf0e10cSrcweir                     .appendChild( new TextNode("7") ) ) )
3851*cdf0e10cSrcweir             .appendChild( new MetaNode(mkId_("id7"))
3852*cdf0e10cSrcweir                 .appendChild( new MetaNode(mkId_("id8"))
3853*cdf0e10cSrcweir                     .appendChild( new TextNode("8") ) ) )
3854*cdf0e10cSrcweir             .appendChild( new MetaNode(mkId_("id9"))
3855*cdf0e10cSrcweir                 .appendChild( new MetaFieldNode(mkId_("id10"))
3856*cdf0e10cSrcweir                     .appendChild( new TextNode("9") ) ) )
3857*cdf0e10cSrcweir             .appendChild( new MetaFieldNode(mkId_("id11"))
3858*cdf0e10cSrcweir                 .appendChild( new MetaNode(mkId_("id12"))
3859*cdf0e10cSrcweir                     .appendChild( new TextNode("10") ) ) )
3860*cdf0e10cSrcweir             .appendChild( new MetaFieldNode(mkId_("id13"))
3861*cdf0e10cSrcweir                 .appendChild( new MetaFieldNode(mkId_("id14"))
3862*cdf0e10cSrcweir                     .appendChild( new TextNode("11") ) ) )
3863*cdf0e10cSrcweir             .appendChild( new MetaNode(mkId_("id15"))
3864*cdf0e10cSrcweir                 .appendChild( new RubyNode("ruby6")
3865*cdf0e10cSrcweir                     .appendChild( new MetaFieldNode(mkId_("id16"))
3866*cdf0e10cSrcweir                         .appendChild( new TextNode("12") ) ) ) )
3867*cdf0e10cSrcweir             .appendChild( new MetaNode(mkId_("")) {
3868*cdf0e10cSrcweir                                 public boolean equals(Object other) {
3869*cdf0e10cSrcweir                                     return (other instanceof MetaNode);
3870*cdf0e10cSrcweir                                 } }
3871*cdf0e10cSrcweir                 .appendChild( new TextNode("13") ) )
3872*cdf0e10cSrcweir             .appendChild( new TextNode(" X X ") );
3873*cdf0e10cSrcweir         doTest(xTextDoc, root, false);
3874*cdf0e10cSrcweir 
3875*cdf0e10cSrcweir         System.out.println("...done");
3876*cdf0e10cSrcweir     }
3877*cdf0e10cSrcweir 
3878*cdf0e10cSrcweir     @Test public void testLoadStoreXmlid() throws Exception
3879*cdf0e10cSrcweir     {
3880*cdf0e10cSrcweir         XTextDocument xComp = null;
3881*cdf0e10cSrcweir         String filename = "TESTXMLID.odt";
3882*cdf0e10cSrcweir         String file;
3883*cdf0e10cSrcweir         try {
3884*cdf0e10cSrcweir             file = TestDocument.getUrl(filename);
3885*cdf0e10cSrcweir             xComp = doLoad(file);
3886*cdf0e10cSrcweir             if (xComp != null)
3887*cdf0e10cSrcweir             {
3888*cdf0e10cSrcweir                 checkLoadXmlId(xComp);
3889*cdf0e10cSrcweir                 file = m_TmpDir + filename;
3890*cdf0e10cSrcweir                 doStore(xComp, file);
3891*cdf0e10cSrcweir                 close(xComp);
3892*cdf0e10cSrcweir                 xComp = doLoad(file);
3893*cdf0e10cSrcweir                 checkLoadXmlId(xComp);
3894*cdf0e10cSrcweir             }
3895*cdf0e10cSrcweir         } finally {
3896*cdf0e10cSrcweir             close(xComp);
3897*cdf0e10cSrcweir         }
3898*cdf0e10cSrcweir     }
3899*cdf0e10cSrcweir 
3900*cdf0e10cSrcweir     public void checkLoadXmlId(XTextDocument xTextDoc) throws Exception
3901*cdf0e10cSrcweir     {
3902*cdf0e10cSrcweir         XText xText = xTextDoc.getText();
3903*cdf0e10cSrcweir 
3904*cdf0e10cSrcweir         System.out.println("Checking bookmarks in loaded test document...");
3905*cdf0e10cSrcweir 
3906*cdf0e10cSrcweir         XRepositorySupplier xRS = (XRepositorySupplier)
3907*cdf0e10cSrcweir             UnoRuntime.queryInterface(XRepositorySupplier.class, xTextDoc);
3908*cdf0e10cSrcweir         XDocumentRepository xRepo = (XDocumentRepository)
3909*cdf0e10cSrcweir             UnoRuntime.queryInterface(XDocumentRepository.class,
3910*cdf0e10cSrcweir                 xRS.getRDFRepository());
3911*cdf0e10cSrcweir         XBookmarksSupplier xBMS = (XBookmarksSupplier)
3912*cdf0e10cSrcweir             UnoRuntime.queryInterface(XBookmarksSupplier.class, xTextDoc);
3913*cdf0e10cSrcweir         XNameAccess xBookmarks = xBMS.getBookmarks();
3914*cdf0e10cSrcweir         XMetadatable xMark1 = (XMetadatable) UnoRuntime.queryInterface(
3915*cdf0e10cSrcweir                 XMetadatable.class, xBookmarks.getByName("mk1"));
3916*cdf0e10cSrcweir         assertTrue("mark1",
3917*cdf0e10cSrcweir                 eq(xMark1.getMetadataReference(),
3918*cdf0e10cSrcweir                     new StringPair("content.xml", "id90")));
3919*cdf0e10cSrcweir 
3920*cdf0e10cSrcweir         XMetadatable xMark2 = (XMetadatable) UnoRuntime.queryInterface(
3921*cdf0e10cSrcweir                 XMetadatable.class, xBookmarks.getByName("mk2"));
3922*cdf0e10cSrcweir         Pair<Statement[], Boolean> result = xRepo.getStatementRDFa(xMark2);
3923*cdf0e10cSrcweir         assertTrue("mark2", (result.First.length == 1)
3924*cdf0e10cSrcweir             && result.First[0].Subject.getStringValue().equals("uri:foo")
3925*cdf0e10cSrcweir             && result.First[0].Predicate.getStringValue().equals("uri:bar")
3926*cdf0e10cSrcweir             && result.First[0].Object.getStringValue().contains("a fooish bar")
3927*cdf0e10cSrcweir             );
3928*cdf0e10cSrcweir 
3929*cdf0e10cSrcweir         XMetadatable xMark3 = (XMetadatable) UnoRuntime.queryInterface(
3930*cdf0e10cSrcweir                 XMetadatable.class, xBookmarks.getByName("mk3"));
3931*cdf0e10cSrcweir         assertTrue("mark3",
3932*cdf0e10cSrcweir                 eq(xMark3.getMetadataReference(),
3933*cdf0e10cSrcweir                     new StringPair("content.xml", "id91")));
3934*cdf0e10cSrcweir 
3935*cdf0e10cSrcweir         System.out.println("...done");
3936*cdf0e10cSrcweir 
3937*cdf0e10cSrcweir         System.out.println("Checking sections in loaded test document...");
3938*cdf0e10cSrcweir 
3939*cdf0e10cSrcweir         XTextSectionsSupplier xTSS = (XTextSectionsSupplier)
3940*cdf0e10cSrcweir             UnoRuntime.queryInterface(XTextSectionsSupplier.class, xTextDoc);
3941*cdf0e10cSrcweir 
3942*cdf0e10cSrcweir         XNameAccess xSections = xTSS.getTextSections();
3943*cdf0e10cSrcweir 
3944*cdf0e10cSrcweir         XMetadatable xSection1 = (XMetadatable) UnoRuntime.queryInterface(
3945*cdf0e10cSrcweir                 XMetadatable.class, xSections.getByName("Section 1"));
3946*cdf0e10cSrcweir         assertTrue("idsection1", eq(xSection1.getMetadataReference(),
3947*cdf0e10cSrcweir                     new StringPair("content.xml", "idSection1")));
3948*cdf0e10cSrcweir 
3949*cdf0e10cSrcweir         XMetadatable xSection2 = (XMetadatable) UnoRuntime.queryInterface(
3950*cdf0e10cSrcweir                 XMetadatable.class, xSections.getByName("Section 2"));
3951*cdf0e10cSrcweir         assertTrue("idSection2", eq(xSection2.getMetadataReference(),
3952*cdf0e10cSrcweir                     new StringPair("content.xml", "idSection2")));
3953*cdf0e10cSrcweir 
3954*cdf0e10cSrcweir         XMetadatable xSection3 = (XMetadatable) UnoRuntime.queryInterface(
3955*cdf0e10cSrcweir                 XMetadatable.class,
3956*cdf0e10cSrcweir                 xSections.getByName("Table of Contents1_Head"));
3957*cdf0e10cSrcweir         assertTrue("idTOCTitle", eq(xSection3.getMetadataReference(),
3958*cdf0e10cSrcweir                     new StringPair("content.xml", "idTOCTitle")));
3959*cdf0e10cSrcweir 
3960*cdf0e10cSrcweir         XMetadatable xSection4 = (XMetadatable) UnoRuntime.queryInterface(
3961*cdf0e10cSrcweir                 XMetadatable.class,
3962*cdf0e10cSrcweir                 xSections.getByName("Alphabetical Index1_Head"));
3963*cdf0e10cSrcweir         assertTrue("idAITitle", eq(xSection4.getMetadataReference(),
3964*cdf0e10cSrcweir                     new StringPair("content.xml", "idAITitle")));
3965*cdf0e10cSrcweir 
3966*cdf0e10cSrcweir         XMetadatable xSection5 = (XMetadatable) UnoRuntime.queryInterface(
3967*cdf0e10cSrcweir                 XMetadatable.class,
3968*cdf0e10cSrcweir                 xSections.getByName("Illustration Index1_Head"));
3969*cdf0e10cSrcweir         assertTrue("idIITitle", eq(xSection5.getMetadataReference(),
3970*cdf0e10cSrcweir                     new StringPair("content.xml", "idIITitle")));
3971*cdf0e10cSrcweir 
3972*cdf0e10cSrcweir         XMetadatable xSection6 = (XMetadatable) UnoRuntime.queryInterface(
3973*cdf0e10cSrcweir                 XMetadatable.class,
3974*cdf0e10cSrcweir                 xSections.getByName("Index of Tables1_Head"));
3975*cdf0e10cSrcweir         assertTrue("idIOTTitle", eq(xSection6.getMetadataReference(),
3976*cdf0e10cSrcweir                     new StringPair("content.xml", "idIOTTitle")));
3977*cdf0e10cSrcweir 
3978*cdf0e10cSrcweir         XMetadatable xSection7 = (XMetadatable) UnoRuntime.queryInterface(
3979*cdf0e10cSrcweir                 XMetadatable.class,
3980*cdf0e10cSrcweir                 xSections.getByName("User-Defined1_Head"));
3981*cdf0e10cSrcweir         assertTrue("idUDTitle", eq(xSection7.getMetadataReference(),
3982*cdf0e10cSrcweir                     new StringPair("content.xml", "idUDTitle")));
3983*cdf0e10cSrcweir 
3984*cdf0e10cSrcweir         XMetadatable xSection8 = (XMetadatable) UnoRuntime.queryInterface(
3985*cdf0e10cSrcweir                 XMetadatable.class,
3986*cdf0e10cSrcweir                 xSections.getByName("Table of Objects1_Head"));
3987*cdf0e10cSrcweir         assertTrue("idTOOTitle", eq(xSection8.getMetadataReference(),
3988*cdf0e10cSrcweir                     new StringPair("content.xml", "idTOOTitle")));
3989*cdf0e10cSrcweir 
3990*cdf0e10cSrcweir         XMetadatable xSection9 = (XMetadatable) UnoRuntime.queryInterface(
3991*cdf0e10cSrcweir                 XMetadatable.class, xSections.getByName("Bibliography1_Head"));
3992*cdf0e10cSrcweir         assertTrue("idBibTitle", eq(xSection9.getMetadataReference(),
3993*cdf0e10cSrcweir                     new StringPair("content.xml", "idBibTitle")));
3994*cdf0e10cSrcweir 
3995*cdf0e10cSrcweir         System.out.println("...done");
3996*cdf0e10cSrcweir 
3997*cdf0e10cSrcweir         System.out.println("Checking indexes in loaded test document...");
3998*cdf0e10cSrcweir 
3999*cdf0e10cSrcweir         XDocumentIndexesSupplier xDIS = (XDocumentIndexesSupplier)
4000*cdf0e10cSrcweir             UnoRuntime.queryInterface(XDocumentIndexesSupplier.class, xTextDoc);
4001*cdf0e10cSrcweir         XIndexAccess xIndexesIA = xDIS.getDocumentIndexes();
4002*cdf0e10cSrcweir         XNameAccess xIndexes =
4003*cdf0e10cSrcweir             UnoRuntime.queryInterface(XNameAccess.class, xIndexesIA);
4004*cdf0e10cSrcweir 
4005*cdf0e10cSrcweir         XMetadatable xIndex1 = (XMetadatable) UnoRuntime.queryInterface(
4006*cdf0e10cSrcweir                 XMetadatable.class, xIndexes.getByName("Table of Contents1"));
4007*cdf0e10cSrcweir         assertTrue("idTOC", eq(xIndex1.getMetadataReference(),
4008*cdf0e10cSrcweir                     new StringPair("content.xml", "idTOC")));
4009*cdf0e10cSrcweir         XMetadatable xIndex1s = (XMetadatable) UnoRuntime.queryInterface(
4010*cdf0e10cSrcweir                 XMetadatable.class, xSections.getByName("Table of Contents1"));
4011*cdf0e10cSrcweir         assertTrue("idTOC", eq(xIndex1s.getMetadataReference(),
4012*cdf0e10cSrcweir                     new StringPair("content.xml", "idTOC")));
4013*cdf0e10cSrcweir 
4014*cdf0e10cSrcweir         XMetadatable xIndex2 = (XMetadatable) UnoRuntime.queryInterface(
4015*cdf0e10cSrcweir                 XMetadatable.class, xIndexes.getByName("Alphabetical Index1"));
4016*cdf0e10cSrcweir         assertTrue("idAI", eq(xIndex2.getMetadataReference(),
4017*cdf0e10cSrcweir                     new StringPair("content.xml", "idAI")));
4018*cdf0e10cSrcweir         XMetadatable xIndex2s = (XMetadatable) UnoRuntime.queryInterface(
4019*cdf0e10cSrcweir                 XMetadatable.class, xSections.getByName("Alphabetical Index1"));
4020*cdf0e10cSrcweir         assertTrue("idAI", eq(xIndex2s.getMetadataReference(),
4021*cdf0e10cSrcweir                     new StringPair("content.xml", "idAI")));
4022*cdf0e10cSrcweir 
4023*cdf0e10cSrcweir         XMetadatable xIndex3 = (XMetadatable) UnoRuntime.queryInterface(
4024*cdf0e10cSrcweir                 XMetadatable.class, xIndexes.getByName("Illustration Index1"));
4025*cdf0e10cSrcweir         assertTrue("idII", eq(xIndex3.getMetadataReference(),
4026*cdf0e10cSrcweir                     new StringPair("content.xml", "idII")));
4027*cdf0e10cSrcweir         XMetadatable xIndex3s = (XMetadatable) UnoRuntime.queryInterface(
4028*cdf0e10cSrcweir                 XMetadatable.class, xSections.getByName("Illustration Index1"));
4029*cdf0e10cSrcweir         assertTrue("idII", eq(xIndex3s.getMetadataReference(),
4030*cdf0e10cSrcweir                     new StringPair("content.xml", "idII")));
4031*cdf0e10cSrcweir 
4032*cdf0e10cSrcweir         XMetadatable xIndex4 = (XMetadatable) UnoRuntime.queryInterface(
4033*cdf0e10cSrcweir                 XMetadatable.class, xIndexes.getByName("Index of Tables1"));
4034*cdf0e10cSrcweir         assertTrue("idIOT", eq(xIndex4.getMetadataReference(),
4035*cdf0e10cSrcweir                     new StringPair("content.xml", "idIOT")));
4036*cdf0e10cSrcweir         XMetadatable xIndex4s = (XMetadatable) UnoRuntime.queryInterface(
4037*cdf0e10cSrcweir                 XMetadatable.class, xSections.getByName("Index of Tables1"));
4038*cdf0e10cSrcweir         assertTrue("idIOT", eq(xIndex4s.getMetadataReference(),
4039*cdf0e10cSrcweir                     new StringPair("content.xml", "idIOT")));
4040*cdf0e10cSrcweir 
4041*cdf0e10cSrcweir         XMetadatable xIndex5 = (XMetadatable) UnoRuntime.queryInterface(
4042*cdf0e10cSrcweir                 XMetadatable.class, xIndexes.getByName("User-Defined1"));
4043*cdf0e10cSrcweir         assertTrue("idUD", eq(xIndex5.getMetadataReference(),
4044*cdf0e10cSrcweir                     new StringPair("content.xml", "idUD")));
4045*cdf0e10cSrcweir         XMetadatable xIndex5s = (XMetadatable) UnoRuntime.queryInterface(
4046*cdf0e10cSrcweir                 XMetadatable.class, xSections.getByName("User-Defined1"));
4047*cdf0e10cSrcweir         assertTrue("idUD", eq(xIndex5s.getMetadataReference(),
4048*cdf0e10cSrcweir                     new StringPair("content.xml", "idUD")));
4049*cdf0e10cSrcweir 
4050*cdf0e10cSrcweir         XMetadatable xIndex6 = (XMetadatable) UnoRuntime.queryInterface(
4051*cdf0e10cSrcweir                 XMetadatable.class, xIndexes.getByName("Table of Objects1"));
4052*cdf0e10cSrcweir         assertTrue("idTOO", eq(xIndex6.getMetadataReference(),
4053*cdf0e10cSrcweir                     new StringPair("content.xml", "idTOO")));
4054*cdf0e10cSrcweir         XMetadatable xIndex6s = (XMetadatable) UnoRuntime.queryInterface(
4055*cdf0e10cSrcweir                 XMetadatable.class, xSections.getByName("Table of Objects1"));
4056*cdf0e10cSrcweir         assertTrue("idTOO", eq(xIndex6s.getMetadataReference(),
4057*cdf0e10cSrcweir                     new StringPair("content.xml", "idTOO")));
4058*cdf0e10cSrcweir 
4059*cdf0e10cSrcweir         XMetadatable xIndex7 = (XMetadatable) UnoRuntime.queryInterface(
4060*cdf0e10cSrcweir                 XMetadatable.class, xIndexes.getByName("Bibliography1"));
4061*cdf0e10cSrcweir         assertTrue("idBib", eq(xIndex7.getMetadataReference(),
4062*cdf0e10cSrcweir                     new StringPair("content.xml", "idBib")));
4063*cdf0e10cSrcweir         XMetadatable xIndex7s = (XMetadatable) UnoRuntime.queryInterface(
4064*cdf0e10cSrcweir                 XMetadatable.class, xSections.getByName("Bibliography1"));
4065*cdf0e10cSrcweir         assertTrue("idBib", eq(xIndex7s.getMetadataReference(),
4066*cdf0e10cSrcweir                     new StringPair("content.xml", "idBib")));
4067*cdf0e10cSrcweir 
4068*cdf0e10cSrcweir         System.out.println("...done");
4069*cdf0e10cSrcweir     }
4070*cdf0e10cSrcweir 
4071*cdf0e10cSrcweir     static void close(XComponent i_comp)
4072*cdf0e10cSrcweir     {
4073*cdf0e10cSrcweir         try {
4074*cdf0e10cSrcweir             XCloseable xClos = (XCloseable) UnoRuntime.queryInterface(
4075*cdf0e10cSrcweir                         XCloseable.class, i_comp);
4076*cdf0e10cSrcweir             if (xClos != null) xClos.close(true);
4077*cdf0e10cSrcweir         } catch (Exception e) {
4078*cdf0e10cSrcweir         }
4079*cdf0e10cSrcweir     }
4080*cdf0e10cSrcweir 
4081*cdf0e10cSrcweir     private void doTest(TreeNode intree) throws Exception
4082*cdf0e10cSrcweir     {
4083*cdf0e10cSrcweir         doTest(m_xDoc, intree, true);
4084*cdf0e10cSrcweir     }
4085*cdf0e10cSrcweir 
4086*cdf0e10cSrcweir     private void doTest(TreeNode intree, boolean insert) throws Exception
4087*cdf0e10cSrcweir     {
4088*cdf0e10cSrcweir         doTest(m_xDoc, intree, insert);
4089*cdf0e10cSrcweir     }
4090*cdf0e10cSrcweir 
4091*cdf0e10cSrcweir     private void doTest(XTextDocument xDoc, TreeNode intree,
4092*cdf0e10cSrcweir             boolean insert) throws Exception
4093*cdf0e10cSrcweir     {
4094*cdf0e10cSrcweir         dumpTree(intree, "I: ");
4095*cdf0e10cSrcweir 
4096*cdf0e10cSrcweir         if (insert) {
4097*cdf0e10cSrcweir             new TreeInserter(xDoc).insertTree(intree);
4098*cdf0e10cSrcweir         }
4099*cdf0e10cSrcweir 
4100*cdf0e10cSrcweir //Thread.sleep(10000);
4101*cdf0e10cSrcweir 
4102*cdf0e10cSrcweir         XText xText = xDoc.getText();
4103*cdf0e10cSrcweir         XEnumerationAccess xTextEA = (XEnumerationAccess)
4104*cdf0e10cSrcweir             UnoRuntime.queryInterface(XEnumerationAccess.class, xText);
4105*cdf0e10cSrcweir         XEnumeration xTextEnum = xTextEA.createEnumeration();
4106*cdf0e10cSrcweir         // skip to right paragraph
4107*cdf0e10cSrcweir         xTextEnum.nextElement(); // skip first -- always empty!
4108*cdf0e10cSrcweir         Object xElement = xTextEnum.nextElement(); // second contains test case
4109*cdf0e10cSrcweir         XEnumerationAccess xEA = (XEnumerationAccess)
4110*cdf0e10cSrcweir             UnoRuntime.queryInterface(XEnumerationAccess.class, xElement);
4111*cdf0e10cSrcweir         XEnumeration xEnum = xEA.createEnumeration();
4112*cdf0e10cSrcweir         TreeNode outtree = new EnumConverter().convert(xEnum);
4113*cdf0e10cSrcweir 
4114*cdf0e10cSrcweir         dumpTree(outtree, "O: ");
4115*cdf0e10cSrcweir 
4116*cdf0e10cSrcweir         new FuzzyTester().doTest(intree, outtree);
4117*cdf0e10cSrcweir     }
4118*cdf0e10cSrcweir 
4119*cdf0e10cSrcweir     private void dumpTree(TreeNode tree) { dumpTree(tree, "> "); }
4120*cdf0e10cSrcweir 
4121*cdf0e10cSrcweir     private void dumpTree(TreeNode tree, String prefix)
4122*cdf0e10cSrcweir     {
4123*cdf0e10cSrcweir         System.out.println(prefix + tree.toString());
4124*cdf0e10cSrcweir         TreeNodeEnum children = tree.createEnumeration();
4125*cdf0e10cSrcweir         while (children.hasNext()) {
4126*cdf0e10cSrcweir             TreeNode node = children.next();
4127*cdf0e10cSrcweir             dumpTree(node, prefix + "  ");
4128*cdf0e10cSrcweir         }
4129*cdf0e10cSrcweir     }
4130*cdf0e10cSrcweir 
4131*cdf0e10cSrcweir     private String mkName(String prefix)
4132*cdf0e10cSrcweir     {
4133*cdf0e10cSrcweir         return prefix + String.valueOf(m_Count++);
4134*cdf0e10cSrcweir     }
4135*cdf0e10cSrcweir 
4136*cdf0e10cSrcweir     private StringPair mkId(String prefix)
4137*cdf0e10cSrcweir     {
4138*cdf0e10cSrcweir         return new StringPair("content.xml", mkName(prefix));
4139*cdf0e10cSrcweir     }
4140*cdf0e10cSrcweir 
4141*cdf0e10cSrcweir     private StringPair mkId_(String id)
4142*cdf0e10cSrcweir     {
4143*cdf0e10cSrcweir         return new StringPair("content.xml", id);
4144*cdf0e10cSrcweir     }
4145*cdf0e10cSrcweir 
4146*cdf0e10cSrcweir     static boolean eq(StringPair i_Left, StringPair i_Right)
4147*cdf0e10cSrcweir     {
4148*cdf0e10cSrcweir         return ((i_Left.First).equals(i_Right.First)) &&
4149*cdf0e10cSrcweir             ((i_Left.Second).equals(i_Right.Second));
4150*cdf0e10cSrcweir     }
4151*cdf0e10cSrcweir 
4152*cdf0e10cSrcweir     @BeforeClass public static void setUpConnection() throws Exception {
4153*cdf0e10cSrcweir         connection.setUp();
4154*cdf0e10cSrcweir     }
4155*cdf0e10cSrcweir 
4156*cdf0e10cSrcweir     @AfterClass public static void tearDownConnection()
4157*cdf0e10cSrcweir         throws InterruptedException, com.sun.star.uno.Exception
4158*cdf0e10cSrcweir     {
4159*cdf0e10cSrcweir         connection.tearDown();
4160*cdf0e10cSrcweir     }
4161*cdf0e10cSrcweir 
4162*cdf0e10cSrcweir     private static final OfficeConnection connection = new OfficeConnection();
4163*cdf0e10cSrcweir }
4164*cdf0e10cSrcweir 
4165