package org.infohazard.maverick.opt.view;

import javax.servlet.ServletConfig;
import org.infohazard.maverick.flow.ConfigException;
import org.infohazard.maverick.flow.TransformFactory;
import org.infohazard.maverick.flow.View;
import org.infohazard.maverick.flow.ViewFactory;
import org.infohazard.maverick.util.XML;
import org.jdom.Element;

public class FopViewFactory implements ViewFactory {

	public void init(Element factoryNode, ServletConfig servletCfg, TransformFactory transforms) throws ConfigException {}

	public View createView(Element viewNode) throws ConfigException {
		String path = XML.getValue(viewNode, "path");

		if (path == null)
			throw new ConfigException("View node must have a path:  " + XML.toString(viewNode));

		Element transformNode = viewNode.getChild(TransformFactory.TAG_TRANSFORM);
		if (transformNode == null) {
			return new FopView(path);
		} else {
			throw new ConfigException("Since output of FopView is binary pdf data, transforms are not permitted. If you need transforms, set the \"path\" attribute to a maverick controller rather than a static file.");
		}
	}
}