001package votorola.a.position; // Copyright 2011-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 javax.ws.rs.core.UriBuilder; 004import votorola.a.*; 005import votorola.g.lang.*; 006 007 008/** A particular revision of a draft page. A draft revision is identified by a sequence 009 * of one to {@value MAX_PATH_LENGTH} page revisions known as a draft revision path. The 010 * path starts with a {@linkplain CoreRevision core revision} which alone suffices for a 011 * simple {@linkplain LocalDraftRevision local draft} (path length of 1), while a longer 012 * path is necessary to accomodate the indirection of a {@linkplain ComponentPipeRevision 013 * component pipe} and/or {@linkplain PointerRevision remote-draft pointer}, both of 014 * which extend the revision identity across multiple pages (path lengths of 2 to {@value 015 * MAX_PATH_LENGTH}). 016 * 017 * @see <a href='http://reluk.ca/w/Category:Draft' target='_top'>Category:Draft</a> 018 */ 019public interface DraftRevision extends PositionalRevision 020{ 021 022 023 /** The maximum length of a revision path from the {@linkplain CoreRevision position 024 * core} to the draft. 025 */ 026 public static final int MAX_PATH_LENGTH = 3; 027 028 029 030 // ==================================================================================== 031 032 033 /** DraftRevision utilities. 034 */ 035 public @ThreadSafe static final class U 036 { 037 038 private U() {} 039 040 041 /** Constructs the URL of the draft for the named position core. 042 * 043 * @param core the pre-constructed core revision, or null if none actually 044 * exists in the wiki, in which case this method returns the URL of the 045 * core position page. 046 * @param codesvrLoc the value of the <code>gwt.codesvr</code> query parameter, 047 * or null to not append this parameter. If the user is known to be running 048 * GWT in dev mode, then specify this to yield a URL that preserves dev mode. 049 */ 050 public static String resolveLocation( final PollwikiVS wiki, final String coreName, 051 final CoreRevision core, final String codesvrLoc ) 052 { 053 final String loc; 054 if( core == null ) 055 { 056 loc = wiki.encodePageSpecifier(coreName).build().toASCIIString(); 057 } 058 else 059 { 060 final DraftRevision draft = core.draft(); 061 if( codesvrLoc == null ) loc = draft.pageURI().toASCIIString(); 062 else 063 { 064 final UriBuilder ub = UriBuilder.fromUri( draft.pageURI().toASCIIString() ); 065 ub.queryParam( "gwt.codesvr", codesvrLoc ); 066 loc = ub.build().toASCIIString(); 067 } 068 } 069 return loc; 070 } 071 072 } 073 074 075}