Exemple #1
0
MSBInfoPage* MSBInfo::Parse(TiXmlNode* page)
{
	if (page)
	{
		_page = new MSBInfoPage();

		TiXmlNode* child = 0;
		TiXmlNode* root = page;
		TiXmlElement* pageElement = page->ToElement();
		
		if (pageElement)
		{
			_page->EID = pageElement->Attribute("eid");
			_page->Category = pageElement->Attribute("category");
			_page->Type = pageElement->Attribute("type");
			_page->NodeName = pageElement->Attribute("nodeName");

			TiXmlNode* title = page->FirstChild("title");
			if (title)
				_page->Title = title->ToElement()->GetText();
			else
				Core::Dbg->Log(Warning, "No title node found");
		}
		else
			Core::Dbg->Log(Warning, "Page node not accessible");
		pageElement = 0;

		// Navigate to the 'background' part while adding skills
		while((child = root->IterateChildren(child)))
		{
			if (child->ValueStr().compare("skill") == 0)
			{
				TiXmlElement* skillelement = child->ToElement();
				if (skillelement)
				{
					Skill* sk = new Skill();
					sk->ID = skillelement->Attribute("kid");
					sk->Name = skillelement->GetText();
					_page->Skills.push_back(sk);
				}
				else
					Core::Dbg->Log(Warning, "Conversion error in Skill node");
			}
			if (child->ValueStr().compare("backgroundInfo") == 0)
			{
				// Handle background node
				XMLProcessBackground(child);
			}
		}
	
	}
	else
		Core::Dbg->Log(Warning, "XML parse error, no page element found");

	return _page;
}
Exemple #2
0
bool CSmartPlaylistRule::Load(TiXmlElement *element, const CStdString &encoding /* = "UTF-8" */)
{
  if (element == NULL)
    return false;

  // format is:
  // <rule field="Genre" operator="contains">parameter</rule>
  // where parameter can either be a string or a list of
  // <value> tags containing a string
  const char *field = element->Attribute("field");
  const char *oper = element->Attribute("operator");
  TiXmlNode *parameter = element->FirstChild();
  if (field == NULL || oper == NULL || parameter == NULL)
    return false;

  if (parameter->Type() == TiXmlNode::TINYXML_TEXT)
  {
    CStdString utf8Parameter;
    if (encoding.IsEmpty()) // utf8
      utf8Parameter = parameter->ValueStr();
    else
      g_charsetConverter.stringCharsetToUtf8(encoding, parameter->ValueStr(), utf8Parameter);

    if (!utf8Parameter.empty())
      m_parameter.push_back(utf8Parameter);
  }
  else if (parameter->Type() == TiXmlNode::TINYXML_ELEMENT)
  {
    TiXmlElement *valueElem = element->FirstChildElement("value");
    while (valueElem != NULL)
    {
      TiXmlNode *value = valueElem->FirstChild();
      if (value != NULL && value->Type() == TiXmlNode::TINYXML_TEXT)
      {
        CStdString utf8Parameter;
        if (encoding.IsEmpty()) // utf8
          utf8Parameter = value->ValueStr();
        else
          g_charsetConverter.stringCharsetToUtf8(encoding, value->ValueStr(), utf8Parameter);

        if (!utf8Parameter.empty())
          m_parameter.push_back(utf8Parameter);
      }

      valueElem = valueElem->NextSiblingElement("value");
    }
  }
  else
    return false;

  m_field = TranslateField(field);
  m_operator = TranslateOperator(oper);
  return true;
}
Exemple #3
0
bool BXBoxeeServices::Parse()
{
    TiXmlHandle docHandle(&m_doc);
    TiXmlNode* pTSChild = docHandle.FirstChild("services").FirstChild("timestamp").FirstChild().Node();

    if (pTSChild)
    {
        m_timestamp = atoi(pTSChild->Value());
    }

    TiXmlElement *pChild = docHandle.FirstChild("services").Element();
    if (!pChild)
    {
        LOG(LOG_LEVEL_ERROR,"BXBoxeeServices::Parse - FAILED to find <applications> node");
        return false;
    }

    m_services.clear();

    TiXmlNode *pMsgNode = 0;
    while ((pMsgNode = pChild->IterateChildren(pMsgNode)) != NULL)
    {
        if (pMsgNode->ValueStr().compare("object") == 0)
        {
            BXObject obj;
            if (obj.FromXML(pMsgNode))
            {
                m_services.push_back(obj);
            }
        }
    }

    return true;
}
bool CMetadataResolverMusic::LoadAlbumsInfo(BOXEE::BXXMLDocument& doc, vectorMetadata& list)
{
  TiXmlElement* pRootElement = doc.GetDocument().RootElement();
  bool bRetVal = true;
  if (pRootElement->ValueStr() == "results")
  {
    TiXmlNode* pTag = 0;
    BXMetadata album(MEDIA_ITEM_TYPE_AUDIO);

    while ((pTag = pRootElement->IterateChildren(pTag)))
    {
      if (pTag && pTag->ValueStr() == "album")
      {
        TiXmlElement* pValue = pTag->FirstChildElement();

        if (pValue && (LoadAlbumInfo(pValue,album)))
          list.push_back(album);
        else
           bRetVal = false;
      }
      else
        bRetVal = false;
    }
  }
  else
    bRetVal = false;

  return bRetVal;
}
//<BiLink>
void LibraryParser::ParseBiLink(TiXmlNode* pParent) {
	GetBiLinkAttributes(pParent ) ;
	TiXmlNode* Child;
	string Elem;
	BiLink L;
	int Lcount = 0;
	for (Child = pParent->FirstChild() ; Child != 0; Child
			= Child->NextSibling() ) {
		Elem = Child->ValueStr() ;
		if (Elem == "Link") {
			ParseLink(Child ) ;
			if (Lcount == 0) {
				L.L1(mCurrentLink) ;
				Lcount++;
			} else if (Lcount==1) {
				L.L2(mCurrentLink) ;
			}
		} else {
			cout << "Unknown XML element "<< Elem << " in file "<< mFname
					<< endl ;
		}

	}
	mCurrentBiLink = L ;
	mLib->AddBiLink(mCurrentBiLink) ;
}
bool BXBoxeeWebFavorites::Parse()
{
  TiXmlHandle docHandle(&m_doc);

  TiXmlElement *pChild = docHandle.FirstChild("bookmarks").Element();
  if (!pChild)
  {
    LOG(LOG_LEVEL_ERROR,"BXBoxeeWebFavorites::Parse - FAILED to find <bookmark> node");
    return false;
  }

  m_webFavorites.clear();

  TiXmlNode *pMsgNode = 0;
  while ((pMsgNode = pChild->IterateChildren(pMsgNode)) != NULL)
  {
    if (pMsgNode->ValueStr().compare("bookmark") == 0)
    {
      BXObject obj;
      if (obj.FromXML(pMsgNode))
      {
        m_webFavorites.push_back(obj);
      }
    }
  }

  return true;
}
Exemple #7
0
void CGUIIncludes::ResolveParametersForNode(TiXmlElement *node, const Params& params)
{
  if (!node)
    return;
  std::string newValue;
  // run through this element's attributes, resolving any parameters
  TiXmlAttribute *attribute = node->FirstAttribute();
  while (attribute)
  {
    ResolveParamsResult result = ResolveParameters(attribute->ValueStr(), newValue, params);
    if (result == SINGLE_UNDEFINED_PARAM_RESOLVED && strcmp(node->Value(), "param") == 0 &&
        strcmp(attribute->Name(), "value") == 0 && node->Parent() && strcmp(node->Parent()->Value(), "include") == 0)
    {
      // special case: passing <param name="someName" value="$PARAM[undefinedParam]" /> to the nested include
      // this usually happens when trying to forward a missing parameter from the enclosing include to the nested include
      // problem: since 'undefinedParam' is not defined, it expands to <param name="someName" value="" /> and overrides any default value set with <param name="someName" default="someValue" /> in the nested include
      // to prevent this, we'll completely remove this parameter from the nested include call so that the default value can be correctly picked up later
      node->Parent()->RemoveChild(node);
      return;
    }
    else if (result != NO_PARAMS_FOUND)
      attribute->SetValue(newValue);
    attribute = attribute->Next();
  }
  // run through this element's value and children, resolving any parameters
  TiXmlNode *child = node->FirstChild();
  if (child)
  {
    if (child->Type() == TiXmlNode::TINYXML_TEXT)
    {
      ResolveParamsResult result = ResolveParameters(child->ValueStr(), newValue, params);
      if (result == SINGLE_UNDEFINED_PARAM_RESOLVED && strcmp(node->Value(), "param") == 0 &&
          node->Parent() && strcmp(node->Parent()->Value(), "include") == 0)
      {
        // special case: passing <param name="someName">$PARAM[undefinedParam]</param> to the nested include
        // we'll remove the offending param tag same as above
        node->Parent()->RemoveChild(node);
      }
      else if (result != NO_PARAMS_FOUND)
        child->SetValue(newValue);
    }
    else if (child->Type() == TiXmlNode::TINYXML_ELEMENT)
    {
      do
      {
        TiXmlElement *next = child->NextSiblingElement();   // save next as current child might be removed from the tree
        ResolveParametersForNode(static_cast<TiXmlElement *>(child), params);
        child = next;
      }
      while (child);
    }
  }
}
Exemple #8
0
void MSBInfo::XMLProcessBackground(TiXmlNode* bg)
{
	if (bg)
	{
		TiXmlNode* child = 0;
		_page->Text = "";
		while((child = bg->IterateChildren(child)))
		{
			if (child->ValueStr().compare("avobject") == 0)
			{
				TiXmlElement* av = child->ToElement();
				_page->Image = av->Attribute("filename");
			}
			if (child->ValueStr().compare("txt") == 0)
			{
				TiXmlElement* txt = child->ToElement();
				_page->Text += txt->GetText();
			}
		}
	}
	else
		Core::Dbg->Log(Warning, "NULL value passed to utterance node handler");
}
void
XmlPrototypesFile::LoadPrototypes()
{
    TiXmlNode* node = m_File.RootElement();

    if( node == NULL || node->ValueStr() != "prototypes" )
    {
        LOG_ERROR( "UI Manager: " + m_File.ValueStr() + " is not a valid prototypes file! No <prototypes> in root." );
        return;
    }

    node = node->FirstChild();
    while( node != NULL )
    {
        if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "prototype" )
        {
            Ogre::String name = GetString( node, "name" );
            UiManager::getSingleton().AddPrototype( name, node->Clone() );
        }

        node = node->NextSibling();
    }
}
//<Interface>
void LibraryParser::ParseInterface(TiXmlNode* pParent) {
	GetInterfaceAttributes(pParent ) ;
	TiXmlNode* Child;
	string Elem;
	for (Child = pParent->FirstChild() ; Child != 0; Child
			= Child->NextSibling() ) {
		Elem = Child->ValueStr() ;
		if (Elem == "") {
			Parse(Child ) ;
		} else {
			cout << "Unknown XML element "<< Elem << " in file "<< mFname
					<< endl ;
		}
	}
}
Exemple #11
0
const Ogre::String
XmlMapFile::GetWalkmeshFileName()
{
    TiXmlNode* node = m_File.RootElement();

    if( node == NULL || node->ValueStr() != "map" )
    {
        LOG_ERROR( "Field Map XML Manager: " + m_File.ValueStr() + " is not a valid fields map file! No <map> in root." );
        return "";
    }

    node = node->FirstChild();
    while( node != NULL )
    {
        if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "walkmesh" )
        {
            return GetString( node, "file_name" );
        }
        node = node->NextSibling();
    }

    LOG_WARNING( "Can't find field's walkmesh in " + m_File.ValueStr() + "." );
    return "";
}
//<Library>
void LibraryParser::ParseLibrary(TiXmlNode* pParent) {
	cerr << "Parsing the Library "<< endl ;
	GetLibraryAttributes(pParent ) ;
	TiXmlNode* Child;
	string Elem;
	for (Child = pParent->FirstChild() ; Child != 0; Child
			= Child->NextSibling() ) {
		Elem = Child->ValueStr() ;
		if (Elem == "Node") {
			ParseNode(Child ) ;
		} else if (Elem == "Link") {
			ParseLink(Child ) ;
		} else if (Elem == "BiLink") {
			ParseBiLink(Child ) ;
		} else {
			cout << "Unknown XML element "<< Elem<< " in file "<< mFname<< endl ;
		}
	}
}
//<Link>
void LibraryParser::ParseLink(TiXmlNode* pParent) {
	GetLinkAttributes(pParent ) ;
	TiXmlNode* Child;
	string Elem;
	for (Child = pParent->FirstChild() ; Child != 0; Child
			= Child->NextSibling() ) {
		Elem = Child->ValueStr() ;
		if (Elem == "Source") {
			ParseLinkSource(Child ) ;
		} else if (Elem == "Dest") {
			ParseLinkDest(Child ) ;
		} else {
			cout << "Unknown XML element "<< Elem << " in file "<< mFname
					<< endl ;
		}
	}
	//Add link to the library
	mLib->AddLink(mCurrentLink) ;
}
void LibraryParser::ParseDocument(TiXmlNode* pParent) {
	if ( !pParent )
		return;

	int Type = pParent->Type() ;
	string Elem;

	if (Type == TiXmlNode::DOCUMENT ) {
		cout << "Parsing the library from file  "<< mFname << endl ;
		TiXmlNode* Child;
		for (Child = pParent->FirstChild() ; Child != 0; Child
				= Child->NextSibling() ) {
			Elem = Child->ValueStr() ;
			if (Elem == "Library")
				ParseLibrary(Child ) ;
		}
	} else {
		cout << "The document should be parsed..."<< endl ;
	}
	return;
}
bool CXBMCTinyXML::Test()
{
  // scraper results with unescaped &
  CXBMCTinyXML doc;
  CStdString data("<details><url function=\"ParseTMDBRating\" "
                  "cache=\"tmdb-en-12244.json\">"
                  "http://api.themoviedb.org/3/movie/12244"
                  "?api_key=57983e31fb435df4df77afb854740ea9"
                  "&language=en&#x3f;&#x003F;&#0063;</url></details>");
  doc.Parse(data.c_str());
  TiXmlNode *root = doc.RootElement();
  if (root && root->ValueStr() == "details")
  {
    TiXmlElement *url = root->FirstChildElement("url");
    if (url && url->FirstChild())
    {
      return (url->FirstChild()->ValueStr() == "http://api.themoviedb.org/3/movie/12244?api_key=57983e31fb435df4df77afb854740ea9&language=en???");
    }
  }
  return false;
}
Exemple #16
0
TEST(TestXBMCTinyXML, ParseFromFileHandle)
{
  bool retval = false;
  // scraper results with unescaped &
  CXBMCTinyXML doc;
  FILE *f = fopen(XBMC_REF_FILE_PATH("/xbmc/utils/test/CXBMCTinyXML-test.xml"), "r");
  ASSERT_TRUE(f);
  doc.LoadFile(f);
  fclose(f);
  TiXmlNode *root = doc.RootElement();
  if (root && root->ValueStr() == "details")
  {
    TiXmlElement *url = root->FirstChildElement("url");
    if (url && url->FirstChild())
    {
      CStdString str = url->FirstChild()->ValueStr();
      retval = (str.Trim() == "http://api.themoviedb.org/3/movie/12244?api_key=57983e31fb435df4df77afb854740ea9&language=en???");
    }
  }
  EXPECT_TRUE(retval);
}
Exemple #17
0
void CGUIIncludes::ResolveExpressions(TiXmlElement *node)
{
  if (!node)
    return;

  TiXmlNode *child = node->FirstChild();
  if (child && child->Type() == TiXmlNode::TINYXML_TEXT && m_expressionNodes.count(node->ValueStr()))
  {
    child->SetValue(ResolveExpressions(child->ValueStr()));
  }
  else
  {
    TiXmlAttribute *attribute = node->FirstAttribute();
    while (attribute)
    {
      if (m_expressionAttributes.count(attribute->Name()))
        attribute->SetValue(ResolveExpressions(attribute->ValueStr()));

      attribute = attribute->Next();
    }
  }
}
Exemple #18
0
HaloReadError Fluidity::ReadHalos(const string& filename, int& process, int& nprocs, map<int, int>& npnodes, map<int, vector<vector<int> > >& send, map<int, vector<vector<int> > >& recv){ 
  // Read the halo file
  TiXmlDocument doc(filename);
  if(!doc.LoadFile()){
    doc.ErrorDesc();
    return HALO_READ_FILE_NOT_FOUND;
  }
  
  const char* charBuffer;
  ostringstream buffer;
   
  // Extract the XML header
  TiXmlNode* header = doc.FirstChild();
  while(header != NULL and header->Type() != TiXmlNode::DECLARATION){
    header = header->NextSibling();
  }

  // Extract the root node
  TiXmlNode* rootNode = header->NextSiblingElement();
  if(rootNode == NULL){
    return HALO_READ_FILE_INVALID;
  }
  TiXmlElement* rootEle = rootNode->ToElement();
  
  // Extract process
  charBuffer = rootEle->Attribute("process");
  if(charBuffer == NULL){
    return HALO_READ_FILE_INVALID;
  }
  process = atoi(charBuffer);
  if(process < 0){
    return HALO_READ_FILE_INVALID;
  }
  
  // Extract nprocs
  charBuffer = rootEle->Attribute("nprocs");
  if(charBuffer == NULL){
    return HALO_READ_FILE_INVALID;
  }
  nprocs = atoi(charBuffer);
  if(process >= nprocs){
    return HALO_READ_FILE_INVALID;
  }
  
  // Extract halo data for each process for each level
  npnodes.clear();
  send.clear();
  recv.clear();
  // Find the next halo element
  for(TiXmlNode* haloNode = rootEle->FirstChildElement("halo");haloNode != NULL;haloNode = haloNode->NextSiblingElement("halo")){
    if(haloNode == NULL){
      break;
    }
    TiXmlElement* haloEle = haloNode->ToElement();
    
    // Extract the level
    charBuffer = haloEle->Attribute("level");
    if(charBuffer == NULL){
      // Backwards compatibility
      charBuffer = haloEle->Attribute("tag");
      if(charBuffer == NULL){
        return HALO_READ_FILE_INVALID;
      }
    }
    int level = atoi(charBuffer);
    send[level] = vector<vector<int> >(nprocs);
    recv[level] = vector<vector<int> >(nprocs);

    // Extract n_private_nodes
    charBuffer = haloEle->Attribute("n_private_nodes");
    if(charBuffer == NULL){
      return HALO_READ_FILE_INVALID;
    }
    npnodes[level] = atoi(charBuffer);
    if(npnodes[level] < 0){
      return HALO_READ_FILE_INVALID;
    }
    
    // Find the next halo_data element
    for(TiXmlNode* dataNode = haloEle->FirstChildElement("halo_data");dataNode != NULL;dataNode = dataNode->NextSiblingElement("halo_data")){
      if(dataNode == NULL){
        break;
      }
      TiXmlElement* dataEle = dataNode->ToElement();
    
      // Extract the process
      charBuffer = dataEle->Attribute("process");
      if(charBuffer == NULL){
        return HALO_READ_FILE_INVALID;
      }
      int proc = atoi(charBuffer);
      if(proc < 0 or proc >= nprocs){
        return HALO_READ_FILE_INVALID;
      }
      
      // Check that data for this level and process has not already been extracted
      if(send[level][proc].size() > 0 or recv[level][proc].size() > 0){
        return HALO_READ_FILE_INVALID;
      }
      
      // Permit empty send and receive data elements
      send[level][proc] = vector<int>();
      recv[level][proc] = vector<int>();
      
      // Extract the send data
      TiXmlNode* sendDataNode = dataEle->FirstChildElement("send");
      if(sendDataNode != NULL){
        TiXmlNode* sendDataTextNode = sendDataNode->FirstChild();
        while(sendDataTextNode != NULL and sendDataTextNode->Type() != TiXmlNode::TEXT){
          sendDataTextNode = sendDataTextNode->NextSibling();
        }
        if(sendDataTextNode != NULL){
          vector<string> tokens;
          Tokenize(sendDataTextNode->ValueStr(), tokens, " ");
          for(size_t i = 0;i < tokens.size();i++){
            send[level][proc].push_back(atoi(tokens[i].c_str()));
          }
        }
      }
      
      // Extract the receive data
      TiXmlNode* recvDataNode = dataEle->FirstChildElement("receive");
      if(recvDataNode != NULL){
      TiXmlNode* recvDataTextNode = recvDataNode->FirstChild();
        while(recvDataTextNode != NULL and recvDataTextNode->Type() != TiXmlNode::TEXT){
          recvDataTextNode = recvDataTextNode->NextSibling();
        }
        if(recvDataTextNode != NULL){
          vector<string> tokens;
          Tokenize(recvDataTextNode->ValueStr(), tokens, " ");
          for(size_t i = 0;i < tokens.size();i++){
            recv[level][proc].push_back(atoi(tokens[i].c_str()));
          }
        }
      }
    }
  }

  return HALO_READ_SUCCESS;
}
Exemple #19
0
  //----------------------------------------------------------------------------
  bool XmlConfig::loadFile()
  {
    if( !_config )
      return false;
    if( !_dirty_read )
      return true;

    // For now just process xml config once. We could check for file
    // modifications every second and update config if a change occurs...

    // Go through all the container, find all matching components and set
    // parameters
    for( TiXmlNode* child = _config->FirstChild();
         child;
         child = child->NextSibling() )
    {
      if( child->Type() != TiXmlNode::TINYXML_ELEMENT )
        continue;

      const std::string& comp_name = child->ValueStr();
      Type type = StringToType(comp_name);

      bool match = false;

      for( CompInfoList::iterator it = compInfoList.begin();
           it != compInfoList.end();
           ++it )
      {
        if( !it->match(comp_name, type) )
          continue;

        match = true;

        for( TiXmlNode* arg = child->FirstChild();
             arg;
             arg = arg->NextSibling() )
        {
          TiXmlElement* argel = arg->ToElement();
          if( !argel )
            continue;

          const std::string& key = argel->ValueStr();
          const char* argtype = argel->Attribute("type");
          const char* valstr = argel->Attribute("val");
          if(!argtype || !valstr)
          {
            LOG_WARN("incomplete Argument: "  << comp_name << ":" << key);
            continue;
          }

          if( !it->comp->setParameter(argel->ValueStr(), valstr, argtype) )
            LOG_WARN( "Failed to set value '"
                      << argel->ValueStr() << "' of type '"
                      << argtype << "' to '"
                      << valstr << "' on component "
                      << it->comp->name() );
        }
      }

      if( !match )
        LOG_WARN("Failed to find matching component for '" << comp_name << "'");
    }

    return true;
  }
Exemple #20
0
void
XmlMapFile::LoadMap()
{
    TiXmlNode* node = m_File.RootElement();

    if( node == NULL || node->ValueStr() != "map" )
    {
        LOG_ERROR( m_File.ValueStr() + " is not a valid fields map file! No <map> in root." );
        return;
    }

    node = node->FirstChild();
    while( node != NULL )
    {
        if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "walkmesh" )
        {
            Ogre::String name( GetString( node, "file_name" ) );
            if( !name.empty() )
            {
                QGears::WalkmeshFileManager::getSingleton();
                QGears::WalkmeshFilePtr walkmesh( QGears::WalkmeshFileManager::getSingleton().load( name, "Game" ) );
                EntityManager::getSingleton().GetWalkmesh()->load( walkmesh );
            }
        }
        else if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "movement_rotation" )
        {
            Ogre::Degree rotation = Ogre::Degree( GetFloat( node, "degree", 0 ) );
            EntityManager::getSingleton().SetPlayerMoveRotation( Ogre::Radian( rotation ) );
        }
        else if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "background2d" )
        {
            Ogre::String name = GetString( node, "file_name" );
            if( name != "" )
            {
                // TODO migrate this code to a Resource and use it's group to load background
                QGears::Background2DFilePtr background( QGears::Background2DFileManager::getSingleton().load( name, "Game" ) );
                EntityManager::getSingleton().GetBackground2D()->load( background );
            }
        }
        else if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "entity_model" )
        {
            Ogre::String name = GetString( node, "name" );
            if( name == "" )
            {
                LOG_ERROR( "There is no name specified for <entity_model> tag." );
                continue;
            }
            Ogre::String file_name = GetString( node, "file_name" );
            if( file_name == "" )
            {
                LOG_ERROR( "There is no file_name specified for <entity_model> tag." );
                continue;
            }

            Ogre::Vector3 position( GetVector3( node, "position" ) );
            Ogre::Degree direction( Ogre::Degree( GetFloat( node, "direction" ) ) );
            Ogre::Vector3 scale( GetVector3( node, "scale", Ogre::Vector3::UNIT_SCALE ) );
            Ogre::Quaternion orientation( GetQuaternion( node, "root_orientation" ) );

            EntityManager::getSingleton().AddEntity( name, file_name, position, direction, scale, orientation );
        }
        else if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "entity_trigger" )
        {
            Ogre::String name = GetString( node, "name" );
            if( name == "" )
            {
                LOG_ERROR( "There is no name specified for <entity_trigger> tag." );
                continue;
            }

            Ogre::Vector3 point1 = GetVector3( node, "point1", Ogre::Vector3::ZERO );
            Ogre::Vector3 point2 = GetVector3( node, "point2", Ogre::Vector3::ZERO );
            bool enabled = GetBool( node, "enabled", false );

            EntityManager::getSingleton().AddEntityTrigger( name, point1, point2, enabled );
        }
        else if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "entity_point" )
        {
            Ogre::String name = GetString( node, "name" );
            if( name == "" )
            {
                LOG_ERROR( "There is no name specified for <entity_point> tag." );
                continue;
            }

            Ogre::Vector3 position = GetVector3( node, "position" );
            float rotation = GetFloat( node, "rotation" );
            EntityManager::getSingleton().AddEntityPoint( name, position, rotation );
        }
        else if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "entity_script" )
        {
            Ogre::String name = GetString( node, "name" );
            if( name == "" )
            {
                LOG_ERROR( "There is no name specified for <entity_script> tag." );
                continue;
            }

            EntityManager::getSingleton().AddEntityScript( name );
        }
        else if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "script" )
        {
            Ogre::String file_name = GetString( node, "file_name" );
            if( file_name != "" )
            {
                ScriptManager::getSingleton().RunFile( file_name );
            }
        }

        node = node->NextSibling();
    }
}
Exemple #21
0
void CRssReader::GetNewsItems(TiXmlElement* channelXmlNode, int iFeed)
{
  HTML::CHTMLUtil html;

  TiXmlElement * itemNode = channelXmlNode->FirstChildElement("item");
  std::map<std::string, std::wstring> mTagElements;
  typedef std::pair<std::string, std::wstring> StrPair;
  std::list<std::string>::iterator i;

  // Add the title tag in if we didn't pass any tags in at all
  // Represents default behaviour before configurability

  if (m_tagSet.empty())
    AddTag("title");

  while (itemNode > 0)
  {
    TiXmlNode* childNode = itemNode->FirstChild();
    mTagElements.clear();
    while (childNode > 0)
    {
      std::string strName = childNode->ValueStr();

      for (i = m_tagSet.begin(); i != m_tagSet.end(); ++i)
      {
        if (!childNode->NoChildren() && *i == strName)
        {
          std::string htmlText = childNode->FirstChild()->ValueStr();

          // This usually happens in right-to-left languages where they want to
          // specify in the RSS body that the text should be RTL.
          // <title>
          //  <div dir="RTL">��� ����: ���� �� �����</div>
          // </title>
          if (htmlText == "div" || htmlText == "span")
            htmlText = childNode->FirstChild()->FirstChild()->ValueStr();

          std::wstring unicodeText, unicodeText2;

          g_charsetConverter.utf8ToW(htmlText, unicodeText2, m_rtlText);
          html.ConvertHTMLToW(unicodeText2, unicodeText);

          mTagElements.insert(StrPair(*i, unicodeText));
        }
      }
      childNode = childNode->NextSibling();
    }

    int rsscolour = RSS_COLOR_HEADLINE;
    for (i = m_tagSet.begin(); i != m_tagSet.end(); ++i)
    {
      std::map<std::string, std::wstring>::iterator j = mTagElements.find(*i);

      if (j == mTagElements.end())
        continue;

      std::wstring& text = j->second;
      AddString(text, rsscolour, iFeed);
      rsscolour = RSS_COLOR_BODY;
      text = L" - ";
      AddString(text, rsscolour, iFeed);
    }
    itemNode = itemNode->NextSiblingElement("item");
  }
}
void CSettingsManager::read_SettingsXML()
{
  TiXmlDocument xmlDoc;
  if(!xmlDoc.LoadFile(m_XMLFilename))
  {
    KODI->Log(LOG_NOTICE, "No initial settings XML file found.");
    return;
  }

  TiXmlElement *pRootElement = xmlDoc.RootElement();
  if(!pRootElement)
  {
    KODI->Log(LOG_NOTICE, "Settings XML file is empty.");
    return;
  }

  string mainCategory = pRootElement->Value();
  for(TiXmlNode *pGroupNode = pRootElement->FirstChild(); pGroupNode != NULL; pGroupNode = pRootElement->IterateChildren(pGroupNode))
  {
    if(pGroupNode->ValueStr() == "settings_group")
    {
      ATTRIBUTES_LIST groupAttributesList;
      if(pGroupNode && pGroupNode->Type() == TiXmlNode::TINYXML_ELEMENT)
      {
        getAttributesAsList(pGroupNode->ToElement(), groupAttributesList);
      }

      if(pGroupNode && pGroupNode->Type() == TiXmlNode::TINYXML_ELEMENT && groupAttributesList.size() == 2 && pGroupNode->ValueStr() == "settings_group")
      {
        string subCategory = "";
        string groupName = "";
        for(ATTRIBUTES_LIST::iterator iter = groupAttributesList.begin(); iter != groupAttributesList.end(); iter++)
        {
          if(iter->first == "sub_category")
          {
            subCategory = iter->second;
          }

          if(iter->first == "group_name")
          {
            groupName = iter->second;
          }
        }

        for(TiXmlNode *pKeyNode = pGroupNode->FirstChild(); pKeyNode != NULL; pKeyNode = pGroupNode->IterateChildren(pKeyNode))
        {
          if(pKeyNode && pKeyNode->Type() == TiXmlNode::TINYXML_ELEMENT && pKeyNode->ValueStr() == "setting")
          {
            ATTRIBUTES_LIST settingAttributesList;
            if(getAttributesAsList(pKeyNode->ToElement(), settingAttributesList) == 2)
            {
              string key = "";
              ISettingsElement::SettingsTypes type = ISettingsElement::UNKNOWN_SETTING;
              string value = "";
              for(ATTRIBUTES_LIST::iterator iter = settingAttributesList.begin(); iter != settingAttributesList.end(); iter++)
              {
                if(iter->first == "key")
                {
                  key = iter->second;
                }
                else
                {
                  type = CSettingsHelpers::TranslateTypeStrToEnum(iter->first);
                  value = iter->second;
                }
              }

              ISettingsElement *setting = find_Setting(mainCategory, subCategory, groupName, key);
              if(setting && setting->get_Type() == type)
              {
                switch(type)
                  {
                    case ISettingsElement::STRING_SETTING:
                      STRING_SETTINGS(setting)->set_Setting(value);
                    break;

                    case ISettingsElement::UNSIGNED_INT_SETTING:
                      {
                        unsigned int val = stringToVal<unsigned int>(value);
                        UNSIGNED_INT_SETTINGS(setting)->set_Setting(val);
                      }
                    break;

                    case ISettingsElement::INT_SETTING:
                      {
                        int val = stringToVal<int>(value);
                        INT_SETTINGS(setting)->set_Setting(val);
                      }
                    break;

                    case ISettingsElement::FLOAT_SETTING:
                      {
                        float val = stringToVal<float>(value);
                        FLOAT_SETTINGS(setting)->set_Setting(val);
                      }
                    break;

                    case ISettingsElement::DOUBLE_SETTING:
                      {
                        double val = stringToVal<double>(value);
                        DOUBLE_SETTINGS(setting)->set_Setting(val);
                      }
                    break;

                    case ISettingsElement::BOOL_SETTING:
                      if(value == "true" || value == "TRUE" || value == "True")
                      {
                        bool val = true;
                        BOOL_SETTINGS(setting)->set_Setting(val);
                      }
                      else if(value == "false" || value == "FALSE" || value == "False")
                      {
                        bool val = false;
                        BOOL_SETTINGS(setting)->set_Setting(val);
                      }
                      else
                      {
                        KODI->Log(LOG_ERROR, "CSettingsManager: Failed reading bool setting");
                      }
                    break;

                    default:
                      KODI->Log(LOG_ERROR, "CSettingsManager: Unknown settings type!");
                    break;
                  }
              }
              else
              {
                KODI->Log(LOG_ERROR, "CSettingsManager: Read settings element does not match the created settings element type!");
              }
            }
          }
        }
      }
    }
  }
}