de.espirit.firstspirit.access.editor.FileEditorValueExample


package de.espirit.firstspirit.access.editor;

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


/**
 * Example how to store a file (BinaryMedium) into a FileEditorValue.
 *
 * @since 4.2.34
 */
public class FileEditorValueExample {


	/**
	 * Stores given binary object as language specific value (specified by the given language) for the given editor.
	 *
	 * @since 4.2.34
	 */
	public FileEditorValue setValueForLanguage(final FileEditorValue editor, final BinaryMedium object, 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 this instance in the editor value
		editor.set(language, object);

		// 3. and return the instance for further processing
		return editor;
	}


	/**
	 * Gets the language specific value (BinaryMedium) for the given language and file editor.
	 *
	 * @since 4.2.34
	 */
	public BinaryMedium getValueForLanguage(final FileEditorValue editor, final Language language) throws InvalidValueException {

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

		// 2. and return the reference container for further processing
		return medium;
	}
}