01: /*
02: * Copyright 2006 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: DwrService.java 3728 2007-05-01 16:07:54Z gbevin $
07: */
08: package com.uwyn.rife.engine.elements;
09:
10: import java.util.ArrayList;
11: import java.util.List;
12: import java.util.Properties;
13:
14: import javax.servlet.http.HttpServletRequest;
15: import javax.servlet.http.HttpServletResponse;
16:
17: import org.directwebremoting.servlet.PathConstants;
18:
19: import com.uwyn.rife.engine.Element;
20: import com.uwyn.rife.engine.annotations.Elem;
21: import com.uwyn.rife.engine.exceptions.EngineException;
22: import com.uwyn.rife.tools.Convert;
23: import com.uwyn.rife.tools.StringUtils;
24:
25: @Elem
26: public class DwrService extends Element {
27: public final static String PROPERTY_NAMES = "names";
28: public final static String PROPERTY_INCLUDE_UTIL = "includeUtil";
29: public final static String PROPERTY_XML_CONFIGURATOR_PATH = "xmlConfiguratorPath";
30:
31: public final static List<String> DWR_ELEMENT_PROPERTIES = new ArrayList<String>() {
32: {
33: add(PROPERTY_NAMES);
34: add(PROPERTY_INCLUDE_UTIL);
35: add(PROPERTY_XML_CONFIGURATOR_PATH);
36: }
37: };
38:
39: public Class getDeploymentClass() {
40: return DwrServiceDeployer.class;
41: }
42:
43: public void processElement() {
44: DwrServiceDeployer deployer = (DwrServiceDeployer) getDeployer();
45: String engineHandlerUrl = (String) deployer.getContainer()
46: .getBean("engineHandlerUrl");
47: String utilHandlerUrl = (String) deployer.getContainer()
48: .getBean("utilHandlerUrl");
49: String interfaceHandlerUrl = (String) deployer.getContainer()
50: .getBean("interfaceHandlerUrl");
51:
52: try {
53: setProhibitRawAccess(false);
54:
55: HttpServletRequest request = new DwrElementHttpServletRequest(
56: this );
57: HttpServletResponse response = getHttpServletResponse();
58:
59: deployer.initWebContextBuilder(request, response);
60:
61: if (isEmbedded()) {
62: String dwr_root = StringUtils.stripFromEnd(
63: getWebappRootUrl(), "/")
64: + getElementInfo().getUrl();
65:
66: Properties props = getEmbedProperties();
67: for (String name : StringUtils.split(props
68: .getProperty(PROPERTY_NAMES), ",")) {
69: printJavascriptInclusion(dwr_root
70: + interfaceHandlerUrl + name.trim()
71: + PathConstants.EXTENSION_JS);
72: }
73:
74: printJavascriptInclusion(dwr_root + engineHandlerUrl);
75:
76: if (Convert.toBoolean(props
77: .getProperty(PROPERTY_INCLUDE_UTIL), false)) {
78: printJavascriptInclusion(dwr_root + utilHandlerUrl);
79: }
80: } else {
81: deployer.getProcessor().handle(request, response);
82: }
83: } catch (SecurityException e) {
84: defer();
85: } catch (Exception e) {
86: throw new EngineException(e);
87: } finally {
88: deployer.deinitWebContextBuilder();
89: }
90: }
91:
92: private void printJavascriptInclusion(String srcPath) {
93: print("<script type=\"text/javascript\" src=\"" + srcPath
94: + "\"> </script>\n");
95: }
96: }
|