SWUtil.java (cebb507a) SWUtil.java (deb45f49)
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

--- 11 unchanged lines hidden (view full) ---

20 *************************************************************/
21package testlib.uno;
22
23
24import org.openoffice.test.uno.UnoApp;
25
26import com.sun.star.beans.PropertyValue;
27import com.sun.star.beans.XPropertySet;
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

--- 11 unchanged lines hidden (view full) ---

20 *************************************************************/
21package testlib.uno;
22
23
24import org.openoffice.test.uno.UnoApp;
25
26import com.sun.star.beans.PropertyValue;
27import com.sun.star.beans.XPropertySet;
28import com.sun.star.container.XEnumeration;
29import com.sun.star.container.XEnumerationAccess;
28import com.sun.star.container.XNameAccess;
29import com.sun.star.container.XNameContainer;
30import com.sun.star.container.XNamed;
31import com.sun.star.document.XDocumentInfo;
32import com.sun.star.document.XDocumentInfoSupplier;
33import com.sun.star.frame.XStorable;
34import com.sun.star.io.IOException;
30import com.sun.star.container.XNamed;
31import com.sun.star.document.XDocumentInfo;
32import com.sun.star.document.XDocumentInfoSupplier;
33import com.sun.star.frame.XStorable;
34import com.sun.star.io.IOException;
35import com.sun.star.lang.XComponent;
35import com.sun.star.lang.XMultiServiceFactory;
36import com.sun.star.style.BreakType;
36import com.sun.star.lang.XMultiServiceFactory;
37import com.sun.star.style.BreakType;
38import com.sun.star.style.XStyle;
39import com.sun.star.style.XStyleFamiliesSupplier;
37import com.sun.star.text.ControlCharacter;
38import com.sun.star.text.XText;
39import com.sun.star.text.XTextContent;
40import com.sun.star.text.XTextCursor;
41import com.sun.star.text.XTextDocument;
42import com.sun.star.frame.XModel;
43import com.sun.star.frame.XController;
44import com.sun.star.uno.UnoRuntime;
45
46public class SWUtil {
47
48
49
50
51 public static void saveAsDoc(XTextDocument document, String url) throws IOException {
52 saveAs(document, "MS Word 97", url);
53
54 }
55
40import com.sun.star.text.ControlCharacter;
41import com.sun.star.text.XText;
42import com.sun.star.text.XTextContent;
43import com.sun.star.text.XTextCursor;
44import com.sun.star.text.XTextDocument;
45import com.sun.star.frame.XModel;
46import com.sun.star.frame.XController;
47import com.sun.star.uno.UnoRuntime;
48
49public class SWUtil {
50
51
52
53
54 public static void saveAsDoc(XTextDocument document, String url) throws IOException {
55 saveAs(document, "MS Word 97", url);
56
57 }
58
59 public static void saveAsDoc(XComponent component, String url) throws IOException{
60 XTextDocument document = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component);
61 saveAs(document, "MS Word 97", url);
62 }
56
57 public static void saveAsODT(XTextDocument document, String url) throws IOException {
58 saveAs(document, "writer8", url);
59 }
60
61 public static void saveAs(XTextDocument document, String filterValue, String url) throws IOException {
62 XStorable store = (XStorable) UnoRuntime.queryInterface(XStorable.class, document);
63 PropertyValue[] propsValue = new PropertyValue[1];

--- 114 unchanged lines hidden (view full) ---

178 public static int getPageCount(XTextDocument document) throws Exception
179 {
180 XModel xmodel = (XModel)UnoRuntime.queryInterface(XModel.class, document);
181 XController xcont = xmodel.getCurrentController();
182
183 XPropertySet xps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xcont);
184 Integer pageCount = (Integer) xps.getPropertyValue("PageCount");
185 return pageCount.intValue();
63
64 public static void saveAsODT(XTextDocument document, String url) throws IOException {
65 saveAs(document, "writer8", url);
66 }
67
68 public static void saveAs(XTextDocument document, String filterValue, String url) throws IOException {
69 XStorable store = (XStorable) UnoRuntime.queryInterface(XStorable.class, document);
70 PropertyValue[] propsValue = new PropertyValue[1];

--- 114 unchanged lines hidden (view full) ---

185 public static int getPageCount(XTextDocument document) throws Exception
186 {
187 XModel xmodel = (XModel)UnoRuntime.queryInterface(XModel.class, document);
188 XController xcont = xmodel.getCurrentController();
189
190 XPropertySet xps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xcont);
191 Integer pageCount = (Integer) xps.getPropertyValue("PageCount");
192 return pageCount.intValue();
193 }
194
195
196 /**
197 * get specific property value of the default page style
198 * @param xComponent
199 * @param propertyName
200 * @return
201 * @throws Exception
202 */
203 public static Object getDefaultPageStyleProperty(XComponent xComponent, String propertyName) throws Exception
204 {
205 XTextDocument textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, xComponent);
206 XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier)UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, textDocument);
207 XNameAccess xFamilies = (XNameAccess) UnoRuntime.queryInterface (XNameAccess.class, xSupplier.getStyleFamilies());
208 XNameContainer xFamily = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xFamilies.getByName("PageStyles"));
209 XStyle xStyle = (XStyle)UnoRuntime.queryInterface(XStyle.class, xFamily.getByName("Default"));
210 XPropertySet xStyleProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xStyle);
211 Object propertyValue = xStyleProps.getPropertyValue(propertyName.toString());
212 return propertyValue;
186 }
187
213 }
214
215 /**
216 * set value for specific property of default page style.
217 * @param xComponent
218 * @param propertyName
219 * @param propertyValue
220 * @throws Exception
221 */
222 public static void setDefaultPageStyleProperty(XComponent xComponent, String propertyName, Object propertyValue) throws Exception
223 {
224 XTextDocument textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, xComponent);
225 XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier)UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, textDocument);
226 XNameAccess xFamilies = (XNameAccess) UnoRuntime.queryInterface (XNameAccess.class, xSupplier.getStyleFamilies());
227 XNameContainer xFamily = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xFamilies.getByName("PageStyles"));
228 XStyle xStyle = (XStyle)UnoRuntime.queryInterface(XStyle.class, xFamily.getByName("Default"));
229 XPropertySet xStyleProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xStyle);
230 xStyleProps.setPropertyValue (propertyName.toString(), propertyValue);
231 }
188}
232}