@Test public void whenRequestingTheHandleMakeSureItIsNotAppendedTwice() throws Exception { // GIVEN final String uri = "/travel"; final URI2RepositoryMapping mapping = new URI2RepositoryMapping(); mapping.setHandlePrefix("/travel"); mapping.setURIPrefix(""); mapping.setRepository(RepositoryConstants.WEBSITE); // WHEN final String handle = mapping.getHandle(uri); // THEN assertThat("We're expecting the actual URI (which equals to the handle) plus a trailing slash", handle, is(uri + "/")); }
public String getURI(Link uuidLink) { for (URI2RepositoryMapping mapping : mappings) { if (StringUtils.equals(mapping.getRepository(), uuidLink.getWorkspace()) && (uuidLink.getPath().startsWith(mapping.getHandlePrefix()) || uuidLink.isEditorBinaryLink())) { return mapping.getURI(uuidLink); } } return this.getDefaultMapping().getURI(uuidLink); }
/** * Get uri mapping for repo * @return uri mapping for repo */ @Override public String getURIMappingPrefix() { Collection<URI2RepositoryMapping> mappings = uri2RepositoryManager.getMappings(); for (URI2RepositoryMapping mapping : mappings) { if (mapping.getRepository().equals(MediaModule.REPO)) { return mapping.getURIPrefix(); } } return StringUtils.EMPTY; } }
/** * Create a uri based on a handle. */ public String getURI(String handle) { try { return getURI(LinkUtil.createLinkInstance(this.getRepository(), handle, null, null, null)); } catch (LinkException e) { return handle; } }
@Test public void handlePrefixIsNotRemoved() { // GIVEN String uri = "/travel0"; URI2RepositoryMapping mapping = new URI2RepositoryMapping("", RepositoryConstants.WEBSITE, "/travel"); // WHEN String handle = mapping.getHandle(uri); // THEN assertThat(handle, is("/travel/travel0")); } }
path = mapping.getHandle(path); aggregationState.setRepository(mapping.getRepository()); aggregationState.setHandle(path);
final URI2RepositoryMapping mapping = new URI2RepositoryMapping(); mapping.setRepository(repositoryName); mapping.setURIPrefix("/blabla/"); final String uri = mapping.getURI("/Test/image");
/** * Get the handle for this uri. */ public String getHandle(String uri) { return this.getMapping(uri).getHandle(uri); }
/** * The mapping to use for this uri. */ public URI2RepositoryMapping getMapping(String uri) { for (URI2RepositoryMapping mapping : mappings) { if (mapping.matches(uri)) { return mapping; } } return this.getDefaultMapping(); }
@Override public String transform(Link uuidLink) { String linkStr; if (useURI2RepositoryMapping) { linkStr = getURI2RepositoryManager().getURI(uuidLink); } else { linkStr = getURI2RepositoryManager().getDefaultMapping().getURI(uuidLink); } linkStr += getURISuffix(uuidLink); if (useI18N) { linkStr = localizeURI(linkStr, locale); } linkStr = prefixLink(linkStr); return linkStr; }
protected Comparator<URI2RepositoryMapping> getMappingComparator() { return (m0, m1) -> m1.getURIPrefix().compareTo(m0.getURIPrefix()); }
/** * Get the repository to use for this uri. */ public String getRepository(String uri) { return this.getMapping(uri).getRepository(); }
@Test public void testGetURIWhenLinkIsNotEditorBinaryLinkAndPrefixHandleIsSet() throws Exception { when(property.getParent()).thenReturn(node); when(node.isNodeType(NodeTypes.Resource.NAME)).thenReturn(false); Link link = new Link(); link.setPath("contact/pepa/image_file"); link.setPropertyName("file"); link.setFileName("fileName"); link.setExtension("ext"); link.setWorkspace("data"); link.setJCRNode(node); URI2RepositoryManager uri2RepositoryManager = new URI2RepositoryManager(); uri2RepositoryManager.addMapping(new URI2RepositoryMapping("/data", "data", "/blabla")); ComponentsTestUtil.setInstance(URI2RepositoryManager.class, uri2RepositoryManager); assertEquals("/contact/pepa/image_file/file/fileName.ext", URI2RepositoryManager.getInstance().getURI(link)); } }
/** * Create a node handle based on an uri. */ public String getHandle(final String uri) { String cleanedUri = StringUtils.prependIfMissing(StringUtils.removeStart(uri, URIPrefix), "/"); // Remove extension (ignore . anywhere else in the uri) String fileName = StringUtils.substringAfterLast(cleanedUri, "/"); String extension = StringUtils.substringAfterLast(fileName, "."); cleanedUri = StringUtils.removeEnd(cleanedUri, "." + extension); if (StringUtils.isNotEmpty(handlePrefix)) { if (StringUtils.startsWith(cleanedUri,"/")) { String temp = StringUtils.substringAfter(cleanedUri,"/"); temp = StringUtils.substringBefore(temp, "/"); temp = StringUtils.prependIfMissing(temp, "/"); if (StringUtils.isNotEmpty(temp) && temp.equals(handlePrefix)) { // We remove any occurrences of the handle prefix from given URI cleanedUri = StringUtils.removeStart(cleanedUri, handlePrefix); } } // So that we do not double it up afterwards cleanedUri = StringUtils.removeStart(cleanedUri, "/"); cleanedUri = handlePrefix + "/" + cleanedUri; } return cleanHandle(cleanedUri); }
@Test public void getHandleWhenLinkWithPrefixHandleExistInRepo() throws Exception { // GIVEN final URI2RepositoryMapping uri2RepositoryMapping = new URI2RepositoryMapping("/demo-project", "website", "/demoproject/year2010"); // WHEN String handle = uri2RepositoryMapping.getHandle("/demo-project/blah.ext"); // THEN assertThat(handle, is("/demoproject/year2010/blah")); }
public String getHandle(String uri) String handle = super.getHandle(uri); if (MediaEl.module().isLazyResolutionCreation())
/** * When no resource filter is defined in {@link ResourcesModule} or when given URI is white listed in filter it will * delegate to {@link URI2RepositoryMapping#matches(String)}. Otherwise it considers given URI as no match (given * URI is <em>not</em> white listed by resource filter). */ @Override public boolean matches(String uri) { if (resourcesModule.getResourceFilter() == null || resourcesModule.getResourceFilter().vote(uri) > 0) { return super.matches(uri); } // If the URI is not white listed by the resourceFilter we consider it no match return false; }
/** * {@inheritDoc} */ @Override public String transform(Link uuidLink) { String linkStr; if (useURI2RepositoryMapping) { linkStr = getURI2RepositoryManager().getURI(uuidLink); } else { linkStr = getURI2RepositoryManager().getDefaultMapping().getURI(uuidLink); } linkStr += getURISuffix(uuidLink); if (useI18N) { linkStr = Components.getComponent(I18nContentSupport.class).toI18NURI(linkStr); } linkStr = prefixLink(linkStr); return linkStr; }
@Test public void testGetURIWhenLinkIsEditorBinaryLinkAndPrefixHandleIsSet() throws Exception { when(property.getParent()).thenReturn(node); when(node.isNodeType(NodeTypes.Resource.NAME)).thenReturn(true); Link link = new Link(); link.setPath("contact/pepa/image_file"); link.setPropertyName("file"); link.setFileName("fileName"); link.setExtension("ext"); link.setWorkspace("data"); link.setProperty(property); link.setJCRNode(node); URI2RepositoryManager uri2RepositoryManager = new URI2RepositoryManager(); uri2RepositoryManager.addMapping(new URI2RepositoryMapping("/data", "data", "/blabla")); ComponentsTestUtil.setInstance(URI2RepositoryManager.class, uri2RepositoryManager); assertEquals("/data/contact/pepa/image_file/file/fileName.ext", URI2RepositoryManager.getInstance().getURI(link)); }
public String getURI(Link uuidLink) { String uri = uuidLink.getPath(); if (StringUtils.isNotEmpty(this.handlePrefix)) { uri = StringUtils.removeStart(uri, this.handlePrefix); } if (StringUtils.isNotEmpty(this.URIPrefix)) { uri = this.URIPrefix + "/" + uri; } String nodeDataName = uuidLink.getPropertyName(); String fileName = uuidLink.getFileName(); String extension = uuidLink.getExtension(); if (StringUtils.isNotEmpty(nodeDataName)) { uri += "/" + nodeDataName; } if (StringUtils.isNotEmpty(fileName)) { uri += "/" + fileName; } if (StringUtils.isNotEmpty(uri) && StringUtils.isNotEmpty(extension) && !StringUtils.endsWith(uri, "/")) { uri += "." + extension; } return cleanHandle(uri); }