View | Details | Raw Unified | Return to issue 120703
Collapse All | Expand All

(-)testuno/source/testcase/uno/sw/DocumentTest.java (-2 / +41 lines)
Lines 18-24 Link Here
18
import com.sun.star.beans.PropertyValue;
18
import com.sun.star.beans.PropertyValue;
19
import com.sun.star.frame.*;
19
import com.sun.star.frame.*;
20
import com.sun.star.uno.UnoRuntime;
20
import com.sun.star.uno.UnoRuntime;
21
import com.sun.star.util.XCloseable;
21
import com.sun.star.lang.XComponent;
22
import com.sun.star.lang.XComponent;
23
import com.sun.star.container.XEnumerationAccess;
24
import com.sun.star.container.XEnumeration;
22
25
23
26
24
public class DocumentTest {
27
public class DocumentTest {
Lines 64-72 Link Here
64
		XComponent component = componentLoader.loadComponentFromURL(FileUtil.getUrl(workingTemplatePath), "_blank", 0,pros);
67
		XComponent component = componentLoader.loadComponentFromURL(FileUtil.getUrl(workingTemplatePath), "_blank", 0,pros);
65
		return component;
68
		return component;
66
	}
69
	}
70
	
67
71
68
72
	/**
73
	 * test close document
74
	 * @throws Exception
75
	 */
69
	@Test
76
	@Test
77
	public void testCloseDocument() throws Exception
78
	{
79
		XComponent component = unoApp.newDocument("swriter");
80
		unoApp.closeDocument(component);
81
		XModel xModel = unoApp.getDesktop().getCurrentFrame().getController().getModel();		
82
		Assert.assertTrue("Document has been closed.",xModel==null);
83
	}
84
	
85
	/**
86
	 * test new document
87
	 * @throws Exception
88
	 */
89
	@Test
70
	public void testNewDocument() throws Exception
90
	public void testNewDocument() throws Exception
71
	{
91
	{
72
		XComponentLoader componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, unoApp.getDesktop());		
92
		XComponentLoader componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, unoApp.getDesktop());		
Lines 78-84 Link Here
78
		unoApp.closeDocument(textDocument);
98
		unoApp.closeDocument(textDocument);
79
	}
99
	}
80
	
100
	
81
	
101
	/**
102
	 * test new document from template
103
	 * @throws Exception
104
	 */
82
	@Test
105
	@Test
83
	public void testNewDocumentFromTemplate() throws Exception
106
	public void testNewDocumentFromTemplate() throws Exception
84
	{		
107
	{		
Lines 99-104 Link Here
99
        unoApp.closeDocument(textDocument);
122
        unoApp.closeDocument(textDocument);
100
	}
123
	}
101
	
124
	
125
	/**
126
	 * test save document as odt
127
	 * @throws Exception
128
	 */
102
	@Test
129
	@Test
103
	public void testSaveDocument() throws Exception
130
	public void testSaveDocument() throws Exception
104
	{			
131
	{			
Lines 126-131 Link Here
126
        unoApp.closeDocument(textDocument);
153
        unoApp.closeDocument(textDocument);
127
	}
154
	}
128
	
155
	
156
	/**
157
	 * test save document as doc
158
	 * @throws Exception
159
	 */
129
	@Test
160
	@Test
130
	public void testSaveAsDocument() throws Exception
161
	public void testSaveAsDocument() throws Exception
131
	{		
162
	{		
Lines 155-160 Link Here
155
        unoApp.closeDocument(textDocument);
186
        unoApp.closeDocument(textDocument);
156
	}
187
	}
157
	
188
	
189
	/**
190
	 * test export document as pdf
191
	 * @throws Exception
192
	 */
158
	@Test
193
	@Test
159
	public void testExportAsPDF() throws Exception
194
	public void testExportAsPDF() throws Exception
160
	{		
195
	{		
Lines 184-189 Link Here
184
        unoApp.closeDocument(textDocument);
219
        unoApp.closeDocument(textDocument);
185
	}
220
	}
186
	
221
	
222
	/**
223
	 * test save document as template
224
	 * @throws Exception
225
	 */
187
	@Test
226
	@Test
188
	public void testSaveAsTemplate() throws Exception
227
	public void testSaveAsTemplate() throws Exception
189
	{
228
	{
(-)testuno/source/testlib/uno/sw/SWUtil.java (+39 lines)
Line 0 Link Here
1
package testlib.uno.sw;
2
3
import org.openoffice.test.uno.UnoApp;
4
5
import com.sun.star.beans.PropertyValue;
6
import com.sun.star.frame.XStorable;
7
import com.sun.star.text.XTextDocument;
8
import com.sun.star.uno.UnoRuntime;
9
import com.sun.star.lang.XComponent;
10
11
public class SWUtil {
12
	
13
	private static final UnoApp app = new UnoApp();
14
	public static void saveAsDoc(XTextDocument document, String url) throws Exception {
15
		saveAs(document, "MS Word 97", url);
16
		
17
	}
18
19
	public static void saveAsODT(XTextDocument document, String url) throws Exception {
20
		saveAs(document, "writer8", url);
21
	}
22
	
23
	public static void saveAs(XTextDocument document, String filterValue, String url) throws Exception {
24
		XStorable store = UnoRuntime.queryInterface(XStorable.class, document);
25
		
26
		PropertyValue[] propsValue = new PropertyValue[1];
27
		propsValue[0] = new PropertyValue();
28
		propsValue[0].Name = "FilterName";
29
		propsValue[0].Value = filterValue;
30
		store.storeAsURL(url, propsValue);
31
		
32
	}
33
	
34
	public static XTextDocument newDocument() throws Exception {
35
		XComponent component = app.newDocument("swriter");
36
		return (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component);
37
		
38
	}
39
}
(-)testuno/source/testlib/uno/SWUtil.java (+38 lines)
Lines 25-40 Link Here
25
25
26
import com.sun.star.beans.PropertyValue;
26
import com.sun.star.beans.PropertyValue;
27
import com.sun.star.beans.XPropertySet;
27
import com.sun.star.beans.XPropertySet;
28
import com.sun.star.container.XEnumeration;
29
import com.sun.star.container.XEnumerationAccess;
28
import com.sun.star.container.XNamed;
30
import com.sun.star.container.XNamed;
29
import com.sun.star.document.XDocumentInfo;
31
import com.sun.star.document.XDocumentInfo;
30
import com.sun.star.document.XDocumentInfoSupplier;
32
import com.sun.star.document.XDocumentInfoSupplier;
31
import com.sun.star.frame.XStorable;
33
import com.sun.star.frame.XStorable;
32
import com.sun.star.io.IOException;
34
import com.sun.star.io.IOException;
33
import com.sun.star.lang.XMultiServiceFactory;
35
import com.sun.star.lang.XMultiServiceFactory;
36
import com.sun.star.style.BreakType;
37
import com.sun.star.text.ControlCharacter;
34
import com.sun.star.text.XText;
38
import com.sun.star.text.XText;
35
import com.sun.star.text.XTextContent;
39
import com.sun.star.text.XTextContent;
36
import com.sun.star.text.XTextCursor;
40
import com.sun.star.text.XTextCursor;
37
import com.sun.star.text.XTextDocument;
41
import com.sun.star.text.XTextDocument;
42
import com.sun.star.frame.XModel;
43
import com.sun.star.frame.XController;
38
import com.sun.star.uno.UnoRuntime;
44
import com.sun.star.uno.UnoRuntime;
39
45
40
public class SWUtil {
46
public class SWUtil {
Lines 133-136 Link Here
133
		xBookmarkAsNamed.setName(bookmarkName);
139
		xBookmarkAsNamed.setName(bookmarkName);
134
		document.getText().insertTextContent(textCursor, xBookmarkAsTextContent, true);
140
		document.getText().insertTextContent(textCursor, xBookmarkAsTextContent, true);
135
	}
141
	}
142
	
143
	/**
144
	 * insert page break in current cursor
145
	 * @param xText
146
	 * @param currentCursor
147
	 * @throws Exception
148
	 */
149
	public static void insertPageBreak(XText xText, XTextCursor currentCursor) throws Exception
150
	{
151
		XPropertySet xCursorProps = (XPropertySet)UnoRuntime.queryInterface(
152
		        XPropertySet.class, currentCursor);
153
		xCursorProps.setPropertyValue("BreakType", BreakType.PAGE_AFTER);		
154
	    xText.insertControlCharacter(currentCursor,ControlCharacter.PARAGRAPH_BREAK,false); 
155
	}	
156
	
157
	
158
	/**
159
	 * get page count
160
	 * @param document
161
	 * @return
162
	 * @throws Exception
163
	 */
164
	public static int getPageCount(XTextDocument document) throws Exception
165
	{
166
		XModel xmodel = (XModel)UnoRuntime.queryInterface(XModel.class, document);
167
		XController xcont = xmodel.getCurrentController();
168
169
		XPropertySet xps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xcont);
170
		Integer pageCount = (Integer) xps.getPropertyValue("PageCount"); 
171
		return pageCount.intValue();
172
	}
173
	
136
}
174
}

Return to issue 120703