]>
git.argeo.org Git - gpl/argeo-suite.git/blob - publishing/org.argeo.publishing.ui/src/org/argeo/publishing/servlet/FontsServlet.java
1 package org
.argeo
.publishing
.servlet
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
5 import java
.util
.Collections
;
6 import java
.util
.HashMap
;
9 import javax
.servlet
.ServletException
;
10 import javax
.servlet
.http
.HttpServlet
;
11 import javax
.servlet
.http
.HttpServletRequest
;
12 import javax
.servlet
.http
.HttpServletResponse
;
14 import org
.apache
.commons
.io
.IOUtils
;
15 import org
.argeo
.cms
.ui
.CmsTheme
;
17 /** Serves fonts locally. */
18 public class FontsServlet
extends HttpServlet
{
19 private static final long serialVersionUID
= 6009572962850708537L;
20 private Map
<String
, CmsTheme
> themes
= Collections
.synchronizedMap(new HashMap
<>());
23 protected void doGet(HttpServletRequest req
, HttpServletResponse resp
) throws ServletException
, IOException
{
24 String font
= req
.getPathInfo();
25 font
= font
.substring(1, font
.length());
26 for (CmsTheme theme
: themes
.values()) {
27 for (String fontPath
: theme
.getFontsPaths()) {
28 if (fontPath
.endsWith(font
)) {
29 if (font
.endsWith(".woff"))
30 resp
.setContentType("font/woff");
31 else if (font
.endsWith(".woff2"))
32 resp
.setContentType("font/woff2");
33 try (InputStream in
= theme
.loadPath(fontPath
)) {
34 IOUtils
.copy(in
, resp
.getOutputStream());
43 public void addTheme(CmsTheme theme
, Map
<String
, String
> properties
) {
44 themes
.put(theme
.getThemeId(), theme
);
47 public void removeTheme(CmsTheme theme
, Map
<String
, String
> properties
) {
48 themes
.remove(theme
.getThemeId());