/** * Check if this request uses a Cookie based session handling (meaning cookies * are enabled) or whether the session ID needs to be appended to a URL. * * @return <code>true</code> if the session ID is passed via cookies. */ default boolean areCookiesEnabled () { // Just check whether the session ID is appended to the URL or not return "a".equals (encodeURL ("a")); }
@Nonnull public SimpleURL buildURL (@Nullable final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull @Nonempty final String sBasePath, @Nullable final Locale aDisplayLocale, @Nullable final String sMenuItemID) { final StringBuilder aFullPath = new StringBuilder (sBasePath); if (aDisplayLocale != null) aFullPath.append ('/').append (aDisplayLocale.toString ()); if (StringHelper.hasText (sMenuItemID)) aFullPath.append ('/').append (sMenuItemID); final String sFullPath = aFullPath.toString (); return new SimpleURL (aRequestScope != null ? aRequestScope.encodeURL (sFullPath) : sFullPath); }
@Nonnull public SimpleURL buildURL (@Nullable final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull @Nonempty final String sBasePath, @Nullable final Locale aDisplayLocale, @Nullable final String sMenuItemID) { final StringBuilder aFullPath = new StringBuilder (sBasePath); // Encode into path if (aDisplayLocale != null) aFullPath.append ('/') .append (getRequestParamNameLocale ()) .append (m_sSeparator) .append (aDisplayLocale.toString ()); if (StringHelper.hasText (sMenuItemID)) aFullPath.append ('/').append (getRequestParamNameMenuItem ()).append (m_sSeparator).append (sMenuItemID); final String sFullPath = aFullPath.toString (); return new SimpleURL (aRequestScope != null ? aRequestScope.encodeURL (sFullPath) : sFullPath); }
@Nonnull public SimpleURL buildURL (@Nullable final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull @Nonempty final String sBasePath, @Nullable final Locale aDisplayLocale, @Nullable final String sMenuItemID) { // Add menu item parameter as URL parameter final SimpleURL ret = new SimpleURL (aRequestScope != null ? aRequestScope.encodeURL (sBasePath) : sBasePath); if (aDisplayLocale != null) ret.add (getRequestParamNameLocale (), aDisplayLocale.toString ()); if (StringHelper.hasText (sMenuItemID)) ret.add (getRequestParamNameMenuItem (), sMenuItemID); return ret; }
/** * Prefix the passed href with the relative context path in case the passed * href has no protocol yet. * * @param aRequestScope * The request web scope to be used. Required for cookie-less handling. * May not be <code>null</code>. * @param sHRef * The href to be extended. May not be <code>null</code>. * @return Either the original href if already absolute or * <code>/webapp-context/<i>href</i></code> otherwise. Never * <code>null</code>. */ @Nonnull public static String getURIWithContext (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final String sHRef) { ValueEnforcer.notNull (aRequestScope, "RequestScope"); ValueEnforcer.notNull (sHRef, "HRef"); // If known protocol, keep it if (hasKnownProtocol (sHRef)) return sHRef; final String sContextPath = aRequestScope.getContextPath (); return aRequestScope.encodeURL (_getURIWithContext (sContextPath, sHRef)); }
/** * Encodes the specified URL by including the session ID in it, or, if * encoding is not needed, returns the URL unchanged. The implementation of * this method includes the logic to determine whether the session ID needs to * be encoded in the URL. For example, if the browser supports cookies, or * session tracking is turned off, URL encoding is unnecessary. * <p> * For robust session tracking, all URLs emitted by a servlet should be run * through this method. Otherwise, URL rewriting cannot be used with browsers * which do not support cookies. * * @param aURL * the url to be encoded. May not be <code>null</code>. * @return the encoded URL if encoding is needed. Never <code>null</code>. */ @Nonnull default ISimpleURL encodeURL (@Nonnull final ISimpleURL aURL) { ValueEnforcer.notNull (aURL, "URL"); // Encode only the path and copy params and anchor return new SimpleURL (encodeURL (aURL.getPath ()), aURL.params (), aURL.getAnchor ()); }
/** * Prefix the passed href with the absolute server + context path in case the * passed href has no protocol yet. * * @param aRequestScope * The request web scope to be used. Required for cookie-less handling. * May not be <code>null</code>. * @param sHRef * The href to be extended. May not be <code>null</code>. * @return Either the original href if already absolute or * <code>http://servername:8123/webapp-context/<i>href</i></code> * otherwise. Never <code>null</code>. */ @Nonnull public static String getURIWithServerAndContext (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final String sHRef) { ValueEnforcer.notNull (aRequestScope, "RequestScope"); ValueEnforcer.notNull (sHRef, "HRef"); // If known protocol, keep it if (hasKnownProtocol (sHRef)) return sHRef; final String sContextPath = aRequestScope.getContextPath (); final String sURI = aRequestScope.getFullServerPath () + _getURIWithContext (sContextPath, sHRef); return aRequestScope.encodeURL (sURI); }