KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > webtools > print > rmi > FopPrintRemoteImpl


1 /*
2  * $Id: FopPrintRemoteImpl.java 6594 2006-01-26 20:14:31Z jaz $
3  *
4  * Copyright (c) 2001-2006 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.webtools.print.rmi;
26
27 import java.io.StringWriter JavaDoc;
28 import java.io.Writer JavaDoc;
29 import java.rmi.RemoteException JavaDoc;
30 import java.rmi.server.RMIClientSocketFactory JavaDoc;
31 import java.rmi.server.RMIServerSocketFactory JavaDoc;
32 import java.rmi.server.UnicastRemoteObject JavaDoc;
33 import java.util.Locale JavaDoc;
34 import java.util.Map JavaDoc;
35
36 import org.ofbiz.service.DispatchContext;
37 import org.ofbiz.widget.html.HtmlScreenRenderer;
38 import org.ofbiz.widget.screen.ScreenRenderer;
39 import org.ofbiz.entity.GenericValue;
40 import org.ofbiz.entity.GenericEntityException;
41 import org.ofbiz.base.util.UtilMisc;
42
43 /**
44  * FopPrintRemoteImpl
45  *
46  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
47  * @version $Rev: 6594 $
48  * @since 3.5
49  */

50
51 public class FopPrintRemoteImpl extends UnicastRemoteObject JavaDoc implements FopPrintRemote {
52
53     public static final String JavaDoc module = FopPrintRemoteImpl.class.getName();
54
55     protected HtmlScreenRenderer htmlScreenRenderer = new HtmlScreenRenderer();
56     protected DispatchContext dctx = null;
57     protected Locale JavaDoc locale = null;
58
59     public FopPrintRemoteImpl(DispatchContext dctx, Locale JavaDoc locale, RMIClientSocketFactory JavaDoc csf, RMIServerSocketFactory JavaDoc ssf) throws RemoteException JavaDoc {
60         super(0, csf, ssf);
61         this.locale = locale;
62         this.dctx = dctx;
63         if (this.locale == null) {
64             this.locale = Locale.getDefault();
65         }
66     }
67
68     public byte[] getXslFo(String JavaDoc screen, Map JavaDoc parameters) throws RemoteException JavaDoc {
69         // run as the system user
70
GenericValue system = null;
71         try {
72             system = dctx.getDelegator().findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system"));
73         } catch (GenericEntityException e) {
74             throw new RemoteException JavaDoc(e.getMessage());
75         }
76         parameters.put("userLogin", system);
77         if (!parameters.containsKey("locale")) {
78             parameters.put("locale", locale);
79         }
80
81         // render and obtain the XSL-FO
82
Writer JavaDoc writer = new StringWriter JavaDoc();
83         try {
84             ScreenRenderer screens = new ScreenRenderer(writer, null, htmlScreenRenderer);
85             screens.populateContextForService(dctx, parameters);
86             screens.render(screen);
87         } catch (Throwable JavaDoc t) {
88             throw new RemoteException JavaDoc("Problems rendering FOP XSL-FO", t);
89         }
90         return writer.toString().getBytes();
91     }
92 }
93
Popular Tags