Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private static final String SENSITIVE_REGEX = "(^.*<(?:[^:]+:)?%s(?:\\s[^>]*)?>).*(<\\/(?:[^:]+:)?%s\\s*>.*$)";

    /**
     * Creates a map of tag name to clean header XML by running a substitution
     * regex on each entry of tag to dirty header XML.
     *
     * @param dirtyXmlMap a map of tag name to dirty header XML
     * @return a map of tag name to clean header XML
     */
    private static Map<String, String> createTagToCleanXmlMap(Map<String, String> dirtyXmlMap) {
        Map<String, String> cleanXmlMap = new HashMap<String, String>();
        for (Entry<String, String> sensitiveXml : dirtyXmlMap.entrySet()) {
            Pattern p = Pattern.compile(
                    String.format(SENSITIVE_REGEX, sensitiveXml.getKey(), sensitiveXml.getKey()),
                    Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
            Matcher m = p.matcher(sensitiveXml.getValue());
            if (m.matches()) {
                cleanXmlMap.put(sensitiveXml.getKey(), m.replaceFirst("$1******$2"));
            }
        }
        return cleanXmlMap;
    }
}