@Test public void getUserId_deepPath() { Resource resource = context.resourceResolver().getResource("/content/slingshot/users/admin/hobby"); assertThat(SlingshotUtil.getUserId(resource), equalTo("admin")); }
public static String getUserId(final Resource resource) { final String prefix = SlingshotConstants.APP_ROOT_PATH + "/"; String id = null; if ( resource.getPath().startsWith(prefix) ) { final int areaEnd = resource.getPath().indexOf('/', prefix.length()); if ( areaEnd != -1 ) { final int userEnd = resource.getPath().indexOf('/', areaEnd + 1); if ( userEnd == -1 ) { id = resource.getPath().substring(areaEnd + 1); } else { id = resource.getPath().substring(areaEnd + 1, userEnd); } } } return id; }
SlingshotUtil { public static String getUserId(final Resource resource) { final String prefix = SlingshotConstants.APP_ROOT_PATH + "/"; String id = null; if ( resource.getPath().startsWith(prefix) ) { final int areaEnd = resource.getPath().indexOf('/', prefix.length()); if ( areaEnd != -1 ) { final int userEnd = resource.getPath().indexOf('/', areaEnd + 1); if ( userEnd == -1 ) { id = resource.getPath().substring(areaEnd + 1); } else { id = resource.getPath().substring(areaEnd + 1, userEnd); } } } return id; } }
SlingshotUtil { public static String getUserId(final Resource resource) { final String prefix = SlingshotConstants.APP_ROOT_PATH + "/"; String id = null; if ( resource.getPath().startsWith(prefix) ) { final int areaEnd = resource.getPath().indexOf('/', prefix.length()); if ( areaEnd != -1 ) { final int userEnd = resource.getPath().indexOf('/', areaEnd + 1); if ( userEnd == -1 ) { id = resource.getPath().substring(areaEnd + 1); } else { id = resource.getPath().substring(areaEnd + 1, userEnd); } } } return id; }  }
SlingshotUtil { public static String getUserId(final Resource resource) { final String prefix = SlingshotConstants.APP_ROOT_PATH + "/"; String id = null; if ( resource.getPath().startsWith(prefix) ) { final int areaEnd = resource.getPath().indexOf('/', prefix.length()); if ( areaEnd != -1 ) { final int userEnd = resource.getPath().indexOf('/', areaEnd + 1); if ( userEnd == -1 ) { id = resource.getPath().substring(areaEnd + 1); } else { id = resource.getPath().substring(areaEnd + 1, userEnd); } } } return id; }  static String getUserId(final Resource resource); static String getContentPath(final Resource resource); static boolean isUser(final SlingHttpServletRequest request); }
SlingshotUtil { public static String getUserId(final Resource resource) { final String prefix = SlingshotConstants.APP_ROOT_PATH + "/"; String id = null; if ( resource.getPath().startsWith(prefix) ) { final int areaEnd = resource.getPath().indexOf('/', prefix.length()); if ( areaEnd != -1 ) { final int userEnd = resource.getPath().indexOf('/', areaEnd + 1); if ( userEnd == -1 ) { id = resource.getPath().substring(areaEnd + 1); } else { id = resource.getPath().substring(areaEnd + 1, userEnd); } } } return id; }  static String getUserId(final Resource resource); static String getContentPath(final Resource resource); static boolean isUser(final SlingHttpServletRequest request);  }