/** * TODO support references relative to current resource, like "../foo.mp4". * * @param mediaRef link/reference to a media resource. Must either be root relative path or an * absolute URL with protocol. * @return a {@link URL} instance, or <code>null</code> if no appropriate URL could be created * from reference. */ private URL createUrl(String mediaRef) { if (mediaRef == null) return null; if (URL.isEncoded(mediaRef)) { mediaRef = urlDecodeMediaRef(mediaRef); } if (mediaRef.startsWith("/")) { URL localURL = null; try { Path uri = Path.fromString(mediaRef); localURL = this.viewService.constructURL(uri); } catch (Exception e) { // ignore } if (localURL != null) { return localURL; } } else { URL externalURL = null; try { externalURL = URL.parse(mediaRef); } catch (Exception e) { // ignore } if (externalURL != null) { return externalURL; } } return null; }
private Resource getLocalResource(String resourceRef) throws Exception { if (resourceRef != null && resourceRef.startsWith("/")) { RequestContext requestContext = RequestContext.getRequestContext(); Repository repository = requestContext.getRepository(); String token = requestContext.getSecurityToken(); return repository.retrieve(token, Path.fromString(resourceRef), true); } return null; }
@Test public void appendCopySuffix() { Path original = Path.fromString("/lala.html"); Path firstCopy = copyHelper.appendCopySuffix(original, 1); assertEquals(firstCopy, Path.fromString("/lala(1).html")); Path secondCopy = copyHelper.appendCopySuffix(firstCopy, 1); assertEquals(secondCopy, Path.fromString("/lala(2).html")); Path thirdCopy = copyHelper.appendCopySuffix(secondCopy, 1); assertEquals(thirdCopy, Path.fromString("/lala(3).html")); Path parenthesisName = Path.fromString("/test/te(3)st.xml"); Path copiedParenthesis = copyHelper.appendCopySuffix(parenthesisName, 3); assertEquals(copiedParenthesis, Path.fromString("/test/te(3)st(3).xml")); Path copyToDoubleDigit = Path.fromString("/foo(9).html"); Path firstToDoubleDigitCopy = copyHelper.appendCopySuffix(copyToDoubleDigit, 1); assertEquals(firstToDoubleDigitCopy, Path.fromString("/foo(10).html")); }