| 1 | package com.hammurapi.render; |
| 2 | |
| 3 | import java.io.File; |
| 4 | import java.util.ArrayList; |
| 5 | import java.util.List; |
| 6 | import java.util.Locale; |
| 7 | import java.util.Map; |
| 8 | |
| 9 | import com.hammurapi.common.Context; |
| 10 | import com.hammurapi.common.IdentityManager; |
| 11 | |
| 12 | /** |
| 13 | * If profile is "outline" or "outline_http" this renderer also renders e<element id>.html with default profile |
| 14 | * and e<element id>_contents.html with contents or contents_http profile. |
| 15 | * @author Pavel Vlasov |
| 16 | * |
| 17 | */ |
| 18 | public class MultiFileJxpRenderer implements MultiFileRenderer, RenderingConstants { |
| 19 | |
| 20 | private JxpRenderer renderer; |
| 21 | private Object source; |
| 22 | |
| 23 | public MultiFileJxpRenderer(Object obj) { |
| 24 | this.renderer = new JxpRenderer(obj); |
| 25 | this.source = obj; |
| 26 | } |
| 27 | |
| 28 | @Override |
| 29 | public List<File> render(File out, Map<String, Object> environment, Context context, String profile, Locale locale) throws RenderingException { |
| 30 | List<File> ret = new ArrayList<File>(); |
| 31 | if (renderer.render(out, environment, context, profile, locale)) { |
| 32 | ret.add(out); |
| 33 | if (OUTLINE.equals(profile) || OUTLINE_HTTP.equals(profile)) { |
| 34 | IdentityManager<?> identityManager = context.lookup(IdentityManager.class); |
| 35 | Object id = identityManager.getIdentity(source); |
| 36 | File detailsOut = new File(out.getParentFile(), "e"+id+".html"); |
| 37 | if (renderer.render(detailsOut, environment, context, null, locale)) { |
| 38 | ret.add(detailsOut); |
| 39 | } |
| 40 | boolean http = OUTLINE_HTTP.equals(profile); |
| 41 | File contentsOut = new File(out.getParentFile(), "e"+id+"_contents.html"); |
| 42 | if (renderer.render(contentsOut, environment, context, http ? CONTENTS_HTTP : CONTENTS, locale)) { |
| 43 | ret.add(contentsOut); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | return ret; |
| 48 | } |
| 49 | |
| 50 | } |