01: /*
02: * SwingML Copyright (C) 2002 SwingML Team
03: *
04: * This library is free software; you can redistribute it and/or modify it under
05: * the terms of the GNU Lesser General Public License as published by the Free
06: * Software Foundation; either version 2 of the License, or (at your option) any
07: * later version.
08: *
09: * This library is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12: * details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with this library; if not, write to the Free Software Foundation, Inc.,
16: * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: *
18: * Authors: Ezequiel Cuellar <ecuellar@crosslogic.com> Alessandro Di Bella
19: * <alessandro.dibella@fuurou.org>
20: *
21: */
22: package org.swingml;
23:
24: import java.io.*;
25: import java.net.*;
26:
27: import org.swingml.system.*;
28:
29: public class URLHandler {
30:
31: public static String encode(String aUrl) {
32: String aUrlEncode = "";
33: try {
34: aUrlEncode = URLEncoder.encode(aUrl, "UTF-8");
35: } catch (UnsupportedEncodingException uee) {
36: SwingMLLogger.getInstance().log(
37: "The XML URL is not valid: " + aUrl);
38: }
39: return aUrlEncode;
40: }
41:
42: public static URL handle(String aUrl) {
43: URL theSource = null;
44: if (theSource == null) {
45: try {
46: SwingMLRenderer theRenderer = SwingMLRenderer
47: .getRenderer();
48: URL theDocumentBase = theRenderer.getDocumentBase();
49: theSource = new URL(theDocumentBase, aUrl);
50: } catch (MalformedURLException e) {
51: SwingMLLogger.getInstance().log(e);
52: }
53: }
54: return theSource;
55: }
56: }
|