You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Michael Osipov (Jira)" <ji...@apache.org> on 2023/08/15 08:36:00 UTC

[jira] [Created] (TEXT-229) Add XmlEncoderStringLookup/XmlDecoderStringLookup

Michael Osipov created TEXT-229:
-----------------------------------

             Summary: Add XmlEncoderStringLookup/XmlDecoderStringLookup
                 Key: TEXT-229
                 URL: https://issues.apache.org/jira/browse/TEXT-229
             Project: Commons Text
          Issue Type: New Feature
    Affects Versions: 1.10.0
            Reporter: Michael Osipov


While we have URL encoder and decoder it'd be helpful to have builtin {{XmlEncoderStringLookup}} and {{XmlDecoderStringLookup}}.

A quick hack works for me:
{code:java}
	public static void main(String[] args) {
		Map<String, StringLookup> lookups = new HashMap<>();
		lookups.put("xmlEncoder", XmlEncoderStringLookup.INSTANCE);
		Map<String, String> vars = new HashMap<>();
		vars.put("foo", "bar");
		vars.put("baz", "<password>");
		StringLookupFactory factory = StringLookupFactory.INSTANCE;
		StringLookup interpolatorStringLookup = factory.interpolatorStringLookup(lookups, factory.mapStringLookup(vars), false);
		StringSubstitutor sub = new StringSubstitutor(interpolatorStringLookup);
		sub.setEnableSubstitutionInVariables(true);

		System.out.println(sub.replace("${foo}, ${xmlEncoder:<foo bar='sdfsf' />} ${xmlEncoder:${baz}}"));
	}
{code}
{noformat}
bar, &lt;foo bar=&apos;sdfsf&apos; /&gt; &lt;password&gt;
{noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)