01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17: package org.apache.poi.hslf.model;
18:
19: import junit.framework.TestCase;
20:
21: import java.io.FileInputStream;
22: import java.io.File;
23:
24: import org.apache.poi.hslf.usermodel.SlideShow;
25:
26: /**
27: * Test Hyperlink.
28: *
29: * @author Yegor Kozlov
30: */
31: public class TestHyperlink extends TestCase {
32: protected String cwd = System.getProperty("HSLF.testdata.path");
33:
34: public void testTextRunHyperlinks() throws Exception {
35: FileInputStream is = new FileInputStream(new File(cwd,
36: "WithLinks.ppt"));
37: SlideShow ppt = new SlideShow(is);
38: is.close();
39:
40: TextRun[] run;
41: Slide slide;
42: slide = ppt.getSlides()[0];
43: run = slide.getTextRuns();
44: for (int i = 0; i < run.length; i++) {
45: String text = run[i].getText();
46: if (text.equals("This page has two links:\n"
47: + "http://jakarta.apache.org/poi/\n" + "\n"
48: + "http://slashdot.org/\n" + "\n"
49: + "In addition, its notes has one link")) {
50:
51: Hyperlink[] links = run[i].getHyperlinks();
52: assertNotNull(links);
53: assertEquals(2, links.length);
54:
55: assertEquals("http://jakarta.apache.org/poi/", links[0]
56: .getTitle());
57: assertEquals("http://jakarta.apache.org/poi/", links[0]
58: .getAddress());
59: assertEquals("http://jakarta.apache.org/poi/", text
60: .substring(links[0].getStartIndex(), links[0]
61: .getEndIndex() - 1));
62:
63: assertEquals("http://slashdot.org/", links[1]
64: .getTitle());
65: assertEquals("http://slashdot.org/", links[1]
66: .getAddress());
67: assertEquals("http://slashdot.org/", text.substring(
68: links[1].getStartIndex(), links[1]
69: .getEndIndex() - 1));
70:
71: }
72: }
73:
74: slide = ppt.getSlides()[1];
75: run = slide.getTextRuns();
76: for (int i = 0; i < run.length; i++) {
77: String text = run[i].getText();
78: if (text.equals("I have the one link:\n" + "Jakarta HSSF")) {
79:
80: Hyperlink[] links = run[i].getHyperlinks();
81: assertNotNull(links);
82: assertEquals(1, links.length);
83:
84: assertEquals("http://jakarta.apache.org/poi/hssf/",
85: links[0].getTitle());
86: assertEquals("http://jakarta.apache.org/poi/hssf/",
87: links[0].getAddress());
88: assertEquals("Jakarta HSSF", text.substring(links[0]
89: .getStartIndex(), links[0].getEndIndex() - 1));
90:
91: }
92: }
93:
94: }
95:
96: }
|