001package votorola.a.web.wic.authen; // Copyright 2008-2013, 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. 002 003import org.apache.wicket.markup.html.basic.Label; 004import org.apache.wicket.markup.html.form.TextField; 005import org.apache.wicket.markup.html.panel.Panel; 006import org.apache.wicket.model.PropertyModel; 007import votorola.a.web.wic.*; 008import votorola.g.lang.*; 009import votorola.g.locale.*; 010 011 012/** An alias test login option for a login page. It includes an HTML text field backed by a 013 * Java string field "aliasInput", which must be present in the login page. 014 * 015 * @see <a href='../../../../../../../a/web/wic/authen/WC_Alias.html' 016 * target='_top'>WC_Alias.html</a> 017 */ 018@ThreadRestricted("wicket") final class WC_Alias extends Panel 019{ 020 021 022 /** Constructs a WC_Alias. 023 * 024 * @param page the login page in which the option will appear. 025 */ 026 WC_Alias( final String id, final VPageHTML page, final VRequestCycle cycle ) 027 { 028 super( id ); 029 030 final BundleFormatter bun = cycle.bunW(); 031 add( new Label( "or", 032 bun.l( "a.web.wic.authen.WP_Login.or_XHT" )).setEscapeModelStrings( false )); 033 add( new Label( "or-test", bun.l( "a.web.wic.authen.WP_Login.or-test" ))); 034 add( new Label( "aliasLabel", bun.l( "a.web.wic.authen.WP_Login.alias" ))); 035 final TextField<String> field = new TextField<String>( "alias", 036 new PropertyModel<String>( page, "aliasInput" )); 037 VPageHTML.invalidStyled( VPageHTML.inputLengthConstrained( field )); 038 add( field ); 039 add( new Label( "aliasDescription", 040 bun.l( "a.web.wic.authen.WP_Login.aliasDescription" ))); 041 } 042 043 044 045 // ------------------------------------------------------------------------------------ 046 047 048 /** Converts a user's chosen alias to an email address. 049 */ 050 static @ThreadSafe String toEmail( final String alias ) 051 { 052 final StringBuilder b = new StringBuilder( 32 ); 053 for( int c = 0, cN = alias.length(); c < cN; ++c ) 054 { 055 if( b.length() >= 60 ) break; // max for local part actually 64, per qmail addresses(5) 056 057 char ch = alias.charAt( c ); 058 // ch = Character.toUpperCase( ch ); // make the aliases stand out in the UI 059 // if( (ch < '0' || ch > '9') && (ch < 'A' || ch > 'Z') ) ch = '-'; 060 //// not till I normalize them, currently that's a BUG (normalize?) 061 // ch = Character.toLowerCase( ch ); 062 // if( (ch < '0' || ch > '9') && (ch < 'a' || ch > 'z') ) ch = '-'; // potentially illegal 063 //// but allow mixed case, e.g. for descriptive naming of pseudo-pipes 064 if( (ch < '0' || ch > '9') 065 && (ch < 'A' || ch > 'Z') 066 && (ch < 'a' || ch > 'z') ) ch = '-'; // potentially illegal 067 b.append( ch ); 068 } 069 070 final String prefix = "test-"; 071 if( !b.toString().startsWith( prefix )) b.insert( 0, prefix ); 072 b.append( "@zelea.com" ); 073 return b.toString(); 074 } 075 076 077}