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 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 package fvt.uno.sw.frame; 22 23 import static org.junit.Assert.*; 24 25 import org.junit.After; 26 import org.junit.AfterClass; 27 import org.junit.Before; 28 import org.junit.Test; 29 import org.openoffice.test.common.Testspace; 30 import org.openoffice.test.uno.UnoApp; 31 32 import testlib.uno.SWUtil; 33 34 import com.sun.star.beans.XPropertySet; 35 import com.sun.star.container.XNameAccess; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.text.XText; 38 import com.sun.star.text.XTextCursor; 39 import com.sun.star.text.XTextDocument; 40 import com.sun.star.text.XTextFrame; 41 import com.sun.star.text.XTextFramesSupplier; 42 import com.sun.star.uno.UnoRuntime; 43 44 public class FrameHyperlink { 45 private static final UnoApp app = new UnoApp(); 46 private XTextDocument xTextDocument=null; 47 private XMultiServiceFactory xWriterFactory=null; 48 private XText xText=null; 49 @Before setUp()50 public void setUp() throws Exception { 51 app.start(); 52 } 53 54 @After tearDown()55 public void tearDown() throws Exception { 56 app.closeDocument(xTextDocument); 57 } 58 @AfterClass tearDownConnection()59 public static void tearDownConnection() throws Exception { 60 app.close(); 61 } 62 63 @Test testFrameHyperlink()64 public void testFrameHyperlink() throws Exception { 65 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 66 xText=xTextDocument.getText(); 67 XTextCursor xTextCursor = xText.createTextCursor(); 68 // get internal service factory of the document 69 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 70 // Create a new table from the document's factory 71 XTextFrame xTextFrame = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame")); 72 xText.insertTextContent(xTextCursor,xTextFrame,false); 73 XPropertySet xTextFrameProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextFrame); 74 xTextFrameProps.setPropertyValue("HyperLinkURL","http://www.google.com.hk/"); 75 xTextFrameProps.setPropertyValue("HyperLinkTarget","google"); 76 xTextFrameProps.setPropertyValue("HyperLinkName","FrameHyperlinkToGoogle"); 77 78 //save and reopen the document 79 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app)); 80 XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt); 81 XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames(); 82 XTextFrame xTextFrame_Assert=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrames_odt.getByName("Frame1")); 83 XPropertySet xTextFrameProps_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextFrame_Assert); 84 assertEquals("assert Frame hyperlink url","http://www.google.com.hk/", xTextFrameProps_assert.getPropertyValue("HyperLinkURL")); 85 assertEquals("assert Frame hyperlink target","google", xTextFrameProps_assert.getPropertyValue("HyperLinkTarget")); 86 assertEquals("assert Frame hyperlink name", "FrameHyperlinkToGoogle",xTextFrameProps_assert.getPropertyValue("HyperLinkName")); 87 } 88 } 89