1*1ff9903bSLi Feng Wang package fvt.uno.sw.frame;
2*1ff9903bSLi Feng Wang 
3*1ff9903bSLi Feng Wang import static org.junit.Assert.*;
4*1ff9903bSLi Feng Wang 
5*1ff9903bSLi Feng Wang import org.junit.After;
6*1ff9903bSLi Feng Wang import org.junit.AfterClass;
7*1ff9903bSLi Feng Wang import org.junit.Before;
8*1ff9903bSLi Feng Wang import org.junit.Test;
9*1ff9903bSLi Feng Wang import org.openoffice.test.common.Testspace;
10*1ff9903bSLi Feng Wang import org.openoffice.test.uno.UnoApp;
11*1ff9903bSLi Feng Wang 
12*1ff9903bSLi Feng Wang import testlib.uno.SWUtil;
13*1ff9903bSLi Feng Wang 
14*1ff9903bSLi Feng Wang import com.sun.star.beans.XPropertySet;
15*1ff9903bSLi Feng Wang import com.sun.star.container.XNameAccess;
16*1ff9903bSLi Feng Wang import com.sun.star.lang.XMultiServiceFactory;
17*1ff9903bSLi Feng Wang import com.sun.star.text.XText;
18*1ff9903bSLi Feng Wang import com.sun.star.text.XTextCursor;
19*1ff9903bSLi Feng Wang import com.sun.star.text.XTextDocument;
20*1ff9903bSLi Feng Wang import com.sun.star.text.XTextFrame;
21*1ff9903bSLi Feng Wang import com.sun.star.text.XTextFramesSupplier;
22*1ff9903bSLi Feng Wang import com.sun.star.uno.UnoRuntime;
23*1ff9903bSLi Feng Wang 
24*1ff9903bSLi Feng Wang public class FrameHyperlink {
25*1ff9903bSLi Feng Wang 	private static final UnoApp app = new UnoApp();
26*1ff9903bSLi Feng Wang 	private XTextDocument xTextDocument=null;
27*1ff9903bSLi Feng Wang 	private XMultiServiceFactory xWriterFactory=null;
28*1ff9903bSLi Feng Wang 	private XText xText=null;
29*1ff9903bSLi Feng Wang 	@Before
30*1ff9903bSLi Feng Wang 	public void setUp() throws Exception {
31*1ff9903bSLi Feng Wang 		app.start();
32*1ff9903bSLi Feng Wang 	}
33*1ff9903bSLi Feng Wang 
34*1ff9903bSLi Feng Wang 	@After
35*1ff9903bSLi Feng Wang 	public void tearDown() throws Exception {
36*1ff9903bSLi Feng Wang 		app.closeDocument(xTextDocument);
37*1ff9903bSLi Feng Wang 	}
38*1ff9903bSLi Feng Wang 	@AfterClass
39*1ff9903bSLi Feng Wang 	public static void tearDownConnection() throws Exception {
40*1ff9903bSLi Feng Wang 		app.close();
41*1ff9903bSLi Feng Wang 	}
42*1ff9903bSLi Feng Wang 
43*1ff9903bSLi Feng Wang 	@Test
44*1ff9903bSLi Feng Wang 	public void testFrameHyperlink() throws Exception {
45*1ff9903bSLi Feng Wang 		xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
46*1ff9903bSLi Feng Wang 		xText=xTextDocument.getText();
47*1ff9903bSLi Feng Wang 		XTextCursor xTextCursor = xText.createTextCursor();
48*1ff9903bSLi Feng Wang 		// get internal service factory of the document
49*1ff9903bSLi Feng Wang 		xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
50*1ff9903bSLi Feng Wang 		// Create a new table from the document's factory
51*1ff9903bSLi Feng Wang 		XTextFrame xTextFrame = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame"));
52*1ff9903bSLi Feng Wang 		xText.insertTextContent(xTextCursor,xTextFrame,false);
53*1ff9903bSLi Feng Wang 		XPropertySet xTextFrameProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextFrame);
54*1ff9903bSLi Feng Wang 		xTextFrameProps.setPropertyValue("HyperLinkURL","http://www.google.com.hk/");
55*1ff9903bSLi Feng Wang 		xTextFrameProps.setPropertyValue("HyperLinkTarget","google");
56*1ff9903bSLi Feng Wang 		xTextFrameProps.setPropertyValue("HyperLinkName","FrameHyperlinkToGoogle");
57*1ff9903bSLi Feng Wang 
58*1ff9903bSLi Feng Wang 		//save and reopen the document
59*1ff9903bSLi Feng Wang 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app));
60*1ff9903bSLi Feng Wang 		XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt);
61*1ff9903bSLi Feng Wang 		XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames();
62*1ff9903bSLi Feng Wang 		XTextFrame xTextFrame_Assert=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrames_odt.getByName("Frame1"));
63*1ff9903bSLi Feng Wang 		XPropertySet xTextFrameProps_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextFrame_Assert);
64*1ff9903bSLi Feng Wang 		assertEquals("assert Frame hyperlink url","http://www.google.com.hk/", xTextFrameProps_assert.getPropertyValue("HyperLinkURL"));
65*1ff9903bSLi Feng Wang 		assertEquals("assert Frame hyperlink target","google", xTextFrameProps_assert.getPropertyValue("HyperLinkTarget"));
66*1ff9903bSLi Feng Wang 		assertEquals("assert Frame hyperlink name", "FrameHyperlinkToGoogle",xTextFrameProps_assert.getPropertyValue("HyperLinkName"));
67*1ff9903bSLi Feng Wang 	}
68*1ff9903bSLi Feng Wang }
69