diff options
Diffstat (limited to 'petascope/src/petascope/wcs2/schemas/SchemaServlet.java')
-rw-r--r-- | petascope/src/petascope/wcs2/schemas/SchemaServlet.java | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/petascope/src/petascope/wcs2/schemas/SchemaServlet.java b/petascope/src/petascope/wcs2/schemas/SchemaServlet.java new file mode 100644 index 0000000..231d7a5 --- /dev/null +++ b/petascope/src/petascope/wcs2/schemas/SchemaServlet.java @@ -0,0 +1,96 @@ +/* + * This file is part of PetaScope. + * + * PetaScope 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 3 of + * the License, or (at your option) any later version. + * + * PetaScope 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 PetaScope. If not, see <http://www.gnu.org/licenses/>. + * + * For more information please see <http://www.PetaScope.org> + * or contact Peter Baumann via <baumann@rasdaman.com>. + * + * Copyright 2009 Jacobs University Bremen, Peter Baumann. + */ +package petascope.wcs2.schemas; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +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; + +/** Servlet that handles GET requests for the WCS 2.0 schema files. + * + * @author Andrei Aiordachioaie + */ +public class SchemaServlet extends HttpServlet { + + /** + * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("application/xml;charset=UTF-8"); + PrintWriter out = response.getWriter(); + try { + String schemaFile = request.getPathInfo(); + String pathPrefix = "/xml/ogc/wcs/2.0.0/"; + File file = new File(getServletContext().getRealPath(pathPrefix + schemaFile)); + String fileContents = IOUtils.toString(new FileReader(file)); + out.write(fileContents); + } finally { + out.close(); + } + } + + /** + * Handles the HTTP <code>GET</code> method. + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP <code>POST</code> method. + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + } +} |