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.

PICFAndOfficeArtData.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.hwpf.model;
  16. import java.util.LinkedList;
  17. import java.util.List;
  18. import org.apache.poi.ddf.DefaultEscherRecordFactory;
  19. import org.apache.poi.ddf.EscherBSERecord;
  20. import org.apache.poi.ddf.EscherBlipRecord;
  21. import org.apache.poi.ddf.EscherContainerRecord;
  22. import org.apache.poi.ddf.EscherRecord;
  23. import org.apache.poi.ddf.EscherRecordTypes;
  24. import org.apache.poi.hwpf.HWPFDocument;
  25. import org.apache.poi.hwpf.model.types.PICFAbstractType;
  26. import org.apache.poi.util.IOUtils;
  27. import org.apache.poi.util.Internal;
  28. import org.apache.poi.util.LittleEndian;
  29. @Internal
  30. public class PICFAndOfficeArtData {
  31. /**
  32. * Can contain either a {@link EscherBlipRecord} or a {@link EscherBSERecord}.
  33. * <p>
  34. * Should never contain more than 1 record.
  35. */
  36. private final List<EscherRecord> _blipRecords = new LinkedList<>();
  37. private final PICF _picf;
  38. /**
  39. * A {@link EscherRecordTypes#SP_CONTAINER}.
  40. */
  41. private final EscherContainerRecord _shape = new EscherContainerRecord();
  42. private byte[] _stPicName;
  43. public PICFAndOfficeArtData( byte[] dataStream, int startOffset )
  44. {
  45. int offset = startOffset;
  46. _picf = new PICF( dataStream, offset );
  47. offset += PICFAbstractType.getSize();
  48. if ( _picf.getMm() == 0x0066 )
  49. {
  50. short _cchPicName = LittleEndian.getUByte(dataStream, offset);
  51. offset += 1;
  52. _stPicName = IOUtils.safelyClone(dataStream, offset, _cchPicName, HWPFDocument.getMaxRecordLength());
  53. offset += _cchPicName;
  54. }
  55. final DefaultEscherRecordFactory escherRecordFactory = new DefaultEscherRecordFactory();
  56. int recordSize = _shape.fillFields( dataStream, offset,
  57. escherRecordFactory );
  58. offset += recordSize;
  59. while ( ( offset - startOffset ) < _picf.getLcb() )
  60. {
  61. EscherRecord nextRecord = escherRecordFactory.createRecord(
  62. dataStream, offset );
  63. if ( nextRecord.getRecordId() != (short) 0xF007
  64. && ( nextRecord.getRecordId() < (short) 0xF018 || nextRecord
  65. .getRecordId() > (short) 0xF117 ) )
  66. break;
  67. int blipRecordSize = nextRecord.fillFields( dataStream, offset,
  68. escherRecordFactory );
  69. offset += blipRecordSize;
  70. _blipRecords.add( nextRecord );
  71. // [MS-ODRAW] allows for multiple records in a OfficeArtInlineSpContainer, which is what we're parsing here.
  72. // However, in the context of a HWPF document, there should be only 1.
  73. assert _blipRecords.size() == 1;
  74. }
  75. }
  76. /**
  77. * Contains {@link EscherBlipRecord}s and {@link EscherBSERecord}s.
  78. *
  79. * @return List of BLIP records. Never {@code null}.
  80. */
  81. public List<EscherRecord> getBlipRecords()
  82. {
  83. return _blipRecords;
  84. }
  85. public PICF getPicf()
  86. {
  87. return _picf;
  88. }
  89. /**
  90. * @return The {@link EscherRecordTypes#SP_CONTAINER}.
  91. */
  92. public EscherContainerRecord getShape()
  93. {
  94. return _shape;
  95. }
  96. public byte[] getStPicName()
  97. {
  98. return _stPicName;
  99. }
  100. }