Java tutorial
/* Copyright (c) 2010 Ministry of the Interior and Kingdom Relations, * the Netherlands. All rights reserved. * * This file is part of the MinBZK Search Enricher indexing generator. * * Search Enricher is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Search Enricher 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Search Enricher. If not, see <http://www.gnu.org/licenses/>. */ package nl.minbzk.dwr.zoeken.enricher.settings; import java.io.PrintWriter; import java.util.List; import java.util.Map.Entry; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import nl.minbzk.dwr.zoeken.enricher.Uploader; import nl.minbzk.dwr.zoeken.enricher.service.EnricherService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.AbstractController; /** * Import controller. * * @author Jasper van Veghel <j.veghel@rijksoverheid.nl> */ @Controller("settingsController") public class EnricherSettingsController extends AbstractController { /** * The enricher settings. */ @Autowired private EnricherSettings enricherSettings; /** * The enricher service. */ @Autowired private EnricherService enricherService; /** * Handle a request. * * @param request * @param response * @return ModelAndView */ @Override protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception { PrintWriter writer = response.getWriter(); writer.write("<html>\n\t<head>\n\t\t<title>Search Enricher Settings</title>\n\t</head>\n\n\t<body>\n"); writer.write("\t<h1>Search Enricher Settings</h1>\n<hr />\n"); // Word breaking writer.write("<h2>Word breaking</h2>\n"); if (enricherSettings.getWordBreakMax() == 0 || enricherSettings.getWordBreakMin() == 0) writer.write("Disabled<br />\n"); else writer.write("Min: " + enricherSettings.getWordBreakMin() + ", Max: " + enricherSettings.getWordBreakMax() + "<br />\n"); writer.write("<br />\n"); // Additional detectors writer.write("<h2>Additional parsers and detectors for Tika</h2>\n"); if (enricherSettings.getTikaDetectors().size() > 0 || enricherSettings.getTikaParsers().size() > 0) { for (String tikaDetector : enricherSettings.getTikaDetectors()) writer.write("Detector: " + tikaDetector + "<br />\n"); for (String tikaParser : enricherSettings.getTikaParsers()) writer.write("Parser: " + tikaParser + "<br />\n"); } else writer.write("None<br />\n"); writer.write("<br />\n"); // Jobs writer.write("\t<h1>Search Enricher Jobs</h1>\n<hr />\n"); for (Entry<String, EnricherJob> entry : enricherSettings.getJobs().entrySet()) { List<Uploader> derivedUploaders = enricherService.deriveUploaders(entry.getValue()); entry.getValue().writeOut(writer, derivedUploaders); } writer.write("\t</body>\n</html>\n"); return null; } }