001: /*
002: * ====================================================================
003: * JAFFA - Java Application Framework For All
004: *
005: * Copyright (C) 2002 JAFFA Development Group
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * Redistribution and use of this software and associated documentation ("Software"),
022: * with or without modification, are permitted provided that the following conditions are met:
023: * 1. Redistributions of source code must retain copyright statements and notices.
024: * Redistributions must also contain a copy of this document.
025: * 2. Redistributions in binary form must reproduce the above copyright notice,
026: * this list of conditions and the following disclaimer in the documentation
027: * and/or other materials provided with the distribution.
028: * 3. The name "JAFFA" must not be used to endorse or promote products derived from
029: * this Software without prior written permission. For written permission,
030: * please contact mail to: jaffagroup@yahoo.com.
031: * 4. Products derived from this Software may not be called "JAFFA" nor may "JAFFA"
032: * appear in their names without prior written permission.
033: * 5. Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net).
034: *
035: * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: */
049:
050: /*
051: * URLHelperTest.java
052: *
053: * Created on May 3, 2002, 8:33 AM
054: */
055:
056: package org.jaffa.util;
057:
058: import javax.servlet.*;
059: import javax.servlet.http.*;
060: import org.jaffa.util.URLHelper;
061:
062: /**
063: *
064: * @author paule
065: * @version
066: */
067: public class URLHelperTest extends HttpServlet {
068:
069: /** Initializes the servlet.
070: */
071: public void init(ServletConfig config) throws ServletException {
072: super .init(config);
073:
074: }
075:
076: /** Destroys the servlet.
077: */
078: public void destroy() {
079:
080: }
081:
082: /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
083: * @param request servlet request
084: * @param response servlet response
085: */
086: protected void processRequest(HttpServletRequest request,
087: HttpServletResponse response) throws ServletException,
088: java.io.IOException {
089: response.setContentType("text/html");
090: java.io.PrintWriter out = response.getWriter();
091:
092: out.println("<html>");
093: out.println("<head>");
094: out.println("<title>URL Test</title>");
095: out.println("</head>");
096: out.println("<body>");
097:
098: try {
099: String a = "classpath:///org/jaffa/config/framework.properties";
100: out.println("URL: " + a);
101: out.println("<br>");
102: out.println("Real URL: "
103: + URLHelper.newExtendedURL(a).toExternalForm());
104: out.println("<br>");
105:
106: String b = "webroot:///index.html";
107: out.println("URL: " + b);
108: out.println("<br>");
109: out.println("Real URL: "
110: + URLHelper.newExtendedURL(b).toExternalForm());
111: out.println("<br>");
112:
113: String c = "file:///index.html";
114: out.println("URL: " + c);
115: out.println("<br>");
116: out.println("Real URL: "
117: + URLHelper.newExtendedURL(c).toExternalForm());
118: out.println("<br>");
119: } catch (Exception e) {
120: e.printStackTrace();
121: }
122:
123: out.println("</body>");
124: out.println("</html>");
125: out.close();
126: }
127:
128: /** Handles the HTTP <code>GET</code> method.
129: * @param request servlet request
130: * @param response servlet response
131: */
132: protected void doGet(HttpServletRequest request,
133: HttpServletResponse response) throws ServletException,
134: java.io.IOException {
135: processRequest(request, response);
136: }
137:
138: /** Handles the HTTP <code>POST</code> method.
139: * @param request servlet request
140: * @param response servlet response
141: */
142: protected void doPost(HttpServletRequest request,
143: HttpServletResponse response) throws ServletException,
144: java.io.IOException {
145: processRequest(request, response);
146: }
147:
148: /** Returns a short description of the servlet.
149: */
150: public String getServletInfo() {
151: return "Short description";
152: }
153:
154: }
|