MutableAttributeSet a2 = new SimpleAttributeSet();
a1.addAttribute(StyleConstants.NameAttribute, "MY_FIRST");
a2.addAttribute(StyleConstants.NameAttribute, "MY_SECOND");
ElementSpec s1 = new ElementSpec(a1, ElementSpec.ContentType,
"1".toCharArray(), 0, 1);
ElementSpec s2 = new ElementSpec(a2, ElementSpec.ContentType,
"2".toCharArray(), 0, 1);
OpenDocument d = new OpenDocument();
try
{
d.insert(0, new ElementSpec[] { s1, s2 });
harness.check(d.getLength(), 2, "Length");
harness.check("12", d.getText(0, d.getLength()));
Element[] e = d.getRootElements();
StringBuffer b = new StringBuffer();
for (int i = 0; i < e.length; i++)
{
dump(b, e[i]);
}
String r = b.toString();
// Both elements must be included somewhere. They positions must match.
harness.check(r.indexOf("MY_FIRST:0-1") >=0);
harness.check(r.indexOf("MY_SECOND:1-2") >=0);
// Insert the third element in between.
MutableAttributeSet a3 = new SimpleAttributeSet();
a1.addAttribute(StyleConstants.NameAttribute, "MY_MIDDLE");
ElementSpec sm = new ElementSpec(a1, ElementSpec.ContentType,
"m".toCharArray(), 0, 1);
d.insert(1, new ElementSpec[] { sm });
harness.check(d.getLength(), 3, "Length");
harness.check("1m2", d.getText(0, d.getLength()));