// Path: src/main/java/org/thymeleaf/itutorial/beans/Customer.java
// public class Customer {
//     
//     private Integer id;
//     private String firstName;
//     private String lastName;
//     private Gender gender;
//     private PaymentMethod paymentMethod;
//     private int balance;
//     private String personalWebsite;
//     
//     public Customer() {
//         super();
//     }
// 
//     public Customer(
//             final Integer id, final String firstName, final String lastName, 
//             final Gender gender, final PaymentMethod paymentMethod,
//             final int balance, final String personalWebsite) {
//         super();
//         this.id = id;
//         this.firstName = firstName;
//         this.lastName = lastName;
//         this.gender = gender;
//         this.paymentMethod = paymentMethod;
//         this.balance = balance;
//         this.personalWebsite = personalWebsite;
//     }
// 
//     public Integer getId() {
//         return this.id;
//     }
// 
//     public void setId(final Integer id) {
//         this.id = id;
//     }
// 
//     public int getBalance() {
//         return this.balance;
//     }
// 
//     public void setBalance(final int balance) {
//         this.balance = balance;
//     }
// 
//     public String getFirstName() {
//         return this.firstName;
//     }
// 
//     public void setFirstName(final String firstName) {
//         this.firstName = firstName;
//     }
// 
//     public Gender getGender() {
//         return this.gender;
//     }
// 
//     public void setGender(final Gender gender) {
//         this.gender = gender;
//     }
// 
//     public String getLastName() {
//         return this.lastName;
//     }
// 
//     public void setLastName(final String lastName) {
//         this.lastName = lastName;
//     }
// 
//     public PaymentMethod getPaymentMethod() {
//         return this.paymentMethod;
//     }
// 
//     public void setPaymentMethod(final PaymentMethod paymentMethod) {
//         this.paymentMethod = paymentMethod;
//     }
// 
//     public String getPersonalWebsite() {
//         return personalWebsite;
//     }
// 
//     public void setPersonalWebsite(String personalWebsite) {
//         this.personalWebsite = personalWebsite;
//     }
// }
// 
// Path: src/main/java/org/thymeleaf/itutorial/IndexController.java
// public static final String THYMELEAF_VERSION_PARAMETER = "thymeleafVersion";


import java.io.IOException;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.thymeleaf.itutorial.beans.Customer;
import static org.thymeleaf.itutorial.IndexController.THYMELEAF_VERSION_PARAMETER;
/*
 * =============================================================================
 * 
 *   Copyright (c) 2011-2014, The THYMELEAF team (http://www.thymeleaf.org)
 * 
 *   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 org.thymeleaf.itutorial;


@Controller
public class ExerciseController {

    private static final String CHARSET = "UTF-8";

    @Autowired private ServletContext servletContext;

    @RequestMapping(value = "/exercise/{index}", method = RequestMethod.GET)
    public String exercise(@PathVariable("index") final Integer index, final Model model) throws IOException {
        Exercise exercise = Exercise.get(index);
        String question = new ExerciseResourceLoader(servletContext, exercise).getResource("question.html", CHARSET);
        model.addAttribute("question", question);
        model.addAttribute("exercise", exercise);
        model.addAttribute("thymeleafVersion", servletContext.getInitParameter(THYMELEAF_VERSION_PARAMETER));
        return "exercise.html";
    }

    // Auxiliar mapping for Exercise 11.
    @RequestMapping("/exercise11/product.html")
    public String product(@RequestParam("action") String action, Model model) {
        model.addAttribute("product", DAO.loadProduct());
        if ("view".equals(action)) {
            return "/exercise11/viewProduct.html";
        } else if ("edit".equals(action)) {
            return "/exercise11/editProduct.html";
        } else {
            throw new IllegalArgumentException("Action -" + action +"- not recognized");
        }
    }

    // Auxiliar mapping for Exercise 12.
    @RequestMapping("/exercise12/saveCustomer.html")
// Path: src/main/java/org/thymeleaf/itutorial/beans/Customer.java
// public class Customer {
//     
//     private Integer id;
//     private String firstName;
//     private String lastName;
//     private Gender gender;
//     private PaymentMethod paymentMethod;
//     private int balance;
//     private String personalWebsite;
//     
//     public Customer() {
//         super();
//     }
// 
//     public Customer(
//             final Integer id, final String firstName, final String lastName, 
//             final Gender gender, final PaymentMethod paymentMethod,
//             final int balance, final String personalWebsite) {
//         super();
//         this.id = id;
//         this.firstName = firstName;
//         this.lastName = lastName;
//         this.gender = gender;
//         this.paymentMethod = paymentMethod;
//         this.balance = balance;
//         this.personalWebsite = personalWebsite;
//     }
// 
//     public Integer getId() {
//         return this.id;
//     }
// 
//     public void setId(final Integer id) {
//         this.id = id;
//     }
// 
//     public int getBalance() {
//         return this.balance;
//     }
// 
//     public void setBalance(final int balance) {
//         this.balance = balance;
//     }
// 
//     public String getFirstName() {
//         return this.firstName;
//     }
// 
//     public void setFirstName(final String firstName) {
//         this.firstName = firstName;
//     }
// 
//     public Gender getGender() {
//         return this.gender;
//     }
// 
//     public void setGender(final Gender gender) {
//         this.gender = gender;
//     }
// 
//     public String getLastName() {
//         return this.lastName;
//     }
// 
//     public void setLastName(final String lastName) {
//         this.lastName = lastName;
//     }
// 
//     public PaymentMethod getPaymentMethod() {
//         return this.paymentMethod;
//     }
// 
//     public void setPaymentMethod(final PaymentMethod paymentMethod) {
//         this.paymentMethod = paymentMethod;
//     }
// 
//     public String getPersonalWebsite() {
//         return personalWebsite;
//     }
// 
//     public void setPersonalWebsite(String personalWebsite) {
//         this.personalWebsite = personalWebsite;
//     }
// }
// 
// Path: src/main/java/org/thymeleaf/itutorial/IndexController.java
// public static final String THYMELEAF_VERSION_PARAMETER = "thymeleafVersion";


// Path: src/main/java/org/thymeleaf/itutorial/ExerciseController.java
import java.io.IOException;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.thymeleaf.itutorial.beans.Customer;
import static org.thymeleaf.itutorial.IndexController.THYMELEAF_VERSION_PARAMETER;

/*
 * =============================================================================
 * 
 *   Copyright (c) 2011-2014, The THYMELEAF team (http://www.thymeleaf.org)
 * 
 *   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 org.thymeleaf.itutorial;


@Controller
public class ExerciseController {

    private static final String CHARSET = "UTF-8";

    @Autowired private ServletContext servletContext;

    @RequestMapping(value = "/exercise/{index}", method = RequestMethod.GET)
    public String exercise(@PathVariable("index") final Integer index, final Model model) throws IOException {
        Exercise exercise = Exercise.get(index);
        String question = new ExerciseResourceLoader(servletContext, exercise).getResource("question.html", CHARSET);
        model.addAttribute("question", question);
        model.addAttribute("exercise", exercise);
        model.addAttribute("thymeleafVersion", servletContext.getInitParameter(THYMELEAF_VERSION_PARAMETER));
        return "exercise.html";
    }

    // Auxiliar mapping for Exercise 11.
    @RequestMapping("/exercise11/product.html")
    public String product(@RequestParam("action") String action, Model model) {
        model.addAttribute("product", DAO.loadProduct());
        if ("view".equals(action)) {
            return "/exercise11/viewProduct.html";
        } else if ("edit".equals(action)) {
            return "/exercise11/editProduct.html";
        } else {
            throw new IllegalArgumentException("Action -" + action +"- not recognized");
        }
    }

    // Auxiliar mapping for Exercise 12.
    @RequestMapping("/exercise12/saveCustomer.html")
    public String saveCustomer(Customer customer, Model model) {