1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package fvt.uno.sw.paragraph; 23 24 import static org.junit.Assert.*; 25 26 import org.junit.After; 27 import org.junit.Before; 28 import org.junit.Ignore; 29 import org.junit.Test; 30 import org.openoffice.test.common.FileUtil; 31 import org.openoffice.test.common.Testspace; 32 import org.openoffice.test.uno.UnoApp; 33 34 import com.sun.star.style.NumberingType; 35 import com.sun.star.text.*; 36 import com.sun.star.beans.*; 37 import com.sun.star.container.XIndexAccess; 38 import com.sun.star.container.XIndexReplace; 39 import com.sun.star.frame.XStorable; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.uno.UnoRuntime; 42 43 public class ParagraphNumberingAndBullet_Numbering { 44 private static final UnoApp app = new UnoApp(); 45 XText xText = null; 46 47 @Before 48 public void setUp() throws Exception { 49 app.start(); 50 51 } 52 53 @After 54 public void tearDown() throws Exception { 55 app.close(); 56 } 57 /* 58 * test paragraph background color 59 * 1.new a text document 60 * 2.insert some text 61 * 3.set paragraph numbering and bullet with numbering 62 * 4.save and close the document 63 * 5.reload the saved document and check the paragraph numbering bullet 64 */ 65 @Test 66 public void testNumberingBullet_ARABIC() throws Exception { 67 68 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 69 xText = xTextDocument.getText(); 70 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!" + 71 "Hello,world!Hello,world!"); 72 //create cursor to select paragraph and formating paragraph 73 XTextCursor xTextCursor = xText.createTextCursor(); 74 //create paragraph property set 75 XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 76 //create document service factory 77 XMultiServiceFactory xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 78 //set numbering character 79 XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules")); 80 PropertyValue[] propsRule = {new PropertyValue()}; 81 propsRule[0].Name = "NumberingType"; 82 propsRule[0].Value = NumberingType.ARABIC; 83 XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 84 xReplaceRule.replaceByIndex(0, propsRule); 85 //set paragraph numbering and bullet character 86 xTextProps.setPropertyValue("NumberingRules", xNumRule); 87 //save to odt 88 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 89 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 90 aStoreProperties_odt[0] = new PropertyValue(); 91 aStoreProperties_odt[1] = new PropertyValue(); 92 aStoreProperties_odt[0].Name = "Override"; 93 aStoreProperties_odt[0].Value = true; 94 aStoreProperties_odt[1].Name = "FilterName"; 95 aStoreProperties_odt[1].Value = "writer8"; 96 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 97 //save to doc 98 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 99 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 100 aStoreProperties_doc[0] = new PropertyValue(); 101 aStoreProperties_doc[1] = new PropertyValue(); 102 aStoreProperties_doc[0].Name = "Override"; 103 aStoreProperties_doc[0].Value = true; 104 aStoreProperties_doc[1].Name = "FilterName"; 105 aStoreProperties_doc[1].Value = "MS Word 97"; 106 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 107 app.closeDocument(xTextDocument); 108 109 //reopen the document 110 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 111 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 112 XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 113 XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 114 PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 115 //verify paragraph numbering and bullet alignment 116 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name); 117 assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_odt[11].Value); 118 119 //reopen the document 120 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 121 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 122 XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 123 PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 124 //verify paragraph numbering and bullet alignment 125 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name); 126 assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_doc[11].Value); 127 } 128 @Test 129 public void testNumberingBullet_ARABIC_Suffix() throws Exception { 130 131 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 132 xText = xTextDocument.getText(); 133 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!" + 134 "Hello,world!Hello,world!"); 135 //create cursor to select paragraph and formating paragraph 136 XTextCursor xTextCursor = xText.createTextCursor(); 137 //create paragraph property set 138 XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 139 //create document service factory 140 XMultiServiceFactory xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 141 //set numbering character 142 XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules")); 143 PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue()}; 144 propsRule[0].Name = "NumberingType"; 145 propsRule[0].Value = NumberingType.ARABIC; 146 propsRule[1].Name = "Suffix"; 147 propsRule[1].Value = ")"; 148 XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 149 xReplaceRule.replaceByIndex(0, propsRule); 150 //set paragraph numbering and bullet character 151 xTextProps.setPropertyValue("NumberingRules", xNumRule); 152 //save to odt 153 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 154 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 155 aStoreProperties_odt[0] = new PropertyValue(); 156 aStoreProperties_odt[1] = new PropertyValue(); 157 aStoreProperties_odt[0].Name = "Override"; 158 aStoreProperties_odt[0].Value = true; 159 aStoreProperties_odt[1].Name = "FilterName"; 160 aStoreProperties_odt[1].Value = "writer8"; 161 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 162 //save to doc 163 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 164 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 165 aStoreProperties_doc[0] = new PropertyValue(); 166 aStoreProperties_doc[1] = new PropertyValue(); 167 aStoreProperties_doc[0].Name = "Override"; 168 aStoreProperties_doc[0].Value = true; 169 aStoreProperties_doc[1].Name = "FilterName"; 170 aStoreProperties_doc[1].Value = "MS Word 97"; 171 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 172 app.closeDocument(xTextDocument); 173 174 //reopen the document 175 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 176 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 177 XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 178 XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 179 PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 180 //verify paragraph numbering and bullet alignment 181 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name); 182 assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_odt[11].Value); 183 assertEquals("assert numbering and bullet","Suffix",propsRule_assert_odt[3].Name); 184 assertEquals("assert numbering and bullet",")",propsRule_assert_odt[3].Value); 185 186 //reopen the document 187 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 188 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 189 XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 190 PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 191 //verify paragraph numbering and bullet alignment 192 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name); 193 assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_doc[11].Value); 194 assertEquals("assert numbering and bullet","Suffix",propsRule_assert_doc[3].Name); 195 assertEquals("assert numbering and bullet",")",propsRule_assert_doc[3].Value); 196 } 197 @Test 198 public void testNumberingBullet_ARABIC_Preffix_Suffix() throws Exception { 199 200 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 201 xText = xTextDocument.getText(); 202 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!" + 203 "Hello,world!Hello,world!"); 204 //create cursor to select paragraph and formating paragraph 205 XTextCursor xTextCursor = xText.createTextCursor(); 206 //create paragraph property set 207 XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 208 //create document service factory 209 XMultiServiceFactory xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 210 //set numbering character 211 XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules")); 212 PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue(),new PropertyValue()}; 213 propsRule[0].Name = "NumberingType"; 214 propsRule[0].Value = NumberingType.ARABIC; 215 propsRule[1].Name = "Suffix"; 216 propsRule[1].Value = ")"; 217 propsRule[2].Name = "Prefix"; 218 propsRule[2].Value = "("; 219 XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 220 xReplaceRule.replaceByIndex(0, propsRule); 221 //set paragraph numbering and bullet character 222 xTextProps.setPropertyValue("NumberingRules", xNumRule); 223 //save to odt 224 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 225 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 226 aStoreProperties_odt[0] = new PropertyValue(); 227 aStoreProperties_odt[1] = new PropertyValue(); 228 aStoreProperties_odt[0].Name = "Override"; 229 aStoreProperties_odt[0].Value = true; 230 aStoreProperties_odt[1].Name = "FilterName"; 231 aStoreProperties_odt[1].Value = "writer8"; 232 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 233 //save to doc 234 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 235 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 236 aStoreProperties_doc[0] = new PropertyValue(); 237 aStoreProperties_doc[1] = new PropertyValue(); 238 aStoreProperties_doc[0].Name = "Override"; 239 aStoreProperties_doc[0].Value = true; 240 aStoreProperties_doc[1].Name = "FilterName"; 241 aStoreProperties_doc[1].Value = "MS Word 97"; 242 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 243 app.closeDocument(xTextDocument); 244 245 //reopen the document 246 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 247 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 248 XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 249 XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 250 PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 251 //verify paragraph numbering and bullet alignment 252 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name); 253 assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_odt[11].Value); 254 assertEquals("assert numbering and bullet","Suffix",propsRule_assert_odt[3].Name); 255 assertEquals("assert numbering and bullet",")",propsRule_assert_odt[3].Value); 256 assertEquals("assert numbering and bullet","Prefix",propsRule_assert_odt[2].Name); 257 assertEquals("assert numbering and bullet","(",propsRule_assert_odt[2].Value); 258 259 //reopen the document 260 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 261 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 262 XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 263 PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 264 //verify paragraph numbering and bullet alignment 265 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name); 266 assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_doc[11].Value); 267 assertEquals("assert numbering and bullet","Suffix",propsRule_assert_doc[3].Name); 268 assertEquals("assert numbering and bullet",")",propsRule_assert_doc[3].Value); 269 assertEquals("assert numbering and bullet","Prefix",propsRule_assert_odt[2].Name); 270 assertEquals("assert numbering and bullet","(",propsRule_assert_odt[2].Value); 271 } 272 @Test 273 public void testNumberingBullet_ROMAN_LOWER() throws Exception { 274 275 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 276 xText = xTextDocument.getText(); 277 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!" + 278 "Hello,world!Hello,world!"); 279 //create cursor to select paragraph and formating paragraph 280 XTextCursor xTextCursor = xText.createTextCursor(); 281 //create paragraph property set 282 XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 283 //create document service factory 284 XMultiServiceFactory xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 285 //set numbering character 286 XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules")); 287 PropertyValue[] propsRule = {new PropertyValue()}; 288 propsRule[0].Name = "NumberingType"; 289 propsRule[0].Value = NumberingType.ROMAN_LOWER; 290 XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 291 xReplaceRule.replaceByIndex(0, propsRule); 292 //set paragraph numbering and bullet character 293 xTextProps.setPropertyValue("NumberingRules", xNumRule); 294 //save to odt 295 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 296 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 297 aStoreProperties_odt[0] = new PropertyValue(); 298 aStoreProperties_odt[1] = new PropertyValue(); 299 aStoreProperties_odt[0].Name = "Override"; 300 aStoreProperties_odt[0].Value = true; 301 aStoreProperties_odt[1].Name = "FilterName"; 302 aStoreProperties_odt[1].Value = "writer8"; 303 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 304 //save to doc 305 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 306 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 307 aStoreProperties_doc[0] = new PropertyValue(); 308 aStoreProperties_doc[1] = new PropertyValue(); 309 aStoreProperties_doc[0].Name = "Override"; 310 aStoreProperties_doc[0].Value = true; 311 aStoreProperties_doc[1].Name = "FilterName"; 312 aStoreProperties_doc[1].Value = "MS Word 97"; 313 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 314 app.closeDocument(xTextDocument); 315 316 //reopen the document 317 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 318 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 319 XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 320 XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 321 PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 322 //verify paragraph numbering and bullet alignment 323 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name); 324 assertEquals("assert numbering and bullet",NumberingType.ROMAN_LOWER,propsRule_assert_odt[11].Value); 325 326 //reopen the document 327 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 328 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 329 XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 330 PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 331 //verify paragraph numbering and bullet alignment 332 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name); 333 assertEquals("assert numbering and bullet",NumberingType.ROMAN_LOWER,propsRule_assert_doc[11].Value); 334 } 335 @Test 336 public void testNumberingBullet_ROMAN_UPPER() throws Exception { 337 338 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 339 xText = xTextDocument.getText(); 340 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!" + 341 "Hello,world!Hello,world!"); 342 //create cursor to select paragraph and formating paragraph 343 XTextCursor xTextCursor = xText.createTextCursor(); 344 //create paragraph property set 345 XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 346 //create document service factory 347 XMultiServiceFactory xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 348 //set numbering character 349 XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules")); 350 PropertyValue[] propsRule = {new PropertyValue()}; 351 propsRule[0].Name = "NumberingType"; 352 propsRule[0].Value = NumberingType.ROMAN_UPPER; 353 XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 354 xReplaceRule.replaceByIndex(0, propsRule); 355 //set paragraph numbering and bullet character 356 xTextProps.setPropertyValue("NumberingRules", xNumRule); 357 //save to odt 358 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 359 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 360 aStoreProperties_odt[0] = new PropertyValue(); 361 aStoreProperties_odt[1] = new PropertyValue(); 362 aStoreProperties_odt[0].Name = "Override"; 363 aStoreProperties_odt[0].Value = true; 364 aStoreProperties_odt[1].Name = "FilterName"; 365 aStoreProperties_odt[1].Value = "writer8"; 366 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 367 //save to doc 368 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 369 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 370 aStoreProperties_doc[0] = new PropertyValue(); 371 aStoreProperties_doc[1] = new PropertyValue(); 372 aStoreProperties_doc[0].Name = "Override"; 373 aStoreProperties_doc[0].Value = true; 374 aStoreProperties_doc[1].Name = "FilterName"; 375 aStoreProperties_doc[1].Value = "MS Word 97"; 376 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 377 app.closeDocument(xTextDocument); 378 379 //reopen the document 380 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 381 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 382 XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 383 XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 384 PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 385 //verify paragraph numbering and bullet alignment 386 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name); 387 assertEquals("assert numbering and bullet",NumberingType.ROMAN_UPPER,propsRule_assert_odt[11].Value); 388 389 //reopen the document 390 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 391 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 392 XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 393 PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 394 //verify paragraph numbering and bullet alignment 395 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name); 396 assertEquals("assert numbering and bullet",NumberingType.ROMAN_UPPER,propsRule_assert_doc[11].Value); 397 } 398 @Test@Ignore("Bug #120826 - [testUNO patch]A,B,C numbering bullet will change to A,AA,AAA when save to doc.") 399 public void testNumberingBullet_CHARS_UPPER_LETTER() throws Exception { 400 401 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 402 xText = xTextDocument.getText(); 403 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!" + 404 "Hello,world!Hello,world!"); 405 //create cursor to select paragraph and formating paragraph 406 XTextCursor xTextCursor = xText.createTextCursor(); 407 //create paragraph property set 408 XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 409 //create document service factory 410 XMultiServiceFactory xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 411 //set numbering character 412 XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules")); 413 PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue()}; 414 propsRule[0].Name = "NumberingType"; 415 propsRule[0].Value = NumberingType.CHARS_UPPER_LETTER; 416 propsRule[1].Name = "Suffix"; 417 propsRule[1].Value = ")"; 418 XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 419 xReplaceRule.replaceByIndex(0, propsRule); 420 //set paragraph numbering and bullet character 421 xTextProps.setPropertyValue("NumberingRules", xNumRule); 422 //save to odt 423 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 424 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 425 aStoreProperties_odt[0] = new PropertyValue(); 426 aStoreProperties_odt[1] = new PropertyValue(); 427 aStoreProperties_odt[0].Name = "Override"; 428 aStoreProperties_odt[0].Value = true; 429 aStoreProperties_odt[1].Name = "FilterName"; 430 aStoreProperties_odt[1].Value = "writer8"; 431 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 432 //save to doc 433 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 434 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 435 aStoreProperties_doc[0] = new PropertyValue(); 436 aStoreProperties_doc[1] = new PropertyValue(); 437 aStoreProperties_doc[0].Name = "Override"; 438 aStoreProperties_doc[0].Value = true; 439 aStoreProperties_doc[1].Name = "FilterName"; 440 aStoreProperties_doc[1].Value = "MS Word 97"; 441 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 442 app.closeDocument(xTextDocument); 443 444 //reopen the document 445 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 446 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 447 XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 448 XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 449 PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 450 //verify paragraph numbering and bullet alignment 451 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name); 452 assertEquals("assert numbering and bullet",NumberingType.CHARS_UPPER_LETTER,propsRule_assert_odt[11].Value); 453 assertEquals("assert numbering and bullet","Suffix",propsRule_assert_odt[3].Name); 454 assertEquals("assert numbering and bullet",")",propsRule_assert_odt[3].Value); 455 456 //reopen the document 457 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 458 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 459 XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 460 PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 461 //verify paragraph numbering and bullet alignment 462 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name); 463 assertEquals("assert numbering and bullet",NumberingType.CHARS_UPPER_LETTER,propsRule_assert_doc[11].Value); 464 assertEquals("assert numbering and bullet","Suffix",propsRule_assert_doc[3].Name); 465 assertEquals("assert numbering and bullet",")",propsRule_assert_doc[3].Value); 466 } 467 @Test@Ignore("Bug #120826 - [testUNO patch]A,B,C numbering bullet will change to A,AA,AAA when save to doc.") 468 public void testNumberingBullet_CHARS_LOWER_LETTER_Suffix() throws Exception { 469 470 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 471 xText = xTextDocument.getText(); 472 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!" + 473 "Hello,world!Hello,world!"); 474 //create cursor to select paragraph and formating paragraph 475 XTextCursor xTextCursor = xText.createTextCursor(); 476 //create paragraph property set 477 XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 478 //create document service factory 479 XMultiServiceFactory xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 480 //set numbering character 481 XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules")); 482 PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue()}; 483 propsRule[0].Name = "NumberingType"; 484 propsRule[0].Value = NumberingType.CHARS_LOWER_LETTER; 485 propsRule[1].Name = "Suffix"; 486 propsRule[1].Value = ")"; 487 XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 488 xReplaceRule.replaceByIndex(0, propsRule); 489 //set paragraph numbering and bullet character 490 xTextProps.setPropertyValue("NumberingRules", xNumRule); 491 //save to odt 492 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 493 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 494 aStoreProperties_odt[0] = new PropertyValue(); 495 aStoreProperties_odt[1] = new PropertyValue(); 496 aStoreProperties_odt[0].Name = "Override"; 497 aStoreProperties_odt[0].Value = true; 498 aStoreProperties_odt[1].Name = "FilterName"; 499 aStoreProperties_odt[1].Value = "writer8"; 500 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 501 //save to doc 502 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 503 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 504 aStoreProperties_doc[0] = new PropertyValue(); 505 aStoreProperties_doc[1] = new PropertyValue(); 506 aStoreProperties_doc[0].Name = "Override"; 507 aStoreProperties_doc[0].Value = true; 508 aStoreProperties_doc[1].Name = "FilterName"; 509 aStoreProperties_doc[1].Value = "MS Word 97"; 510 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 511 app.closeDocument(xTextDocument); 512 513 //reopen the document 514 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 515 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 516 XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 517 XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 518 PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 519 //verify paragraph numbering and bullet alignment 520 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name); 521 assertEquals("assert numbering and bullet",NumberingType.CHARS_LOWER_LETTER,propsRule_assert_odt[11].Value); 522 assertEquals("assert numbering and bullet","Suffix",propsRule_assert_odt[3].Name); 523 assertEquals("assert numbering and bullet",")",propsRule_assert_odt[3].Value); 524 525 //reopen the document 526 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 527 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 528 XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 529 PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 530 //verify paragraph numbering and bullet alignment 531 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name); 532 assertEquals("assert numbering and bullet",NumberingType.CHARS_LOWER_LETTER,propsRule_assert_doc[11].Value); 533 assertEquals("assert numbering and bullet","Suffix",propsRule_assert_doc[3].Name); 534 assertEquals("assert numbering and bullet",")",propsRule_assert_doc[3].Value); 535 } 536 @Test@Ignore("Bug #120826 - [testUNO patch]A,B,C numbering bullet will change to A,AA,AAA when save to doc.") 537 public void testNumberingBullet_CHARS_LOWER_LETTER_Suffix_Prefix() throws Exception { 538 539 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 540 xText = xTextDocument.getText(); 541 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!" + 542 "Hello,world!Hello,world!"); 543 //create cursor to select paragraph and formating paragraph 544 XTextCursor xTextCursor = xText.createTextCursor(); 545 //create paragraph property set 546 XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 547 //create document service factory 548 XMultiServiceFactory xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 549 //set numbering character 550 XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules")); 551 PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue(),new PropertyValue()}; 552 propsRule[0].Name = "NumberingType"; 553 propsRule[0].Value = NumberingType.CHARS_LOWER_LETTER; 554 propsRule[1].Name = "Suffix"; 555 propsRule[1].Value = ")"; 556 propsRule[2].Name = "Prefix"; 557 propsRule[2].Value = "("; 558 XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 559 xReplaceRule.replaceByIndex(0, propsRule); 560 //set paragraph numbering and bullet character 561 xTextProps.setPropertyValue("NumberingRules", xNumRule); 562 //save to odt 563 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 564 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 565 aStoreProperties_odt[0] = new PropertyValue(); 566 aStoreProperties_odt[1] = new PropertyValue(); 567 aStoreProperties_odt[0].Name = "Override"; 568 aStoreProperties_odt[0].Value = true; 569 aStoreProperties_odt[1].Name = "FilterName"; 570 aStoreProperties_odt[1].Value = "writer8"; 571 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 572 //save to doc 573 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 574 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 575 aStoreProperties_doc[0] = new PropertyValue(); 576 aStoreProperties_doc[1] = new PropertyValue(); 577 aStoreProperties_doc[0].Name = "Override"; 578 aStoreProperties_doc[0].Value = true; 579 aStoreProperties_doc[1].Name = "FilterName"; 580 aStoreProperties_doc[1].Value = "MS Word 97"; 581 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 582 app.closeDocument(xTextDocument); 583 584 //reopen the document 585 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 586 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 587 XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 588 XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 589 PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 590 //verify paragraph numbering and bullet alignment 591 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name); 592 assertEquals("assert numbering and bullet",NumberingType.CHARS_LOWER_LETTER,propsRule_assert_odt[11].Value); 593 assertEquals("assert numbering and bullet","Suffix",propsRule_assert_odt[3].Name); 594 assertEquals("assert numbering and bullet",")",propsRule_assert_odt[3].Value); 595 assertEquals("assert numbering and bullet","Prefix",propsRule_assert_odt[2].Name); 596 assertEquals("assert numbering and bullet","(",propsRule_assert_odt[2].Value); 597 598 //reopen the document 599 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 600 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 601 XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 602 PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 603 //verify paragraph numbering and bullet alignment 604 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name); 605 assertEquals("assert numbering and bullet",NumberingType.CHARS_LOWER_LETTER,propsRule_assert_doc[11].Value); 606 assertEquals("assert numbering and bullet","Suffix",propsRule_assert_doc[3].Name); 607 assertEquals("assert numbering and bullet",")",propsRule_assert_doc[3].Value); 608 assertEquals("assert numbering and bullet","Prefix",propsRule_assert_doc[2].Name); 609 assertEquals("assert numbering and bullet","(",propsRule_assert_doc[2].Value); 610 } 611 } 612