1 package fvt.uno.sw.paragraph; 2 3 import static org.junit.Assert.*; 4 5 import org.junit.After; 6 import org.junit.Before; 7 import org.junit.Test; 8 import org.openoffice.test.common.FileUtil; 9 import org.openoffice.test.common.Testspace; 10 import org.openoffice.test.uno.UnoApp; 11 12 import com.sun.star.text.*; 13 import com.sun.star.beans.*; 14 import com.sun.star.container.XIndexAccess; 15 import com.sun.star.container.XIndexReplace; 16 import com.sun.star.frame.XStorable; 17 import com.sun.star.lang.XMultiServiceFactory; 18 import com.sun.star.uno.UnoRuntime; 19 20 public class ParagraphNumberingAndBulletTabStop { 21 private static final UnoApp app = new UnoApp(); 22 XText xText = null; 23 24 @Before 25 public void setUp() throws Exception { 26 app.start(); 27 28 } 29 30 @After 31 public void tearDown() throws Exception { 32 app.close(); 33 } 34 /* 35 * test paragraph background color 36 * 1.new a text document 37 * 2.insert some text 38 * 3.set paragraph numbering tab stop position 39 * 4.save and close the document 40 * 5.reload the saved document and check the paragraph numbering tab stop position 41 */ 42 @Test 43 public void testNumberingBulletTabStop() throws Exception { 44 45 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 46 xText = xTextDocument.getText(); 47 xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!" + 48 "Hello,world!Hello,world!"); 49 //create cursor to select paragraph and formating paragraph 50 XTextCursor xTextCursor = xText.createTextCursor(); 51 //create paragraph property set 52 XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 53 //create document service factory 54 XMultiServiceFactory xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 55 //set numbering character 56 XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules")); 57 PropertyValue[] propsRule = {new PropertyValue()}; 58 propsRule[0].Name = "ListtabStopPosition"; 59 propsRule[0].Value = 5001; 60 XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 61 xReplaceRule.replaceByIndex(0, propsRule); 62 //set paragraph numbering and bullet character 63 xTextProps.setPropertyValue("NumberingRules", xNumRule); 64 //save to odt 65 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 66 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 67 aStoreProperties_odt[0] = new PropertyValue(); 68 aStoreProperties_odt[1] = new PropertyValue(); 69 aStoreProperties_odt[0].Name = "Override"; 70 aStoreProperties_odt[0].Value = true; 71 aStoreProperties_odt[1].Name = "FilterName"; 72 aStoreProperties_odt[1].Value = "writer8"; 73 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 74 //save to doc 75 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 76 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 77 aStoreProperties_doc[0] = new PropertyValue(); 78 aStoreProperties_doc[1] = new PropertyValue(); 79 aStoreProperties_doc[0].Name = "Override"; 80 aStoreProperties_doc[0].Value = true; 81 aStoreProperties_doc[1].Name = "FilterName"; 82 aStoreProperties_doc[1].Value = "MS Word 97"; 83 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 84 app.closeDocument(xTextDocument); 85 86 //reopen the document 87 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 88 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 89 XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 90 XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 91 PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 92 //verify paragraph numbering and bullet alignment 93 assertEquals("assert numbering and bullet","ListtabStopPosition",propsRule_assert_odt[8].Name); 94 assertEquals("assert numbering and bullet",5001,propsRule_assert_odt[8].Value); 95 96 //reopen the document 97 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 98 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 99 XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 100 PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 101 //verify paragraph numbering and bullet alignment 102 assertEquals("assert numbering and bullet","ListtabStopPosition",propsRule_assert_doc[8].Name); 103 assertEquals("assert numbering and bullet",5001,propsRule_assert_doc[8].Value); 104 } 105 } 106