/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF 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 * * 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. */ package org.apache.jasper.tagplugins.jstl.core; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.jasper.Constants; import org.apache.jasper.compiler.tagplugin.TagPluginContext; /** * Simple TagPluginContext implementation for test purpose * * @author Sheldon Shao (XShao@ebay.com) */ public class SimpleTagPluginContext implements TagPluginContext { private boolean scriptless = false; private HashMap attributes = new HashMap(); private boolean dontUseTagPlugin = false; private boolean isTagFile = false; private HashMap pluginAttributes = new HashMap(); private TagPluginContext parentContext; private List imports = new ArrayList(4); private Map declarations = new HashMap(); private String body = ""; /* * Sequence number for temporary variables. */ private int tempSequenceNumber = 0; /** * Script let code */ private StringBuilder code = new StringBuilder(); @Override public boolean isScriptless() { return scriptless; } @Override public boolean isAttributeSpecified(String attribute) { return attributes.containsKey(attribute); } @Override public String getTemporaryVariableName() { return Constants.TEMP_VARIABLE_NAME_PREFIX + (tempSequenceNumber++); } @Override public void generateImport(String s) { imports.add(s); } @Override public void generateDeclaration(String id, String text) { declarations.put(id, text); } @Override public void generateJavaSource(String s) { code.append(s); } @Override public boolean isConstantAttribute(String attribute) { return attributes.containsKey(attribute); } @Override public String getConstantAttribute(String attribute) { return attributes.get(attribute); } @Override public void generateAttribute(String attribute) { code.append(attributes.get(attribute)); } @Override public void generateBody() { code.append(body); } @Override public void dontUseTagPlugin() { dontUseTagPlugin = true; } @Override public TagPluginContext getParentContext() { return parentContext; } @Override public void setPluginAttribute(String key, Object value) { pluginAttributes.put(key, value); } @Override public Object getPluginAttribute(String key) { return pluginAttributes.get(key); } @Override public boolean isTagFile() { return isTagFile; } public void setTagFile(boolean isTagFile) { this.isTagFile = isTagFile; } /** * Return the status of "dontUseTagPlugin" * * @return the status of "dontUseTagPlugin" */ public boolean isDontUseTagPlugin() { return dontUseTagPlugin; } /** * Return all imports added by tagPlugins */ public List getImports() { return imports; } public void setBody(String body) { this.body = body; } public String getBody() { return body; } /** * Add attribute * * @param attribute * Attribute Name * @param value * Value */ public void addAttribute(String attribute, String value) { attributes.put(attribute, value); } public String getCode() { return code.toString(); } }