bool ossim::getPath(const ossimString& path, const ossimXmlDocument* xdoc, ossimString& s) { bool result = false; if (xdoc) { std::vector<ossimRefPtr<ossimXmlNode> > xnodes; xdoc->findNodes(path, xnodes); if ( xnodes.size() == 1 ) // Error if more than one. { if ( xnodes[0].valid() ) { s = xnodes[0]->getText(); result = true; } else { if(traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "ossim::getPath ERROR:\n" << "Node not found: " << path << std::endl; } } } else if ( xnodes.size() == 0 ) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "ossim::getPath ERROR:\n" << "Node not found: " << path << std::endl; } } else { if(traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "ossim::getPath ERROR:\n" << "Multiple nodes found: " << path << std::endl; } } } if (!result) { s.clear(); } return result; }
bool ossimGeometricSarSensorModel::saveState(ossimKeywordlist& kwl, const char* prefix) const { static const char MODULE[] = "ossimGeometricSarSensorModel::saveState"; bool result = false; if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n"; } if (_platformPosition && _sensor && _refPoint) { if ( _platformPosition->saveState(kwl, prefix) ) { if ( _sensor->saveState(kwl, prefix) ) { result = _refPoint->saveState(kwl, prefix); if (result) { kwl.add(prefix, PRODUCT_GEOREFERENCED_FLAG_KW, (_isProductGeoreferenced?"true":"false")); kwl.add(prefix, OPTIMIZATION_FACTOR_X_KW, _optimizationFactorX); kwl.add(prefix, OPTIMIZATION_FACTOR_Y_KW, _optimizationFactorY); kwl.add(prefix, OPTIMIZATION_BIAS_X_KW, _optimizationBiasX); kwl.add(prefix, OPTIMIZATION_BIAS_Y_KW, _optimizationBiasY); result = ossimSensorModel::saveState(kwl, prefix); } } } } if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " exit status = " << (result?"true":"false\n") << std::endl; } return result; }
/** * Send a datagram to a socket defined by a n2n_sock_t. * * @return -1 on error otherwise number of bytes sent */ ssize_t sendto_sock(int sock_fd, const void *pktbuf, size_t pktsize, const n2n_sock_t *dest) { n2n_sock_str_t sockbuf; struct sockaddr_storage dst_addr; ssize_t sent; sock2sockaddr(&dst_addr, dest); //traceDebug("sendto_sock %lu to [%s]", pktsize, sock2str(sockbuf, dest)); sent = sendto(sock_fd, pktbuf, pktsize, 0 /* flags */, (const struct sockaddr *) &dst_addr, sizeof(struct sockaddr_in)); if (sent < 0) { char *c = strerror(errno); traceError("sendto failed (%d) %s", errno, c); } else { traceDebug("sendto sent=%d", (signed int) sent); } return sent; }
bool ossimXmlNode::readCDataContent(std::istream& in) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::readCDataContent: entered ...\n"; } // Ignore up to "]]>" bool result = false; char c; while(!in.fail()) { c = in.get(); if ( c != ']' ) { theText += c; } else // at "]" { c = in.get(); if( c == ']' ) // at "]]" { c = in.get(); if( c == '>' ) { //in >> xmlskipws; result = true; break; } } } } if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "theText: " << theText << "\nexit status: " << (result?"true":"false") << "\nossimXmlNode::readCDataContent: leaving ...\n"; } return result; }
bool ossimXmlNode::readTag(std::istream& in, ossimString& tag) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::readTag: entered ......\n"; } xmlskipws(in); tag.clear(); int c = in.peek(); // bool validTag = false; // while(!validTag) { while( (c != ' ')&& (c != '\n')&& (c != '\t')&& (c != '\r')&& (c != '<')&& (c != '>')&& (c != '/')&& (!in.fail())) { tag += (char)c; in.ignore(1); c = in.peek(); if(tag == "!--") // ignore comment tags { tag = "--"; break; } } } if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::readTag: leaving ......\n"; } return (!tag.empty())&&(!in.fail()); }
bool ossim::findFirstNode(const ossimString& path, ossimRefPtr<ossimXmlNode> node, ossimString& s) { bool result = false; if ( node.valid() ) { ossimRefPtr<ossimXmlNode> n = node->findFirstNode(path); if ( n.valid() ) { s = n->getText(); if ( s.size() ) { result = true; } else { if(!traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "ossim::findFirstNode ERROR:\n" << "Node empty: " << path << std::endl; } } } else { if(!traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "ossim::findFirstNode ERROR:\n" << "Node not found: " << path << std::endl; } } } return result; }
void ossimGeometricSarSensorModel::lineSampleHeightToWorld( const ossimDpt& image_point, const double& heightEllipsoid, ossimGpt& worldPoint) const { SarSensor sensor(_sensor,_platformPosition); double lon, lat; // const double CLUM = 2.99792458e+8 ; // optimization double col = image_point.x - (image_point.x * _optimizationFactorX + _optimizationBiasX) ; double line = image_point.y - (image_point.y * _optimizationFactorY + _optimizationBiasY) ; JSDDateTime azimuthTime = getTime(line) ; // Slant range computation, depending on the product type double slantRange; if (_isProductGeoreferenced) { slantRange = getSlantRangeFromGeoreferenced(col) ; } else { slantRange = getSlantRange(col) ; } int etatLoc = sensor.ImageToWorld(slantRange, azimuthTime, heightEllipsoid, lon, lat); if(traceDebug()) { switch (etatLoc) { case 0: ossimNotify(ossimNotifyLevel_DEBUG) << "successful call to lineSampleHeightToWorld" << std::endl; break; case 1: ossimNotify(ossimNotifyLevel_DEBUG) << "lineSampleHeightToWorld : no real root to the equation belongs to the imaging ray" << std::endl; break; case 2: ossimNotify(ossimNotifyLevel_DEBUG) << "lineSampleHeightToWorld : no real root to the equation" << std::endl; break; default : ossimNotify(ossimNotifyLevel_DEBUG) << "lineSampleHeightToWorld : unknown error case" << std::endl; break; } } worldPoint.lat = lat; worldPoint.lon = lon; worldPoint.hgt = heightEllipsoid ; }
ossimRefPtr<ossimXmlNode> ossimXmlNode::addNode(const ossimString& relPath, const ossimString& text) { if (relPath.empty()) return 0; // // First verify that this is not an absolute path: // if (relPath[static_cast<std::string::size_type>(0)] == XPATH_DELIM) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimXmlNode::addNode\n" << "Only relative XPaths can be searched from a node. " << "Returning null list...\n"; } return 0; } // // Read the desired tag from the relative xpath // const std::string::size_type delim_pos = relPath.find(XPATH_DELIM); const ossimString desiredTag = relPath.substr(0,delim_pos); ossimRefPtr<ossimXmlNode> node = findFirstNode(desiredTag); if(!node.valid()) { // No XPATH_DELIM character found, or XPATH_DELIM at the end of xpath if (delim_pos==std::string::npos || delim_pos == relPath.size()-1) { node = addChildNode(desiredTag, text); } else { node = addChildNode(desiredTag, ""); } } if (delim_pos != std::string::npos && delim_pos != relPath.size()-1) // XPATH_DELIM character found! { const ossimString subPath = relPath.substr(delim_pos+1, std::string::npos); return node->addNode(subPath, text); } return node; }
AlosPalsarRecord* AlosPalsarRecordFactory::Instanciate(int id) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "Intanciate AlosPalsar record:" << id << "\n"; } AlosPalsarRecord* record = _availableRecords[id]; if (record == NULL) { return NULL; } else { return record->Instanciate(); } }
//***************************************************************************** // METHOD: ossimTileMapModel::loadState() // // Restores the model's state from the KWL. This KWL also serves as a // geometry file. // //***************************************************************************** bool ossimTileMapModel::loadState(const ossimKeywordlist& kwl, const char* prefix) { if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::loadState: entering..." << std::endl; if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::loadState:" << "\nInput kwl: " << kwl << std::endl; } const char* value = NULL; //const char* keyword =NULL; bool success; //*** // Assure this keywordlist contains correct type info: //*** value = kwl.find(prefix, ossimKeywordNames::TYPE_KW); if (!value || (strcmp(value, TYPE_NAME(this)))) { theErrorStatus = 1; return false; } value = kwl.find(prefix, "depth"); qDepth = atoi(value); //*** // Pass on to the base-class for parsing first: //*** success = ossimSensorModel::loadState(kwl, prefix); if (!success) { theErrorStatus++; return false; } updateModel(); if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimTileMapModel::loadState: returning..." << std::endl; return true; }
bool ossimTileMapModel::open(const ossimFilename& file) { static const char MODULE[] = "ossimTileMapModel::open"; ossimString os = file.beforePos(4); if (traceDebug()) { CLOG << " Entered..." << std::endl << " trying to open file " << file << std::endl; } if(os == "http" || file.ext() == "otb") { return true; } return false; }
bool ossim::getPath(const ossimString& path, const ossimXmlDocument* xdoc, std::vector<ossimString>& v) { bool result = false; if (xdoc) { std::vector<ossimRefPtr<ossimXmlNode> > xnodes; xdoc->findNodes(path, xnodes); if ( xnodes.size() ) { std::vector<ossimRefPtr<ossimXmlNode> >::const_iterator i = xnodes.begin(); while ( i != xnodes.end() ) { v.push_back( (*i)->getText() ); ++i; } result = true; } else { if(traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "ossim::getPath ERROR:\n" << "Nodes not found: " << path << std::endl; } } } if (!result) { v.clear(); } return result; }
bool ossimCodecFactory::decodeJpeg( const std::vector<ossim_uint8>& in, ossimRefPtr<ossimImageData>& out ) const { bool result = false; // Note: This is public and can be called directly; hence, the signature check // Check for jpeg signature: if ( in.size() > 3 ) { if ( (in[0] == 0xff) && (in[1] == 0xd8) && (in[2] == 0xff) && (in[3] == 0xe0) ) { /* This struct contains the JPEG decompression parameters and pointers * to working space (which is allocated as needed by the JPEG library). */ jpeg_decompress_struct cinfo; /* We use our private extension JPEG error handler. * Note that this struct must live as long as the main JPEG parameter * struct, to avoid dangling-pointer problems. */ ossimJpegErrorMgr jerr; /* Step 1: allocate and initialize JPEG decompression object */ /* We set up the normal JPEG error routines, then override error_exit. */ cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = ossimJpegErrorExit; /* Establish the setjmp return context for my_error_exit to use. */ if (setjmp(jerr.setjmp_buffer) == 0) { result = true; /* Now we can initialize the JPEG decompression object. */ jpeg_CreateDecompress(&cinfo, JPEG_LIB_VERSION, sizeof(cinfo)); //--- // Step 2: specify data source. In this case we will uncompress from // memory so we will use "ossimJpegMemorySrc" in place of " jpeg_stdio_src". //--- ossimJpegMemorySrc ( &cinfo, &(in.front()), (size_t)(in.size()) ); /* Step 3: read file parameters with jpeg_read_header() */ jpeg_read_header(&cinfo, TRUE); /* Step 4: set parameters for decompression */ /* In this example, we don't need to change any of the defaults set by * jpeg_read_header(), so we do nothing here. */ /* Step 5: Start decompressor */ jpeg_start_decompress(&cinfo); #if 0 /* Please leave for debug. (drb) */ if ( traceDebug() ) { ossimNotify(ossimNotifyLevel_DEBUG) << "jpeg cinfo.output_width: " << cinfo.output_width << "\njpeg cinfo.output_height: " << cinfo.output_height << "\n"; } #endif const ossim_uint32 SAMPLES = cinfo.output_width; const ossim_uint32 LINES = cinfo.output_height; const ossim_uint32 BANDS = cinfo.output_components; if ( out.valid() ) { // This will resize tile if not correct. out->setImageRectangleAndBands( ossimIrect(0,0,(ossim_int32)SAMPLES-1,(ossim_int32)LINES-1), BANDS ); } else { out = new ossimU8ImageData( 0, BANDS, SAMPLES, LINES ); out->initialize(); } // Get pointers to the cache tile buffers. std::vector<ossim_uint8*> destinationBuffer(BANDS); for (ossim_uint32 band = 0; band < BANDS; ++band) { destinationBuffer[band] = out->getUcharBuf(band); } std::vector<ossim_uint8> lineBuffer(SAMPLES * cinfo.output_components); JSAMPROW jbuf[1]; jbuf[0] = (JSAMPROW) &(lineBuffer.front()); while (cinfo.output_scanline < LINES) { // Read a line from the jpeg file. jpeg_read_scanlines(&cinfo, jbuf, 1); //--- // Copy the line which if band interleaved by pixel the the band // separate buffers. //--- ossim_uint32 index = 0; for (ossim_uint32 sample = 0; sample < SAMPLES; ++sample) { for (ossim_uint32 band = 0; band < BANDS; ++band) { destinationBuffer[band][sample] = lineBuffer[index]; ++index; } } for (ossim_uint32 band = 0; band < BANDS; ++band) { destinationBuffer[band] += SAMPLES; } } // Set the tile status: out->validate(); // clean up... jpeg_finish_decompress(&cinfo); } // Matches: if (setjmp(jerr.setjmp_buffer) == 0) jpeg_destroy_decompress(&cinfo); } // Matches: if ( (in[0] == 0xff) ... ) } // Matches: if ( in.size() > 3 ) return result; }
/* Read key control file and return the number of specs stored or a negative * error code. * * As the specs are read in the from and until time values are compared to * present time. Only those keys which are valid are stored. */ int n2n_read_keyfile(n2n_cipherspec_t *specs, /* fill out this array of cipherspecs */ size_t numspecs, /* number of slots in the array. */ const char *ctrlfile_path) /* path to control file */ { /* Each line contains one cipherspec. */ int retval = 0; FILE *fp = NULL; size_t idx = 0; time_t now = time(NULL); traceDebug("Reading '%s'\n", ctrlfile_path); fp = fopen(ctrlfile_path, "r"); if (fp) { /* Read the file a line a time with fgets. */ char line[N2N_KEYFILE_LINESIZE]; size_t lineNum = 0; while (idx < numspecs) { n2n_cipherspec_t *k = &(specs[idx]); fgets(line, N2N_KEYFILE_LINESIZE, fp); ++lineNum; if (strlen(line) > 1) { if (0 == parseKeyLine(k, line)) { if (k->valid_until > now) { traceInfo(" --> [%u] from %lu, until %lu, transform=%hu, data=%s\n", idx, k->valid_from, k->valid_until, k->t, k->opaque); ++retval; ++idx; } else { traceInfo(" --X [%u] from %lu, until %lu, transform=%hu, data=%s\n", idx, k->valid_from, k->valid_until, k->t, k->opaque); } } else { traceWarning("Failed to decode line %u\n", lineNum); } } if (feof(fp)) { break; } line[0] = 0; /* this line has been consumed */ } fclose(fp); fp = NULL; } else { traceError("Failed to open '%s'\n", ctrlfile_path); retval = -1; } return retval; }
bool ossimGeometricSarSensorModel::loadState(const ossimKeywordlist &kwl, const char *prefix) { static const char MODULE[] = "ossimGeometricSarSensorModel::loadState"; if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n"; } bool result = true; // Load the base class; if ( ossimSensorModel::loadState(kwl, prefix) == false ) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << MODULE << "\nossimSensorModel::loadState failed!\n"; } result = false; } // Load the platform position state. if ( !_platformPosition) { _platformPosition = new PlatformPosition(); } if ( _platformPosition->loadState(kwl, prefix) == false ) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << MODULE << "\n_platformPosition->loadState failed!\n"; } result = false; } // Load the sensor position state. if ( !_sensor) { _sensor = new SensorParams(); } if ( _sensor->loadState(kwl, prefix) == false ) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << MODULE << "\n_sensor->loadState failed!\n"; } result = false; } // Load the ref point. if ( !_refPoint) { _refPoint = new RefPoint(); } if ( _refPoint->loadState(kwl, prefix) == false ) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << MODULE << "\n_refPoint->loadState failed!\n"; } result = false; } const char* lookup = 0; ossimString s; lookup = kwl.find(prefix, PRODUCT_GEOREFERENCED_FLAG_KW); if (lookup) { s = lookup; _isProductGeoreferenced = s.toBool(); } else { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << MODULE << "\nRequired keyword not found: " << PRODUCT_GEOREFERENCED_FLAG_KW << "\n"; } result = false; } lookup = kwl.find(prefix, OPTIMIZATION_FACTOR_X_KW); if (lookup) { s = lookup; _optimizationFactorX = s.toDouble(); } else { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << MODULE << "\nRequired keyword not found: " << OPTIMIZATION_FACTOR_X_KW << "\n"; } result = false; } lookup = kwl.find(prefix, OPTIMIZATION_FACTOR_Y_KW); if (lookup) { s = lookup; _optimizationFactorY = s.toDouble(); } else { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << MODULE << "\nRequired keyword not found: " << OPTIMIZATION_FACTOR_Y_KW << "\n"; } result = false; } lookup = kwl.find(prefix,OPTIMIZATION_BIAS_X_KW); if (lookup) { s = lookup; _optimizationBiasX= s.toDouble(); } else { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << MODULE << "\nRequired keyword not found: " << OPTIMIZATION_BIAS_X_KW << "\n"; } result = false; } lookup = kwl.find(prefix,OPTIMIZATION_BIAS_Y_KW); if (lookup) { s = lookup; _optimizationBiasY = s.toDouble(); } else { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << MODULE << "\nRequired keyword not found: " << OPTIMIZATION_BIAS_X_KW << "\n"; } result = false; } // if (result && traceDebug()) // if (result) // { // ossimNotify(ossimNotifyLevel_DEBUG) // << "calling saveState to verify loadState..." << endl; // ossimKeywordlist kwl2; // saveState(kwl2, 0); // ossimNotify(ossimNotifyLevel_DEBUG) // << "saveState result after loadState:" << kwl2 << endl; // } if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " exit status = " << (result?"true":"false\n") << std::endl; } return result; }
ossimRefPtr<ossimXmlNode> ossimXmlNode::findFirstNode(const ossimString& xpath) { if(theChildNodes.size() < 1) return 0; if (xpath.empty()) return 0; // // First verify that this is not an absolute path: // if (xpath[static_cast<std::string::size_type>(0)] == XPATH_DELIM) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimXmlNode::findFirstNode\n" << "Only relative XPaths can be searched from a node. " << "Returning null list...\n"; } return 0; } // // Read the desired tag from the relative xpath // const std::string::size_type delim_pos = xpath.find(XPATH_DELIM); // TODO: need string_view const ossimString desired_tag = xpath.substr(0,delim_pos); ossimRefPtr<ossimXmlNode> result = 0; // // Loop over all child nodes for match: // ossimXmlNode::ChildListType::iterator child_iter = theChildNodes.begin(); ossimXmlNode::ChildListType::iterator child_end = theChildNodes.end(); if (delim_pos==std::string::npos) // No XPATH_DELIM character found { for ( ; child_iter != child_end ; ++ child_iter) { if ((*child_iter)->getTag() == desired_tag) return *child_iter; } } else { const ossimString sub_xpath = xpath.substr(delim_pos+1, std::string::npos); for ( ; child_iter != child_end ; ++ child_iter) { if ((*child_iter)->getTag() == desired_tag) { // // This match identifies a possible tree to search given the // remaining xpath (sub_xpath). Query this child node to search // its tree for the remaining xpath: // ossimRefPtr<ossimXmlNode> result = (*child_iter)->findFirstNode(sub_xpath); if (result.get()) { return result; } } } } return 0; }
void ossimXmlNode::findChildNodes(const ossimString& xpath, ossimXmlNode::ChildListType& result)const { //*** // Scan for trivial result (no children owned): //*** if (theChildNodes.empty()) return; if (xpath.empty()) return; //--- // First verify that this is not an absolute path: //--- if (xpath[static_cast<std::string::size_type>(0)] == XPATH_DELIM) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimXmlNode::findChildNodes\n" << "Only relative XPaths can be searched from a node. " << "Returning null list...\n"; } return; } //*** // Read the desired tag from the relative xpath //*** const std::string::size_type delim_pos = xpath.find(XPATH_DELIM); // TODO: need string_view const ossimString desired_tag = xpath.substr(0,delim_pos); //*** // Loop over all child nodes for match: //*** ossimXmlNode::ChildListType::const_iterator child_iter = theChildNodes.begin(); ossimXmlNode::ChildListType::const_iterator child_end = theChildNodes.end(); if (delim_pos==std::string::npos) // No XPATH_DELIM character found { for ( ; child_iter != child_end ; ++ child_iter) { if ((*child_iter)->getTag() == desired_tag) //*** // This was the final target node, simply append to the result: //*** result.push_back(*child_iter); } } else { const ossimString sub_xpath = xpath.substr(delim_pos+1, std::string::npos); for ( ; child_iter != child_end ; ++ child_iter) { if ((*child_iter)->getTag() == desired_tag) //*** // This match identifies a possible tree to search given the // remaining xpath (sub_xpath). Query this child node to search // its tree for the remaining xpath: //*** (*child_iter)->findChildNodes(sub_xpath, result); } } }
bool ossimXmlNode::read(std::istream& in) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: entered ......\n"; } char c; xmlskipws(in); if(in.fail()) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return false; } if(in.peek() == '<') { in.ignore(1); } if(in.fail()) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return false; } ossimString endTag; if(!readTag(in, theTag)) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return false; } if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "theTag = " << theTag << "\n"; } if((!in.fail())&&readEndTag(in, endTag)) { if((endTag == "")|| (endTag == theTag)) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return true; } else { setErrorStatus(); if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return false; } } // now parse attributes ossimRefPtr<ossimXmlAttribute> attribute = new ossimXmlAttribute; while(attribute->read(in)) { theAttributes.push_back(new ossimXmlAttribute(*attribute)); } // skip white space characters // xmlskipws(in); if(!in.fail()&&readEndTag(in, endTag)) { if((endTag == "")|| (endTag == theTag)) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return true; } else { setErrorStatus(); if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return false; } } c = in.peek(); // make sure the attribute is closed // if(c != '>') { setErrorStatus(); if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return false; } in.ignore(1); c = in.peek(); // now do the text portion if(!readTextContent(in)) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return false; } xmlskipws(in); c = in.peek(); if(c != '<') { setErrorStatus(); if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return false; } in.ignore(1); if(readEndTag(in, endTag)) { if((endTag == "")|| (endTag == theTag)) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return true; } else { setErrorStatus(); if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return false; } } c = in.peek(); //--- // now if it's not an endtag then it must be a tag starting the new child // node //--- ossimRefPtr<ossimXmlNode> childNode; do { childNode = new ossimXmlNode; childNode->setParent(this); if(childNode->read(in)) { theChildNodes.push_back(childNode); } else { setErrorStatus(); if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return false; } xmlskipws(in); c = in.peek(); if(c != '<') { setErrorStatus(); if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return false; } in.ignore(1); if(readEndTag(in, endTag)) { if((endTag == "")|| (endTag == theTag)) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return true; } else { setErrorStatus(); if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n"; } return false; } } }while( !in.fail() ); if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::read: leaving ......\n"; } return true; }
bool ossimXmlNode::readTextContent(std::istream& in) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimXmlNode::readTextContent: entered ...\n"; } //--- // Parse the text string. Do it with no peeks, ignores, or putbacks as // those seem to have issues on Windows (vs9). //--- bool result = false; theText = ""; theCDataFlag = false; xmlskipws(in); if ( !in.fail() ) { std::streampos initialPos = in.tellg(); char c = in.get(); if ( c != '<' ) { do // Get the text up to the next '<'. { theText += c; c = in.get(); } while ( (c != '<') && !in.fail() ); in.unget(); // Put '<' back. result = !in.fail(); } else // At "<" see if comment { c = in.get(); if ( c != '!' ) { in.seekg(initialPos); result = !in.fail(); } else // at "<!" { c = in.get(); if ( c == '-' ) { // Comment section: <!-- some comment --> c = in.get(); if ( c == '-' ) // at "<!--" { // Strip comment while( !in.fail() ) // continue until we see a --> pattern { c = in.get(); if(c == '-') { c = in.get(); if(c == '-') { c = in.get(); if(c == '>') { result = !in.fail(); break; } } } } } } else if ( c == '[' ) // at "<![" { // CDATA section: <![CDATA[something-here]]> c = in.get(); if ( c == 'C') // at "<![C:" { c = in.get(); if ( c == 'D' )// at "<![CD" { c = in.get(); if ( c == 'A' ) // at "<![CDA" { c = in.get(); if ( c == 'T' ) // at "<![CDAT" { c = in.get(); if ( c == 'A' ) // at "<![CDATA" { c = in.get(); if ( c == '[' ) // at "<!CDATA[" { if (readCDataContent(in)) { theCDataFlag = true; result = true; } } } } } } } } } } } if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "theText: " << theText << "\ntheCDataFlag: " << (theCDataFlag?"true":"false") << "\nexit status: " << (result?"true":"false") << "\nossimXmlNode::readTextContent: leaving ...\n"; } return result; }