Java tutorial
/* 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.web.control; import no.dusken.aranea.model.Section; import no.dusken.aranea.service.SectionService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Required; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.ServletRequestUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.AbstractController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.*; @Controller public class HeaderController { private SectionService sectionService; @RequestMapping("/header.do") public String handleHeaderMenu( @RequestParam(value = "section", required = false, defaultValue = "") String sectionUrl, @RequestParam(value = "subsection", required = false, defaultValue = "") String subSectionUrl, Model model) { Section section = sectionService.getSectionByUrl(sectionUrl, null); model.addAttribute("selectedSection", section); if (subSectionUrl != null && !subSectionUrl.equals("")) { Section subsection = sectionService.getSectionByUrl(subSectionUrl, section); model.addAttribute("selectedSubsection", subsection); } if (section != null) { List<Section> children = section.getActiveChildren(); if (children != null && children.size() > 0) { model.addAttribute("children", children); } } GregorianCalendar now = new GregorianCalendar(); model.addAttribute("now", now); List<Section> sections = sectionService.getTopLevelSections(false); model.addAttribute("sections", sections); model.addAttribute("years", now.get(Calendar.YEAR) - 1914); return "no/dusken/aranea/base/web/header/view"; } @Required @Autowired public void setSectionService(SectionService sectionService) { this.sectionService = sectionService; } }