void plainconf::outputConfigFile(const XmlNode *pNode, FILE *fp, int level) { XmlNodeList list; int count = pNode->getAllChildren(list); list.sort(s_compare); if (count > 0) { if (level > 0) { fprintf(fp, "\n"); outputSpaces(level, fp); const char *value = pNode->getValue(); if (!value) value = ""; fprintf(fp, "%s %s {\n", pNode->getName(), value); } XmlNodeList::const_iterator iter; for (iter = list.begin(); iter != list.end(); ++iter) outputConfigFile((*iter), fp, level + 1); if (level > 0) { outputSpaces(level, fp); fprintf(fp, "}\n"); } } else outputSigleNode(fp, pNode, level); }
void displayNodeList(XmlNodeList &nodelist) { for (auto i = nodelist.begin(); i != nodelist.end(); ++i) { cout << (*i)->toString() << endl; } }
int main() { const int NUMBER_OF_FILES = 4; // can change if more/less than 4 files vector<string> filenames = getFileNames(NUMBER_OF_FILES); ThreadedUserParser userParser("<user>(.|\\n)*?</user>"); cout << "Starting timer...\n\n\n"; clock_t begin = clock(); // start timer cout << "Now parsing all files..."; XmlNodeList nodelist = userParser.parseUserFiles(filenames); clock_t end = clock(); cout << "Finished parsing all files." << endl << "\nTotal number of users: " << nodelist.size() << endl << "Total time taken to parse: " << double(end - begin) / CLOCKS_PER_SEC << " seconds\n\n\n"; cout << "\n\nNow displaying all user data (encrypted):\n\n"; displayNodeList(nodelist); cout << "\n\n\n\n\n"; cout << "Decrypting all user data..."; decryptUserData(nodelist); cout << "Finished decrypting all user data.\n\n\n"; cout << "\n\nNow displaying user data (decrypted):\n\n"; displayNodeList(nodelist); cout << "\n\n\nNow exiting...\n\n"; return 0; }
void decryptUserData(XmlNodeList &nodelist) { UserDecryptor decryptor; for (auto i = nodelist.begin(); i != nodelist.end(); ++i) { // "*i" dereferences the XmlNode* which is then // casted to a User*, which finally is dereferenced // to the User instance and passed to decryptor.convert() decryptor.convert(*dynamic_cast<User*>(*i)); } }
void plainconf::handleSpecialCaseLoop(XmlNode *pNode) { XmlNodeList list; int count = pNode->getAllChildren(list); if (count > 0) { XmlNodeList::const_iterator iter; for (iter = list.begin(); iter != list.end(); ++iter) handleSpecialCaseLoop(*iter); handleSpecialCase(pNode); } }
void plainconf::release(XmlNode *pNode) { XmlNodeList list; int count = pNode->getAllChildren(list); if (count > 0) { XmlNodeList::const_iterator iter; for (iter = list.begin(); iter != list.end(); ++iter) release(*iter); } if (!pNode->getParent()) delete pNode; }
WMSCapabilities* WMSCapabilitiesReader::read(std::istream &in) { osg::ref_ptr<WMSCapabilities> capabilities = new WMSCapabilities; osg::ref_ptr<XmlDocument> doc = XmlDocument::load( in ); if (!doc.valid() || doc->getChildren().empty()) { OE_NOTICE << "Failed to load Capabilities " << std::endl; return 0; } //Get the Capabilities version osg::ref_ptr<XmlElement> e_root = static_cast<XmlElement*>(doc->getChildren()[0].get()); capabilities->setVersion( e_root->getAttr(ATTR_VERSION ) ); osg::ref_ptr<XmlElement> e_capability = e_root->getSubElement( ELEM_CAPABILITY ); if (!e_capability.valid()) { OE_NOTICE << "Could not find Capability element" << std::endl; return 0; } //Get the supported formats osg::ref_ptr<XmlElement> e_request = e_capability->getSubElement( ELEM_REQUEST ); if (e_request.valid()) { osg::ref_ptr<XmlElement> e_getMap = e_request->getSubElement( ELEM_GETMAP ); if ( e_getMap.valid() ) { //Read all the formats XmlNodeList formats = e_getMap->getSubElements( ELEM_FORMAT ); for( XmlNodeList::const_iterator i = formats.begin(); i != formats.end(); i++ ) { string format = trim(static_cast<XmlElement*>( i->get() )->getText()); capabilities->getFormats().push_back(format); } } } //Try to read the layers readLayers( e_capability.get(), 0, capabilities->getLayers()); return capabilities.release(); }
XmlNodeList XmlElement::getSubElements( const std::string& name ) const { XmlNodeList results; std::string name_lower = name; std::transform( name_lower.begin(), name_lower.end(), name_lower.begin(), tolower ); for( XmlNodeList::const_iterator i = getChildren().begin(); i != getChildren().end(); i++ ) { if ( i->get()->isElement() ) { XmlElement* e = (XmlElement*)i->get(); std::string name = e->getName(); std::transform( name.begin(), name.end(), name.begin(), tolower ); if ( name == name_lower ) results.push_back( e ); } } return results; }
WFSCapabilities* WFSCapabilitiesReader::read(std::istream &in) { osg::ref_ptr<WFSCapabilities> capabilities = new WFSCapabilities; osg::ref_ptr<XmlDocument> doc = XmlDocument::load( in ); if (!doc.valid() || doc->getChildren().empty()) { OE_NOTICE << "Failed to load Capabilities " << std::endl; return 0; } //Get the Capabilities version osg::ref_ptr<XmlElement> e_root = static_cast<XmlElement*>(doc->getChildren()[0].get()); capabilities->setVersion( e_root->getAttr(ATTR_VERSION ) ); removeElementNamespace(e_root); osg::ref_ptr<XmlElement> e_service = e_root->getSubElement( ELEM_SERVICE ); if (!e_service.valid()) { OE_NOTICE << "Could not find Service element" << std::endl; return 0; } //Read the parameters from the Service block capabilities->setName( e_service->getSubElementText(ELEM_NAME ) ); capabilities->setAbstract( e_service->getSubElementText( ELEM_ABSTRACT ) ); capabilities->setTitle( e_service->getSubElementText( ELEM_TITLE ) ); //Read all the feature types osg::ref_ptr<XmlElement> e_feature_types = e_root->getSubElement( ELEM_FEATURETYPELIST ); if (e_feature_types.valid()) { XmlNodeList featureTypes = e_feature_types->getSubElements( ELEM_FEATURETYPE ); for( XmlNodeList::const_iterator itr = featureTypes.begin(); itr != featureTypes.end(); itr++ ) { XmlElement* e_featureType = static_cast<XmlElement*>( itr->get() ); WFSFeatureType* featureType = new WFSFeatureType(); featureType->setName( e_featureType->getSubElementText( ELEM_NAME ) ); featureType->setTitle( e_featureType->getSubElementText( ELEM_TITLE ) ); featureType->setAbstract( e_featureType->getSubElementText( ELEM_ABSTRACT ) ); //NOTE: TILED and MAXLEVEL aren't part of the WFS spec, these are enhancements to our server for tiled WFS access std::string tiledStr = e_featureType->getSubElementText(ELEM_TILED); featureType->setTiled( as<bool>(tiledStr, false) ); std::string maxLevelStr = e_featureType->getSubElementText(ELEM_MAXLEVEL); featureType->setMaxLevel( as<int>(maxLevelStr, -1)); std::string firstLevelStr = e_featureType->getSubElementText(ELEM_FIRSTLEVEL); featureType->setFirstLevel( as<int>(firstLevelStr, 0)); // Read the SRS std::string srsText = e_featureType->getSubElementText(ELEM_SRS); if (srsText.compare("") != 0) { featureType->setSRS( srsText ); } osg::ref_ptr<XmlElement> e_bb = e_featureType->getSubElement( ELEM_LATLONGBOUNDINGBOX ); if (e_bb.valid()) { double minX, minY, maxX, maxY; minX = as<double>(e_bb->getAttr( ATTR_MINX ), 0); minY = as<double>(e_bb->getAttr( ATTR_MINY ), 0); maxX = as<double>(e_bb->getAttr( ATTR_MAXX ), 0); maxY = as<double>(e_bb->getAttr( ATTR_MAXY ), 0); featureType->setExtent( GeoExtent( osgEarth::SpatialReference::create( srsText ), minX, minY, maxX, maxY) ); } capabilities->getFeatureTypes().push_back( featureType ); } } return capabilities.release(); }
static void readLayers(XmlElement* e, WMSLayer* parentLayer, WMSLayer::LayerList& layers) { XmlNodeList layerNodes = e->getSubElements( ELEM_LAYER ); for( XmlNodeList::const_iterator i = layerNodes.begin(); i != layerNodes.end(); i++ ) { XmlElement* e_layer = static_cast<XmlElement*>( i->get() ); WMSLayer *layer = new WMSLayer; layer->setName( e_layer->getSubElementText( ELEM_NAME ) ); layer->setTitle( e_layer->getSubElementText( ELEM_TITLE ) ); layer->setAbstract( e_layer->getSubElementText( ELEM_ABSTRACT ) ); //Read all the supported styles XmlNodeList styles = e_layer->getSubElements( ELEM_STYLE ); for( XmlNodeList::const_iterator styleitr = styles.begin(); styleitr != styles.end(); styleitr++ ) { XmlElement* e_style = static_cast<XmlElement*>( styleitr->get() ); string name = e_style->getSubElementText( ELEM_NAME ); string title = e_style->getSubElementText( ELEM_TITLE ); layer->getStyles().push_back(WMSStyle(name,title)); } //Read all the supported SRS's XmlNodeList spatialReferences = e_layer->getSubElements( ELEM_SRS ); for (XmlNodeList::const_iterator srsitr = spatialReferences.begin(); srsitr != spatialReferences.end(); ++srsitr) { string srs = static_cast<XmlElement*>( srsitr->get() )->getText(); layer->getSpatialReferences().push_back(srs); } //Read all the supported CRS's spatialReferences = e_layer->getSubElements( ELEM_CRS ); for (XmlNodeList::const_iterator srsitr = spatialReferences.begin(); srsitr != spatialReferences.end(); ++srsitr) { string crs = static_cast<XmlElement*>( srsitr->get() )->getText(); layer->getSpatialReferences().push_back(crs); } osg::ref_ptr<XmlElement> e_bb = e_layer->getSubElement( ELEM_LATLONBOUNDINGBOX ); if (e_bb.valid()) { double minX, minY, maxX, maxY; minX = as<double>(e_bb->getAttr( ATTR_MINX ), 0); minY = as<double>(e_bb->getAttr( ATTR_MINY ), 0); maxX = as<double>(e_bb->getAttr( ATTR_MAXX ), 0); maxY = as<double>(e_bb->getAttr( ATTR_MAXY ), 0); layer->setLatLonExtents(minX, minY, maxX, maxY); } else { osg::ref_ptr<XmlElement> e_gbb = e_layer->getSubElement( ELEM_GEOGRAPHICBOUNDINGBOX ); if (e_gbb.valid()) { double minX, minY, maxX, maxY; minX = as<double>(e_gbb->getSubElementText( ATTR_WESTLON ), 0); minY = as<double>(e_gbb->getSubElementText( ATTR_SOUTHLAT ), 0); maxX = as<double>(e_gbb->getSubElementText( ATTR_EASTLON ), 0); maxY = as<double>(e_gbb->getSubElementText( ATTR_NORTHLAT ), 0); layer->setLatLonExtents(minX, minY, maxX, maxY); } } e_bb = e_layer->getSubElement( ELEM_BOUNDINGBOX ); if (e_bb.valid()) { double minX, minY, maxX, maxY; minX = as<double>(e_bb->getAttr( ATTR_MINX ), 0); minY = as<double>(e_bb->getAttr( ATTR_MINY ), 0); maxX = as<double>(e_bb->getAttr( ATTR_MAXX ), 0); maxY = as<double>(e_bb->getAttr( ATTR_MAXY ), 0); layer->setExtents(minX, minY, maxX, maxY); } //Add the layer to the list and set its parent layer layers.push_back(layer); layer->setParentLayer( parentLayer ); //Read any other layers that are in the layer node readLayers( e_layer, layer, layer->getLayers()); } }