All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.gwt.resources.gss.RenamingSubstitutionMap Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2014 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.resources.gss;

import com.google.gwt.thirdparty.common.css.SubstitutionMap;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 * This SubstitutionMap is used for renaming each style classes of the ast by its corresponding
 * obfuscated name.
 * 

* It takes care of eventual prefix and does not rename external style classes. *

* It lists the eventual external style class candidates (class without associated obfuscation * name) */ public class RenamingSubstitutionMap implements SubstitutionMap { private final Map replacementMap; private Set classes; private Set externalClassCandidates; public RenamingSubstitutionMap(Map> replacementsWithPrefix) { this.replacementMap = computeReplacementMap(replacementsWithPrefix); classes = new HashSet(); externalClassCandidates = new HashSet(); } private Map computeReplacementMap( Map> replacementsWithPrefix) { Map result = new HashMap(); for (Entry> entry : replacementsWithPrefix.entrySet()) { final String prefix = entry.getKey(); Map replacement = new HashMap(); for (Entry replacementEntry : entry.getValue().entrySet()) { replacement.put(prefix + replacementEntry.getKey(), replacementEntry.getValue()); } result.putAll(replacement); } return result; } @Override public String get(String key) { classes.add(key); String replacement = replacementMap.get(key); if (replacement == null) { // could be an external style class externalClassCandidates.add(key); return key; } return replacement; } public Set getStyleClasses() { return classes; } public Set getExternalClassCandidates() { return externalClassCandidates; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy