2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * TemplateParameters.cpp
20 * Supplies xmltooling TemplateEngine with additional parameters from a PropertySet.
24 #include "util/TemplateParameters.h"
27 #include <xmltooling/XMLToolingConfig.h>
28 #include <xmltooling/util/URLEncoder.h>
30 using namespace shibsp;
31 using namespace xmltooling;
34 void TemplateParameters::setPropertySet(const PropertySet* props)
38 // Create a timestamp.
39 time_t now = time(NULL);
42 m_map["now"] = ctime_r(&now,timebuf,sizeof(timebuf));
44 m_map["now"] = ctime(&now);
48 const char* TemplateParameters::getParameter(const char* name) const
51 if (!strcmp(name, "errorType"))
52 return m_toolingException ? m_toolingException->getClassName() : "std::exception";
53 else if (!strcmp(name, "errorText"))
54 return m_exception->what();
57 const char* pch = TemplateEngine::TemplateParameters::getParameter(name);
60 pair<bool,const char*> p = m_props->getString(name);
61 return p.first ? p.second : NULL;
64 string TemplateParameters::toQueryString() const
66 // Capture local stuff.
69 const URLEncoder* enc = XMLToolingConfig::getConfig().getURLEncoder();
70 for (map<string,string>::const_iterator i=m_map.begin(); i!=m_map.end(); i++)
71 q = q + '&' + i->first + '=' + enc->encode(i->second.c_str());
73 // Add in the exception content.
75 q = q + "&errorType=" + enc->encode(getParameter("errorType")) + "&errorText=" + enc->encode(getParameter("errorText"));
76 if (m_toolingException)
77 q = q + '&' + m_toolingException->toQueryString();