Example #1
0
WebNode* Folder::GetPage(const string& pageName) const
{
	const size_t slashInd = pageName.find_first_of('/', 1);
	
	if(slashInd != string::npos)
	{
		const size_t endInd = pageName.length() - slashInd;
		string localName = string(pageName, 1, slashInd - 1);
		const string remainingName = string(pageName, slashInd, endInd);
		Util::to_upper(localName);
		auto potentialPage =  this->pages.find(localName);
		if(potentialPage != this->pages.end())
		{
			switch (potentialPage->second->GetNodeType())
			{
			case FOLDER:
				Folder* nextFolder = static_cast<Folder*>(potentialPage->second);
				WebNode* nextNode = nextFolder->GetPage(remainingName);
				return nextNode;
				break;
			}
		}
		
		//log.error(pageName + " not found in directory " + this->fullPath);
	}
	else
	{
		if(pageName[0] != '/')
		{
			string pageN = pageName;
			Util::to_upper(pageN);
			auto potentialPage =  this->pages.find(pageN);
			if(potentialPage != this->pages.end())
			{
				return potentialPage->second;
			}
		}
		else
		{
			string pageN(pageName, 1, pageName.length() - 1);
			Util::to_upper(pageN);
			auto potentialPage =  this->pages.find(pageN);
			if(potentialPage != this->pages.end())
			{
				return potentialPage->second;
			}
		}

		log.error(pageName + " not found in directory " + this->fullPath);
	}
	
	return nullptr;
}