@Test public void testGetTemporaryFile() throws Exception { oldcore.getXWikiContext().setWikiId("wiki"); createEmptyFile("temp/module/wiki/Space/Page/file.txt"); assertNotNull(action.getTemporaryFile("/xwiki/bin/temp/Space/Page/module/file.txt", oldcore.getXWikiContext())); }
protected File getTemporaryFile(String uri, XWikiContext context) { Matcher matcher = URI_PATTERN.matcher(uri); File result = null; if (matcher.find()) { List<String> pathSegments = new ArrayList<String>(); pathSegments.add("temp"); pathSegments.add(withMinimalURLEncoding(matcher.group(3))); pathSegments.add(encodeURLPathSegment(context.getWikiId())); pathSegments.add(withMinimalURLEncoding(matcher.group(1))); pathSegments.add(withMinimalURLEncoding(matcher.group(2))); String prefix = StringUtils.join(pathSegments, PATH_SEPARATOR); for (String filePathSegment : matcher.group(4).split(PATH_SEPARATOR)) { pathSegments.add(withMinimalURLEncoding(filePathSegment)); } String path = URI.create(StringUtils.join(pathSegments, PATH_SEPARATOR)).normalize().toString(); if (path.startsWith(prefix)) { result = new File(this.environment.getTemporaryDirectory(), path); result = result.exists() ? result : null; } } return result; }
TempResourceAction extends XWikiAction { protected File getTemporaryFile(String uri, XWikiContext context) { Matcher matcher = URI_PATTERN.matcher(uri); File result = null; if (matcher.find()) { List<String> pathSegments = new ArrayList<String>(); pathSegments.add("temp"); pathSegments.add(withMinimalURLEncoding(matcher.group(3))); pathSegments.add(encodeURLPathSegment(context.getWikiId())); pathSegments.add(withMinimalURLEncoding(matcher.group(1))); pathSegments.add(withMinimalURLEncoding(matcher.group(2))); String prefix = StringUtils.join(pathSegments, PATH_SEPARATOR); for (String filePathSegment : matcher.group(4).split(PATH_SEPARATOR)) { pathSegments.add(withMinimalURLEncoding(filePathSegment)); } String path = URI.create(StringUtils.join(pathSegments, PATH_SEPARATOR)).normalize().toString(); if (path.startsWith(prefix)) { result = new File(this.environment.getTemporaryDirectory(), path); result = result.exists() ? result : null; } } return result; } }
TempResourceAction extends XWikiAction { protected File getTemporaryFile(String uri, XWikiContext context) { Matcher matcher = URI_PATTERN.matcher(uri); File result = null; if (matcher.find()) { List<String> pathSegments = new ArrayList<String>(); pathSegments.add("temp"); pathSegments.add(withMinimalURLEncoding(matcher.group(3))); pathSegments.add(encodeURLPathSegment(context.getWikiId())); pathSegments.add(withMinimalURLEncoding(matcher.group(1))); pathSegments.add(withMinimalURLEncoding(matcher.group(2))); String prefix = StringUtils.join(pathSegments, PATH_SEPARATOR); for (String filePathSegment : matcher.group(4).split(PATH_SEPARATOR)) { pathSegments.add(withMinimalURLEncoding(filePathSegment)); } String path = URI.create(StringUtils.join(pathSegments, PATH_SEPARATOR)).normalize().toString(); if (path.startsWith(prefix)) { result = new File(this.environment.getTemporaryDirectory(), path); result = result.exists() ? result : null; } } return result; }  }
TempResourceAction extends XWikiAction { protected File getTemporaryFile(String uri, XWikiContext context) { Matcher matcher = URI_PATTERN.matcher(uri); File result = null; if (matcher.find()) { List<String> pathSegments = new ArrayList<String>(); pathSegments.add("temp"); pathSegments.add(withMinimalURLEncoding(matcher.group(3))); pathSegments.add(encodeURLPathSegment(context.getWikiId())); pathSegments.add(withMinimalURLEncoding(matcher.group(1))); pathSegments.add(withMinimalURLEncoding(matcher.group(2))); String prefix = StringUtils.join(pathSegments, PATH_SEPARATOR); for (String filePathSegment : matcher.group(4).split(PATH_SEPARATOR)) { pathSegments.add(withMinimalURLEncoding(filePathSegment)); } String path = URI.create(StringUtils.join(pathSegments, PATH_SEPARATOR)).normalize().toString(); if (path.startsWith(prefix)) { result = new File(this.environment.getTemporaryDirectory(), path); result = result.exists() ? result : null; } } return result; }  @Override String render(XWikiContext context); }
TempResourceAction extends XWikiAction { protected File getTemporaryFile(String uri, XWikiContext context) { Matcher matcher = URI_PATTERN.matcher(uri); File result = null; if (matcher.find()) { List<String> pathSegments = new ArrayList<String>(); pathSegments.add("temp"); pathSegments.add(withMinimalURLEncoding(matcher.group(3))); pathSegments.add(encodeURLPathSegment(context.getWikiId())); pathSegments.add(withMinimalURLEncoding(matcher.group(1))); pathSegments.add(withMinimalURLEncoding(matcher.group(2))); String prefix = StringUtils.join(pathSegments, PATH_SEPARATOR); for (String filePathSegment : matcher.group(4).split(PATH_SEPARATOR)) { pathSegments.add(withMinimalURLEncoding(filePathSegment)); } String path = URI.create(StringUtils.join(pathSegments, PATH_SEPARATOR)).normalize().toString(); if (path.startsWith(prefix)) { result = new File(this.environment.getTemporaryDirectory(), path); result = result.exists() ? result : null; } } return result; }  @Override String render(XWikiContext context); static final Pattern URI_PATTERN; }