You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2009/05/21 23:41:47 UTC

svn commit: r777275 - in /poi/trunk/src: documentation/content/xdocs/changes.xml documentation/content/xdocs/status.xml java/org/apache/poi/hssf/record/ExternalNameRecord.java testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java

Author: josh
Date: Thu May 21 21:41:47 2009
New Revision: 777275

URL: http://svn.apache.org/viewvc?rev=777275&view=rev
Log:
Bugzilla 47229 - Fixed ExternalNameRecord to handle DDE links

Modified:
    poi/trunk/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=777275&r1=777274&r2=777275&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Thu May 21 21:41:47 2009
@@ -37,6 +37,7 @@
 
 		<!-- Don't forget to update status.xml too! -->
         <release version="3.5-beta6" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="add">47229 - Fixed ExternalNameRecord to handle DDE links</action>
            <action dev="POI-DEVELOPERS" type="add">46287 - Control of header and footer extraction in ExcelExtractor / XSSFExcelExtractor</action>
            <action dev="POI-DEVELOPERS" type="add">46554 - New ant target "jar-examples"</action>
            <action dev="POI-DEVELOPERS" type="add">46161 - Support in XSSF for setGroupColumnCollapsed and setGroupRowCollapsed</action>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=777275&r1=777274&r2=777275&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu May 21 21:41:47 2009
@@ -34,6 +34,7 @@
 	<!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5-beta6" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="add">47229 - Fixed ExternalNameRecord to handle DDE links</action>
            <action dev="POI-DEVELOPERS" type="add">46287 - Control of header and footer extraction in ExcelExtractor / XSSFExcelExtractor</action>
            <action dev="POI-DEVELOPERS" type="add">46554 - New ant target "jar-examples"</action>
            <action dev="POI-DEVELOPERS" type="add">46161 - Support in XSSF for setGroupColumnCollapsed and setGroupRowCollapsed</action>

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java?rev=777275&r1=777274&r2=777275&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java Thu May 21 21:41:47 2009
@@ -17,14 +17,14 @@
 
 package org.apache.poi.hssf.record;
 
+import org.apache.poi.hssf.record.constant.ConstantValueParser;
 import org.apache.poi.ss.formula.Formula;
-import org.apache.poi.util.LittleEndianByteArrayOutputStream;
 import org.apache.poi.util.LittleEndianOutput;
 import org.apache.poi.util.StringUtil;
 
 /**
  * EXTERNALNAME (0x0023)<p/>
- * 
+ *
  * @author Josh Micich
  */
 public final class ExternalNameRecord extends StandardRecord {
@@ -32,7 +32,7 @@
 	public final static short sid = 0x0023; // as per BIFF8. (some old versions used 0x223)
 
 	private static final int OPT_BUILTIN_NAME          = 0x0001;
-	private static final int OPT_AUTOMATIC_LINK        = 0x0002; // m$ doc calls this fWantAdvise 
+	private static final int OPT_AUTOMATIC_LINK        = 0x0002; // m$ doc calls this fWantAdvise
 	private static final int OPT_PICTURE_LINK          = 0x0004;
 	private static final int OPT_STD_DOCUMENT_NAME     = 0x0008;
 	private static final int OPT_OLE_LINK              = 0x0010;
@@ -47,6 +47,21 @@
 	private Formula  field_5_name_definition;
 
 	/**
+	 * 'rgoper' / 'Last received results of the DDE link'
+	 * (seems to be only applicable to DDE links)<br/>
+	 * Logically this is a 2-D array, which has been flattened into 1-D array here.
+	 */
+	private Object[] _ddeValues;
+	/**
+	 * (logical) number of columns in the {@link #_ddeValues} array
+	 */
+	private int _nColumns;
+	/**
+	 * (logical) number of rows in the {@link #_ddeValues} array
+	 */
+	private int _nRows;
+
+	/**
 	 * Convenience Function to determine if the name is a built-in name
 	 */
 	public boolean isBuiltInName() {
@@ -88,6 +103,11 @@
 			+ 2 + field_4_name.length(); // nameLen and name
 		if(hasFormula()) {
 			result += field_5_name_definition.getEncodedSize();
+		} else {
+			if (_ddeValues != null) {
+				result += 3; // byte, short
+				result += ConstantValueParser.getEncodedSize(_ddeValues);
+			}
 		}
 		return result;
 	}
@@ -101,6 +121,12 @@
 		StringUtil.putCompressedUnicode(field_4_name, out);
 		if (hasFormula()) {
 			field_5_name_definition.serialize(out);
+		} else {
+			if (_ddeValues != null) {
+				out.writeByte(_nColumns-1);
+				out.writeShort(_nRows-1);
+				ConstantValueParser.encode(out, _ddeValues);
+			}
 		}
 	}
 
@@ -112,6 +138,16 @@
 		short nameLength    = in.readShort();
 		field_4_name = in.readCompressedUnicode(nameLength);
 		if(!hasFormula()) {
+			if (!isStdDocumentNameIdentifier() && !isOLELink() && isAutomaticLink()) {
+				// both need to be incremented
+				int nColumns = in.readUByte() + 1;
+				int nRows = in.readShort() + 1;
+
+				int totalCount = nRows * nColumns;
+				_ddeValues = ConstantValueParser.parse(in, totalCount);
+				_nColumns = nColumns;
+				_nRows = nRows;
+			}
 			if(in.remaining() > 0) {
 				throw readFail("Some unread data (is formula present?)");
 			}
@@ -127,11 +163,11 @@
 		field_5_name_definition = Formula.read(formulaLen, in, nBytesRemaining);
 	}
 	/*
-	 * Makes better error messages (while hasFormula() is not reliable) 
+	 * Makes better error messages (while hasFormula() is not reliable)
 	 * Remove this when hasFormula() is stable.
 	 */
 	private RuntimeException readFail(String msg) {
-		String fullMsg = msg + " fields: (option=" + field_1_option_flag + " index=" + field_2_index 
+		String fullMsg = msg + " fields: (option=" + field_1_option_flag + " index=" + field_2_index
 		+ " not_used=" + field_3_not_used + " name='" + field_4_name + "')";
 		return new RecordFormatException(fullMsg);
 	}

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java?rev=777275&r1=777274&r2=777275&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java Thu May 21 21:41:47 2009
@@ -17,6 +17,8 @@
 
 package org.apache.poi.hssf.record;
 
+import org.apache.poi.util.HexRead;
+
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 /**
@@ -102,4 +104,35 @@
 
 		TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataPlainName, enr.serialize());
 	}
+
+	public void testDDELink_bug47229() {
+		/**
+		 * Hex dump read directly from text of bugzilla 47229
+		 */
+		final byte[] dataDDE = HexRead.readFromString(
+				"E2 7F 00 00 00 00 " +
+				"37 00 " + // text len
+				// 010672AT0 MUNI,[RTG_MOODY_UNDERLYING,RTG_SP_UNDERLYING]
+				"30 31 30 36 37 32 41 54 30 20 4D 55 4E 49 2C " +
+				"5B 52 54 47 5F 4D 4F 4F 44 59 5F 55 4E 44 45 52 4C 59 49 4E 47 2C " +
+				"52 54 47 5F 53 50 5F 55 4E 44 45 52 4C 59 49 4E 47 5D " +
+				// constant array { { "#N/A N.A.", "#N/A N.A.", }, }
+				" 01 00 00 " +
+				"02 09 00 00 23 4E 2F 41 20 4E 2E 41 2E " +
+				"02 09 00 00 23 4E 2F 41 20 4E 2E 41 2E");
+		ExternalNameRecord enr;
+		try {
+			enr = createSimpleENR(dataDDE);
+		} catch (RecordFormatException e) {
+			// actual msg reported in bugzilla 47229 is different
+			// because that seems to be using a version from before svn r646666
+			if (e.getMessage().startsWith("Some unread data (is formula present?)")) {
+				throw new AssertionFailedError("Identified bug 47229 - failed to read ENR with OLE/DDE result data");
+			}
+			throw e;
+		}
+		assertEquals("010672AT0 MUNI,[RTG_MOODY_UNDERLYING,RTG_SP_UNDERLYING]", enr.getText());
+
+		TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataDDE, enr.serialize());
+	}
 }



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