bug 59783: replace deprecated Hyperlink.LINK_* and Hyperlink.getType usage
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753041 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
31f2b5fdd1
commit
2944b7a7a8
@ -18,9 +18,16 @@ package org.apache.poi.xssf.usermodel.examples;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.CreationHelper;
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
import org.apache.poi.ss.usermodel.Hyperlink;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
/**
|
||||
* Demonstrates how to create hyperlinks.
|
||||
@ -43,26 +50,26 @@ public class HyperlinkExample {
|
||||
Cell cell;
|
||||
Sheet sheet = wb.createSheet("Hyperlinks");
|
||||
//URL
|
||||
cell = sheet.createRow(0).createCell((short)0);
|
||||
cell = sheet.createRow(0).createCell(0);
|
||||
cell.setCellValue("URL Link");
|
||||
|
||||
Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
|
||||
Hyperlink link = createHelper.createHyperlink(HyperlinkType.URL);
|
||||
link.setAddress("http://poi.apache.org/");
|
||||
cell.setHyperlink(link);
|
||||
cell.setCellStyle(hlink_style);
|
||||
|
||||
//link to a file in the current directory
|
||||
cell = sheet.createRow(1).createCell((short)0);
|
||||
cell = sheet.createRow(1).createCell(0);
|
||||
cell.setCellValue("File Link");
|
||||
link = createHelper.createHyperlink(Hyperlink.LINK_FILE);
|
||||
link = createHelper.createHyperlink(HyperlinkType.FILE);
|
||||
link.setAddress("link1.xls");
|
||||
cell.setHyperlink(link);
|
||||
cell.setCellStyle(hlink_style);
|
||||
|
||||
//e-mail link
|
||||
cell = sheet.createRow(2).createCell((short)0);
|
||||
cell = sheet.createRow(2).createCell(0);
|
||||
cell.setCellValue("Email Link");
|
||||
link = createHelper.createHyperlink(Hyperlink.LINK_EMAIL);
|
||||
link = createHelper.createHyperlink(HyperlinkType.EMAIL);
|
||||
//note, if subject contains white spaces, make sure they are url-encoded
|
||||
link.setAddress("mailto:poi@apache.org?subject=Hyperlinks");
|
||||
cell.setHyperlink(link);
|
||||
@ -72,11 +79,11 @@ public class HyperlinkExample {
|
||||
|
||||
//create a target sheet and cell
|
||||
Sheet sheet2 = wb.createSheet("Target Sheet");
|
||||
sheet2.createRow(0).createCell((short)0).setCellValue("Target Cell");
|
||||
sheet2.createRow(0).createCell(0).setCellValue("Target Cell");
|
||||
|
||||
cell = sheet.createRow(3).createCell((short)0);
|
||||
cell = sheet.createRow(3).createCell(0);
|
||||
cell.setCellValue("Worksheet Link");
|
||||
Hyperlink link2 = createHelper.createHyperlink(Hyperlink.LINK_DOCUMENT);
|
||||
Hyperlink link2 = createHelper.createHyperlink(HyperlinkType.DOCUMENT);
|
||||
link2.setAddress("'Target Sheet'!A1");
|
||||
cell.setHyperlink(link2);
|
||||
cell.setCellStyle(hlink_style);
|
||||
|
@ -42,7 +42,7 @@ public class XSSFHyperlink implements Hyperlink {
|
||||
* Create a new XSSFHyperlink. This method is protected to be used only by {@link XSSFCreationHelper#createHyperlink(int)}
|
||||
*
|
||||
* @param type - the type of hyperlink to create, see {@link Hyperlink}
|
||||
* @deprecated POI 3.15 beta 3. Use {@link XSSFHyperlink(Hyperlink)} instead.
|
||||
* @deprecated POI 3.15 beta 3. Use {@link #XSSFHyperlink(Hyperlink)} instead.
|
||||
*/
|
||||
protected XSSFHyperlink(int type) {
|
||||
this(HyperlinkType.forInt(type));
|
||||
|
@ -23,10 +23,10 @@ import java.awt.geom.Rectangle2D;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||
import org.apache.poi.openxml4j.opc.TargetMode;
|
||||
import org.apache.poi.sl.usermodel.Hyperlink;
|
||||
import org.apache.poi.xslf.XSLFTestDataSamples;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -146,31 +146,31 @@ public class TestXSLFHyperlink {
|
||||
hl1 = tb1.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
|
||||
assertNotNull(hl1);
|
||||
assertEquals("dev@poi.apache.org", hl1.getLabel());
|
||||
assertEquals(Hyperlink.LINK_EMAIL, hl1.getType());
|
||||
assertEquals(HyperlinkType.EMAIL, hl1.getTypeEnum());
|
||||
|
||||
tb2 = (XSLFTextBox)slides.get(1).getShapes().get(0);
|
||||
hl2 = tb2.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
|
||||
assertNotNull(hl2);
|
||||
assertEquals("lastslide", hl2.getXmlObject().getAction().split("=")[1]);
|
||||
assertEquals(Hyperlink.LINK_DOCUMENT, hl2.getType());
|
||||
assertEquals(HyperlinkType.DOCUMENT, hl2.getTypeEnum());
|
||||
|
||||
tb3 = (XSLFTextBox)slides.get(2).getShapes().get(0);
|
||||
hl3 = tb3.getTextParagraphs().get(0).getTextRuns().get(3).getHyperlink();
|
||||
assertNotNull(hl3);
|
||||
assertEquals("/ppt/slides/slide1.xml", hl3.getAddress());
|
||||
assertEquals(Hyperlink.LINK_DOCUMENT, hl3.getType());
|
||||
assertEquals(HyperlinkType.DOCUMENT, hl3.getTypeEnum());
|
||||
|
||||
tb4 = (XSLFTextBox)slides.get(3).getShapes().get(0);
|
||||
hl4 = tb4.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
|
||||
assertNotNull(hl4);
|
||||
assertEquals("http://poi.apache.org", hl4.getLabel());
|
||||
assertEquals(Hyperlink.LINK_URL, hl4.getType());
|
||||
assertEquals(HyperlinkType.URL, hl4.getTypeEnum());
|
||||
|
||||
tb5 = (XSLFTextBox)slides.get(4).getShapes().get(0);
|
||||
hl5 = tb5.getHyperlink();
|
||||
assertNotNull(hl5);
|
||||
assertEquals("firstslide", hl5.getXmlObject().getAction().split("=")[1]);
|
||||
assertEquals(Hyperlink.LINK_DOCUMENT, hl5.getType());
|
||||
assertEquals(HyperlinkType.DOCUMENT, hl5.getTypeEnum());
|
||||
|
||||
ppt2.close();
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ import org.apache.poi.POIXMLDocumentPart;
|
||||
import org.apache.poi.POIXMLDocumentPart.RelationPart;
|
||||
import org.apache.poi.POIXMLException;
|
||||
import org.apache.poi.POIXMLProperties;
|
||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
@ -1841,7 +1842,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
||||
XSSFHyperlink hyperlink;
|
||||
|
||||
// Try with a cell reference
|
||||
hyperlink = creationHelper.createHyperlink(Hyperlink.LINK_URL);
|
||||
hyperlink = creationHelper.createHyperlink(HyperlinkType.URL);
|
||||
sheet.addHyperlink(hyperlink);
|
||||
hyperlink.setAddress("http://myurl");
|
||||
hyperlink.setCellReference("B4");
|
||||
@ -1851,7 +1852,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
||||
assertEquals(1, hyperlink.getLastColumn());
|
||||
|
||||
// Try with explicit rows / columns
|
||||
hyperlink = creationHelper.createHyperlink(Hyperlink.LINK_URL);
|
||||
hyperlink = creationHelper.createHyperlink(HyperlinkType.URL);
|
||||
sheet.addHyperlink(hyperlink);
|
||||
hyperlink.setAddress("http://myurl");
|
||||
hyperlink.setFirstRow(5);
|
||||
|
@ -27,6 +27,7 @@ import static org.junit.Assert.assertTrue;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||
import org.apache.poi.hssf.HSSFITestDataProvider;
|
||||
import org.apache.poi.ss.SpreadsheetVersion;
|
||||
import org.apache.poi.ss.usermodel.BaseTestXCell;
|
||||
@ -565,7 +566,7 @@ public final class TestXSSFCell extends BaseTestXCell {
|
||||
final CreationHelper createHelper = wb.getCreationHelper();
|
||||
|
||||
srcCell.setCellValue("URL LINK");
|
||||
Hyperlink link = createHelper.createHyperlink(org.apache.poi.common.usermodel.Hyperlink.LINK_URL);
|
||||
Hyperlink link = createHelper.createHyperlink(HyperlinkType.URL);
|
||||
link.setAddress("http://poi.apache.org/");
|
||||
srcCell.setHyperlink(link);
|
||||
|
||||
@ -602,7 +603,7 @@ public final class TestXSSFCell extends BaseTestXCell {
|
||||
final CreationHelper createHelper = wb.getCreationHelper();
|
||||
|
||||
srcCell.setCellValue("URL LINK");
|
||||
Hyperlink link = createHelper.createHyperlink(org.apache.poi.common.usermodel.Hyperlink.LINK_URL);
|
||||
Hyperlink link = createHelper.createHyperlink(HyperlinkType.URL);
|
||||
link.setAddress("http://poi.apache.org/");
|
||||
destCell.setHyperlink(link);
|
||||
|
||||
|
@ -28,6 +28,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||
import org.apache.poi.hslf.HSLFTestDataSamples;
|
||||
import org.apache.poi.hslf.record.InteractiveInfoAtom;
|
||||
import org.apache.poi.hslf.usermodel.HSLFHyperlink;
|
||||
@ -128,31 +129,31 @@ public final class TestHyperlink {
|
||||
hl1 = tb1.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
|
||||
assertNotNull(hl1);
|
||||
assertEquals("dev@poi.apache.org", hl1.getLabel());
|
||||
assertEquals(Hyperlink.LINK_EMAIL, hl1.getType());
|
||||
assertEquals(HyperlinkType.EMAIL, hl1.getTypeEnum());
|
||||
|
||||
HSLFTextBox tb2 = (HSLFTextBox)slides.get(1).getShapes().get(0);
|
||||
hl2 = tb2.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
|
||||
assertNotNull(hl2);
|
||||
assertEquals(InteractiveInfoAtom.LINK_LastSlide, hl2.getInfo().getInteractiveInfoAtom().getHyperlinkType());
|
||||
assertEquals(Hyperlink.LINK_DOCUMENT, hl2.getType());
|
||||
assertEquals(HyperlinkType.DOCUMENT, hl2.getTypeEnum());
|
||||
|
||||
HSLFTextBox tb3 = (HSLFTextBox)slides.get(2).getShapes().get(0);
|
||||
hl3 = tb3.getTextParagraphs().get(0).getTextRuns().get(1).getHyperlink();
|
||||
assertNotNull(hl3);
|
||||
assertEquals(ppt2.getSlides().get(0)._getSheetNumber(), Integer.parseInt(hl3.getAddress().split(",")[0]));
|
||||
assertEquals(Hyperlink.LINK_DOCUMENT, hl3.getType());
|
||||
assertEquals(HyperlinkType.DOCUMENT, hl3.getTypeEnum());
|
||||
|
||||
HSLFTextBox tb4 = (HSLFTextBox)slides.get(3).getShapes().get(0);
|
||||
hl4 = tb4.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
|
||||
assertNotNull(hl4);
|
||||
assertEquals("http://poi.apache.org", hl4.getLabel());
|
||||
assertEquals(Hyperlink.LINK_URL, hl4.getType());
|
||||
assertEquals(HyperlinkType.URL, hl4.getTypeEnum());
|
||||
|
||||
tb5 = (HSLFTextBox)slides.get(4).getShapes().get(0);
|
||||
hl5 = tb5.getHyperlink();
|
||||
assertNotNull(hl5);
|
||||
assertEquals(InteractiveInfoAtom.LINK_FirstSlide, hl5.getInfo().getInteractiveInfoAtom().getHyperlinkType());
|
||||
assertEquals(Hyperlink.LINK_DOCUMENT, hl5.getType());
|
||||
assertEquals(HyperlinkType.DOCUMENT, hl5.getTypeEnum());
|
||||
|
||||
ppt2.close();
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import static org.junit.Assert.fail;
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
import org.apache.poi.ss.SpreadsheetVersion;
|
||||
@ -771,21 +772,21 @@ public abstract class BaseTestCell {
|
||||
CreationHelper helper = wb1.getCreationHelper();
|
||||
|
||||
Cell cell1 = row.createCell(1);
|
||||
Hyperlink link1 = helper.createHyperlink(Hyperlink.LINK_URL);
|
||||
Hyperlink link1 = helper.createHyperlink(HyperlinkType.URL);
|
||||
cell1.setHyperlink(link1);
|
||||
assertNotNull(cell1.getHyperlink());
|
||||
cell1.removeHyperlink();
|
||||
assertNull(cell1.getHyperlink());
|
||||
|
||||
Cell cell2 = row.createCell(0);
|
||||
Hyperlink link2 = helper.createHyperlink(Hyperlink.LINK_URL);
|
||||
Hyperlink link2 = helper.createHyperlink(HyperlinkType.URL);
|
||||
cell2.setHyperlink(link2);
|
||||
assertNotNull(cell2.getHyperlink());
|
||||
cell2.setHyperlink(null);
|
||||
assertNull(cell2.getHyperlink());
|
||||
|
||||
Cell cell3 = row.createCell(2);
|
||||
Hyperlink link3 = helper.createHyperlink(Hyperlink.LINK_URL);
|
||||
Hyperlink link3 = helper.createHyperlink(HyperlinkType.URL);
|
||||
link3.setAddress("http://poi.apache.org/");
|
||||
cell3.setHyperlink(link3);
|
||||
assertNotNull(cell3.getHyperlink());
|
||||
|
@ -25,7 +25,7 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
|
||||
/**
|
||||
@ -53,21 +53,21 @@ public abstract class BaseTestHyperlink {
|
||||
//URL
|
||||
cell = sheet.createRow(0).createCell((short) 0);
|
||||
cell.setCellValue("URL Link");
|
||||
link = createHelper.createHyperlink(Hyperlink.LINK_URL);
|
||||
link = createHelper.createHyperlink(HyperlinkType.URL);
|
||||
link.setAddress("http://poi.apache.org/");
|
||||
cell.setHyperlink(link);
|
||||
|
||||
//link to a file in the current directory
|
||||
cell = sheet.createRow(1).createCell((short) 0);
|
||||
cell.setCellValue("File Link");
|
||||
link = createHelper.createHyperlink(Hyperlink.LINK_FILE);
|
||||
link = createHelper.createHyperlink(HyperlinkType.FILE);
|
||||
link.setAddress("hyperinks-beta4-dump.txt");
|
||||
cell.setHyperlink(link);
|
||||
|
||||
//e-mail link
|
||||
cell = sheet.createRow(2).createCell((short) 0);
|
||||
cell.setCellValue("Email Link");
|
||||
link = createHelper.createHyperlink(Hyperlink.LINK_EMAIL);
|
||||
link = createHelper.createHyperlink(HyperlinkType.EMAIL);
|
||||
//note, if subject contains white spaces, make sure they are url-encoded
|
||||
link.setAddress("mailto:poi@apache.org?subject=Hyperlinks");
|
||||
cell.setHyperlink(link);
|
||||
@ -80,7 +80,7 @@ public abstract class BaseTestHyperlink {
|
||||
|
||||
cell = sheet.createRow(3).createCell((short) 0);
|
||||
cell.setCellValue("Worksheet Link");
|
||||
link = createHelper.createHyperlink(Hyperlink.LINK_DOCUMENT);
|
||||
link = createHelper.createHyperlink(HyperlinkType.DOCUMENT);
|
||||
link.setAddress("'Target Sheet'!A1");
|
||||
cell.setHyperlink(link);
|
||||
|
||||
@ -116,7 +116,7 @@ public abstract class BaseTestHyperlink {
|
||||
cell1 = row.createCell(0);
|
||||
cell2 = row.createCell(1);
|
||||
cell1.setCellValue("URL Link");
|
||||
link1 = createHelper.createHyperlink(Hyperlink.LINK_URL);
|
||||
link1 = createHelper.createHyperlink(HyperlinkType.URL);
|
||||
link1.setAddress("http://poi.apache.org/");
|
||||
cell1.setHyperlink(link1);
|
||||
|
||||
|
@ -37,6 +37,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
import org.apache.poi.ss.SpreadsheetVersion;
|
||||
import org.apache.poi.ss.util.CellAddress;
|
||||
@ -1212,7 +1213,7 @@ public abstract class BaseTestSheet {
|
||||
@Test
|
||||
public void getHyperlink() throws IOException {
|
||||
Workbook workbook = _testDataProvider.createWorkbook();
|
||||
Hyperlink hyperlink = workbook.getCreationHelper().createHyperlink(Hyperlink.LINK_URL);
|
||||
Hyperlink hyperlink = workbook.getCreationHelper().createHyperlink(HyperlinkType.URL);
|
||||
hyperlink.setAddress("https://poi.apache.org/");
|
||||
|
||||
Sheet sheet = workbook.createSheet();
|
||||
|
Loading…
Reference in New Issue
Block a user