/** * Returns true if the sitemap contains the URI represented by virtual page part of {@code navigationState}. * * @param navigationState the NavigationState which contains the uri to check * @return */ @Override public synchronized boolean hasUri(NavigationState navigationState) { return uriMap.containsKey(navigationState.getVirtualPage()); }
/** * Returns the {@link SitemapNode} associated with {@code navigationState}, or null if none found * * @param navigationState * @return */ @Override public synchronized T nodeFor(NavigationState navigationState) { if (navigationState == null) { return null; } return uriMap.get(navigationState.getVirtualPage()); }
/** * Returns true if the sitemap contains the URI represented by virtual page part of {@code navigationState}. * * @param navigationState the NavigationState which contains the uri to check * @return */ @Override public synchronized boolean hasUri(NavigationState navigationState) { return uriMap.containsKey(navigationState.getVirtualPage()); }
private boolean isStandardUri(StandardPageKey key, NavigationState navigationState) { return key == (uriStandardPages.get(navigationState.getVirtualPage())); }
/** * Returns the {@link SitemapNode} associated with {@code navigationState}, or null if none found * * @param navigationState * @return */ @Override public synchronized T nodeFor(NavigationState navigationState) { if (navigationState == null) { return null; } return uriMap.get(navigationState.getVirtualPage()); }
private boolean isStandardUri(StandardPageKey key, NavigationState navigationState) { return key == (uriStandardPages.get(navigationState.getVirtualPage())); }
/** * If the virtual page represented by {@code navigationState} has been redirected, return the page it has been * redirected to, otherwise, just return the virtual page unchanged. Allows for multiple levels of redirect. * * @param navigationState the navigationState to assess * @return */ @Override public synchronized String getRedirectPageFor(NavigationState navigationState) { String virtualPage = navigationState.getVirtualPage(); return getRedirectPageFor(virtualPage); }
/** * Returns the {@link SitemapNode} associated with {@code uri}, or null if none found * * @param uri * @return */ @Override public synchronized T nodeFor(String uri) { return uriMap.get(uriHandler.navigationState(uri) .getVirtualPage()); }
/** * Returns the {@link SitemapNode} associated with {@code uri}, or null if none found * * @param uri * @return */ @Override public synchronized T nodeFor(String uri) { return uriMap.get(uriHandler.navigationState(uri) .getVirtualPage()); }
/** * If the virtual page represented by {@code navigationState} has been redirected, return the page it has been * redirected to, otherwise, just return the virtual page unchanged. Allows for multiple levels of redirect. * * @param navigationState the navigationState to assess * @return */ @Override public synchronized String getRedirectPageFor(NavigationState navigationState) { String virtualPage = navigationState.getVirtualPage(); return getRedirectPageFor(virtualPage); }
/** * Creates a Permission object from the uri fragment held in {@code navigationState}. The '/' characters are * changed * to ':' to facilitate use of Shiro WildcardPermission. If {@code appendWildCard} is true, a final ':*' is added. * The fill translation is, for example, for a URI of:<br> * <br> * <i>private/deptx/teamy/current projects</i> becomes a Shiro permission of <br> * <br> * <i>uri:view:private:deptx:teamy:current projects</i> with no wildcard, or <br> * <br> * <i>uri:view:private:deptx:teamy:current projects:*</i> with a wildcard * * @param navigationState * @param appendWildcard * @return */ protected final void construct(NavigationState navigationState, boolean appendWildcard, boolean edit) { construct(navigationState.getVirtualPage(), appendWildcard, edit); }
@Override public String fragment(NavigationState navigationState) { StringBuilder buf = new StringBuilder(); if (useBang) { buf.append('!'); } String vp = navigationState.getVirtualPage() == null ? virtualPageFromSegments(navigationState.getPathSegments()) : navigationState.getVirtualPage(); buf.append(vp); // append the parameters for (Map.Entry<String, String> entry : navigationState.getParameters() .entrySet()) { buf.append('/'); buf.append(entry.getKey()); buf.append('='); buf.append(entry.getValue()); } return buf.toString(); }
private void validateSegments(NavigationState navigationState) { if (navigationState.getVirtualPage() == null) { String virtualPage = virtualPageFromSegments(navigationState.getPathSegments()); navigationState.virtualPage(virtualPage); } else if (navigationState.getPathSegments() .isEmpty()) { navigationState.pathSegments(segmentsFromVirtualPage(navigationState.getVirtualPage())); } }
private void validateSegments(NavigationState navigationState) { if (navigationState.getVirtualPage() == null) { String virtualPage = virtualPageFromSegments(navigationState.getPathSegments()); navigationState.virtualPage(virtualPage); } else if (navigationState.getPathSegments() .isEmpty()) { navigationState.pathSegments(segmentsFromVirtualPage(navigationState.getVirtualPage())); } }
/** * Checks {@code navigationState} to see whether the {@link Sitemap} defines this as a page which should be * redirected. If it is, {@code navigationState} is modified, modified for the redirected page. If no * redirection is required, the {@code navigationState} is returned unchanged. * * @param navigationState the proposed navigation state before considering redirection */ private void redirectIfNeeded(NavigationState navigationState) { String page = navigationState.getVirtualPage(); String redirection = userSitemap.getRedirectPageFor(page); // if no redirect found, do nothing if (!redirection.equals(page)) { navigationState.virtualPage(redirection) .update(uriHandler); } }
/** * Checks {@code navigationState} to see whether the {@link Sitemap} defines this as a page which should be * redirected. If it is, {@code navigationState} is modified, modified for the redirected page. If no * redirection is required, the {@code navigationState} is returned unchanged. * * @param navigationState the proposed navigation state before considering redirection */ private void redirectIfNeeded(NavigationState navigationState) { String page = navigationState.getVirtualPage(); String redirection = userSitemap.getRedirectPageFor(page); // if no redirect found, do nothing if (!redirection.equals(page)) { navigationState.virtualPage(redirection) .update(uriHandler); } }
@Test public void add_child_standard_page_child() { //given when(navState.getVirtualPage()).thenReturn("public/home"); MasterSitemapNode parent = new MasterSitemapNode(1, "public", TestLabelKey.Yes, PUBLIC, -1, PublicHomeView.class); MasterSitemapNode child = new MasterSitemapNode(2, "home", StandardPageKey.Public_Home, PUBLIC, -1, PublicHomeView.class); //when sitemap.addChild(parent, child); //then assertThat(sitemap.getStandardPages()).containsKey(StandardPageKey.Public_Home); assertThat(sitemap.standardPageNode(StandardPageKey.Public_Home)).isEqualTo(child); assertThat(sitemap.isPublicHomeUri(navState)).isTrue(); assertThat(sitemap.isPrivateHomeUri(navState)).isFalse(); }
/** * AddChild should add standard page if it is one */ @Test public void add_child_standard_page_parent() { //given when(navState.getVirtualPage()).thenReturn("public"); MasterSitemapNode parent = new MasterSitemapNode(1, "public", StandardPageKey.Public_Home, PUBLIC, -1, PublicHomeView.class); MasterSitemapNode child = new MasterSitemapNode(2, "home", TestLabelKey.Yes, PUBLIC, -1, PublicHomeView.class); //when sitemap.addChild(parent, child); //then assertThat(sitemap.getStandardPages()).containsKey(StandardPageKey.Public_Home); assertThat(sitemap.standardPageNode(StandardPageKey.Public_Home)).isEqualTo(parent); assertThat(sitemap.isPublicHomeUri(navState)).isTrue(); assertThat(sitemap.isPrivateHomeUri(navState)).isFalse(); }
@Test public void setVirtualPage() { // given uriHandler.setUseBang(false); NavigationState navigationState = uriHandler.navigationState(home_p2); // when navigationState.virtualPage("view2") .update(uriHandler); String fragment = uriHandler.fragment(navigationState); // then assertThat(fragment).isEqualTo("view2/a=b/year=1970"); assertThat(navigationState.getVirtualPage()).isEqualTo("view2"); assertThat(navigationState.getParameterList()).containsOnly("a=b", "year=1970"); }
@Test public void remove_node_removes_standard_page() { when(navState.getVirtualPage()).thenReturn("public/home"); MasterSitemapNode parent = new MasterSitemapNode(1, "public", TestLabelKey.Yes, PUBLIC, -1, PublicHomeView.class); MasterSitemapNode child = new MasterSitemapNode(2, "home", StandardPageKey.Public_Home, PUBLIC, -1, PublicHomeView.class); //when sitemap.addChild(parent, child); //then assertThat(sitemap.getStandardPages()).containsKey(StandardPageKey.Public_Home); assertThat(sitemap.getStandardPageUris()).containsKey("public/home"); //when sitemap.removeNode(child); //then assertThat(sitemap.getStandardPages()).doesNotContainKey(StandardPageKey.Public_Home); assertThat(sitemap.getStandardPageUris()).doesNotContainKey("public/home"); }