Esempio n. 1
0
void addTilePatterns(XmlElement* e_root, TileService* tileService)
{
    //Read all the TilePatterns
    XmlNodeList tile_patterns = e_root->getSubElements( ELEM_TILEPATTERN );
    for( XmlNodeList::const_iterator i = tile_patterns.begin(); i != tile_patterns.end(); i++ )
    {            
        //We only really care about a single access pattern, so extract it
        string txt = static_cast<XmlElement*>( i->get() )->getText();
        //Access patterns are separated by whitespace 
        std::string whitespace (" \t\f\v\n\r");
        string::size_type len = txt.find_first_of(whitespace);
        if (len != string::npos)
        {
            txt = trim(txt.substr(0, len));
        }
        TilePattern pattern(txt);
        tileService->getPatterns().push_back(pattern);
    }

    //Read all TilePatterns in the TiledGroups
    XmlNodeList tiled_groups = e_root->getSubElements(ELEM_TILEDGROUP);
    for( XmlNodeList::const_iterator i = tiled_groups.begin(); i != tiled_groups.end(); i++ )
    {
        addTilePatterns(static_cast<XmlElement*>(i->get()), tileService);
    }
}
Esempio n. 2
0
void
XmlDocument::store( std::ostream& out ) const
{
    out << "<?xml version=\"1.0\"?>" << std::endl;
    for( XmlNodeList::const_iterator i = getChildren().begin(); i != getChildren().end(); i++ )
    {
        storeNode( i->get(), 0, out );
    }
}
Esempio n. 3
0
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();
}
Esempio n. 4
0
std::string
XmlElement::getText() const
{
    std::stringstream builder;

    for( XmlNodeList::const_iterator i = getChildren().begin(); i != getChildren().end(); i++ )
    {
        if ( i->get()->isText() )
        {
            builder << ( static_cast<XmlText*>( i->get() ) )->getValue();
        }
    }

 	 std::string builderStr;
	 builderStr = builder.str();
    std::string result = trim( builderStr );
    return result;
}
Esempio n. 5
0
Config
XmlElement::getConfig() const
{
    Config conf( name );
    for( XmlAttributes::const_iterator a = attrs.begin(); a != attrs.end(); a++ )
        conf.attr( a->first ) = a->second;
    for( XmlNodeList::const_iterator c = children.begin(); c != children.end(); c++ )
    {
        XmlNode* n = c->get();
        if ( n->isElement() )
            conf.add( static_cast<const XmlElement*>(n)->getConfig() );
    }

    conf.value() = getText();
        //else 
        //    conf.value() = trim( static_cast<const XmlText*>(n)->getValue() );
    return conf;
}
Esempio n. 6
0
XmlElement*
XmlElement::getSubElement( const std::string& name ) const
{
    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 )
                return e;
        }
    }
    return NULL;
}
Esempio n. 7
0
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();
}
Esempio n. 8
0
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());
    }
}