package votorola.a.position; // Copyright 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. import java.io.*; import java.util.regex.*; import javax.mail.internet.*; import votorola.a.*; import votorola.a.voter.*; import votorola.g.*; import votorola.g.lang.*; /** A particular revision of a component pipe. * * @see Category:Component pipe */ public @ThreadSafe abstract class ComponentPipeRevision extends PageRevision1 implements PipeRevision { /** Constructs a ComponentPipeRevision. */ ComponentPipeRevision( final PollwikiVS wiki, int _pageID, String _pageName, int _rev, int _revLatest, final String nomineeName, final String personName, String _pollName ) throws MalformedContent { super( wiki.scriptURI(), _pageID, _pageName, _rev, _revLatest, wiki.uri().toASCIIString(), wiki.maybeUgly() ); if( "Anonymous".equals( nomineeName )) { throw new MalformedContent( "anonymous nominee disallowed", wiki, rev() ); // unlike office pipe; no point allowing here till its clear what kind of // behaviour would be expected } try{ nominee = IDPair.fromUsername( nomineeName ); } catch( final AddressException x ) { throw new MalformedContent( "nominee username is not mailish: " + nomineeName, x, wiki, rev() ); } try{ person = IDPair.fromUsername( personName ); } catch( final AddressException x ) { throw new MalformedContent( "pipe name is not mailish: " + personName, x, wiki, rev() ); } pollName = _pollName; } /** Constructs a ComponentPipeRevision as a copy of another. */ ComponentPipeRevision( final ComponentPipeRevision rCP ) { super( rCP ); nominee = rCP.nominee; person = rCP.person; pollName = rCP.pollName; } // ------------------------------------------------------------------------------------ /** The search pattern for the definitive template call in a component pipe page. If * the pattern matches, then it splits the wikitext of the call into groups based on * the template parameter values (1) nominee username and (2) poll name. This method * of extracting properties from a revision is required because SemanticMediawiki's * data store does not attach properties to revisions, only to pages. * * @see Category:Component_pipe * @see PipeRevision#TEMPLATE_CALL_PATTERN */ static final Pattern TEMPLATE_CALL_PATTERN = Pattern.compile( "\\{\\s*\\{\\s*[Cc]omponent pipe\\s*" + "(?:\\|\\s*.+?\\s*=\\s*.+?\\s*)*" // * + "\\|\\s*nominee\\s*=\\s*(.+?)\\s*" // NOMINEE USERNAME + "(?:\\|\\s*.+?\\s*=\\s*.+?\\s*)*" // * + "\\|\\s*poll\\s*=\\s*(.+?)\\s*" // POLL NAME + "(?:\\|\\s*.+?\\s*=\\s*.+?\\s*)*" // * + "\\}\\s*\\}" ); // * any other parameters are currently ignored // - C o m p o n e n t - P i p e - R e v i s i o n ------------------------------------ /** The nominee drafter. * * @see Property:Nominee */ public final IDPair nominee() { return nominee; } private final IDPair nominee; // - P o s i t i o n a l - R e v i s i o n -------------------------------------------- public final IDPair person() { return person; } private final IDPair person; public final String pollName() { return pollName; } private final String pollName; // ==================================================================================== /** Thrown when a request cannot be met because the content of a page is not in the * form required for a component pipe. */ static @ThreadSafe final class MalformedContent extends IOException implements UserInformative { MalformedContent( final String message, final PollwikiVS wiki, final int rev ) { super( message + " | " + MediaWiki.revLoc(wiki.scriptURI(),rev) ); } MalformedContent( final String message, Throwable _cause, final PollwikiVS wiki, final int rev ) { super( message + " | " + MediaWiki.revLoc(wiki.scriptURI(),rev), _cause ); } } }