Java Map Replace replaceEntities(final Map replacements, final String xml)

Here you can find the source of replaceEntities(final Map replacements, final String xml)

Description

This function takes the Map generated by the calculateEntityReplacements function, and uses those values to replace any entities in the XML string with their unique random integer replacements.

License

GNU General Public License

Parameter

Parameter Description
replacements The Map generated by the calculateEntityReplacements function
xml The XML string to modify

Return

The modified XML

Declaration

private static String replaceEntities(final Map<String, String> replacements, final String xml) 

Method Source Code

//package com.java2s;

import java.util.Map;

public class Main {
    /**/*  ww  w . ja v a2 s  .c  om*/
     * This function takes the Map generated by the calculateEntityReplacements function, and uses those values to replace any entities in the XML string with
     * their unique random integer replacements. The end results is an XML string that contains no entities, but contains identifiable strings that can be used
     * to replace those entities at a later point.
     * 
     * @param replacements
     *            The Map generated by the calculateEntityReplacements function
     * @param xml
     *            The XML string to modify
     * @return The modified XML
     */
    private static String replaceEntities(final Map<String, String> replacements, final String xml) {
        String retValue = xml;
        for (final String entity : replacements.keySet())
            retValue = retValue.replaceAll("\\&" + entity + ";", replacements.get(entity));
        return retValue;
    }
}

Related

  1. replaceByMap(String _searchStr, Map _replacements)
  2. replaceByMap(String tpl, Map map)
  3. replaceCharacters(String sequence, Map map, boolean reverse)
  4. replaceCharactersInArray(char[] characters, Map replacements)
  5. replaceElements(Map destinationMap, Map sourceMap)
  6. replaceFromMap(final String string, final Map replacements)
  7. replaceFromMap(String string, Map replacements)
  8. replaceGlobalTokensFromMap(Map dataMap, String message)
  9. replaceInvalid(String uri, Map reps)