poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1058555 - in /poi/trunk/src/scratchpad/src/org/apache/poi/hmef: CompressedRTF.java MAPIAttribute.java MAPIRtfAttribute.java MAPIStringAttribute.java
Date Thu, 13 Jan 2011 13:53:02 GMT
Author: nick
Date: Thu Jan 13 13:53:02 2011
New Revision: 1058555

URL: http://svn.apache.org/viewvc?rev=1058555&view=rev
Log:
Start on TNEF RTF attribute decompression, but not quite finished yet

Added:
    poi/trunk/src/scratchpad/src/org/apache/poi/hmef/MAPIRtfAttribute.java
Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hmef/MAPIAttribute.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hmef/MAPIStringAttribute.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java?rev=1058555&r1=1058554&r2=1058555&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java Thu Jan 13 13:53:02
2011
@@ -31,10 +31,13 @@ import org.apache.poi.util.LittleEndian;
  * Within a {@link HMEFMessage}, the content is often
  *  stored in as RTF, but LZW compressed. This class
  *  handles decompressing it for you.
+ *  
+ * Note - this doesn't quite decompress the data correctly,
+ *  more work and unit testing is required...
  */
 public final class CompressedRTF extends LZWDecompresser {
    public static final byte[] COMPRESSED_SIGNATURE =
-      new byte[] { (byte)'L', (byte)'Z', (byte)'F', (byte)'U' };
+      new byte[] { (byte)'L', (byte)'Z', (byte)'F', (byte)'u' };
    public static final byte[] UNCOMPRESSED_SIGNATURE =
       new byte[] { (byte)'M', (byte)'E', (byte)'L', (byte)'A' };
    public static final int COMPRESSED_SIGNATURE_INT =

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hmef/MAPIAttribute.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hmef/MAPIAttribute.java?rev=1058555&r1=1058554&r2=1058555&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hmef/MAPIAttribute.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hmef/MAPIAttribute.java Thu Jan 13 13:53:02
2011
@@ -62,7 +62,17 @@ public class MAPIAttribute {
    }
    
    public String toString() {
-      return property.toString() + " " + HexDump.toHex(data);
+      String hex;
+      if(data.length <= 16) {
+         hex = HexDump.toHex(data);
+      } else {
+         byte[] d = new byte[16];
+         System.arraycopy(data, 0, d, 0, 16);
+         hex = HexDump.toHex(d);
+         hex = hex.substring(0, hex.length()-1) + ", ....]";
+      }
+      
+      return property.toString() + " " + hex;
    }
    
    /**
@@ -146,6 +156,8 @@ public class MAPIAttribute {
             MAPIAttribute attr;
             if(type == Types.UNICODE_STRING || type == Types.ASCII_STRING) {
                attr = new MAPIStringAttribute(prop, type, data);
+            } else if(id == MAPIProperty.RTF_COMPRESSED.id) {
+               attr = new MAPIRtfAttribute(prop, type, data);
             } else {
                attr = new MAPIAttribute(prop, type, data);
             }

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hmef/MAPIRtfAttribute.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hmef/MAPIRtfAttribute.java?rev=1058555&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hmef/MAPIRtfAttribute.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hmef/MAPIRtfAttribute.java Thu Jan 13 13:53:02
2011
@@ -0,0 +1,49 @@
+/* ====================================================================
+   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.hmef;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import org.apache.poi.hsmf.datatypes.MAPIProperty;
+import org.apache.poi.util.StringUtil;
+
+/**
+ * A pure-MAPI attribute holding RTF (compressed or not), which applies 
+ *  to a {@link HMEFMessage} or one of its {@link Attachment}s.
+ */
+public final class MAPIRtfAttribute extends MAPIAttribute {
+   private final String data;
+   
+   public MAPIRtfAttribute(MAPIProperty property, int type, byte[] data) throws IOException
{
+      super(property, type, data);
+      
+      CompressedRTF rtf = new CompressedRTF();
+      byte[] decomp = rtf.decompress(new ByteArrayInputStream(data));
+      
+      this.data = StringUtil.getFromCompressedUnicode(decomp, 0, decomp.length);
+   }
+   
+   public String getDataString() {
+      return data;
+   }
+   
+   public String toString() {
+      return getProperty().toString() + " " + data;
+   }
+}

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hmef/MAPIStringAttribute.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hmef/MAPIStringAttribute.java?rev=1058555&r1=1058554&r2=1058555&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hmef/MAPIStringAttribute.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hmef/MAPIStringAttribute.java Thu Jan 13 13:53:02
2011
@@ -65,6 +65,10 @@ public final class MAPIStringAttribute e
       this.data = tmpData;
    }
    
+   public String getDataString() {
+      return data;
+   }
+   
    public String toString() {
       return getProperty().toString() + " " + data;
    }



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


Mime
View raw message