/*
 * Copyright 2013, 2014 Deutsche Nationalbibliothek
 *
 * 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.culturegraph.mf.stream.converter;

import org.culturegraph.mf.framework.DefaultStreamPipe;
import org.culturegraph.mf.framework.ObjectReceiver;
import org.culturegraph.mf.framework.StreamReceiver;
import org.culturegraph.mf.framework.annotations.Description;
import org.culturegraph.mf.framework.annotations.FluxCommand;
import org.culturegraph.mf.framework.annotations.In;
import org.culturegraph.mf.framework.annotations.Out;

/**
 * Outputs the name and value of each literal which is received
 * as a string. Name and value are separated by a separator string.
 * The default separator string is a tab. If a literal name is
 * empty, only the value will be output without a separator.
 * <p>
 * The module ignores record and entity events. In particular,
 * this means that literal names are not prefixed by the name
 * of the entity which contains them.
 *
 * @author Markus Michael Geipel
 *
 */
@Description("Outputs the name and value of each literal which is received " +
		"as a string. Name and value are separated by a separator " +
		"string. The default separator string is a tab. If a literal " +
		"name is empty, only the value will be output without a separator. " +
		"The module ignores record and entity events. In particular, " +
		"this means that literal names are not prefixed by the name " +
		"of the entity which contains them.")
@In(StreamReceiver.class)
@Out(String.class)
@FluxCommand("encode-literals")
public final class StreamLiteralFormatter
		extends DefaultStreamPipe<ObjectReceiver<String>> {

	private static final String DEFAULT_SEPARATOR = "\t";

	private String separator = DEFAULT_SEPARATOR;

	public void setSeparator(final String separator) {
		this.separator = separator;
	}

	@Override
	public void literal(final String name, final String value) {
		if (name == null || name.isEmpty()) {
			getReceiver().process(value);
		} else {
			getReceiver().process(name + separator + value);
		}
	}

}

@@ -1,11 +1,45 @@
 /*%0A
+ * Copyright 2016 Christoph B%C3%B6hme%0A
  * Copyr
@@ -1091,21 +1091,19 @@
 %0A/**%0A * 
-Outpu
+Emi
 ts the n
@@ -1149,19 +1149,16 @@
 received
-%0A *
  as a st
@@ -1154,32 +1154,35 @@
 ved as a string.
+%0A *
  Name and value 
@@ -1217,19 +1217,16 @@
  string.
-%0A *
  The def
@@ -1231,32 +1231,35 @@
 efault separator
+%0A *
  string is a tab
@@ -1280,19 +1280,16 @@
  name is
-%0A *
  empty, 
@@ -1309,32 +1309,35 @@
 e will be output
+%0A *
  without a separ
@@ -1401,27 +1401,9 @@
 ts. 
-In particular,%0A * t
+T
 his 
@@ -1418,32 +1418,35 @@
 at literal names
+%0A *
  are not prefixe
@@ -1458,19 +1458,16 @@
 the name
-%0A *
  of the 
@@ -2168,23 +2168,89 @@
 g%3E%3E %7B%0A%0A%09
-private
+/**%0A%09 * The default value for %7B@link #setSeparator(String)%7D.%0A%09 */%0A%09public
  static 
@@ -2337,16 +2337,406 @@
 RATOR;%0A%0A
+%09/**%0A%09 * Sets the separator between the literal name and value. The separator is%0A%09 * only added if the literal name is not empty.%0A%09 * %3Cp%3E%0A%09 * The default separator is &ldquo;%7B@link #DEFAULT_SEPARATOR%7D&rdquo;.%0A%09 * %3Cp%3E%0A%09 * The parameter can be changed at any time during processing. It becomes%0A%09 * effective with the next literal received.%0A%09 *%0A%09 * @param separator the separator string.%0A%09 */%0A
 %09public 
@@ -2813,16 +2813,72 @@
 or;%0A%09%7D%0A%0A
+%09public String getSeparator() %7B%0A%09%09return separator;%0A%09%7D%0A%0A
 %09@Overri

Improve Javadoc of StreamLiteralFormatter