/* 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.Page; import no.dusken.aranea.model.PageRelation; import no.dusken.aranea.service.PageRelationService; import no.dusken.aranea.service.PageService; import org.springframework.beans.factory.annotation.Required; import org.springframework.web.bind.ServletRequestUtils; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /* * @author Marvin B. Lillehaug <lillehau@underdusken.no> */ public class AddRelationPageController implements Controller { private PageService pageService; private PageRelationService pageRelationService; public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { //getting the referencepage Long pageID = ServletRequestUtils.getLongParameter(request, "referencePage", 0); Page referencePage = pageService.getEntity(pageID); int numberToadd = ServletRequestUtils.getIntParameter(request, "nPages", 0); for (int i = 0; i < numberToadd; i++) { //checking if pageI is selected String nextPage = "page" + i; Long pID = ServletRequestUtils.getLongParameter(request, nextPage, 0); Page p = null; if(pID != 0){ p = pageService.getEntity(pID); } if (p != null && !referencePage.isRelatedTo(p)) { String description1 = ServletRequestUtils.getStringParameter(request, "description1" + nextPage, ""); String description2 = ServletRequestUtils.getStringParameter(request, "description2" + nextPage, ""); boolean onFrontPage = ServletRequestUtils.getBooleanParameter(request, "onFrontPage", false); PageRelation relation = new PageRelation(referencePage, description1, p, description2, onFrontPage); pageRelationService.saveOrUpdate(relation); } } return new ModelAndView("redirect:editPageRelation.do?referencePage=" + referencePage.getID()); } @Required public void setPageService(PageService pageService) { this.pageService = pageService; } @Required public void setPageRelationService(PageRelationService pageRelationService) { this.pageRelationService = pageRelationService; } }