package se.l4.dust.core.internal.template.components;

import java.io.IOException;

import se.l4.dust.api.template.Emittable;
import se.l4.dust.api.template.TemplateEmitter;
import se.l4.dust.api.template.TemplateOutputStream;
import se.l4.dust.core.internal.template.TemplateEmitterImpl;

public class DataContextSwitcher
	implements Emittable
{
	private final Integer id;
	private final Emittable[] content;

	public DataContextSwitcher(Integer id, Emittable[] content)
	{
		this.id = id;
		this.content = content;
	}
	
	@Override
	public void emit(TemplateEmitter emitter, TemplateOutputStream out)
		throws IOException
	{
		TemplateEmitterImpl emitterImpl = (TemplateEmitterImpl) emitter;
		Integer old = emitterImpl.switchData(id);
		
		emitterImpl.emit(content);
		
		emitterImpl.switchData(old);
	}
	
	@Override
	public String toString()
	{
		return "DataSwitch[id=" + id + "]";
	}
}

@@ -736,40 +736,127 @@
 ;%0A%09%09
-%0A%09%09emitterImpl.emit(content);%0A%09%09
+Integer oldC = emitterImpl.switchComponent(id);%0A%09%09%0A%09%09emitterImpl.emit(content);%0A%09%09%0A%09%09emitterImpl.switchComponent(oldC);
 %0A%09%09e

Switch component to solve body in body issues