@Override public List<String> getElements(int argCount, String filter) { CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule); if (cakeModule == null) { return Collections.emptyList(); } CakeVersion version = cakeModule.getCakeVersion(); if (version == null) { return Collections.emptyList(); } int cakeVersion = version.getMajor(); List<String> elements = new LinkedList<String>(); if (type == null) { return elements; } if (argCount == 1) { String pluginName = null; boolean isPlugin = false; // CakePHP 2.x if (cakeVersion >= 2) { String[] split = filter.split("\\.", 2); // NOI18N int splitLength = split.length; // is plugin? if (splitLength > 0) { isPlugin = isPlugin(split[0]); if (isPlugin) { if (splitLength > 1) { filter = split[1]; } else { filter = ""; // NOI18N } pluginName = split[0]; } } } // check subdirectory filter = setSubDirectoryPath(filter); // add elements for (DIR_TYPE dirType : dirTypes) { if (!isPlugin) { if (PLUGINS.contains(dirType)) { continue; } } FileObject webrootDirectory = cakeModule.getDirectory(dirType, FILE_TYPE.WEBROOT, pluginName); if (webrootDirectory != null) { FileObject targetDirectory = null; if (filter.startsWith(SLASH)) { targetDirectory = webrootDirectory; } else { targetDirectory = webrootDirectory.getFileObject(getRelativePath()); } if (targetDirectory != null) { for (FileObject element : targetDirectory.getChildren()) { addElement(element, filter, elements, pluginName); } break; } } if (isPlugin && !elements.isEmpty()) { return elements; } } if (!subDirectoryPath.isEmpty() || isPlugin) { return elements; } // plugin names // CakePHP 2.x if (cakeVersion >= 2) { for (DIR_TYPE dirType : PLUGINS) { FileObject pluginDirectory = cakeModule.getDirectory(dirType); if (pluginDirectory != null) { for (FileObject child : pluginDirectory.getChildren()) { if (child.isFolder()) { String name = child.getNameExt(); FileObject webrootDirectory = cakeModule.getDirectory(dirType, FILE_TYPE.WEBROOT, name); if (webrootDirectory != null && webrootDirectory.getFileObject(type.toString()) != null) { if (name.startsWith(filter)) { name = name + DOT; elements.add(name); } } } } } } } } return elements; }
/** * Get relative path for subdirectory. * * @return relative path */ private String getRelativePath() { if (subDirectoryPath.startsWith(SLASH)) { return subDirectoryPath.replaceFirst(SLASH, ""); // NOI18N } return type.toString() + SLASH + subDirectoryPath; }