package votorola.a.web.wic; // Copyright 2008-2009, 2012, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import java.net.*; import java.util.*; import javax.servlet.http.*; import votorola.g.lang.*; import votorola.g.locale.*; import votorola.g.util.*; import org.apache.wicket.*; import org.apache.wicket.protocol.http.RequestUtils; import org.apache.wicket.request.Response; import org.apache.wicket.request.cycle.*; import org.apache.wicket.request.http.*; import org.apache.wicket.request.mapper.parameter.PageParameters; /** A request cycle in the Wicket web interface. */ public final @ThreadRestricted("wicket") class VRequestCycle extends RequestCycle implements BundleFormatter.GProvider { /** Constructs a VRequestCycle. */ VRequestCycle( RequestCycleContext _context ) { super( _context ); final Locale loc = getRequest().getLocale(); final ResourceBundle.Control c = new BundleControlU(); bunA = new BundleFormatter( ResourceBundle.getBundle( "votorola.a.locale.A", loc, c )); bunG = new BundleFormatter( ResourceBundle.getBundle( "votorola.g.locale.G", loc, c )); bunW = new BundleFormatter( ResourceBundle.getBundle( "votorola.a.locale.W", loc, c )); } // ------------------------------------------------------------------------------------ /** Returns the URI of the preferred context for fetching static GWT scripts. This is * either the configured VOWicket.{@linkplain VOWicket#mirroredContextURI() * mirroredContextURI}() or the absolute path to the context on the local container. * * @see #staticContextLocation() */ public String gwtContextLocation() { // return vRequest().getContextPath(); ////// // But if we run a cross-site linker (xs or xsiframe) then we can do this: return staticContextLocation(); ////// // That could be a server or port other than the page origin. The browser's "same // origin" security policy won't allow GWT's ordinary linker to load its scripts from // there, apparently because the iframe it uses establishes a separate document with // its own origin. We might get around that by setting the document's "domain" // property (not sure), but that would have to be a config option under admin control // in any case. } /** Returns the URI of the preferred location for fetching static files. This is * either the configured VOWicket.{@linkplain VOWicket#mirroredContextURI() * mirroredContextURI}() or the absolute path to the context on the local container. * * @see #gwtContextLocation() */ public String staticContextLocation() { final URI uri = VOWicket.get().mirroredContextURI(); return uri == null? vRequest().getContextPath(): uri.toASCIIString(); } // /** Returns the page to be rendered for the current request in cases where the last // * sheduled handler is of type // * {@linkplain IComponentRequestHandler IComponentRequestHandler}, // * {@linkplain IPageClassRequestHandler IPageClassRequestHandler}, or // * {@linkplain IPageRequestHandler IPageRequestHandler}. // * This method replicates the behaviour of getResponsePage() in Wicket 1.4, // * which was removed in 1.5. // * // * @see 1.4 API for RequestCycle.getResponsePage() // */ // public final Page responsePage() { throw new UnsupportedOperationException(); } // // // private volatile Page responsePage; // // { // // Following advice: // // https://issues.apache.org/jira/browse/WICKET-3643 // // https://cwiki.apache.org/WICKET/requestcycle-in-wicket-15.html // getListeners().add( new AbstractRequestCycleListener() // { // public @Override @ThreadSafe void onRequestHandlerScheduled( // final RequestCycle cycle, final IRequestHandler handler ) // { // assert cycle == VRequestCycle.this; // NOT YET CODED // } // }); // } /// Left off coding when I realized the clients for this are dead code. Keep for reference. /** Constructs an absolute, normalized URI for a bookmarkable page. * * @see #urlFor(Class,PageParameters) * @see org.apache.wicket.Component#urlFor(Class,PageParameters) */ public URI uriFor( Class pageClass ) { return uriFor( pageClass, /*parameters*/null ); } /** Constructs an absolute, normalized URI for a bookmarkable page with parameters. * * @see #urlFor(Class,PageParameters) * @see org.apache.wicket.Component#urlFor(Class,PageParameters) */ public URI uriFor( Class pageClass, PageParameters parameters ) { CharSequence cS = urlFor( pageClass, parameters ); // relative (1.3 and 1.5) and not bookmarkable as docs claim; while mapUrlFor is apparently relative too, though always to filter base cS = RequestUtils.toAbsolutePath( // so correct it ((HttpServletRequest)vRequest().getContainerRequest()).getRequestURL().toString(), cS.toString() ); try { final URI uri = new URI( cS.toString() ); return uri.normalize(); // chop trailing dot segments, '././' - seen for Application.getHomePage() } catch( URISyntaxException x ) { throw new RuntimeException( x ); } } /** Constructs an absolute URI for the context path, without a trailing slash (/). * * @see HttpServletRequest#getContextPath() */ public URI uriForContextPath() { final HttpServletRequest sR = (HttpServletRequest)vRequest().getContainerRequest(); final StringBuilder b = new StringBuilder(); final String scheme = sR.getScheme(); b.append( scheme ).append( "://" ).append( sR.getServerName() ); final int port = sR.getServerPort(); if( !scheme.equals("http") || port != 80 ) b.append( ':' ).append( port ); b.append( sR.getContextPath() ); try{ return new URI( b.toString() ); } catch( URISyntaxException x ) { throw new RuntimeException( x ); } } /** @see #getRequest() */ public WebRequest vRequest() { return (WebRequest)getRequest(); } // vX not getX, per VSession.vApplication /** @see #getOriginalResponse() */ public WebResponse vResponse() { return (WebResponse)getOriginalResponse(); } // vX not getX, per VSession.vApplication // - B u n d l e - F o r m a t t e r . G - P r o v i d e r - ( e t c . ) -------------- /** The application (A) bundle formatter. It uses bundle base name * 'votorola.a.locale.A'. * * @see * locale/A.properties */ public BundleFormatter bunA() { return bunA; } private final BundleFormatter bunA; public BundleFormatter bunG() { return bunG; } private final BundleFormatter bunG; /** The web (W) bundle formatter. It uses bundle base name 'votorola.a.locale.W'. * * @see * locale/W.properties */ public BundleFormatter bunW() { return bunW; } private final BundleFormatter bunW; // /** Constructs a bundle formatter for the component's locale. // */ // public static BundleFormatter newBun( Component component ) // { // return new BundleFormatter( component.getLocale(), "votorola.a.locale.W" ); // } // - R e q u e s t - C y c l e -------------------------------------------------------- public static VRequestCycle get() { return (VRequestCycle)RequestCycle.get(); } }