107d7dbdcSHerbert Dürr /**************************************************************
207d7dbdcSHerbert Dürr  *
307d7dbdcSHerbert Dürr  * Licensed to the Apache Software Foundation (ASF) under one
407d7dbdcSHerbert Dürr  * or more contributor license agreements.  See the NOTICE file
507d7dbdcSHerbert Dürr  * distributed with this work for additional information
607d7dbdcSHerbert Dürr  * regarding copyright ownership.  The ASF licenses this file
707d7dbdcSHerbert Dürr  * to you under the Apache License, Version 2.0 (the
807d7dbdcSHerbert Dürr  * "License"); you may not use this file except in compliance
907d7dbdcSHerbert Dürr  * with the License.  You may obtain a copy of the License at
1007d7dbdcSHerbert Dürr  *
1107d7dbdcSHerbert Dürr  *   http://www.apache.org/licenses/LICENSE-2.0
1207d7dbdcSHerbert Dürr  *
1307d7dbdcSHerbert Dürr  * Unless required by applicable law or agreed to in writing,
1407d7dbdcSHerbert Dürr  * software distributed under the License is distributed on an
1507d7dbdcSHerbert Dürr  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1607d7dbdcSHerbert Dürr  * KIND, either express or implied.  See the License for the
1707d7dbdcSHerbert Dürr  * specific language governing permissions and limitations
1807d7dbdcSHerbert Dürr  * under the License.
1907d7dbdcSHerbert Dürr  *
2007d7dbdcSHerbert Dürr  *************************************************************/
2107d7dbdcSHerbert Dürr 
22eba4d44aSLiu Zhe package fvt.uno.sw.paragraph;
23294fe326SLiu Zhe 
24294fe326SLiu Zhe import static org.junit.Assert.*;
25294fe326SLiu Zhe 
26294fe326SLiu Zhe import org.junit.After;
27294fe326SLiu Zhe import org.junit.Before;
28294fe326SLiu Zhe import org.junit.Test;
29294fe326SLiu Zhe import org.openoffice.test.common.FileUtil;
30294fe326SLiu Zhe import org.openoffice.test.common.Testspace;
31294fe326SLiu Zhe import org.openoffice.test.uno.UnoApp;
32294fe326SLiu Zhe 
33294fe326SLiu Zhe import com.sun.star.text.*;
34294fe326SLiu Zhe import com.sun.star.beans.*;
35294fe326SLiu Zhe import com.sun.star.container.XIndexAccess;
36294fe326SLiu Zhe import com.sun.star.container.XIndexReplace;
37294fe326SLiu Zhe import com.sun.star.frame.XStorable;
38294fe326SLiu Zhe import com.sun.star.lang.XMultiServiceFactory;
39294fe326SLiu Zhe import com.sun.star.uno.UnoRuntime;
40294fe326SLiu Zhe 
41294fe326SLiu Zhe public class ParagraphNumberingAndBulletTabStop {
42294fe326SLiu Zhe 	private static final UnoApp app = new UnoApp();
43294fe326SLiu Zhe 	XText xText = null;
44294fe326SLiu Zhe 
45294fe326SLiu Zhe 	@Before
setUp()46294fe326SLiu Zhe 	public void setUp() throws Exception {
47294fe326SLiu Zhe 		app.start();
48294fe326SLiu Zhe 
49294fe326SLiu Zhe 	}
50294fe326SLiu Zhe 
51294fe326SLiu Zhe 	@After
tearDown()52294fe326SLiu Zhe 	public void tearDown() throws Exception {
53294fe326SLiu Zhe 		app.close();
54294fe326SLiu Zhe 	}
55294fe326SLiu Zhe 	/*
56294fe326SLiu Zhe 	 * test paragraph background color
57294fe326SLiu Zhe 	 * 1.new a text document
58294fe326SLiu Zhe 	 * 2.insert some text
59294fe326SLiu Zhe 	 * 3.set paragraph numbering tab stop position
60294fe326SLiu Zhe 	 * 4.save and close the document
61294fe326SLiu Zhe 	 * 5.reload the saved document and check the paragraph numbering tab stop position
62294fe326SLiu Zhe 	 */
63294fe326SLiu Zhe 	@Test
testNumberingBulletTabStop()64294fe326SLiu Zhe 	public void testNumberingBulletTabStop() throws Exception {
65294fe326SLiu Zhe 
66294fe326SLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
67294fe326SLiu Zhe 		xText = xTextDocument.getText();
68294fe326SLiu Zhe 		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!" +
69294fe326SLiu Zhe 				"Hello,world!Hello,world!");
70*cbe561cdSJohn Bampton 		//create cursor to select paragraph and formatting paragraph
71294fe326SLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
72294fe326SLiu Zhe 		//create paragraph property set
73294fe326SLiu Zhe 		XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
74294fe326SLiu Zhe 		//create document service factory
75294fe326SLiu Zhe 		XMultiServiceFactory  xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
76294fe326SLiu Zhe 		//set numbering character
77294fe326SLiu Zhe 		XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules"));
78294fe326SLiu Zhe 		PropertyValue[] propsRule = {new PropertyValue()};
79294fe326SLiu Zhe 		propsRule[0].Name = "ListtabStopPosition";
80294fe326SLiu Zhe 		propsRule[0].Value = 5001;
81294fe326SLiu Zhe 		XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule);
82294fe326SLiu Zhe 		xReplaceRule.replaceByIndex(0, propsRule);
83294fe326SLiu Zhe 		//set paragraph numbering and bullet character
84294fe326SLiu Zhe 		xTextProps.setPropertyValue("NumberingRules", xNumRule);
85294fe326SLiu Zhe 		//save to odt
86294fe326SLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
87294fe326SLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
88294fe326SLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
89294fe326SLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
90294fe326SLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
91294fe326SLiu Zhe 		aStoreProperties_odt[0].Value = true;
92294fe326SLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
93294fe326SLiu Zhe 		aStoreProperties_odt[1].Value = "writer8";
94294fe326SLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
95294fe326SLiu Zhe 		//save to doc
96294fe326SLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
97294fe326SLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
98294fe326SLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
99294fe326SLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
100294fe326SLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
101294fe326SLiu Zhe 		aStoreProperties_doc[0].Value = true;
102294fe326SLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
103294fe326SLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
104294fe326SLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
105294fe326SLiu Zhe 		app.closeDocument(xTextDocument);
106294fe326SLiu Zhe 
107294fe326SLiu Zhe 		//reopen the document
108294fe326SLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
109294fe326SLiu Zhe 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
110294fe326SLiu Zhe 		XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules"));
111294fe326SLiu Zhe 		XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt);
112294fe326SLiu Zhe 		PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0));
113294fe326SLiu Zhe 		//verify paragraph numbering and bullet alignment
114294fe326SLiu Zhe 		assertEquals("assert numbering and bullet","ListtabStopPosition",propsRule_assert_odt[8].Name);
115294fe326SLiu Zhe 		assertEquals("assert numbering and bullet",5001,propsRule_assert_odt[8].Value);
116294fe326SLiu Zhe 
117294fe326SLiu Zhe 		//reopen the document
118294fe326SLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
119294fe326SLiu Zhe 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
120294fe326SLiu Zhe 		XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules"));
121294fe326SLiu Zhe 		PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0));
122294fe326SLiu Zhe 		//verify paragraph numbering and bullet alignment
123294fe326SLiu Zhe 		assertEquals("assert numbering and bullet","ListtabStopPosition",propsRule_assert_doc[8].Name);
124294fe326SLiu Zhe 		assertEquals("assert numbering and bullet",5001,propsRule_assert_doc[8].Value);
125294fe326SLiu Zhe 	}
126294fe326SLiu Zhe }
127