You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestUnicode.java 3.0KB

* Writing support added to the SummaryInformation and DocumentSummaryInformation classes. These classes now have methods for setting and removing properties. Coherent extensions are: ** Documentation section about writing standard properties added to the HPSF HOW-TO. ** Example application added showing how to modify the document summary information. ** Testcases added for testing modifying summary information and document summary information. ** PropertySetFactory extended to create SummaryInformation and DocumentSummaryInformation instances. * Added MutablePropertySet.write(DirectoryEntry, String) to ease writing a property set to a POI filesystem document. * Improved codepage handling. * Bug fixed: Integral values were read and written as unsigned instead of signed. * Reworked the mapping between variant types and Java types: Variant.VT_I4 is mapped to Integer now and Variant.VT_I8 to Long. This might cause incompatibilities if you are doing low-level HPSF programming. * Changed SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID from a byte[] to a byte[][] in order to contain the format ID of the first and the second section. This is an incompatible change! * Added PropertySet.getFirstSection(). This method is similar to getSingleSection() won't choke if the property set has more than one section. * Support for low-level reading and writing of Variant.VT_I8 type properties added. * Unnecessary casts removed. * Poibrowser's display format changed slightly. git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@382887 13f79535-47bb-0310-9956-ffa450edef68
hace 18 años
* Writing support added to the SummaryInformation and DocumentSummaryInformation classes. These classes now have methods for setting and removing properties. Coherent extensions are: ** Documentation section about writing standard properties added to the HPSF HOW-TO. ** Example application added showing how to modify the document summary information. ** Testcases added for testing modifying summary information and document summary information. ** PropertySetFactory extended to create SummaryInformation and DocumentSummaryInformation instances. * Added MutablePropertySet.write(DirectoryEntry, String) to ease writing a property set to a POI filesystem document. * Improved codepage handling. * Bug fixed: Integral values were read and written as unsigned instead of signed. * Reworked the mapping between variant types and Java types: Variant.VT_I4 is mapped to Integer now and Variant.VT_I8 to Long. This might cause incompatibilities if you are doing low-level HPSF programming. * Changed SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID from a byte[] to a byte[][] in order to contain the format ID of the first and the second section. This is an incompatible change! * Added PropertySet.getFirstSection(). This method is similar to getSingleSection() won't choke if the property set has more than one section. * Support for low-level reading and writing of Variant.VT_I8 type properties added. * Unnecessary casts removed. * Poibrowser's display format changed slightly. git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@382887 13f79535-47bb-0310-9956-ffa450edef68
hace 18 años
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hpsf.basic;
  16. import static org.junit.jupiter.api.Assertions.assertEquals;
  17. import static org.junit.jupiter.api.Assertions.assertTrue;
  18. import java.io.ByteArrayInputStream;
  19. import java.io.File;
  20. import java.io.IOException;
  21. import org.apache.poi.POIDataSamples;
  22. import org.apache.poi.hpsf.DocumentSummaryInformation;
  23. import org.apache.poi.hpsf.HPSFException;
  24. import org.apache.poi.hpsf.PropertySet;
  25. import org.apache.poi.hpsf.PropertySetFactory;
  26. import org.apache.poi.hpsf.Section;
  27. import org.apache.poi.hpsf.SummaryInformation;
  28. import org.apache.poi.util.CodePageUtil;
  29. import org.junit.jupiter.api.Test;
  30. /**
  31. * Tests whether Unicode string can be read from a DocumentSummaryInformation.
  32. */
  33. class TestUnicode {
  34. private static final POIDataSamples samples = POIDataSamples.getHPSFInstance();
  35. /**
  36. * Tests the {@link PropertySet} methods. The test file has two
  37. * property set: the first one is a {@link SummaryInformation},
  38. * the second one is a {@link DocumentSummaryInformation}.
  39. *
  40. * @throws IOException if an I/O exception occurs
  41. * @throws HPSFException if an HPSF exception occurs
  42. */
  43. @Test
  44. void testPropertySetMethods() throws IOException, HPSFException {
  45. final String POI_FS = "TestUnicode.xls";
  46. final String[] POI_FILES = { DocumentSummaryInformation.DEFAULT_STREAM_NAME };
  47. File data = samples.getFile(POI_FS);
  48. POIFile poiFile = Util.readPOIFiles(data, POI_FILES).get(0);
  49. byte[] b = poiFile.getBytes();
  50. PropertySet ps = PropertySetFactory.create(new ByteArrayInputStream(b));
  51. assertTrue(ps.isDocumentSummaryInformation());
  52. assertEquals(2, ps.getSectionCount());
  53. Section s = ps.getSections().get(1);
  54. assertEquals(CodePageUtil.CP_UTF16, s.getProperty(1));
  55. assertEquals(-96070278, s.getProperty(2));
  56. assertEquals("MCon_Info zu Office bei Schreiner", s.getProperty(3));
  57. assertEquals("petrovitsch@schreiner-online.de", s.getProperty(4));
  58. assertEquals("Petrovitsch, Wilhelm", s.getProperty(5));
  59. }
  60. }