merge the formfield patch from ooo-build
[ooovba.git] / sw / qa / complex / writer / TextPortionEnumerationTest.java
blobaec77b891a0b19bc008ae30d16f7161618f5a48d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: $
10 * $Revision: $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package complex.writer;
33 import complexlib.ComplexTestCase;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.AnyConverter;
36 import com.sun.star.uno.XComponentContext;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.lang.XComponent;
39 import com.sun.star.lang.XServiceInfo;
40 import com.sun.star.beans.XPropertySet;
41 import com.sun.star.beans.XPropertySetInfo;
42 import com.sun.star.beans.PropertyValue;
43 import com.sun.star.beans.Pair;
44 import com.sun.star.beans.StringPair;
45 import com.sun.star.container.XNamed;
46 import com.sun.star.container.XContentEnumerationAccess;
47 import com.sun.star.container.XEnumerationAccess;
48 import com.sun.star.container.XEnumeration;
49 import com.sun.star.container.NoSuchElementException;
50 import com.sun.star.frame.XStorable;
51 import com.sun.star.util.XCloseable;
52 import com.sun.star.text.XText;
53 import com.sun.star.text.XTextContent;
54 import com.sun.star.text.XTextDocument;
55 import com.sun.star.text.XTextRange;
56 import com.sun.star.text.XTextCursor;
57 import com.sun.star.text.XWordCursor;
58 import com.sun.star.text.XSentenceCursor;
59 import com.sun.star.text.XParagraphCursor;
60 import com.sun.star.text.XFootnote;
61 import com.sun.star.text.XTextField;
62 import com.sun.star.text.TextContentAnchorType;
63 import static com.sun.star.text.TextContentAnchorType.*;
64 import static com.sun.star.text.ControlCharacter.*;
65 import com.sun.star.rdf.XMetadatable;
67 import java.util.Map;
68 import java.util.HashMap;
69 import java.util.List;
70 import java.util.ArrayList;
71 import java.util.Stack;
74 class TreeNodeEnum
76 private Object[] m_Elements;
77 private int m_Pos;
78 TreeNodeEnum(Object[] Elements) { m_Elements = Elements; m_Pos = 0; }
79 boolean hasNext() { return m_Pos < m_Elements.length; }
80 TreeNode next() { return (TreeNode) m_Elements[m_Pos++]; }
83 /** base class for tree nodes. only instance: root of tree. */
84 class TreeNode
86 private List<TreeNode> m_Children;
87 String getType() { return "__ROOT__"; }
88 boolean hasContent() { return false; }
89 boolean isNesting() { return false; }
90 TreeNode dup() { throw new RuntimeException("TreeNode.dup"); }
91 TreeNodeEnum createEnumeration() {
92 return new TreeNodeEnum(m_Children.toArray());
94 TreeNode() { m_Children = new ArrayList<TreeNode>(); }
95 TreeNode appendChild(TreeNode child)
96 { m_Children.add(child); return this; }
97 public String toString() {
98 return "<" + getType() + ">";
102 abstract class MarkNode extends TreeNode
104 boolean m_isPoint;
105 boolean m_isStart = false;
106 String m_Name;
107 boolean isPoint() { return m_isPoint; }
108 boolean isStart() { return m_isStart; }
109 String getName() { return m_Name; }
110 MarkNode(String name) { m_Name = name; m_isPoint = true; }
111 boolean equals(MarkNode other) {
112 return (other.m_Name.equals(m_Name)) && (other.m_isPoint == m_isPoint)
113 && (other.m_isStart == m_isStart);
115 public String toString() {
116 return super.toString() + "\tname: " + m_Name +
117 "\tisPoint: " + m_isPoint + "\tisStart: " + m_isStart;
121 class BookmarkNode extends MarkNode
123 private StringPair m_XmlId;
124 StringPair getXmlId() { return m_XmlId; }
125 BookmarkNode dup() { return new BookmarkNode(getName(), getXmlId()); }
126 BookmarkNode(String name) { this(name, new StringPair()); }
127 BookmarkNode(String name, StringPair xmlid) {
128 super(name); m_XmlId = xmlid;
130 String getType() { return "Bookmark"; }
131 public boolean equals(Object other) {
132 return (other instanceof BookmarkNode)
133 && super.equals((MarkNode) other)
134 && MetaNode.eq(((BookmarkNode) other).m_XmlId, m_XmlId);
136 public String toString() {
137 return super.toString()
138 + "\txmlid: " + m_XmlId.First + "#" + m_XmlId.Second;
142 class BookmarkStartNode extends BookmarkNode
144 BookmarkStartNode dup() { return new BookmarkStartNode(getName()); }
145 BookmarkStartNode(String name) { this(name, new StringPair()); }
146 BookmarkStartNode(String name, StringPair xmlid) {
147 super(name, xmlid); m_isPoint = false; m_isStart = true;
151 class BookmarkEndNode extends BookmarkNode
153 BookmarkEndNode dup() { return new BookmarkEndNode(getName()); }
154 BookmarkEndNode(String name) { this(name, new StringPair()); }
155 BookmarkEndNode(String name, StringPair xmlid) {
156 super(name, xmlid); m_isPoint = false; m_isStart = false;
160 class ReferenceMarkNode extends MarkNode
162 ReferenceMarkNode dup() { return new ReferenceMarkNode(getName()); }
163 ReferenceMarkNode(String name) { super(name); }
164 String getType() { return "ReferenceMark"; }
165 public boolean equals(Object other) {
166 return (other instanceof ReferenceMarkNode)
167 && super.equals((MarkNode) other);
171 class ReferenceMarkStartNode extends ReferenceMarkNode
173 ReferenceMarkStartNode dup()
174 { return new ReferenceMarkStartNode(getName()); }
175 ReferenceMarkStartNode(String name) {
176 super(name); m_isPoint = false; m_isStart = true;
180 class ReferenceMarkEndNode extends ReferenceMarkNode
182 ReferenceMarkEndNode dup()
183 { return new ReferenceMarkEndNode(getName()); }
184 ReferenceMarkEndNode(String name) {
185 super(name); m_isPoint = false; m_isStart = false;
189 class DocumentIndexMarkNode extends MarkNode
191 DocumentIndexMarkNode dup()
192 { return new DocumentIndexMarkNode(getName()); }
193 DocumentIndexMarkNode(String name) { super(name); }
194 String getType() { return "DocumentIndexMark"; }
195 public boolean equals(Object other) {
196 return (other instanceof DocumentIndexMarkNode)
197 && super.equals((MarkNode) other);
201 class DocumentIndexMarkStartNode extends DocumentIndexMarkNode
203 DocumentIndexMarkStartNode dup()
204 { return new DocumentIndexMarkStartNode(getName()); }
205 DocumentIndexMarkStartNode(String name) {
206 super(name); m_isPoint = false; m_isStart = true;
210 class DocumentIndexMarkEndNode extends DocumentIndexMarkNode
212 DocumentIndexMarkEndNode dup()
213 { return new DocumentIndexMarkEndNode(getName()); }
214 DocumentIndexMarkEndNode(String name) {
215 super(name); m_isPoint = false; m_isStart = false;
219 abstract class ContentNode extends TreeNode
221 private String m_Content;
222 String getContent() { return m_Content; }
223 boolean hasContent() { return true; }
224 ContentNode(String content) {
225 m_Content = content;
227 TreeNode appendChild(TreeNode t) {
228 throw new RuntimeException("ContentNode.appendChild");
230 public String toString() {
231 return super.toString() + "\tcontent: " + m_Content;
233 boolean equals(ContentNode other) {
234 return (other.m_Content.equals(m_Content));
238 class TextNode extends ContentNode
240 TextNode dup() { return new TextNode(getContent()); }
241 TextNode(String content) { super(content); }
242 String getType() { return "Text"; }
243 public boolean equals(Object other) {
244 return (other instanceof TextNode) && super.equals((ContentNode) other);
248 class TextFieldNode extends ContentNode
250 TextFieldNode dup() { return new TextFieldNode(getContent()); }
251 TextFieldNode(String content) { super(content); }
252 String getType() { return "TextField"; }
253 public boolean equals(Object other) {
254 return (other instanceof TextFieldNode)
255 && super.equals((ContentNode) other);
259 class FrameNode extends TreeNode
261 private String m_Name;
262 private TextContentAnchorType m_Anchor;
263 String getName() { return m_Name; }
264 TextContentAnchorType getAnchor() { return m_Anchor; }
265 FrameNode dup() { return new FrameNode(getName(), getAnchor()); }
266 FrameNode(String name, TextContentAnchorType anchor) {
267 m_Name = name; m_Anchor = anchor;
269 String getType() { return "Frame"; }
270 public boolean equals(Object other) {
271 return (other instanceof FrameNode)
272 && (((FrameNode) other).m_Name.equals(m_Name))
273 && (((FrameNode) other).m_Anchor == m_Anchor);
275 public String toString() {
276 return super.toString()
277 + "\tname: " + m_Name + "\tanchor: " + toString(m_Anchor);
279 static String toString(TextContentAnchorType anchor) {
280 switch (anchor.getValue()) {
281 case AS_CHARACTER_value: return "AS_CHARACTER";
282 case AT_CHARACTER_value: return "AT_CHARACTER";
283 case AT_PARAGRAPH_value: return "AT_PARAGRAPH";
284 case AT_PAGE_value: return "AT_PAGE";
285 case AT_FRAME_value: return "AT_FRAME";
286 default: throw new RuntimeException("unknown anchor");
291 class FootnoteNode extends TreeNode
293 private String m_Label;
294 String getLabel() { return m_Label; }
295 FootnoteNode dup() { return new FootnoteNode(getLabel()); }
296 FootnoteNode(String label) { m_Label = label; }
297 String getType() { return "Footnote"; }
298 public boolean equals(Object other) {
299 return (other instanceof FootnoteNode)
300 && (((FootnoteNode) other).m_Label.equals(m_Label));
302 public String toString() {
303 return super.toString() + "\tlabel: " + m_Label;
307 class ControlCharacterNode extends TreeNode
309 private short m_Char;
310 short getChar() { return m_Char; }
311 ControlCharacterNode dup() { return new ControlCharacterNode(getChar()); }
312 ControlCharacterNode(short c) { m_Char = c; }
313 String getType() { return "ControlCharacter"; }
314 public boolean equals(Object other) {
315 return (other instanceof ControlCharacterNode)
316 && (((ControlCharacterNode) other).m_Char == m_Char);
318 public String toString() {
319 return super.toString() + "\tchar: " + m_Char;
323 class SoftPageBreakNode extends TreeNode
325 String getType() { return "SoftPageBreak"; }
326 public boolean equals(Object other) {
327 return (other instanceof SoftPageBreakNode);
331 class HyperlinkNode extends TreeNode
333 private String m_URL;
334 String getURL() { return m_URL; }
335 HyperlinkNode dup() { return new HyperlinkNode(getURL()); }
336 HyperlinkNode(String url) {
337 if (url.length() == 0) throw new RuntimeException("HyperlinkNode");
338 m_URL = url;
340 String getType() { return "Hyperlink"; }
341 boolean isNesting() { return true; }
342 public boolean equals(Object other) {
343 return (other instanceof HyperlinkNode)
344 && (((HyperlinkNode) other).m_URL.equals(m_URL));
346 public String toString() {
347 return super.toString() + "\turl: " + m_URL;
351 class RubyNode extends TreeNode
353 private String m_Ruby;
354 String getRubyText() { return m_Ruby; }
355 RubyNode dup() { return new RubyNode(getRubyText()); }
356 RubyNode(String ruby) {
357 if (ruby.length() == 0) throw new RuntimeException("RubyNode");
358 m_Ruby = ruby;
360 String getType() { return "Ruby"; }
361 boolean isNesting() { return true; }
362 public boolean equals(Object other) {
363 return (other instanceof RubyNode)
364 && (((RubyNode) other).m_Ruby.equals(m_Ruby));
366 public String toString() {
367 return super.toString() + "\trubytext: " + m_Ruby;
371 class MetaNode extends TreeNode
373 private StringPair m_XmlId;
374 StringPair getXmlId() { return m_XmlId; }
375 MetaNode dup() { return new MetaNode(getXmlId()); }
376 MetaNode (StringPair xmlid) { m_XmlId = xmlid; }
377 String getType() { return "InContentMetadata"; }
378 boolean isNesting() { return true; }
379 public boolean equals(Object other) {
380 return (other instanceof MetaNode)
381 && eq(((MetaNode) other).m_XmlId, m_XmlId);
383 static boolean eq(StringPair left, StringPair right)
385 return left.First.equals(right.First)
386 && left.Second.equals(right.Second);
388 public String toString() {
389 return super.toString()
390 + "\txmlid: " + m_XmlId.First + "#" + m_XmlId.Second;
394 class MetaFieldNode extends MetaNode
396 MetaFieldNode dup() { return new MetaFieldNode(getXmlId()); }
397 MetaFieldNode (StringPair xmlid) { super(xmlid); }
398 String getType() { return "MetadataField"; }
401 class Range
403 private short m_Start;
404 private short m_End;
405 private TreeNode m_Node;
406 short getStart() { return m_Start; }
407 short getEnd() { return m_End ; }
408 short getExtent() { return (short) (m_End - m_Start); }
409 TreeNode getNode() { return m_Node; }
410 Range(int start, int end, TreeNode node)
411 { m_Start = (short) start; m_End = (short) end; m_Node = node; }
414 //----------------------------------------------------------------------
416 /* this is where we nail the pudding to the wall */
417 class FuzzyTester
419 private long m_DiffContent = 0;
420 private long m_DiffMissing = 0;
421 private long m_DiffNesting = 0;
422 private long m_DiffSpuriousEmptyText = 0;
423 private long m_DiffSequence = 0; // ignored?
424 private Stack<Pair<TreeNode, TreeNodeEnum>> m_StackExpected;
425 private Stack<Pair<TreeNode, TreeNodeEnum>> m_StackActual;
426 private List<TreeNode> m_BufferExpected;
427 private List<TreeNode> m_BufferActual;
428 private share.LogWriter m_Log;
430 FuzzyTester(share.LogWriter log) {
431 m_Log = log;
432 m_BufferExpected = new ArrayList<TreeNode>();
433 m_BufferActual = new ArrayList<TreeNode>();
434 m_StackExpected = new Stack<Pair<TreeNode, TreeNodeEnum>>();
435 m_StackActual = new Stack<Pair<TreeNode, TreeNodeEnum>>();
438 /** idea: traverse both trees, enumerate nodes, stopping at content nodes.
439 then compare buffers. */
440 boolean doTest(TreeNode expected, TreeNode actual)
442 if (!expected.getType().equals("__ROOT__"))
443 throw new RuntimeException("doTest: expected: root");
444 if (!actual.getType().equals("__ROOT__"))
445 throw new RuntimeException("doTest: actual: root");
446 m_StackExpected.push(new Pair(expected, expected.createEnumeration()));
447 m_StackActual.push(new Pair(actual, actual.createEnumeration()));
448 do {
449 traverse(m_StackExpected, m_BufferExpected);
450 traverse(m_StackActual, m_BufferActual);
451 //??? root?
452 testBuffer();
453 } while (!m_StackExpected.empty() || !m_StackActual.empty());
454 if (m_DiffSequence != 0) {
455 m_Log.println("warning: " + m_DiffSequence
456 + " differences in sequence");
458 if (m_DiffSpuriousEmptyText != 0) {
459 m_Log.println("warning: " + m_DiffSpuriousEmptyText
460 + " spurious empty text nodes");
462 if (m_DiffNesting != 0) {
463 m_Log.println("WARNING: " + m_DiffNesting
464 + " differences in nesting");
466 return (m_DiffContent == 0) && (m_DiffMissing == 0);
469 private void traverse(Stack<Pair<TreeNode, TreeNodeEnum>> stack,
470 List<TreeNode> buffer)
472 while (!stack.empty()) {
473 TreeNodeEnum topEnum = stack.peek().Second;
474 if (topEnum.hasNext()) {
475 TreeNode node = topEnum.next();
476 buffer.add(node);
477 TreeNodeEnum nodeEnum = node.createEnumeration();
478 if (nodeEnum.hasNext()) {
479 stack.push(new Pair(node, nodeEnum));
481 if (node.hasContent()) {
482 if (!((node instanceof TextNode) // spurious empty text?
483 && ((TextNode) node).getContent().length() == 0)) {
484 return; // break here
487 } else {
488 buffer.add(stack.peek().First);
489 stack.pop();
494 private void testTerminatingNode()
496 int lenExpected = m_BufferExpected.size();
497 int lenActual = m_BufferActual.size();
498 if (lenExpected == 0 || lenActual == 0)
499 return;
500 TreeNode expected = m_BufferExpected.get(lenExpected - 1);
501 TreeNode actual = m_BufferActual.get(lenActual - 1);
503 boolean eRoot = expected.getType().equals("__ROOT__");
504 boolean aRoot = actual.getType().equals("__ROOT__");
505 if (eRoot || aRoot) {
506 if (!(eRoot && aRoot)) {
507 if (aRoot) printMissing(expected);
508 else printUnexpected(actual);
509 m_DiffMissing++;
511 return;
514 testContentNode((ContentNode) expected, (ContentNode) actual);
516 m_BufferExpected.set(lenExpected - 1, null);
517 m_BufferActual.set(lenActual - 1, null);
520 private void testContentNode(ContentNode expected, ContentNode actual)
522 String contentExpected = expected.getContent();
523 String contentActual = actual.getContent();
524 if (!expected.equals(actual)) {
525 printDiff("text content differs", contentExpected, contentActual);
526 m_DiffContent++;
530 private void testBuffer()
532 int lenExpected = m_BufferExpected.size();
533 int lenActual = m_BufferActual.size();
534 for (int i = 0; i < lenExpected - 1; i++ )
536 TreeNode node = m_BufferExpected.get(i);
537 int j = m_BufferActual.indexOf(node);
538 if (j >= 0) {
539 TreeNode other = m_BufferActual.get(j);
540 if (j != i)
542 //FIXME how bad is this?
543 printDiff("position differs",
544 String.valueOf(i), String.valueOf(j));
545 // a hacky hack
546 int min = Math.min(i,j);
547 int max = Math.max(Math.min(lenActual - 1, i),j);
548 for (int k = min; k != max; k ++) {
549 TreeNode tmp = m_BufferActual.get(k);
550 if (tmp != null && tmp.isNesting()) {
551 printNesting(node, tmp);
552 m_DiffNesting++;
555 m_DiffSequence++;
557 m_BufferActual.set(j, null);
558 } else {
559 //m_Log.println("testBuffer:");
560 printMissing(node);
561 m_DiffMissing++;
564 for (int j = 0; j < lenActual - 1; j++)
566 TreeNode node = m_BufferActual.get(j);
567 if (node != null)
569 //m_Log.println("testBuffer:");
570 printUnexpected(node);
571 if ((node instanceof TextNode) &&
572 ((TextNode) node).getContent().length() == 0) {
573 m_DiffSpuriousEmptyText++;
574 } else {
575 m_DiffMissing++;
579 testTerminatingNode();
580 m_BufferExpected.clear();
581 m_BufferActual.clear();
584 void printDiff(String prefix, String expected, String actual)
586 m_Log.println(prefix +
587 ":\texpected: " + expected + "\tactual: " + actual);
590 void printNesting(TreeNode node, TreeNode nesting)
592 m_Log.println("node: " + node.toString()
593 + " possibly moved across nesting " + nesting.toString());
596 void printMissing(TreeNode node)
598 m_Log.println(" missing node: " + node.toString());
602 void printUnexpected(TreeNode node)
604 m_Log.println("unexpected node: " + node.toString());
610 //----------------------------------------------------------------------
612 class EnumConverter
614 private Stack<TreeNode> m_Stack;
615 TextPortionEnumerationTest m_T;
617 EnumConverter(TextPortionEnumerationTest err) {
618 m_Stack = new Stack<TreeNode>(); m_T = err;
621 TreeNode convert(XEnumeration xEnum) throws Exception
623 TreeNode root = new TreeNode();
624 m_Stack.push(root);
625 TreeNode ret = convertChildren(xEnum);
626 m_T.assure("EnumConverter.convert: stack", m_Stack.empty());
627 return ret;
630 TreeNode convertChildren(XEnumeration xEnum) throws Exception
632 while (xEnum.hasMoreElements()) {
633 TreeNode node;
634 Object xElement = xEnum.nextElement();
635 XTextRange xPortion = (XTextRange)
636 UnoRuntime.queryInterface(XTextRange.class, xElement);
637 XPropertySet xPropSet = (XPropertySet)
638 UnoRuntime.queryInterface(XPropertySet.class, xPortion);
639 String type = (String) xPropSet.getPropertyValue("TextPortionType");
640 if (type.equals("Text")) {
641 String text = xPortion.getString();
642 node = new TextNode(text);
643 String url = (String) xPropSet.getPropertyValue("HyperLinkURL");
644 if (url.length() > 0) {
645 TreeNode temp = node;
646 node = new HyperlinkNode(url);
647 node.appendChild(temp);
649 } else if (type.equals("TextField")) {
650 Object xField = xPropSet.getPropertyValue("TextField");
651 XServiceInfo xService = (XServiceInfo)
652 UnoRuntime.queryInterface(XServiceInfo.class, xField);
653 if (xService.supportsService(
654 "com.sun.star.text.textfield.MetadataField"))
656 XMetadatable xMeta = (XMetadatable)
657 UnoRuntime.queryInterface(XMetadatable.class, xField);
658 StringPair xmlid = xMeta.getMetadataReference();
659 node = new MetaFieldNode(xmlid);
660 m_Stack.push(node);
661 XEnumerationAccess xEA = (XEnumerationAccess)
662 UnoRuntime.queryInterface(XEnumerationAccess.class,
663 xMeta);
664 XEnumeration xEnumChildren = xEA.createEnumeration();
665 TreeNode node2 = convertChildren(xEnumChildren);
666 m_T.assure("stack error: meta-field", node == node2);
667 } else {
668 XPropertySet xFieldPropSet = (XPropertySet)
669 UnoRuntime.queryInterface(XPropertySet.class, xField);
670 String content = (String)
671 xFieldPropSet.getPropertyValue("Content");
672 boolean isFixed = (Boolean)
673 xFieldPropSet.getPropertyValue("IsFixed");
674 m_T.assure("field not fixed?", isFixed);
675 node = new TextFieldNode(content);
677 } else if (type.equals("Footnote")) {
678 Object xNote = xPropSet.getPropertyValue("Footnote");
679 XFootnote xFootnote = (XFootnote)
680 UnoRuntime.queryInterface(XFootnote.class, xNote);
681 String label = xFootnote.getLabel();
682 node = new FootnoteNode(label);
683 } else if (type.equals("Frame")) {
684 XContentEnumerationAccess xCEA = (XContentEnumerationAccess)
685 UnoRuntime.queryInterface(XContentEnumerationAccess.class,
686 xPortion);
687 XEnumeration xContentEnum = xCEA.createContentEnumeration("");
688 while (xContentEnum.hasMoreElements()) {
689 Object xFrame = xContentEnum.nextElement();
690 XPropertySet xFramePropSet = (XPropertySet)
691 UnoRuntime.queryInterface(XPropertySet.class, xFrame);
692 TextContentAnchorType anchor = (TextContentAnchorType)
693 xFramePropSet.getPropertyValue("AnchorType");
694 XNamed xNamed = (XNamed)
695 UnoRuntime.queryInterface(XNamed.class, xFrame);
696 String name = xNamed.getName();
697 node = new FrameNode(name, anchor);
698 m_Stack.peek().appendChild(node);
700 continue;
701 } else if (type.equals("ControlCharacter")) {
702 short c = (Short)
703 xPropSet.getPropertyValue("ControlCharacter");
704 node = new ControlCharacterNode(c);
705 } else if (type.equals("Bookmark")) {
706 Object xMark = xPropSet.getPropertyValue("Bookmark");
707 XNamed xNamed = (XNamed)
708 UnoRuntime.queryInterface(XNamed.class, xMark);
709 String name = xNamed.getName();
710 XMetadatable xMetadatable = (XMetadatable)
711 UnoRuntime.queryInterface(XMetadatable.class, xMark);
712 StringPair xmlid = xMetadatable.getMetadataReference();
713 boolean isCollapsed = (Boolean)
714 xPropSet.getPropertyValue("IsCollapsed");
715 if (isCollapsed) {
716 node = new BookmarkNode(name, xmlid);
717 } else {
718 boolean isStart = (Boolean)
719 xPropSet.getPropertyValue("IsStart");
720 if (isStart) {
721 node = new BookmarkStartNode(name, xmlid);
722 } else {
723 node = new BookmarkEndNode(name, xmlid);
726 } else if (type.equals("ReferenceMark")) {
727 Object xMark = xPropSet.getPropertyValue("ReferenceMark");
728 XNamed xNamed = (XNamed)
729 UnoRuntime.queryInterface(XNamed.class, xMark);
730 String name = xNamed.getName();
731 boolean isCollapsed = (Boolean)
732 xPropSet.getPropertyValue("IsCollapsed");
733 if (isCollapsed) {
734 node = new ReferenceMarkNode(name);
735 } else {
736 boolean isStart = (Boolean)
737 xPropSet.getPropertyValue("IsStart");
738 if (isStart) {
739 node = new ReferenceMarkStartNode(name);
740 } else {
741 node = new ReferenceMarkEndNode(name);
744 } else if (type.equals("DocumentIndexMark")) {
745 Object xMark = xPropSet.getPropertyValue("DocumentIndexMark");
746 XPropertySet xMarkSet = (XPropertySet)
747 UnoRuntime.queryInterface(XPropertySet.class, xMark);
748 String name = (String) xMarkSet.getPropertyValue("PrimaryKey");
749 boolean isCollapsed = (Boolean)
750 xPropSet.getPropertyValue("IsCollapsed");
751 if (isCollapsed) {
752 node = new DocumentIndexMarkNode(name);
753 } else {
754 boolean isStart = (Boolean)
755 xPropSet.getPropertyValue("IsStart");
756 if (isStart) {
757 node = new DocumentIndexMarkStartNode(name);
758 } else {
759 node = new DocumentIndexMarkEndNode(name);
762 } else if (type.equals("SoftPageBreak")) {
763 node = new SoftPageBreakNode();
764 } else if (type.equals("Ruby")) {
765 boolean isStart = (Boolean)
766 xPropSet.getPropertyValue("IsStart");
767 if (isStart) {
768 // ARRGH!!! stupid api...
769 // the text is ONLY at the start!
770 String ruby = (String)
771 xPropSet.getPropertyValue("RubyText");
772 node = new RubyNode(ruby);
773 m_Stack.push(node);
774 continue;
775 } else {
776 node = m_Stack.pop();
777 m_T.assure("stack error: Ruby expected; is: " +
778 node.toString(), node instanceof RubyNode);
779 // m_T.assure("stack error: ruby",
780 // ruby.equals(((RubyNode)node).getRubyText()));
782 } else if (type.equals("InContentMetadata")) {
783 Object xMeta = xPropSet.getPropertyValue("InContentMetadata");
784 XMetadatable xMetadatable = (XMetadatable)
785 UnoRuntime.queryInterface(XMetadatable.class, xMeta);
786 StringPair xmlid = xMetadatable.getMetadataReference();
787 node = new MetaNode(xmlid);
788 m_Stack.push(node);
789 XEnumerationAccess xEA = (XEnumerationAccess)
790 UnoRuntime.queryInterface(XEnumerationAccess.class, xMeta);
791 XEnumeration xEnumChildren = xEA.createEnumeration();
792 TreeNode node2 = convertChildren(xEnumChildren);
793 m_T.assure("stack error: meta", node == node2);
794 // } else if (type.equals("MetadataField")) {
795 // Object xMeta = xPropSet.getPropertyValue("MetadataField");
796 } else {
797 throw new RuntimeException("unexpected type: " + type);
799 m_Stack.peek().appendChild(node);
801 TreeNode ret = m_Stack.pop();
802 return ret;
807 //----------------------------------------------------------------------
809 abstract class Inserter
811 private XMultiServiceFactory m_xDocFactory;
812 XText m_xText;
813 XParagraphCursor m_xCursor;
815 Inserter(XTextDocument xDoc)
817 m_xDocFactory = (XMultiServiceFactory)
818 UnoRuntime.queryInterface(XMultiServiceFactory.class, xDoc);
819 m_xText = xDoc.getText();
820 XTextCursor xCursor = m_xText.createTextCursor();
821 m_xCursor = (XParagraphCursor)
822 UnoRuntime.queryInterface(XParagraphCursor.class, xCursor);
825 void initParagraph() throws Exception
827 m_xCursor.gotoStartOfParagraph(false);
828 m_xText.insertControlCharacter(m_xCursor, PARAGRAPH_BREAK, false);
829 // we split the first (empty) paragraph, and then insert into the
830 // second (empty) paragraph; this ensures first is always empty!
833 void insertControlCharacter(XTextCursor xCursor, short cchar)
834 throws Exception
836 m_xText.insertControlCharacter(xCursor, cchar, false);
839 void insertText(XTextCursor xCursor, String text)
841 xCursor.setString(text);
844 void insertTextField(XTextCursor xCursor, String content) throws Exception
846 XTextContent xContent = makeTextField(content);
847 xContent.attach(xCursor);
850 XTextContent makeTextField(String content)
851 throws Exception
853 Object xField =
854 m_xDocFactory.createInstance("com.sun.star.text.textfield.Author");
855 XTextContent xContent = (XTextContent)
856 UnoRuntime.queryInterface(XTextContent.class, xField);
857 XPropertySet xPropSet = (XPropertySet)
858 UnoRuntime.queryInterface(XPropertySet.class, xField);
859 xPropSet.setPropertyValue("IsFixed", true);
860 xPropSet.setPropertyValue("FullName", false);
861 xPropSet.setPropertyValue("Content", content);
862 return xContent;
865 void insertFrame(XTextRange xCursor, String name,
866 TextContentAnchorType anchor) throws Exception
868 XTextContent xContent = makeFrame(name, anchor);
869 xContent.attach(xCursor);
872 XTextContent makeFrame(String name, TextContentAnchorType anchor)
873 throws Exception
875 Object xFrame =
876 m_xDocFactory.createInstance("com.sun.star.text.TextFrame");
877 XTextContent xContent = (XTextContent)
878 UnoRuntime.queryInterface(XTextContent.class, xFrame);
879 XPropertySet xPropSet = (XPropertySet)
880 UnoRuntime.queryInterface(XPropertySet.class, xFrame);
881 xPropSet.setPropertyValue("AnchorType", anchor);
882 XNamed xNamed = (XNamed)
883 UnoRuntime.queryInterface(XNamed.class, xContent);
884 xNamed.setName(name);
885 return xContent;
888 void insertFootnote(XTextCursor xCursor, String label) throws Exception
890 XTextContent xContent = makeFootnote(label);
891 xContent.attach(xCursor);
894 XTextContent makeFootnote(String label) throws Exception
896 Object xNote =
897 m_xDocFactory.createInstance("com.sun.star.text.Footnote");
898 XTextContent xContent = (XTextContent)
899 UnoRuntime.queryInterface(XTextContent.class, xNote);
900 XFootnote xFootnote = (XFootnote)
901 UnoRuntime.queryInterface(XFootnote.class, xNote);
902 xFootnote.setLabel(label);
903 return xContent;
906 void insertBookmark(XTextCursor xCursor, String name, StringPair xmlid)
907 throws Exception
909 XTextContent xContent = makeBookmark(name);
910 xContent.attach(xCursor);
911 if (!xmlid.First.equals(""))
913 XMetadatable xMetadatable = (XMetadatable)
914 UnoRuntime.queryInterface(XMetadatable.class, xContent);
915 xMetadatable.setMetadataReference(xmlid);
919 XTextContent makeBookmark(String name) throws Exception
921 Object xBookmark =
922 m_xDocFactory.createInstance("com.sun.star.text.Bookmark");
923 XTextContent xContent = (XTextContent)
924 UnoRuntime.queryInterface(XTextContent.class, xBookmark);
925 XNamed xNamed = (XNamed)
926 UnoRuntime.queryInterface(XNamed.class, xContent);
927 xNamed.setName(name);
928 return xContent;
931 void insertReferenceMark(XTextCursor xCursor, String name) throws Exception
933 XTextContent xContent = makeReferenceMark(name);
934 xContent.attach(xCursor);
937 XTextContent makeReferenceMark(String name) throws Exception
939 Object xMark =
940 m_xDocFactory.createInstance("com.sun.star.text.ReferenceMark");
941 XTextContent xContent = (XTextContent)
942 UnoRuntime.queryInterface(XTextContent.class, xMark);
943 XNamed xNamed = (XNamed)
944 UnoRuntime.queryInterface(XNamed.class, xContent);
945 xNamed.setName(name);
946 return xContent;
949 void insertDocumentIndexMark(XTextCursor xCursor, String key)
950 throws Exception
952 XTextContent xContent = makeDocumentIndexMark(key);
953 xContent.attach(xCursor);
956 XTextContent makeDocumentIndexMark(String key) throws Exception
958 Object xMark =
959 m_xDocFactory.createInstance("com.sun.star.text.DocumentIndexMark");
960 XTextContent xContent = (XTextContent)
961 UnoRuntime.queryInterface(XTextContent.class, xMark);
962 XPropertySet xPropSet = (XPropertySet)
963 UnoRuntime.queryInterface(XPropertySet.class, xMark);
964 xPropSet.setPropertyValue("PrimaryKey", key);
965 return xContent;
968 void insertHyperlink(XTextCursor xCursor, String url) throws Exception
970 XPropertySet xPropSet = (XPropertySet)
971 UnoRuntime.queryInterface(XPropertySet.class, xCursor);
972 xPropSet.setPropertyValue("HyperLinkURL", url);
975 void insertRuby(XTextCursor xCursor, String rubytext) throws Exception
977 XPropertySet xPropSet = (XPropertySet)
978 UnoRuntime.queryInterface(XPropertySet.class, xCursor);
979 xPropSet.setPropertyValue("RubyText", rubytext);
982 void insertMeta(XTextCursor xCursor, StringPair xmlid)
983 throws Exception
985 XTextContent xContent = makeMeta();
986 xContent.attach(xCursor);
987 XMetadatable xMetadatable = (XMetadatable)
988 UnoRuntime.queryInterface(XMetadatable.class, xContent);
989 xMetadatable.setMetadataReference(xmlid);
992 XTextContent makeMeta() throws Exception
994 Object xMeta = m_xDocFactory.createInstance(
995 "com.sun.star.text.InContentMetadata");
996 XTextContent xContent = (XTextContent)
997 UnoRuntime.queryInterface(XTextContent.class, xMeta);
998 return xContent;
1001 void insertMetaField(XTextCursor xCursor, StringPair xmlid)
1002 throws Exception
1004 XTextContent xContent = makeMetaField();
1005 xContent.attach(xCursor);
1006 XMetadatable xMetadatable = (XMetadatable)
1007 UnoRuntime.queryInterface(XMetadatable.class, xContent);
1008 xMetadatable.setMetadataReference(xmlid);
1011 XTextField makeMetaField() throws Exception
1013 Object xMeta = m_xDocFactory.createInstance(
1014 "com.sun.star.text.textfield.MetadataField");
1015 XTextField xContent = (XTextField)
1016 UnoRuntime.queryInterface(XTextField.class, xMeta);
1017 return xContent;
1022 class TreeInserter extends Inserter
1024 private Map<String, XTextRange> m_BookmarkStarts;
1025 private Map<String, XTextRange> m_ReferenceMarkStarts;
1026 private Map<String, XTextRange> m_DocumentIndexMarkStarts;
1027 private List<Pair<XTextRange, FrameNode>> m_FrameHints;
1029 TreeInserter(XTextDocument xDoc)
1031 super(xDoc);
1032 m_BookmarkStarts = new HashMap<String, XTextRange>();
1033 m_ReferenceMarkStarts = new HashMap<String, XTextRange>();
1034 m_DocumentIndexMarkStarts = new HashMap<String, XTextRange>();
1035 m_FrameHints = new ArrayList<Pair<XTextRange, FrameNode>>();
1038 void insertTree(TreeNode tree) throws Exception
1040 if (!tree.getType().equals("__ROOT__"))
1041 throw new RuntimeException("insertTree: test error: no root");
1042 initParagraph();
1043 insertChildren(tree.createEnumeration());
1044 for (int i = 0; i < m_FrameHints.size(); ++i) {
1045 Pair<XTextRange, FrameNode> p = m_FrameHints.get(i);
1046 insertFrame(p.First, p.Second.getName(), p.Second.getAnchor());
1050 void insertChildren(TreeNodeEnum children) throws Exception
1052 while (children.hasNext()) {
1053 m_xCursor.gotoEndOfParagraph(false);
1054 TreeNode node = children.next();
1055 String type = node.getType();
1056 if (type.equals("Bookmark")) {
1057 BookmarkNode bkmk = (BookmarkNode) node;
1058 String name = bkmk.getName();
1059 StringPair id = bkmk.getXmlId();
1060 if (bkmk.isPoint()) {
1061 insertBookmark(m_xCursor, name, id);
1062 } else if (bkmk.isStart()) {
1063 m_BookmarkStarts.put(name, m_xCursor.getStart());
1064 } else {
1065 XTextRange xRange = m_BookmarkStarts.get(name);
1066 XParagraphCursor xCursor = mkCursor(xRange);
1067 insertBookmark(xCursor, name, id);
1069 } else if (type.equals("ReferenceMark")) {
1070 ReferenceMarkNode mark = (ReferenceMarkNode) node;
1071 String name = mark.getName();
1072 if (mark.isPoint()) {
1073 insertReferenceMark(m_xCursor, name);
1074 } else if (mark.isStart()) {
1075 m_ReferenceMarkStarts.put(name, m_xCursor.getStart());
1076 } else {
1077 XTextRange xRange = m_ReferenceMarkStarts.get(name);
1078 XParagraphCursor xCursor = mkCursor(xRange);
1079 insertReferenceMark(xCursor, name);
1081 } else if (type.equals("DocumentIndexMark")) {
1082 DocumentIndexMarkNode mark = (DocumentIndexMarkNode) node;
1083 String name = mark.getName();
1084 if (mark.isPoint()) {
1085 insertDocumentIndexMark(m_xCursor, name);
1086 } else if (mark.isStart()) {
1087 m_DocumentIndexMarkStarts.put(name, m_xCursor.getStart());
1088 } else {
1089 XTextRange xRange = m_DocumentIndexMarkStarts.get(name);
1090 XParagraphCursor xCursor = mkCursor(xRange);
1091 insertDocumentIndexMark(xCursor, name);
1093 } else if (type.equals("Hyperlink")) {
1094 HyperlinkNode href = (HyperlinkNode) node;
1095 XTextRange xRange = m_xCursor.getStart();
1096 insertChildren(href.createEnumeration());
1097 XParagraphCursor xCursor = mkCursor(xRange);
1098 insertHyperlink(xCursor, href.getURL());
1099 } else if (type.equals("Ruby")) {
1100 RubyNode ruby = (RubyNode) node;
1101 XTextRange xRange = m_xCursor.getStart();
1102 insertChildren(ruby.createEnumeration());
1103 XParagraphCursor xCursor = mkCursor(xRange);
1104 insertRuby(xCursor, ruby.getRubyText());
1105 } else if (type.equals("InContentMetadata")) {
1106 MetaNode meta = (MetaNode) node;
1107 XTextRange xRange = m_xCursor.getStart();
1108 insertChildren(meta.createEnumeration());
1109 XParagraphCursor xCursor = mkCursor(xRange);
1110 insertMeta(xCursor, meta.getXmlId());
1111 } else if (type.equals("MetadataField")) {
1112 MetaFieldNode meta = (MetaFieldNode) node;
1113 XTextRange xRange = m_xCursor.getStart();
1114 insertChildren(meta.createEnumeration());
1115 XParagraphCursor xCursor = mkCursor(xRange);
1116 insertMetaField(xCursor, meta.getXmlId());
1117 } else if (type.equals("Text")) {
1118 TextNode text = (TextNode) node;
1119 insertText(m_xCursor, text.getContent());
1120 } else if (type.equals("TextField")) {
1121 TextFieldNode field = (TextFieldNode) node;
1122 insertTextField(m_xCursor, field.getContent());
1123 } else if (type.equals("Footnote")) {
1124 FootnoteNode note = (FootnoteNode) node;
1125 insertFootnote(m_xCursor, note.getLabel());
1126 } else if (type.equals("Frame")) {
1127 FrameNode frame = (FrameNode) node;
1128 if (frame.getAnchor() == AT_CHARACTER) {
1129 m_FrameHints.add( new Pair(m_xCursor.getStart(), frame) );
1130 } else {
1131 insertFrame(m_xCursor, frame.getName(), frame.getAnchor());
1133 } else if (type.equals("ControlCharacter")) {
1134 ControlCharacterNode cchar = (ControlCharacterNode) node;
1135 insertControlCharacter(m_xCursor, cchar.getChar());
1136 } else if (type.equals("SoftPageBreak")) {
1137 SoftPageBreakNode spbk = (SoftPageBreakNode) node;
1138 throw new RuntimeException("sorry, cannot test SoftPageBreak");
1139 } else {
1140 throw new RuntimeException("unexpected type: " + type);
1145 XParagraphCursor mkCursor(XTextRange xRange)
1147 XTextCursor xCursor = m_xText.createTextCursorByRange(xRange);
1148 XParagraphCursor xParaCursor = (XParagraphCursor)
1149 UnoRuntime.queryInterface(XParagraphCursor.class, xCursor);
1150 xParaCursor.gotoEndOfParagraph(true);
1151 return xParaCursor;
1156 // FIXME: this does not account for inserted dummy characters!
1157 class RangeInserter extends Inserter
1159 RangeInserter(XTextDocument xDoc) throws Exception
1160 { super(xDoc); initParagraph(); }
1163 void insertText(int pos, String text)
1165 m_xCursor.gotoStartOfParagraph(false);
1166 m_xCursor.goRight((short) pos, false);
1167 insertText(m_xCursor, text);
1171 void insertRange(Range range) throws Exception
1173 m_xCursor.gotoStartOfParagraph(false);
1174 m_xCursor.goRight(range.getStart(), false);
1175 m_xCursor.goRight(range.getExtent(), true);
1176 insertNode(m_xCursor, range.getNode());
1179 void insertNode(XParagraphCursor xCursor, TreeNode node) throws Exception
1181 String type = node.getType();
1182 if (type.equals("Bookmark")) {
1183 BookmarkNode bkmk = (BookmarkNode) node;
1184 if (bkmk.isPoint()) throw new RuntimeException("range only");
1185 insertBookmark(xCursor, bkmk.getName(), bkmk.getXmlId());
1186 } else if (type.equals("ReferenceMark")) {
1187 ReferenceMarkNode mark = (ReferenceMarkNode) node;
1188 if (mark.isPoint()) throw new RuntimeException("range only");
1189 insertReferenceMark(xCursor, mark.getName());
1190 } else if (type.equals("DocumentIndexMark")) {
1191 DocumentIndexMarkNode mark = (DocumentIndexMarkNode) node;
1192 if (mark.isPoint()) throw new RuntimeException("range only");
1193 insertDocumentIndexMark(xCursor, mark.getName());
1194 } else if (type.equals("Hyperlink")) {
1195 HyperlinkNode href = (HyperlinkNode) node;
1196 insertHyperlink(xCursor, href.getURL());
1197 } else if (type.equals("Ruby")) {
1198 RubyNode ruby = (RubyNode) node;
1199 insertRuby(xCursor, ruby.getRubyText());
1200 } else if (type.equals("InContentMetadata")) {
1201 MetaNode meta = (MetaNode) node;
1202 insertMeta(xCursor, meta.getXmlId());
1203 } else if (type.equals("MetadataField")) {
1204 MetaFieldNode meta = (MetaFieldNode) node;
1205 insertMetaField(xCursor, meta.getXmlId());
1206 } else if (type.equals("Text")) {
1207 TextNode text = (TextNode) node;
1208 insertText(xCursor, text.getContent());
1209 } else if (type.equals("TextField")) {
1210 TextFieldNode field = (TextFieldNode) node;
1211 insertTextField(m_xCursor, field.getContent());
1212 } else if (type.equals("Footnote")) {
1213 FootnoteNode note = (FootnoteNode) node;
1214 insertFootnote(m_xCursor, note.getLabel());
1215 } else if (type.equals("Frame")) {
1216 FrameNode frame = (FrameNode) node;
1217 insertFrame(xCursor, frame.getName(), frame.getAnchor());
1218 } else if (type.equals("ControlCharacter")) {
1219 ControlCharacterNode cchar = (ControlCharacterNode) node;
1220 insertControlCharacter(m_xCursor, cchar.getChar());
1221 } else if (type.equals("SoftPageBreak")) {
1222 throw new RuntimeException("sorry, cannot test SoftPageBreak");
1223 } else {
1224 throw new RuntimeException("unexpected type: " + type);
1230 //----------------------------------------------------------------------
1232 public class TextPortionEnumerationTest extends ComplexTestCase
1234 private XMultiServiceFactory m_xMSF = null;
1235 private XComponentContext m_xContext = null;
1236 private XTextDocument m_xDoc = null;
1237 private String m_TmpDir = null;
1239 private int m_Count = 1;
1241 // public String[] getTestMethodNames() { return new String[] { "testLoadStore" }; }
1242 public String[] getTestMethodNames() {
1243 return new String[] {
1244 "testText",
1245 "testTextField",
1246 // "testControlChar",
1247 // "testSoftPageBreak",
1248 "testFootnote",
1249 "testFrameAs",
1250 "testFrameAt",
1251 "testBookmarkPoint",
1252 "testBookmark",
1253 "testBookmarkPointXmlId",
1254 "testBookmarkXmlId",
1255 "testRefmarkPoint",
1256 "testRefmark",
1257 "testToxmarkPoint",
1258 "testToxmark",
1259 "testHyperlink",
1260 "testHyperlinkEmpty",
1261 "testRuby",
1262 "testRubyEmpty",
1263 "testMeta",
1264 "testMetaEmpty",
1265 "testMetaField",
1266 "testMetaFieldEmpty",
1267 "testBookmark1",
1268 "testBookmark2",
1269 "testRefMark2",
1270 "testRefMark3",
1271 "testToxMark2",
1272 "testToxMark3",
1273 "testMarks1",
1274 "testMarks2",
1275 "testMarks3",
1276 "testFrameMark1",
1277 "testFrameMark2",
1278 "testFrameMark3",
1279 "testFrameMark4",
1280 "testFrames1",
1281 "testFrames2",
1282 "testFrames3",
1283 "testFrames4",
1284 "testFrames5",
1285 "testRubyHyperlink1",
1286 "testRubyHyperlink2",
1287 "testEnd1",
1288 "testEnd2",
1289 "testEnd3",
1290 "testEnd4",
1291 "testEnd5",
1292 "testEmpty1",
1293 "testEmpty2",
1294 "testEmpty3",
1295 "test1",
1296 "testRange1",
1297 "testRangeHyperlinkHyperlink",
1298 "testRangeHyperlinkRuby",
1299 "testRangeRubyHyperlink",
1300 "testRangeRubyRuby",
1301 "testRangeHyperlinkMeta",
1302 "testRangeRubyMeta",
1303 "testRangeMetaHyperlink",
1304 "testRangeMetaRuby",
1305 "testRangeMetaMeta",
1306 "testRange2",
1307 "testRange3",
1308 "testRange4",
1309 "testRange5",
1310 "testRange6",
1311 "testRange7",
1312 "testMetaXText",
1313 "testMetaXTextCursor",
1314 "testMetaXTextAttachToxMark",
1315 "testMetaXTextAttachRefMark",
1316 "testMetaXTextAttachTextField",
1317 "testMetaXTextAttachFootnote",
1318 "testMetaXTextAttachMeta",
1319 "testMetaFieldXTextField",
1320 "testMetaFieldXPropertySet",
1321 "testLoadStore",
1325 public void before() throws Exception
1327 m_xMSF = (XMultiServiceFactory) param.getMSF();
1328 XPropertySet xPropertySet = (XPropertySet)
1329 UnoRuntime.queryInterface(XPropertySet.class, m_xMSF);
1330 Object defaultCtx = xPropertySet.getPropertyValue("DefaultContext");
1331 m_xContext = (XComponentContext)
1332 UnoRuntime.queryInterface(XComponentContext.class, defaultCtx);
1333 assure("could not get component context.", m_xContext != null);
1334 m_xDoc = util.WriterTools.createTextDoc(m_xMSF);
1335 m_TmpDir = util.utils.getOfficeTemp/*Dir*/(m_xMSF);
1336 log.println("tempdir: " + m_TmpDir);
1339 public void after()
1341 if (m_xDoc != null) {
1342 util.DesktopTools.closeDoc(m_xDoc);
1343 m_xDoc = null;
1347 public void testText() throws Exception
1349 TreeNode root = new TreeNode();
1350 TreeNode text = new TextNode("abc");
1351 root.appendChild(text);
1352 doTest(root);
1355 public void testTextField() throws Exception
1357 String name = mkName("ruby");
1358 TreeNode root = new TreeNode();
1359 TreeNode txtf = new TextFieldNode("abc");
1360 root.appendChild(txtf);
1361 doTest(root);
1364 public void testControlChar() throws Exception
1366 //FIXME this is converted to a text portion: ControlCharacter is obsolete
1367 TreeNode root = new TreeNode();
1368 TreeNode cchr = new ControlCharacterNode(HARD_HYPHEN);
1369 root.appendChild(cchr);
1370 doTest(root);
1373 public void testSoftPageBreak() throws Exception
1375 //FIXME: insert a soft page break: not done
1376 TreeNode root = new TreeNode();
1377 TreeNode spbk = new SoftPageBreakNode();
1378 TreeNode text = new TextNode("abc");
1379 root.appendChild(spbk);
1380 root.appendChild(text);
1381 doTest(root);
1384 public void testFootnote() throws Exception
1386 String name = mkName("ftn");
1387 TreeNode root = new TreeNode();
1388 TreeNode ftnd = new FootnoteNode(name);
1389 root.appendChild(ftnd);
1390 doTest(root);
1393 public void testFrameAs() throws Exception
1395 String name = mkName("frame");
1396 TreeNode root = new TreeNode();
1397 TreeNode fram = new FrameNode(name, AS_CHARACTER);
1398 root.appendChild(fram);
1399 doTest(root);
1402 public void testFrameAt() throws Exception
1404 String name = mkName("frame");
1405 TreeNode root = new TreeNode();
1406 // TreeNode text = new TextNode(""); // necessary?
1407 TreeNode fram = new FrameNode(name, AT_CHARACTER);
1408 // root.appendChild(text);
1409 root.appendChild(fram);
1410 doTest(root);
1413 public void testBookmarkPoint() throws Exception
1415 String name = mkName("mark");
1416 TreeNode root = new TreeNode();
1417 TreeNode bkmk = new BookmarkNode(name);
1418 TreeNode text = new TextNode("abc");
1419 root.appendChild(bkmk);
1420 root.appendChild(text);
1421 doTest(root);
1424 public void testBookmark() throws Exception
1426 String name = mkName("mark");
1427 TreeNode root = new TreeNode();
1428 TreeNode bkm1 = new BookmarkStartNode(name);
1429 TreeNode text = new TextNode("abc");
1430 TreeNode bkm2 = new BookmarkEndNode(name);
1431 root.appendChild(bkm1);
1432 root.appendChild(text);
1433 root.appendChild(bkm2);
1434 doTest(root);
1437 public void testBookmarkPointXmlId() throws Exception
1439 String name = mkName("mark");
1440 StringPair id = mkId("id");
1441 TreeNode root = new TreeNode();
1442 TreeNode bkmk = new BookmarkNode(name, id);
1443 TreeNode text = new TextNode("abc");
1444 root.appendChild(bkmk);
1445 root.appendChild(text);
1446 doTest(root);
1449 public void testBookmarkXmlId() throws Exception
1451 String name = mkName("mark");
1452 StringPair id = mkId("id");
1453 TreeNode root = new TreeNode();
1454 TreeNode bkm1 = new BookmarkStartNode(name, id);
1455 TreeNode text = new TextNode("abc");
1456 TreeNode bkm2 = new BookmarkEndNode(name, id);
1457 root.appendChild(bkm1);
1458 root.appendChild(text);
1459 root.appendChild(bkm2);
1460 doTest(root);
1463 public void testRefmarkPoint() throws Exception
1465 String name = mkName("refmark");
1466 TreeNode root = new TreeNode();
1467 TreeNode rfmk = new ReferenceMarkNode(name);
1468 TreeNode text = new TextNode("abc");
1469 root.appendChild(rfmk);
1470 root.appendChild(text);
1471 doTest(root);
1474 public void testRefmark() throws Exception
1476 String name = mkName("refmark");
1477 TreeNode root = new TreeNode();
1478 TreeNode rfm1 = new ReferenceMarkStartNode(name);
1479 TreeNode text = new TextNode("abc");
1480 TreeNode rfm2 = new ReferenceMarkEndNode(name);
1481 root.appendChild(rfm1);
1482 root.appendChild(text);
1483 root.appendChild(rfm2);
1484 doTest(root);
1487 public void testToxmarkPoint() throws Exception
1489 String name = mkName("toxmark");
1490 TreeNode root = new TreeNode();
1491 TreeNode txmk = new DocumentIndexMarkNode(name);
1492 TreeNode text = new TextNode("abc");
1493 root.appendChild(txmk);
1494 root.appendChild(text);
1495 doTest(root);
1498 public void testToxmark() throws Exception
1500 String name = mkName("toxmark");
1501 TreeNode root = new TreeNode();
1502 TreeNode txm1 = new DocumentIndexMarkStartNode(name);
1503 TreeNode text = new TextNode("abc");
1504 TreeNode txm2 = new DocumentIndexMarkEndNode(name);
1505 root.appendChild(txm1);
1506 root.appendChild(text);
1507 root.appendChild(txm2);
1508 doTest(root);
1511 public void testHyperlink() throws Exception
1513 String name = mkName("url");
1514 TreeNode root = new TreeNode();
1515 TreeNode href = new HyperlinkNode(name);
1516 TreeNode text = new TextNode("abc");
1517 href.appendChild(text);
1518 root.appendChild(href);
1519 doTest(root);
1522 public void testHyperlinkEmpty() throws Exception
1524 String name = mkName("url");
1525 TreeNode root = new TreeNode();
1526 TreeNode href = new HyperlinkNode(name);
1527 TreeNode text = new TextNode("");
1528 href.appendChild(text);
1529 root.appendChild(href);
1530 doTest(root);
1533 public void testRuby() throws Exception
1535 String name = mkName("ruby");
1536 TreeNode root = new TreeNode();
1537 TreeNode ruby = new RubyNode(name);
1538 TreeNode text = new TextNode("abc");
1539 ruby.appendChild(text);
1540 root.appendChild(ruby);
1541 doTest(root);
1544 public void testRubyEmpty() throws Exception
1546 // BUG: #i91534#
1547 String name = mkName("ruby");
1548 TreeNode root = new TreeNode();
1549 TreeNode ruby = new RubyNode(name);
1550 root.appendChild(ruby);
1551 doTest(root);
1554 public void testMeta() throws Exception
1556 StringPair id = new StringPair("content.xml", mkName("id"));
1557 TreeNode root = new TreeNode();
1558 TreeNode meta = new MetaNode(id);
1559 TreeNode text = new TextNode("abc");
1560 root.appendChild(new TextNode("123"));
1561 meta.appendChild(text);
1562 root.appendChild(meta);
1563 doTest(root);
1566 public void testMetaEmpty() throws Exception
1568 StringPair id = new StringPair("content.xml", mkName("id"));
1569 TreeNode root = new TreeNode();
1570 TreeNode meta = new MetaNode(id);
1571 // TreeNode text = new TextNode("");
1572 // meta.appendChild(text);
1573 root.appendChild(meta);
1574 doTest(root);
1577 public void testMetaField() throws Exception
1579 StringPair id = new StringPair("content.xml", mkName("id"));
1580 TreeNode root = new TreeNode();
1581 TreeNode meta = new MetaFieldNode(id);
1582 TreeNode text = new TextNode("abc");
1583 root.appendChild(new TextNode("123"));
1584 meta.appendChild(text);
1585 root.appendChild(meta);
1586 doTest(root);
1589 public void testMetaFieldEmpty() throws Exception
1591 StringPair id = new StringPair("content.xml", mkName("id"));
1592 TreeNode root = new TreeNode();
1593 TreeNode meta = new MetaFieldNode(id);
1594 // TreeNode text = new TextNode("");
1595 // meta.appendChild(text);
1596 root.appendChild(meta);
1597 doTest(root);
1600 public void testBookmark1() throws Exception
1602 String name1 = mkName("mark");
1603 String name2 = mkName("mark");
1604 String name3 = mkName("mark");
1605 TreeNode root = new TreeNode();
1606 root.appendChild( new BookmarkStartNode(name1) );
1607 root.appendChild( new BookmarkNode(name2) );
1608 root.appendChild( new BookmarkStartNode(name3) );
1609 root.appendChild( new TextNode("abc") );
1610 root.appendChild( new BookmarkEndNode(name1) );
1611 root.appendChild( new TextNode("de") );
1612 root.appendChild( new BookmarkEndNode(name3) );
1613 doTest(root);
1616 public void testBookmark2() throws Exception
1618 String name1 = mkName("mark");
1619 String name2 = mkName("mark");
1620 String name3 = mkName("mark");
1621 TreeNode root = new TreeNode();
1622 root.appendChild( new BookmarkStartNode(name1) );
1623 root.appendChild( new TextNode("abc") );
1624 root.appendChild( new BookmarkNode(name2) );
1625 root.appendChild( new BookmarkStartNode(name3) );
1626 root.appendChild( new BookmarkEndNode(name1) );
1627 root.appendChild( new TextNode("de") );
1628 root.appendChild( new BookmarkEndNode(name3) );
1629 doTest(root);
1632 public void testRefMark2() throws Exception
1634 String name1 = mkName("refmark");
1635 TreeNode root = new TreeNode();
1636 root.appendChild( new ReferenceMarkStartNode(name1) );
1637 root.appendChild( new TextNode("abc") );
1638 // BUG: #i102541# (this is actually not unoportenum's fault)
1639 root.appendChild( new ReferenceMarkEndNode(name1) );
1640 root.appendChild( new TextNode("de") );
1641 doTest(root);
1644 public void testRefMark3() throws Exception
1646 String name1 = mkName("refmark");
1647 String name2 = mkName("refmark");
1648 TreeNode root = new TreeNode();
1649 root.appendChild( new ReferenceMarkStartNode(name1) );
1650 root.appendChild( new ReferenceMarkStartNode(name2) );
1651 root.appendChild( new TextNode("abc") );
1652 root.appendChild( new ReferenceMarkEndNode(name2) );
1653 root.appendChild( new ReferenceMarkEndNode(name1) );
1654 root.appendChild( new TextNode("de") );
1655 doTest(root);
1658 public void testToxMark2() throws Exception
1660 String name1 = mkName("toxmark");
1661 TreeNode root = new TreeNode();
1662 root.appendChild( new DocumentIndexMarkStartNode(name1) );
1663 root.appendChild( new TextNode("abc") );
1664 root.appendChild( new DocumentIndexMarkEndNode(name1) );
1665 root.appendChild( new TextNode("de") );
1666 doTest(root);
1669 public void testToxMark3() throws Exception
1671 String name1 = mkName("toxmark");
1672 String name2 = mkName("toxmark");
1673 TreeNode root = new TreeNode();
1674 root.appendChild( new DocumentIndexMarkStartNode(name1) );
1675 root.appendChild( new DocumentIndexMarkStartNode(name2) );
1676 root.appendChild( new TextNode("abc") );
1677 root.appendChild( new DocumentIndexMarkEndNode(name2) );
1678 root.appendChild( new DocumentIndexMarkEndNode(name1) );
1679 root.appendChild( new TextNode("de") );
1680 doTest(root);
1683 public void testMarks1() throws Exception
1685 String name1 = mkName("bookmark");
1686 String name2 = mkName("toxmark");
1687 String name3 = mkName("refmark");
1688 String name4 = mkName("toxmark");
1689 TreeNode root = new TreeNode();
1690 root.appendChild( new BookmarkStartNode(name1) );
1691 root.appendChild( new DocumentIndexMarkNode(name2) );
1692 root.appendChild( new ReferenceMarkStartNode(name3) );
1693 root.appendChild( new TextNode("abc") );
1694 root.appendChild( new BookmarkEndNode(name1) );
1695 root.appendChild( new DocumentIndexMarkStartNode(name4) );
1696 root.appendChild( new TextNode("de") );
1697 root.appendChild( new DocumentIndexMarkEndNode(name4) );
1698 root.appendChild( new ReferenceMarkEndNode(name3) );
1699 doTest(root);
1702 public void testMarks2() throws Exception
1704 String name1 = mkName("bookmark");
1705 String name2 = mkName("refmark");
1706 String name3 = mkName("refmark");
1707 String name4 = mkName("toxmark");
1708 String name5 = mkName("refmark");
1709 TreeNode root = new TreeNode();
1710 root.appendChild( new BookmarkStartNode(name1) );
1711 root.appendChild( new ReferenceMarkNode(name2) );
1712 root.appendChild( new ReferenceMarkStartNode(name3) );
1713 root.appendChild( new TextNode("abc") );
1714 root.appendChild( new DocumentIndexMarkStartNode(name4) );
1715 root.appendChild( new ReferenceMarkStartNode(name5) );
1716 // BUG: #i102541# (this is actually not unoportenum's fault)
1717 root.appendChild( new ReferenceMarkEndNode(name3) );
1718 root.appendChild( new TextNode("de") );
1719 root.appendChild( new DocumentIndexMarkEndNode(name4) );
1720 root.appendChild( new BookmarkEndNode(name1) );
1721 root.appendChild( new ReferenceMarkEndNode(name5) );
1722 doTest(root);
1725 public void testMarks3() throws Exception
1727 String name1 = mkName("bookmark");
1728 String name2 = mkName("refmark");
1729 String name3 = mkName("refmark");
1730 String name4 = mkName("toxmark");
1731 String name5 = mkName("refmark");
1732 TreeNode root = new TreeNode();
1733 root.appendChild( new BookmarkStartNode(name1) );
1734 root.appendChild( new DocumentIndexMarkNode(name2) );
1735 root.appendChild( new DocumentIndexMarkStartNode(name3) );
1736 root.appendChild( new TextNode("abc") );
1737 root.appendChild( new ReferenceMarkStartNode(name4) );
1738 root.appendChild( new DocumentIndexMarkStartNode(name5) );
1739 root.appendChild( new DocumentIndexMarkEndNode(name3) );
1740 root.appendChild( new TextNode("de") );
1741 root.appendChild( new ReferenceMarkEndNode(name4) );
1742 root.appendChild( new BookmarkEndNode(name1) );
1743 root.appendChild( new DocumentIndexMarkEndNode(name5) );
1744 doTest(root);
1747 public void testFrameMark1() throws Exception
1749 String name1 = mkName("bookmark");
1750 String name2 = mkName("frame");
1751 TreeNode root = new TreeNode();
1752 root.appendChild( new TextNode("abc") );
1753 root.appendChild( new BookmarkNode(name1) );
1754 root.appendChild( new TextNode("de") );
1755 root.appendChild( new FrameNode(name2, AS_CHARACTER) );
1756 doTest(root);
1759 public void testFrameMark2() throws Exception
1761 // BUG: #i98530#
1762 String name1 = mkName("bookmark");
1763 String name2 = mkName("frame");
1764 TreeNode root = new TreeNode();
1765 root.appendChild( new TextNode("abc") );
1766 root.appendChild( new BookmarkNode(name1) );
1767 root.appendChild( new TextNode("de") );
1768 root.appendChild( new FrameNode(name2, AT_CHARACTER) );
1769 doTest(root);
1772 public void testFrameMark3() throws Exception
1774 String name1 = mkName("frame");
1775 String name2 = mkName("bookmark");
1776 TreeNode root = new TreeNode();
1777 root.appendChild( new TextNode("abc") );
1778 root.appendChild( new FrameNode(name1, AS_CHARACTER) );
1779 root.appendChild( new TextNode("de") );
1780 root.appendChild( new BookmarkNode(name2) );
1781 doTest(root);
1784 public void testFrameMark4() throws Exception
1786 String name1 = mkName("frame");
1787 String name2 = mkName("bookmark");
1788 TreeNode root = new TreeNode();
1789 root.appendChild( new TextNode("abc") );
1790 root.appendChild( new FrameNode(name1, AT_CHARACTER) );
1791 root.appendChild( new TextNode("de") );
1792 root.appendChild( new BookmarkNode(name2) );
1793 doTest(root);
1796 public void testFrames1() throws Exception
1798 String name1 = mkName("frame");
1799 String name2 = mkName("frame");
1800 String name3 = mkName("frame");
1801 TreeNode root = new TreeNode();
1802 root.appendChild( new FrameNode(name1, AT_CHARACTER) );
1803 root.appendChild( new FrameNode(name2, AT_CHARACTER) );
1804 root.appendChild( new FrameNode(name3, AT_CHARACTER) );
1805 doTest(root);
1808 public void testFrames2() throws Exception
1810 String name1 = mkName("frame");
1811 String name2 = mkName("frame");
1812 String name3 = mkName("frame");
1813 TreeNode root = new TreeNode();
1814 root.appendChild( new FrameNode(name1, AS_CHARACTER) );
1815 root.appendChild( new FrameNode(name2, AS_CHARACTER) );
1816 root.appendChild( new FrameNode(name3, AS_CHARACTER) );
1817 doTest(root);
1820 public void testFrames3() throws Exception
1822 String name1 = mkName("frame");
1823 String name2 = mkName("frame");
1824 String name3 = mkName("frame");
1825 TreeNode root = new TreeNode();
1826 root.appendChild( new FrameNode(name1, AT_CHARACTER) );
1827 root.appendChild( new FrameNode(name2, AS_CHARACTER) );
1828 root.appendChild( new FrameNode(name3, AT_CHARACTER) );
1829 doTest(root);
1832 public void testFrames4() throws Exception
1834 String name1 = mkName("frame");
1835 String name2 = mkName("frame");
1836 String name3 = mkName("frame");
1837 TreeNode root = new TreeNode();
1838 root.appendChild( new FrameNode(name1, AT_CHARACTER) );
1839 root.appendChild( new FrameNode(name2, AT_CHARACTER) );
1840 root.appendChild( new FrameNode(name3, AS_CHARACTER) );
1841 doTest(root);
1844 public void testFrames5() throws Exception
1846 String name1 = mkName("frame");
1847 String name2 = mkName("frame");
1848 String name3 = mkName("frame");
1849 TreeNode root = new TreeNode();
1850 root.appendChild( new FrameNode(name1, AS_CHARACTER) );
1851 root.appendChild( new FrameNode(name2, AT_CHARACTER) );
1852 root.appendChild( new FrameNode(name3, AT_CHARACTER) );
1853 doTest(root);
1856 public void testRubyHyperlink1() throws Exception
1858 String name1 = mkName("ruby");
1859 String name2 = mkName("url");
1860 TreeNode root = new TreeNode();
1861 TreeNode ruby = new RubyNode(name1);
1862 TreeNode href = new HyperlinkNode(name2);
1863 href.appendChild( new TextNode("abc") );
1864 ruby.appendChild(href);
1865 root.appendChild(ruby);
1866 doTest(root);
1869 public void testRubyHyperlink2() throws Exception
1871 String name1 = mkName("url");
1872 String name2 = mkName("ruby");
1873 TreeNode root = new TreeNode();
1874 TreeNode href = new HyperlinkNode(name1);
1875 TreeNode ruby = new RubyNode(name2);
1876 ruby.appendChild( new TextNode("abc") );
1877 href.appendChild(ruby);
1878 root.appendChild(href);
1879 doTest(root);
1882 public void testEnd1() throws Exception
1884 String name1 = mkName("bookmark");
1885 String name2 = mkName("toxmark");
1886 String name3 = mkName("refmark");
1887 TreeNode root = new TreeNode();
1888 root.appendChild( new TextNode("abc") );
1889 root.appendChild( new BookmarkNode(name1) );
1890 root.appendChild( new DocumentIndexMarkNode(name2) );
1891 root.appendChild( new ReferenceMarkNode(name3) );
1892 doTest(root);
1895 public void testEnd2() throws Exception
1897 String name1 = mkName("bookmark");
1898 String name2 = mkName("frame");
1899 String name3 = mkName("refmark");
1900 String name4 = mkName("frame");
1901 String name5 = mkName("frame");
1902 TreeNode root = new TreeNode();
1903 root.appendChild( new TextNode("abc") );
1904 root.appendChild( new BookmarkNode(name1) );
1905 root.appendChild( new FrameNode(name2, AT_CHARACTER) );
1906 root.appendChild( new ReferenceMarkNode(name3) );
1907 root.appendChild( new FrameNode(name4, AT_CHARACTER) );
1908 root.appendChild( new FrameNode(name5, AT_CHARACTER) );
1909 doTest(root);
1912 public void testEnd3() throws Exception
1914 String name1 = mkName("ftn");
1915 String name2 = mkName("toxmark");
1916 TreeNode root = new TreeNode();
1917 root.appendChild( new TextNode("abc") );
1918 root.appendChild( new FootnoteNode(name1) );
1919 root.appendChild( new DocumentIndexMarkNode(name2) );
1920 doTest(root);
1923 public void testEnd4() throws Exception
1925 String name1 = mkName("bookmark");
1926 String name2 = mkName("frame");
1927 TreeNode root = new TreeNode();
1928 root.appendChild( new BookmarkStartNode(name1) );
1929 root.appendChild( new TextNode("abc") );
1930 root.appendChild( new FrameNode(name2, AS_CHARACTER) );
1931 root.appendChild( new BookmarkEndNode(name1) );
1932 doTest(root);
1935 public void testEnd5() throws Exception
1937 String name1 = mkName("refmark");
1938 String name2 = mkName("ruby");
1939 TreeNode root = new TreeNode();
1940 root.appendChild( new ReferenceMarkStartNode(name1) );
1941 root.appendChild( new TextNode("abc") );
1942 TreeNode ruby = new RubyNode(name2);
1943 ruby.appendChild( new TextFieldNode("de") );
1944 root.appendChild(ruby);
1945 root.appendChild( new ReferenceMarkEndNode(name1) );
1946 doTest(root);
1949 public void testEmpty1() throws Exception
1951 String name1 = mkName("refmark");
1952 String name2 = mkName("toxmark");
1953 String name3 = mkName("bookmark");
1954 String name4 = mkName("frame");
1955 String name7 = mkName("refmark");
1956 String name8 = mkName("toxmark");
1957 String name9 = mkName("bookmark");
1958 String nameA = mkName("frame");
1959 TreeNode root = new TreeNode();
1960 root.appendChild( new ReferenceMarkNode(name1) );
1961 root.appendChild( new DocumentIndexMarkNode(name2) );
1962 root.appendChild( new BookmarkNode(name3) );
1963 root.appendChild( new FrameNode(name4, AT_CHARACTER) );
1964 root.appendChild( new ReferenceMarkNode(name7) );
1965 root.appendChild( new DocumentIndexMarkNode(name8) );
1966 root.appendChild( new BookmarkNode(name9) );
1967 root.appendChild( new FrameNode(nameA, AT_CHARACTER) );
1968 doTest(root);
1971 public void testEmpty2() throws Exception
1973 String name3 = mkName("bookmark");
1974 String name4 = mkName("frame");
1975 String name9 = mkName("bookmark");
1976 String nameA = mkName("frame");
1977 TreeNode root = new TreeNode();
1978 root.appendChild( new BookmarkNode(name3) );
1979 root.appendChild( new FrameNode(name4, AT_CHARACTER) );
1980 root.appendChild( new BookmarkNode(name9) );
1981 root.appendChild( new FrameNode(nameA, AT_CHARACTER) );
1982 doTest(root);
1985 public void testEmpty3() throws Exception
1987 String name1 = mkName("refmark");
1988 String name2 = mkName("toxmark");
1989 String name3 = mkName("bookmark");
1990 String name4 = mkName("frame");
1991 String name5 = mkName("url");
1992 String name6 = mkName("ruby");
1993 String name7 = mkName("refmark");
1994 String name8 = mkName("toxmark");
1995 String name9 = mkName("bookmark");
1996 String nameA = mkName("frame");
1997 TreeNode root = new TreeNode();
1998 root.appendChild( new ReferenceMarkNode(name1) );
1999 root.appendChild( new DocumentIndexMarkNode(name2) );
2000 root.appendChild( new BookmarkNode(name3) );
2001 root.appendChild( new FrameNode(name4, AT_CHARACTER) );
2002 /* currently empty hyperlinks may get eaten...
2003 TreeNode href = new HyperlinkNode(name5);
2004 href.appendChild( new TextNode("") );
2005 root.appendChild(href);
2007 TreeNode ruby = new RubyNode(name6);
2008 root.appendChild(ruby);
2009 root.appendChild( new ReferenceMarkNode(name7) );
2010 root.appendChild( new DocumentIndexMarkNode(name8) );
2011 root.appendChild( new BookmarkNode(name9) );
2012 root.appendChild( new FrameNode(nameA, AT_CHARACTER) );
2013 doTest(root);
2016 public void test1() throws Exception
2018 String name1 = mkName("frame");
2019 String name2 = mkName("bookmark");
2020 String name3 = mkName("ruby");
2021 String name4 = mkName("ftn");
2022 String name5 = mkName("frame");
2023 TreeNode root = new TreeNode();
2024 root.appendChild( new FrameNode(name1, AT_CHARACTER) );
2025 root.appendChild( new BookmarkStartNode(name2) );
2026 root.appendChild( new TextNode("abc") );
2027 TreeNode ruby = new RubyNode(name3);
2028 ruby.appendChild( new TextNode("de") );
2029 ruby.appendChild( new FootnoteNode(name4) );
2030 ruby.appendChild( new BookmarkEndNode(name2) );
2031 root.appendChild(ruby);
2032 root.appendChild( new TextNode("fg") );
2033 root.appendChild( new FrameNode(name5, AT_CHARACTER) );
2034 root.appendChild( new TextFieldNode("h") );
2035 doTest(root);
2038 /* some range tests for the insertion: these are for the current
2039 API which treats hyperlinks and rubys not as entities, but as formatting
2040 attributes; if these ever become entities, they should not be split!
2043 public void testRange1() throws Exception
2045 String name1 = mkName("url");
2046 RangeInserter inserter = new RangeInserter(m_xDoc);
2047 TreeNode text = new TextNode("12345");
2048 inserter.insertRange(new Range(0, 0, text));
2049 TreeNode url1 = new HyperlinkNode(name1);
2050 Range range1 = new Range(0, 5, url1);
2051 inserter.insertRange(range1);
2052 TreeNode root = new TreeNode();
2053 root.appendChild( url1 );
2054 url1.appendChild( text );
2055 doTest(root, false);
2058 public void testRangeHyperlinkHyperlink() throws Exception
2060 RangeInserter inserter = new RangeInserter(m_xDoc);
2061 TreeNode text = new TextNode("123456789");
2062 inserter.insertRange( new Range(0, 0, text) );
2063 TreeNode url1 = new HyperlinkNode( mkName("url") );
2064 inserter.insertRange( new Range(1, 4, url1) );
2065 // overlap left
2066 TreeNode url2 = new HyperlinkNode( mkName("url") );
2067 inserter.insertRange( new Range(0, 2, url2) );
2068 TreeNode root = new TreeNode()
2069 .appendChild( url2.dup().appendChild( new TextNode("12") ) )
2070 .appendChild( url1.dup().appendChild( new TextNode("34") ) )
2071 .appendChild( new TextNode("56789") );
2072 doTest(root, false);
2073 // overlap right
2074 TreeNode url3 = new HyperlinkNode( mkName("url") );
2075 inserter.insertRange( new Range(3, 7, url3) );
2076 root = new TreeNode()
2077 .appendChild( url2.dup().appendChild( new TextNode("12") ) )
2078 .appendChild( url1.dup().appendChild( new TextNode("3") ) )
2079 .appendChild( url3.dup().appendChild( new TextNode("4567") ) )
2080 .appendChild( new TextNode("89") );
2081 doTest(root, false);
2082 // around
2083 TreeNode url4 = new HyperlinkNode( mkName("url") );
2084 inserter.insertRange( new Range(3, 7, url4) );
2085 root = new TreeNode()
2086 .appendChild( url2.dup().appendChild( new TextNode("12") ) )
2087 .appendChild( url1.dup().appendChild( new TextNode("3") ) )
2088 .appendChild( url4.dup().appendChild( new TextNode("4567") ) )
2089 .appendChild( new TextNode("89") );
2090 doTest(root, false);
2091 // inside
2092 TreeNode url5 = new HyperlinkNode( mkName("url") );
2093 inserter.insertRange( new Range(4, 6, url5) );
2094 root = new TreeNode()
2095 .appendChild( url2.dup().appendChild( new TextNode("12") ) )
2096 .appendChild( url1.dup().appendChild( new TextNode("3") ) )
2097 .appendChild( url4.dup().appendChild( new TextNode("4") ) )
2098 .appendChild( url5.dup().appendChild( new TextNode("56") ) )
2099 .appendChild( url4.dup().appendChild( new TextNode("7") ) )
2100 .appendChild( new TextNode("89") );
2101 doTest(root, false);
2104 public void testRangeHyperlinkRuby() throws Exception
2106 RangeInserter inserter = new RangeInserter(m_xDoc);
2107 TreeNode text = new TextNode("123456789");
2108 inserter.insertRange( new Range(0, 0, text) );
2109 TreeNode url1 = new HyperlinkNode( mkName("url") );
2110 inserter.insertRange( new Range(1, 4, url1) );
2111 // overlap left
2112 TreeNode rby2 = new RubyNode( mkName("ruby") );
2113 inserter.insertRange( new Range(0, 2, rby2) );
2114 TreeNode root = new TreeNode()
2115 .appendChild( rby2.dup()
2116 .appendChild( new TextNode("1") )
2117 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2118 .appendChild( url1.dup().appendChild( new TextNode("34") ) )
2119 .appendChild( new TextNode("56789") );
2120 doTest(root, false);
2121 // overlap right
2122 TreeNode rby3 = new RubyNode( mkName("ruby") );
2123 inserter.insertRange( new Range(3, 5, rby3) );
2124 root = new TreeNode()
2125 .appendChild( rby2.dup()
2126 .appendChild( new TextNode("1") )
2127 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2128 .appendChild( url1.dup().appendChild( new TextNode("3") ) )
2129 .appendChild( rby3.dup()
2130 .appendChild( url1.dup().appendChild( new TextNode("4") ) )
2131 .appendChild( new TextNode("5") ) )
2132 .appendChild( new TextNode("6789") );
2133 doTest(root, false);
2134 // around
2135 TreeNode rby4 = new RubyNode( mkName("ruby") );
2136 inserter.insertRange( new Range(2, 3, rby4) );
2137 root = new TreeNode()
2138 .appendChild( rby2.dup()
2139 .appendChild( new TextNode("1") )
2140 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2141 .appendChild( rby4.dup()
2142 .appendChild( url1.dup().appendChild( new TextNode("3") ) ) )
2143 .appendChild( rby3.dup()
2144 .appendChild( url1.dup().appendChild( new TextNode("4") ) )
2145 .appendChild( new TextNode("5") ) )
2146 .appendChild( new TextNode("6789") );
2147 doTest(root, false);
2148 // inside
2149 TreeNode url5 = new HyperlinkNode( mkName("url") );
2150 inserter.insertRange( new Range(6, 9, url5) );
2151 TreeNode rby6 = new RubyNode( mkName("ruby") );
2152 inserter.insertRange( new Range(7, 8, rby6) );
2153 root = new TreeNode()
2154 .appendChild( rby2.dup()
2155 .appendChild( new TextNode("1") )
2156 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2157 .appendChild( rby4.dup()
2158 .appendChild( url1.dup().appendChild( new TextNode("3") ) ) )
2159 .appendChild( rby3.dup()
2160 .appendChild( url1.dup().appendChild( new TextNode("4") ) )
2161 .appendChild( new TextNode("5") ) )
2162 .appendChild( new TextNode("6") )
2163 .appendChild( url5.dup().appendChild( new TextNode("7") ) )
2164 .appendChild( rby6.dup()
2165 .appendChild( url5.dup().appendChild( new TextNode("8") ) ) )
2166 .appendChild( url5.dup().appendChild( new TextNode("9") ) );
2167 doTest(root, false);
2170 public void testRangeRubyHyperlink() throws Exception
2172 RangeInserter inserter = new RangeInserter(m_xDoc);
2173 TreeNode text = new TextNode("123456789");
2174 inserter.insertRange( new Range(0, 0, text) );
2175 TreeNode rby1 = new RubyNode( mkName("ruby") );
2176 inserter.insertRange( new Range(1, 6, rby1) );
2177 // overlap left
2178 TreeNode url2 = new HyperlinkNode( mkName("url") );
2179 inserter.insertRange( new Range(0, 3, url2) );
2180 TreeNode root = new TreeNode()
2181 .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2182 .appendChild( rby1.dup()
2183 .appendChild( url2.dup().appendChild( new TextNode("23") ) )
2184 .appendChild( new TextNode("456") ) )
2185 .appendChild( new TextNode("789") );
2186 doTest(root, false);
2187 // overlap right
2188 TreeNode url3 = new HyperlinkNode( mkName("url") );
2189 inserter.insertRange( new Range(5, 7, url3) );
2190 root = new TreeNode()
2191 .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2192 .appendChild( rby1.dup()
2193 .appendChild( url2.dup().appendChild( new TextNode("23") ) )
2194 .appendChild( new TextNode("45") )
2195 .appendChild( url3.dup().appendChild( new TextNode("6") ) ) )
2196 .appendChild( url3.dup().appendChild( new TextNode("7") ) )
2197 .appendChild( new TextNode("89") );
2198 doTest(root, false);
2199 // around (not quite, due to API)
2200 TreeNode url4 = new HyperlinkNode( mkName("url") );
2201 inserter.insertRange( new Range(1, 8, url4) );
2202 root = new TreeNode()
2203 .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2204 .appendChild( rby1.dup()
2205 .appendChild( url4.dup()
2206 .appendChild( new TextNode("23456") ) ) )
2207 .appendChild( url4.dup().appendChild( new TextNode("78") ) )
2208 .appendChild( new TextNode("9") );
2209 doTest(root, false);
2210 // inside
2211 TreeNode url5 = new HyperlinkNode( mkName("url") );
2212 inserter.insertRange( new Range(3, 5, url5) );
2213 root = new TreeNode()
2214 .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2215 .appendChild( rby1.dup()
2216 .appendChild( url4.dup()
2217 .appendChild( new TextNode("23") ) )
2218 .appendChild( url5.dup()
2219 .appendChild( new TextNode("45") ) )
2220 .appendChild( url4.dup()
2221 .appendChild( new TextNode("6") ) ) )
2222 .appendChild( url4.dup().appendChild( new TextNode("78") ) )
2223 .appendChild( new TextNode("9") );
2224 doTest(root, false);
2227 public void testRangeRubyRuby() throws Exception
2229 RangeInserter inserter = new RangeInserter(m_xDoc);
2230 TreeNode text = new TextNode("123456789");
2231 inserter.insertRange( new Range(0, 0, text) );
2232 TreeNode rby1 = new RubyNode( mkName("ruby") );
2233 inserter.insertRange( new Range(1, 4, rby1) );
2234 // overlap left
2235 TreeNode rby2 = new RubyNode( mkName("ruby") );
2236 inserter.insertRange( new Range(0, 2, rby2) );
2237 TreeNode root = new TreeNode()
2238 .appendChild( rby2.dup().appendChild( new TextNode("12") ) )
2239 .appendChild( rby1.dup().appendChild( new TextNode("34") ) )
2240 .appendChild( new TextNode("56789") );
2241 doTest(root, false);
2242 // overlap right
2243 TreeNode rby3 = new RubyNode( mkName("ruby") );
2244 inserter.insertRange( new Range(3, 7, rby3) );
2245 root = new TreeNode()
2246 .appendChild( rby2.dup().appendChild( new TextNode("12") ) )
2247 .appendChild( rby1.dup().appendChild( new TextNode("3") ) )
2248 .appendChild( rby3.dup().appendChild( new TextNode("4567") ) )
2249 .appendChild( new TextNode("89") );
2250 doTest(root, false);
2251 // around
2252 TreeNode rby4 = new RubyNode( mkName("ruby") );
2253 inserter.insertRange( new Range(3, 7, rby4) );
2254 root = new TreeNode()
2255 .appendChild( rby2.dup().appendChild( new TextNode("12") ) )
2256 .appendChild( rby1.dup().appendChild( new TextNode("3") ) )
2257 .appendChild( rby4.dup().appendChild( new TextNode("4567") ) )
2258 .appendChild( new TextNode("89") );
2259 doTest(root, false);
2260 // inside
2261 TreeNode rby5 = new RubyNode( mkName("ruby") );
2262 inserter.insertRange( new Range(4, 6, rby5) );
2263 root = new TreeNode()
2264 .appendChild( rby2.dup().appendChild( new TextNode("12") ) )
2265 .appendChild( rby1.dup().appendChild( new TextNode("3") ) )
2266 .appendChild( rby4.dup().appendChild( new TextNode("4") ) )
2267 .appendChild( rby5.dup().appendChild( new TextNode("56") ) )
2268 .appendChild( rby4.dup().appendChild( new TextNode("7") ) )
2269 .appendChild( new TextNode("89") );
2270 doTest(root, false);
2273 public void testRangeHyperlinkMeta() throws Exception
2275 RangeInserter inserter = new RangeInserter(m_xDoc);
2276 TreeNode text = new TextNode("123456789");
2277 inserter.insertRange( new Range(0, 0, text) );
2278 TreeNode url1 = new HyperlinkNode( mkName("url") );
2279 inserter.insertRange( new Range(1, 4, url1) );
2280 // overlap left
2281 TreeNode met2 = new MetaNode( mkId("id") );
2282 inserter.insertRange( new Range(0, 2, met2) );
2283 TreeNode root = new TreeNode()
2284 .appendChild( met2.dup()
2285 .appendChild( new TextNode("1") )
2286 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2287 .appendChild( url1.dup().appendChild( new TextNode("34") ) )
2288 .appendChild( new TextNode("56789") );
2289 doTest(root, false);
2290 // overlap right
2291 TreeNode met3 = new MetaNode( mkId("id") );
2292 inserter.insertRange( new Range(4/*-1*/, 6/*-1*/, met3) );
2293 root = new TreeNode()
2294 .appendChild( met2.dup()
2295 .appendChild( new TextNode("1") )
2296 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2297 .appendChild( url1.dup().appendChild( new TextNode("3") ) )
2298 .appendChild( met3.dup()
2299 .appendChild( url1.dup().appendChild( new TextNode("4") ) )
2300 .appendChild( new TextNode("5") ) )
2301 .appendChild( new TextNode("6789") );
2302 doTest(root, false);
2303 // around
2304 TreeNode met4 = new MetaNode( mkId("id") );
2305 inserter.insertRange( new Range(3/*-1*/, 4/*-1*/, met4) );
2306 root = new TreeNode()
2307 .appendChild( met2.dup()
2308 .appendChild( new TextNode("1") )
2309 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2310 .appendChild( met4.dup()
2311 .appendChild( url1.dup().appendChild( new TextNode("3") ) ) )
2312 .appendChild( met3.dup()
2313 .appendChild( url1.dup().appendChild( new TextNode("4") ) )
2314 .appendChild( new TextNode("5") ) )
2315 .appendChild( new TextNode("6789") );
2316 doTest(root, false);
2317 // inside
2318 TreeNode url5 = new HyperlinkNode( mkName("url") );
2319 inserter.insertRange( new Range(9/*-3*/, 12/*-3*/, url5) );
2320 TreeNode met6 = new MetaNode( mkId("id") );
2321 inserter.insertRange( new Range(10/*-3*/, 11/*-3*/, met6) );
2322 root = new TreeNode()
2323 .appendChild( met2.dup()
2324 .appendChild( new TextNode("1") )
2325 .appendChild( url1.dup().appendChild( new TextNode("2") ) ) )
2326 .appendChild( met4.dup()
2327 .appendChild( url1.dup().appendChild( new TextNode("3") ) ) )
2328 .appendChild( met3.dup()
2329 .appendChild( url1.dup().appendChild( new TextNode("4") ) )
2330 .appendChild( new TextNode("5") ) )
2331 .appendChild( new TextNode("6") )
2332 .appendChild( url5.dup().appendChild( new TextNode("7") ) )
2333 .appendChild( met6.dup()
2334 .appendChild( url5.dup().appendChild( new TextNode("8") ) ) )
2335 .appendChild( url5.dup().appendChild( new TextNode("9") ) );
2336 doTest(root, false);
2339 public void testRangeRubyMeta() throws Exception
2341 RangeInserter inserter = new RangeInserter(m_xDoc);
2342 TreeNode text = new TextNode("123456789");
2343 inserter.insertRange( new Range(0, 0, text) );
2344 TreeNode rby1 = new RubyNode( mkName("ruby") );
2345 inserter.insertRange( new Range(1, 4, rby1) );
2346 // overlap left
2347 TreeNode met2 = new MetaNode( mkId("id") );
2348 inserter.insertRange( new Range(0, 2, met2) );
2349 TreeNode root = new TreeNode()
2350 .appendChild( met2.dup()
2351 .appendChild( new TextNode("1") )
2352 .appendChild( rby1.dup().appendChild( new TextNode("2") ) ) )
2353 .appendChild( rby1.dup().appendChild( new TextNode("34") ) )
2354 .appendChild( new TextNode("56789") );
2355 doTest(root, false);
2356 // overlap right
2357 TreeNode met3 = new MetaNode( mkId("id") );
2358 inserter.insertRange( new Range(4/*-1*/, 6/*-1*/, met3) );
2359 root = new TreeNode()
2360 .appendChild( met2.dup()
2361 .appendChild( new TextNode("1") )
2362 .appendChild( rby1.dup().appendChild( new TextNode("2") ) ) )
2363 .appendChild( rby1.dup().appendChild( new TextNode("3") ) )
2364 .appendChild( met3.dup()
2365 .appendChild( rby1.dup().appendChild( new TextNode("4") ) )
2366 .appendChild( new TextNode("5") ) )
2367 .appendChild( new TextNode("6789") );
2368 doTest(root, false);
2369 // around
2370 TreeNode met4 = new MetaNode( mkId("id") );
2371 inserter.insertRange( new Range(3/*-1*/, 4/*-1*/, met4) );
2372 root = new TreeNode()
2373 .appendChild( met2.dup()
2374 .appendChild( new TextNode("1") )
2375 .appendChild( rby1.dup().appendChild( new TextNode("2") ) ) )
2376 .appendChild( met4.dup()
2377 .appendChild( rby1.dup().appendChild( new TextNode("3") ) ) )
2378 .appendChild( met3.dup()
2379 .appendChild( rby1.dup().appendChild( new TextNode("4") ) )
2380 .appendChild( new TextNode("5") ) )
2381 .appendChild( new TextNode("6789") );
2382 doTest(root, false);
2383 // inside
2384 TreeNode rby5 = new RubyNode( mkName("ruby") );
2385 inserter.insertRange( new Range(9/*-3*/, 12/*-3*/, rby5) );
2386 TreeNode met6 = new MetaNode( mkId("id") );
2387 inserter.insertRange( new Range(10/*-3*/, 11/*-3*/, met6) );
2388 root = new TreeNode()
2389 .appendChild( met2.dup()
2390 .appendChild( new TextNode("1") )
2391 .appendChild( rby1.dup().appendChild( new TextNode("2") ) ) )
2392 .appendChild( met4.dup()
2393 .appendChild( rby1.dup().appendChild( new TextNode("3") ) ) )
2394 .appendChild( met3.dup()
2395 .appendChild( rby1.dup().appendChild( new TextNode("4") ) )
2396 .appendChild( new TextNode("5") ) )
2397 .appendChild( new TextNode("6") )
2398 .appendChild( rby5.dup()
2399 .appendChild( new TextNode("7") )
2400 .appendChild( met6.dup()
2401 .appendChild( new TextNode("8") ) )
2402 .appendChild( new TextNode("9") ) );
2403 doTest(root, false);
2406 public void testRangeMetaHyperlink() throws Exception
2408 RangeInserter inserter = new RangeInserter(m_xDoc);
2409 TreeNode text = new TextNode("123456789");
2410 inserter.insertRange( new Range(0, 0, text) );
2411 TreeNode met1 = new MetaNode( mkId("id") );
2412 inserter.insertRange( new Range(1, 6, met1) );
2413 // overlap left
2414 TreeNode url2 = new HyperlinkNode( mkName("url") );
2415 inserter.insertRange( new Range(0, 4/*-1*/, url2) );
2416 TreeNode root = new TreeNode()
2417 .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2418 .appendChild( met1.dup()
2419 .appendChild( url2.dup().appendChild( new TextNode("23") ) )
2420 .appendChild( new TextNode("456") ) )
2421 .appendChild( new TextNode("789") );
2422 doTest(root, false);
2423 // overlap right
2424 TreeNode url3 = new HyperlinkNode( mkName("url") );
2425 inserter.insertRange( new Range(6/*-1*/, 8/*-1*/, url3) );
2426 root = new TreeNode()
2427 .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2428 .appendChild( met1.dup()
2429 .appendChild( url2.dup().appendChild( new TextNode("23") ) )
2430 .appendChild( new TextNode("45") )
2431 .appendChild( url3.dup().appendChild( new TextNode("6") ) ) )
2432 .appendChild( url3.dup().appendChild( new TextNode("7") ) )
2433 .appendChild( new TextNode("89") );
2434 doTest(root, false);
2435 // around (not quite, due to API)
2436 TreeNode url4 = new HyperlinkNode( mkName("url") );
2437 inserter.insertRange( new Range(1, 9/*-1*/, url4) );
2438 root = new TreeNode()
2439 .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2440 .appendChild( met1.dup()
2441 .appendChild( url4.dup()
2442 .appendChild( new TextNode("23456") ) ) )
2443 .appendChild( url4.dup().appendChild( new TextNode("78") ) )
2444 .appendChild( new TextNode("9") );
2445 doTest(root, false);
2446 // inside
2447 TreeNode url5 = new HyperlinkNode( mkName("url") );
2448 inserter.insertRange( new Range(4/*-1*/, 6/*-1*/, url5) );
2449 root = new TreeNode()
2450 .appendChild( url2.dup().appendChild( new TextNode("1") ) )
2451 .appendChild( met1.dup()
2452 .appendChild( url4.dup()
2453 .appendChild( new TextNode("23") ) )
2454 .appendChild( url5.dup()
2455 .appendChild( new TextNode("45") ) )
2456 .appendChild( url4.dup()
2457 .appendChild( new TextNode("6") ) ) )
2458 .appendChild( url4.dup().appendChild( new TextNode("78") ) )
2459 .appendChild( new TextNode("9") );
2460 doTest(root, false);
2463 public void testRangeMetaRuby() throws Exception
2465 RangeInserter inserter = new RangeInserter(m_xDoc);
2466 TreeNode text = new TextNode("123456789");
2467 inserter.insertRange( new Range(0, 0, text) );
2468 TreeNode met1 = new MetaNode( mkId("id") );
2469 inserter.insertRange( new Range(1, 5, met1) );
2470 // overlap left
2471 TreeNode rby2 = new RubyNode( mkName("ruby") );
2472 inserter.insertRange( new Range(0, 3/*-1*/, rby2) );
2473 TreeNode root = new TreeNode()
2474 .appendChild( rby2.dup().appendChild( new TextNode("1") ) )
2475 .appendChild( met1.dup()
2476 .appendChild( rby2.dup().appendChild( new TextNode("2") ) )
2477 .appendChild( new TextNode("345") ) )
2478 .appendChild( new TextNode("6789") );
2479 doTest(root, false);
2480 // overlap right
2481 TreeNode rby3 = new RubyNode( mkName("ruby") );
2482 inserter.insertRange( new Range(5/*-1*/, 7/*-1*/, rby3) );
2483 root = new TreeNode()
2484 .appendChild( rby2.dup().appendChild( new TextNode("1") ) )
2485 .appendChild( met1.dup()
2486 .appendChild( rby2.dup().appendChild( new TextNode("2") ) )
2487 .appendChild( new TextNode("34") )
2488 .appendChild( rby3.dup().appendChild( new TextNode("5") ) ) )
2489 .appendChild( rby3.dup().appendChild( new TextNode("6") ) )
2490 .appendChild( new TextNode("789") );
2491 doTest(root, false);
2492 // around
2493 TreeNode rby4 = new RubyNode( mkName("ruby") );
2494 inserter.insertRange( new Range(1, 7/*-1*/, rby4) );
2495 root = new TreeNode()
2496 .appendChild( rby2.dup().appendChild( new TextNode("1") ) )
2497 .appendChild( rby4.dup()
2498 .appendChild( met1.dup()
2499 .appendChild( new TextNode("2345") ) )
2500 .appendChild( new TextNode("6") ) )
2501 .appendChild( new TextNode("789") );
2502 doTest(root, false);
2503 // inside
2504 TreeNode met5 = new MetaNode( mkId("id") );
2505 inserter.insertRange( new Range(7/*-1*/, 9/*-1*/, met5) );
2506 TreeNode rby6 = new RubyNode( mkName("ruby") );
2507 inserter.insertRange( new Range(9/*-2*/, 10/*-2*/, rby6) );
2508 root = new TreeNode()
2509 .appendChild( rby2.dup().appendChild( new TextNode("1") ) )
2510 .appendChild( rby4.dup()
2511 .appendChild( met1.dup()
2512 .appendChild( new TextNode("2345") ) )
2513 .appendChild( new TextNode("6") ) )
2514 .appendChild( met5.dup()
2515 .appendChild( new TextNode("7") )
2516 .appendChild( rby6.dup()
2517 .appendChild( new TextNode("8") ) ) )
2518 .appendChild( new TextNode("9") );
2519 doTest(root, false);
2520 // inside, with invalid range that includes the dummy char
2521 TreeNode rby7 = new RubyNode( mkName("ruby") );
2522 inserter.insertRange( new Range(7/*-1*/, 9/*-2*/, rby7) );
2523 root = new TreeNode()
2524 .appendChild( rby2.dup().appendChild( new TextNode("1") ) )
2525 .appendChild( rby4.dup()
2526 .appendChild( met1.dup()
2527 .appendChild( new TextNode("2345") ) )
2528 .appendChild( new TextNode("6") ) )
2529 .appendChild( met5.dup()
2530 .appendChild( rby7.dup()
2531 .appendChild( new TextNode("7") ) )
2532 .appendChild( rby6.dup()
2533 .appendChild( new TextNode("8") ) ) )
2534 .appendChild( new TextNode("9") );
2535 doTest(root, false);
2536 // around, at same position as meta
2537 TreeNode rby8 = new RubyNode( mkName("ruby") );
2538 inserter.insertRange( new Range(7/*-1*/, 10/*-2*/, rby8) );
2539 root = new TreeNode()
2540 .appendChild( rby2.dup().appendChild( new TextNode("1") ) )
2541 .appendChild( rby4.dup()
2542 .appendChild( met1.dup()
2543 .appendChild( new TextNode("2345") ) )
2544 .appendChild( new TextNode("6") ) )
2545 .appendChild( rby8.dup()
2546 .appendChild( met5.dup()
2547 .appendChild( new TextNode("78") ) ) )
2548 .appendChild( new TextNode("9") );
2549 doTest(root, false);
2552 public void testRangeMetaMeta() throws Exception
2554 RangeInserter inserter = new RangeInserter(m_xDoc);
2555 TreeNode text = new TextNode("123456789");
2556 inserter.insertRange( new Range(0, 0, text) );
2557 TreeNode met1 = new MetaNode( mkId("id") );
2558 inserter.insertRange( new Range(3, 6, met1) );
2559 // overlap left
2560 TreeNode met2 = new MetaNode( mkId("id") );
2561 try {
2562 inserter.insertRange( new Range(0, 4, met2) );
2563 assure("testRangeMetaMeta: overlap left allowed", false);
2564 } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
2565 TreeNode root = new TreeNode()
2566 .appendChild( new TextNode("123") )
2567 .appendChild( met1.dup().appendChild( new TextNode("456") ) )
2568 .appendChild( new TextNode("789") );
2569 doTest(root, false);
2570 // overlap right
2571 TreeNode met3 = new MetaNode( mkId("id") );
2572 try {
2573 inserter.insertRange( new Range(5/*-1*/, 8/*-1*/, met3) );
2574 assure("testRangeMetaMeta: overlap right allowed", false);
2575 } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
2576 root = new TreeNode()
2577 .appendChild( new TextNode("123") )
2578 .appendChild( met1.dup().appendChild( new TextNode("456") ) )
2579 .appendChild( new TextNode("789") );
2580 doTest(root, false);
2581 // around
2582 TreeNode met4 = new MetaNode( mkId("id") );
2583 inserter.insertRange( new Range(3, 7/*-1*/, met4) );
2584 root = new TreeNode()
2585 .appendChild( new TextNode("123") )
2586 .appendChild( met4.dup()
2587 .appendChild( met1.dup().appendChild( new TextNode("456") ) ) )
2588 .appendChild( new TextNode("789") );
2589 doTest(root, false);
2590 // inside
2591 TreeNode met5 = new MetaNode( mkId("id") );
2592 inserter.insertRange( new Range(6/*-2*/, 8/*-2*/, met5) );
2593 root = new TreeNode()
2594 .appendChild( new TextNode("123") )
2595 .appendChild( met4.dup()
2596 .appendChild( met1.dup()
2597 .appendChild( new TextNode("4") )
2598 .appendChild( met5.dup()
2599 .appendChild( new TextNode("56") ) ) ) )
2600 .appendChild( new TextNode("789") );
2601 doTest(root, false);
2604 public void testRange2() throws Exception
2606 RangeInserter inserter = new RangeInserter(m_xDoc);
2607 TreeNode text = new TextNode("123456789");
2608 inserter.insertRange( new Range(0, 0, text) );
2609 TreeNode met1 = new MetaNode( mkId("id") );
2610 inserter.insertRange( new Range(1, 8, met1) );
2611 TreeNode met2 = new MetaNode( mkId("id") );
2612 inserter.insertRange( new Range(3/*-1*/, 8/*-1*/, met2) );
2613 TreeNode met3 = new MetaNode( mkId("id") );
2614 inserter.insertRange( new Range(5/*-2*/, 8/*-2*/, met3) );
2615 TreeNode root = new TreeNode()
2616 .appendChild( new TextNode("1") )
2617 .appendChild( met1.dup()
2618 .appendChild( new TextNode("2") )
2619 .appendChild( met2.dup()
2620 .appendChild( new TextNode("3") )
2621 .appendChild( met3.dup()
2622 .appendChild( new TextNode("456") ) )
2623 .appendChild( new TextNode("7") ) )
2624 .appendChild( new TextNode("8") ) )
2625 .appendChild( new TextNode("9") );
2626 doTest(root, false);
2627 // split ruby at every meta start!
2628 TreeNode rby4 = new RubyNode( mkName("ruby") );
2629 inserter.insertRange( new Range(0, 7/*-3*/, rby4) );
2630 root = new TreeNode()
2631 .appendChild( rby4.dup()
2632 .appendChild( new TextNode("1") ) )
2633 .appendChild( met1.dup()
2634 .appendChild( rby4.dup()
2635 .appendChild( new TextNode("2") ) )
2636 .appendChild( met2.dup()
2637 .appendChild( rby4.dup()
2638 .appendChild( new TextNode("3") ) )
2639 .appendChild( met3.dup()
2640 .appendChild( rby4.dup()
2641 .appendChild( new TextNode("4") ) )
2642 .appendChild( new TextNode("56") ) )
2643 .appendChild( new TextNode("7") ) )
2644 .appendChild( new TextNode("8") ) )
2645 .appendChild( new TextNode("9") );
2646 doTest(root, false);
2647 // split ruby at every meta end!
2648 TreeNode rby5 = new RubyNode( mkName("ruby") );
2649 inserter.insertRange( new Range(8/*-3*/, 12/*-3*/, rby5) );
2650 root = new TreeNode()
2651 .appendChild( rby4.dup()
2652 .appendChild( new TextNode("1") ) )
2653 .appendChild( met1.dup()
2654 .appendChild( rby4.dup()
2655 .appendChild( new TextNode("2") ) )
2656 .appendChild( met2.dup()
2657 .appendChild( rby4.dup()
2658 .appendChild( new TextNode("3") ) )
2659 .appendChild( met3.dup()
2660 .appendChild( rby4.dup()
2661 .appendChild( new TextNode("4") ) )
2662 .appendChild( new TextNode("5") )
2663 .appendChild( rby5.dup()
2664 .appendChild( new TextNode("6") ) ) )
2665 .appendChild( rby5.dup()
2666 .appendChild( new TextNode("7") ) ) )
2667 .appendChild( rby5.dup()
2668 .appendChild( new TextNode("8") ) ) )
2669 .appendChild( rby5.dup()
2670 .appendChild( new TextNode("9") ) );
2671 doTest(root, false);
2674 public void testRange3() throws Exception
2676 RangeInserter inserter = new RangeInserter(m_xDoc);
2677 TreeNode text = new TextNode("123456789");
2678 inserter.insertRange( new Range(0, 0, text) );
2679 TreeNode rby1 = new RubyNode( mkName("ruby") );
2680 inserter.insertRange( new Range(0, 9, rby1) );
2681 TreeNode met2 = new MetaNode( mkId("id") );
2682 inserter.insertRange( new Range(2, 7, met2) );
2683 TreeNode root = new TreeNode()
2684 .appendChild( rby1.dup()
2685 .appendChild( new TextNode("12") )
2686 .appendChild( met2.dup()
2687 .appendChild( new TextNode("34567") ) )
2688 .appendChild( new TextNode("89") ) );
2689 doTest(root, false);
2690 // overwrite outer ruby, split remains at inner meta!
2691 TreeNode rby3 = new RubyNode( mkName("ruby") );
2692 inserter.insertRange( new Range(5/*-1*/, 6/*-1*/, rby3) );
2693 root = new TreeNode()
2694 .appendChild( rby1.dup()
2695 .appendChild( new TextNode("12") ) )
2696 .appendChild( met2.dup()
2697 .appendChild( rby1.dup()
2698 .appendChild( new TextNode("34") ) )
2699 .appendChild( rby3.dup()
2700 .appendChild( new TextNode("5") ) )
2701 .appendChild( rby1.dup()
2702 .appendChild( new TextNode("67") ) ) )
2703 .appendChild( rby1.dup()
2704 .appendChild( new TextNode("89") ) );
2705 doTest(root, false);
2708 public void testRange4() throws Exception
2710 RangeInserter inserter = new RangeInserter(m_xDoc);
2711 TreeNode text = new TextNode("123456789");
2712 inserter.insertRange( new Range(0, 0, text) );
2713 TreeNode rby1 = new RubyNode( mkName("ruby") );
2714 inserter.insertRange( new Range(0, 9, rby1) );
2715 TreeNode met2 = new MetaNode( mkId("id") );
2716 inserter.insertRange( new Range(1, 8, met2) );
2717 TreeNode met3 = new MetaNode( mkId("id") );
2718 inserter.insertRange( new Range(3/*-1*/, 8/*-1*/, met3) );
2719 TreeNode met4 = new MetaNode( mkId("id") );
2720 inserter.insertRange( new Range(5/*-2*/, 8/*-2*/, met4) );
2721 TreeNode root = new TreeNode()
2722 .appendChild( rby1.dup()
2723 .appendChild( new TextNode("1") )
2724 .appendChild( met2.dup()
2725 .appendChild( new TextNode("2") )
2726 .appendChild( met3.dup()
2727 .appendChild( new TextNode("3") )
2728 .appendChild( met4.dup()
2729 .appendChild( new TextNode("456") ) )
2730 .appendChild( new TextNode("7") ) )
2731 .appendChild( new TextNode("8") ) )
2732 .appendChild( new TextNode("9") ) );
2733 doTest(root, false);
2734 // overwrite outer ruby, split remains at every inner meta!
2735 TreeNode rby5 = new RubyNode( mkName("ruby") );
2736 inserter.insertRange( new Range(7/*-3*/, 8/*-3*/, rby5) );
2737 root = new TreeNode()
2738 .appendChild( rby1.dup()
2739 .appendChild( new TextNode("1") ) )
2740 .appendChild( met2.dup()
2741 .appendChild( rby1.dup()
2742 .appendChild( new TextNode("2") ) )
2743 .appendChild( met3.dup()
2744 .appendChild( rby1.dup()
2745 .appendChild( new TextNode("3") ) )
2746 .appendChild( met4.dup()
2747 .appendChild( rby1.dup()
2748 .appendChild( new TextNode("4") ) )
2749 .appendChild( rby5.dup()
2750 .appendChild( new TextNode("5") ) )
2751 .appendChild( rby1.dup()
2752 .appendChild( new TextNode("6") ) ) )
2753 .appendChild( rby1.dup()
2754 .appendChild( new TextNode("7") ) ) )
2755 .appendChild( rby1.dup()
2756 .appendChild( new TextNode("8") ) ) )
2757 .appendChild( rby1.dup()
2758 .appendChild( new TextNode("9") ) );
2759 doTest(root, false);
2762 public void testRange5() throws Exception
2764 RangeInserter inserter = new RangeInserter(m_xDoc);
2765 TreeNode text = new TextNode("123456789");
2766 inserter.insertRange( new Range(0, 0, text) );
2767 TreeNode rby1 = new RubyNode( mkName("ruby") );
2768 inserter.insertRange( new Range(0, 9, rby1) );
2769 TreeNode met2 = new MetaNode( mkId("id") );
2770 inserter.insertRange( new Range(1, 3, met2) );
2771 TreeNode met3 = new MetaNode( mkId("id") );
2772 inserter.insertRange( new Range(5/*-1*/, 6/*-1*/, met3) );
2773 TreeNode met4 = new MetaNode( mkId("id") );
2774 inserter.insertRange( new Range(8/*-2*/, 10/*-2*/, met4) );
2775 TreeNode root = new TreeNode()
2776 .appendChild( rby1.dup()
2777 .appendChild( new TextNode("1") )
2778 .appendChild( met2.dup().appendChild( new TextNode("23") ) )
2779 .appendChild( new TextNode("4") )
2780 .appendChild( met3.dup().appendChild( new TextNode("5") ) )
2781 .appendChild( new TextNode("6") )
2782 .appendChild( met4.dup().appendChild( new TextNode("78") ) )
2783 .appendChild( new TextNode("9") ) );
2784 doTest(root, false);
2785 // overwrite outer ruby, but split at inner metas!
2786 TreeNode rby5 = new RubyNode( mkName("ruby") );
2787 inserter.insertRange( new Range(3/*-1*/, 10/*-3*/, rby5) );
2788 root = new TreeNode()
2789 .appendChild( rby1.dup()
2790 .appendChild( new TextNode("1") ) )
2791 .appendChild( met2.dup()
2792 .appendChild( rby1.dup()
2793 .appendChild( new TextNode("2") ) )
2794 .appendChild( rby5.dup()
2795 .appendChild( new TextNode("3") ) ) )
2796 .appendChild( rby5.dup()
2797 .appendChild( new TextNode("4") )
2798 .appendChild( met3.dup()
2799 .appendChild( new TextNode("5") ) )
2800 .appendChild( new TextNode("6") ) )
2801 .appendChild( met4.dup()
2802 .appendChild( rby5.dup()
2803 .appendChild( new TextNode("7") ) )
2804 .appendChild( rby1.dup()
2805 .appendChild( new TextNode("8") ) ) )
2806 .appendChild( rby1.dup()
2807 .appendChild( new TextNode("9") ) );
2808 doTest(root, false);
2811 public void testRange6() throws Exception
2813 RangeInserter inserter = new RangeInserter(m_xDoc);
2814 TreeNode text = new TextNode("123456789");
2815 inserter.insertRange( new Range(0, 0, text) );
2816 TreeNode met1 = new MetaNode( mkId("id") );
2817 inserter.insertRange( new Range(1, 5, met1) );
2818 TreeNode met2 = new MetaNode( mkId("id") );
2819 inserter.insertRange( new Range(3/*-1*/, 6/*-1*/, met2) );
2820 TreeNode met3 = new MetaNode( mkId("id") );
2821 inserter.insertRange( new Range(5/*-2*/, 7/*-2*/, met3) );
2822 TreeNode root = new TreeNode()
2823 .appendChild( new TextNode("1") )
2824 .appendChild( met1.dup()
2825 .appendChild( new TextNode("2") )
2826 .appendChild( met2.dup()
2827 .appendChild( new TextNode("3") )
2828 .appendChild( met3.dup()
2829 .appendChild( new TextNode("45") ) ) ) )
2830 .appendChild( new TextNode("6789") );
2831 doTest(root, false);
2832 // split at 3 metas, all at same position
2833 TreeNode rby4 = new RubyNode( mkName("ruby") );
2834 inserter.insertRange( new Range(7/*-3*/, 10/*-3*/, rby4) );
2835 root = new TreeNode()
2836 .appendChild( new TextNode("1") )
2837 .appendChild( met1.dup()
2838 .appendChild( new TextNode("2") )
2839 .appendChild( met2.dup()
2840 .appendChild( new TextNode("3") )
2841 .appendChild( met3.dup()
2842 .appendChild( new TextNode("4") )
2843 .appendChild( rby4.dup()
2844 .appendChild( new TextNode("5") ) ) ) ) )
2845 .appendChild( rby4.dup()
2846 .appendChild( new TextNode("67") ) )
2847 .appendChild( new TextNode("89") );
2848 doTest(root, false);
2851 public void testRange7() throws Exception
2853 RangeInserter inserter = new RangeInserter(m_xDoc);
2854 TreeNode text = new TextNode("123456789");
2855 inserter.insertRange( new Range(0, 0, text) );
2856 TreeNode url1 = new HyperlinkNode( mkName("url") );
2857 inserter.insertRange( new Range(1, 5, url1) );
2858 TreeNode met2 = new MetaNode( mkId("id") );
2859 inserter.insertRange( new Range(3, 5, met2) );
2860 TreeNode root = new TreeNode()
2861 .appendChild( new TextNode("1") )
2862 .appendChild( url1.dup()
2863 .appendChild( new TextNode("23") ) )
2864 .appendChild( met2.dup()
2865 .appendChild( url1.dup()
2866 .appendChild( new TextNode("45") ) ) )
2867 .appendChild( new TextNode("6789") );
2868 doTest(root, false);
2869 // this should result in not splitting the hyperlink, but due to API
2870 // we can't tell :(
2871 TreeNode rby3 = new RubyNode( mkName("ruby") );
2872 inserter.insertRange( new Range(5/*-1*/, 8/*-1*/, rby3) );
2873 root = new TreeNode()
2874 .appendChild( new TextNode("1") )
2875 .appendChild( url1.dup()
2876 .appendChild( new TextNode("23") ) )
2877 .appendChild( met2.dup()
2878 .appendChild( url1.dup()
2879 .appendChild( new TextNode("4") ) )
2880 .appendChild( rby3.dup()
2881 .appendChild( url1.dup()
2882 .appendChild( new TextNode("5") ) ) ) )
2883 .appendChild( rby3.dup()
2884 .appendChild( new TextNode("67") ) )
2885 .appendChild( new TextNode("89") );
2886 doTest(root, false);
2889 /* TODO: test partial selection, test UNDO/REDO */
2891 /** test SwXMeta XText interface */
2892 public void testMetaXText() throws Exception
2894 RangeInserter inserter = new RangeInserter(m_xDoc);
2895 TreeNode text = new TextNode("12AB6789");
2896 inserter.insertRange( new Range(0, 0, text) );
2897 MetaNode meta = new MetaNode( mkId("id") );
2898 // inserter.insertRange( new Range(3, 5, met2) );
2899 XTextContent xMeta = inserter.makeMeta();
2901 XText xDocText = m_xDoc.getText();
2902 XTextCursor xDocTextCursor = xDocText.createTextCursor();
2903 xDocTextCursor.goRight((short)3, false);
2904 xDocTextCursor.goRight((short)2, true);
2905 xDocText.insertTextContent(xDocTextCursor, xMeta, true);
2906 // xMeta.attach(xDocTextCursor);
2908 XMetadatable xMetadatable = (XMetadatable)
2909 UnoRuntime.queryInterface(XMetadatable.class, xMeta);
2910 xMetadatable.setMetadataReference(meta.getXmlId());
2911 XText xText = (XText) UnoRuntime.queryInterface(XText.class, xMeta);
2913 XText xParentText = xText.getText();
2914 assure("getText(): no parent", xParentText != null);
2916 XTextRange xStart = xText.getStart();
2917 assure("getStart(): no start", xStart != null);
2919 XTextRange xEnd = xText.getEnd();
2920 assure("getEnd(): no end", xEnd != null);
2923 String string = xText.getString();
2924 assure("getString(): invalid string returned",
2925 string != null && "AB".equals(string) );
2928 xText.setString("45");
2931 String string = xText.getString();
2932 assure("getString(): invalid string returned: " + string,
2933 string != null && "45".equals(string) );
2936 XTextCursor xTextCursor = xText.createTextCursor();
2937 assure("createTextCursor(): failed", xTextCursor != null);
2939 try {
2940 xText.createTextCursorByRange(null);
2941 assure("createTextCursorByRange(): null allowed?", false);
2942 } catch (RuntimeException e) { /* expected */ }
2944 XTextCursor xTextCursorStart = xText.createTextCursorByRange(xStart);
2945 assure("createTextCursorByRange(): failed for start",
2946 xTextCursorStart != null);
2948 XTextCursor xTextCursorEnd = xText.createTextCursorByRange(xEnd);
2949 assure("createTextCursorByRange(): failed for end",
2950 xTextCursorEnd != null);
2952 // move outside meta
2953 xDocTextCursor.gotoStart(false);
2955 try {
2956 xText.insertString(null, "foo", false);
2957 assure("insertString(): null allowed?", false);
2958 } catch (RuntimeException e) { /* expected */ }
2960 try {
2961 xText.insertString(xDocTextCursor, "foo", false);
2962 assure("insertString(): cursor outside allowed?", false);
2963 } catch (RuntimeException e) { /* expected */ }
2965 xStart = xText.getStart();
2966 xText.insertString(xStart, "A", false);
2968 String string = xText.getString();
2969 assure("getString(): invalid string returned: " + string,
2970 string != null && "A45".equals(string) );
2973 xText.insertString(xEnd, "B", false);
2975 String string = xText.getString();
2976 assure("getString(): invalid string returned: " + string,
2977 string != null && "A45B".equals(string) );
2980 try {
2981 xText.insertControlCharacter(null, HARD_HYPHEN, false);
2982 assure("insertControlCharacter(): null allowed?", false);
2983 } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
2985 xStart = xText.getStart();
2986 try {
2987 xText.insertControlCharacter(xDocTextCursor, HARD_HYPHEN, false);
2988 assure("insertControlCharacter(): cursor outside allowed?", false);
2989 } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
2991 xText.insertControlCharacter(xStart, HARD_HYPHEN, false);
2993 String string = xText.getString();
2994 assure("getString(): invalid string returned: " + string,
2995 string != null && ('\u2011' + "A45B").equals(string) );
2998 xText.insertControlCharacter(xEnd, HARD_HYPHEN, false);
3000 String string = xText.getString();
3001 assure("getString(): invalid string returned: " + string,
3002 string != null &&
3003 ('\u2011' + "A45B" + '\u2011').equals(string) );
3006 xText.setString("45");
3008 try {
3009 xText.insertTextContent(null, xMeta, false);
3010 assure("insertTextContent(): null range allowed?", false);
3011 } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
3013 try {
3014 xText.insertTextContent(xStart, null, false);
3015 assure("insertTextContent(): null content allowed?", false);
3016 } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
3018 try {
3019 xText.insertTextContent(xDocTextCursor, xMeta, false);
3020 assure("insertTextContent(): cursor outside allowed?", false);
3021 } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
3023 TextFieldNode field1 = new TextFieldNode( "f1" );
3024 TextFieldNode field2 = new TextFieldNode( "f2" );
3025 XTextContent xField1 = inserter.makeTextField(field1.getContent());
3026 XTextContent xField2 = inserter.makeTextField(field2.getContent());
3028 xStart = xText.getStart();
3029 xText.insertTextContent(xStart, xField1, false);
3031 TreeNode root = new TreeNode()
3032 .appendChild( new TextNode("12") )
3033 .appendChild( meta.dup()
3034 .appendChild( field1.dup() )
3035 .appendChild( new TextNode("45") ) )
3036 .appendChild( new TextNode("6789") );
3037 doTest(root, false);
3039 xText.insertTextContent(xEnd, xField2, false);
3041 root = new TreeNode()
3042 .appendChild( new TextNode("12") )
3043 .appendChild( meta.dup()
3044 .appendChild( field1.dup() )
3045 .appendChild( new TextNode("45") )
3046 .appendChild( field2.dup() ) )
3047 .appendChild( new TextNode("6789") );
3048 doTest(root, false);
3050 try {
3051 xText.removeTextContent(null);
3052 assure("removeTextContent(): null content allowed?", false);
3053 } catch (RuntimeException e) { /* expected */ }
3055 xText.removeTextContent(xField1);
3057 XTextRange xAnchor = xMeta.getAnchor();
3058 assure("getAnchor(): null", xAnchor != null);
3060 // evil test case: insert ruby around meta
3061 RubyNode ruby = new RubyNode( mkName("ruby") );
3062 inserter.insertRange( new Range(2, 6, ruby) );
3064 /* prevent caching...
3065 root = new TreeNode()
3066 .appendChild( new TextNode("12") )
3067 .appendChild( ruby.dup()
3068 .appendChild( meta.dup()
3069 .appendChild( new TextNode("45") )
3070 .appendChild( field2.dup() ) ) )
3071 .appendChild( new TextNode("6789") );
3072 doTest(root, false);
3075 XEnumerationAccess xEA = (XEnumerationAccess)
3076 UnoRuntime.queryInterface(XEnumerationAccess.class, xMeta);
3077 XEnumeration xEnum = xEA.createEnumeration();
3078 assure("createEnumeration(): returns null", xEnum != null);
3080 assure("hasNext(): first missing", xEnum.hasMoreElements());
3081 Object xElement = xEnum.nextElement();
3082 XTextRange xPortion = (XTextRange)
3083 UnoRuntime.queryInterface(XTextRange.class, xElement);
3084 XPropertySet xPropSet = (XPropertySet)
3085 UnoRuntime.queryInterface(XPropertySet.class, xPortion);
3086 String type = (String) xPropSet.getPropertyValue("TextPortionType");
3087 assure("first: not text", type.equals("Text"));
3088 String txt = xPortion.getString();
3089 assure("first: text differs: " + txt, "45".equals(txt));
3092 assure("hasNext(): second missing", xEnum.hasMoreElements());
3093 Object xElement = xEnum.nextElement();
3094 XTextRange xPortion = (XTextRange)
3095 UnoRuntime.queryInterface(XTextRange.class, xElement);
3096 XPropertySet xPropSet = (XPropertySet)
3097 UnoRuntime.queryInterface(XPropertySet.class, xPortion);
3098 String type = (String) xPropSet.getPropertyValue("TextPortionType");
3099 assure("second: not text", type.equals("TextField"));
3101 // no ruby end here!!!
3102 assure("hasNext(): more elements?", !xEnum.hasMoreElements());
3104 XComponent xComponent = (XComponent)
3105 UnoRuntime.queryInterface(XComponent.class, xMeta);
3106 xComponent.dispose();
3108 try {
3109 XTextCursor xCursor = xText.createTextCursor();
3110 assure("createTextCursor(): succeeds on disposed object?",
3111 xCursor == null);
3112 } catch (RuntimeException e) { /* expected */ }
3115 /** check that cursor move methods move to positions in the meta,
3116 but do not move to positions outside the meta. */
3117 public void testMetaXTextCursor() throws Exception
3119 RangeInserter inserter = new RangeInserter(m_xDoc);
3120 TreeNode text = new TextNode("Text. 12 More text here.");
3121 inserter.insertRange( new Range(0, 0, text) );
3122 MetaNode met1 = new MetaNode( mkId("id") );
3123 XTextContent xMeta = inserter.makeMeta();
3125 XText xDocText = m_xDoc.getText();
3126 XTextCursor xDocTextCursor = xDocText.createTextCursor();
3127 xDocTextCursor.goRight((short)7, false);
3128 xDocTextCursor.goRight((short)2, true);
3129 xDocText.insertTextContent(xDocTextCursor, xMeta, true);
3130 xDocTextCursor.gotoStart(true);
3132 XMetadatable xMetadatable = (XMetadatable)
3133 UnoRuntime.queryInterface(XMetadatable.class, xMeta);
3134 xMetadatable.setMetadataReference(met1.getXmlId());
3135 XText xText = (XText) UnoRuntime.queryInterface(XText.class, xMeta);
3137 XTextRange xStart = xText.getStart();
3138 assure("getStart(): no start", xStart != null);
3139 XTextRange xEnd = xText.getEnd();
3140 assure("getEnd(): no end", xEnd != null);
3142 XTextCursor xTextCursor = xText.createTextCursor();
3143 assure("createTextCursor(): no cursor", xTextCursor != null);
3145 // XTextCursor
3146 boolean bSuccess = false;
3147 xTextCursor.gotoStart(false);
3148 xTextCursor.gotoEnd(false);
3149 bSuccess = xTextCursor.goLeft((short)1, false);
3150 assure("goLeft(): failed", bSuccess);
3151 bSuccess = xTextCursor.goLeft((short)1000, false);
3152 assure("goLeft(): succeeded", !bSuccess);
3153 bSuccess = xTextCursor.goRight((short)1, false);
3154 assure("goRight(): failed", bSuccess);
3155 bSuccess = xTextCursor.goRight((short)1000, false);
3156 assure("goRight(): succeeded", !bSuccess);
3157 xTextCursor.gotoRange(xStart, false);
3158 xTextCursor.gotoRange(xEnd, false);
3159 try {
3160 xTextCursor.gotoRange(xDocTextCursor, false);
3161 assure("gotoRange(): succeeded", false);
3162 } catch (RuntimeException e) { /* expected */ }
3164 // XWordCursor
3165 xText.setString("Two words");
3166 xTextCursor.gotoStart(false);
3167 XWordCursor xWordCursor = (XWordCursor)
3168 UnoRuntime.queryInterface(XWordCursor.class, xTextCursor);
3170 bSuccess = xWordCursor.gotoNextWord(true);
3171 assure("gotoNextWord(): failed", bSuccess);
3173 String string = xTextCursor.getString();
3174 assure("gotoNextWord(): wrong string: " + string,
3175 "Two ".equals(string));
3177 bSuccess = xWordCursor.gotoNextWord(false);
3178 assure("gotoNextWord(): succeeded", !bSuccess);
3179 xTextCursor.collapseToEnd();
3180 bSuccess = xWordCursor.gotoPreviousWord(true);
3181 assure("gotoPreviousWord(): failed", bSuccess);
3183 String string = xTextCursor.getString();
3184 assure("gotoPreviousWord(): wrong string: " + string,
3185 "words".equals(string));
3187 bSuccess = xWordCursor.gotoPreviousWord(false);
3188 assure("gotoPreviousWord(): succeeded", !bSuccess);
3189 bSuccess = xWordCursor.gotoEndOfWord(true);
3190 assure("gotoEndOfWord(): failed", bSuccess);
3192 String string = xTextCursor.getString();
3193 assure("gotoEndOfWord(): wrong string: " + string,
3194 "Two".equals(string));
3196 xTextCursor.gotoEnd(false);
3197 bSuccess = xWordCursor.gotoStartOfWord(true);
3198 assure("gotoStartOfWord(): failed", bSuccess);
3200 String string = xTextCursor.getString();
3201 assure("gotoStartOfWord(): wrong string: " + string,
3202 "words".equals(string));
3204 xText.setString("");
3205 bSuccess = xWordCursor.gotoEndOfWord(false);
3206 assure("gotoEndOfWord(): succeeded", !bSuccess);
3207 bSuccess = xWordCursor.gotoStartOfWord(false);
3208 assure("gotoStartOfWord(): succeeded", !bSuccess);
3210 // XSentenceCursor
3211 xText.setString("This is a sentence. Another sentence.");
3212 xTextCursor.gotoStart(false);
3213 XSentenceCursor xSentenceCursor = (XSentenceCursor)
3214 UnoRuntime.queryInterface(XSentenceCursor.class, xTextCursor);
3216 bSuccess = xSentenceCursor.gotoNextSentence(true);
3217 assure("gotoNextSentence(): failed", bSuccess);
3219 String string = xTextCursor.getString();
3220 assure("gotoNextSentence(): wrong string: " + string,
3221 "This is a sentence. ".equals(string));
3223 bSuccess = xSentenceCursor.gotoNextSentence(false);
3224 assure("gotoNextSentence(): succeeded", !bSuccess);
3225 // FIXME:
3226 // the sentence cursor seems to work differently than the word cursor
3227 xText.setString("This is a sentence. Another sentence. Sentence 3.");
3228 xTextCursor.gotoEnd(false);
3229 bSuccess = xSentenceCursor.gotoPreviousSentence(true);
3230 assure("gotoPreviousSentence(): failed", bSuccess);
3232 String string = xTextCursor.getString();
3233 assure("gotoPreviousSentence(): wrong string: " + string,
3234 "Another sentence. Sentence 3.".equals(string));
3236 bSuccess = xSentenceCursor.gotoPreviousSentence(false);
3237 assure("gotoPreviousSentence(): succeeded", !bSuccess);
3238 bSuccess = xSentenceCursor.gotoEndOfSentence(true);
3239 assure("gotoEndOfSentence(): failed", bSuccess);
3241 String string = xTextCursor.getString();
3242 assure("gotoEndOfSentence(): wrong string: " + string,
3243 "This is a sentence.".equals(string));
3245 xTextCursor.gotoEnd(false);
3246 bSuccess = xSentenceCursor.gotoStartOfSentence(true);
3247 assure("gotoStartOfSentence(): failed", bSuccess);
3249 String string = xTextCursor.getString();
3250 assure("gotoStartOfSentence(): wrong string: " + string,
3251 "Sentence 3.".equals(string));
3253 xText.setString("");
3254 bSuccess = xSentenceCursor.gotoEndOfSentence(false);
3255 assure("gotoEndOfSentence(): succeeded", !bSuccess);
3256 bSuccess = xSentenceCursor.gotoStartOfSentence(false);
3257 assure("gotoStartOfSentence(): succeeded", !bSuccess);
3259 XParagraphCursor xParagraphCursor = (XParagraphCursor)
3260 UnoRuntime.queryInterface(XParagraphCursor.class, xTextCursor);
3262 // XParagraphCursor (does not make sense)
3263 bSuccess = xParagraphCursor.gotoNextParagraph(false);
3264 assure("gotoNextParagraph(): succeeded", !bSuccess);
3265 bSuccess = xParagraphCursor.gotoPreviousParagraph(false);
3266 assure("gotoPreviousParagraph(): succeeded", !bSuccess);
3267 bSuccess = xParagraphCursor.gotoStartOfParagraph(false);
3268 assure("gotoStartOfParagraph(): succeeded", !bSuccess);
3269 bSuccess = xParagraphCursor.gotoEndOfParagraph(false);
3270 assure("gotoEndOfParagraph(): succeeded", !bSuccess);
3274 abstract class AttachHelper
3276 abstract boolean isAttribute();
3277 abstract TreeNode mkTreeNode();
3278 abstract XTextContent mkTextContent(Inserter inserter, TreeNode node)
3279 throws Exception;
3280 void postInserted(TreeNode node, XTextContent xContent)
3281 throws Exception { }
3284 public void testMetaXTextAttachToxMark() throws Exception
3286 doMetaXTextAttach( new AttachHelper()
3288 boolean isAttribute() { return true; }
3289 TreeNode mkTreeNode() {
3290 return new DocumentIndexMarkNode( mkName("toxmark") );
3292 XTextContent mkTextContent(Inserter inserter, TreeNode node)
3293 throws Exception {
3294 return inserter.makeDocumentIndexMark(
3295 ((DocumentIndexMarkNode)node).getName());
3300 public void testMetaXTextAttachRefMark() throws Exception
3302 doMetaXTextAttach( new AttachHelper()
3304 boolean isAttribute() { return true; }
3305 TreeNode mkTreeNode() {
3306 return new ReferenceMarkNode( mkName("refmark") );
3308 XTextContent mkTextContent(Inserter inserter, TreeNode node)
3309 throws Exception {
3310 return inserter.makeReferenceMark(
3311 ((ReferenceMarkNode)node).getName());
3316 public void testMetaXTextAttachTextField() throws Exception
3318 doMetaXTextAttach( new AttachHelper()
3320 boolean isAttribute() { return false; }
3321 TreeNode mkTreeNode() {
3322 return new TextFieldNode( mkName("field") );
3324 XTextContent mkTextContent(Inserter inserter, TreeNode node)
3325 throws Exception {
3326 return inserter.makeTextField(
3327 ((TextFieldNode)node).getContent());
3332 public void testMetaXTextAttachFootnote() throws Exception
3334 doMetaXTextAttach( new AttachHelper()
3336 boolean isAttribute() { return false; }
3337 TreeNode mkTreeNode() {
3338 return new FootnoteNode( mkName("ftn") );
3340 XTextContent mkTextContent(Inserter inserter, TreeNode node)
3341 throws Exception {
3342 return inserter.makeFootnote(
3343 ((FootnoteNode)node).getLabel());
3348 public void testMetaXTextAttachMeta() throws Exception
3350 doMetaXTextAttach( new AttachHelper()
3352 boolean isAttribute() { return true; }
3353 TreeNode mkTreeNode() {
3354 return new MetaNode( mkId("id") );
3356 XTextContent mkTextContent(Inserter inserter, TreeNode node)
3357 throws Exception {
3358 return inserter.makeMeta();
3360 void postInserted(TreeNode node, XTextContent xContent)
3361 throws Exception {
3362 XMetadatable xMetadatable = (XMetadatable)
3363 UnoRuntime.queryInterface(XMetadatable.class, xContent);
3364 xMetadatable.setMetadataReference(
3365 ((MetaNode)node).getXmlId());
3370 void doMetaXTextAttach(AttachHelper helper) throws Exception
3372 RangeInserter inserter = new RangeInserter(m_xDoc);
3373 TreeNode text = new TextNode("12AB6789");
3374 inserter.insertRange( new Range(0, 0, text) );
3375 MetaNode met1 = new MetaNode( mkId("id") );
3376 XTextContent xMeta = inserter.makeMeta();
3378 XText xDocText = m_xDoc.getText();
3379 XTextCursor xDocTextCursor = xDocText.createTextCursor();
3380 xDocTextCursor.goRight((short)3, false);
3381 xDocTextCursor.goRight((short)2, true);
3382 xDocText.insertTextContent(xDocTextCursor, xMeta, true);
3384 XMetadatable xMetadatable = (XMetadatable)
3385 UnoRuntime.queryInterface(XMetadatable.class, xMeta);
3386 xMetadatable.setMetadataReference(met1.getXmlId());
3387 XText xText = (XText) UnoRuntime.queryInterface(XText.class, xMeta);
3388 XTextRange xStart = null;
3389 XTextRange xEnd = null;
3392 xStart = xText.getStart();
3393 xEnd = xText.getEnd();
3395 TreeNode nod1 = helper.mkTreeNode();
3396 TreeNode nod2 = helper.mkTreeNode();
3397 XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
3398 XTextContent xContent2 = helper.mkTextContent(inserter, nod2);
3400 // insertTextContent with meta getStart()/getEnd()
3401 xText.insertTextContent(xStart, xContent1, false);
3402 xText.insertTextContent(xEnd , xContent2, false);
3404 helper.postInserted(nod1, xContent1);
3405 helper.postInserted(nod2, xContent2);
3407 TreeNode root = new TreeNode()
3408 .appendChild( new TextNode("12") )
3409 .appendChild( met1.dup()
3410 .appendChild( nod1.dup() )
3411 .appendChild( new TextNode("AB") )
3412 .appendChild( nod2.dup() ) )
3413 .appendChild( new TextNode("6789") );
3414 doTest(root, false);
3417 xText.setString("AB");
3418 xStart = xText.getStart();
3419 xEnd = xText.getEnd();
3421 TreeNode nod1 = helper.mkTreeNode();
3422 TreeNode nod2 = helper.mkTreeNode();
3423 XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
3424 XTextContent xContent2 = helper.mkTextContent(inserter, nod2);
3426 XTextCursor xTextCursor = xText.createTextCursor();
3427 xTextCursor.gotoStart(false);
3429 // insertTextContent with meta cursor
3430 xText.insertTextContent(xTextCursor, xContent1, false);
3431 xTextCursor.gotoEnd(false);
3432 xText.insertTextContent(xTextCursor, xContent2, false);
3434 helper.postInserted(nod1, xContent1);
3435 helper.postInserted(nod2, xContent2);
3437 TreeNode root = new TreeNode()
3438 .appendChild( new TextNode("12") )
3439 .appendChild( met1.dup()
3440 .appendChild( nod1.dup() )
3441 .appendChild( new TextNode("AB") )
3442 .appendChild( nod2.dup() ) )
3443 .appendChild( new TextNode("6789") );
3444 doTest(root, false);
3446 if (!helper.isAttribute())
3448 // xText.setString("AB");
3449 xStart = xText.getStart();
3450 xEnd = xText.getEnd();
3452 TreeNode nod1 = helper.mkTreeNode();
3453 TreeNode nod2 = helper.mkTreeNode();
3454 XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
3455 XTextContent xContent2 = helper.mkTextContent(inserter, nod2);
3457 XTextCursor xTextCursor = xText.createTextCursor();
3458 xTextCursor.gotoStart(false);
3459 xTextCursor.goRight((short)1, true);
3461 // insertTextContent with meta cursor and absorb
3462 xText.insertTextContent(xTextCursor, xContent1, true);
3463 xTextCursor.gotoEnd(false);
3464 xTextCursor.goLeft((short)1, true);
3465 xText.insertTextContent(xTextCursor, xContent2, true);
3467 helper.postInserted(nod1, xContent1);
3468 helper.postInserted(nod2, xContent2);
3470 TreeNode root = new TreeNode()
3471 .appendChild( new TextNode("12") )
3472 .appendChild( met1.dup()
3473 .appendChild( nod1.dup() )
3474 .appendChild( new TextNode("AB") )
3475 .appendChild( nod2.dup() ) )
3476 .appendChild( new TextNode("6789") );
3477 doTest(root, false);
3480 xText.setString("AB");
3481 xStart = xText.getStart();
3482 xEnd = xText.getEnd();
3484 TreeNode nod1 = helper.mkTreeNode();
3485 TreeNode nod2 = helper.mkTreeNode();
3486 XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
3487 XTextContent xContent2 = helper.mkTextContent(inserter, nod2);
3489 xDocTextCursor.gotoRange(xStart, false);
3491 // insertTextContent with document cursor
3492 xText.insertTextContent(xDocTextCursor, xContent1, false);
3493 xDocTextCursor.gotoRange(xEnd, false);
3494 xText.insertTextContent(xDocTextCursor, xContent2, false);
3496 helper.postInserted(nod1, xContent1);
3497 helper.postInserted(nod2, xContent2);
3499 TreeNode root = new TreeNode()
3500 .appendChild( new TextNode("12") )
3501 .appendChild( met1.dup()
3502 .appendChild( nod1.dup() )
3503 .appendChild( new TextNode("AB") )
3504 .appendChild( nod2.dup() ) )
3505 .appendChild( new TextNode("6789") );
3506 doTest(root, false);
3508 if (!helper.isAttribute())
3510 // xText.setString("AB");
3511 xStart = xText.getStart();
3512 xEnd = xText.getEnd();
3514 TreeNode nod1 = helper.mkTreeNode();
3515 TreeNode nod2 = helper.mkTreeNode();
3516 XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
3517 XTextContent xContent2 = helper.mkTextContent(inserter, nod2);
3519 xDocTextCursor.gotoRange(xStart, false);
3520 xDocTextCursor.goRight((short)1, true);
3522 // insertTextContent with document cursor and absorb
3523 xText.insertTextContent(xDocTextCursor, xContent1, true);
3524 xDocTextCursor.gotoRange(xEnd, false);
3525 xDocTextCursor.goLeft((short)1, true);
3526 xText.insertTextContent(xDocTextCursor, xContent2, true);
3528 helper.postInserted(nod1, xContent1);
3529 helper.postInserted(nod2, xContent2);
3531 TreeNode root = new TreeNode()
3532 .appendChild( new TextNode("12") )
3533 .appendChild( met1.dup()
3534 .appendChild( nod1.dup() )
3535 .appendChild( new TextNode("AB") )
3536 .appendChild( nod2.dup() ) )
3537 .appendChild( new TextNode("6789") );
3538 doTest(root, false);
3541 xText.setString("AB");
3542 xStart = xText.getStart();
3543 xEnd = xText.getEnd();
3545 TreeNode nod1 = helper.mkTreeNode();
3546 TreeNode nod2 = helper.mkTreeNode();
3547 XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
3548 XTextContent xContent2 = helper.mkTextContent(inserter, nod2);
3550 // attach to range from meta getStart()/getEnd()
3551 xContent1.attach(xStart);
3552 xContent2.attach(xEnd);
3554 helper.postInserted(nod1, xContent1);
3555 helper.postInserted(nod2, xContent2);
3557 TreeNode root = new TreeNode()
3558 .appendChild( new TextNode("12") )
3559 .appendChild( met1.dup()
3560 .appendChild( nod1.dup() )
3561 .appendChild( new TextNode("AB") )
3562 .appendChild( nod2.dup() ) )
3563 .appendChild( new TextNode("6789") );
3564 doTest(root, false);
3567 xText.setString("AB");
3568 xStart = xText.getStart();
3569 xEnd = xText.getEnd();
3571 TreeNode nod1 = helper.mkTreeNode();
3572 TreeNode nod2 = helper.mkTreeNode();
3573 XTextContent xContent1 = helper.mkTextContent(inserter, nod1);
3574 XTextContent xContent2 = helper.mkTextContent(inserter, nod2);
3576 XTextCursor xTextCursor = xText.createTextCursor();
3577 xTextCursor.gotoStart(false);
3579 // attach to cursor from meta XText
3580 xContent1.attach(xTextCursor);
3581 xTextCursor.gotoEnd(false);
3582 xContent2.attach(xTextCursor);
3584 helper.postInserted(nod1, xContent1);
3585 helper.postInserted(nod2, xContent2);
3587 TreeNode root = new TreeNode()
3588 .appendChild( new TextNode("12") )
3589 .appendChild( met1.dup()
3590 .appendChild( nod1.dup() )
3591 .appendChild( new TextNode("AB") )
3592 .appendChild( nod2.dup() ) )
3593 .appendChild( new TextNode("6789") );
3594 doTest(root, false);
3598 public void testMetaFieldXTextField() throws Exception
3600 com.sun.star.rdf.XRepositorySupplier xModel =
3601 (com.sun.star.rdf.XRepositorySupplier) UnoRuntime.queryInterface(
3602 com.sun.star.rdf.XRepositorySupplier.class, m_xDoc);
3603 com.sun.star.rdf.XRepository xRepo = xModel.getRDFRepository();
3604 // for testing just add it to the first graph
3605 com.sun.star.rdf.XURI[] Graphs = xRepo.getGraphNames();
3606 com.sun.star.rdf.XNamedGraph xGraph = xRepo.getGraph(Graphs[0]);
3607 com.sun.star.rdf.XURI xOdfPrefix =
3608 com.sun.star.rdf.URI.createKnown(m_xContext,
3609 com.sun.star.rdf.URIs.ODF_PREFIX);
3610 com.sun.star.rdf.XURI xOdfSuffix =
3611 com.sun.star.rdf.URI.createKnown(m_xContext,
3612 com.sun.star.rdf.URIs.ODF_SUFFIX);
3613 com.sun.star.rdf.XNode xPrefix =
3614 com.sun.star.rdf.Literal.create(m_xContext, "foo");
3615 com.sun.star.rdf.XNode xSuffix =
3616 com.sun.star.rdf.Literal.create(m_xContext, "bar");
3618 RangeInserter inserter = new RangeInserter(m_xDoc);
3619 TreeNode text = new TextNode("abc");
3620 inserter.insertRange( new Range(0, 0, text) );
3621 XText xDocText = m_xDoc.getText();
3622 XTextCursor xDocTextCursor = xDocText.createTextCursor();
3623 xDocTextCursor.goRight((short)1, false);
3624 xDocTextCursor.goRight((short)3, true);
3626 XTextField xMetaField = inserter.makeMetaField();
3628 xDocText.insertTextContent(xDocTextCursor, xMetaField, true);
3630 XMetadatable xMetadatable = (XMetadatable)
3631 UnoRuntime.queryInterface(XMetadatable.class, xMetaField);
3632 xMetadatable.ensureMetadataReference();
3634 xGraph.addStatement(xMetadatable, xOdfPrefix, xPrefix);
3635 xGraph.addStatement(xMetadatable, xOdfSuffix, xSuffix);
3636 assure("getPresentation(): wrong",
3637 "fooabcbar".equals(xMetaField.getPresentation(false)));
3638 inserter.insertRange( new Range(0, 0, text) );
3641 public void testMetaFieldXPropertySet() throws Exception
3643 RangeInserter inserter = new RangeInserter(m_xDoc);
3644 TreeNode text = new TextNode("123");
3645 inserter.insertRange( new Range(0, 0, text) );
3646 XText xDocText = m_xDoc.getText();
3647 XTextCursor xDocTextCursor = xDocText.createTextCursor();
3648 xDocTextCursor.goRight((short)1, false);
3649 xDocTextCursor.goRight((short)3, true);
3651 XTextField xMetaField = inserter.makeMetaField();
3653 xDocText.insertTextContent(xDocTextCursor, xMetaField, true);
3655 XPropertySet xPropertySet = (XPropertySet)
3656 UnoRuntime.queryInterface(XPropertySet.class, xMetaField);
3657 assure("PropertySet: not supported?", xPropertySet != null);
3658 XPropertySetInfo xPropertySetInfo = xPropertySet.getPropertySetInfo();
3659 assure("hasPropertyByName(\"NumberFormat\"):",
3660 xPropertySetInfo.hasPropertyByName("NumberFormat"));
3661 assure("hasPropertyByName(\"IsFixedLanguage\"):",
3662 xPropertySetInfo.hasPropertyByName("IsFixedLanguage"));
3664 int def = (Integer) xPropertySet.getPropertyValue("NumberFormat");
3665 log.println("NumberFormat: default is " + def);
3666 short INT = com.sun.star.i18n.NumberFormatIndex.NUMBER_INT;
3667 xPropertySet.setPropertyValue("NumberFormat", INT);
3668 xPropertySet.setPropertyValue("IsFixedLanguage", true);
3669 int format = (Integer) xPropertySet.getPropertyValue("NumberFormat");
3670 assure("NumberFormat: failed", format == INT);
3671 boolean isFixed = (Boolean)
3672 xPropertySet.getPropertyValue("IsFixedLanguage");
3673 assure("IsFixedLanguage: failed", isFixed);
3676 public void testLoadStore() throws Exception
3678 XComponent xComp = null;
3679 String filename = "TESTMETA.odt";
3680 String file;
3681 try {
3682 file = util.utils.getFullTestURL(filename);
3683 xComp = doLoad(file);
3684 if (xComp != null)
3686 file = m_TmpDir + filename;
3687 doStore(xComp, file);
3688 close(xComp);
3689 xComp = doLoad(file);
3691 } finally {
3692 close(xComp);
3696 private void doStore(XComponent xComp, String file) throws Exception
3698 log.println("Storing test document...");
3700 XStorable xStor = (XStorable) UnoRuntime.queryInterface(
3701 XStorable.class, xComp);
3703 xStor.storeToURL(file, new PropertyValue[0]);
3705 log.println("...done");
3708 public XComponent doLoad(String file) throws Exception
3710 XComponent xComp = null;
3712 log.println("Loading test document...");
3714 PropertyValue[] loadProps = new PropertyValue[1];
3715 loadProps[0] = new PropertyValue();
3716 loadProps[0].Name = "Hidden";
3717 loadProps[0].Value = new Boolean(true);
3719 xComp = util.DesktopTools.loadDoc(m_xMSF, file, loadProps);
3720 // xComp = util.DesktopTools.getCLoader(m_xMSF).loadComponentFromURL(file, "_blank", 0, loadProps);
3723 XTextDocument xTextDoc = (XTextDocument)
3724 UnoRuntime.queryInterface(XTextDocument.class, xComp);
3726 XText xText = xTextDoc.getText();
3728 log.println("...done");
3730 log.println("Checking meta(-field)s in loaded test document...");
3732 TreeNode root = new TreeNode()
3733 .appendChild( new RubyNode("ruby1")
3734 .appendChild( new TextNode("1") ) )
3735 .appendChild( new MetaNode(mkId_("id1"))
3736 .appendChild( new TextNode("2") ) )
3737 .appendChild( new MetaFieldNode(mkId_("id2"))
3738 .appendChild( new TextNode("3") ) )
3739 .appendChild( new RubyNode("ruby2")
3740 .appendChild( new MetaNode(mkId_("id3"))
3741 .appendChild( new TextNode("4") ) ) )
3742 .appendChild( new RubyNode("ruby3")
3743 .appendChild( new MetaFieldNode(mkId_("id4"))
3744 .appendChild( new TextNode("5") ) ) )
3745 .appendChild( new MetaNode(mkId_("id5"))
3746 .appendChild( new RubyNode("ruby4")
3747 .appendChild( new TextNode("6") ) ) )
3748 .appendChild( new MetaFieldNode(mkId_("id6"))
3749 .appendChild( new RubyNode("ruby5")
3750 .appendChild( new TextNode("7") ) ) )
3751 .appendChild( new MetaNode(mkId_("id7"))
3752 .appendChild( new MetaNode(mkId_("id8"))
3753 .appendChild( new TextNode("8") ) ) )
3754 .appendChild( new MetaNode(mkId_("id9"))
3755 .appendChild( new MetaFieldNode(mkId_("id10"))
3756 .appendChild( new TextNode("9") ) ) )
3757 .appendChild( new MetaFieldNode(mkId_("id11"))
3758 .appendChild( new MetaNode(mkId_("id12"))
3759 .appendChild( new TextNode("10") ) ) )
3760 .appendChild( new MetaFieldNode(mkId_("id13"))
3761 .appendChild( new MetaFieldNode(mkId_("id14"))
3762 .appendChild( new TextNode("11") ) ) )
3763 .appendChild( new MetaNode(mkId_("id15"))
3764 .appendChild( new RubyNode("ruby6")
3765 .appendChild( new MetaFieldNode(mkId_("id16"))
3766 .appendChild( new TextNode("12") ) ) ) )
3767 .appendChild( new MetaNode(mkId_("")) {
3768 public boolean equals(Object other) {
3769 return (other instanceof MetaNode);
3771 .appendChild( new TextNode("13") ) )
3772 .appendChild( new TextNode(" X X ") );
3773 doTest(xTextDoc, root, false);
3775 log.println("...done");
3777 return xComp;
3780 static void close(XComponent i_comp)
3782 try {
3783 XCloseable xClos = (XCloseable) UnoRuntime.queryInterface(
3784 XCloseable.class, i_comp);
3785 if (xClos != null) xClos.close(true);
3786 } catch (Exception e) {
3790 private void doTest(TreeNode intree) throws Exception
3792 doTest(m_xDoc, intree, true);
3795 private void doTest(TreeNode intree, boolean insert) throws Exception
3797 doTest(m_xDoc, intree, insert);
3800 private void doTest(XTextDocument xDoc, TreeNode intree,
3801 boolean insert) throws Exception
3803 dumpTree(intree, "I: ");
3805 if (insert) {
3806 new TreeInserter(xDoc).insertTree(intree);
3809 //Thread.sleep(10000);
3811 XText xText = xDoc.getText();
3812 XEnumerationAccess xTextEA = (XEnumerationAccess)
3813 UnoRuntime.queryInterface(XEnumerationAccess.class, xText);
3814 XEnumeration xTextEnum = xTextEA.createEnumeration();
3815 // skip to right paragraph
3816 xTextEnum.nextElement(); // skip first -- always empty!
3817 Object xElement = xTextEnum.nextElement(); // second contains test case
3818 XEnumerationAccess xEA = (XEnumerationAccess)
3819 UnoRuntime.queryInterface(XEnumerationAccess.class, xElement);
3820 XEnumeration xEnum = xEA.createEnumeration();
3821 TreeNode outtree = new EnumConverter(this).convert(xEnum);
3823 dumpTree(outtree, "O: ");
3825 boolean success = new FuzzyTester(log).doTest(intree, outtree);
3826 assure("test failed", success);
3829 private void dumpTree(TreeNode tree) { dumpTree(tree, "> "); }
3831 private void dumpTree(TreeNode tree, String prefix)
3833 log.println(prefix + tree.toString());
3834 TreeNodeEnum children = tree.createEnumeration();
3835 while (children.hasNext()) {
3836 TreeNode node = children.next();
3837 dumpTree(node, prefix + " ");
3841 private String mkName(String prefix)
3843 return prefix + String.valueOf(m_Count++);
3846 private StringPair mkId(String prefix)
3848 return new StringPair("content.xml", mkName(prefix));
3851 private StringPair mkId_(String id)
3853 return new StringPair("content.xml", id);
3856 public void assure(String str, boolean cond) { super.assure(str, cond); }