Skip to content

Commit

Permalink
Merge pull request #1406 from gritGmbH/enhancement/rest-api-add-fontl…
Browse files Browse the repository at this point in the history
…ist-83

Adds endpoint to REST API to list available fonts on the server
  • Loading branch information
copierrj authored Nov 23, 2022
2 parents b1ba2e8 + 7ca1717 commit 0d7c566
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*----------------------------------------------------------------------------
This file is part of deegree, http://deegree.org/
Copyright (C) 2001-2010 by:
- Department of Geography, University of Bonn -
and
- lat/lon GmbH -
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact information:
lat/lon GmbH
Aennchenstr. 19, 53177 Bonn
Germany
http://lat-lon.de/
Department of Geography, University of Bonn
Prof. Dr. Klaus Greve
Postfach 1147, 53001 Bonn
Germany
http://www.geographie.uni-bonn.de/deegree/
e-mail: info@deegree.org
----------------------------------------------------------------------------*/
package org.deegree.services.config.actions;

import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.io.IOException;
import java.util.SortedSet;
import java.util.TreeSet;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;

/**
* List the currently available fonts in the server
*
* @author <a href="mailto:reichhelm@grit.de">Stephan Reichhelm</a>
*/
public class ListFonts {

public static void listFonts( HttpServletResponse resp )
throws IOException {
resp.setContentType( "text/plain" );

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
SortedSet<String> fonts = new TreeSet<>();

// list names and families
for ( Font font : ge.getAllFonts() ) {
fonts.add( font.getName() );
fonts.add( font.getFamily() );
}

ServletOutputStream os = resp.getOutputStream();
for ( String name : fonts ) {
IOUtils.write( name + "\n", os );
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//$HeadURL$
/*----------------------------------------------------------------------------
This file is part of deegree, http://deegree.org/
Copyright (C) 2001-2010 by:
Expand Down Expand Up @@ -42,6 +41,7 @@
import static org.deegree.services.config.actions.Download.download;
import static org.deegree.services.config.actions.Invalidate.invalidate;
import static org.deegree.services.config.actions.List.list;
import static org.deegree.services.config.actions.ListFonts.listFonts;
import static org.deegree.services.config.actions.ListWorkspaces.listWorkspaces;
import static org.deegree.services.config.actions.Restart.restart;
import static org.deegree.services.config.actions.UpdateBboxCache.updateBboxCache;
Expand All @@ -63,9 +63,6 @@
/**
*
* @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
* @author last edited by: $Author$
*
* @version $Revision$, $Date$
*/
public class ConfigServlet extends HttpServlet {

Expand Down Expand Up @@ -93,6 +90,7 @@ protected void doGet( HttpServletRequest req, HttpServletResponse resp )
data.append( "GET /config/update - rescan config files and update resources\n" );
data.append( "GET /config/update/wsname - update with workspace <wsname>, rescan config files and update resources\n" );
data.append( "GET /config/listworkspaces - list available workspace names\n" );
data.append( "GET /config/listfonts - list currently available fonts on the server\n" );
data.append( "GET /config/list[/path] - list currently running workspace or directory in workspace\n" );
data.append( "GET /config/list/wsname[/path] - list workspace with name <wsname> or directory in workspace\n" );
data.append( "GET /config/invalidate/datasources/tile/id/matrixset[?bbox=] - invalidate part or all of a tile store cache's tile matrix set\n" );
Expand Down Expand Up @@ -148,6 +146,8 @@ private void dispatch( String path, HttpServletRequest req, HttpServletResponse

if ( path.toLowerCase().startsWith( "/listworkspaces" ) ) {
listWorkspaces( resp );
} else if ( path.toLowerCase().startsWith( "/listfonts" ) ) {
listFonts( resp );
} else if ( path.toLowerCase().startsWith( "/list" ) ) {
list( path.substring( 5 ), resp );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ GET /config/restart/wsname - restart with work
GET /config/update - update currently running workspace, rescan config files and update resources
GET /config/update/wsname - update with workspace <wsname>, rescan config files and update resources
GET /config/listworkspaces - list available workspace names
GET /config/listfonts - list currently available fonts on the server
GET /config/list[/path] - list currently running workspace or directory in workspace
GET /config/list/wsname[/path] - list workspace with name <wsname> or directory in workspace
GET /config/invalidate/datasources/tile/id/matrixset[?bbox=] - invalidate part or all of a tile store cache's tile matrix set
Expand Down

0 comments on commit 0d7c566

Please sign in to comment.