incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liu...@apache.org
Subject svn commit: r1374948 - /incubator/ooo/trunk/main/test/testuno/source/testlib/uno/sw/SWUtil.java
Date Mon, 20 Aug 2012 08:52:16 GMT
Author: liuzhe
Date: Mon Aug 20 08:52:15 2012
New Revision: 1374948

URL: http://svn.apache.org/viewvc?rev=1374948&view=rev
Log:
Testcases for bookmark

Modified:
    incubator/ooo/trunk/main/test/testuno/source/testlib/uno/sw/SWUtil.java

Modified: incubator/ooo/trunk/main/test/testuno/source/testlib/uno/sw/SWUtil.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testlib/uno/sw/SWUtil.java?rev=1374948&r1=1374947&r2=1374948&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/source/testlib/uno/sw/SWUtil.java (original)
+++ incubator/ooo/trunk/main/test/testuno/source/testlib/uno/sw/SWUtil.java Mon Aug 20 08:52:15
2012
@@ -3,7 +3,13 @@ package testlib.uno.sw;
 import org.openoffice.test.uno.UnoApp;
 
 import com.sun.star.beans.PropertyValue;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.container.XNamed;
 import com.sun.star.frame.XStorable;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.text.XBookmarksSupplier;
+import com.sun.star.text.XTextContent;
+import com.sun.star.text.XTextCursor;
 import com.sun.star.text.XTextDocument;
 import com.sun.star.uno.UnoRuntime;
 
@@ -34,4 +40,21 @@ public class SWUtil {
 		return (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
 		
 	}
+	
+	/**
+	 * Insert a bookmark into text document
+	 * @param document text document
+	 * @param textCursor which part will be bookmarked
+	 * @param bookmarkName bookmark name
+	 * @throws Exception
+	 */
+	public static void insertBookmark(XTextDocument document, XTextCursor textCursor, String
bookmarkName) throws Exception {
+		XMultiServiceFactory xDocFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class,
document);
+		Object xBookmark = xDocFactory.createInstance("com.sun.star.text.Bookmark");
+		XTextContent xBookmarkAsTextContent = (XTextContent) UnoRuntime.queryInterface(XTextContent.class,
xBookmark);
+		XNamed xBookmarkAsNamed = (XNamed) UnoRuntime.queryInterface(XNamed.class, xBookmark);
+		xBookmarkAsNamed.setName(bookmarkName);
+		document.getText().insertTextContent(textCursor, xBookmarkAsTextContent, true);
+	}
+
 }



Mime
View raw message