これを行う最も簡単な方法は、独自の を開発すること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=<[^>]+>
明らかに、これは、開始の '<' と終了の '>' の間のすべてを削除する必要があることを前提としています。自分で正規表現に取り組み、より良いパターンを見つけることができます。
また、Initial.properties に TagConverter を登録する必要があります。
$class=atg.nucleus.InitialService
$scope=global
initialServices+=\
/com/acme/tagconverter/StripHTMLConverter
これで、意図したとおりに使用できるはずです。
var mydatawithouthtml = '<dsp:valueof param="product.data" converter="striphtml"/>'