/*
(non-Javadoc)

@see net.jawr.web.resource.bundle.handler.ResourceBundlesHandler#
getBundlePaths (boolean, java.lang.String,
net.jawr.web.resource.bundle.iterator.ConditionalCommentCallbackHandler,
java.lang.String)
176723
@Override
	public ResourceBundlePathsIterator getBundlePaths(DebugMode debugMode, String bundleId,
			ConditionalCommentCallbackHandler commentCallbackHandler, Map<String, String> variants) {

		List<JoinableResourceBundle> currentBundles = new ArrayList<>();

		// if the path did not correspond to a global bundle, find the requested
		// one.
		if (!isGlobalResourceBundle(bundleId)) {
			for (JoinableResourceBundle bundle : contextBundles) {
				if (bundle.getId().equals(bundleId)) {

					currentBundles.add(bundle);
					break;
				}
			}
		}

		return getBundleIterator(debugMode, currentBundles, commentCallbackHandler, variants);
	}
808642
protected void renderBundleLinks(JoinableResourceBundle bundle, BundleRendererContext ctx,
			Map<String, String> variant, Writer out, boolean debugOn) throws IOException {

		ResourceBundlePathsIterator it = bundler.getBundlePaths(bundle.getId(), new ConditionalCommentRenderer(out),
				variant);
		renderBundleLinks(it, ctx, debugOn, out);
	}
1138348
@Override
	public List<PathMapping> getPathMappings(JoinableResourceBundle bundle, String resourcePath,
			ResourceReaderHandler rsReader) {

		List<PathMapping> pathMappings = new ArrayList<>();
		PathMapping pathMapping = null;
		GeneratorMappingHelper helper = new GeneratorMappingHelper(resourcePath);
		String path = resolver.getResourcePath(helper.getPath());
		String[] names = path.split(RESOURCE_BUNDLE_SEPARATOR);

		for (String resourceName : names) {

			path = resourceName.replace(PACKAGE_SEPARATOR, JawrConstant.URL_SEPARATOR_CHAR);
			path = control.toBundleName(path, new Locale("", "")) + PROPERTIES_FILE_SUFFIX;
			URL rbURL = LocaleUtils.getResourceBundleURL(path, config.getContext());
			if (rbURL != null) {
				String strURL = rbURL.toString();
				// returns the path mapping only if the MessageBundle are on a
				// filesystem
				if (strURL.startsWith(JawrConstant.FILE_URL_PREFIX)) {
					String parentPath = "/WEB-INF/classes/" + PathNormalizer.getParentPath(path);
					String resourceBundleName = FileNameUtils.getBaseName(path);
					MessageBundleFileFilter filter = new MessageBundleFileFilter(resourceBundleName);
					pathMapping = new PathMapping(bundle, parentPath, filter);
					pathMappings.add(pathMapping);
				}
			}
		}
		return pathMappings;
	}
606183
@SuppressWarnings("unchecked")
    private Set<String> getResourcePaths() {

        Set<String> resources = new HashSet<String>();
        for (Component c : m_resources) {
            if (c instanceof CmsRemovableFormRow<?>) {
                String value = ((CmsRemovableFormRow<CmsPathSelectField>)c).getInput().getValue();
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(value)) {
                    resources.add(value);
                }
            }
        }
        return resources;
    }
546285
protected TemplateLoader getTemplateLoaderForPath(String templateLoaderPath) throws IOException {
        if (templateLoaderPath.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
            String basePackagePath = templateLoaderPath.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length());
            if (log.isDebugEnabled()) {
                log.debug("Template loader path [" + templateLoaderPath +
                        "] resolved to class path [" + basePackagePath + "]");
            }
            return new ClassTemplateLoader(environment.getClassLoader(), basePackagePath);
        } else if (templateLoaderPath.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
            File file = new File(templateLoaderPath.substring(ResourceUtils.FILE_URL_PREFIX.length()));
            if (log.isDebugEnabled()) {
                log.debug("Template loader path [" + templateLoaderPath +
                        "] resolved to file path [" + file.getAbsolutePath() + "]");
            }
            return new FileTemplateLoader(file);
        } else {
            File file = new File(environment.getBasePath(), templateLoaderPath);
            if (log.isDebugEnabled()) {
                log.debug("Template loader path [" + templateLoaderPath +
                        "] resolved to file path [" + file.getAbsolutePath() + "]");
            }
            return new FileTemplateLoader(file);
        }
    }
624503
@Override
	public String getResourcePath(String requestedPath) {
		String resourcePath = super.getResourcePath(requestedPath);
		GeneratorMappingHelper helper = new GeneratorMappingHelper(resourcePath);
		String fullPath = null;
		if (StringUtils.isNotEmpty(helper.getBracketsParam())) {
			// Use the webjars reference stored in the bracket params
			fullPath = locator.getFullPath(helper.getBracketsParam(), helper.getPath());
		} else {
			fullPath = locator.getFullPath(resourcePath);
		}
		if (checkResourcePathForInfo || checkResourcePathForWarning) {
			checkResourcePath(resourcePath, fullPath);
		}
		return fullPath.substring(GeneratorRegistry.WEBJARS_GENERATOR_HELPER_PREFIX.length() - 2);
	}
654877
public static List<String> getSourcePaths(Context context) throws PackageManager.NameNotFoundException, IOException {
        ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0);
        File sourceApk = new File(applicationInfo.sourceDir);

        List<String> sourcePaths = new ArrayList<>();
        sourcePaths.add(applicationInfo.sourceDir); //add the default apk path

        //the prefix of extracted file, ie: test.classes
        String extractedFilePrefix = sourceApk.getName() + EXTRACTED_NAME_EXT;

//        如果VM已经支持了MultiDex，就不要去Secondary Folder加载 Classesx.zip了，那里已经么有了
//        通过是否存在sp中的multidex.version是不准确的，因为从低版本升级上来的用户，是包含这个sp配置的
        if (!isVMMultidexCapable()) {
            //the total dex numbers
            int totalDexNumber = getMultiDexPreferences(context).getInt(KEY_DEX_NUMBER, 1);
            File dexDir = new File(applicationInfo.dataDir, SECONDARY_FOLDER_NAME);

            for (int secondaryNumber = 2; secondaryNumber <= totalDexNumber; secondaryNumber++) {
                //for each dex file, ie: test.classes2.zip, test.classes3.zip...
                String fileName = extractedFilePrefix + secondaryNumber + EXTRACTED_SUFFIX;
                File extractedFile = new File(dexDir, fileName);
                if (extractedFile.isFile()) {
                    sourcePaths.add(extractedFile.getAbsolutePath());
                    //we ignore the verify zip part
                } else {
                    throw new IOException("Missing extracted secondary dex file '" + extractedFile.getPath() + "'");
                }
            }
        }

        if (ARouter.debuggable()) { // Search instant run support only debuggable
            sourcePaths.addAll(tryLoadInstantRunDexFile(applicationInfo));
        }
        return sourcePaths;
    }
950959
@Override
	public List<BundlePath> getItemDebugPathList(Map<String, String> variants) {

		if (StringUtils.isNotEmpty(debugURL)) {
			return bundlePathMapping.getItemDebugPathList();
		}
		return getItemPathList(bundlePathMapping.getItemDebugPathList(), variants);
	}
57343
public Set getResourcePaths(String path, boolean searchMetaInf)
  {
    java.util.HashSet set = new java.util.HashSet();

    if ((WCCustomProperties.SKIP_META_INF_RESOURCES_PROCESSING) && (searchMetaInf == true)){

        searchMetaInf = false;
        logger.logp(Level.FINE, CLASS_NAME, "getResourcePaths", "override searchMetaInf to false becuase of custom property");
    }
    
    
    if (container != null){
        try {
            addResourcePaths(set, container, path, searchMetaInf);
        } catch (UnableToAdaptException e) {
            throw new IllegalStateException(e);
        }
        
        // PM21451 Start
        // search the static doc roots and include a search of meta-inf resources if boolean parameter is true
        // 96723: Hard code a "false" parameter to avoid searching META-INF resources a second time. The
        // resource paths are already added by Liberty specific container code.
        set.addAll(getStaticDocumentRootUtils().getResourcePaths(path,false));

        // look at the JSP doc roots but don't search meta-inf resources this time (meta-inf resources are common
        // to both doc roots).
        set.addAll(getJSPDocumentRootUtils().getResourcePaths(path,false));
        // PM21451 End
        
        return set;
    }

    java.io.File root = new java.io.File(documentRoot + path);

    if (root.exists())
    {
      java.io.File[] fileList = root.listFiles();
      if (fileList != null)
      {
        for (int i = 0; i < fileList.length; i++)
        {
          String resourcePath = fileList[i].getPath();
          resourcePath = resourcePath.substring(documentRoot.length());
          resourcePath = resourcePath.replace('\\', '/');
          if (fileList[i].isDirectory())
          {
            if (resourcePath.endsWith("/") == false)
            {
              resourcePath += "/";
            }
          }
          set.add(resourcePath);
        }
      }
    }
    return (set);
  }
872770
public static List<String> getSourcePaths() throws PackageManager.NameNotFoundException, IOException {
        ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo(getPackageName(), 0);
        File sourceApk = new File(applicationInfo.sourceDir);
        File dexDir = new File(applicationInfo.dataDir, SECONDARY_FOLDER_NAME);
        File instantRunDir = new File(applicationInfo.dataDir, INSTANT_RUN_DEX_DIR_PATH); //default instant-run dir

        List<String> sourcePaths = new ArrayList<>();
        sourcePaths.add(applicationInfo.sourceDir); //add the default apk path

        if (instantRunDir.exists()) { //check if app using instant run
            for(final File dexFile : instantRunDir.listFiles()) { //add all sources from instan-run
                sourcePaths.add(dexFile.getAbsolutePath());
            }
        }

        //the prefix of extracted file, ie: test.classes
        String extractedFilePrefix = sourceApk.getName() + EXTRACTED_NAME_EXT;
        //the total dex numbers
        int totalDexNumber = getMultiDexPreferences().getInt(KEY_DEX_NUMBER, 1);

        for (int secondaryNumber = 2; secondaryNumber <= totalDexNumber; secondaryNumber++) {
            //for each dex file, ie: test.classes2.zip, test.classes3.zip...
            String fileName = extractedFilePrefix + secondaryNumber + EXTRACTED_SUFFIX;
            File extractedFile = new File(dexDir, fileName);
            if (extractedFile.isFile()) {
                sourcePaths.add(extractedFile.getAbsolutePath());
                //we ignore the verify zip part
            }
        }

        return sourcePaths;
    }
465248
protected ResourceBundle resolveBundle (HttpServletRequest req, String bundlePath,
                                            ClassLoader loader, boolean silent)
    {
        ResourceBundle bundle = null;

        if (req != null) {
            Enumeration<?> locales = req.getLocales();
            while (locales.hasMoreElements()) {
                Locale locale = (Locale)locales.nextElement();

                try {
                    // java caches resource bundles, so we don't need to reinvent the wheel here.
                    // however, java also falls back from a specific bundle to a more general one
                    // if it can't find a specific bundle. that's real nice of it, but we want
                    // first to see whether or not we have exact matches on any of the preferred
                    // locales specified by the client. if we don't, then we can rely on java's
                    // fallback mechanisms
                    bundle = ResourceBundle.getBundle(bundlePath, locale, loader);

                    // if it's an exact match, off we go
                    if (bundle.getLocale().equals(locale)) {
                        break;
                    }

                } catch (MissingResourceException mre) {
                    // no need to freak out quite yet, see if we have something for one of the
                    // other preferred locales
                }
            }
        }

        // if we were unable to find an exact match for any of the user's preferred locales, take
        // their most preferred and let java perform it's fallback logic on that one
        if (bundle == null) {
            Locale locale = (req == null) ? _deflocale : req.getLocale();
            try {
                bundle = ResourceBundle.getBundle(bundlePath, locale, loader);
            } catch (MissingResourceException mre) {
                if (!silent) {
                    // if we were unable even to find a default bundle, we may want to log a
                    // warning
                    log.warning("Unable to resolve any message bundle", "req", getURL(req),
                                "locale", locale, "bundlePath", bundlePath, "classLoader", loader,
                                "siteBundlePath", _siteBundlePath, "siteLoader", _siteLoader);
                }
            }
        }

        return bundle;
    }
1265909
private List<String> getResourcePaths() {

        List<String> res = new ArrayList<String>();
        for (Component c : m_resources) {
            if (c instanceof CmsRemovableFormRow<?>) {
                AbstractField<?> field = (AbstractField<?>)(((CmsRemovableFormRow)c).getInput());
                res.add((String)(field.getValue()));
            }
        }
        return res;
    }
751337
private void findAdditionalPossiblePaths(Map<String, List<String>> pathNodes,
                                             List<String> paths,
                                             String base,
                                             String baseType,
                                             int maxDepth,
                                             String logPrefix) {
        if (maxDepth == 0) {
            return;
        }

        LOG.debug("Possible:{} > {}:{}", logPrefix, baseType, base);

        if (pathNodes.containsKey(baseType)) {
            List<String> childPaths = pathNodes.get(baseType);
            if (childPaths != null) {
                for (String childPath : childPaths) {
                    final int colonPos = childPath.indexOf(':');
                    final String childType = childPath.substring(0, colonPos);
                    final String childName = childPath.substring(colonPos + 1);

                    String childBase;
                    if (base.isEmpty()) {
                        childBase = childName;
                    } else {
                        if (childName.isEmpty()) {
                            childBase = base;
                        } else {
                            childBase = base + '.' + childName;
                        }
                    }

                    String newPath = childType + ':' + childBase;
                    if (!paths.contains(newPath)) {
                        LOG.debug("Possible:{} + {}:{}", logPrefix, childType, childBase);
                        paths.add(childType + ':' + childBase);

                        findAdditionalPossiblePaths(pathNodes, paths, childBase, childType, maxDepth - 1, logPrefix + "--");
                    }
                }
            }
        }
        LOG.debug("Possible:{} < {}:{}", logPrefix, baseType, base);
    }
1171961
protected ResourceBundlesHandler getResourceBundlesHandler(FacesContext context) {
		Object handler = context.getExternalContext().getApplicationMap().get(getResourceBundlesHandlerAttributeName());
		if (null == handler)
			throw new IllegalStateException(
					"ResourceBundlesHandler not present in servlet context. Initialization of Jawr either failed or never occurred.");

		ResourceBundlesHandler rsHandler = (ResourceBundlesHandler) handler;
		return rsHandler;
	}
579947
private static void getClassPathesFromLoader(ClassLoader cl, Map pathes) {
	if (cl instanceof URLClassLoader) _getClassPathesFromLoader((URLClassLoader) cl, pathes);
    }
1299891
protected String getClasspath() throws IOException {
        List<String> classpath = new ArrayList<>();
        classpath.add(getBundleJarPath());
        classpath.addAll(getPluginsPath());
        return StringUtils.toString(classpath.toArray(new String[classpath.size()]), " ");
    }
1193433
public String[] getPaths (String packagePath, String key)
    {
        return getConfig(packagePath).getValue(key, (String[])null);
    }