Return-Path: X-Original-To: apmail-poi-commits-archive@minotaur.apache.org Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7CCEF9A10 for ; Thu, 2 Feb 2012 10:38:25 +0000 (UTC) Received: (qmail 5652 invoked by uid 500); 2 Feb 2012 10:38:24 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 5604 invoked by uid 500); 2 Feb 2012 10:38:17 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 5585 invoked by uid 99); 2 Feb 2012 10:38:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Feb 2012 10:38:12 +0000 X-ASF-Spam-Status: No, hits=-1996.9 required=5.0 tests=ALL_TRUSTED,T_FILL_THIS_FORM_SHORT,URI_OBFU_WWW X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Feb 2012 10:38:10 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7EEDD238889B for ; Thu, 2 Feb 2012 10:37:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1239529 - in /poi/trunk/src: documentation/content/xdocs/status.xml ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java Date: Thu, 02 Feb 2012 10:37:50 -0000 To: commits@poi.apache.org From: yegor@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120202103750.7EEDD238889B@eris.apache.org> Author: yegor Date: Thu Feb 2 10:37:49 2012 New Revision: 1239529 URL: http://svn.apache.org/viewvc?rev=1239529&view=rev Log: validate hyperlink address as discussed on poi-user Modified: poi/trunk/src/documentation/content/xdocs/status.xml poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java Modified: poi/trunk/src/documentation/content/xdocs/status.xml URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1239529&r1=1239528&r2=1239529&view=diff ============================================================================== --- poi/trunk/src/documentation/content/xdocs/status.xml (original) +++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Feb 2 10:37:49 2012 @@ -34,6 +34,7 @@ + Validate address of hyperlinks in XSSF 52540 - Relax the M4.1 constraint on reading OOXML files, as some Office produced ones do have 2 Core Properties, despite the specification explicitly forbidding this 52462 - Added implementation for SUMIFS() POIXMLPropertiesTextExtractor support for extracting custom OOXML properties as text Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java?rev=1239529&r1=1239528&r2=1239529&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java Thu Feb 2 10:37:49 2012 @@ -17,6 +17,7 @@ package org.apache.poi.xssf.usermodel; import java.net.URI; +import java.net.URISyntaxException; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; @@ -181,18 +182,37 @@ public class XSSFHyperlink implements Hy } /** - * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, path to a file + * Hyperlink address. Depending on the hyperlink type it can be URL, e-mail, path to a file * * @param address - the address of this hyperlink */ public void setAddress(String address) { - _location = address; + validate(address); + + _location = address; //we must set location for internal hyperlinks if (_type == Hyperlink.LINK_DOCUMENT) { setLocation(address); } } + private void validate(String address) { + switch (_type){ + // email, path to file and url must be valid URIs + case Hyperlink.LINK_EMAIL: + case Hyperlink.LINK_FILE: + case Hyperlink.LINK_URL: + try { + new URI(address); + } catch (URISyntaxException x) { + IllegalArgumentException y = new IllegalArgumentException("Address of hyperlink must be a valid URI"); + y.initCause(x); + throw y; + } + break; + } + } + /** * Assigns this hyperlink to the given cell reference */ Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java?rev=1239529&r1=1239528&r2=1239529&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java Thu Feb 2 10:37:49 2012 @@ -50,6 +50,35 @@ public final class TestXSSFHyperlink ext doTestHyperlinkContents(sheet); } + public void testCreate() { + XSSFWorkbook workbook = new XSSFWorkbook(); + XSSFCreationHelper createHelper = workbook.getCreationHelper(); + + String[] validURLs = { + "http://apache.org", + "www.apache.org", + "/temp", + "c:/temp", + "http://apache.org/default.php?s=isTramsformed&submit=Search&la=*&li=*"}; + for(String s : validURLs){ + createHelper.createHyperlink(Hyperlink.LINK_URL).setAddress(s); + } + + String[] invalidURLs = { + "http:\\apache.org", + "www.apache .org", + "c:\\temp", + "\\poi"}; + for(String s : invalidURLs){ + try { + createHelper.createHyperlink(Hyperlink.LINK_URL).setAddress(s); + fail("expected IllegalArgumentException: " + s); + } catch (IllegalArgumentException e){ + + } + } + } + public void testLoadSave() { XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx"); CreationHelper createHelper = workbook.getCreationHelper(); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org