Kaydet (Commit) 156862e0 authored tarafından Liu Zhe's avatar Liu Zhe

#120603# - [testuno]Test Create and Load Date and Time Field in Writer by UNO

Patch by: Zong Dong Jun <zongdj001@gmail.com>
Review by: Liu Zhe <aliuzhe@gmail.com>
üst 7eab7876
...@@ -84,7 +84,7 @@ public class UnoApp { ...@@ -84,7 +84,7 @@ public class UnoApp {
SystemUtil.sleep(2); SystemUtil.sleep(2);
} }
throw new RuntimeException("OpenOffice can be connected!"); throw new RuntimeException("OpenOffice can't be connected!");
} }
private Timer timer = new Timer(true); private Timer timer = new Timer(true);
...@@ -145,6 +145,12 @@ public class UnoApp { ...@@ -145,6 +145,12 @@ public class UnoApp {
return componentLoader.loadComponentFromURL(FileUtil.getUrl(file), "_blank", 0, new PropertyValue[0]); return componentLoader.loadComponentFromURL(FileUtil.getUrl(file), "_blank", 0, new PropertyValue[0]);
} }
public XComponent loadDocumentFromURL(String url) throws Exception {
XComponentLoader componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktop);
return componentLoader.loadComponentFromURL(url, "_blank", 0, new PropertyValue[0]);
}
public XComponent newDocument(String type) throws Exception { public XComponent newDocument(String type) throws Exception {
XComponentLoader componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktop); XComponentLoader componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktop);
return componentLoader.loadComponentFromURL("private:factory/" + type, "_blank", 0, new PropertyValue[0]); return componentLoader.loadComponentFromURL("private:factory/" + type, "_blank", 0, new PropertyValue[0]);
......
package testlib.uno.sw;
import org.openoffice.test.uno.UnoApp;
import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.XStorable;
import com.sun.star.io.IOException;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime;
public class SWUtil {
private static final UnoApp app = new UnoApp();
public static void saveAsDoc(XTextDocument document, String url) {
saveAs(document, "MS Word 97", url);
}
public static void saveAsODT(XTextDocument document, String url) {
saveAs(document, "writer8", url);
}
public static void saveAs(XTextDocument document, String filterValue, String url) {
XStorable store = UnoRuntime.queryInterface(XStorable.class, document);
PropertyValue[] propsValue = new PropertyValue[1];
propsValue[0] = new PropertyValue();
propsValue[0].Name = "FilterName";
propsValue[0].Value = filterValue;
try {
store.storeAsURL(url, propsValue);
} catch (IOException e) {
e.printStackTrace();
}
}
public static XTextDocument newDocument() {
try {
return (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment