OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimNitfFileHeaderV2_X.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 //----------------------------------------------------------------------------
8 // $Id: ossimNitfFileHeaderV2_X.cpp 23245 2015-04-08 20:53:04Z rashadkm $
9 
12 
13 #include <iomanip>
14 #include <sstream>
15 #include <ossim/base/ossimDate.h> /* for ossimLocalTm */
21 
22 RTTI_DEF1(ossimNitfFileHeaderV2_X, "ossimNitfFileHeaderV2_X", ossimNitfFileHeader);
23 static ossimString monthConversionTable[] = {" ", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
24 
44 
46 {
47 }
48 
50 {
51  ossimNitfCommon::setField(theComplexityLevel, level, 2, std::ios::right, '0');
52 }
53 
55 {
57 }
58 
60 {
62 }
63 
65  const ossimLocalTm& d)
66 {
67  // Convert to ZULU as per spec for both versions.
68  ossimLocalTm d1 = d.convertToGmt();
69 
71 
72  if(version.contains("2.1"))
73  {
74  out << std::setw(4)
75  << std::setfill('0')
76  << d1.getYear()
77  << std::setw(2)
78  << std::setfill('0')
79  << d1.getMonth()
80  << std::setw(2)
81  << std::setfill('0')
82  << d1.getDay()
83  << std::setw(2)
84  << std::setfill('0')
85  << d1.getHour()
86  << std::setw(2)
87  << std::setfill('0')
88  << d1.getMin()
89  << std::setw(2)
90  << std::setfill('0')
91  << d1.getSec();
92  }
93  else
94  {
95  out << std::setw(2)
96  << std::setfill('0')
97  << d1.getDay()
98  << std::setw(2)
99  << std::setfill('0')
100  << d1.getHour()
101  << std::setw(2)
102  << std::setfill('0')
103  << d1.getMin()
104  << std::setw(2)
105  << std::setfill('0')
106  << d1.getSec()
107  << "Z"
108  <<monthConversionTable[d1.getMonth()]
109  << std::setw(2)
110  << std::setfill('0')
111  <<d1.getShortYear();
112 
113  }
114 
115  return out.str();
116 }
117 
119 {
120  memcpy(theDateTime, formatDate(getVersion(), d).c_str(), 14);
121 }
122 
124 {
125  if(d.size()==14)
126  {
127  memcpy(theDateTime, d.c_str(), 14);
128  }
129 }
130 
132 {
133  setDate(ossimLocalTm(0));
134 }
135 
137 {
139 }
140 
142 {
143  ossimNitfCommon::setField(theSecurityClassification, securityClassification, 1);
144 }
145 
147 {
148  if(copyNumber.trim() == "")
149  {
150  memset(theCopyNumber, '0', 5);
151  }
152  else
153  {
154  ossimNitfCommon::setField(theCopyNumber, copyNumber, 5, std::ios::right, '0');
155  }
156 }
157 
159 {
160  if(numberOfCopies.trim() == "")
161  {
162  memset(theNumberOfCopies, 0, 5);
163  }
164  else
165  {
166  ossimNitfCommon::setField(theNumberOfCopies, numberOfCopies, 5, std::ios::right, '0');
167  }
168 }
169 
171 {
173 }
174 
176 {
177  return theComplexityLevel;
178 }
179 
181 {
182  return theSystemType;
183 }
184 
186 {
188 }
189 
191 {
192  return theDateTime;
193 }
194 
196 {
197  return theFileTitle;
198 }
199 
201 {
203 }
204 
206 {
207  return theCopyNumber;
208 }
209 
211 {
212  return theNumberOfCopies;
213 }
214 
216 {
217  return theEncryption;
218 }
219 
221 {
222  return true;
223 }
224 
226 {
227  if(!property.valid()) return;
228 
229  ossimString name = property->getName();
230 
231  // Make case insensitive:
232  name.upcase();
233 
234  if(name == FHDR_KW)
235  {
236 
237  }
238  else if(name == STYPE_KW)
239  {
240  setSystemType(property->valueToString());
241  }
242  else if(name == OSTAID_KW)
243  {
245  }
246  else if(name == FDT_KW)
247  {
248  setDate(property->valueToString());
249  }
250  else if(name == FTITLE_KW)
251  {
252  setTitle(property->valueToString());
253  }
254  else if(name == FSCLAS_KW)
255  {
257  }
258  else if(name == FSCODE_KW)
259  {
260  setCodeWords(property->valueToString());
261  }
262  else if(name == FSCTLH_KW)
263  {
265  }
266  else if(name == FSREL_KW)
267  {
269  }
270  else if(name == FSCAUT_KW)
271  {
273  }
274  else if(name == FSCTLN_KW)
275  {
277  }
278  else if(name == FSCOP_KW)
279  {
280  setCopyNumber(property->valueToString());
281  }
282  else if(name == FSCPYS_KW)
283  {
284  setNumberOfCopies(property->valueToString());
285  }
286  else if(name == ENCRYP_KW)
287  {
288  setEncryption(property->valueToString());
289  }
290  else if(name == ONAME_KW)
291  {
292  setOriginatorsName(property->valueToString());
293  }
294  else if(name == OPHONE_KW)
295  {
296  setOriginatorsPhone(property->valueToString());
297  }
298  else
299  {
301  }
302 }
303 
305 {
306  ossimRefPtr<ossimProperty> property = 0;
307 
308  if(name == FHDR_KW)
309  {
310  property = new ossimStringProperty(name, ossimString(theFileTypeVersion));
311  }
312  else if(name == VERSION_KW)
313  {
314  property = new ossimStringProperty(name, ossimString(getVersion()));
315  }
316  else if(name == FILE_TYPE_KW)
317  {
318  property = new ossimStringProperty(name, "NITF");
319  }
320  else if(name == CLEVEL_KW)
321  {
322  ossimNumericProperty* numericProperty =
323  new ossimNumericProperty(name,
325  1,
326  99);
328  property = numericProperty;
329 
330  }
331  else if(name == STYPE_KW)
332  {
333  property = new ossimStringProperty(name, getSystemType().trim());
334  }
335  else if(name == OSTAID_KW)
336  {
337  property = new ossimStringProperty(name, getOriginatingStationId().trim());
338  }
339  else if(name == FDT_KW)
340  {
341  property = new ossimStringProperty(name, getDate());
342  }
343  else if(name == FTITLE_KW)
344  {
345  property = new ossimStringProperty(name, getTitle().trim());
346  }
347  else if(name == FSCLAS_KW)
348  {
349  ossimStringProperty* stringProperty =
350  new ossimStringProperty(name,
351  getSecurityClassification().trim(),
352  false);
353 
354  stringProperty->addConstraint("");
355  stringProperty->addConstraint("T");
356  stringProperty->addConstraint("S");
357  stringProperty->addConstraint("C");
358  stringProperty->addConstraint("R");
359  stringProperty->addConstraint("U");
360 
361  property = stringProperty;
362  }
363  else if(name == FSCODE_KW)
364  {
365  property = new ossimStringProperty(name,
366  getCodeWords().trim());
367  }
368  else if(name == FSCTLH_KW)
369  {
370  property = new ossimStringProperty(name,
371  getControlAndHandling().trim());
372  }
373  else if(name == FSREL_KW)
374  {
375  property = new ossimStringProperty(name,
376  getReleasingInstructions().trim());
377  }
378  else if(name == FSCAUT_KW)
379  {
380  property = new ossimStringProperty(name,
381  getClassificationAuthority().trim());
382  }
383  else if(name == FSCTLN_KW)
384  {
385  property = new ossimStringProperty(name,
386  getSecurityControlNumber().trim());
387 
388  }
389  else if(name == FSCOP_KW)
390  {
391  property = new ossimStringProperty(name,
392  getCopyNumber().trim());
393  }
394  else if(name == FSCPYS_KW)
395  {
396  property = new ossimStringProperty(name,
397  getNumberOfCopies().trim());
398  }
399  else if(name == ENCRYP_KW)
400  {
401  property = new ossimStringProperty(name,
402  getEncryption().trim(),
403  false);
404  }
405  else
406  {
407  property = ossimNitfFileHeader::getProperty(name).get();
408  }
409 
410  return property;
411 }
412 
414 {
415  bool result = ossimNitfFileHeader::saveState(kwl, prefix);
416 
417  if(result)
418  {
419  kwl.add(prefix, FHDR_KW.c_str(), theFileTypeVersion);
420  kwl.add(prefix, CLEVEL_KW.c_str(), theComplexityLevel);
421  kwl.add(prefix, STYPE_KW.c_str(), theSystemType);
422  kwl.add(prefix, OSTAID_KW.c_str(), theOriginatingStationId);
423  kwl.add(prefix, FDT_KW.c_str(), theDateTime);
424  kwl.add(prefix, FTITLE_KW.c_str(), theFileTitle);
426  kwl.add(prefix, FSCOP_KW.c_str(), theCopyNumber);
427  kwl.add(prefix, FSCPYS_KW.c_str(), theNumberOfCopies);
428  kwl.add(prefix, ENCRYP_KW.c_str(), theEncryption);
429  }
430 
431  return result;
432 }
433 
434 bool ossimNitfFileHeaderV2_X::loadState(const ossimKeywordlist& kwl, const char* prefix)
435 {
436  // Note: Currently not looking up all fieds only ones that make sense.
437 
438  const char* lookup;
439 
440  lookup = kwl.find( prefix, CLEVEL_KW);
441  if ( lookup )
442  {
443  setComplexityLevel( ossimString(lookup) );
444  }
445  lookup = kwl.find( prefix, STYPE_KW);
446  if ( lookup )
447  {
448  setSystemType( ossimString(lookup) );
449  }
450  lookup = kwl.find( prefix, OSTAID_KW);
451  if ( lookup )
452  {
454  }
455  lookup = kwl.find( prefix, FDT_KW);
456  if ( lookup )
457  {
458  setDate( ossimString(lookup) );
459  }
460  lookup = kwl.find( prefix, FTITLE_KW);
461  if ( lookup )
462  {
463  setTitle( ossimString(lookup) );
464  }
465  lookup = kwl.find( prefix, FSCLAS_KW);
466  if ( lookup )
467  {
469  }
470  lookup = kwl.find( prefix, FSCODE_KW);
471  if ( lookup )
472  {
473  setCodeWords( ossimString(lookup) );
474  }
475  lookup = kwl.find( prefix, FSCTLH_KW);
476  if ( lookup )
477  {
479  }
480  lookup = kwl.find( prefix, FSREL_KW);
481  if ( lookup )
482  {
484  }
485  lookup = kwl.find( prefix, FSCAUT_KW);
486  if ( lookup )
487  {
489  }
490  lookup = kwl.find( prefix, FSCTLN_KW);
491  if ( lookup )
492  {
494  }
495  lookup = kwl.find( prefix, FSCOP_KW);
496  if ( lookup )
497  {
498  setCopyNumber( ossimString(lookup) );
499  }
500  lookup = kwl.find( prefix, FSCPYS_KW);
501  if ( lookup )
502  {
503  setNumberOfCopies( ossimString(lookup) );
504  }
505  lookup = kwl.find( prefix, ENCRYP_KW);
506  if ( lookup )
507  {
508  setEncryption( ossimString(lookup) );
509  }
510  lookup = kwl.find( prefix, ONAME_KW);
511  if ( lookup )
512  {
513  setOriginatorsName( ossimString(lookup) );
514  }
515  lookup = kwl.find( prefix, OPHONE_KW);
516  if ( lookup )
517  {
518  setOriginatorsPhone( ossimString(lookup) );
519  }
520 
521  return true;
522 }
523 
524 void ossimNitfFileHeaderV2_X::getPropertyNames(std::vector<ossimString>& propertyNames)const
525 {
527  propertyNames.push_back(FILE_TYPE_KW);
528  propertyNames.push_back(VERSION_KW);
529  propertyNames.push_back(FHDR_KW);
530  propertyNames.push_back(CLEVEL_KW);
531  propertyNames.push_back(STYPE_KW);
532  propertyNames.push_back(OSTAID_KW);
533  propertyNames.push_back(FDT_KW);
534  propertyNames.push_back(FTITLE_KW);
535  propertyNames.push_back(FSCLAS_KW);
536  propertyNames.push_back(FSCODE_KW);
537  propertyNames.push_back(FSCTLH_KW);
538  propertyNames.push_back(FSREL_KW);
539  propertyNames.push_back(FSCAUT_KW);
540  propertyNames.push_back(FSCTLN_KW);
541  propertyNames.push_back(FSCOP_KW);
542  propertyNames.push_back(FSCPYS_KW);
543  propertyNames.push_back(ENCRYP_KW);
544  propertyNames.push_back(ONAME_KW);
545  propertyNames.push_back(OPHONE_KW);
546 }
virtual void valueToString(ossimString &valueResult) const =0
char theComplexityLevel[3]
Field: CLEVEL.
static const ossimString FSCOP_KW
virtual void setProperty(ossimRefPtr< ossimProperty > property)
char theOriginatingStationId[11]
Field: OSTAID.
virtual const char * getVersion() const =0
static ossimString upcase(const ossimString &aString)
Definition: ossimString.cpp:34
ossimString getOriginatingStationId() const
void setSystemType(const ossimString &systemType)
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
char theFileTypeVersion[10]
Field: FHDR Required field for NITF and is a 9 byte value.
static const ossimString FSREL_KW
Represents serializable keyword/value map.
static const ossimString STYPE_KW
bool valid() const
Definition: ossimRefPtr.h:75
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to set fields from a keyword list.
const char * find(const char *key) const
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual ossimString getSecurityClassification() const
bool contains(char aChar) const
Definition: ossimString.h:58
virtual bool isValid() const
isValid will test if the fields are valid and will return true or false.
virtual bool saveState(ossimKeywordlist &kwl, const ossimString &prefix="") const
static const ossimString FSCPYS_KW
int getSec() const
Definition: ossimDate.cpp:580
static const ossimString FTITLE_KW
int getYear() const
Definition: ossimDate.cpp:433
int getMin() const
Definition: ossimDate.cpp:575
char theSystemType[5]
Field: STYPE.
void setCopyNumber(const ossimString &copyNumber)
RTTI_DEF1(ossimNitfFileHeaderV2_X, "ossimNitfFileHeaderV2_X", ossimNitfFileHeader)
void addConstraint(const ossimString &value)
static const ossimString FSCLAS_KW
virtual ossimString getReleasingInstructions() const =0
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual void setOriginatorsPhone(const ossimString &origniatorPhone)=0
virtual void setControlAndHandling(const ossimString &controlAndHandling)=0
static const ossimString OSTAID_KW
virtual ossimString getSecurityControlNumber() const =0
virtual void setSecurityControlNumber(const ossimString &controlNo)=0
void setTitle(const ossimString &title)
virtual void setDate()
Sets field FDT to current time converted to GMT(ZULU).
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
static const ossimString FILE_TYPE_KW
Properties of a NITF 2.x Header file.
static const ossimString ONAME_KW
static const ossimString FSCODE_KW
virtual void setNumericType(ossimNumericPropertyType type)
ossimLocalTm convertToGmt() const
Definition: ossimDate.cpp:677
std::string::size_type size() const
Definition: ossimString.h:405
int getShortYear() const
Definition: ossimDate.cpp:443
char theEncryption[2]
Field: ENCRYP.
static const ossimString FSCAUT_KW
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
char theDateTime[15]
Field: FDT.
static const ossimString ENCRYP_KW
static const ossimString FHDR_KW
virtual void setCodeWords(const ossimString &codeWords)=0
void setEncryption(const ossimString &encryption)
virtual void setClassificationAuthority(const ossimString &classAuth)=0
virtual void setOriginatorsName(const ossimString &originatorName)=0
void setNumberOfCopies(const ossimString &numberOfCopies)
ossimString getNumberOfCopies() const
void setOriginatingStationId(const ossimString &originationId)
virtual void setReleasingInstructions(const ossimString &releasingInstructions)=0
virtual ossimString getControlAndHandling() const =0
void setFileSecurityClassification(const ossimString &securityClassification)
void setComplexityLevel(const ossimString &level)
static const ossimString CLEVEL_KW
int getMonth() const
Definition: ossimDate.cpp:448
static const ossimString OPHONE_KW
static const ossimString FSCTLH_KW
virtual ossimString getClassificationAuthority() const =0
static const ossimString FSCTLN_KW
int getDay() const
Definition: ossimDate.cpp:453
static void setField(void *fieldDestination, const ossimString &src, std::streamsize width, std::ios_base::fmtflags ioflags=std::ios::left, char fill=' ')
Sets a field with a given string, width, and IOS flags.
char theCopyNumber[6]
Field: FSCOP.
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
static const ossimString FDT_KW
char theFileTitle[81]
Field: FTITLE.
static ossimString formatDate(const ossimString &version, const ossimLocalTm &d)
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
char theSecurityClassification[2]
Field: FSCLAS.
char theNumberOfCopies[6]
Field: FSCOPYS.
virtual ossimString getCodeWords() const =0
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
int getHour() const
Definition: ossimDate.cpp:570
bool saveState(ossimKeywordlist &kwl, const ossimString &prefix="") const
static const ossimString VERSION_KW
virtual void setProperty(ossimRefPtr< ossimProperty > property)
ossimString getComplexityLevel() const