Exemple #1
0
KSHOWWNDNODE* KUiShowWndTree::AddNodeByName(IIniFile *pIni, const char *pszName)
{
    KSHOWWNDNODE* pResult = NULL;
    KG_PROCESS_ERROR(pIni);
    KG_PROCESS_ERROR(pszName && pszName[0]);
    KG_PROCESS_ERROR(strcmp(pszName, m_Root.szName));

    pResult = IsNodeExist(pszName);
    if (pResult) 
    {
        KG_PROCESS_ERROR(0);
    }

    char szParentName[128] = "";
    pIni->GetString(pszName, "._Parent", "", szParentName, sizeof(szParentName));

    KSHOWWNDNODE *pParentNode = IsNodeExist(szParentName);
    if (!pParentNode)
    {
        pParentNode = AddNodeByName(pIni, szParentName);
        KG_PROCESS_ERROR(pParentNode);
    }

    KSHOWWNDNODE *pNode = new KSHOWWNDNODE;
    ZeroMemory(pNode, sizeof(KSHOWWNDNODE));
    strcpy(pNode->szName, pszName);
    strcpy(pNode->szParentName, szParentName);
    AddChild(pParentNode, pNode);

    pResult= pNode;
Exit0:
    return pResult;
}
Exemple #2
0
/**
\todo Set functions of XmlUtility depend on DOMParserSTL::Set functions.
 Calling DomParserSTL::SetXXXX() followed by GetXXXXX() doesn't show the updated value.
*/
int CIdXmlUtility::SetValue(string strElementPath,string strValue,bool bCreate)
{
	m_strElementPath = strElementPath;

	if( !IsNodeExist(m_strElementPath)  ) //if the strelementpath doesn't exist
	{
		if( bCreate == false ) //path is REQUIRED, return error
			return 0;
		else
		{
			//create the strelementpath
			m_domParser->ResetPos();//set current element of parser to root
			stringCollection_t nodes = getNodes(strElementPath);//Get the element names in descending order from root
			cerr<<"Current Node:"<<m_domParser->GetTagName()<<endl;
			//case 1:
			//		Leaf element is missing
			//case 2:
			//		Internal element is missing

			m_domParser->ResetPos();//set current element of parser to root
			strCollIter_t i=nodes.begin();	//skip the root node (ie Settings node)
			i++;
			for(; i != nodes.end(); i++)
            {
				string nodeName = *i;
				#if defined(WIN32) && !defined(__CYGWIN__)
					g_tLog.WriteLog("Current Node:%s", m_domParser->GetTagName());
				#else
					g_tLog.WriteLog("Current Node:%s", m_domParser->GetTagName().c_str());
				#endif

				g_tLog.WriteLog("Looking for child node:%s", nodeName.c_str());
				if( !m_domParser->FindChildElem(i->c_str()) )
					m_domParser->AddChildElem( i->c_str() );  //if not found child, create

                m_domParser->IntoElem();//goes inside that element
            }

		}
	}

	//Set the value for the newly created path and if the strelementpath exists then also it sets the value
	m_domParser->SetData(strValue.c_str(),0);
	m_domParser->Save(m_strXmlFilePath.c_str());
	return 1;
}
Exemple #3
0
/**
\todo Set functions of XmlUtility depend on DOMParserSTL::Set functions.
 Calling DomParserSTL::SetXXXX() followed by GetXXXXX() doesn't show the updated value.
*/
int CIdXmlUtility::SetAttrValue(string strElementPath,string strAttrName,string strValue,bool bCreate)
{
	m_strElementPath = strElementPath;
	if(!IsNodeExist(m_strElementPath))  //if the strelementpath doesn't exist
    {
		if(bCreate == false)
		{
		   return 0;
		}
		else  //create the strelementpath
		{
			//Step 1) create the element path
		    stringCollection_t nodes = getNodes(strElementPath);

			//Step 2) create the attribute
			//Step 3) set the attribute value
			m_domParser->ResetPos();//set current element of parser to root
			strCollIter_t i=nodes.begin();	//skip the root node (ie Settings node)
			i++;
			for( ; i != nodes.end(); i++ )
            {
                string nodeName = *i;
				g_tLog.WriteLog("Looking for child node:%s", nodeName.c_str());

				if( !m_domParser->FindChildElem(i->c_str()) )	//if not found child element, create
					m_domParser->AddChildElem( i->c_str() );

                m_domParser->IntoElem();//goes inside that element
            }

		}
	}

   // case 1: Attribute exists then set the value
	// case 1.1:
	//		attrib="abcd"
	// case 1.2:
	//		attrib=""
	//SOLUTION1: SetAttrib() will set the value if any OR create any missing attribute
	if( bCreate == true )
	{
		m_domParser->SetAttrib(strAttrName.c_str(),strValue.c_str());
		m_domParser->Save(m_strXmlFilePath.c_str());
		return 1;
	}
	else
	{
    //DONE: As SetAttrib default behaviour creates any missing attributes]
   // case 2: Attribute missing
   //		   case 2.1: bCreate is true then
   //		   case 2.2: bCreate is false then return error
   // SOLUTION2:
	//		if (bCreate == false && !found)
	//			return error
	//		else if( bCreate == true && found)
	//			use SetAttrib to create the attribute and set the value

		// Details: Check if Attrib exists
		int i=0;
		bool found = false;
		string tmpAttrbName;
		while(1)
		{
			tmpAttrbName = m_domParser->GetAttribName(i++);
			if( tmpAttrbName == "" )
				break;
			if( strAttrName == tmpAttrbName )
				found = true;
		}
		 if( found )
		{
			m_domParser->SetAttrib(strAttrName.c_str(),strValue.c_str());
			return 1;
		}
		else
		{
			//attrib not found return error
			return 0;
		}
	}
}