01: package org.mandarax.jdbc.server.http;
02:
03: /*
04: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20:
21: import org.mandarax.jdbc.JDBCUtils;
22: import javax.servlet.ServletContext;
23:
24: /**
25: * Web server based facade implementation. Uses the servlet context in order to
26: * convert virtual path to real path information.
27: * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
28: * @version 3.3.2 <29 December 2004>
29: * @since 3.0
30: */
31:
32: public class WebServerFacade extends
33: org.mandarax.jdbc.server.DefaultServerFacade {
34:
35: private ServletContext context = null;
36:
37: /**
38: * Constructor.
39: * @param context the servlet context (used to convert a virtual path to a real path)
40: */
41: public WebServerFacade(ServletContext context) {
42: super ();
43: this .context = context;
44: }
45:
46: /**
47: * Convert a db url to a local url.
48: * This implementation simply removes the NET token.
49: * @param a db url
50: * @return a local db url (to be used by the local driver)
51: */
52: public String convertToLocalUrl(String url) {
53: // ref,mypackage.myserver,http://localhost:8080/mandaraxjdbc
54: String[] parts = JDBCUtils.parseNetUrl(url);
55: if (parts == null) {
56: LOG_JDBC.warn("Cannot parse URL: " + url);
57: return null;
58: }
59: String protocol = parts[0];
60: String virtualPath = parts[1];
61: String realPath = null;
62: // ref means that the resource is a name of a class !
63: if (protocol.equalsIgnoreCase("ref"))
64: realPath = virtualPath;
65: else
66: realPath = context.getRealPath(virtualPath);
67:
68: return new StringBuffer().append(JDBCUtils.URL_PREFIX).append(
69: JDBCUtils.URL_SEPARATOR).append(protocol).append(
70: JDBCUtils.URL_SEPARATOR).append(realPath).toString();
71: }
72:
73: }
|