2 * Copyright 2001-2006 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 * @file xmltooling/util/TemplateEngine.h
20 * Simple template replacement engine.
23 #ifndef __xmltooling_template_h__
24 #define __xmltooling_template_h__
26 #include <xmltooling/base.h>
32 namespace xmltooling {
35 * Simple template replacement engine. Supports the following:
37 * <li> <mlp key/> </li>
38 * <li> <mlpif key> stuff </mlpif></li>
39 * <li> <mlpifnot key> stuff </mlpifnot></li>
42 * The default tag prefix is "mlp". This can be overridden for
45 class XMLTOOL_API TemplateEngine
47 MAKE_NONCOPYABLE(TemplateEngine);
54 virtual ~TemplateEngine() {}
57 * Sets the tag name to use when locating template replacement tags.
59 * @param tagPrefix base prefix for tags
61 void setTagPrefix(const char* tagPrefix);
64 * Processes template from an input stream and executes replacements and
65 * conditional logic based on parameters.
67 * @param is input stream providing template
68 * @param os output stream to send results of executing template
69 * @param parameters name/value parameters to plug into template
70 * @param e optional exception to extract parameters from
75 const std::map<std::string,std::string>& parameters,
76 const XMLToolingException* e=NULL
80 void trimspace(std::string& s) const;
81 void html_encode(std::ostream& os, const char* start) const;
84 const std::string& buf,
87 const std::map<std::string,std::string>& parameters,
88 const XMLToolingException* e
91 std::string keytag,iftag,ifendtag,ifnottag,ifnotendtag;
95 #endif /* __xmltooling_template_h__ */