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.Test; 29 import org.openoffice.test.common.FileUtil; 30 import org.openoffice.test.common.Testspace; 31 import org.openoffice.test.uno.UnoApp; 32 33 import com.sun.star.style.NumberingType; 34 import com.sun.star.text.*; 35 import com.sun.star.beans.*; 36 import com.sun.star.container.XIndexAccess; 37 import com.sun.star.container.XIndexReplace; 38 import com.sun.star.frame.XStorable; 39 import com.sun.star.lang.XMultiServiceFactory; 40 import com.sun.star.uno.UnoRuntime; 41 42 public class ParagraphNumberingAndBulletAlignment { 43 private static final UnoApp app = new UnoApp(); 44 XText xText = null; 45 46 @Before setUp()47 public void setUp() throws Exception { 48 app.start(); 49 50 } 51 52 @After tearDown()53 public void tearDown() throws Exception { 54 app.close(); 55 } 56 /* 57 * test paragraph background color 58 * 1.new a text document 59 * 2.insert some text 60 * 3.set paragraph numbering alignment 61 * 4.save and close the document 62 * 5.reload the saved document and check the paragraph numbering alignment 63 */ 64 @Test testNumberingBulletAlign_Right()65 public void testNumberingBulletAlign_Right() throws Exception { 66 67 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 68 xText = xTextDocument.getText(); 69 xText.setString("we are Chinese,they are American.\nwe are all living in one earth!\nHello,world!Hello,world!Hello,world!\nHello,world!Hello,world!Hello,world!" + 70 "Hello,world!Hello,world!"); 71 //create cursor to select paragraph and formatting paragraph 72 XTextCursor xTextCursor = xText.createTextCursor(); 73 //create paragraph property set 74 XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 75 //create document service factory 76 XMultiServiceFactory xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 77 //set numbering character 78 XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules")); 79 PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue()}; 80 propsRule[1].Name = "NumberingType"; 81 propsRule[1].Value = NumberingType.ARABIC; 82 propsRule[0].Name = "Adjust"; 83 propsRule[0].Value = HoriOrientation.RIGHT; 84 XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 85 xReplaceRule.replaceByIndex(0, propsRule); 86 //set paragraph numbering and bullet character 87 xTextProps.setPropertyValue("NumberingRules", xNumRule); 88 //save to odt 89 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 90 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 91 aStoreProperties_odt[0] = new PropertyValue(); 92 aStoreProperties_odt[1] = new PropertyValue(); 93 aStoreProperties_odt[0].Name = "Override"; 94 aStoreProperties_odt[0].Value = true; 95 aStoreProperties_odt[1].Name = "FilterName"; 96 aStoreProperties_odt[1].Value = "writer8"; 97 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 98 //save to doc 99 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 100 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 101 aStoreProperties_doc[0] = new PropertyValue(); 102 aStoreProperties_doc[1] = new PropertyValue(); 103 aStoreProperties_doc[0].Name = "Override"; 104 aStoreProperties_doc[0].Value = true; 105 aStoreProperties_doc[1].Name = "FilterName"; 106 aStoreProperties_doc[1].Value = "MS Word 97"; 107 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 108 app.closeDocument(xTextDocument); 109 110 //reopen the document 111 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 112 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 113 XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 114 XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 115 PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 116 //verify paragraph numbering and bullet alignment 117 assertEquals("assert numbering and bullet","Adjust",propsRule_assert_odt[0].Name); 118 assertEquals("assert numbering and bullet",HoriOrientation.RIGHT,propsRule_assert_odt[0].Value); 119 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name); 120 assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_odt[11].Value); 121 122 //reopen the document 123 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 124 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 125 XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 126 PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 127 //verify paragraph numbering and bullet alignment 128 assertEquals("assert numbering and bullet","Adjust",propsRule_assert_doc[0].Name); 129 assertEquals("assert numbering and bullet",HoriOrientation.RIGHT,propsRule_assert_doc[0].Value); 130 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name); 131 assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_doc[11].Value); 132 } 133 @Test testNumberingBulletAlign_Left()134 public void testNumberingBulletAlign_Left() throws Exception { 135 136 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 137 xText = xTextDocument.getText(); 138 xText.setString("we are Chinese,they are American.\nwe are all living in one earth!\nHello,world!Hello,world!Hello,world!\nHello,world!Hello,world!Hello,world!" + 139 "Hello,world!Hello,world!"); 140 //create cursor to select paragraph and formatting paragraph 141 XTextCursor xTextCursor = xText.createTextCursor(); 142 //create paragraph property set 143 XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 144 //create document service factory 145 XMultiServiceFactory xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 146 //set numbering character 147 XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules")); 148 PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue()}; 149 propsRule[1].Name = "NumberingType"; 150 propsRule[1].Value = NumberingType.ARABIC; 151 propsRule[0].Name = "Adjust"; 152 propsRule[0].Value = HoriOrientation.LEFT; 153 XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 154 xReplaceRule.replaceByIndex(0, propsRule); 155 //set paragraph numbering and bullet character 156 xTextProps.setPropertyValue("NumberingRules", xNumRule); 157 //save to odt 158 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 159 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 160 aStoreProperties_odt[0] = new PropertyValue(); 161 aStoreProperties_odt[1] = new PropertyValue(); 162 aStoreProperties_odt[0].Name = "Override"; 163 aStoreProperties_odt[0].Value = true; 164 aStoreProperties_odt[1].Name = "FilterName"; 165 aStoreProperties_odt[1].Value = "writer8"; 166 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 167 //save to doc 168 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 169 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 170 aStoreProperties_doc[0] = new PropertyValue(); 171 aStoreProperties_doc[1] = new PropertyValue(); 172 aStoreProperties_doc[0].Name = "Override"; 173 aStoreProperties_doc[0].Value = true; 174 aStoreProperties_doc[1].Name = "FilterName"; 175 aStoreProperties_doc[1].Value = "MS Word 97"; 176 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 177 app.closeDocument(xTextDocument); 178 179 //reopen the document 180 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 181 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 182 XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 183 XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 184 PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 185 //verify paragraph numbering and bullet alignment 186 assertEquals("assert numbering and bullet","Adjust",propsRule_assert_odt[0].Name); 187 assertEquals("assert numbering and bullet",HoriOrientation.LEFT,propsRule_assert_odt[0].Value); 188 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name); 189 assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_odt[11].Value); 190 191 //reopen the document 192 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 193 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 194 XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 195 PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 196 //verify paragraph numbering and bullet alignment 197 assertEquals("assert numbering and bullet","Adjust",propsRule_assert_doc[0].Name); 198 assertEquals("assert numbering and bullet",HoriOrientation.LEFT,propsRule_assert_doc[0].Value); 199 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name); 200 assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_doc[11].Value); 201 } 202 @Test testNumberingBulletAlign_Center()203 public void testNumberingBulletAlign_Center() throws Exception { 204 205 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 206 xText = xTextDocument.getText(); 207 xText.setString("we are Chinese,they are American.\nwe are all living in one earth!\nHello,world!Hello,world!Hello,world!\nHello,world!Hello,world!Hello,world!" + 208 "Hello,world!Hello,world!"); 209 //create cursor to select paragraph and formatting paragraph 210 XTextCursor xTextCursor = xText.createTextCursor(); 211 //create paragraph property set 212 XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 213 //create document service factory 214 XMultiServiceFactory xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 215 //set numbering character 216 XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules")); 217 PropertyValue[] propsRule = {new PropertyValue(),new PropertyValue()}; 218 propsRule[1].Name = "NumberingType"; 219 propsRule[1].Value = NumberingType.ARABIC; 220 propsRule[0].Name = "Adjust"; 221 propsRule[0].Value = HoriOrientation.CENTER; 222 XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule); 223 xReplaceRule.replaceByIndex(0, propsRule); 224 //set paragraph numbering and bullet character 225 xTextProps.setPropertyValue("NumberingRules", xNumRule); 226 //save to odt 227 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 228 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 229 aStoreProperties_odt[0] = new PropertyValue(); 230 aStoreProperties_odt[1] = new PropertyValue(); 231 aStoreProperties_odt[0].Name = "Override"; 232 aStoreProperties_odt[0].Value = true; 233 aStoreProperties_odt[1].Name = "FilterName"; 234 aStoreProperties_odt[1].Value = "writer8"; 235 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 236 //save to doc 237 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 238 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 239 aStoreProperties_doc[0] = new PropertyValue(); 240 aStoreProperties_doc[1] = new PropertyValue(); 241 aStoreProperties_doc[0].Name = "Override"; 242 aStoreProperties_doc[0].Value = true; 243 aStoreProperties_doc[1].Name = "FilterName"; 244 aStoreProperties_doc[1].Value = "MS Word 97"; 245 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 246 app.closeDocument(xTextDocument); 247 248 //reopen the document 249 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 250 XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 251 XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules")); 252 XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt); 253 PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0)); 254 //verify paragraph numbering and bullet alignment 255 assertEquals("assert numbering and bullet","Adjust",propsRule_assert_odt[0].Name); 256 assertEquals("assert numbering and bullet",HoriOrientation.CENTER,propsRule_assert_odt[0].Value); 257 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_odt[11].Name); 258 assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_odt[11].Value); 259 260 //reopen the document 261 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 262 XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 263 XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules")); 264 PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0)); 265 //verify paragraph numbering and bullet alignment 266 assertEquals("assert numbering and bullet","Adjust",propsRule_assert_doc[0].Name); 267 assertEquals("assert numbering and bullet",HoriOrientation.CENTER,propsRule_assert_doc[0].Value); 268 assertEquals("assert numbering and bullet","NumberingType",propsRule_assert_doc[11].Name); 269 assertEquals("assert numbering and bullet",NumberingType.ARABIC,propsRule_assert_doc[11].Value); 270 } 271 } 272