Java HTML Jsoup Document applyCacheKeysToResourceUrls(Document document, long pluginModifiedTimestamp, Locale locale)

Here you can find the source of applyCacheKeysToResourceUrls(Document document, long pluginModifiedTimestamp, Locale locale)

Description

apply Cache Keys To Resource Urls

License

Open Source License

Declaration

public static void applyCacheKeysToResourceUrls(Document document, long pluginModifiedTimestamp,
            Locale locale) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.util.Locale;

public class Main {
    public static void applyCacheKeysToResourceUrls(Document document, long pluginModifiedTimestamp,
            Locale locale) {//from   www  .ja va 2  s  .c o m
        String cacheKey = getCacheKeyPathSegments(pluginModifiedTimestamp, locale);

        Elements injectedScripts = document.select("script[data-spark-injected]");
        for (Element script : injectedScripts) {
            script.attr("src", cacheKey + "/" + script.attr("src"));
        }

        Elements injectedStyles = document.select("link[data-spark-injected]");
        for (Element style : injectedStyles) {
            style.attr("href", cacheKey + "/" + style.attr("href"));
        }
    }

    private static String getCacheKeyPathSegments(long pluginModifiedTimestamp, Locale locale) {
        return "_/" + pluginModifiedTimestamp + "/" + locale.toString();
    }
}

Related

  1. convertLinksToAbsolute(String link, org.jsoup.nodes.Document doc)
  2. detectLanguage(Document doc)
  3. emptyDocument()
  4. formatDocument(Document doc)