zhao
2021-07-09 0821715ebc11d3934d0594a1cc2c39686d808906
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
/* ====================================================================
   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.
==================================================================== */
 
/* ================================================================
 * About NPOI
 * Author: Tony Qu 
 * Author's email: tonyqus (at) gmail.com 
 * Author's Blog: tonyqus.wordpress.com.cn (wp.tonyqus.cn)
 * HomePage: http://www.codeplex.com/npoi
 * Contributors:
 * 
 * ==============================================================*/
 
namespace HH.WMS.Utils.NPOI.HPSF
{
    using System;
    using System.IO;
    using System.Collections;
    using HH.WMS.Utils.NPOI.HPSF.Wellknown;
 
    /// <summary>
    /// Convenience class representing a DocumentSummary Information stream in a
    /// Microsoft Office document.
    /// @author Rainer Klute 
    /// klute@rainer-klute.de
    /// @author Drew Varner (Drew.Varner cloSeto sc.edu)
    /// @author robert_flaherty@hyperion.com
    /// @since 2002-02-09
    /// </summary>
    [Serializable]
    public class DocumentSummaryInformation : SpecialPropertySet
    {
 
        /**
         * The document name a document summary information stream
         * usually has in a POIFS filesystem.
         */
        public static String DEFAULT_STREAM_NAME =
            "\x0005DocumentSummaryInformation";
 
        public override PropertyIDMap PropertySetIDMap
        {
            get
            {
                return PropertyIDMap.DocumentSummaryInformationProperties;
            }
        }
 
        /// <summary>
        /// Initializes a new instance of the <see cref="DocumentSummaryInformation"/> class.
        /// </summary>
        /// <param name="ps">A property Set which should be Created from a
        /// document summary information stream.</param>
        public DocumentSummaryInformation(PropertySet ps): base(ps)
        {
            if (!IsDocumentSummaryInformation)
                throw new UnexpectedPropertySetTypeException
                    ("Not a " + GetType().Name);
        }
 
 
 
        /// <summary>
        /// Gets or sets the category.
        /// </summary>
        /// <value>The category value</value>
        public String Category
        {
            get
            {
                return (String)GetProperty(PropertyIDMap.PID_CATEGORY);
            }
            set
            {
                MutableSection s = (MutableSection)FirstSection;
                s.SetProperty(PropertyIDMap.PID_CATEGORY, value);
            }
        }
 
        /// <summary>
        /// Removes the category.
        /// </summary>
        public void RemoveCategory()
        {
            MutableSection s = (MutableSection)FirstSection;
            s.RemoveProperty(PropertyIDMap.PID_CATEGORY);
        }
 
 
 
        /// <summary>
        /// Gets or sets the presentation format (or null).
        /// </summary>
        /// <value>The presentation format value</value>
        public String PresentationFormat
        {
            get { return (String)GetProperty(PropertyIDMap.PID_PRESFORMAT); }
            set
            {
                MutableSection s = (MutableSection)FirstSection;
                s.SetProperty(PropertyIDMap.PID_PRESFORMAT, value);
            }
        }
 
        /// <summary>
        /// Removes the presentation format.
        /// </summary>
        public void RemovePresentationFormat()
        {
            MutableSection s = (MutableSection)FirstSection;
            s.RemoveProperty(PropertyIDMap.PID_PRESFORMAT);
        }
 
 
 
        /// <summary>
        /// Gets or sets the byte count or 0 if the {@link
        /// DocumentSummaryInformation} does not contain a byte count.
        /// </summary>
        /// <value>The byteCount value</value>
        public int ByteCount
        {
            get
            {
                return GetPropertyIntValue(PropertyIDMap.PID_BYTECOUNT);
            }
            set
            {
                MutableSection s = (MutableSection)FirstSection;
                s.SetProperty(PropertyIDMap.PID_BYTECOUNT, value);
            }
        }
 
        /// <summary>
        /// Removes the byte count.
        /// </summary>
        public void RemoveByteCount()
        {
            MutableSection s = (MutableSection)FirstSection;
            s.RemoveProperty(PropertyIDMap.PID_BYTECOUNT);
        }
 
 
 
        /// <summary>
        /// Gets or sets the line count or 0 if the {@link
        /// DocumentSummaryInformation} does not contain a line count.
        /// </summary>
        /// <value>The line count value.</value>
        public int LineCount
        {
            get
            {
                return GetPropertyIntValue(PropertyIDMap.PID_LINECOUNT);
            }
            set
            {
                MutableSection s = (MutableSection)FirstSection;
                s.SetProperty(PropertyIDMap.PID_LINECOUNT, value);
            }
        }
 
 
        /// <summary>
        /// Removes the line count.
        /// </summary>
        public void RemoveLineCount()
        {
            MutableSection s = (MutableSection)FirstSection;
            s.RemoveProperty(PropertyIDMap.PID_LINECOUNT);
        }
 
 
 
        /// <summary>
        /// Gets or sets the par count or 0 if the {@link
        /// DocumentSummaryInformation} does not contain a par count.
        /// </summary>
        /// <value>The par count value</value>
        public int ParCount
        {
            get { return GetPropertyIntValue(PropertyIDMap.PID_PARCOUNT); }
            set
            {
                MutableSection s = (MutableSection)FirstSection;
                s.SetProperty(PropertyIDMap.PID_PARCOUNT, value);
            }
        }
 
 
        /// <summary>
        /// Removes the par count.
        /// </summary>
        public void RemoveParCount()
        {
            MutableSection s = (MutableSection)FirstSection;
            s.RemoveProperty(PropertyIDMap.PID_PARCOUNT);
        }
 
 
 
        /// <summary>
        /// Gets or sets the slide count or 0 if the {@link
        /// DocumentSummaryInformation} does not contain a slide count.
        /// </summary>
        /// <value>The slide count value</value>
        public int SlideCount
        {
            get { return GetPropertyIntValue(PropertyIDMap.PID_SLIDECOUNT); }
            set
            {
                MutableSection s = (MutableSection)FirstSection;
                s.SetProperty(PropertyIDMap.PID_SLIDECOUNT, value);
            }
        }
 
        /// <summary>
        /// Removes the slide count.
        /// </summary>
        public void RemoveSlideCount()
        {
            MutableSection s = (MutableSection)FirstSection;
            s.RemoveProperty(PropertyIDMap.PID_SLIDECOUNT);
        }
 
 
 
        /// <summary>
        /// Gets or sets the note count or 0 if the {@link
        /// DocumentSummaryInformation} does not contain a note count
        /// </summary>
        /// <value>The note count value</value>
        public int NoteCount
        {
            get { return GetPropertyIntValue(PropertyIDMap.PID_NOTECOUNT); }
            set
            {
                MutableSection s = (MutableSection)FirstSection;
                s.SetProperty(PropertyIDMap.PID_NOTECOUNT, value);
            }
        }
 
        /// <summary>
        /// Removes the note count.
        /// </summary>
        public void RemoveNoteCount()
        {
            MutableSection s = (MutableSection)FirstSection;
            s.RemoveProperty(PropertyIDMap.PID_NOTECOUNT);
        }
 
 
 
        /// <summary>
        /// Gets or sets the hidden count or 0 if the {@link
        /// DocumentSummaryInformation} does not contain a hidden
        /// count.
        /// </summary>
        /// <value>The hidden count value.</value>
        public int HiddenCount
        {
            get { return GetPropertyIntValue(PropertyIDMap.PID_HIDDENCOUNT); }
            set
            {
                MutableSection s = (MutableSection)Sections[0];
                s.SetProperty(PropertyIDMap.PID_HIDDENCOUNT, value);
            }
        }
 
        /// <summary>
        /// Removes the hidden count.
        /// </summary>
        public void RemoveHiddenCount()
        {
            MutableSection s = (MutableSection)FirstSection;
            s.RemoveProperty(PropertyIDMap.PID_HIDDENCOUNT);
        }
 
 
 
        /// <summary>
        /// Returns the mmclip count or 0 if the {@link
        /// DocumentSummaryInformation} does not contain a mmclip
        /// count.
        /// </summary>
        /// <value>The mmclip count value.</value>
        public int MMClipCount
        {
            get { return GetPropertyIntValue(PropertyIDMap.PID_MMCLIPCOUNT); }
            set
            {
                MutableSection s = (MutableSection)FirstSection;
                s.SetProperty(PropertyIDMap.PID_MMCLIPCOUNT, value);
            }
        }
 
        /// <summary>
        /// Removes the MMClip count.
        /// </summary>
        public void RemoveMMClipCount()
        {
            MutableSection s = (MutableSection)FirstSection;
            s.RemoveProperty(PropertyIDMap.PID_MMCLIPCOUNT);
        }
 
 
 
        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="DocumentSummaryInformation"/> is scale.
        /// </summary>
        /// <value><c>true</c> if cropping is desired; otherwise, <c>false</c>.</value>
        public bool Scale
        {
            get { return GetPropertyBooleanValue(PropertyIDMap.PID_SCALE); }
            set
            {
                MutableSection s = (MutableSection)FirstSection;
                s.SetProperty(PropertyIDMap.PID_SCALE, value);
            }
        }
 
        /// <summary>
        /// Removes the scale.
        /// </summary>
        public void RemoveScale()
        {
            MutableSection s = (MutableSection)FirstSection;
            s.RemoveProperty(PropertyIDMap.PID_SCALE);
        }
 
 
 
        /// <summary>
        /// Gets or sets the heading pair (or null)
        /// </summary>
        /// <value>The heading pair value.</value>
        public byte[] HeadingPair
        {
            get
            {
                return (byte[])GetProperty(PropertyIDMap.PID_HEADINGPAIR);
            }
            set {
                throw new NotImplementedException("Writing byte arrays ");
            }
        }
 
        /// <summary>
        /// Removes the heading pair.
        /// </summary>
        public void RemoveHeadingPair()
        {
            MutableSection s = (MutableSection)FirstSection;
            s.RemoveProperty(PropertyIDMap.PID_HEADINGPAIR);
        }
 
 
 
        /// <summary>
        /// Gets or sets the doc parts.
        /// </summary>
        /// <value>The doc parts value</value>
        public byte[] Docparts
        {
            get
            {
                return (byte[])GetProperty(PropertyIDMap.PID_DOCPARTS);
            }
            set 
            {
                throw new NotImplementedException("Writing byte arrays");
            }
        }
 
        /// <summary>
        /// Removes the doc parts.
        /// </summary>
        public void RemoveDocparts()
        {
            MutableSection s = (MutableSection)FirstSection;
            s.RemoveProperty(PropertyIDMap.PID_DOCPARTS);
        }
 
 
 
        /// <summary>
        /// Gets or sets the manager (or <c>null</c>).
        /// </summary>
        /// <value>The manager value</value>
        public String Manager
        {
            get { return (String)GetProperty(PropertyIDMap.PID_MANAGER); }
            set
            {
                MutableSection s = (MutableSection)FirstSection;
                s.SetProperty(PropertyIDMap.PID_MANAGER, value);
            }
        }
 
        /// <summary>
        /// Removes the manager.
        /// </summary>
        public void RemoveManager()
        {
            MutableSection s = (MutableSection)FirstSection;
            s.RemoveProperty(PropertyIDMap.PID_MANAGER);
        }
 
 
 
        /// <summary>
        /// Gets or sets the company (or <c>null</c>).
        /// </summary>
        /// <value>The company value</value>
        public String Company
        {
            get { return (String)GetProperty(PropertyIDMap.PID_COMPANY); }
            set
            {
                MutableSection s = (MutableSection)FirstSection;
                s.SetProperty(PropertyIDMap.PID_COMPANY, value);
            }
        }
 
        /// <summary>
        /// Removes the company.
        /// </summary>
        public void RemoveCompany()
        {
            MutableSection s = (MutableSection)FirstSection;
            s.RemoveProperty(PropertyIDMap.PID_COMPANY);
        }
 
 
 
        /// <summary>
        /// Gets or sets a value indicating whether [links dirty].
        /// </summary>
        /// <value><c>true</c> if the custom links are dirty.; otherwise, <c>false</c>.</value>
        public bool LinksDirty
        {
            get { return GetPropertyBooleanValue(PropertyIDMap.PID_LINKSDIRTY); }
            set
            {
                MutableSection s = (MutableSection)FirstSection;
                s.SetProperty(PropertyIDMap.PID_LINKSDIRTY, value);
            }
        }
 
        /// <summary>
        /// Removes the links dirty.
        /// </summary>
        public void RemoveLinksDirty()
        {
            MutableSection s = (MutableSection)FirstSection;
            s.RemoveProperty(PropertyIDMap.PID_LINKSDIRTY);
        }
 
 
 
        /// <summary>
        /// Gets or sets the custom properties.
        /// </summary>
        /// <value>The custom properties.</value>
        public CustomProperties CustomProperties
        {
            get
            {
                CustomProperties cps = null;
                if (SectionCount >= 2)
                {
                    cps = new CustomProperties();
                    Section section = (Section)Sections[1];
                    IDictionary dictionary = section.Dictionary;
                    Property[] properties = section.Properties;
                    int propertyCount = 0;
                    for (int i = 0; i < properties.Length; i++)
                    {
                        Property p = properties[i];
                        long id = p.ID;
                        if (id != 0 && id != 1)
                        {
                            propertyCount++;
                            CustomProperty cp = new CustomProperty(p,
                                    (string)dictionary[id]);
                            cps.Put(cp.Name, cp);
                        }
                    }
                    if (cps.Count != propertyCount)
                        cps.IsPure=false;
                }
                return cps;
            }
            set 
            {
                EnsureSection2();
                MutableSection section = (MutableSection)Sections[1];
                IDictionary dictionary = value.Dictionary;
                section.Clear();
 
                /* Set the codepage. If both custom properties and section have a
                 * codepage, the codepage from the custom properties wins, else take the
                 * one that is defined. If none is defined, take Unicode. */
                int cpCodepage = value.Codepage;
                if (cpCodepage < 0)
                    cpCodepage = section.Codepage;
                if (cpCodepage < 0)
                    cpCodepage = (int)Constants.CP_UNICODE;
                value.Codepage=cpCodepage;
                section.Codepage=cpCodepage; //add codepage propertyset
                section.Dictionary=dictionary; //generate dictionary propertyset
                //generate MutableSections
                for (IEnumerator i = value.Values.GetEnumerator(); i.MoveNext(); )
                {
                    Property p = (Property)i.Current;
                    section.SetProperty(p);
                }
            }
        }
 
 
        /// <summary>
        /// Creates section 2 if it is not alReady present.
        /// </summary>
        private void EnsureSection2()
        {
            if (SectionCount < 2)
            {
                MutableSection s2 = new MutableSection();
                s2.SetFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID2);
                AddSection(s2);
            }
        }
 
 
 
        /// <summary>
        /// Removes the custom properties.
        /// </summary>
        public void RemoveCustomProperties()
        {
            if (SectionCount >= 2)
                Sections.RemoveAt(1);
            else
                throw new HPSFRuntimeException("Illegal internal format of Document SummaryInformation stream: second section is missing.");
        }
 
    }
}