From 595525a03c83954bdf4ccc9cef009c120f7d6f6c Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 4 Apr 2008 17:59:43 +0000 Subject: [PATCH] Create Hyperlink interface, based on HSSFHyperlink. Stub out for XSSF, but have yet to implement. (See WithMoreVariousData.xlsx for all the different kinds when implementing) git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@644797 13f79535-47bb-0310-9956-ffa450edef68 --- .../hssf/usermodel/HSSFCreationHelper.java | 8 ++ .../poi/hssf/usermodel/HSSFHyperlink.java | 13 +- .../apache/poi/ss/usermodel/Hyperlink.java | 40 ++++++ .../poi/ss/usermodel/CreationHelper.java | 6 + .../apache/poi/ss/usermodel/Hyperlink.java | 135 ++++++++++++++++++ .../xssf/usermodel/XSSFCreationHelper.java | 6 + .../poi/xssf/usermodel/XSSFHyperlink.java | 121 ++++++++++++++++ 7 files changed, 319 insertions(+), 10 deletions(-) create mode 100644 src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Hyperlink.java create mode 100644 src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Hyperlink.java create mode 100644 src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java index 79b4e9a852..42d28a7281 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java @@ -17,6 +17,7 @@ package org.apache.poi.hssf.usermodel; import org.apache.poi.ss.usermodel.CreationHelper; +import org.apache.poi.ss.usermodel.Sheet; public class HSSFCreationHelper implements CreationHelper { private HSSFWorkbook workbook; @@ -39,4 +40,11 @@ public class HSSFCreationHelper implements CreationHelper { public HSSFDataFormat createDataFormat() { return dataFormat; } + + public HSSFHyperlink createHyperlink(int type, Sheet sheetFor) { + return createHyperlink(type); + } + public HSSFHyperlink createHyperlink(int type) { + return new HSSFHyperlink(type); + } } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java b/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java index 7f1c2639c9..53d9298ee0 100755 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java @@ -16,22 +16,15 @@ ==================================================================== */ package org.apache.poi.hssf.usermodel; -import org.apache.poi.hssf.record.EscherAggregate; -import org.apache.poi.hssf.record.NoteRecord; -import org.apache.poi.hssf.record.TextObjectRecord; import org.apache.poi.hssf.record.HyperlinkRecord; -import org.apache.poi.ddf.*; - -import java.util.Map; -import java.util.List; -import java.util.Iterator; +import org.apache.poi.ss.usermodel.Hyperlink; /** * Represents an Excel hyperlink. * * @author Yegor Kozlov (yegor at apache dot org) */ -public class HSSFHyperlink { +public class HSSFHyperlink implements Hyperlink { /** * Link to a existing file or web page @@ -209,7 +202,7 @@ public class HSSFHyperlink { * * @return the type of this hyperlink */ - protected int getType(){ + public int getType(){ return link_type; } } diff --git a/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Hyperlink.java b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Hyperlink.java new file mode 100644 index 0000000000..04d7dc40a8 --- /dev/null +++ b/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Hyperlink.java @@ -0,0 +1,40 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.ss.usermodel; + +public interface Hyperlink { + /** + * Link to a existing file or web page + */ + public static final int LINK_URL = 1; + + /** + * Link to a place in this document + */ + public static final int LINK_DOCUMENT = 2; + + /** + * Link to an E-mail address + */ + public static final int LINK_EMAIL = 3; + + /** + * Link to a file + */ + public static final int LINK_FILE = 4; +} diff --git a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CreationHelper.java b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CreationHelper.java index 78fe632527..375429c6b9 100644 --- a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CreationHelper.java +++ b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CreationHelper.java @@ -39,4 +39,10 @@ public interface CreationHelper { * Creates a new DataFormat instance */ DataFormat createDataFormat(); + + /** + * Creates a new Hyperlink, of the given type, + * for the given sheet + */ + Hyperlink createHyperlink(int type, Sheet sheetFor); } \ No newline at end of file diff --git a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Hyperlink.java b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Hyperlink.java new file mode 100644 index 0000000000..c207c925ad --- /dev/null +++ b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Hyperlink.java @@ -0,0 +1,135 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.ss.usermodel; + +/** + * Represents an Excel hyperlink. + */ +public interface Hyperlink { + /** + * Link to a existing file or web page + */ + public static final int LINK_URL = 1; + + /** + * Link to a place in this document + */ + public static final int LINK_DOCUMENT = 2; + + /** + * Link to an E-mail address + */ + public static final int LINK_EMAIL = 3; + + /** + * Link to a file + */ + public static final int LINK_FILE = 4; + + /** + * Return the row of the first cell that contains the hyperlink + * + * @return the 0-based row of the cell that contains the hyperlink + */ + public int getFirstRow(); + + /** + * Set the row of the first cell that contains the hyperlink + * + * @param row the 0-based row of the first cell that contains the hyperlink + */ + public void setFirstRow(int row); + + /** + * Return the row of the last cell that contains the hyperlink + * + * @return the 0-based row of the last cell that contains the hyperlink + */ + public int getLastRow(); + + /** + * Set the row of the last cell that contains the hyperlink + * + * @param row the 0-based row of the last cell that contains the hyperlink + */ + public void setLastRow(int row); + + /** + * Return the column of the first cell that contains the hyperlink + * + * @return the 0-based column of the first cell that contains the hyperlink + */ + public short getFirstColumn(); + + /** + * Set the column of the first cell that contains the hyperlink + * + * @param col the 0-based column of the first cell that contains the hyperlink + */ + public void setFirstColumn(short col); + + /** + * Return the column of the last cell that contains the hyperlink + * + * @return the 0-based column of the last cell that contains the hyperlink + */ + public short getLastColumn(); + + /** + * Set the column of the last cell that contains the hyperlink + * + * @param col the 0-based column of the last cell that contains the hyperlink + */ + public void setLastColumn(short col); + + + + /** + * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc. + * + * @return the address of this hyperlink + */ + public String getAddress(); + + /** + * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc. + * + * @param address the address of this hyperlink + */ + public void setAddress(String address); + + /** + * Return text label for this hyperlink + * + * @return text to display + */ + public String getLabel(); + + /** + * Sets text label for this hyperlink + * + * @param label text label for this hyperlink + */ + public void setLabel(String label); + + /** + * Return the type of this hyperlink + * + * @return the type of this hyperlink + */ + public int getType(); +} diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java index 94eb5c1ec4..e22fe01fa0 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java @@ -18,7 +18,9 @@ package org.apache.poi.xssf.usermodel; import org.apache.poi.ss.usermodel.CreationHelper; import org.apache.poi.ss.usermodel.DataFormat; +import org.apache.poi.ss.usermodel.Hyperlink; import org.apache.poi.ss.usermodel.RichTextString; +import org.apache.poi.ss.usermodel.Sheet; public class XSSFCreationHelper implements CreationHelper { private XSSFWorkbook workbook; @@ -40,4 +42,8 @@ public class XSSFCreationHelper implements CreationHelper { public DataFormat createDataFormat() { return dataFormat; } + + public Hyperlink createHyperlink(int type, Sheet sheetFor) { + return new XSSFHyperlink(type, (XSSFSheet)sheetFor); + } } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java new file mode 100644 index 0000000000..feba0cf9df --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java @@ -0,0 +1,121 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.xssf.usermodel; + +import org.apache.poi.ss.usermodel.Hyperlink; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHyperlink; + +import org.openxml4j.opc.Package; +import org.openxml4j.opc.PackagePart; + +/** + * XSSF Implementation of a Hyperlink. + * Note - unlike with HSSF, many kinds of hyperlink + * are largely stored as relations of the sheet + */ +public class XSSFHyperlink implements Hyperlink { + private int type; + private XSSFSheet sheet; + private CTHyperlink ctHyperlink; + + protected XSSFHyperlink(int type, XSSFSheet sheet) { + this.type = type; + this.sheet = sheet; + this.ctHyperlink = CTHyperlink.Factory.newInstance(); + } + protected XSSFHyperlink(CTHyperlink ctHyperlink, XSSFSheet sheet) { + this.sheet = sheet; + this.ctHyperlink = ctHyperlink; + + // Figure out the Hyperlink type + // TODO + } + + /** + * Returns the underlying hyperlink object + */ + protected CTHyperlink getCTHyperlink() { + return ctHyperlink; + } + + /** + * Do we need to a relation too, to represent + * this hyperlink? + */ + public boolean needsRelationToo() { + // TODO + return false; + } + + /** + * Generates the relation if required + */ + protected void generateRelationIfNeeded(Package pkg, PackagePart sheetPart) { + // TODO + } + + public int getType() { + return type; + } + + public String getAddress() { + // TODO Auto-generated method stub + return null; + } + public String getLabel() { + // TODO Auto-generated method stub + return null; + } + + public void setLabel(String label) { + // TODO Auto-generated method stub + } + public void setAddress(String address) { + // TODO Auto-generated method stub + + } + + public short getFirstColumn() { + // TODO Auto-generated method stub + return 0; + } + public int getFirstRow() { + // TODO Auto-generated method stub + return 0; + } + public short getLastColumn() { + // TODO Auto-generated method stub + return 0; + } + public int getLastRow() { + // TODO Auto-generated method stub + return 0; + } + + public void setFirstColumn(short col) { + // TODO Auto-generated method stub + } + public void setFirstRow(int row) { + // TODO Auto-generated method stub + } + public void setLastColumn(short col) { + // TODO Auto-generated method stub + } + public void setLastRow(int row) { + // TODO Auto-generated method stub + } +} -- 2.39.5