Bug 42033 - [PATCH] name record not supported my native language.
Summary: [PATCH] name record not supported my native language.
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.0-dev
Hardware: PC FreeBSD
: P3 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-03 05:27 UTC by Toru Iseki
Modified: 2008-01-08 09:49 UTC (History)
0 users



Attachments
patch (3.62 KB, patch)
2007-04-03 05:28 UTC, Toru Iseki
Details | Diff
TestCase (1.25 KB, text/plain)
2007-04-03 05:29 UTC, Toru Iseki
Details
TestCase (1.17 KB, text/plain)
2007-04-03 05:33 UTC, Toru Iseki
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Toru Iseki 2007-04-03 05:27:47 UTC
Hi All.
(I can't write english so well, sorry.)
I wrote a patch for NameRecord.java to support unicode in NamedRange.

I tried to read and write Cell, that had been defined by Named Range(Unicode
name defined), but did not go well.

This patch is like to BoundSheetRecord.java, readUnicodeLEString used to read,
putUnicodeLE used to write.

regards.


Index: src/java/org/apache/poi/hssf/record/NameRecord.java
===================================================================
--- src/java/org/apache/poi/hssf/record/NameRecord.java	(revision 525136)
+++ src/java/org/apache/poi/hssf/record/NameRecord.java	(working copy)
@@ -274,6 +274,7 @@
      */
     public void setNameText(String name){
         field_12_name_text = name;
+        setCompressedUnicodeFlag(StringUtil.hasMultibyte(name) ? (byte)1 :
(byte)0);
     }
 
     //    public void setNameDefintion(String definition){
@@ -328,6 +329,15 @@
     public byte getNameTextLength(){
         return field_3_length_name_text;
     }
+    
+    /** gets the name length that depends on the unicode flag
+     * @return raw name length
+     */
+    public byte getRawNameTextLength(){
+        return (byte) ( ( ( field_11_compressed_unicode_flag & 0x01 ) == 1 )
+                ? 2 * field_3_length_name_text
+                : field_3_length_name_text );
+    }
 
     /** get the definition length
      * @return definition length
@@ -532,13 +542,15 @@
             
 			int start_of_name_definition = 19 + field_3_length_name_text;
 
-			if (this.isBuiltInName()) {
-				//can send the builtin name directly in
-				data [19 + offset] =  this.getBuiltInName();
-			} else {
-				StringUtil.putCompressedUnicode( getNameText(), data, 19 + offset );
-				
-			}
+            if (this.isBuiltInName()) {
+                //can send the builtin name directly in
+                data [19 + offset] =  this.getBuiltInName();
+            } else if ((this.getCompressedUnicodeFlag() & 0x01) == 1) {
+                StringUtil.putUnicodeLE( getNameText(), data, 19 + offset );
+                start_of_name_definition = 19 + (2 * field_3_length_name_text);
+            } else {
+                StringUtil.putCompressedUnicode( getNameText(), data, 19 +
offset );
+            }
 
 
 			Ptg.serializePtgStack(field_13_name_definition,  data,
start_of_name_definition + offset );
@@ -566,7 +578,7 @@
     public int getTextsLength(){
         int result;
 
-        result = getNameTextLength() + getDescriptionTextLength() +
+        result = getRawNameTextLength() + getDescriptionTextLength() +
         getHelpTopicLength() + getStatusBarLength();
 
 
@@ -724,19 +736,19 @@
         field_8_length_description_text = in.readByte();
         field_9_length_help_topic_text  = in.readByte();
         field_10_length_status_bar_text = in.readByte();
-            
-			//store the name in byte form if it's a builtin name
-        field_11_compressed_unicode_flag= in.readByte();        
-			if (this.isBuiltInName()) {
-                field_12_builtIn_name = in.readByte();
-        } else {                
-          if (field_11_compressed_unicode_flag == 1) {
-            field_12_name_text =
in.readCompressedUnicode(field_3_length_name_text);
-          } else {
-            field_12_name_text =
in.readCompressedUnicode(field_3_length_name_text);
-          }
-			}
-            
+        
+        //store the name in byte form if it's a builtin name
+        field_11_compressed_unicode_flag= in.readByte();
+        if (this.isBuiltInName()) {
+            field_12_builtIn_name = in.readByte();
+        } else {
+            if (field_11_compressed_unicode_flag == 1) {
+                field_12_name_text =
in.readUnicodeLEString(field_3_length_name_text);
+            } else {
+                field_12_name_text =
in.readCompressedUnicode(field_3_length_name_text);
+            }
+        }
+    
         field_13_name_definition =
Ptg.createParsedExpressionTokens(field_4_length_name_definition, in);
     
         //Who says that this can only ever be compressed unicode???
Comment 1 Toru Iseki 2007-04-03 05:28:33 UTC
Created attachment 19898 [details]
patch
Comment 2 Toru Iseki 2007-04-03 05:29:43 UTC
Created attachment 19899 [details]
TestCase
Comment 3 Toru Iseki 2007-04-03 05:33:13 UTC
Created attachment 19900 [details]
TestCase
Comment 4 Nick Burch 2008-01-08 09:49:27 UTC
Thanks for this, applied