BookmarkableUrlHelper { public static String registerOpenedScreen(String bookmarkableUrl, final PlaceRequest placeRequest) { final String screenName = placeRequest.getFullIdentifier(); final String closedScreen = CLOSED_PREFIX.concat(screenName); final String currentBookmarkableUrl = bookmarkableUrl; if (screenWasClosed(bookmarkableUrl, closedScreen)) { bookmarkableUrl = bookmarkableUrl.replace(closedScreen, screenName); } else if (!isPerspectiveInUrl(bookmarkableUrl)) { if (isNotBlank(bookmarkableUrl)) { bookmarkableUrl = bookmarkableUrl.concat(SEPARATOR).concat(screenName); } else { bookmarkableUrl = screenName; } } else { if (!urlContainsExtraPerspectiveScreen(bookmarkableUrl)) { bookmarkableUrl = bookmarkableUrl.concat(OTHER_SCREEN_SEP).concat(screenName); } else { bookmarkableUrl = bookmarkableUrl.concat(SEPARATOR).concat(screenName); } } if (isBiggerThenMaxURLSize(bookmarkableUrl)) { return currentBookmarkableUrl; } return bookmarkableUrl; }  static String registerOpenedScreen(String bookmarkableUrl,
                                              final PlaceRequest placeRequest); static String registerClose(String bookmarkableUrl,
                                       final String screenName); static PlaceRequest getPerspectiveFromPlace(PlaceRequest place); static boolean isPerspectiveScreen(final String bookmarkableUrl,
                                              final String screen); static boolean isPerspectiveInUrl(final String url); static boolean urlContainsExtraPerspectiveScreen(final String bookmarkableUrl); static String getUrlToken(final String bookmarkableUrl,
                                     final String screen); static Set<String> getDockedScreensFromUrl(final String url); static Set<String> getDockedScreensFromPlace(final PlaceRequest place); static Set<String> getScreensFromPlace(final PlaceRequest place); static Set<String> getClosedScreenFromPlace(final PlaceRequest place); static Set<String> getOpenedScreenFromPlace(final PlaceRequest place); static boolean isScreenClosed(final String bookmarkableUrl,
                                         String screen); static String registerOpenedPerspective(String currentBookmarkableURLStatus,
                                                   PlaceRequest place); static String registerOpenedDock(String currentBookmarkableURLStatus,
                                            UberfireDock targetDock); static String registerClosedDock(String currentBookmarkableURLStatus,
                                            UberfireDock targetDock); static String registerCloseEditor(final String currentBookmarkableURLStatus,
                                             final PlaceRequest place); final static String PERSPECTIVE_SEP; final static String DOCK_BEGIN_SEP; final static String DOCK_CLOSE_SEP; final static String SEPARATOR; final static String OTHER_SCREEN_SEP; final static String CLOSED_PREFIX; final static String CLOSED_DOCK_PREFIX; final static int MAX_NAV_URL_SIZE; }
@Test public void testRegisterOpen() { PlaceRequest req1 = new DefaultPlaceRequest("screen1"); PlaceRequest req2 = new DefaultPlaceRequest("screen2"); PlaceRequest req3 = new DefaultPlaceRequest("screen3"); PlaceRequest req4 = new DefaultPlaceRequest("screen4"); final String perspective = "perspective"; String url = ""; url = BookmarkableUrlHelper.registerOpenedScreen(url, req1); assertEquals(req1.getFullIdentifier(), url); url = BookmarkableUrlHelper.registerOpenedScreen(url, req2); assertEquals("screen1,screen2", url); url = perspective.concat(BookmarkableUrlHelper.PERSPECTIVE_SEP) .concat(url); url = BookmarkableUrlHelper.registerOpenedScreen(url, req3); assertEquals("perspective|screen1,screen2$screen3", url); url = BookmarkableUrlHelper.registerOpenedScreen(url, req4); assertEquals("perspective|screen1,screen2$screen3,screen4", url); final String closedScreen = "closedScreen"; final PlaceRequest closed = new DefaultPlaceRequest(closedScreen); url = "perspective|" .concat(BookmarkableUrlHelper.CLOSED_PREFIX) .concat(closedScreen).concat(",openScreen$externalScreen"); url = BookmarkableUrlHelper.registerOpenedScreen(url, closed); String expected = "perspective|" .concat(closedScreen).concat(",openScreen$externalScreen"); assertEquals(expected, url); StringBuilder bigUrl = new StringBuilder(perspective); while (bigUrl.length() < BookmarkableUrlHelper.MAX_NAV_URL_SIZE) { bigUrl.append(",screen"); } url = BookmarkableUrlHelper.registerOpenedScreen(bigUrl.toString(), req1); assertNotNull(url); assertEquals(bigUrl.toString(), url); }