de.espirit.firstspirit.access.editor.DateEditorValueExample


package de.espirit.firstspirit.access.editor;

import de.espirit.firstspirit.access.Language;
import de.espirit.firstspirit.access.editor.value.InvalidValueException;

import java.util.Date;

/**
 * Example how to get the value of a DateEditorValue and how to store a value into a DateEditorValue.
 *
 * @since 4.2.34
 */
public class DateEditorValueExample {

	/**
	 * Stores the value into the DateEditorValue for the given language.
	 *
	 * @since 4.2.34
	 */
	public void setValueForLanguage(final DateEditorValue editor, final Date value, final Language language) throws InvalidValueException {

		// 1. check if language is provided if editor is language dependent ("useLanguages='yes'" in gom syntax)
		if (editor.isLanguageDependent() && language == null) {
			throw new NullPointerException("Language is missing!");
		}

		// 2. store value into the editor value
		editor.set(language, value);
	}


	/**
	 * Returns the value of the TextualEditorValue for the given language.
	 *
	 * @since 4.2.34
	 */
	public Date getValueForLanguage(final DateEditorValue editor, final Language language) {

		// 1. get the stored instance in the editor value
		final Date value = editor.get(language);

		// 2. and return the value for further processing
		return value;
	}
}