//
// https://www.ramecera.it/myscrewdriver.html
// e-mail: screwdriver@ramecera.it
//
/* This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License v1.0 which accompanies this
 * distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html */
package it.ramecera.screwdriver.component;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import it.ramecera.salad.everyday.Candies;
import it.ramecera.salad.everyday.ExactException;
import it.ramecera.salad.everyday.Mix;
import it.ramecera.salad.everyday.Universal;
import it.ramecera.salad.file.Equipment;
import it.ramecera.screwdriver.CandyScrew;
import it.ramecera.screwdriver.Markup;
import it.ramecera.screwdriver.Skill;
import it.ramecera.screwdriver.Train;

/** @author M. Maglioni */
final public class SpringProperties_xml extends FileComponent {

	/** @param skill application main data
	 * @param snippetG name of the file containing the snippet */
	public SpringProperties_xml(Skill skill, String snippetG) {
		super();
		this.skill = skill;
		this.snippetG = snippetG;
	}

	/** @throws ExactException exception specified by a numeric code */
	@Override
	public void synthesis(HashMap<String, Markup> markupE,
			List<Train> trainE, CandyScrew candyScrew)

			throws FileNotFoundException, IOException, ExactException {

		skill.springPropertiesG = skill.candies.snippetsYS + snippetG;
		producedMaterial = Equipment.oneString(skill.springPropertiesG)
				+ Candies.LF;
		producedMaterial += Candies.TABS
				+ "<bean id=\"messageSource\" class=\"org.springframework"
				+ ".context.support.ReloadableResourceBundleMessageSource\">"
				+ Candies.LF;
		producedMaterial += Candies.TABS + Candies.TABS
				+ "<property name=\"basenames\">" + Candies.LF;
		producedMaterial += Candies.TABS + Candies.TABS + Candies.TABS
				+ "<list>" + Candies.LF;
		String content = "# PROPERTIES LIST" + Candies.LF;
		content += "# SPRING SECURITY" + Candies.LF;
		content += "AbstractUserDetailsAuthenticationProvider"
				+ ".badCredentials=Username o password errata"
				+ Candies.LF;
		content += "AbstractUserDetailsAuthenticationProvider"
				+ ".disabled=Disabled user" + Candies.LF;
		content += "AbstractUserDetailsAuthenticationProvider"
				+ ".expired=Expired account" + Candies.LF;
		content += "ConcurrentSessionControllerImpl.exceededAllowed"
				+ "=This user is already logged in." + Candies.LF;
		content += "AbstractAccessDecisionManager.accessDenied"
				+ "=Denied access" + Candies.LF;
		content += "ConcurrentSessionControlStrategy.exceededAllowed"
				+ "=The maximum number of sessions for this user have been exceeded"
				+ Candies.LF;
		for (int i = 0; i < markupE.get("uintp").recurrenceE
				.size(); i++) {
			Equipment.scriviFileDaStringa(new File(Mix.dress_C(
					skill.mainResources) + markupE.get(
							"uintp").recurrenceE.get(i).locomotor.text
					+ ".properties"), content);
			producedMaterial += Candies.TABS + Candies.TABS
					+ Candies.TABS + Candies.TABS + "<value>classpath:"
					+ markupE.get("uintp").recurrenceE.get(
							i).locomotor.text + "</value>" + Candies.LF;
		}
		/* the markup i18n can be present one time, but here I desire
		 * execute a loop */
		for (int i = 0; i < markupE.get("i18n").recurrenceE
				.size(); i++) {
			Equipment.scriviFileDaStringa(new File(Mix.dress_C(
					skill.mainResources) + markupE.get(
							"i18n").recurrenceE.get(i).locomotor.text
					+ ".properties"), content);
			producedMaterial += Candies.TABS + Candies.TABS
					+ Candies.TABS + Candies.TABS + "<value>classpath:"
					+ markupE.get("i18n").recurrenceE.get(
							i).locomotor.text + "</value>" + Candies.LF;
			for (int j = 0; j < markupE.get("language").recurrenceE
					.size(); j++) {
				if (!markupE.get("language").recurrenceE.get(
						j).locomotor.text.equalsIgnoreCase(
								Universal.languageE[skill.defaulan][1])) {
					Equipment.scriviFileDaStringa(new File(Mix.dress_C(
							skill.mainResources) + markupE.get(
									"i18n").recurrenceE.get(
											i).locomotor.text + "_"
							+ markupE.get("language").recurrenceE.get(
									j).locomotor.text + ".properties"),
							content);
				}
			}
		}
		producedMaterial += Candies.TABS + Candies.TABS + Candies.TABS
				+ "</list>" + Candies.LF;
		producedMaterial += Candies.TABS + Candies.TABS + "</property>"
				+ Candies.LF;
		producedMaterial += Candies.TABS + Candies.TABS
				+ "<property name=\"defaultEncoding\" " + "value=\""
				+ skill.charset + "\" />" + Candies.LF;
		producedMaterial += Candies.TABS + Candies.TABS
				+ "<property name=\"fallbackToSystemLocale\" "
				+ "value=\"false\" />" + Candies.LF;
		producedMaterial += Candies.TABS + "</bean>" + Candies.LF;
		producedMaterial += "</beans>";
	}

	/* written only to comply with the abstract class FileComponent */
	@SuppressWarnings("javadoc")
	@Override
	/** @param markupE the list of markups
	 * @param skill together with the characteristics of the application
	 * @param trash file where the deleted files are moved
	 * @throws ExactException exception specified by a numeric code */
	public void directory(HashMap<String, Markup> markupE)

			throws ExactException {

	}
}
