最简单的方法是开发自己的tagconverter
. 一个简单的实现方法如下:
package com.acme.tagconverter;
import java.util.Properties;
import java.util.regex.Pattern;
import atg.droplet.TagAttributeDescriptor;
import atg.droplet.TagConversionException;
import atg.droplet.TagConverter;
import atg.droplet.TagConverterManager;
import atg.nucleus.GenericService;
import atg.nucleus.ServiceException;
import atg.servlet.DynamoHttpServletRequest;
public class StripHTMLConverter extends GenericService implements TagConverter {
private Pattern tagPattern;
@Override
public void doStartService() throws ServiceException {
TagConverterManager.registerTagConverter(this);
}
public String convertObjectToString(DynamoHttpServletRequest request, Object obj, Properties attributes) throws TagConversionException {
return tagPattern.matcher(obj.toString()).replaceAll("");
}
public Object convertStringToObject(DynamoHttpServletRequest request, String str, Properties attributes) throws TagConversionException {
return str;
}
public String getName() {
return "striphtml";
}
public TagAttributeDescriptor[] getTagAttributeDescriptors() {
return new TagAttributeDescriptor[0];
}
public void setTagPattern(String tagPattern) {
this.tagPattern = Pattern.compile(tagPattern);
}
public String getTagPattern() {
return tagPattern.pattern();
}
}
然后通过包含模式的组件属性文件引用它:
$class=com.acme.tagconverter.StripHTMLConverter
tagPattern=<[^>]+>
显然,这假设应该删除开始 '<' 和结束 '>' 之间的所有内容。您可以自己研究 RegEx 以找到更好的模式。
您还应该在 Initial.properties 中注册 TagConverter
$class=atg.nucleus.InitialService
$scope=global
initialServices+=\
/com/acme/tagconverter/StripHTMLConverter
现在您应该可以按照您的意愿使用它了。
var mydatawithouthtml = '<dsp:valueof param="product.data" converter="striphtml"/>'