com.liferay.taglib.util.AttributesTagSupport Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.taglib.util;
import com.liferay.petra.string.StringPool;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.tagext.DynamicAttributes;
/**
* @author Eduardo Lundgren
* @author Shuyang Zhou
*/
public class AttributesTagSupport
extends ParamAndPropertyAncestorTagImpl implements DynamicAttributes {
public void clearDynamicAttributes() {
_dynamicAttributes.clear();
}
public String getAttributeNamespace() {
return _attributeNamespace;
}
/**
* @deprecated As of Judson (7.1.x), with no direct replacement
*/
@Deprecated
public Map getScopedAttributes() {
return Collections.emptyMap();
}
@Override
public void release() {
super.release();
_attributeNamespace = null;
_dynamicAttributes = null;
}
public void setAttributeNamespace(String attributeNamespace) {
_attributeNamespace = attributeNamespace;
}
@Override
public void setDynamicAttribute(
String uri, String localName, Object value) {
_dynamicAttributes.put(localName, value);
}
public void setNamespacedAttribute(
HttpServletRequest request, String key, Object value) {
if (value instanceof Boolean) {
value = String.valueOf(value);
}
else if (value instanceof Number) {
value = String.valueOf(value);
}
request.setAttribute(_encodeKey(key), value);
}
/**
* @deprecated As of Judson (7.1.x), with no direct replacement
*/
@Deprecated
public void setScopedAttribute(String name, Object value) {
}
protected Map getDynamicAttributes() {
return _dynamicAttributes;
}
private String _encodeKey(String key) {
if (_attributeNamespace.length() == 0) {
return key;
}
return _attributeNamespace.concat(key);
}
private String _attributeNamespace = StringPool.BLANK;
private Map _dynamicAttributes = new HashMap<>();
}