OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimPluginCommon.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 // Author: David Burken
8 //
9 // Description: Common code for this plugin.
10 //
11 //----------------------------------------------------------------------------
12 // $Id$
13 
14 #include <cstdlib>
15 
16 #include <ossimPluginCommon.h>
17 #include <ossim/base/ossimDate.h>
18 #include <ossim/base/ossimNotify.h>
19 #include <ossim/base/ossimString.h>
22 #include <otb/CivilDateTime.h>
23 #include <ossim/base/ossimTrace.h>
24 static ossimTrace traceDebug("ossimPluginCommon:debug");
25 namespace ossimplugins
26 {
27 
28 
29 bool ossim::iso8601TimeStringToCivilDate(const std::string& dateString,
30  CivilDateTime& outputDate)
31 {
32  bool result = true;
33 
34  ossimLocalTm otm;
35  if ( otm.setIso8601(dateString) )
36  {
37  outputDate.set_year( otm.getYear() );
38  outputDate.set_month( otm.getMonth() );
39  outputDate.set_day( otm.getDay() );
40 
41  int second = otm.tm_hour * 3600 + otm.tm_min * 60 + otm.tm_sec;
42  outputDate.set_second( second );
43  outputDate.set_decimal( otm.getFractionalSecond() );
44 
45  }
46  else
47  {
48  result = false;
49  }
50 
51  return result;
52 }
53 
54 
55 bool ossim::getPath(const ossimString& path,
56  const ossimXmlDocument* xdoc,
57  ossimString& s)
58 {
59  bool result = false;
60  if (xdoc)
61  {
62  std::vector<ossimRefPtr<ossimXmlNode> > xnodes;
63  xdoc->findNodes(path, xnodes);
64  if ( xnodes.size() == 1 ) // Error if more than one.
65  {
66  if ( xnodes[0].valid() )
67  {
68  s = xnodes[0]->getText();
69  result = true;
70  }
71  else
72  {
73  if(traceDebug())
74  {
75 
77  << "ossim::getPath ERROR:\n"
78  << "Node not found: " << path
79  << std::endl;
80  }
81  }
82  }
83  else if ( xnodes.size() == 0 )
84  {
85  if(traceDebug())
86  {
88  << "ossim::getPath ERROR:\n"
89  << "Node not found: " << path
90  << std::endl;
91  }
92  }
93  else
94  {
95  if(traceDebug())
96  {
97 
99  << "ossim::getPath ERROR:\n"
100  << "Multiple nodes found: " << path
101  << std::endl;
102  }
103  }
104  }
105  if (!result)
106  {
107  s.clear();
108  }
109  return result;
110 }
111 
112 bool ossim::getPath(const ossimString& path,
113  const ossimXmlDocument* xdoc,
114  std::vector<ossimString>& v)
115 {
116  bool result = false;
117  if (xdoc)
118  {
119  std::vector<ossimRefPtr<ossimXmlNode> > xnodes;
120  xdoc->findNodes(path, xnodes);
121  if ( xnodes.size() )
122  {
123  std::vector<ossimRefPtr<ossimXmlNode> >::const_iterator i =
124  xnodes.begin();
125  while ( i != xnodes.end() )
126  {
127  v.push_back( (*i)->getText() );
128  ++i;
129  }
130  result = true;
131  }
132  else
133  {
134  if(traceDebug())
135  {
137  << "ossim::getPath ERROR:\n"
138  << "Nodes not found: " << path
139  << std::endl;
140  }
141  }
142  }
143  if (!result)
144  {
145  v.clear();
146  }
147  return result;
148 }
149 
152  ossimString& s)
153 {
154  bool result = false;
155  if ( node.valid() )
156  {
158  if ( n.valid() )
159  {
160  s = n->getText();
161  if ( s.size() )
162  {
163  result = true;
164  }
165  else
166  {
167  if(!traceDebug())
168  {
170  << "ossim::findFirstNode ERROR:\n"
171  << "Node empty: " << path
172  << std::endl;
173  }
174  }
175  }
176  else
177  {
178  if(!traceDebug())
179  {
181  << "ossim::findFirstNode ERROR:\n"
182  << "Node not found: " << path
183  << std::endl;
184  }
185  }
186  }
187  return result;
188 }
189 }
void clear()
Erases the entire container.
Definition: ossimString.h:432
This class represents a date and time in the civil format.
Definition: CivilDateTime.h:30
bool valid() const
Definition: ossimRefPtr.h:75
int getYear() const
Definition: ossimDate.cpp:433
void set_second(int second)
bool iso8601TimeStringToCivilDate(const std::string &dataString, CivilDateTime &outputDate)
Converts date string from ISO 8601 format to CivilDateTime.
const ossimRefPtr< ossimXmlNode > & findFirstNode(const ossimString &rel_xpath) const
void set_decimal(double decimal)
std::string::size_type size() const
Definition: ossimString.h:405
os2<< "> n<< " > nendobj n
double getFractionalSecond() const
Definition: ossimDate.cpp:585
int getMonth() const
Definition: ossimDate.cpp:448
int getDay() const
Definition: ossimDate.cpp:453
bool findFirstNode(const ossimString &path, ossimRefPtr< ossimXmlNode > node, ossimString &s)
Finds from node with path from node and initializes string.
bool setIso8601(const std::string &timeString, bool shiftToGmtOffsetZero=false)
Definition: ossimDate.cpp:789
bool getPath(const ossimString &path, const ossimXmlDocument *xdoc, ossimString &s)
Gets path from doc and initializes string.
void findNodes(const ossimString &xpath, std::vector< ossimRefPtr< ossimXmlNode > > &nodelist) const
Appends any matching nodes to the list supplied (should be empty):
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)