1*eba4d44aSLiu Zhe package fvt.uno.sw.paragraph;
2294fe326SLiu Zhe 
3294fe326SLiu Zhe import static org.junit.Assert.*;
4294fe326SLiu Zhe 
5294fe326SLiu Zhe import org.junit.After;
6294fe326SLiu Zhe import org.junit.Before;
7294fe326SLiu Zhe import org.junit.Test;
8294fe326SLiu Zhe import org.openoffice.test.common.FileUtil;
9294fe326SLiu Zhe import org.openoffice.test.common.Testspace;
10294fe326SLiu Zhe import org.openoffice.test.uno.UnoApp;
11294fe326SLiu Zhe 
12294fe326SLiu Zhe import com.sun.star.text.*;
13294fe326SLiu Zhe import com.sun.star.beans.*;
14294fe326SLiu Zhe import com.sun.star.container.XIndexAccess;
15294fe326SLiu Zhe import com.sun.star.container.XIndexReplace;
16294fe326SLiu Zhe import com.sun.star.frame.XStorable;
17294fe326SLiu Zhe import com.sun.star.lang.XMultiServiceFactory;
18294fe326SLiu Zhe import com.sun.star.uno.UnoRuntime;
19294fe326SLiu Zhe 
20294fe326SLiu Zhe public class ParagraphNumberingAndBulletTabStop {
21294fe326SLiu Zhe 	private static final UnoApp app = new UnoApp();
22294fe326SLiu Zhe 	XText xText = null;
23294fe326SLiu Zhe 
24294fe326SLiu Zhe 	@Before
25294fe326SLiu Zhe 	public void setUp() throws Exception {
26294fe326SLiu Zhe 		app.start();
27294fe326SLiu Zhe 
28294fe326SLiu Zhe 	}
29294fe326SLiu Zhe 
30294fe326SLiu Zhe 	@After
31294fe326SLiu Zhe 	public void tearDown() throws Exception {
32294fe326SLiu Zhe 		app.close();
33294fe326SLiu Zhe 	}
34294fe326SLiu Zhe 	/*
35294fe326SLiu Zhe 	 * test paragraph background color
36294fe326SLiu Zhe 	 * 1.new a text document
37294fe326SLiu Zhe 	 * 2.insert some text
38294fe326SLiu Zhe 	 * 3.set paragraph numbering tab stop position
39294fe326SLiu Zhe 	 * 4.save and close the document
40294fe326SLiu Zhe 	 * 5.reload the saved document and check the paragraph numbering tab stop position
41294fe326SLiu Zhe 	 */
42294fe326SLiu Zhe 	@Test
43294fe326SLiu Zhe 	public void testNumberingBulletTabStop() throws Exception {
44294fe326SLiu Zhe 
45294fe326SLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
46294fe326SLiu Zhe 		xText = xTextDocument.getText();
47294fe326SLiu 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!" +
48294fe326SLiu Zhe 				"Hello,world!Hello,world!");
49294fe326SLiu Zhe 		//create cursor to select paragraph and formating paragraph
50294fe326SLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
51294fe326SLiu Zhe 		//create paragraph property set
52294fe326SLiu Zhe 		XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
53294fe326SLiu Zhe 		//create document service factory
54294fe326SLiu Zhe 		XMultiServiceFactory  xWriterFactory= (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
55294fe326SLiu Zhe 		//set numbering character
56294fe326SLiu Zhe 		XIndexAccess xNumRule = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,xWriterFactory.createInstance("com.sun.star.text.NumberingRules"));
57294fe326SLiu Zhe 		PropertyValue[] propsRule = {new PropertyValue()};
58294fe326SLiu Zhe 		propsRule[0].Name = "ListtabStopPosition";
59294fe326SLiu Zhe 		propsRule[0].Value = 5001;
60294fe326SLiu Zhe 		XIndexReplace xReplaceRule = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule);
61294fe326SLiu Zhe 		xReplaceRule.replaceByIndex(0, propsRule);
62294fe326SLiu Zhe 		//set paragraph numbering and bullet character
63294fe326SLiu Zhe 		xTextProps.setPropertyValue("NumberingRules", xNumRule);
64294fe326SLiu Zhe 		//save to odt
65294fe326SLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
66294fe326SLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
67294fe326SLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
68294fe326SLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
69294fe326SLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
70294fe326SLiu Zhe 		aStoreProperties_odt[0].Value = true;
71294fe326SLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
72294fe326SLiu Zhe 		aStoreProperties_odt[1].Value = "writer8";
73294fe326SLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
74294fe326SLiu Zhe 		//save to doc
75294fe326SLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
76294fe326SLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
77294fe326SLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
78294fe326SLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
79294fe326SLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
80294fe326SLiu Zhe 		aStoreProperties_doc[0].Value = true;
81294fe326SLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
82294fe326SLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
83294fe326SLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
84294fe326SLiu Zhe 		app.closeDocument(xTextDocument);
85294fe326SLiu Zhe 
86294fe326SLiu Zhe 		//reopen the document
87294fe326SLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
88294fe326SLiu Zhe 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
89294fe326SLiu Zhe 		XIndexAccess xNumRule_assert_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_odt.getPropertyValue("NumberingRules"));
90294fe326SLiu Zhe 		XIndexReplace xReplaceRule_assert_odt = (XIndexReplace) UnoRuntime.queryInterface(XIndexReplace.class, xNumRule_assert_odt);
91294fe326SLiu Zhe 		PropertyValue[] propsRule_assert_odt=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xReplaceRule_assert_odt.getByIndex(0));
92294fe326SLiu Zhe 		//verify paragraph numbering and bullet alignment
93294fe326SLiu Zhe 		assertEquals("assert numbering and bullet","ListtabStopPosition",propsRule_assert_odt[8].Name);
94294fe326SLiu Zhe 		assertEquals("assert numbering and bullet",5001,propsRule_assert_odt[8].Value);
95294fe326SLiu Zhe 
96294fe326SLiu Zhe 		//reopen the document
97294fe326SLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
98294fe326SLiu Zhe 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
99294fe326SLiu Zhe 		XIndexAccess xNumRule_assert_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xCursorProps_Assert_doc.getPropertyValue("NumberingRules"));
100294fe326SLiu Zhe 		PropertyValue[] propsRule_assert_doc=(PropertyValue[]) UnoRuntime.queryInterface(PropertyValue[].class,xNumRule_assert_doc.getByIndex(0));
101294fe326SLiu Zhe 		//verify paragraph numbering and bullet alignment
102294fe326SLiu Zhe 		assertEquals("assert numbering and bullet","ListtabStopPosition",propsRule_assert_doc[8].Name);
103294fe326SLiu Zhe 		assertEquals("assert numbering and bullet",5001,propsRule_assert_doc[8].Value);
104294fe326SLiu Zhe 	}
105294fe326SLiu Zhe }
106