1 2 17 18 package org.apache.poi.ddf; 19 20 import org.apache.poi.util.LittleEndian; 21 import org.apache.poi.hssf.record.RecordFormatException; 22 23 import java.util.List ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 27 32 public class EscherPropertyFactory 33 { 34 41 public List createProperties( byte[] data, int offset, short numProperties ) 42 { 43 List results = new ArrayList (); 44 45 int pos = offset; 46 int complexBytes = 0; 47 for (int i = 0; i < numProperties; i++) 49 { 50 short propId; 51 int propData; 52 propId = LittleEndian.getShort( data, pos ); 53 propData = LittleEndian.getInt( data, pos + 2 ); 54 short propNumber = (short) ( propId & (short) 0x3FFF ); 55 boolean isComplex = ( propId & (short) 0x8000 ) != 0; 56 boolean isBlipId = ( propId & (short) 0x4000 ) != 0; 57 if ( isComplex ) 58 complexBytes = propData; 59 else 60 complexBytes = 0; 61 byte propertyType = EscherProperties.getPropertyType( (short) propNumber ); 62 if ( propertyType == EscherPropertyMetaData.TYPE_BOOLEAN ) 63 results.add( new EscherBoolProperty( propNumber, propData ) ); 64 else if ( propertyType == EscherPropertyMetaData.TYPE_RGB ) 65 results.add( new EscherRGBProperty( propNumber, propData ) ); 66 else if ( propertyType == EscherPropertyMetaData.TYPE_SHAPEPATH ) 67 results.add( new EscherShapePathProperty( propNumber, propData ) ); 68 else 69 { 70 if ( !isComplex ) 71 results.add( new EscherSimpleProperty( propNumber, propData ) ); 72 else 73 { 74 if ( propertyType == EscherPropertyMetaData.TYPE_ARRAY) 75 results.add( new EscherArrayProperty( propId, new byte[propData]) ); 76 else 77 results.add( new EscherComplexProperty( propId, new byte[propData]) ); 78 79 } 80 } 81 pos += 6; 82 } 84 85 for ( Iterator iterator = results.iterator(); iterator.hasNext(); ) 87 { 88 EscherProperty p = (EscherProperty) iterator.next(); 89 if (p instanceof EscherComplexProperty) 90 { 91 if (p instanceof EscherArrayProperty) 92 { 93 pos += ((EscherArrayProperty)p).setArrayData(data, pos); 94 } 95 else 96 { 97 byte[] complexData = ((EscherComplexProperty)p).getComplexData(); 98 System.arraycopy(data, pos, complexData, 0, complexData.length); 99 pos += complexData.length; 100 } 101 } 102 } 103 104 return results; 105 } 106 107 108 } 109 | Popular Tags |