assertTrue("DocumentStatistics:WordCount", containsNV(ds,
new NamedValue("WordCount", new Integer(23))));
assertTrue("DocumentStatistics:PageCount", containsNV(ds,
new NamedValue("PageCount", new Integer(1))));
XPropertyContainer udpc = xDP.getUserDefinedProperties();
XPropertySet udps = UnoRuntime.queryInterface( XPropertySet.class, udpc );
assertTrue("UserDefined 1", "Dies ist ein wichtiger Hinweis"
.equals(udps.getPropertyValue("Hinweis")));
assertTrue("UserDefined 2", ("Kann Spuren von N"
+ new String(new byte[] { (byte) 0xc3, (byte) 0xbc }, "UTF-8")
+ "ssen enthalten")
.equals(udps.getPropertyValue("Warnung")));
System.out.println("...done");
System.out.println("Checking meta-data updates...");
String str;
DateTime dt = new DateTime();
Locale l = new Locale();
int i;
str = "me";
xDP.setAuthor(str);
assertTrue("setAuthor", str.equals(xDP.getAuthor()));
str = "the computa";
xDP.setGenerator(str);
assertTrue("setGenerator", str.equals(xDP.getGenerator()));
dt.Year = 2038;
dt.Month = 1;
dt.Day = 1;
xDP.setCreationDate(dt);
assertTrue("setCreationDate", dt.Year == xDP.getCreationDate().Year);
str = "El t'itulo";
xDP.setTitle(str);
assertTrue("setTitle", str.equals(xDP.getTitle()));
str = "Ein verkommenes Subjekt";
xDP.setSubject(str);
assertTrue("setSubject", str.equals(xDP.getSubject()));
str = "Este descripci'on no es importante";
xDP.setDescription(str);
assertTrue("setDescription", str.equals(xDP.getDescription()));
l.Language = "en";
l.Country = "GB";
xDP.setLanguage(l);
Locale l2 = xDP.getLanguage();
assertTrue("setLanguage Lang", l.Language.equals(l2.Language));
assertTrue("setLanguage Cty", l.Country.equals(l2.Country));
str = "myself";
xDP.setModifiedBy(str);
assertTrue("setModifiedBy", str.equals(xDP.getModifiedBy()));
dt.Year = 2042;
xDP.setModificationDate(dt);
assertTrue("setModificationDate",
dt.Year == xDP.getModificationDate().Year);
str = "i didnt do it";
xDP.setPrintedBy(str);
assertTrue("setPrintedBy", str.equals(xDP.getPrintedBy()));
dt.Year = 2024;
xDP.setPrintDate(dt);
assertTrue("setPrintDate", dt.Year == xDP.getPrintDate().Year);
str = "blah";
xDP.setTemplateName(str);
assertTrue("setTemplateName", str.equals(xDP.getTemplateName()));
str = "gopher://some-hole-in-the-ground/";
xDP.setTemplateURL(str);
assertTrue("setTemplateURL", str.equals(xDP.getTemplateURL()));
dt.Year = 2043;
xDP.setTemplateDate(dt);
assertTrue("setTemplateDate", dt.Year == xDP.getTemplateDate().Year);
str = "http://nowhere/";
xDP.setAutoloadURL(str);
assertTrue("setAutoloadURL", str.equals(xDP.getAutoloadURL()));
i = 3661; // this might not work (due to conversion via double...)
xDP.setAutoloadSecs(i);
// System.out.println("set: " + i + " get: " + xDP.getAutoloadSecs());
assertTrue("setAutoloadSecs", i == xDP.getAutoloadSecs());
str = "_blank";
xDP.setDefaultTarget(str);
assertTrue("setDefaultTarget", str.equals(xDP.getDefaultTarget()));
i = 42;
xDP.setEditingCycles((short) i);
assertTrue("setEditingCycles", i == xDP.getEditingCycles());
i = 84;
xDP.setEditingDuration(i);
assertTrue("setEditingDuration", i == xDP.getEditingDuration());
str = "";
String[] kws2 = new String[] {
"keywordly", "keywordlike", "keywordalicious" };
xDP.setKeywords(kws2);
kws = xDP.getKeywords();
assertTrue("setKeywords", fromArray(kws).containsAll(fromArray(kws2)));
NamedValue[] ds2 = new NamedValue[] {
new NamedValue("SyllableCount", new Integer(9)),
new NamedValue("FrameCount", new Integer(2)),
new NamedValue("SentenceCount", new Integer(7)) };
xDP.setDocumentStatistics(ds2);
ds = xDP.getDocumentStatistics();
assertTrue("setDocumentStatistics:SyllableCount", containsNV(ds,
new NamedValue("SyllableCount", new Integer(9))));
assertTrue("setDocumentStatistics:FrameCount", containsNV(ds,
new NamedValue("FrameCount", new Integer(2))));
assertTrue("setDocumentStatistics:SentenceCount", containsNV(ds,
new NamedValue("SentenceCount", new Integer(7))));
System.out.println("...done");
System.out.println("Checking user-defined meta-data updates...");
// actually, this tests the PropertyBag service
// but maybe the DocumentProperties service will be implemented
// differently some day...
boolean b = true;
double d = 3.1415;
// note that Time is only supported for backward compatibilty!
Time t = new Time();
t.Hours = 1;
t.Minutes = 16;
Date date = new Date();
date.Year = 2071;
date.Month = 2;
date.Day = 3;
dt.Year = 2065;
Duration dur = new Duration();
dur.Negative = true;
dur.Years = 1001;
dur.Months = 999;
dur.Days = 888;
dur.Hours = 777;
dur.Minutes = 666;
dur.Seconds = 555;
dur.MilliSeconds = 444;
udpc.addProperty("Frobnicate", PropertyAttribute.REMOVEABLE, b);
udpc.addProperty("FrobDuration", PropertyAttribute.REMOVEABLE, dur);
udpc.addProperty("FrobDuration2", PropertyAttribute.REMOVEABLE, t);
udpc.addProperty("FrobEndDate", PropertyAttribute.REMOVEABLE, date);
udpc.addProperty("FrobStartTime", PropertyAttribute.REMOVEABLE, dt);
udpc.addProperty("Pi", PropertyAttribute.REMOVEABLE, new Double(d));
udpc.addProperty("Foo", PropertyAttribute.REMOVEABLE, "bar");
udpc.addProperty("Removed", PropertyAttribute.REMOVEABLE, "bar");
// #i94175#: empty property name is valid ODF 1.1
udpc.addProperty("", PropertyAttribute.REMOVEABLE, "eeeeek");
try {
udpc.removeProperty("Info 1");
udpc.removeProperty("Removed");
} catch (UnknownPropertyException e) {
fail("removeProperty failed");
}
try {
udpc.addProperty("Forbidden", PropertyAttribute.REMOVEABLE,
new String[] { "foo", "bar" });
fail("inserting value of non-supported type did not fail");
} catch (IllegalTypeException e) {
// ignore
}
assertTrue("UserDefined bool", new Boolean(b).equals(
udps.getPropertyValue("Frobnicate")));
assertTrue("UserDefined duration", eqDuration(dur, (Duration)
udps.getPropertyValue("FrobDuration")));
assertTrue("UserDefined time", eqTime(t, (Time)
udps.getPropertyValue("FrobDuration2")));
assertTrue("UserDefined date", eqDate(date, (Date)
udps.getPropertyValue("FrobEndDate")));
assertTrue("UserDefined datetime", eqDateTime(dt, (DateTime)
udps.getPropertyValue("FrobStartTime")));
assertTrue("UserDefined float", new Double(d).equals(
udps.getPropertyValue("Pi")));
assertTrue("UserDefined string", "bar".equals(
udps.getPropertyValue("Foo")));
assertTrue("UserDefined empty name", "eeeeek".equals(
udps.getPropertyValue("")));
try {
udps.getPropertyValue("Removed");
fail("UserDefined remove didn't");
} catch (UnknownPropertyException e) {
// ok
}
System.out.println("...done");
System.out.println("Checking storing meta-data to file...");
xDP.storeToMedium(temp + "TEST.odt", mimeArgs);
System.out.println("...done");
System.out.println("Checking loading meta-data from stored file...");
xDP.loadFromMedium(temp + "TEST.odt", noArgs);
System.out.println("...done");
System.out.println("Checking user-defined meta-data from stored file...");
udpc = xDP.getUserDefinedProperties();
udps = UnoRuntime.queryInterface( XPropertySet.class, udpc );
assertTrue("UserDefined bool", new Boolean(b).equals(
udps.getPropertyValue("Frobnicate")));
assertTrue("UserDefined duration", eqDuration(dur, (Duration)
udps.getPropertyValue("FrobDuration")));
// this is now a Duration!
Duration t_dur = new Duration(false, (short)0, (short)0, (short)0,
t.Hours, t.Minutes, t.Seconds,
(short)(10 * t.HundredthSeconds));
assertTrue("UserDefined time", eqDuration(t_dur, (Duration)
udps.getPropertyValue("FrobDuration2")));
assertTrue("UserDefined date", eqDate(date, (Date)
udps.getPropertyValue("FrobEndDate")));
assertTrue("UserDefined datetime", eqDateTime(dt, (DateTime)
udps.getPropertyValue("FrobStartTime")));
assertTrue("UserDefined float", new Double(d).equals(
udps.getPropertyValue("Pi")));
assertTrue("UserDefined string", "bar".equals(
udps.getPropertyValue("Foo")));
try {
udps.getPropertyValue("Removed");
fail("UserDefined remove didn't");
} catch (UnknownPropertyException e) {
// ok
}
System.out.println("...done");
System.out.println("Checking notification listener interface...");
Listener listener = new Listener();
XModifyBroadcaster xMB = UnoRuntime.queryInterface( XModifyBroadcaster.class, xDP );
xMB.addModifyListener(listener);
xDP.setAuthor("not me");
assertTrue("Listener Author", listener.reset());
udpc.addProperty("Listener", PropertyAttribute.REMOVEABLE, "foo");
assertTrue("Listener UserDefined Add", listener.reset());
udps.setPropertyValue("Listener", "bar");
assertTrue("Listener UserDefined Set", listener.reset());
udpc.removeProperty("Listener");
assertTrue("Listener UserDefined Remove", listener.reset());
xMB.removeModifyListener(listener);
udpc.addProperty("Listener2", PropertyAttribute.REMOVEABLE, "foo");
assertTrue("Removed Listener UserDefined Add", !listener.reset());
System.out.println("...done");
} catch (Exception e) {