JCRContentUtils implements ServletContextAware { public static String stringToJCRSearchExp(String str) { if (str == null) { throw new IllegalArgumentException("Must pass a valid String"); } str = str.trim(); final int length = str.length(); if (length == 0) { return "''"; } int nextDoubleQuote = str.indexOf('"'); if (nextDoubleQuote < 0) { return stringToQueryLiteral(str); } StringBuilder stringBuilder = new StringBuilder(length + 10); stringBuilder.append(str.substring(0, nextDoubleQuote)); char previousChar = 0; boolean hasStartingDoubleQuote = false; for (int i = nextDoubleQuote; i < length; i++) { char c = str.charAt(i); if (c == '"') { if (!hasStartingDoubleQuote) { nextDoubleQuote = str.indexOf('"', i + 1); if (nextDoubleQuote < 0) { if (previousChar != '\\') { stringBuilder.append('\\'); } stringBuilder.append(str.substring(i, length)); break; } hasStartingDoubleQuote = true; } else { hasStartingDoubleQuote = false; } } stringBuilder.append(c); previousChar = c; } return stringToQueryLiteral(stringBuilder.toString()); } @SuppressWarnings("unchecked")  JCRContentUtils(Map<String, List<String>> mimeTypes, Map<String, String> fileExtensionIcons, Map<String, String> defaultUserFolderTypes); static JCRContentUtils getInstance(); static int callDataStoreGarbageCollector(); static boolean check(String icon); static void clearAllLocks(final String path, final boolean processChildNodes, final String workspace); static Value createValue(Object objectValue, ValueFactory factory); static Value[] createValues(Collection<?> objectValues, ValueFactory factory); static String decodeJCRNamePrefix(final String encodedPrefix); static void deleteJackrabbitIndexes(File repositoryHome); static File downloadFileContent(JCRNodeWrapper node); static File downloadFileContent(JCRNodeWrapper node, File targetFile); static String encodeJCRNamePrefix(final String originalPrefix); static String escapeLocalNodeName(String name); static String escapeNodePath(String path); static String findAvailableNodeName(Node dest, String name); static String findAvailableNodeName(Node dest, String name, boolean hasExtension); static JCRNodeWrapper findDisplayableNode(JCRNodeWrapper node, RenderContext context); static JCRNodeWrapper findDisplayableNode(JCRNodeWrapper node, RenderContext context, JCRSiteNode contextSite); static String generateNodeName(String text); static String generateNodeName(String text, int maxLength); static Set<String> getAssignableMixins(JCRNodeWrapper node); static List<JCRNodeWrapper> getChildrenOfType(JCRNodeWrapper node, String type); static List<JCRNodeWrapper> getChildrenOfType(JCRNodeWrapper node, String type, int limit); static String getContentNodeName(Node node); static String getContentObjectPath(Node node); static NodeIterator getDescendantNodes(JCRNodeWrapper node, String type); static String getDisplayLabel(Object item, Locale locale, ExtendedNodeType nodeTypeForSearchingLabel); static String getExpandedName(String name, NamespaceRegistry namespaceRegistry); static String getJCRName(String qualifiedName, NamespaceRegistry namespaceRegistry); static String getIconWithContext(ExtendedNodeType type); static String getIcon(ExtendedNodeType type); static String getIcon(JCRNodeWrapper f); static String getIconWithContext(JCRNodeWrapper f, boolean useContext); static String getIconsFolder(final ExtendedNodeType primaryNodeType); static JCRNodeLockType getLockType(String lockTypeToken); static Set<JCRNodeLockType> getLockTypes(Map<String, List<String>> lockInfos); static String getNameFromPath(String path); static List<JCRNodeWrapper> getNodes(JCRNodeWrapper node, String type); static List<JCRNodeWrapper> getNodes(JCRNodeWrapper node, String type, int limit); static JCRNodeWrapper getOrAddPath(JCRSessionWrapper session, JCRNodeWrapper parentNode, String path, String pathNodeType); static String getParentJCRPath(String path); static JCRNodeWrapper getParentOfType(JCRNodeWrapper node,
                                                 String type); static JCRNodeWrapper getPathFolder(JCRNodeWrapper root, String name, String options, String nodeType); static PropertyDefinition getPropertyDefinition(NodeType type,
                                                           String property); static PropertyDefinition getPropertyDefinition(String nodeType,
                                                           String property); static int getPropertyDefSelector(ItemDefinition itemDef); static String getSiteKey(String jcrNodePath); static String getSystemSitePath(); static Object getValue(Value propertyValue); static boolean hasPermission(String workspaceName, final String permissionName, final String nodeUUID); static void importSkeletons(String skeletonLocations, String targetPath,
                                       JCRSessionWrapper session); static void importSkeletons(String skeletonLocations, String targetPath,
                                       JCRSessionWrapper session, int importUUIDBehavior, Map<String, String> replacements); static void importSkeletons(String skeletonLocations, String targetPath,
                                       JCRSessionWrapper session, Map<String, String> replacements); static boolean isADisplayableNode(JCRNodeWrapper node, RenderContext context); static boolean isMimeTypeGroup(String mimeType, String mimeTypeGroup); static boolean isMimeTypeGroup(String mimeType, String... mimeTypeGroups); static boolean isLanguageInvalid(Node node, String languageCode); static boolean isLockedAndCannotBeEdited(JCRNodeWrapper node); static boolean isNodeType(JCRNodeWrapper node, Iterable<String> types); static boolean isNodeType(JCRNodeWrapper node, String... types); static boolean isNodeType(JCRNodeWrapper node, String type); @Deprecated static boolean isNotJcrUuid(String uuid); static boolean isValidFilename(String name); static final boolean isValidWorkspace(String workspace); static final boolean isValidWorkspace(String workspace, boolean allowBlank); static void registerNamespace(Session session, String prefix, String uri); static String replaceColon(String name); static long size(RangeIterator iterator); static String[] splitJCRPath(String path); static String stringToJCRPathExp(String str); static String stringToJCRSearchExp(String str); static String stringToQueryLiteral(String str); static String unescapeLocalNodeName(final String encodedLocalName); String generateNodeName(JCRNodeWrapper parent, String nodeType); String generateNodeName(JCRNodeWrapper parent, String defaultLanguage, ExtendedNodeType nodeType, String targetName); Map<String, String> getFileExtensionIcons(); Map<String, List<String>> getMimeTypes(); NameGenerationHelper getNameGenerationHelper(); Set<String> getUnsupportedMarkForDeletionNodeTypes(); void setNameGenerationHelper(NameGenerationHelper nameGenerationHelper); void setUnsupportedMarkForDeletionNodeTypes(Set<String> unsupportedMarkForDeletionNodeTypes); Pattern getHandleFallbackLocaleForPathPattern(); void setHandleFallbackLocaleForPath(String handleFallbackLocaleForPath); @SuppressWarnings({"unchecked", "rawtypes"}) static List<Map<String, Object>> getRolesForNode(JCRNodeWrapper node, boolean includeInherited, boolean expandGroups, String roles, int limit,
                                                            boolean latestFirst); static Map<String, T> reverse(Map<String, T> orderedMap); static String sqlEncode(String s); static JCRNodeWrapper getParentWithAclInheritanceBroken(JCRNodeWrapper node); static String getMimeType(String fileName); static String getMimeType(String fileName, String fallbackMimeType); void setServletContext(ServletContext servletContext); JCRNodeWrapper getUserPrivateFilesFolder(JCRSessionWrapper session); JCRNodeWrapper getDefaultUserFolder(JCRSessionWrapper session, String path); JCRNodeWrapper getDefaultUserFolder(JCRSessionWrapper session, String path, boolean saveIfCreate); static boolean isUserMemberOfGroup(String siteKey, String groupName, String userName, String userRealm, boolean isRoot); static boolean needVersion(JCRNodeWrapper node, Set<String> versionedTypes); static Set<String> splitAndUnify(String input, String separator); static final Pattern COLON_PATTERN; static final Comparator<NodeType> NODE_TYPE_NAME_COMPARATOR; }
@Test public void testStringToJCRSearchExp() { String term = "foo bar"; assertEquals(getFinalTerm(term), JCRContentUtils.stringToJCRSearchExp(term)); term = "foo -bar"; assertEquals(getFinalTerm(term), JCRContentUtils.stringToJCRSearchExp(term)); term = "foo \\-bar"; assertEquals(getFinalTerm(term), JCRContentUtils.stringToJCRSearchExp(term)); term = "foo \"bar"; assertEquals(getFinalTerm("foo \\\"bar"), JCRContentUtils.stringToJCRSearchExp(term)); term = "foo \"bar baz\""; assertEquals(getFinalTerm(term), JCRContentUtils.stringToJCRSearchExp(term)); term = "foo \"bar -baz\""; assertEquals(getFinalTerm(term), JCRContentUtils.stringToJCRSearchExp(term)); term = "foo \"bar baz\" boo\""; assertEquals(getFinalTerm("foo \"bar baz\" boo\\\""), JCRContentUtils.stringToJCRSearchExp(term)); term = "foo \"bar baz\" \"fu boo\""; assertEquals(getFinalTerm("foo \"bar baz\" \"fu boo\""), JCRContentUtils.stringToJCRSearchExp(term)); term = " foo \"bar baz\" boo bu "; assertEquals(getFinalTerm("foo \"bar baz\" boo bu"), JCRContentUtils.stringToJCRSearchExp(term)); term = "\"foo"; assertEquals(getFinalTerm("\\\"foo"), JCRContentUtils.stringToJCRSearchExp(term)); term = "foo\""; assertEquals(getFinalTerm("foo\\\""), JCRContentUtils.stringToJCRSearchExp(term)); term = "\""; assertEquals(getFinalTerm("\\\""), JCRContentUtils.stringToJCRSearchExp(term)); term = ""; assertEquals(getFinalTerm(""), JCRContentUtils.stringToJCRSearchExp(term)); }