001package votorola.a.count; // Copyright 2010, 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. 002 003import java.util.regex.*; 004import org.apache.wicket.AttributeModifier; 005import org.apache.wicket.markup.html.*; 006import org.apache.wicket.markup.html.link.*; 007import org.apache.wicket.markup.html.panel.*; 008import votorola.a.*; 009import votorola.a.web.wic.*; 010import votorola.g.*; 011import votorola.g.lang.*; 012 013 014/** A small map of a polling division, linking to the division page in the pollwiki. 015 * 016 * @see <a href='../../../../../a/count/WC_DivisionSmallMap.html' target='_top'>WC_DivisionSmallMap.html</a> 017 * @see <a href='http://reluk.ca/w/Property:Small_map' target='_top' 018 * >zelea.com/w/Property:Small_map</a> 019 */ 020public @ThreadRestricted("wicket") final class WC_DivisionSmallMap extends Panel 021{ 022 023 024 /** Constructs a WC_DivisionSmallMap. 025 */ 026 public WC_DivisionSmallMap( String _id, final String divisionPageNameOrNull, 027 final String mapPageName, final VRequestCycle cycle ) 028 { 029 super( _id ); 030 setRenderBodyOnly( true ); 031 final VoteServer voteServer = VOWicket.get().vsRun().voteServer(); 032 033 final ExternalLink link; 034 if( divisionPageNameOrNull == null ) 035 { 036 link = new ExternalLink( "a", "." ); 037 link.setEnabled( false ); 038 } 039 else 040 { 041 link = new ExternalLink( "a", voteServer.pollwiki().encodePageSpecifier( 042 divisionPageNameOrNull ).build().toASCIIString() ); 043 } 044 add( link ); 045 046 final WebMarkupContainer img = new WebMarkupContainer( "img" ); 047 { 048 final MatchResult m = MediaWiki.parsePageName( mapPageName ); 049 if( m == null ) 050 { 051 throw new VotorolaRuntimeException( "malformed page name: " + mapPageName ); 052 } 053 054 img.add( AttributeModifier.replace( "src", voteServer.pollwiki().encodePageSpecifier( 055 "Special:FilePath/" + m.group( 2 ) ).build().toASCIIString() )); 056 } 057 link.add( img ); 058 } 059 060 061}