Return-Path: Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: (qmail 65955 invoked from network); 11 Jan 2010 12:20:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 11 Jan 2010 12:20:04 -0000 Received: (qmail 33309 invoked by uid 500); 11 Jan 2010 12:20:04 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 33275 invoked by uid 500); 11 Jan 2010 12:20:04 -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 33266 invoked by uid 99); 11 Jan 2010 12:20:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Jan 2010 12:20:04 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED 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; Mon, 11 Jan 2010 12:20:03 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3D7AD23888E2; Mon, 11 Jan 2010 12:19:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r897847 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hsmf/MAPIMessage.java testcases/org/apache/poi/hsmf/TestBasics.java Date: Mon, 11 Jan 2010 12:19:43 -0000 To: commits@poi.apache.org From: nick@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100111121943.3D7AD23888E2@eris.apache.org> Author: nick Date: Mon Jan 11 12:19:42 2010 New Revision: 897847 URL: http://svn.apache.org/viewvc?rev=897847&view=rev Log: Make it possible to return null on missing chunks, rather than the exception Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java?rev=897847&r1=897846&r2=897847&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java Mon Jan 11 12:19:42 2010 @@ -50,6 +50,8 @@ private NameIdChunks nameIdChunks; private RecipientChunks recipientChunks; private AttachmentChunks[] attachmentChunks; + + private boolean returnNullOnMissingChunk = false; /** * Constructor for creating new files. @@ -125,7 +127,11 @@ */ public String getStringFromChunk(StringChunk chunk) throws ChunkNotFoundException { if(chunk == null) { - throw new ChunkNotFoundException(); + if(returnNullOnMissingChunk) { + return null; + } else { + throw new ChunkNotFoundException(); + } } return chunk.getValue(); } @@ -230,6 +236,8 @@ if(mainChunks.submissionChunk != null) { return mainChunks.submissionChunk.getAcceptedAtTime(); } + if(returnNullOnMissingChunk) + return null; throw new ChunkNotFoundException(); } @@ -268,4 +276,25 @@ public void write(OutputStream out) throws IOException { throw new UnsupportedOperationException("Writing isn't yet supported for HSMF, sorry"); } + + + /** + * Will you get a null on a missing chunk, or a + * {@link ChunkNotFoundException} (default is the + * exception). + */ + public boolean isReturnNullOnMissingChunk() { + return returnNullOnMissingChunk; + } + + /** + * Sets whether on asking for a missing chunk, + * you get back null or a {@link ChunkNotFoundException} + * (default is the exception). + */ + public void setReturnNullOnMissingChunk(boolean returnNullOnMissingChunk) { + this.returnNullOnMissingChunk = returnNullOnMissingChunk; + } + + } Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java?rev=897847&r1=897846&r2=897847&view=diff ============================================================================== --- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java (original) +++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java Mon Jan 11 12:19:42 2010 @@ -22,6 +22,7 @@ import junit.framework.TestCase; import org.apache.poi.POIDataSamples; +import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; /** * Tests to verify that we can perform basic opperations on @@ -74,4 +75,31 @@ assertEquals(0, outlook30.getAttachmentFiles().length); assertEquals(2, attachments.getAttachmentFiles().length); } + + /** + * Test missing chunks + */ + public void testMissingChunks() throws Exception { + assertEquals(false, attachments.isReturnNullOnMissingChunk()); + + try { + attachments.getMessageDate(); + fail(); + } catch(ChunkNotFoundException e) { + // Good + } + + attachments.setReturnNullOnMissingChunk(true); + + assertEquals(null, attachments.getMessageDate()); + + attachments.setReturnNullOnMissingChunk(false); + + try { + attachments.getMessageDate(); + fail(); + } catch(ChunkNotFoundException e) { + // Good + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org