View | Details | Raw Unified | Return to bug 24183
Collapse All | Expand All

(-)src/java/org/apache/poi/poifs/filesystem/DirectoryEntry.java (+17 lines)
Lines 160-164 Link Here
160
160
161
    public DirectoryEntry createDirectory(final String name)
161
    public DirectoryEntry createDirectory(final String name)
162
        throws IOException;
162
        throws IOException;
163
164
    /**
165
     * @return CLSID assigned to the directory entry
166
     *         "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
167
     */
168
169
    public String getCLSID();
170
171
    /**
172
     * Sets CLSID to be assigned to the directory entry.
173
     * "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
174
     *
175
     * @param CLSID to be assigned to the directory entry
176
     */
177
178
    public void setCLSID(final String clsid);
179
163
}   // end public interface DirectoryEntry
180
}   // end public interface DirectoryEntry
164
181
(-)src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java (+22 lines)
Lines 346-351 Link Here
346
        return rval;
346
        return rval;
347
    }
347
    }
348
348
349
    /**
350
     * @return CLSID assigned to the directory entry
351
     *         "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
352
     */
353
354
    public String getCLSID()
355
    {
356
        return (( DirectoryProperty )getProperty()).getCLSID();
357
    }
358
359
    /**
360
     * Sets CLSID to be assigned to the directory entry.
361
     * "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
362
     *
363
     * @param CLSID to be assigned to the directory entry
364
     */
365
366
    public void setCLSID(final String clsid)
367
    {
368
        (( DirectoryProperty )getProperty()).setCLSID(clsid);
369
    }
370
349
    /* **********  END  implementation of DirectoryEntry ********** */
371
    /* **********  END  implementation of DirectoryEntry ********** */
350
    /* ********** START implementation of Entry ********** */
372
    /* ********** START implementation of Entry ********** */
351
373
(-)src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java (+2 lines)
Lines 423-428 Link Here
423
                DirectoryNode new_dir =
423
                DirectoryNode new_dir =
424
                    ( DirectoryNode ) parent.createDirectory(name);
424
                    ( DirectoryNode ) parent.createDirectory(name);
425
425
426
                ((DirectoryProperty)new_dir.getProperty()).setCLSID(property.getCLSID());
427
426
                processProperties(
428
                processProperties(
427
                    small_blocks, big_blocks,
429
                    small_blocks, big_blocks,
428
                    (( DirectoryProperty ) property).getChildren(), new_dir);
430
                    (( DirectoryProperty ) property).getChildren(), new_dir);
(-)src/java/org/apache/poi/poifs/property/Property.java (+69 lines)
Lines 65-70 Link Here
65
import org.apache.poi.util.IntegerField;
65
import org.apache.poi.util.IntegerField;
66
import org.apache.poi.util.LittleEndianConsts;
66
import org.apache.poi.util.LittleEndianConsts;
67
import org.apache.poi.util.ShortField;
67
import org.apache.poi.util.ShortField;
68
import org.apache.poi.util.ByteArrayField;
69
import org.apache.poi.util.HexDump;
68
70
69
/**
71
/**
70
 * This abstract base class is the ancestor of all classes
72
 * This abstract base class is the ancestor of all classes
Lines 87-92 Link Here
87
    static final private int    _previous_property_offset = 0x44;
89
    static final private int    _previous_property_offset = 0x44;
88
    static final private int    _next_property_offset     = 0x48;
90
    static final private int    _next_property_offset     = 0x48;
89
    static final private int    _child_property_offset    = 0x4C;
91
    static final private int    _child_property_offset    = 0x4C;
92
    static final private int    _clsid_offset             = 0x50;
90
    static final private int    _seconds_1_offset         = 0x64;
93
    static final private int    _seconds_1_offset         = 0x64;
91
    static final private int    _days_1_offset            = 0x68;
94
    static final private int    _days_1_offset            = 0x68;
92
    static final private int    _seconds_2_offset         = 0x6C;
95
    static final private int    _seconds_2_offset         = 0x6C;
Lines 107-112 Link Here
107
    private IntegerField        _previous_property;
110
    private IntegerField        _previous_property;
108
    private IntegerField        _next_property;
111
    private IntegerField        _next_property;
109
    private IntegerField        _child_property;
112
    private IntegerField        _child_property;
113
    private ByteArrayField      _clsid;
110
    private IntegerField        _seconds_1;
114
    private IntegerField        _seconds_1;
111
    private IntegerField        _days_1;
115
    private IntegerField        _days_1;
112
    private IntegerField        _seconds_2;
116
    private IntegerField        _seconds_2;
Lines 136-141 Link Here
136
                                              _NO_INDEX, _raw_data);
140
                                              _NO_INDEX, _raw_data);
137
        _child_property    = new IntegerField(_child_property_offset,
141
        _child_property    = new IntegerField(_child_property_offset,
138
                                              _NO_INDEX, _raw_data);
142
                                              _NO_INDEX, _raw_data);
143
        _clsid             = new ByteArrayField(_clsid_offset, 16, _raw_data);
144
139
        _seconds_1         = new IntegerField(_seconds_1_offset, 0,
145
        _seconds_1         = new IntegerField(_seconds_1_offset, 0,
140
                                              _raw_data);
146
                                              _raw_data);
141
        _days_1            = new IntegerField(_days_1_offset, 0, _raw_data);
147
        _days_1            = new IntegerField(_days_1_offset, 0, _raw_data);
Lines 173-178 Link Here
173
                                              _raw_data);
179
                                              _raw_data);
174
        _child_property    = new IntegerField(_child_property_offset,
180
        _child_property    = new IntegerField(_child_property_offset,
175
                                              _raw_data);
181
                                              _raw_data);
182
        _clsid             = new ByteArrayField(_clsid_offset, 16, _raw_data);
176
        _seconds_1         = new IntegerField(_seconds_1_offset, _raw_data);
183
        _seconds_1         = new IntegerField(_seconds_1_offset, _raw_data);
177
        _days_1            = new IntegerField(_days_1_offset, _raw_data);
184
        _days_1            = new IntegerField(_days_1_offset, _raw_data);
178
        _seconds_2         = new IntegerField(_seconds_2_offset, _raw_data);
185
        _seconds_2         = new IntegerField(_seconds_2_offset, _raw_data);
Lines 445-450 Link Here
445
    static boolean isValidIndex(int index)
452
    static boolean isValidIndex(int index)
446
    {
453
    {
447
        return index != _NO_INDEX;
454
        return index != _NO_INDEX;
455
    }
456
457
    /**
458
     * @return CLSID assigned to the directory property
459
     *
460
     *         "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
461
     * offset   01234567890123456789012345678901234567
462
     * [0..37]  0         1         2         3
463
     *
464
     */
465
466
    private final static int[]  clsid_separator_offset = {   0,   9,  14,  19,  24,  37 };
467
    private final static char[] clsid_separator_char   = { '{', '-', '-', '-', '-', '}' };
468
    private final static byte[] clsid_byte2str  = { 3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15 };
469
470
    public String getCLSID()
471
    {
472
        StringBuffer buf = new StringBuffer(38);
473
474
        byte[] data = _clsid.get();
475
        for (int i=0; i< data.length; i++)
476
            buf.append(HexDump.toHex(data[clsid_byte2str[i]]));
477
478
        for (int i=0; i<clsid_separator_offset.length; i++)
479
            buf.insert( clsid_separator_offset[i], clsid_separator_char[i]);
480
481
        return buf.toString();
482
    }
483
484
    /**
485
     * Sets CLSID to be assigned to the directory property
486
     * "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
487
     *
488
     * @param CLSID to be assigned to the directory entry
489
     *
490
     *         "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
491
     * offset   01234567890123456789012345678901234567
492
     * [0..37]  0         1         2         3
493
     *
494
     */
495
496
    public void setCLSID(final String clsid)
497
    {
498
        String msg = "Invalid clsid ('" + clsid + "'). Expected '{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}'";
499
500
        if (clsid.length() != 38 )
501
            throw new IllegalArgumentException(msg);
502
503
        StringBuffer buf = new StringBuffer(38);
504
        for (int i=1; i < clsid.length()-1; i++)
505
            if (clsid.charAt(i) != '-') buf.append( clsid.charAt(i) );
506
507
        try {
508
            byte[] data = new byte[16];
509
            for (int i=0; i<data.length; i++)
510
                data[clsid_byte2str[i]] = (byte)Integer.parseInt("" + buf.charAt(2*i) + buf.charAt(2*i+1), 16);
511
512
            _clsid.set(data,_raw_data);
513
        }
514
        catch (NumberFormatException e) {
515
            throw new IllegalArgumentException(msg);
516
        }
448
    }
517
    }
449
518
450
    /* ********** START implementation of Child ********** */
519
    /* ********** START implementation of Child ********** */
(-)src/java/org/apache/poi/util/ByteArrayField.java (+89 lines)
Added Link Here
1
package org.apache.poi.util;
2
3
import java.io.*;
4
5
public class ByteArrayField
6
        implements FixedField
7
{
8
9
    private byte[]            _value;
10
    private final int         _offset;
11
12
    public ByteArrayField(final int offset, final int length)
13
        throws ArrayIndexOutOfBoundsException
14
    {
15
        if (offset < 0)
16
        {
17
            throw new ArrayIndexOutOfBoundsException("negative offset");
18
        }
19
        _offset = offset;
20
21
        if (length < 1)
22
        {
23
            throw new ArrayIndexOutOfBoundsException("negative or zero length");
24
        }
25
        _value = new byte[length];
26
    }
27
28
    public ByteArrayField(final int offset, final int length, final byte[] data)
29
    {
30
        this(offset,length);
31
        readFromBytes(data);
32
    }
33
34
    public ByteArrayField(final int offset, final byte[] value, final byte[] data)
35
    {
36
        this(offset,value.length);
37
        set(value,data);
38
    }
39
40
    public byte[] get()
41
        throws ArrayIndexOutOfBoundsException
42
    {
43
        byte[] data = new byte[_value.length];
44
        System.arraycopy(_value, 0, data, 0, _value.length);
45
        return data;
46
    }
47
48
    public void set(final byte[] data)
49
        throws ArrayIndexOutOfBoundsException
50
    {
51
        System.arraycopy(data, 0, _value, 0, Math.min(data.length, _value.length));
52
    }
53
54
    public void set(final byte[] value, final byte[] data)
55
        throws ArrayIndexOutOfBoundsException
56
    {
57
        set(value);
58
        writeToBytes(data);
59
    }
60
61
    public void readFromBytes(byte [] data)
62
        throws ArrayIndexOutOfBoundsException
63
    {
64
        System.arraycopy(data, _offset, _value, 0, _value.length);
65
    };
66
67
    public void readFromStream(InputStream stream)
68
        throws IOException, LittleEndian.BufferUnderrunException
69
    {
70
        stream.read(_value, 0, _value.length);
71
    }
72
73
    public void writeToBytes(byte [] data)
74
        throws ArrayIndexOutOfBoundsException
75
    {
76
        System.arraycopy(_value, 0, data, _offset, _value.length);
77
    }
78
79
    public String toString()
80
    {
81
        StringBuffer retVal = new StringBuffer();
82
        for(int x = 0; x < _value.length; x++)
83
        {
84
            retVal.append(HexDump.toHex(_value[x]));
85
        }
86
        return retVal.toString();
87
    }
88
89
}

Return to bug 24183