Uploaded image for project: 'Commons Text'
  1. Commons Text
  2. TEXT-229

Add XmlEncoderStringLookup/XmlDecoderStringLookup

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.10.0
    • 1.11.0
    • None

    Description

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

      A quick hack works for me:

      	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}}"));
      	}
      
      bar, &lt;foo bar=&apos;sdfsf&apos; /&gt; &lt;password&gt;
      

      Attachments

        Issue Links

          Activity

            People

              ggregory Gary D. Gregory
              michael-o Michael Osipov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: