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

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

54 }
55
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 {
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

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

54 }
55
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 = UnoRuntime.queryInterface(XStorable.class, document);
62 XStorable store = (XStorable) UnoRuntime.queryInterface(XStorable.class, document);
63 PropertyValue[] propsValue = new PropertyValue[1];
64 propsValue[0] = new PropertyValue();
65 propsValue[0].Name = "FilterName";
66 propsValue[0].Value = filterValue;
67 store.storeAsURL(url, propsValue);
68
69 }
70
71 public static void save(XTextDocument document) throws IOException {
63 PropertyValue[] propsValue = new PropertyValue[1];
64 propsValue[0] = new PropertyValue();
65 propsValue[0].Name = "FilterName";
66 propsValue[0].Value = filterValue;
67 store.storeAsURL(url, propsValue);
68
69 }
70
71 public static void save(XTextDocument document) throws IOException {
72 XStorable store = UnoRuntime.queryInterface(XStorable.class, document);
72 XStorable store = (XStorable) UnoRuntime.queryInterface(XStorable.class, document);
73 store.store();
74 }
75
76 public static XTextDocument saveAndReload(XTextDocument document, UnoApp app) throws Exception {
73 store.store();
74 }
75
76 public static XTextDocument saveAndReload(XTextDocument document, UnoApp app) throws Exception {
77 XStorable store = UnoRuntime.queryInterface(XStorable.class, document);
77 XStorable store = (XStorable) UnoRuntime.queryInterface(XStorable.class, document);
78 store.store();
79 String url = document.getURL();
80 app.closeDocument(document);
81 return openDocumentFromURL(url, app);
82
83 }
84
85 public static XTextDocument newDocument(UnoApp app) throws Exception {

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

112 /**
113 * Set document properties. such as subject, title etc
114 * @param document - set document information on this document
115 * @param prop - document information, including "Subject" ,"Title", "Author", "Title", "KeyWords"
116 * @param propValue - value you want to set for prop
117 * @throws Exception
118 */
119 public static void setDocumentProperty(XTextDocument document, String prop, String propValue) throws Exception {
78 store.store();
79 String url = document.getURL();
80 app.closeDocument(document);
81 return openDocumentFromURL(url, app);
82
83 }
84
85 public static XTextDocument newDocument(UnoApp app) throws Exception {

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

112 /**
113 * Set document properties. such as subject, title etc
114 * @param document - set document information on this document
115 * @param prop - document information, including "Subject" ,"Title", "Author", "Title", "KeyWords"
116 * @param propValue - value you want to set for prop
117 * @throws Exception
118 */
119 public static void setDocumentProperty(XTextDocument document, String prop, String propValue) throws Exception {
120 XDocumentInfoSupplier docInfoSupplier = UnoRuntime.queryInterface(XDocumentInfoSupplier.class, document);
120 XDocumentInfoSupplier docInfoSupplier = (XDocumentInfoSupplier) UnoRuntime.queryInterface(XDocumentInfoSupplier.class, document);
121 XDocumentInfo docInfo = docInfoSupplier.getDocumentInfo();
122 XPropertySet propsDocInfo = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, docInfo);
123 propsDocInfo.setPropertyValue(prop, propValue);
124 }
125
126
127 /**
128 * Insert a bookmark into text document
129 * @param document text document
130 * @param textCursor which part will be bookmarked
131 * @param bookmarkName bookmark name
132 * @throws Exception
133 */
134 public static void insertBookmark(XTextDocument document, XTextCursor textCursor, String bookmarkName) throws Exception {
121 XDocumentInfo docInfo = docInfoSupplier.getDocumentInfo();
122 XPropertySet propsDocInfo = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, docInfo);
123 propsDocInfo.setPropertyValue(prop, propValue);
124 }
125
126
127 /**
128 * Insert a bookmark into text document
129 * @param document text document
130 * @param textCursor which part will be bookmarked
131 * @param bookmarkName bookmark name
132 * @throws Exception
133 */
134 public static void insertBookmark(XTextDocument document, XTextCursor textCursor, String bookmarkName) throws Exception {
135 XMultiServiceFactory xDocFactory = UnoRuntime.queryInterface(XMultiServiceFactory.class, document);
135 XMultiServiceFactory xDocFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, document);
136 Object xBookmark = xDocFactory.createInstance("com.sun.star.text.Bookmark");
136 Object xBookmark = xDocFactory.createInstance("com.sun.star.text.Bookmark");
137 XTextContent xBookmarkAsTextContent = UnoRuntime.queryInterface(XTextContent.class, xBookmark);
138 XNamed xBookmarkAsNamed = UnoRuntime.queryInterface(XNamed.class, xBookmark);
137 XTextContent xBookmarkAsTextContent = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, xBookmark);
138 XNamed xBookmarkAsNamed = (XNamed) UnoRuntime.queryInterface(XNamed.class, xBookmark);
139 xBookmarkAsNamed.setName(bookmarkName);
140 document.getText().insertTextContent(textCursor, xBookmarkAsTextContent, true);
141 }
142
143 /**
144 * insert column break in current cursor
145 * @param xText
146 * @param currentCursor

--- 42 unchanged lines hidden ---
139 xBookmarkAsNamed.setName(bookmarkName);
140 document.getText().insertTextContent(textCursor, xBookmarkAsTextContent, true);
141 }
142
143 /**
144 * insert column break in current cursor
145 * @param xText
146 * @param currentCursor

--- 42 unchanged lines hidden ---