fcs
2025-04-10 0163870d662dc5b7d69ceff977490ede594f7d82
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
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
//
// officegen: basic Microsoft Office common code
//
// Please refer to README.md for this module's documentations.
//
// Copyright (c) 2013 Ziv Barber;
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
 
/**
 * Basicgen common utilities used by any document type related to Microsoft Office.
 */
 
var baseobj = require('../core/index.js')
 
function encodeHTML(inStr) {
  return inStr
    .replace(/&/g, '&')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
}
 
/**
 * This method extending the given officegen object with the common code needed by any MS-Office based document.
 * Use this module for every type of MS-Office document.
 *
 * @example <caption>Using this module for implementing a new MS-Office based document type:</caption>
 * var baseobj = require ( "officegen" )
 * var msdoc = require ( "./lib/msofficegen.js" )
 *
 * function makeMyDoc ( officegenObj, typeCodeName, options, officegenObjPlugins, typeInfo ) {
 *   msdoc.makemsdoc ( officegenObj, typeCodeName, options, officegenObjPlugins, typeInfo )
 *   officegenObjPlugins.plugs.type.msoffice.makeOfficeGenerator ( 'word', 'document', {} )
 *
 *   officegenObj.on ( 'clearData', function () {
 *   })
 * }
 * @param {object} genobj The object to extend.
 * @param {object} new_type The type of object to create.
 * @param {object} options The object's options.
 * @param {object} gen_private Access to the internals of this object.
 * @param {object} type_info Additional information about this type.
 * @summary Extend officegen object with MS-Office support.
 * @constructor
 * @name makemsdoc
 */
function makemsdoc(genobj, new_type, options, gen_private, type_info) {
  /**
   * Generate string of the current date and time.
   *
   * This method generating a string with the current date and time in Office XML format.
   *
   * @return String of the current date and time in Office XML format.
   */
  function getCurDateTimeForOffice() {
    var date = new Date()
 
    var year = date.getFullYear()
    var month = date.getMonth() + 1
    var day = date.getDate()
    var hour = date.getHours()
    var min = date.getMinutes()
    var sec = date.getSeconds()
 
    month = (month < 10 ? '0' : '') + month
    day = (day < 10 ? '0' : '') + day
    hour = (hour < 10 ? '0' : '') + hour
    min = (min < 10 ? '0' : '') + min
    sec = (sec < 10 ? '0' : '') + sec
 
    return (
      year + '-' + month + '-' + day + 'T' + hour + ':' + min + ':' + sec + 'Z'
    )
  }
 
  /**
   * Compact the given array.
   *
   * This function compacting the given array.
   *
   * @param {object} arr The array to compact.
   */
  function compactArray(arr) {
    var len = arr.length
 
    for (var i = 0; i < len; i++) {
      if (arr[i]) {
        arr.push(arr[i])
      } // Endif.
    } // End of for loop.
 
    arr.splice(0, len) // Cut the array and leave only the non-empty values.
  }
 
  /**
   * Create the main files list resource.
   *
   * @param {object} data Ignored by this callback function.
   * @return Text string.
   */
  function cbMakeMainFilesList(data) {
    var outString = gen_private.plugs.type.msoffice.cbMakeMsOfficeBasicXml(data)
    outString +=
      '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">'
 
    for (
      var i = 0, total_size = gen_private.type.msoffice.files_list.length;
      i < total_size;
      i++
    ) {
      if (typeof gen_private.type.msoffice.files_list[i] !== 'undefined') {
        if (gen_private.type.msoffice.files_list[i].ext) {
          // Fixed by @author:vtloc @date:2014Jan09
          // Reason: if we write out duplicate extension, office will raise error
          //
          if (
            outString.indexOf(
              '<Default Extension="' +
                gen_private.type.msoffice.files_list[i].ext
            ) === -1
          ) {
            // check to make sure we don't write duplicate extension tag
            outString +=
              '<Default Extension="' +
              gen_private.type.msoffice.files_list[i].ext +
              '" ContentType="' +
              gen_private.type.msoffice.files_list[i].type +
              '"/>'
 
            if (gen_private.type.msoffice.files_list[i].ext === 'jpeg') {
              outString += '<Default Extension="jpg" ContentType="image/jpg"/>'
            } // Endif.
          }
        } else {
          outString +=
            '<Override PartName="' +
            gen_private.type.msoffice.files_list[i].name +
            '" ContentType="' +
            gen_private.type.msoffice.files_list[i].type +
            '"/>'
        } // Endif.
      } // Endif.
    } // End of for loop.
 
    outString += '</Types>\n'
    return outString
  }
 
  /**
   * Create the theme to use with this document.
   *
   * @param {object} data Ignored by this callback function.
   * @return Text string.
   */
  function cbMakeTheme(data) {
    if (genobj.theme) {
      // console.log ( genobj.theme )
      return genobj.theme
    } // Endif.
 
    return (
      gen_private.plugs.type.msoffice.cbMakeMsOfficeBasicXml(data) +
      '<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme"><a:themeElements><a:clrScheme name="Office"><a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="1F497D"/></a:dk2><a:lt2><a:srgbClr val="EEECE1"/></a:lt2><a:accent1><a:srgbClr val="4F81BD"/></a:accent1><a:accent2><a:srgbClr val="C0504D"/></a:accent2><a:accent3><a:srgbClr val="9BBB59"/></a:accent3><a:accent4><a:srgbClr val="8064A2"/></a:accent4><a:accent5><a:srgbClr val="4BACC6"/></a:accent5><a:accent6><a:srgbClr val="F79646"/></a:accent6><a:hlink><a:srgbClr val="0000FF"/></a:hlink><a:folHlink><a:srgbClr val="800080"/></a:folHlink></a:clrScheme><a:fontScheme name="Office"><a:majorFont><a:latin typeface="Calibri"/><a:ea typeface=""/><a:cs typeface=""/><a:font script="Jpan" typeface="MS P????"/><a:font script="Hang" typeface="?? ??"/><a:font script="Hans" typeface="??"/><a:font script="Hant" typeface="????"/><a:font script="Arab" typeface="Times New Roman"/><a:font script="Hebr" typeface="Times New Roman"/><a:font script="Thai" typeface="Angsana New"/><a:font script="Ethi" typeface="Nyala"/><a:font script="Beng" typeface="Vrinda"/><a:font script="Gujr" typeface="Shruti"/><a:font script="Khmr" typeface="MoolBoran"/><a:font script="Knda" typeface="Tunga"/><a:font script="Guru" typeface="Raavi"/><a:font script="Cans" typeface="Euphemia"/><a:font script="Cher" typeface="Plantagenet Cherokee"/><a:font script="Yiii" typeface="Microsoft Yi Baiti"/><a:font script="Tibt" typeface="Microsoft Himalaya"/><a:font script="Thaa" typeface="MV Boli"/><a:font script="Deva" typeface="Mangal"/><a:font script="Telu" typeface="Gautami"/><a:font script="Taml" typeface="Latha"/><a:font script="Syrc" typeface="Estrangelo Edessa"/><a:font script="Orya" typeface="Kalinga"/><a:font script="Mlym" typeface="Kartika"/><a:font script="Laoo" typeface="DokChampa"/><a:font script="Sinh" typeface="Iskoola Pota"/><a:font script="Mong" typeface="Mongolian Baiti"/><a:font script="Viet" typeface="Times New Roman"/><a:font script="Uigh" typeface="Microsoft Uighur"/></a:majorFont><a:minorFont><a:latin typeface="Calibri"/><a:ea typeface=""/><a:cs typeface=""/><a:font script="Jpan" typeface="MS P????"/><a:font script="Hang" typeface="?? ??"/><a:font script="Hans" typeface="??"/><a:font script="Hant" typeface="????"/><a:font script="Arab" typeface="Arial"/><a:font script="Hebr" typeface="Arial"/><a:font script="Thai" typeface="Cordia New"/><a:font script="Ethi" typeface="Nyala"/><a:font script="Beng" typeface="Vrinda"/><a:font script="Gujr" typeface="Shruti"/><a:font script="Khmr" typeface="DaunPenh"/><a:font script="Knda" typeface="Tunga"/><a:font script="Guru" typeface="Raavi"/><a:font script="Cans" typeface="Euphemia"/><a:font script="Cher" typeface="Plantagenet Cherokee"/><a:font script="Yiii" typeface="Microsoft Yi Baiti"/><a:font script="Tibt" typeface="Microsoft Himalaya"/><a:font script="Thaa" typeface="MV Boli"/><a:font script="Deva" typeface="Mangal"/><a:font script="Telu" typeface="Gautami"/><a:font script="Taml" typeface="Latha"/><a:font script="Syrc" typeface="Estrangelo Edessa"/><a:font script="Orya" typeface="Kalinga"/><a:font script="Mlym" typeface="Kartika"/><a:font script="Laoo" typeface="DokChampa"/><a:font script="Sinh" typeface="Iskoola Pota"/><a:font script="Mong" typeface="Mongolian Baiti"/><a:font script="Viet" typeface="Arial"/><a:font script="Uigh" typeface="Microsoft Uighur"/></a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="50000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="35000"><a:schemeClr val="phClr"><a:tint val="37000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="15000"/><a:satMod val="350000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="16200000" scaled="1"/></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:shade val="51000"/><a:satMod val="130000"/></a:schemeClr></a:gs><a:gs pos="80000"><a:schemeClr val="phClr"><a:shade val="93000"/><a:satMod val="130000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="94000"/><a:satMod val="135000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="16200000" scaled="0"/></a:gradFill></a:fillStyleLst><a:lnStyleLst><a:ln w="9525" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"><a:shade val="95000"/><a:satMod val="105000"/></a:schemeClr></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="25400" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="38100" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="20000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="38000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst><a:scene3d><a:camera prst="orthographicFront"><a:rot lat="0" lon="0" rev="0"/></a:camera><a:lightRig rig="threePt" dir="t"><a:rot lat="0" lon="0" rev="1200000"/></a:lightRig></a:scene3d><a:sp3d><a:bevelT w="63500" h="25400"/></a:sp3d></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="40000"/><a:satMod val="350000"/></a:schemeClr></a:gs><a:gs pos="40000"><a:schemeClr val="phClr"><a:tint val="45000"/><a:shade val="99000"/><a:satMod val="350000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="20000"/><a:satMod val="255000"/></a:schemeClr></a:gs></a:gsLst><a:path path="circle"><a:fillToRect l="50000" t="-80000" r="50000" b="180000"/></a:path></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="80000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="30000"/><a:satMod val="200000"/></a:schemeClr></a:gs></a:gsLst><a:path path="circle"><a:fillToRect l="50000" t="50000" r="50000" b="50000"/></a:path></a:gradFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements><a:objectDefaults/><a:extraClrSchemeLst/></a:theme>'
    )
  }
 
  /**
   * Generate the coreProperties for the document.
   *
   * This method creating the docProps/core.xml resource inside any MS based document. Each type of document generator is adding the
   * supported document properties using calls to gen_private.plugs.type.msoffice.addInfoType().
   *
   * @param {object} data Ignored by this callback function.
   * @return Text string.
   */
  function cbMakeCore(data) {
    var curDateTime = getCurDateTimeForOffice()
    var userName =
      genobj.options.author || genobj.options.creator || 'officegen'
    var extraFields = ''
 
    // Work on all the properties:
    for (var infoRec in genobj.info) {
      if (
        genobj.info[infoRec] &&
        genobj.info[infoRec].element &&
        genobj.info[infoRec].data
      ) {
        extraFields +=
          '<' +
          genobj.info[infoRec].element +
          '>' +
          encodeHTML(genobj.info[infoRec].data) +
          '</' +
          genobj.info[infoRec].element +
          '>'
      } // Endif.
    } // End of for loop.
 
    return (
      gen_private.plugs.type.msoffice.cbMakeMsOfficeBasicXml(data) +
      '<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
      extraFields +
      '<dc:creator>' +
      userName +
      '</dc:creator><cp:lastModifiedBy>' +
      userName +
      '</cp:lastModifiedBy><cp:revision>1</cp:revision><dcterms:created xsi:type="dcterms:W3CDTF">' +
      curDateTime +
      '</dcterms:created><dcterms:modified xsi:type="dcterms:W3CDTF">' +
      curDateTime +
      '</dcterms:modified></cp:coreProperties>'
    )
  }
 
  /**
   * Remove selected records from the given array.
   *
   * This method destroys records inside the given array of the given type.
   *
   * @param {object} arr The array to work on it.
   * @param {object} type_to_clear The type of records to clear.
   */
  function clearSmartArrayFromType(arr, type_to_clear) {
    var is_need_compact = false
 
    for (var i = 0, total_size = arr.length; i < total_size; i++) {
      if (typeof arr[i] !== 'undefined') {
        if (arr[i].clear && arr[i].clear === type_to_clear) {
          delete arr[i]
          is_need_compact = true
        } // Endif.
      } // Endif.
    } // End of for loop.
 
    if (is_need_compact) {
      compactArray(arr)
    } // Endif.
  }
 
  /**
   * Clean after finishing to generate the document.
   *
   * This method destroying any additional resources added by the 'beforeGen' effect to the generator.
   *
   * @param {object} err Generation error message (if there were any).
   * @param {object} written Number of bytes been created.
   */
  function cbOfficeClearAfterGenerate(err, written) {
    if (err) {
      // BMK_TODO:
    } // Endif.
 
    clearSmartArrayFromType(gen_private.type.msoffice.rels_main, 'generate')
    clearSmartArrayFromType(gen_private.type.msoffice.rels_app, 'generate')
    clearSmartArrayFromType(gen_private.type.msoffice.files_list, 'generate')
 
    if (genobj.generate_data) {
      genobj.generate_data = null
      delete genobj.generate_data
    } // Endif.
  }
 
  /**
   * Clear all the information of the current document.
   */
  function cbOfficeClearDocData() {
    clearSmartArrayFromType(gen_private.type.msoffice.rels_main, 'data')
    clearSmartArrayFromType(gen_private.type.msoffice.rels_app, 'data')
    clearSmartArrayFromType(gen_private.type.msoffice.files_list, 'data')
 
    for (var infoItem in genobj.info) {
      genobj.info[infoItem].data = genobj.info[infoItem].def_data
    } // Endif.
 
    gen_private.type.msoffice.src_files_list = []
 
    // Ask the document implementation to clear it's data:
    genobj.emit('clearDocType', gen_private)
  }
 
  // Basic API for plugins:
 
  gen_private.plugs.type.msoffice = {}
 
  /**
   * Configure a new Office property type.
   *
   * This method register a new type of property that the user can configure. This property must be
   * a valid MS-Office property as you can configure on the "files/properties" menu option on MS-Office.
   *
   * @param {object} element_name The name of the XML element of this type.
   * @param {object} def_data Default value of this type.
   * @param {object} prop_name The name of the options property to configure this type.
   * @param {object} user_access_func_name The name of the function to create to configure this type.
   */
  gen_private.plugs.type.msoffice.addInfoType = function(
    element_name,
    def_data,
    prop_name,
    user_access_func_name
  ) {
    genobj.info[element_name] = {}
    genobj.info[element_name].element = element_name
    genobj.info[element_name].data = def_data
    genobj.info[element_name].def_data = def_data
 
    // The user of officegen can configure this property using the options object:
    if (genobj.options[prop_name]) {
      genobj.info[element_name].data = genobj.options[prop_name]
    } // Endif.
 
    genobj[user_access_func_name] = function(new_data) {
      genobj.info[element_name].data = new_data
    }
  }
 
  /**
   * Get the string that opening every Office XML type.
   *
   * Every Microsoft Office XML resource will have this header at the begining of the file.
   *
   * @param {object} data Ignored by this callback function.
   * @return Text string.
   */
  gen_private.plugs.type.msoffice.cbMakeMsOfficeBasicXml = function(data) {
    return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n'
  }
 
  /**
   * Generate rel based XML file.
   *
   * @param {object} data Array filled with all the rels links.
   * @return Text string.
   */
  gen_private.plugs.type.msoffice.cbMakeRels = function(data) {
    var outString = gen_private.plugs.type.msoffice.cbMakeMsOfficeBasicXml(data)
    outString +=
      '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'
 
    // Add all the rels records inside the data array:
    var realRel = 1
    for (var i = 0, total_size = data.length; i < total_size; i++) {
      if (typeof data[i] !== 'undefined') {
        outString +=
          '<Relationship Id="rId' +
          realRel +
          '" Type="' +
          data[i].type +
          '" Target="' +
          data[i].target +
          '"'
 
        if (data[i].targetMode) {
          outString += ' TargetMode="' + data[i].targetMode + '"'
        } // Endif.
 
        outString += '/>'
        realRel++
      } // Endif.
    } // End of for loop.
 
    outString += '</Relationships>\n'
    return outString
  }
 
  /**
   * Prepare the officegen object to MS-Office documents.
   *
   * Every plugin that implementing gemenrating MS-Office document must call this method to initialize
   * the common stuff.
   *
   * @param {object} main_path The name of the main folder holding the common resources of this type.
   * @param {object} main_file The main resource file name of this type.
   * @param {object} ext_opt Optional settings (unused right now).
   */
  gen_private.plugs.type.msoffice.makeOfficeGenerator = function(
    main_path,
    main_file,
    ext_opt
  ) {
    gen_private.features.type.msoffice = {}
    gen_private.features.type.msoffice.main_path = main_path
    gen_private.features.type.msoffice.main_path_file = main_file
    gen_private.type.msoffice = {}
    gen_private.type.msoffice.rels_main = []
    gen_private.type.msoffice.rels_app = []
    gen_private.type.msoffice.files_list = []
    gen_private.type.msoffice.src_files_list = []
 
    // Holding all the Office properties:
    genobj.info = {}
 
    genobj.on('afterGen', cbOfficeClearAfterGenerate)
    genobj.on('clearDoc', cbOfficeClearDocData)
 
    gen_private.type.msoffice.rels_main.push(
      {
        target: 'docProps/app.xml',
        type:
          'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
        clear: 'type'
      },
      {
        target: 'docProps/core.xml',
        type:
          'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
        clear: 'type'
      },
      {
        target:
          gen_private.features.type.msoffice.main_path +
          '/' +
          gen_private.features.type.msoffice.main_path_file +
          '.xml',
        type:
          'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
        clear: 'type'
      }
    )
 
    gen_private.type.msoffice.files_list.push(
      {
        ext: 'rels',
        type: 'application/vnd.openxmlformats-package.relationships+xml',
        clear: 'type'
      },
      {
        ext: 'xml',
        type: 'application/xml',
        clear: 'type'
      },
      {
        ext: 'jpeg',
        type: 'image/jpeg',
        clear: 'type'
      },
      {
        ext: 'png',
        type: 'image/png',
        clear: 'type'
      },
      {
        ext: 'gif',
        type: 'image/gif',
        clear: 'type'
      },
      {
        name: '/docProps/app.xml',
        type:
          'application/vnd.openxmlformats-officedocument.extended-properties+xml',
        clear: 'type'
      },
      {
        name:
          '/' +
          gen_private.features.type.msoffice.main_path +
          '/theme/theme1.xml',
        type: 'application/vnd.openxmlformats-officedocument.theme+xml',
        clear: 'type'
      },
      {
        name: '/docProps/core.xml',
        type: 'application/vnd.openxmlformats-package.core-properties+xml',
        clear: 'type'
      }
    )
 
    genobj.theme = genobj.options.themeXml || null
 
    genobj.setTheme = function(xmlData) {
      genobj.theme = xmlData
      // BMK_TODO: BMK_TODO: In the future I'll add a parser to the .thmx files.
    }
 
    gen_private.plugs.intAddAnyResourceToParse(
      '_rels\\.rels',
      'buffer',
      gen_private.type.msoffice.rels_main,
      gen_private.plugs.type.msoffice.cbMakeRels,
      true
    )
    gen_private.plugs.intAddAnyResourceToParse(
      '[Content_Types].xml',
      'buffer',
      null,
      cbMakeMainFilesList,
      true
    )
    gen_private.plugs.intAddAnyResourceToParse(
      'docProps\\core.xml',
      'buffer',
      null,
      cbMakeCore,
      true
    )
 
    gen_private.plugs.intAddAnyResourceToParse(
      gen_private.features.type.msoffice.main_path + '\\theme\\theme1.xml',
      'buffer',
      null,
      cbMakeTheme,
      true
    )
  }
 
  /**
   * Generate random unique ID.
   *
   * This method generates a random unique ID.
   *
   * @param {object} baseGroup Optional first part of the ID.
   * @return Unique ID string.
   */
  gen_private.plugs.type.msoffice.makeUniqueID = function(baseGroup) {
    var charTable = [
      '0',
      '1',
      '2',
      '3',
      '4',
      '5',
      '6',
      '7',
      '8',
      '9',
      'A',
      'B',
      'C',
      'D',
      'E',
      'F',
      'G',
      'H',
      'I',
      'J',
      'K',
      'L',
      'M',
      'N',
      'O',
      'P',
      'Q',
      'R',
      'S',
      'T',
      'U',
      'V',
      'W',
      'X',
      'Y',
      'Z'
    ]
 
    function makeRandomChar() {
      return charTable[Math.floor(Math.random() * charTable.length)]
    }
 
    var outStr =
      baseGroup ||
      makeRandomChar() +
        makeRandomChar() +
        makeRandomChar() +
        makeRandomChar() +
        makeRandomChar() +
        makeRandomChar() +
        makeRandomChar() +
        makeRandomChar()
 
    outStr +=
      '-' +
      makeRandomChar() +
      makeRandomChar() +
      makeRandomChar() +
      makeRandomChar()
    outStr +=
      '-' +
      makeRandomChar() +
      makeRandomChar() +
      makeRandomChar() +
      makeRandomChar()
    outStr +=
      '-' +
      makeRandomChar() +
      makeRandomChar() +
      makeRandomChar() +
      makeRandomChar()
    outStr +=
      '-' +
      makeRandomChar() +
      makeRandomChar() +
      makeRandomChar() +
      makeRandomChar()
    outStr +=
      makeRandomChar() + makeRandomChar() + makeRandomChar() + makeRandomChar()
    outStr +=
      makeRandomChar() + makeRandomChar() + makeRandomChar() + makeRandomChar()
    return outStr
  }
 
  return this
}
 
baseobj.plugins.registerPrototype(
  'msoffice',
  makemsdoc,
  'Microsoft Office Document Prototype'
)
 
exports.makemsdoc = makemsdoc