/** * Parses provided URI to the link. * * @param link URI representing path to piece of content * @return Link pointing to the content represented by provided URI */ public static Link parseLink(String link) throws LinkException { // ignore context handle if existing link = StringUtils.removeStart(link, MgnlContext.getContextPath()); Matcher matcher = LINK_PATTERN.matcher(link); if (matcher.matches()) { String orgHandle = matcher.group(1); orgHandle = Components.getComponent(I18nContentSupport.class).toRawURI(orgHandle); String workspaceName = getURI2RepositoryManager().getRepository(orgHandle); String handle = getURI2RepositoryManager().getHandle(orgHandle); return createLinkInstance(workspaceName, handle, matcher.group(3), matcher.group(5), matcher.group(7)); } throw new LinkException("can't parse [ " + link + "]"); }
@Test public void getHandleStripsExtensionInclTheDot() throws Exception { // GIVEN // WHEN // THEN assertThat(uri2RepositoryManager.getHandle("/blah.ext"), is("/blah")); assertThat(uri2RepositoryManager.getHandle("/b.l/ah.ext"), is("/b.l/ah")); assertThat(uri2RepositoryManager.getHandle("/bl.ah.ext"), is("/bl.ah")); }