0

「valueishtml」プロパティを true に設定した atg dsp:valueof タグを使用してデータを取得しています。取得したこのデータを html タグなしで EL 経由で json 変数に渡す必要があります。誰かがこれを行う方法を教えてもらえますか? . 以下は、私が行う必要があることの例です。これはコードではないことに注意してください。

var mydatawithouthtml = <dsp:valueof param="product.data" valueishtml="true"/>

<json:property name="data" value="${mydatawithouthtml}" />

現在、「product.data」には、json に渡される html タグが含まれています。html タグのない json データが必要です。

ティア

4

1 に答える 1

0

これを行う最も簡単な方法は、独自の を開発すること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"/>'
于 2016-01-07T06:20:26.640 に答える