--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
+ <implementation class="org.argeo.publishing.servlet.FontsServlet"/>
+ <service>
+ <provide interface="javax.servlet.Servlet"/>
+ </service>
+ <property name="osgi.http.whiteboard.servlet.pattern" type="String" value="/fonts/*"/>
+ <property name="osgi.http.whiteboard.context.select" type="String" value="(osgi.http.whiteboard.context.name=default)"/>
+ <reference bind="addTheme" cardinality="0..n" interface="org.argeo.cms.ui.CmsTheme" name="CmsTheme" policy="dynamic" unbind="removeTheme"/>
+</scr:component>
--- /dev/null
+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<String, CmsTheme> 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<String, String> properties) {
+ themes.put(theme.getThemeId(), theme);
+ }
+
+ public void removeTheme(CmsTheme theme, Map<String, String> properties) {
+ themes.remove(theme.getThemeId());
+ }
+
+}