assure ("DocumentStatistics:WordCount", containsNV(ds,
new NamedValue("WordCount", new Integer(23))));
assure ("DocumentStatistics:PageCount", containsNV(ds,
new NamedValue("PageCount", new Integer(1))));
XPropertyContainer udpc = xDP.getUserDefinedProperties();
XPropertySet udps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, udpc);
assure ("UserDefined 1", "Dies ist ein wichtiger Hinweis"
.equals(udps.getPropertyValue("Hinweis")));
assure ("UserDefined 2", ("Kann Spuren von N"
+ new String(new byte[] { (byte) 0xc3, (byte) 0xbc }, "UTF-8")
+ "ssen enthalten")
.equals(udps.getPropertyValue("Warnung")));
log.println("...done");
log.println("Checking meta-data updates...");
String str;
DateTime dt = new DateTime();
Locale l = new Locale();
int i;
str = "me";
xDP.setAuthor(str);
assure ("setAuthor", str.equals(xDP.getAuthor()));
str = "the computa";
xDP.setGenerator(str);
assure ("setGenerator", str.equals(xDP.getGenerator()));
dt.Year = 2038;
dt.Month = 1;
dt.Day = 1;
xDP.setCreationDate(dt);
assure ("setCreationDate", dt.Year == xDP.getCreationDate().Year);
str = "El t'itulo";
xDP.setTitle(str);
assure ("setTitle", str.equals(xDP.getTitle()));
str = "Ein verkommenes Subjekt";
xDP.setSubject(str);
assure ("setSubject", str.equals(xDP.getSubject()));
str = "Este descripci'on no es importante";
xDP.setDescription(str);
assure ("setDescription", str.equals(xDP.getDescription()));
l.Language = "en";
l.Country = "GB";
xDP.setLanguage(l);
Locale l2 = xDP.getLanguage();
assure ("setLanguage Lang", l.Language.equals(l2.Language));
assure ("setLanguage Cty", l.Country.equals(l2.Country));
str = "myself";
xDP.setModifiedBy(str);
assure ("setModifiedBy", str.equals(xDP.getModifiedBy()));
dt.Year = 2042;
xDP.setModificationDate(dt);
assure ("setModificationDate",
dt.Year == xDP.getModificationDate().Year);
str = "i didnt do it";
xDP.setPrintedBy(str);
assure ("setPrintedBy", str.equals(xDP.getPrintedBy()));
dt.Year = 2024;
xDP.setPrintDate(dt);
assure ("setPrintDate", dt.Year == xDP.getPrintDate().Year);
str = "blah";
xDP.setTemplateName(str);
assure ("setTemplateName", str.equals(xDP.getTemplateName()));
str = "gopher://some-hole-in-the-ground/";
xDP.setTemplateURL(str);
assure ("setTemplateURL", str.equals(xDP.getTemplateURL()));
dt.Year = 2043;
xDP.setTemplateDate(dt);
assure ("setTemplateDate", dt.Year == xDP.getTemplateDate().Year);
str = "http://nowhere/";
xDP.setAutoloadURL(str);
assure ("setAutoloadURL", str.equals(xDP.getAutoloadURL()));
i = 3661; // this might not work (due to conversion via double...)
xDP.setAutoloadSecs(i);
// log.println("set: " + i + " get: " + xDP.getAutoloadSecs());
assure ("setAutoloadSecs", i == xDP.getAutoloadSecs());
str = "_blank";
xDP.setDefaultTarget(str);
assure ("setDefaultTarget", str.equals(xDP.getDefaultTarget()));
i = 42;
xDP.setEditingCycles((short) i);
assure ("setEditingCycles", i == xDP.getEditingCycles());
i = 84;
xDP.setEditingDuration(i);
assure ("setEditingDuration", i == xDP.getEditingDuration());
str = "";
String[] kws2 = new String[] {
"keywordly", "keywordlike", "keywordalicious" };
xDP.setKeywords(kws2);
kws = xDP.getKeywords();
assure ("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();
assure ("setDocumentStatistics:SyllableCount", containsNV(ds,
new NamedValue("SyllableCount", new Integer(9))));
assure ("setDocumentStatistics:FrameCount", containsNV(ds,
new NamedValue("FrameCount", new Integer(2))));
assure ("setDocumentStatistics:SentenceCount", containsNV(ds,
new NamedValue("SentenceCount", new Integer(7))));
log.println("...done");
log.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,
new Boolean(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) {
assure("removeProperty failed", false);
}
try {
udpc.addProperty("Forbidden", PropertyAttribute.REMOVEABLE,
new String[] { "foo", "bar" });
assure("inserting value of non-supported type did not fail",
false);
} catch (IllegalTypeException e) {
// ignore
}
assure ("UserDefined bool", new Boolean(b).equals(
udps.getPropertyValue("Frobnicate")));
assure ("UserDefined duration", eqDuration(dur, (Duration)
udps.getPropertyValue("FrobDuration")));
assure ("UserDefined time", eqTime(t, (Time)
udps.getPropertyValue("FrobDuration2")));
assure ("UserDefined date", eqDate(date, (Date)
udps.getPropertyValue("FrobEndDate")));
assure ("UserDefined datetime", eqDateTime(dt, (DateTime)
udps.getPropertyValue("FrobStartTime")));
assure ("UserDefined float", new Double(d).equals(
udps.getPropertyValue("Pi")));
assure ("UserDefined string", "bar".equals(
udps.getPropertyValue("Foo")));
assure ("UserDefined empty name", "eeeeek".equals(
udps.getPropertyValue("")));
try {
udps.getPropertyValue("Removed");
assure("UserDefined remove didn't", false);
} catch (UnknownPropertyException e) {
// ok
}
log.println("...done");
log.println("Checking storing meta-data to file...");
xDP.storeToMedium(temp + "TEST.odt", mimeArgs);
log.println("...done");
log.println("Checking loading meta-data from stored file...");
xDP.loadFromMedium(temp + "TEST.odt", noArgs);
log.println("...done");
log.println("Checking user-defined meta-data from stored file...");
udpc = xDP.getUserDefinedProperties();
udps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, udpc);
assure ("UserDefined bool", new Boolean(b).equals(
udps.getPropertyValue("Frobnicate")));
assure ("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));
assure ("UserDefined time", eqDuration(t_dur, (Duration)
udps.getPropertyValue("FrobDuration2")));
assure ("UserDefined date", eqDate(date, (Date)
udps.getPropertyValue("FrobEndDate")));
assure ("UserDefined datetime", eqDateTime(dt, (DateTime)
udps.getPropertyValue("FrobStartTime")));
assure ("UserDefined float", new Double(d).equals(
udps.getPropertyValue("Pi")));
assure ("UserDefined string", "bar".equals(
udps.getPropertyValue("Foo")));
try {
udps.getPropertyValue("Removed");
assure("UserDefined remove didn't", false);
} catch (UnknownPropertyException e) {
// ok
}
log.println("...done");
log.println("Checking notification listener interface...");
Listener listener = new Listener();
XModifyBroadcaster xMB = (XModifyBroadcaster)
UnoRuntime.queryInterface(XModifyBroadcaster.class, xDP);
xMB.addModifyListener(listener);
xDP.setAuthor("not me");
assure ("Listener Author", listener.reset());
udpc.addProperty("Listener", PropertyAttribute.REMOVEABLE, "foo");
assure ("Listener UserDefined Add", listener.reset());
udps.setPropertyValue("Listener", "bar");
assure ("Listener UserDefined Set", listener.reset());
udpc.removeProperty("Listener");
assure ("Listener UserDefined Remove", listener.reset());
xMB.removeModifyListener(listener);
udpc.addProperty("Listener2", PropertyAttribute.REMOVEABLE, "foo");
assure ("Removed Listener UserDefined Add", !listener.reset());
log.println("...done");
} catch (Exception e) {