X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2Futil%2FTemplateEngine.h;h=4a86c86f146cc163d5e2a8bd763488b2b6eae496;hb=a93d0241cb0fcbbd03ec671ec92ace2cd1519af9;hp=ad4027b9a24c59926a99ffdef5e6f05ec6fa06a1;hpb=358b99357f9a3e3b68aef61e8374a9d80d1c1a28;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/util/TemplateEngine.h b/xmltooling/util/TemplateEngine.h index ad4027b..4a86c86 100644 --- a/xmltooling/util/TemplateEngine.h +++ b/xmltooling/util/TemplateEngine.h @@ -1,29 +1,33 @@ -/* - * Copyright 2001-2007 Internet2 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at +/** + * Licensed to the University Corporation for Advanced Internet + * Development, Inc. (UCAID) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + * + * UCAID licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the + * License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. */ /** * @file xmltooling/util/TemplateEngine.h - * + * * Simple template replacement engine. */ #ifndef __xmltooling_template_h__ #define __xmltooling_template_h__ -#include +#include #include #include @@ -37,6 +41,8 @@ namespace xmltooling { + class XMLTOOL_API GenericRequest; + /** * Simple template replacement engine. Supports the following: *
    @@ -44,72 +50,68 @@ namespace xmltooling { *
  • <mlpif key> stuff </mlpif>
  • *
  • <mlpifnot key> stuff </mlpifnot>
  • *
  • <mlpfor key> stuff </mlpfor>
  • + *
  • <mlp $name/> (in for loop only)
  • + *
  • <mlp $value/> (in for loop only)
  • *
- * + * * The default tag prefix is "mlp". This can be overridden for * compatibility. */ class XMLTOOL_API TemplateEngine { - MAKE_NONCOPYABLE(TemplateEngine); + MAKE_NONCOPYABLE(TemplateEngine); public: - TemplateEngine() { - setTagPrefix("mlp"); - } + /** Default constructor. */ + TemplateEngine(); + + virtual ~TemplateEngine(); - virtual ~TemplateEngine() {} - /** * Sets the tag name to use when locating template replacement tags. - * + * * @param tagPrefix base prefix for tags */ void setTagPrefix(const char* tagPrefix); - + /** * Interface to parameters to plug into templates. * Allows callers to supply a more dynamic lookup mechanism to supplement a basic map. */ class XMLTOOL_API TemplateParameters { - // MAKE_NONCOPYABLE(TemplateParameters); public: - TemplateParameters() : m_request(NULL) {} - virtual ~TemplateParameters() {} - + TemplateParameters(); + virtual ~TemplateParameters(); + /** Map of known parameters to supply to template. */ std::map m_map; - std::map > m_collectionMap; - + + /** Map of sub-collections used in for loops. */ + std::map< std::string,std::multimap > m_collectionMap; + /** Request from client that resulted in template being processed. */ const GenericRequest* m_request; - + /** * Returns the value of a parameter to plug into the template. - * + * * @param name name of parameter - * @return value of parameter, or NULL + * @return value of parameter, or nullptr */ - virtual const char* getParameter(const char* name) const { - std::map::const_iterator i=m_map.find(name); - return (i!=m_map.end() ? i->second.c_str() : (m_request ? m_request->getParameter(name) : NULL)); - } + virtual const char* getParameter(const char* name) const; /** - * Returns the collection of parameters to plug into the template. - * - * @param name name of parameter collection - * @return vector of parameters + * Returns a named collection of sub-parameters to pass into a loop. + * + * @param name name of sub-collection + * @return pointer to a multimap of sub-parameters, or nullptr */ - virtual const std::vector getParameterCollection(const char* name) const { - std::map >::const_iterator i=m_collectionMap.find(name); - return (i->second); - } + virtual const std::multimap* getLoopCollection(const char* name) const; }; - + /** * Processes template from an input stream and executes replacements and - * conditional logic based on parameters. - * + * conditional logic based on parameters. + * * @param is input stream providing template * @param os output stream to send results of executing template * @param parameters parameters to plug into template @@ -119,7 +121,7 @@ namespace xmltooling { std::istream& is, std::ostream& os, const TemplateParameters& parameters, - const XMLToolingException* e=NULL + const XMLToolingException* e=nullptr ) const; /** @@ -129,7 +131,6 @@ namespace xmltooling { static std::string unsafe_chars; private: - void trimspace(std::string& s) const; void html_encode(std::ostream& os, const char* start) const; void process( bool visible, @@ -137,9 +138,10 @@ namespace xmltooling { const char*& lastpos, std::ostream& os, const TemplateParameters& parameters, + const std::pair& loopentry, const XMLToolingException* e ) const; - + std::string keytag,iftag,ifendtag,ifnottag,ifnotendtag,fortag,forendtag; }; };