[ http://mc4j.org/jira/browse/STS-421?page=comments#action_10832 ] 
            
Jan Moravec commented on STS-421:
---------------------------------

Ops, it seems that JIRA mixes up file comments with normal comments. Anyway.

I am currently very short of time and stressed with my projects. So I am afraid 
I cannot possibly devote any time to patching 1.5. We are still on 1.4.3 and 
that's where I implemented the desired functionality by extending the 
stripes:form tag and adding additional attributes to adjust the form's action 
URL. I have not customized stripes:url and stripes:link tags because I can 
currently live with the customized form tag.

I am attaching the source code for the customized stripes:form tag just in case 
anyone wants to take this further and create a patch for 1.5.

The customized form tag calls a URL normalization method outside the attached 
FormTag.java source. This is the normalization method as it stands right now:

 /**
   * Normalizes the specified URL.
   *
   * @param url an input URL.
   * @return the normalized URL.
   * @see #normalizeUrl(java.net.URL)
   */
  public static URL normalizeUrl( String url )
  {
    try
    {
      return normalizeUrl( new URL( url ) );
    }
    catch ( MalformedURLException e )
    {
      throw new IllegalArgumentException( "Invalid URL: " + url, e );
    }
  }


  /**
   * Normalizes the specified URL by:
   * <ol>
   * <li>Converting the host name and protocol
   * name to lower-case.</li>
   * <li>Dropping the port number in case it is a default port number
   * for the specified protocol.</li>
   * <li>If the input URL's file path is set to &quot;/&quot;, then it is 
removed.</li>
   * <li>The input URL's ref path is disregarded.</li>
   * <li>The input URL's user info path is disregarded.</li>
   * </ol>
   *
   * @param url an input URL.
   * @return the normalized URL.
   */
  public static URL normalizeUrl( URL url )
  {
    String protocol = url.getProtocol().toLowerCase();
    String host = url.getHost().toLowerCase();

    // if a standard port is used, set port to -1
    int port = url.getPort();
    if ( ( port == WebConst.URL_STANDARD_PORT_HTTP && 
WebConst.URL_SCHEME_HTTP.equals( protocol ) ) ||
        ( port == WebConst.URL_STANDARD_PORT_HTTPS && 
WebConst.URL_SCHEME_HTTPS.equals( protocol ) ) )
      port = -1;

    String file = url.getFile();
    if ( "/".equals( file ) )
      file = CommonConst.EMPTY_STRING;

    try
    {
      return new URL( protocol, host, port, file );
    }
    catch ( MalformedURLException e )
    {
      throw new ShouldNeverHappenException( "Error normalizing URL: " + url, e 
);
    }
  }

Jan

> Support for protocol, host, port and context stripes:form, stripes:link and 
> stripes:url tags
> --------------------------------------------------------------------------------------------
>
>                 Key: STS-421
>                 URL: http://mc4j.org/jira/browse/STS-421
>             Project: Stripes
>          Issue Type: Improvement
>          Components: Tag Library
>    Affects Versions: Release 1.4.3
>            Reporter: Jan Moravec
>         Assigned To: Tim Fennell
>            Priority: Minor
>         Attachments: FormTag.java
>
>
> It would be great if stripes:form, stripes:link and stripes:url tags 
> supported additional attributes to make the rendered URL absolute. This is 
> very handy in situations when the user is on a page that got loaded via HTTP 
> and you need to point them to an action over HTTPS. 
> This is very common for title pages containing user login forms that should 
> be submitted over HTTPS. Redirecting the user to HTTPS as soon as they hit 
> the title page is not desirable. Most of the functionality on the title page 
> is typically available to non-authenticated users and there is no need to 
> further stress the HTTP server with unnecessary HTTPS traffic.
> Stripes tags should be intelligent enough to calculate sane defaults (e.g. if 
> protocol="https" is specified and no port is specified, then the port should 
> be set  to 443) and normalize the generated URLs (when a standard port is 
> used for the chosen protocol, then the port number is dropped from the URL).
> According to the reactions on the mailing list (search for "Force HTTPS for 
> submit"), there are users who would appreciate this functionality.
> I have already implemented an extension of the stripes:form tag + 
> normalization routines etc. to support the 4 above-mentioned attributes so I 
> can possibly extract the relevant code and post it.
> Jan

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://mc4j.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to