Example #1
0
		void WebPageLinkFunction::_setFromParametersMap(const ParametersMap& map)
		{
			// Target
			string targetStr(map.get<string>(PARAMETER_TARGET));
			ParametersMap::Trim(targetStr);
			if(!targetStr.empty() && targetStr[0] >= '0' && targetStr[0] <= '9')
			{	// Page by ID
				try
				{
					RegistryKeyType pageId(lexical_cast<RegistryKeyType>(targetStr));
					_target = Env::GetOfficialEnv().get<Webpage>(pageId).get();
				}
				catch(bad_lexical_cast&)
				{
					throw RequestException("Bad cast in page id");
				}
				catch(ObjectNotFoundException<Webpage>&)
				{
					throw RequestException("No such web page");
				}
			}
			else
			{	// Page by smart URL
				_target = getSite()->getPageBySmartURL(targetStr);
				if(!_target)
				{
					throw RequestException("No such web page");
				}
			}

			
			optional<string> ot(map.getOptional<string>(PARAMETER_TEXT, false));
			_text = ot ? *ot : _target->getName();
			_useSmartURL = map.getDefault<bool>(PARAMETER_USE_SMART_URL, true);

			_confirm = map.getDefault<string>(PARAMETER_CONFIRM, string(), false);

			_title = map.getDefault<string>(PARAMETER_TITLE);

			// Class
			_class = map.getDefault<string>(PARAMETER_CLASS);

			// Additional parameters
			BOOST_FOREACH(const ParametersMap::Map::value_type& item, map.getMap())
			{
				if(item.first == PARAMETER_TEXT ||
					item.first == PARAMETER_TARGET ||
					item.first == PARAMETER_USE_SMART_URL ||
					item.first == PARAMETER_CONFIRM ||
					item.first == PARAMETER_TITLE ||
					item.first == PARAMETER_CLASS
				){
					continue;
				}

				// Using the getValue virtual method instead of item.second in order to handle DelayedEvaluationParametersMap
				_parameters.insert(item.first, map.getValue(item.first));
			}
		}