bug 59783: replace deprecated Hyperlink.LINK_* and Hyperlink.getType usage

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753040 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-07-17 09:32:29 +00:00
parent 146839d0ce
commit 31f2b5fdd1
4 changed files with 49 additions and 47 deletions

View File

@ -1109,15 +1109,15 @@ public class HSSFCell implements Cell {
link.setFirstColumn(_record.getColumn());
link.setLastColumn(_record.getColumn());
switch(link.getType()){
case HSSFHyperlink.LINK_EMAIL:
case HSSFHyperlink.LINK_URL:
switch(link.getTypeEnum()){
case EMAIL:
case URL:
link.setLabel("url");
break;
case HSSFHyperlink.LINK_FILE:
case FILE:
link.setLabel("file");
break;
case HSSFHyperlink.LINK_DOCUMENT:
case DOCUMENT:
link.setLabel("place");
break;
default:

View File

@ -71,7 +71,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
"http://apache.org/default.php?s=isTramsformed&submit=Search&la=*&li=*"};
for(int i = 0; i < urls.length; i++){
String s = urls[i];
XSSFHyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
XSSFHyperlink link = createHelper.createHyperlink(HyperlinkType.URL);
link.setAddress(s);
XSSFCell cell = row.createCell(i);
@ -111,7 +111,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
"\\poi"};
for(String s : invalidURLs){
try {
createHelper.createHyperlink(Hyperlink.LINK_URL).setAddress(s);
createHelper.createHyperlink(HyperlinkType.URL).setAddress(s);
fail("expected IllegalArgumentException: " + s);
} catch (IllegalArgumentException e){
@ -153,7 +153,7 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
Row r17 = sheet.createRow(17);
Cell r17c = r17.createCell(2);
Hyperlink hyperlink = createHelper.createHyperlink(Hyperlink.LINK_URL);
Hyperlink hyperlink = createHelper.createHyperlink(HyperlinkType.URL);
hyperlink.setAddress("http://poi.apache.org/spreadsheet/");
hyperlink.setLabel("POI SS Link");
r17c.setHyperlink(hyperlink);
@ -161,8 +161,8 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
assertEquals(5, sheet.getNumHyperlinks());
doTestHyperlinkContents(sheet);
assertEquals(Hyperlink.LINK_URL,
sheet.getRow(17).getCell(2).getHyperlink().getType());
assertEquals(HyperlinkType.URL,
sheet.getRow(17).getCell(2).getHyperlink().getTypeEnum());
assertEquals("POI SS Link",
sheet.getRow(17).getCell(2).getHyperlink().getLabel());
assertEquals("http://poi.apache.org/spreadsheet/",
@ -182,8 +182,8 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
assertEquals(5, sheet.getNumHyperlinks());
doTestHyperlinkContents(sheet);
assertEquals(Hyperlink.LINK_URL,
sheet.getRow(17).getCell(2).getHyperlink().getType());
assertEquals(HyperlinkType.URL,
sheet.getRow(17).getCell(2).getHyperlink().getTypeEnum());
assertEquals("POI SS Link",
sheet.getRow(17).getCell(2).getHyperlink().getLabel());
assertEquals("http://poi.apache.org/spreadsheet/",
@ -200,32 +200,32 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
assertNotNull(sheet.getRow(16).getCell(2).getHyperlink());
// First is a link to poi
assertEquals(Hyperlink.LINK_URL,
sheet.getRow(3).getCell(2).getHyperlink().getType());
assertEquals(HyperlinkType.URL,
sheet.getRow(3).getCell(2).getHyperlink().getTypeEnum());
assertEquals(null,
sheet.getRow(3).getCell(2).getHyperlink().getLabel());
assertEquals("http://poi.apache.org/",
sheet.getRow(3).getCell(2).getHyperlink().getAddress());
// Next is an internal doc link
assertEquals(Hyperlink.LINK_DOCUMENT,
sheet.getRow(14).getCell(2).getHyperlink().getType());
assertEquals(HyperlinkType.DOCUMENT,
sheet.getRow(14).getCell(2).getHyperlink().getTypeEnum());
assertEquals("Internal hyperlink to A2",
sheet.getRow(14).getCell(2).getHyperlink().getLabel());
assertEquals("Sheet1!A2",
sheet.getRow(14).getCell(2).getHyperlink().getAddress());
// Next is a file
assertEquals(Hyperlink.LINK_FILE,
sheet.getRow(15).getCell(2).getHyperlink().getType());
assertEquals(HyperlinkType.FILE,
sheet.getRow(15).getCell(2).getHyperlink().getTypeEnum());
assertEquals(null,
sheet.getRow(15).getCell(2).getHyperlink().getLabel());
assertEquals("WithVariousData.xlsx",
sheet.getRow(15).getCell(2).getHyperlink().getAddress());
// Last is a mailto
assertEquals(Hyperlink.LINK_EMAIL,
sheet.getRow(16).getCell(2).getHyperlink().getType());
assertEquals(HyperlinkType.EMAIL,
sheet.getRow(16).getCell(2).getHyperlink().getTypeEnum());
assertEquals(null,
sheet.getRow(16).getCell(2).getHyperlink().getLabel());
assertEquals("mailto:dev@poi.apache.org?subject=XSSF%20Hyperlinks",
@ -242,13 +242,13 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
assertEquals(sh1.getNumberOfComments(), sh2.getNumberOfComments());
XSSFHyperlink l1 = sh1.getHyperlink(0, 1);
assertEquals(XSSFHyperlink.LINK_DOCUMENT, l1.getType());
assertEquals(HyperlinkType.DOCUMENT, l1.getTypeEnum());
assertEquals("B1", l1.getCellRef());
assertEquals("Sort on Titel", l1.getTooltip());
XSSFHyperlink l2 = sh2.getHyperlink(0, 1);
assertEquals(l1.getTooltip(), l2.getTooltip());
assertEquals(XSSFHyperlink.LINK_DOCUMENT, l2.getType());
assertEquals(HyperlinkType.DOCUMENT, l2.getTypeEnum());
assertEquals("B1", l2.getCellRef());
}
@ -313,22 +313,22 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
XSSFHyperlink link = sh.getHyperlink(A2);
assertEquals("address", "A2", link.getCellRef());
assertEquals("link type", Hyperlink.LINK_URL, link.getType());
assertEquals("link type", HyperlinkType.URL, link.getTypeEnum());
assertEquals("link target", "http://twitter.com/#!/apacheorg", link.getAddress());
link = sh.getHyperlink(A3);
assertEquals("address", "A3", link.getCellRef());
assertEquals("link type", Hyperlink.LINK_URL, link.getType());
assertEquals("link type", HyperlinkType.URL, link.getTypeEnum());
assertEquals("link target", "http://www.bailii.org/databases.html#ie", link.getAddress());
link = sh.getHyperlink(A4);
assertEquals("address", "A4", link.getCellRef());
assertEquals("link type", Hyperlink.LINK_URL, link.getType());
assertEquals("link type", HyperlinkType.URL, link.getTypeEnum());
assertEquals("link target", "https://en.wikipedia.org/wiki/Apache_POI#See_also", link.getAddress());
link = sh.getHyperlink(A7);
assertEquals("address", "A7", link.getCellRef());
assertEquals("link type", Hyperlink.LINK_DOCUMENT, link.getType());
assertEquals("link type", HyperlinkType.DOCUMENT, link.getTypeEnum());
assertEquals("link target", "Sheet1", link.getAddress());
wb.close();

View File

@ -20,10 +20,10 @@ package org.apache.poi.hssf.usermodel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import java.io.IOException;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.BaseTestHyperlink;
@ -34,6 +34,7 @@ import org.apache.poi.xssf.usermodel.XSSFCreationHelper;
import org.apache.poi.xssf.usermodel.XSSFHyperlink;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
*/
import org.junit.Test;
/**
* Tests HSSFHyperlink.
@ -64,7 +65,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
assertEquals("POI", link.getLabel());
assertEquals("POI", cell.getRichStringCellValue().getString());
assertEquals("http://poi.apache.org/", link.getAddress());
assertEquals(HSSFHyperlink.LINK_URL, link.getType());
assertEquals(HyperlinkType.URL, link.getTypeEnum());
cell = sheet.getRow(8).getCell(0);
link = cell.getHyperlink();
@ -72,7 +73,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
assertEquals("HSSF", link.getLabel());
assertEquals("HSSF", cell.getRichStringCellValue().getString());
assertEquals("http://poi.apache.org/hssf/", link.getAddress());
assertEquals(HSSFHyperlink.LINK_URL, link.getType());
assertEquals(HyperlinkType.URL, link.getTypeEnum());
sheet = wb.getSheet("Emails");
cell = sheet.getRow(4).getCell(0);
@ -81,7 +82,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
assertEquals("dev", link.getLabel());
assertEquals("dev", cell.getRichStringCellValue().getString());
assertEquals("mailto:dev@poi.apache.org", link.getAddress());
assertEquals(HSSFHyperlink.LINK_EMAIL, link.getType());
assertEquals(HyperlinkType.EMAIL, link.getTypeEnum());
sheet = wb.getSheet("Internal");
cell = sheet.getRow(4).getCell(0);
@ -91,7 +92,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
assertEquals("Link To First Sheet", cell.getRichStringCellValue().getString());
assertEquals("WebLinks!A1", link.getTextMark());
assertEquals("WebLinks!A1", link.getAddress());
assertEquals(HSSFHyperlink.LINK_DOCUMENT, link.getType());
assertEquals(HyperlinkType.DOCUMENT, link.getTypeEnum());
}
@Test
@ -141,14 +142,14 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
//cell A1 has a link to 'Target Sheet-1'!A1
cell = sheet.createRow(0).createCell(0);
cell.setCellValue("Worksheet Link");
link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
link = new HSSFHyperlink(HyperlinkType.DOCUMENT);
link.setTextMark("'Target Sheet'!A1");
cell.setHyperlink(link);
//cell B1 has a link to cell A1 on the same sheet
cell = sheet.createRow(1).createCell(0);
cell.setCellValue("Worksheet Link");
link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
link = new HSSFHyperlink(HyperlinkType.DOCUMENT);
link.setAddress("'Hyperlinks'!A1");
cell.setHyperlink(link);
@ -202,7 +203,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
cell = sheet.createRow(1).createCell(0);
cell.setCellValue("File Link");
link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE);
link = new HSSFHyperlink(HyperlinkType.FILE);
link.setAddress("testfolder\\test.PDF");
cell.setHyperlink(link);
@ -239,7 +240,7 @@ public final class TestHSSFHyperlink extends BaseTestHyperlink {
assertEquals(2, link1.getLastRow());
//assign a hyperlink to A4
HSSFHyperlink link2 = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
HSSFHyperlink link2 = new HSSFHyperlink(HyperlinkType.DOCUMENT);
link2.setAddress("Sheet2!A2");
HSSFCell cell2 = sheet.getRow(3).getCell(0);
cell2.setHyperlink(link2);

View File

@ -28,6 +28,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
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.util.CellAddress;
@ -514,32 +515,32 @@ public abstract class BaseTestSheetShiftRows {
// CellAddress=A1, shifted to A4
Cell cell = row.createCell(0);
cell.setCellStyle(hlinkStyle);
createHyperlink(helper, cell, Hyperlink.LINK_DOCUMENT, "test!E1");
createHyperlink(helper, cell, HyperlinkType.DOCUMENT, "test!E1");
// URL
cell = row.createCell(1);
// CellAddress=B1, shifted to B4
cell.setCellStyle(hlinkStyle);
createHyperlink(helper, cell, Hyperlink.LINK_URL, "http://poi.apache.org/");
createHyperlink(helper, cell, HyperlinkType.URL, "http://poi.apache.org/");
// row0 will be shifted on top of row1, so this URL should be removed from the workbook
Row overwrittenRow = sheet.createRow(3);
cell = overwrittenRow.createCell(2);
// CellAddress=C4, will be overwritten (deleted)
cell.setCellStyle(hlinkStyle);
createHyperlink(helper, cell, Hyperlink.LINK_EMAIL, "mailto:poi@apache.org");
createHyperlink(helper, cell, HyperlinkType.EMAIL, "mailto:poi@apache.org");
// hyperlinks on this row are unaffected by the row shifting, so the hyperlinks should not move
Row unaffectedRow = sheet.createRow(20);
cell = unaffectedRow.createCell(3);
// CellAddress=D21, will be unaffected
cell.setCellStyle(hlinkStyle);
createHyperlink(helper, cell, Hyperlink.LINK_FILE, "54524.xlsx");
createHyperlink(helper, cell, HyperlinkType.FILE, "54524.xlsx");
cell = wb.createSheet("other").createRow(0).createCell(0);
// CellAddress=Other!A1, will be unaffected
cell.setCellStyle(hlinkStyle);
createHyperlink(helper, cell, Hyperlink.LINK_URL, "http://apache.org/");
createHyperlink(helper, cell, HyperlinkType.URL, "http://apache.org/");
int startRow = 0;
int endRow = 0;
@ -555,10 +556,10 @@ public abstract class BaseTestSheetShiftRows {
// document link anchored on a shifted cell should be moved
// Note that hyperlinks do not track what they point to, so this hyperlink should still refer to test!E1
verifyHyperlink(shiftedRow.getCell(0), Hyperlink.LINK_DOCUMENT, "test!E1");
verifyHyperlink(shiftedRow.getCell(0), HyperlinkType.DOCUMENT, "test!E1");
// URL, EMAIL, and FILE links anchored on a shifted cell should be moved
verifyHyperlink(shiftedRow.getCell(1), Hyperlink.LINK_URL, "http://poi.apache.org/");
verifyHyperlink(shiftedRow.getCell(1), HyperlinkType.URL, "http://poi.apache.org/");
// Make sure hyperlinks were moved and not copied
assertNull("Document hyperlink should be moved, not copied", sh.getHyperlink(0, 0));
@ -578,12 +579,12 @@ public abstract class BaseTestSheetShiftRows {
// Make sure unaffected rows are not shifted
Cell unaffectedCell = sh.getRow(20).getCell(3);
assertTrue(cellHasHyperlink(unaffectedCell));
verifyHyperlink(unaffectedCell, Hyperlink.LINK_FILE, "54524.xlsx");
verifyHyperlink(unaffectedCell, HyperlinkType.FILE, "54524.xlsx");
// Make sure cells on other sheets are not affected
unaffectedCell = read.getSheet("other").getRow(0).getCell(0);
assertTrue(cellHasHyperlink(unaffectedCell));
verifyHyperlink(unaffectedCell, Hyperlink.LINK_URL, "http://apache.org/");
verifyHyperlink(unaffectedCell, HyperlinkType.URL, "http://apache.org/");
read.close();
}
@ -678,17 +679,17 @@ public abstract class BaseTestSheetShiftRows {
wb.close();
}
private void createHyperlink(CreationHelper helper, Cell cell, int linkType, String ref) {
private void createHyperlink(CreationHelper helper, Cell cell, HyperlinkType linkType, String ref) {
cell.setCellValue(ref);
Hyperlink link = helper.createHyperlink(linkType);
link.setAddress(ref);
cell.setHyperlink(link);
}
private void verifyHyperlink(Cell cell, int linkType, String ref) {
private void verifyHyperlink(Cell cell, HyperlinkType linkType, String ref) {
assertTrue(cellHasHyperlink(cell));
Hyperlink link = cell.getHyperlink();
assertEquals(linkType, link.getType());
assertEquals(linkType, link.getTypeEnum());
assertEquals(ref, link.getAddress());
}