예제 #1
0
bool 
ServiceReader::read( const Config& conf,  RESTResponse& response )
{
    response.getServices().clear();
    response.getFolders().clear();


    if (conf.hasChild("currentVersion"))
    {
        response.setCurrentVersion( conf.value("currentVersion") );
    }

    if (conf.hasChild("services"))
    {
        ConfigSet services = conf.child("services").children();
        for (ConfigSet::iterator itr = services.begin(); itr != services.end(); ++itr)
        {
            response.getServices().push_back( Service( itr->value("name"), itr->value("type") ) );            
        }
    }

    if (conf.hasChild("folders"))
    {
        ConfigSet folders = conf.child("folders").children();
        for (ConfigSet::iterator itr = folders.begin(); itr != folders.end(); ++itr)
        {
            response.getFolders().push_back( itr->value() );            
        }
    }

    return true;
}
예제 #2
0
void
TextureSplatter::mergeConfig(const Config& conf)
{
    conf.getIfSet( "start_lod",  _startLOD );
    conf.getIfSet( "intensity",  _intensity );
    conf.getIfSet( "scale",      _scale );
    conf.getIfSet( "attenuation_distance", _attenuationDistance );
    conf.getIfSet( "mask_layer", _maskLayerName );

    ConfigSet textures = conf.child("textures").children("texture");
    for(ConfigSet::iterator i = textures.begin(); i != textures.end(); ++i)
    {
        _textures.push_back(TextureSource());
        _textures.back()._tag = i->value("tag");
        _textures.back()._url = i->value("url");
    }
}
예제 #3
0
void
StyleSheet::mergeConfig( const Config& conf )
{
    _uriContext = URIContext( conf.referrer() );

    // read in any resource library references
    ConfigSet libraries = conf.children( "library" );
    for( ConfigSet::iterator i = libraries.begin(); i != libraries.end(); ++i )
    {
        ResourceLibrary* resLib = new ResourceLibrary( *i );
        _resLibs[resLib->getName()] = resLib;
    }

    // read in any scripts
    ConfigSet scripts = conf.children( "script" );
    for( ConfigSet::iterator i = scripts.begin(); i != scripts.end(); ++i )
    {
        // get the script code
        std::string code = i->value();

        // name is optional and unused at the moment
        std::string name = i->value("name");

        std::string lang = i->value("language");
        if ( lang.empty() ) {
            // default to javascript
            lang = "javascript";
        }

        _script = new Script(code, lang, name);
    }

    // read any style class definitions. either "class" or "selector" is allowed
    ConfigSet selectors = conf.children( "selector" );
    if ( selectors.empty() ) selectors = conf.children( "class" );
    for( ConfigSet::iterator i = selectors.begin(); i != selectors.end(); ++i )
    {
        _selectors.push_back( StyleSelector( *i ) );
    }

    // read in the actual styles
    ConfigSet styles = conf.children( "style" );
    for( ConfigSet::iterator i = styles.begin(); i != styles.end(); ++i )
    {
        const Config& styleConf = *i;

        if ( styleConf.value("type") == "text/css" )
        {
            // for CSS data, there may be multiple styles in one CSS block. So
            // parse them all out and add them to the stylesheet.

            // read the inline data:
            std::string cssString = styleConf.value();

            // if there's a URL, read the CSS from the URL:
            if ( styleConf.hasValue("url") )
            {
                URI uri( styleConf.value("url"), styleConf.referrer() );
                cssString = uri.readString().getString();
            }

            // break up the CSS into multiple CSS blocks and parse each one individually.
            std::vector<std::string> blocks;
            CssUtils::split( cssString, blocks );

            for( std::vector<std::string>::iterator i = blocks.begin(); i != blocks.end(); ++i )
            {
                Config blockConf( styleConf );
                blockConf.value() = *i;
                //OE_INFO << LC << "Style block = " << blockConf.toJSON() << std::endl;
                Style style( blockConf );
                _styles[ style.getName() ] = style;
            }
        }
        else
        {
            Style style( styleConf );
            _styles[ style.getName() ] = style;
        }
    }
}
예제 #4
0
파일: Style.cpp 프로젝트: rdelmont/osgearth
void
StyleSheet::mergeConfig( const Config& conf )
{
    // read in any resource library references
    ConfigSet libraries = conf.children( "library" );
    for( ConfigSet::iterator i = libraries.begin(); i != libraries.end(); ++i )
    {
        std::string name = i->value("name");
        if ( name.empty() ) {
            OE_WARN << LC << "Resource library missing required 'name' attribute" << std::endl;
            continue;
        }

        URI uri( i->value("url"), i->uriContext() );
        if ( uri.empty() ) {
            OE_WARN << LC << "Resource library missing required 'url' element" << std::endl;
            continue;
        }

        osg::ref_ptr<ResourceLibrary> reslib = ResourceLibrary::create( uri );
        if ( !reslib.valid() ) {
            OE_WARN << LC << "Resource library creation failed" << std::endl;
            continue;
        }

        addResourceLibrary( name, reslib.get() );
    }

    // read any style class definitions. either "class" or "selector" is allowed
    ConfigSet selectors = conf.children( "selector" );
    if ( selectors.empty() ) selectors = conf.children( "class" );
    for( ConfigSet::iterator i = selectors.begin(); i != selectors.end(); ++i )
    {
        _selectors.push_back( StyleSelector( *i ) );
    }

    // read in the actual styles
    ConfigSet styles = conf.children( "style" );
    for( ConfigSet::iterator i = styles.begin(); i != styles.end(); ++i )
    {
        const Config& styleConf = *i;

        if ( styleConf.value("type") == "text/css" )
        {
            // read the inline data:
            std::string cssString = styleConf.value();

            // if there's a URL, read the CSS from the URL:
            if ( styleConf.hasValue("url") )
            {
                URI uri( styleConf.value("url"), styleConf.uriContext() );
                HTTPClient::readString( uri.full(), cssString );
            }

            // a CSS style definition can actually contain multiple styles. Read them
            // and create one style for each in the catalog.
            std::stringstream buf( cssString );
            Config css = CssUtils::readConfig( buf );
            css.setURIContext( styleConf.uriContext( ) );
            
            const ConfigSet children = css.children();
            for(ConfigSet::const_iterator j = children.begin(); j != children.end(); ++j )
            {
                Style style( styleConf );
                
                if ( SLDReader::readStyleFromCSSParams( *j, style ) )
                    _styles[ j->key() ] = style;
            }            
        }
        else
        {
            Style style( styleConf );
            _styles[ style.getName() ] = style;
        }
    }
}
예제 #5
0
파일: Style.cpp 프로젝트: spencerg/osgearth
void
StyleSheet::mergeConfig( const Config& conf )
{
    _uriContext = URIContext( conf.referrer() );

    // read in any resource library references
    ConfigSet libraries = conf.children( "library" );
    for( ConfigSet::iterator i = libraries.begin(); i != libraries.end(); ++i )
    {
        std::string name = i->value("name");
        if ( name.empty() ) {
            OE_WARN << LC << "Resource library missing required 'name' attribute" << std::endl;
            continue;
        }

        URI uri( i->value("url"), i->referrer() );
        if ( uri.empty() ) {
            OE_WARN << LC << "Resource library missing required 'url' element" << std::endl;
            continue;
        }

        _resLibs[name] = ResourceLibraryEntry(uri,  (osgEarth::Symbology::ResourceLibrary*)0L);

        //addResourceLibrary( name, reslib.get() );
    }

    // read in any scripts
    ConfigSet scripts = conf.children( "script" );
    for( ConfigSet::iterator i = scripts.begin(); i != scripts.end(); ++i )
    {
        // get the script code
        std::string code = i->value();

        // name is optional and unused at the moment
        std::string name = i->value("name");

        std::string lang = i->value("language");
        if ( lang.empty() ) {
            // default to javascript
            lang = "javascript";
        }

        _script = new Script(code, lang, name);
    }

    // read any style class definitions. either "class" or "selector" is allowed
    ConfigSet selectors = conf.children( "selector" );
    if ( selectors.empty() ) selectors = conf.children( "class" );
    for( ConfigSet::iterator i = selectors.begin(); i != selectors.end(); ++i )
    {
        _selectors.push_back( StyleSelector( *i ) );
    }

    // read in the actual styles
    ConfigSet styles = conf.children( "style" );
    for( ConfigSet::iterator i = styles.begin(); i != styles.end(); ++i )
    {
        const Config& styleConf = *i;

        if ( styleConf.value("type") == "text/css" )
        {
            // read the inline data:
            std::string cssString = styleConf.value();

            // if there's a URL, read the CSS from the URL:
            if ( styleConf.hasValue("url") )
            {
                URI uri( styleConf.value("url"), styleConf.referrer() );
                cssString = uri.readString().getString();
            }

            // a CSS style definition can actually contain multiple styles. Read them
            // and create one style for each in the catalog.
            std::stringstream buf( cssString );
            Config css = CssUtils::readConfig( buf );
            css.setReferrer( styleConf.referrer() );
            
            const ConfigSet children = css.children();
            for(ConfigSet::const_iterator j = children.begin(); j != children.end(); ++j )
            {
                Style style( styleConf );
                
                if ( SLDReader::readStyleFromCSSParams( *j, style ) )
                    _styles[ j->key() ] = style;
            }            
        }
        else
        {
            Style style( styleConf );
            _styles[ style.getName() ] = style;
        }
    }
}