X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.publishing.ui%2Fsrc%2Forg%2Fargeo%2Fpublishing%2Fservlet%2FFontsServlet.java;fp=org.argeo.publishing.ui%2Fsrc%2Forg%2Fargeo%2Fpublishing%2Fservlet%2FFontsServlet.java;h=5bc6d0cc642d1536c55a235a810314bff151624d;hb=3440f51df3e4c015972c7b6a0efb3ce16188b89b;hp=0000000000000000000000000000000000000000;hpb=752a7b2614895002a3d184be166ef4162caf0d05;p=gpl%2Fargeo-suite.git diff --git a/org.argeo.publishing.ui/src/org/argeo/publishing/servlet/FontsServlet.java b/org.argeo.publishing.ui/src/org/argeo/publishing/servlet/FontsServlet.java new file mode 100644 index 0000000..5bc6d0c --- /dev/null +++ b/org.argeo.publishing.ui/src/org/argeo/publishing/servlet/FontsServlet.java @@ -0,0 +1,51 @@ +package org.argeo.publishing.servlet; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.IOUtils; +import org.argeo.cms.ui.CmsTheme; + +/** Serves fonts locally. */ +public class FontsServlet extends HttpServlet { + private static final long serialVersionUID = 6009572962850708537L; + private Map themes = Collections.synchronizedMap(new HashMap<>()); + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String font = req.getPathInfo(); + font = font.substring(1, font.length()); + for (CmsTheme theme : themes.values()) { + for (String fontPath : theme.getFontsPaths()) { + if (fontPath.endsWith(font)) { + if (font.endsWith(".woff")) + resp.setContentType("font/woff"); + else if (font.endsWith(".woff2")) + resp.setContentType("font/woff2"); + try (InputStream in = theme.loadPath(fontPath)) { + IOUtils.copy(in, resp.getOutputStream()); + return; + } + } + } + } + resp.setStatus(404); + } + + public void addTheme(CmsTheme theme, Map properties) { + themes.put(theme.getThemeId(), theme); + } + + public void removeTheme(CmsTheme theme, Map properties) { + themes.remove(theme.getThemeId()); + } + +}