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

cn.asens.util.CountUtils Maven / Gradle / Ivy

package cn.asens.util;

import java.util.Map;

/**
 * @author Asens
 */

public class CountUtils {

    public static Map makeUrlMap() {
        try {
            return PropertyUtils.getConfigMap(Thread.currentThread()
                    .getContextClassLoader()
                    .getResourceAsStream("config/urlmap.ini"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String parseReferer(String referer,Map urlMap) {
        if(referer==null){
            return null;
        }
        String refererName=referer;
        String protocol=referer.startsWith("https")?"https":"http";
        if(!"".equals(refererName)){
            referer=referer.substring(referer.indexOf(protocol)+protocol.length()+3);
            referer=referer.substring(referer.indexOf("/"));
            if(referer.contains("?")) {
                referer = referer.substring(0, referer.lastIndexOf("?"));
            }
            refererName=parseUri(referer,urlMap);
            if(refererName==null||"".equals(refererName)){
                refererName=referer;
            }
        }
        return refererName;
    }



    public static String parseUri(String uri,Map urlMap) {
        for(Map.Entry entry:urlMap.entrySet()){
            String key=entry.getKey();
            if(uri.equals(key)){
                return entry.getValue();
            }
        }
        for(Map.Entry entry:urlMap.entrySet()){
            String key=entry.getKey();
            if(uri.matches(key)){
                return entry.getValue();
            }
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy