/* Copyright 2006 - 2010 Under Dusken Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package no.dusken.aranea.admin.control; import no.dusken.aranea.model.Issue; import no.dusken.aranea.service.IssueService; import org.springframework.beans.factory.annotation.Required; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.util.Calendar; /** * This updates the size of the pdfs using the actual file size */ public class PdfSizeController implements Controller { private IssueService issueService; private String pdfDirectory; /** * Process the request and return a ModelAndView object which the DispatcherServlet * will render. A <code>null</code> return value is not an error: It indicates that * this object completed request processing itself, thus there is no ModelAndView * to render. * * @param request current HTTP request * @param response current HTTP response * @return a ModelAndView to render, or <code>null</code> if handled directly * @throws Exception in case of errors */ public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { // ignore the request, this is plain work for (Issue issue : issueService.getIssues()) { String url = pdfDirectory + issue.getFromDate().get(Calendar.YEAR) + "/" + issue.getIssue() + "-" + ((Integer) issue.getFromDate().get(Calendar.YEAR)) .toString() + ".pdf"; File pdfFile = new File(url); issue.setPdfSize(pdfFile.length()); issueService.saveOrUpdate(issue); } return new ModelAndView("redirect:/"); } @Required public void setPdfDirectory(String pdfDirectory) { this.pdfDirectory = pdfDirectory; } @Required public void setIssueService(IssueService issueService) { this.issueService = issueService; } }