From: Nick Burch Date: Mon, 12 Nov 2007 22:12:03 +0000 (+0000) Subject: Patch for unicode NameRecords (bug #43837) X-Git-Tag: REL_3_0_2_BETA1~8 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=33903d5df35375d76beb98cddd0f715a8fcfc388;p=poi.git Patch for unicode NameRecords (bug #43837) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@594316 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index ca6a475253..c750d3347a 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -36,6 +36,7 @@ + 43837 - [PATCH] Support for unicode NameRecords 43721 - [PATCH] Support for Chart Title Format records 42794 - [PATCH] Fix for BOF records from things like Access 43648 - Fix for IntPtg and short vs int diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 2b561f5549..24d49e9384 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ + 43837 - [PATCH] Support for unicode NameRecords 43721 - [PATCH] Support for Chart Title Format records 42794 - [PATCH] Fix for BOF records from things like Access 43648 - Fix for IntPtg and short vs int diff --git a/src/java/org/apache/poi/hssf/record/NameRecord.java b/src/java/org/apache/poi/hssf/record/NameRecord.java index c920a4afc1..4014d7e7ed 100644 --- a/src/java/org/apache/poi/hssf/record/NameRecord.java +++ b/src/java/org/apache/poi/hssf/record/NameRecord.java @@ -719,17 +719,17 @@ public class NameRecord extends Record { 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 + //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(); + 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); - } - } + 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); diff --git a/src/testcases/org/apache/poi/hssf/data/unicodeNameRecord.xls b/src/testcases/org/apache/poi/hssf/data/unicodeNameRecord.xls new file mode 100644 index 0000000000..d1d246062c Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/unicodeNameRecord.xls differ diff --git a/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java b/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java new file mode 100644 index 0000000000..2677c4c42e --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestUnicodeNameRecord.java @@ -0,0 +1,52 @@ +/* ==================================================================== + 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.hssf.record; + + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import junit.framework.TestCase; + +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; + +public class TestUnicodeNameRecord extends TestCase { + private String _test_file_path; + private static final String _test_file_path_property = "HSSF.testdata.path"; + + public TestUnicodeNameRecord() + { + super(); + _test_file_path = System.getProperty( _test_file_path_property ) + + File.separator + "unicodeNameRecord.xls"; + } + + public void testReadBook() throws IOException { + POIFSFileSystem fs = new POIFSFileSystem( + new FileInputStream(_test_file_path) + ); + + // This bit used to crash + HSSFWorkbook book = new HSSFWorkbook(fs); + HSSFSheet sheet = book.getSheetAt(0); + } +}