QueryRecorder { public static String simplify(String query) { query = query.replaceAll("'[^']*'", "'x'"); query = query.replaceAll("ISDESCENDANTNODE\\(\\[/[^]]*\\]\\)", "ISDESCENDANTNODE('x')"); int pathIndex = query.indexOf("/jcr:root/"); if (pathIndex >= 0) { int start = pathIndex + "/jcr:root/".length(); int end = getFirstOccurance(query, start, " ", "/element(", "/text(", "/*", "/(", "/jcr:deref("); String path = query.substring(start, end); int first = path.indexOf('/'); if (first > 0) { first = path.indexOf('/', first + 1); if (first > 0) { path = path.substring(0, first + 1) + "..."; } } String newQuery = query.substring(0, pathIndex) + "/jcr:root/" + path + query.substring(end, query.length()); query = newQuery; } return query; }  static void main(String... args); static void record(String query, boolean internal); static String simplify(String query);  }
@Test public void simplify() { assertEquals("SELECT sling:alias FROM nt:base WHERE sling:alias IS NOT NULL", QueryRecorder.simplify("SELECT sling:alias FROM nt:base WHERE sling:alias IS NOT NULL")); assertEquals("SELECT * FROM [acme] AS s WHERE ISDESCENDANTNODE('x') " + "AND s.[sling:resourceType] = 'x'", QueryRecorder.simplify("SELECT * FROM [acme] AS s WHERE ISDESCENDANTNODE([/conf]) " + "AND s.[sling:resourceType] = 'dam/123'")); assertEquals(" /jcr:root QueryRecorder.simplify(" /jcr:root assertEquals("/jcr:root/content/element(*,sling:Job)[@status='x']", QueryRecorder.simplify("/jcr:root/content/element(*,sling:Job)[@status='RUNNING']")); assertEquals("/jcr:root/content/abc/element(*,sling:Job)[@status='x']", QueryRecorder.simplify("/jcr:root/content/abc/element(*,sling:Job)[@status='RUNNING']")); assertEquals("/jcr:root/content/abc/.../element(*, acme)[@status='x']", QueryRecorder.simplify("/jcr:root/content/abc/def/element(*, acme)[@status='RUNNING']")); assertEquals("/jcr:root/content/abc/...jcr:content[@deviceIdentificationMode]", QueryRecorder.simplify("/jcr:root/contentjcr:content", QueryRecorder.simplify("/jcr:root/(content|var)/b/c/*/jcr:content")); }