~zorba-coders/zorba/1188033

« back to all changes in this revision

Viewing changes to src/archive_module.xq.src/archive_module.cpp

  • Committer: Luis Rodriguez Gonzalez
  • Date: 2013-07-29 19:24:56 UTC
  • Revision ID: kuraru@gmail.com-20130729192456-w67l7o6csl2ekciu
Changes to have global Items from ArchiveModule class made

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
#define ERROR_CORRUPTED_ARCHIVE "CORRUPTED-ARCHIVE"
53
53
#define ERROR_DIFFERENT_COMPRESSIONS_NOT_SUPPORTED "DIFFERENT-COMPRESSIONS-NOT-SUPPORTED"
54
54
 
55
 
#define FORMAT_KEY_NAME "format"
56
 
#define COMPRESSION_KEY_NAME "compression"
57
 
#define NAME_KEY_NAME "name"
58
 
#define TYPE_KEY_NAME "type"
59
 
#define SIZE_KEY_NAME "size"
60
 
#define LAST_MODIFIED_KEY_NAME "last-modified"
61
 
#define ENCODING_KEY_NAME "encoding"
62
 
 
63
55
namespace zorba { namespace archive {
64
56
 
65
 
 
66
 
zorba::Item ArchiveModule::globalFormatName;
 
57
// Allocating global keys
 
58
zorba::Item ArchiveModule::globalFormatKey;
 
59
zorba::Item ArchiveModule::globalCompressionKey;
 
60
zorba::Item ArchiveModule::globalNameKey;
 
61
zorba::Item ArchiveModule::globalTypeKey;
 
62
zorba::Item ArchiveModule::globalSizeKey;
 
63
zorba::Item ArchiveModule::globalLastModifiedKey;
 
64
zorba::Item ArchiveModule::globalEncodingKey;
67
65
 
68
66
/*******************************************************************************
69
67
 ******************************************************************************/
170
168
  zorba::Item&
171
169
  ArchiveModule::getGlobalItems(enum ArchiveModule::GLOBAL_ITEMS g)
172
170
  {
173
 
      return globalFormatName;
 
171
      switch(g)
 
172
      {
 
173
      case FORMAT: return globalFormatKey;
 
174
      case COMPRESSION: return globalCompressionKey;
 
175
      case NAME: return globalNameKey;
 
176
      case TYPE: return globalTypeKey;
 
177
      case SIZE: return globalSizeKey;
 
178
      case LAST_MODIFIED: return globalLastModifiedKey;
 
179
      case ENCODING: return globalEncodingKey;
 
180
      // we should never touch the default clause but ...
 
181
      default: return globalFormatKey;
 
182
      }
174
183
  }
175
184
 
176
185
/*******************************************************************************
242
251
        Item lKeyValue;
243
252
        lKeyValue = aEntry.getObjectValue(lKey.getStringValue());
244
253
 
245
 
        if(lKey.getStringValue() == NAME_KEY_NAME)
 
254
        if(lKey.getStringValue() == ArchiveModule::getGlobalItems(ArchiveModule::NAME).getStringValue())
246
255
        {
247
256
          theEntryPath = lKeyValue.getStringValue();
248
257
        }
249
 
        else if(lKey.getStringValue() == TYPE_KEY_NAME)
 
258
        else if(lKey.getStringValue() == ArchiveModule::getGlobalItems(ArchiveModule::TYPE).getStringValue())
250
259
        {
251
260
          String filetype = lKeyValue.getStringValue();
252
261
          if(filetype == "directory")
254
263
            theEntryType = directory;
255
264
          }
256
265
        }
257
 
        else if (lKey.getStringValue() == LAST_MODIFIED_KEY_NAME)
 
266
        else if (lKey.getStringValue() == ArchiveModule::getGlobalItems(ArchiveModule::LAST_MODIFIED).getStringValue())
258
267
        {
259
268
          ArchiveModule::parseDateTimeItem(lKeyValue, theLastModified);
260
269
        }
261
 
        else if (lKey.getStringValue() == ENCODING_KEY_NAME)
 
270
        else if (lKey.getStringValue() == ArchiveModule::getGlobalItems(ArchiveModule::ENCODING).getStringValue())
262
271
        {
263
272
          theEncoding = lKeyValue.getStringValue();
264
273
          std::transform(
272
281
            throwError(ERROR_INVALID_ENCODING, lMsg.str().c_str());
273
282
          }
274
283
        }
275
 
        else if (lKey.getStringValue() == COMPRESSION_KEY_NAME)
 
284
        else if (lKey.getStringValue() == ArchiveModule::getGlobalItems(ArchiveModule::COMPRESSION).getStringValue())
276
285
        {
277
286
          theCompression = lKeyValue.getStringValue();
278
287
          std::transform(
280
289
              theCompression.end(),
281
290
              theCompression.begin(), ::toupper);
282
291
        }
 
292
        else if (lKey.getStringValue() == ArchiveModule::getGlobalItems(ArchiveModule::SIZE).getStringValue())
 
293
        {
 
294
            theSize = lKeyValue.getLongValue();
 
295
        }
283
296
      }
284
297
    } else
285
298
        theEntryPath = aEntry.getStringValue();
317
330
        Item lOptionValue;
318
331
        lOptionValue = aOptions.getObjectValue(lOptionKey.getStringValue());
319
332
 
320
 
        if (lOptionKey.getStringValue() == COMPRESSION_KEY_NAME)
 
333
        if (lOptionKey.getStringValue() == ArchiveModule::getGlobalItems(ArchiveModule::COMPRESSION).getStringValue())
321
334
        {
322
335
          theCompression = lOptionValue.getStringValue().c_str();
323
336
          std::transform(
325
338
              theCompression.end(),
326
339
              theCompression.begin(), ::toupper);
327
340
        }
328
 
        else if (lOptionKey.getStringValue() == FORMAT_KEY_NAME)
 
341
        else if (lOptionKey.getStringValue() == ArchiveModule::getGlobalItems(ArchiveModule::FORMAT).getStringValue())
329
342
        {
330
343
          theFormat = lOptionValue.getStringValue().c_str();
331
344
          std::transform(
1064
1077
      zorba::Item& aArchive)
1065
1078
    : ArchiveIterator(aArchive)
1066
1079
  {
1067
 
      gNameKey = theFactory->createString(NAME_KEY_NAME);
1068
 
      gTypeKey = theFactory->createString(TYPE_KEY_NAME);
1069
 
      gSizeKey = theFactory->createString(SIZE_KEY_NAME);
1070
 
      gLastModifiedKey = theFactory->createString(LAST_MODIFIED_KEY_NAME);
1071
1080
  }
1072
1081
 
1073
1082
  bool
1089
1098
 
1090
1099
    // create text content (i.e. path name)
1091
1100
    String lName = archive_entry_pathname(lEntry);
1092
 
    lElemPair = std::make_pair<zorba::Item, zorba::Item>(gNameKey,
 
1101
    lElemPair = std::make_pair<zorba::Item, zorba::Item>(ArchiveModule::getGlobalItems(ArchiveModule::NAME),
1093
1102
                                                         theFactory->createString(lName));
1094
1103
    lObjectArray.push_back(lElemPair);
1095
1104
 
1097
1106
    if (archive_entry_size_is_set(lEntry))
1098
1107
    {
1099
1108
      long long lSize = archive_entry_size(lEntry);
1100
 
      lElemPair = std::make_pair<zorba::Item, zorba::Item>(gSizeKey,
 
1109
      lElemPair = std::make_pair<zorba::Item, zorba::Item>(ArchiveModule::getGlobalItems(ArchiveModule::SIZE),
1101
1110
                                                           theFactory->createInteger(lSize));
1102
1111
      lObjectArray.push_back(lElemPair);
1103
1112
    }
1106
1115
    if (archive_entry_mtime_is_set(lEntry))
1107
1116
    {
1108
1117
      time_t lTime = archive_entry_mtime(lEntry);
1109
 
      lElemPair = std::make_pair<zorba::Item, zorba::Item>(gLastModifiedKey,
 
1118
      lElemPair = std::make_pair<zorba::Item, zorba::Item>(ArchiveModule::getGlobalItems(ArchiveModule::LAST_MODIFIED),
1110
1119
                                                           ArchiveModule::createDateTimeItem(lTime));
1111
1120
      lObjectArray.push_back(lElemPair);
1112
1121
    }
1127
1136
      // for the time being don't do anything
1128
1137
    }
1129
1138
 
1130
 
    lElemPair = std::make_pair<zorba::Item, zorba::Item>(gTypeKey,
 
1139
    lElemPair = std::make_pair<zorba::Item, zorba::Item>(ArchiveModule::getGlobalItems(ArchiveModule::TYPE),
1131
1140
                                                         theFactory->createString(lEntryType));
1132
1141
    lObjectArray.push_back(lElemPair);
1133
1142
 
1381
1390
  OptionsFunction::OptionsItemSequence::OptionsIterator::OptionsIterator(Item &aArchive)
1382
1391
      :ArchiveIterator(aArchive)
1383
1392
  {
1384
 
      gFormatKey = theFactory->createString(FORMAT_KEY_NAME);
1385
 
      gCompressionKey = theFactory->createString(COMPRESSION_KEY_NAME);
1386
1393
  }
1387
1394
 
1388
1395
  bool
1420
1427
                                                      theFactory->createString(lFormat));
1421
1428
    lJSONObject.push_back(lElemt);
1422
1429
 
1423
 
    lElemt = std::make_pair<zorba::Item, zorba::Item>(gCompressionKey,
 
1430
    lElemt = std::make_pair<zorba::Item, zorba::Item>(ArchiveModule::getGlobalItems(ArchiveModule::COMPRESSION),
1424
1431
                                                      theFactory->createString(lCompression));
1425
1432
    lJSONObject.push_back(lElemt);
1426
1433