Coverage Report

##### Coverage Report - org.webmacro.servlet.URLTool

Classes in this File | Line Coverage | Branch Coverage | Complexity
URLTool |
0% | 0/6
N/A | N/A
| 1.8;1.8
URLTool$URLToolImpl |
0% | 0/13
0% | 0/2
| 1.8;1.8

1 |  |
     /*
2 |  |
      * Copyright (C) 1998-2000 Semiotek Inc.  All Rights Reserved.
3 |  |
      *
4 |  |
      * Redistribution and use in source and binary forms, with or without
5 |  |
      * modification, are permitted under the terms of either of the following
6 |  |
      * Open Source licenses:
7 |  |
      *
8 |  |
      * The GNU General Public License, version 2, or any later version, as
9 |  |
      * published by the Free Software Foundation
10 |  |
      * (http://www.fsf.org/copyleft/gpl.html);
11 |  |
      *
12 |  |
      *  or
13 |  |
      *
14 |  |
      * The Semiotek Public License (http://webmacro.org/LICENSE.)
15 |  |
      *
16 |  |
      * This software is provided "as is", with NO WARRANTY, not even the
17 |  |
      * implied warranties of fitness to purpose, or merchantability. You
18 |  |
      * assume all risks and liabilities associated with its use.
19 |  |
      *
20 |  |
      * See www.webmacro.org for more information on the WebMacro project.
21 |  |
      */
22 |  |
23 |  |
24 |  |
     package org.webmacro.servlet;
25 |  |
26 |  |
     import org.webmacro.Context;
27 |  |
     import org.webmacro.ContextTool;
28 |  |
     import org.webmacro.PropertyException;
29 |  |
30 |  |
     import javax.servlet.http.HttpServletRequest;
31 |  |
32 |  |
     /**
33 |  |
      * Provide Template with access to url handing routines.
34 |  |
      * @author Sebastian Kanthak (mailto:skanthak@muehlheim.de)
35 |  |
      */
36 | 0 |
     public class URLTool extends ContextTool
37 |  |
     {
38 |  |
39 |  |
         /**
40 |  |
          * Tool implementation.
41 |  |
          */
42 | 0 |
         public class URLToolImpl
43 |  |
         {
44 |  |
45 |  |
             private final WebContext context;
46 |  |
47 |  |
             public URLToolImpl (WebContext context)
48 | 0 |
             {
49 | 0 |
                 super();
50 | 0 |
                 this.context = context;
51 | 0 |
             }
52 |  |
53 |  |
             /**
54 |  |
              * Get the url that was used to access this page,
55 |  |
              * as it is returned by HttpUtils.getRequestURL.
56 |  |
              * @return URL used to access this page without query string
57 |  |
              */
58 |  |
             public String getRequestURL ()
59 |  |
             {
60 | 0 |
                 return context.getRequest().getRequestURL().toString();
61 |  |
             }
62 |  |
63 |  |
             /**
64 |  |
              * Return the complete url, that was used to access this page
65 |  |
              * including path_info and query_string if present.
66 |  |
              * <br>
67 |  |
              * This method uses HttpUtils.getRequestURL to
68 |  |
              * create the url and appends query_string if not null
69 |  |
              * @return URL used to access this page, including query string
70 |  |
              */
71 |  |
             public String getCompleteRequestURL ()
72 |  |
             {
73 | 0 |
                 HttpServletRequest req = context.getRequest();
74 | 0 |
                 StringBuffer b = req.getRequestURL();
75 | 0 |
                 String query = req.getQueryString();
76 | 0 |
                 if (query != null)
77 |  |
                 {
78 | 0 |
                     b.append("?");
79 | 0 |
                     b.append(query);
80 |  |
                 }
81 | 0 |
                 return b.toString();
82 |  |
             }
83 |  |
84 |  |
             public String encode (String url)
85 |  |
             {
86 | 0 |
                 return context.getResponse().encodeURL(url);
87 |  |
             }
88 |  |
         }
89 |  |
90 |  |
         public Object init (Context context) throws PropertyException
91 |  |
         {
92 |  |
             try
93 |  |
             {
94 | 0 |
                 WebContext wc = (WebContext) context;
95 | 0 |
                 return new URLToolImpl(wc);
96 |  |
             }
97 | 0 |
             catch (ClassCastException ce)
98 |  |
             {
99 | 0 |
                 throw new PropertyException("URLTool only works with WebContext", ce);
100 |  |
             }
101 |  |
         }
102 |  |
103 |  |
     }