Author: nick
Date: Tue Jan  8 09:49:08 2008
New Revision: 610082

URL: http://svn.apache.org/viewvc?rev=610082&view=rev
Log:
Support for unicode named named ranges (patch and test from bug #42033)

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/NameRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.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=610082&r1=610081&r2=610082&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Tue Jan  8 09:49:08 
2008
@@ -36,6 +36,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.0.2-FINAL" date="2008-??-??">
+            <action dev="POI-DEVELOPERS" type="add">42033 - Add support for 
named ranges with unicode names</action>
             <action dev="POI-DEVELOPERS" type="add">34023 - When shifting 
rows, update formulas on that sheet to point to the new location of those 
rows</action>
             <action dev="POI-DEVELOPERS" type="add">Support getting all the 
cells referenced by an AreaReference, not just the corner ones</action>
             <action dev="POI-DEVELOPERS" type="add">43510 - Add support for 
named ranges in formulas, including non-contiguous named ranges</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=610082&r1=610081&r2=610082&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue Jan  8 09:49:08 
2008
@@ -33,6 +33,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.0.2-FINAL" date="2008-??-??">
+            <action dev="POI-DEVELOPERS" type="add">42033 - Add support for 
named ranges with unicode names</action>
             <action dev="POI-DEVELOPERS" type="add">34023 - When shifting 
rows, update formulas on that sheet to point to the new location of those 
rows</action>
             <action dev="POI-DEVELOPERS" type="add">Support getting all the 
cells referenced by an AreaReference, not just the corner ones</action>
             <action dev="POI-DEVELOPERS" type="add">43510 - Add support for 
named ranges in formulas, including non-contiguous named ranges</action>

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java?rev=610082&r1=610081&r2=610082&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java Tue Jan  8 
09:49:08 2008
@@ -270,6 +270,9 @@
      */
     public void setNameText(String name){
         field_12_name_text = name;
+        setCompressedUnicodeFlag(
+               StringUtil.hasMultibyte(name) ? (byte)1 : (byte)0
+        );
     }
 
     //    public void setNameDefintion(String definition){
@@ -318,12 +321,24 @@
         return field_2_keyboard_shortcut ;
     }
 
-    /** gets the name length
+    /** 
+     * gets the name length, in characters
      * @return name length
      */
     public byte getNameTextLength(){
         return field_3_length_name_text;
     }
+    
+    /** 
+     * gets the name length, in bytes
+     * @return raw name length
+     */
+    public byte getRawNameTextLength(){
+       if( (field_11_compressed_unicode_flag & 0x01) == 1 ) {
+               return (byte)(2 * field_3_length_name_text);
+       }
+       return field_3_length_name_text;
+    }
 
     /** get the definition length
      * @return definition length
@@ -511,27 +526,16 @@
         data[17 + offset] = getStatusBarLength();
         data[18 + offset] = getCompressedUnicodeFlag();
 
-        /* temp: gjs
-        if (isBuiltInName())
-        {
-            LittleEndian.putShort( data, 2 + offset, (short) ( 16 + 
field_13_raw_name_definition.length ) );
-
-            data[19 + offset] = field_12_builtIn_name;
-            System.arraycopy( field_13_raw_name_definition, 0, data, 20 + 
offset, field_13_raw_name_definition.length );
-
-            return 20 + field_13_raw_name_definition.length;
-        }
-        else
-        {     */            
-            
                        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 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 );
-                               
                        }
 
 
@@ -554,15 +558,15 @@
         /* } */
     }
 
-    /** gets the length of all texts
+    /** 
+     * Gets the length of all texts, in bytes
      * @return total length
      */
     public int getTextsLength(){
         int result;
 
-        result = getNameTextLength() + getDescriptionTextLength() +
-        getHelpTopicLength() + getStatusBarLength();
-
+        result = getRawNameTextLength() + getDescriptionTextLength() +
+               getHelpTopicLength() + getStatusBarLength();
 
         return result;
     }

Modified: 
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java?rev=610082&r1=610081&r2=610082&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java 
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java 
Tue Jan  8 09:49:08 2008
@@ -26,6 +26,8 @@
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.util.TempFile;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -316,7 +318,23 @@
                 assertTrue("Name is 
"+nm2.getNameName(),"RangeTest2".equals(nm2.getNameName()));
                 assertTrue("Reference is 
"+nm2.getReference(),(wb.getSheetName(1)+"!$A$1:$O$21").equals(nm2.getReference()));
         }       
-        
+
+       public void testUnicodeNamedRange() throws Exception {
+           HSSFWorkbook workBook = new HSSFWorkbook();
+           HSSFSheet sheet = workBook.createSheet("Test");
+           HSSFName name = workBook.createName();
+           name.setNameName("\u03B1");
+           name.setReference("Test!$D$3:$E$8");
+           
+           ByteArrayOutputStream out = new ByteArrayOutputStream();
+           workBook.write(out);
+           
+           HSSFWorkbook workBook2 = new HSSFWorkbook(new 
ByteArrayInputStream(out.toByteArray()));
+           HSSFName name2 = workBook2.getNameAt(0);
+           
+           assertEquals("\u03B1", name2.getNameName());
+           assertEquals("Test!$D$3:$E$8", name2.getReference());
+       }
         
         /**
          * Test to see if the print areas can be retrieved/created in memory



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to