You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2010/01/08 14:49:09 UTC

svn commit: r897205 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hsmf/datatypes/ src/org/apache/poi/hsmf/parsers/ testcases/org/apache/poi/hsmf/datatypes/

Author: nick
Date: Fri Jan  8 13:49:09 2010
New Revision: 897205

URL: http://svn.apache.org/viewvc?rev=897205&view=rev
Log:
Quick bit of refactoring to save parsing the type and id twice

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunk.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/StringChunk.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java?rev=897205&r1=897204&r2=897205&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java Fri Jan  8 13:49:09 2010
@@ -36,10 +36,9 @@
 	/**
 	 * Creates a Byte Chunk.
 	 */
-	public ByteChunk(String entryName) {
-		super(entryName);
-	}
-	
+   public ByteChunk(String namePrefix, int chunkId, int type) {
+      super(namePrefix, chunkId, type);
+   }
 	/**
 	 * Create a Byte Chunk, with the specified
 	 *  type.

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunk.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunk.java?rev=897205&r1=897204&r2=897205&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunk.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunk.java Fri Jan  8 13:49:09 2010
@@ -28,21 +28,13 @@
 	protected int type;
 	protected String namePrefix;
 	
-	protected Chunk(String entryName) {
-	   int splitAt = entryName.lastIndexOf('_');
-	   if(splitAt == -1 || splitAt > (entryName.length()-8)) {
-	      throw new IllegalArgumentException("Invalid chunk name " + entryName);
-	   }
-	   
-	   namePrefix = entryName.substring(0, splitAt+1);
-	   String ids = entryName.substring(splitAt+1);
-	   chunkId = Integer.parseInt(ids.substring(0, 4), 16);
-      type    = Integer.parseInt(ids.substring(4, 8), 16);
-	}
+   protected Chunk(String namePrefix, int chunkId, int type) {
+      this.namePrefix = namePrefix;
+      this.chunkId = chunkId;
+      this.type = type;
+   }
 	protected Chunk(int chunkId, int type) {
-	   namePrefix = DEFAULT_NAME_PREFIX;
-	   this.chunkId = chunkId;
-	   this.type = type;
+	   this(DEFAULT_NAME_PREFIX, chunkId, type);
 	}
 
 	/**

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java?rev=897205&r1=897204&r2=897205&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java Fri Jan  8 13:49:09 2010
@@ -44,8 +44,8 @@
 	/**
 	 * Creates a Byte Chunk.
 	 */
-	public MessageSubmissionChunk(String entryName) {
-		super(entryName);
+	public MessageSubmissionChunk(String namePrefix, int chunkId, int type) {
+		super(namePrefix, chunkId, type);
 	}
 	
 	/**

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/StringChunk.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/StringChunk.java?rev=897205&r1=897204&r2=897205&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/StringChunk.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/StringChunk.java Fri Jan  8 13:49:09 2010
@@ -36,8 +36,8 @@
 	/**
 	 * Creates a String Chunk.
 	 */
-	public StringChunk(String entryName) {
-		super(entryName);
+	public StringChunk(String namePrefix, int chunkId, int type) {
+		super(namePrefix, chunkId, type);
 	}
 	
 	/**

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java?rev=897205&r1=897204&r2=897205&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java Fri Jan  8 13:49:09 2010
@@ -102,39 +102,47 @@
     * Creates a chunk, and gives it to its parent group 
     */
    protected static void process(DocumentNode entry, ChunkGroup grouping) {
-      if(entry.getName().length() < 9) {
+      String entryName = entry.getName();
+      
+      if(entryName.length() < 9) {
          // Name in the wrong format
          return;
       }
-      if(entry.getName().indexOf('_') == -1) {
+      if(entryName.indexOf('_') == -1) {
          // Name in the wrong format
          return;
       }
       
-      // See if we can get a type for it
-      String idType = entry.getName().substring(entry.getName().length()-8);
-      String idS = idType.substring(0, 4);
-      String typeS = idType.substring(4); 
+      // Split it into its parts
+      int splitAt = entryName.lastIndexOf('_');
+      if(splitAt == -1 || splitAt > (entryName.length()-8)) {
+         throw new IllegalArgumentException("Invalid chunk name " + entryName);
+      }
+      
+      // Now try to turn it into id + type
+      String namePrefix = entryName.substring(0, splitAt+1);
+      String ids = entryName.substring(splitAt+1);
       try {
-         int id = Integer.parseInt(idS, 16);
-         int type = Integer.parseInt(typeS, 16);
+         int chunkId = Integer.parseInt(ids.substring(0, 4), 16);
+         int type    = Integer.parseInt(ids.substring(4, 8), 16);
+         
          Chunk chunk = null;
          
          // Special cases based on the ID
-         switch(id) {
+         switch(chunkId) {
          case Chunks.SUBMISSION_ID_DATE:
-            chunk = new MessageSubmissionChunk(entry.getName());
+            chunk = new MessageSubmissionChunk(namePrefix, chunkId, type);
             break;
          default:
             // Nothing special about this ID
             // So, do the usual thing which is by type
             switch(type) {
             case Types.BINARY:
-               chunk = new ByteChunk(entry.getName());
+               chunk = new ByteChunk(namePrefix, chunkId, type);
                break;
             case Types.ASCII_STRING:
             case Types.UNICODE_STRING:
-               chunk = new StringChunk(entry.getName());
+               chunk = new StringChunk(namePrefix, chunkId, type);
                break;
             }
          }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java?rev=897205&r1=897204&r2=897205&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java Fri Jan  8 13:49:09 2010
@@ -40,7 +40,7 @@
 		assertEquals(0x0200, chunk.getChunkId());
 		assertEquals(0x001E, chunk.getType());
 
-      chunk = new StringChunk("__substg1.0_0200001E");
+      chunk = new StringChunk("__substg1.0_", 0x0200, 0x001E);
       assertEquals("__substg1.0_0200001E", chunk.getEntryName());
       assertEquals(0x0200, chunk.getChunkId());
       assertEquals(0x001E, chunk.getType());



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org