| package org.apache.struts2.components.template; |
| import java.util.Collections; |
| import java.util.HashMap; |
| import java.util.Map; |
| import java.util.Set; |
| import com.opensymphony.xwork2.config.ConfigurationException; |
| import com.opensymphony.xwork2.inject.Container; |
| import com.opensymphony.xwork2.inject.Inject; |
| public |
| class TemplateEngineManager |
| { |
| public static final |
| String DEFAULT_TEMPLATE_TYPE_CONFIG_KEY |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.DEFAULT_TEMPLATE_TYPE_CONFIG_KEY: Interval 0 : struts . ui . templateSuffix : struts . ui . templateSuffix |
| ="struts . ui . templateSuffix" |
| ; |
| public static final |
| String DEFAULT_TEMPLATE_TYPE |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.DEFAULT_TEMPLATE_TYPE: Interval 0 : ftl : ftl |
| ="ftl" |
| ; |
| Map<String ,EngineFactory > templateEngines |
| //QC Intervals :(Map<String,EngineFactory>) org.apache.struts2.components.template.TemplateEngineManager.templateEngines: Interval 0 : new : new |
| =new HashMap<String ,EngineFactory > () |
| ; |
| Container container |
| //QC Intervals :(Container) org.apache.struts2.components.template.TemplateEngineManager.container: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| ; |
| String defaultTemplateType |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.defaultTemplateType: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| ; |
| @ Inject (DEFAULT_TEMPLATE_TYPE_CONFIG_KEY)public |
| void setDefaultTemplateType |
| ( |
| String type |
| ) |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.setDefaultTemplateType.type: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| { |
| this.defaultTemplateType=type; |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.defaultTemplateType: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| //assignation |
| } |
| @ Inject public |
| void setContainer |
| ( |
| Container container |
| ) |
| //QC Intervals :(Container) org.apache.struts2.components.template.TemplateEngineManager.setContainer.container: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| { |
| this.container=container; |
| //QC Intervals :(Container) org.apache.struts2.components.template.TemplateEngineManager.container: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| //assignation |
| Map<String ,EngineFactory > map=new HashMap<String ,EngineFactory > () |
| //QC Intervals :(Map<String,EngineFactory>) org.apache.struts2.components.template.TemplateEngineManager.setContainer.map: Interval 0 : new : new |
| ; |
| Set<String > prefixes=container.getInstanceNames(TemplateEngine.class ) |
| //QC-CWE476 or QCerrorNPE null pointer reference on container (see http://cwe.mitre.org/data/definitions/476.html) |
| //QC Intervals :(Set<String>) org.apache.struts2.components.template.TemplateEngineManager.setContainer.prefixes: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| ; |
| for ( |
| String prefix |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.setContainer.prefix: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| :prefixes |
| ) |
| { |
| map.put(prefix,new LazyEngineFactory(prefix)); |
| //QC Intervals : (Object) javax.swing.ActionMap.put1 : Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| //QC Intervals : (Action) javax.swing.ActionMap.put2 : Interval 0 : new : new |
| //type of the function/method : void |
| } |
| this.templateEngines=Collections.unmodifiableMap(map); |
| //QC Intervals : (Map) org.apache.struts2.components.template.TemplateEngineManager.templateEngines: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| //assignation |
| } |
| public |
| void registerTemplateEngine |
| ( |
| String templateExtension |
| , |
| final TemplateEngine templateEngine |
| ) |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.registerTemplateEngine.templateExtension: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| //QC Intervals :(TemplateEngine) org.apache.struts2.components.template.TemplateEngineManager.registerTemplateEngine.templateEngine: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| { |
| templateEngines.put(templateExtension,new EngineFactory(){public TemplateEngine create(){return templateEngine;}}); |
| //QC Intervals :(TemplateEngine) org.apache.struts2.components.template.TemplateEngineManager.registerTemplateEngine.create: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| //QC Intervals : (Object) javax.swing.ActionMap.put1 : Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| //QC Intervals : (Action) javax.swing.ActionMap.put2 : Interval 0 : new : new |
| { |
| public |
| TemplateEngine create |
| //QC Intervals :(TemplateEngine) org.apache.struts2.components.template.TemplateEngineManager.registerTemplateEngine.create: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| ( |
| ) |
| { |
| return templateEngine; |
| //QC Intervals : (boolean) org.apache.struts2.components.template.TemplateEngineManager.registerTemplateEngine.registerTemplateEngine.return: Interval 0 : false : false |
| //QC : Interval 1 : false : false |
| } |
| } |
| //type of the function/method : void |
| } |
| public |
| TemplateEngine getTemplateEngine |
| //QC Intervals :(TemplateEngine) org.apache.struts2.components.template.TemplateEngineManager.getTemplateEngine: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| ( |
| Template template |
| , |
| String templateTypeOverride |
| ) |
| //QC Intervals :(Template) org.apache.struts2.components.template.TemplateEngineManager.getTemplateEngine.template: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.getTemplateEngine.templateTypeOverride: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| { |
| String templateType=DEFAULT_TEMPLATE_TYPE |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.getTemplateEngine.templateType: Interval 0 : ftl : ftl |
| //QC : Interval 1 : new : new |
| ; |
| String templateName=template.toString() |
| //QC-CWE476 or QCerrorNPE null pointer reference on template (see http://cwe.mitre.org/data/definitions/476.html) |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.getTemplateEngine.templateName: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| ; |
| if (templateName.indexOf(" . ")> 0) |
| //QC Intervals : (char) java.lang.String.indexOf1 : Interval 0 : . : . |
| //QC-CWE476 or QCerrorNPE null pointer reference on templateName (see http://cwe.mitre.org/data/definitions/476.html) |
| //QC Intervals : (int) java.lang.String.indexOf : Interval 0 : 1 : 2147483647 |
| { |
| templateType=templateName.substring(templateName.indexOf(" . ")+1); |
| //QC-CWE476 or QCerrorNPE null pointer reference on templateName (see http://cwe.mitre.org/data/definitions/476.html) |
| //QC-CWE190 and QCerrorOVF attention overflow + on java.lang.String.indexOf (1,2147483647) and varlocaleb34 (1,1) = 2147483648 |
| //QC-CWE190 and QCerrorOVF attention overflow + on java.lang.String.indexOf (1,2147483647) and varlocaleb38 (1,1) = 2147483648 |
| //QC Intervals : (int) java.lang.String.substring1 : Interval 0 : 2 : 2147483647 |
| //QC-CWE476 or QCerrorNPE null pointer reference on templateName (see http://cwe.mitre.org/data/definitions/476.html) |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.getTemplateEngine.templateType: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| //assignation |
| } |
| else |
| //QC-CWE476 or QCerrorNPE null pointer reference on templateName (see http://cwe.mitre.org/data/definitions/476.html) |
| //QC Intervals : (int) java.lang.String.indexOf : Interval 0 : -2147483647 : -1 |
| //QC : Interval 1 : 0 : 0 |
| if ((templateTypeOverride!=null )&&(templateTypeOverride.length()> 0)) |
| //QC-CWE476 or QCerrorNPE null pointer reference on templateTypeOverride (see http://cwe.mitre.org/data/definitions/476.html) |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.getTemplateEngine.templateTypeOverride: Interval 0 : new : new |
| //QC Intervals : (int) java.lang.String.length : Interval 0 : 1 : 2147483647 |
| { |
| templateType=templateTypeOverride; |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.getTemplateEngine.templateType: Interval 0 : new : new |
| //assignation |
| } |
| else |
| //QC-CWE476 or QCerrorNPE null pointer reference on templateTypeOverride (see http://cwe.mitre.org/data/definitions/476.html) |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.getTemplateEngine.templateTypeOverride: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| //QC Intervals : (int) java.lang.String.length : Interval 0 : -2147483647 : -1 |
| //QC : Interval 1 : 0 : 0 |
| //QC : Interval 2 : 1 : 2147483647 |
| { |
| String type=defaultTemplateType |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.getTemplateEngine.type: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| ; |
| if (type!=null ) |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.getTemplateEngine.type: Interval 0 : new : new |
| { |
| templateType=type; |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.getTemplateEngine.templateType: Interval 0 : new : new |
| //assignation |
| } |
| } |
| return templateEngines.get(templateType).create(); |
| //QC Intervals : (int) javax.swing.DebugGraphics.create1 : Interval 0 : ftl : ftl |
| //QC : Interval 1 : new : new |
| //QC Intervals :(TemplateEngine) org.apache.struts2.components.template.TemplateEngineManager.getTemplateEngine.return: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| } |
| interface EngineFactory |
| { |
| public |
| TemplateEngine create |
| //QC Intervals :(TemplateEngine) org.apache.struts2.components.template.TemplateEngineManager.EngineFactory.create: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| ( |
| ) |
| ; |
| } |
| class LazyEngineFactory |
| implements EngineFactory |
| { |
| private |
| String name |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.LazyEngineFactory.name: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| ; |
| public |
| LazyEngineFactory |
| ( |
| String name |
| ) |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.LazyEngineFactory.LazyEngineFactory.name: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| { |
| this.name=name; |
| //QC Intervals : (String) org.apache.struts2.components.template.TemplateEngineManager.LazyEngineFactory.name: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| //assignation |
| } |
| public |
| TemplateEngine create |
| //QC Intervals :(TemplateEngine) org.apache.struts2.components.template.TemplateEngineManager.LazyEngineFactory.create: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| ( |
| ) |
| { |
| TemplateEngine engine=container.getInstance(TemplateEngine.class ,name) |
| //QC Intervals :(TemplateEngine) org.apache.struts2.components.template.TemplateEngineManager.LazyEngineFactory.create.engine: Interval 0 : null : null |
| //QC : Interval 1 : new : new |
| ; |
| if (engine==null ) |
| //QC Intervals :(TemplateEngine) org.apache.struts2.components.template.TemplateEngineManager.LazyEngineFactory.create.engine: Interval 0 : null : null |
| { |
| throw new ConfigurationException("Unable to locate template engine : "+name); |
| } |
| //QC Intervals :(TemplateEngine) org.apache.struts2.components.template.TemplateEngineManager.LazyEngineFactory.create.engine: Interval 0 : new : new |
| return engine; |
| //QC Intervals :(TemplateEngine) org.apache.struts2.components.template.TemplateEngineManager.LazyEngineFactory.create.return: Interval 0 : new : new |
| } |
| } |
| } |