package 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. import javax.ws.rs.core.UriBuilder; import votorola.a.*; import votorola.g.lang.*; /** A particular revision of a draft page. A draft revision is identified by a sequence * of one to {@value MAX_PATH_LENGTH} page revisions known as a draft revision path. The * path starts with a {@linkplain CoreRevision core revision} which alone suffices for a * simple {@linkplain LocalDraftRevision local draft} (path length of 1), while a longer * path is necessary to accomodate the indirection of a {@linkplain ComponentPipeRevision * component pipe} and/or {@linkplain PointerRevision remote-draft pointer}, both of * which extend the revision identity across multiple pages (path lengths of 2 to {@value * MAX_PATH_LENGTH}). * * @see Category:Draft */ public interface DraftRevision extends PositionalRevision { /** The maximum length of a revision path from the {@linkplain CoreRevision position * core} to the draft. */ public static final int MAX_PATH_LENGTH = 3; // ==================================================================================== /** DraftRevision utilities. */ public @ThreadSafe static final class U { private U() {} /** Constructs the URL of the draft for the named position core. * * @param core the pre-constructed core revision, or null if none actually * exists in the wiki, in which case this method returns the URL of the * core position page. * @param codesvrLoc the value of the gwt.codesvr query parameter, * or null to not append this parameter. If the user is known to be running * GWT in dev mode, then specify this to yield a URL that preserves dev mode. */ public static String resolveLocation( final PollwikiVS wiki, final String coreName, final CoreRevision core, final String codesvrLoc ) { final String loc; if( core == null ) { loc = wiki.encodePageSpecifier(coreName).build().toASCIIString(); } else { final DraftRevision draft = core.draft(); if( codesvrLoc == null ) loc = draft.pageURI().toASCIIString(); else { final UriBuilder ub = UriBuilder.fromUri( draft.pageURI().toASCIIString() ); ub.queryParam( "gwt.codesvr", codesvrLoc ); loc = ub.build().toASCIIString(); } } return loc; } } }