/*
(non-Javadoc)

@seenet.jawr.web.resource.bundle.handler.ResourceBundlesHandler#
getGlobalResourceBundlePaths
(net.jawr.web.resource.bundle.iterator.ConditionalCommentCallbackHandler,
java.lang.String)
17880
@Override
	public ResourceBundlePathsIterator getGlobalResourceBundlePaths(String bundleId,
			ConditionalCommentCallbackHandler commentCallbackHandler, Map<String, String> variants) {

		List<JoinableResourceBundle> currentBundles = new ArrayList<>();
		for (JoinableResourceBundle bundle : globalBundles) {
			if (bundle.getId().equals(bundleId)) {
				currentBundles.add(bundle);
				break;
			}
		}
		return getBundleIterator(getDebugMode(), currentBundles, commentCallbackHandler, variants);
	}
1342136
private Set<String> findExclusionPaths(ServletContext servletContext) {
        Set<String> exclusions = new TreeSet<String>();
        
        // Let other handlers deal with folders that do not reside in the WEB-INF or META-INF
        Set<String> resourcePaths = servletContext.getResourcePaths("/");
        
        // This most certainly should not be null!
        // It means that the server cannot read files at all
        if (resourcePaths == null) throw new InitException("ServletContext cannot read files. Reason is unknown");
        
        resourcePaths.removeIf( path -> path.contains("-INF") || path.contains("-inf"));
    
        // We still need to also remove the views folder from being processed by other handlers
        resourcePaths.removeIf( path -> path.contains(TemplateEngine.TEMPLATES_FOLDER));
        
        // Add the remaining paths to exclusions
        for (String path : resourcePaths) {
            // add leading slash
            if (path.charAt(0) != '/')
                path = '/' + path;
            
            // remove the last slash
            if (path.charAt(path.length()-1) == '/')
                path = path.substring(0, path.length()-1);
            exclusions.add(path);
        }
        
        return exclusions;
    }
1307441
@Override
	public BundlePath nextPath() {

		BundlePath path = null;
		if (null == pathsIterator || !pathsIterator.hasNext()) {
			currentBundle = (JoinableResourceBundle) bundlesIterator.next();

			if (null != currentBundle.getExplorerConditionalExpression()) {
				commentCallbackHandler.openConditionalComment(currentBundle.getExplorerConditionalExpression());
			}

			if (StringUtils.isNotEmpty(currentBundle.getDebugURL())) {
				pathsIterator = Arrays
						.asList(new BundlePath(currentBundle.getBundlePrefix(), currentBundle.getDebugURL(), true))
						.iterator();
			} else {
				pathsIterator = currentBundle.getItemDebugPathList(variants).iterator();
			}
		}

		if (pathsIterator != null && pathsIterator.hasNext()) {
			path = pathsIterator.next();
		}

		return path;
	}
456195
function getLocaleFallbackResource(path) {
        var json;
        var error;
        $.ajax({
            url: CDP.toUrl(path),
            method: "GET",
            async: false,
            dataType: "json",
            success: function (data) {
                json = data;
            },
            error: function (xhr, status) {
                error = CDP.makeErrorInfo(CDP.RESULT_CODE.ERROR_CDP_I18N_INITIALIZE_FAILED, TAG, "ajax request failed. status: " + status);
            }
        });
        if (null != error) {
            throw error;
        }
        return json;
    }
1014637
@Override
	public Set<String> getResourceNames(String path) {

		Set<String> resources = null;

		URL resourceURL = null;

		try {
			resourceURL = ClassLoaderResourceUtils.getResourceURL(getCompletePath(path), this);
			if (resourceURL.toString().startsWith(JAR_URL_PREFIX)) {
				resources = getResourceNamesFromJar(path, resourceURL);
			} else if (resourceURL.toString().startsWith(FILE_URL_PREFIX)) {

				String dirPath = resourceURL.getFile();
				File dir = new File(dirPath);
				resources = FileUtils.getResourceNames(dir);
			}
		} catch (ResourceNotFoundException e) {

			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug("Unable to find resources name for path '" + path + "'", e);
			}
			resources = Collections.emptySet();
		}

		return resources;
	}
725513
@Override
	public boolean isGlobalResourceBundle(String resourceBundleId) {

		boolean isGlobalResourceBundle = false;
		for (JoinableResourceBundle bundle : globalBundles) {
			if (bundle.getId().equals(resourceBundleId)) {
				isGlobalResourceBundle = true;
			}
		}

		return isGlobalResourceBundle;
	}
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);
  }
1142123
protected ResourceBundleHandler initResourceBundleHandler() {
		ResourceBundleHandler rsHandler = null;
		if (jawrConfig.getUseBundleMapping() && StringUtils.isNotEmpty(jawrConfig.getJawrWorkingDirectory())) {
			rsHandler = new ServletContextResourceBundleHandler(servletContext, jawrConfig.getJawrWorkingDirectory(),
					jawrConfig.getResourceCharset(), jawrConfig.getGeneratorRegistry(), resourceType);
		} else {
			rsHandler = new ServletContextResourceBundleHandler(servletContext, jawrConfig.getResourceCharset(),
					jawrConfig.getGeneratorRegistry(), resourceType);
		}
		return rsHandler;
	}
37845
@Override
	public Set<String> getResourcePaths(final String name) {
		final String normalizedname = Path.normalizeResourcePath(name);
		LOG.debug("Searching bundle [" + bundle + "] for resource paths of ["
				+ normalizedname + "]");
		final Enumeration<String> entryPaths = bundle
				.getEntryPaths(normalizedname);
		if (entryPaths == null || !entryPaths.hasMoreElements()) {
			return null;
		}
		Set<String> foundPaths = new HashSet<>();
		while (entryPaths.hasMoreElements()) {
			foundPaths.add(entryPaths.nextElement());
		}
		return foundPaths;
	}
568207
protected String getResourcePath(ParserContext parserContext) {
        if (parserContext != null) {
            try {
                Resource resource = parserContext.getReaderContext().getResource();
                return resource == null ? null : resource.getURL().getPath();
            } catch (IOException e) {}
        }
        
        return null;
    }
274932
@Override
  public @NotNull Set<String> getAllowedComponentsForTemplate(@NotNull String pageComponentPath, @NotNull ResourceResolver resolver) {
    Resource pageComponentResource = resolver.getResource(pageComponentPath);
    if (pageComponentResource != null) {
      Iterable<ParsysConfig> parSysConfigs = parsysConfigManager.getParsysConfigs(pageComponentResource.getPath(), resolver);

      SortedSet<String> allowedChildren = new TreeSet<>();
      for (ParsysConfig parSysConfig : parSysConfigs) {
        allowedChildren.addAll(parSysConfig.getAllowedChildren());
      }

      return allowedChildren;
    }
    // fallback
    return ImmutableSet.of();
  }
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;
    }
757191
@SuppressWarnings("deprecation")
  private ResourceBundle findResourceBundle(Object o) {
    ResourceBundle result = null;

    Parameters p = o.getClass().getAnnotation(Parameters.class);
    if (p != null && ! isEmpty(p.resourceBundle())) {
      result = ResourceBundle.getBundle(p.resourceBundle(), Locale.getDefault());
    } else {
      com.beust.jcommander.ResourceBundle a = o.getClass().getAnnotation(
          com.beust.jcommander.ResourceBundle.class);
      if (a != null && ! isEmpty(a.value())) {
        result = ResourceBundle.getBundle(a.value(), Locale.getDefault());
      }
    }

    return result;
  }
640221
private void checkInheritedRelativePaths( ClassDeclaration jclass )
            throws FatalCompileTimeException
    {
        for ( ClassType type = jclass.getSuperclass();
              type != null && CompilerUtils.isAssignableFrom( FLOWCONTROLLER_BASE_CLASS, type, getEnv() );
              type = type.getSuperclass() )
        {
            TypeDeclaration decl = CompilerUtils.getDeclaration( type );
            
            //
            // Check simple actions in the Controller annotation.
            //
            List simpleActions =
                    CompilerUtils.getAnnotationArrayValue( decl, CONTROLLER_TAG_NAME, SIMPLE_ACTIONS_ATTR, true );
            
            if ( simpleActions != null )
            {
                for ( Iterator j = simpleActions.iterator(); j.hasNext(); )  
                {
                    AnnotationInstance i = ( AnnotationInstance ) j.next();
                    checkRelativePath( i, PATH_ATTR, jclass, decl, false );
                    List conditionalForwards = CompilerUtils.getAnnotationArray( i, CONDITIONAL_FORWARDS_ATTR, true );
                    
                    if ( conditionalForwards != null )
                    {
                        for ( Iterator k = conditionalForwards.iterator(); k.hasNext(); )  
                        {
                            AnnotationInstance ann = ( AnnotationInstance ) k.next();
                            checkRelativePath( ann, PATH_ATTR, jclass, decl, false );
                        }
                    }
                }
            }
            
            //
            // Check Forwards in the Controller annotation.
            //
            List forwards = CompilerUtils.getAnnotationArrayValue( decl, CONTROLLER_TAG_NAME, FORWARDS_ATTR, true );
            
            if ( forwards != null )
            {
                for ( Iterator ii = forwards.iterator(); ii.hasNext(); )  
                {
                    AnnotationInstance i = ( AnnotationInstance ) ii.next();
                    checkRelativePath( i, PATH_ATTR, jclass, decl, false );
                }
            }
            
            //
            // Check Catches in the Controller annotation.
            //
            List catches = CompilerUtils.getAnnotationArrayValue( decl, CONTROLLER_TAG_NAME, CATCHES_ATTR, true );
            
            if ( catches != null )
            {
                for ( Iterator j = catches.iterator(); j.hasNext(); )  
                {
                    AnnotationInstance i = ( AnnotationInstance ) j.next();
                    checkRelativePath( i, PATH_ATTR, jclass, decl, false );
                }
            }

            //
            // Check strutsMerge and validatorMerge in the Controller annotation.
            //
            AnnotationInstance controllerAnnotation = CompilerUtils.getAnnotation( decl, CONTROLLER_TAG_NAME );

            if ( controllerAnnotation != null )
            {
                checkRelativePath( controllerAnnotation, VALIDATOR_MERGE_ATTR, jclass, decl, true );
                checkRelativePath( controllerAnnotation, STRUTSMERGE_ATTR, jclass, decl, true );
            }
            
            //
            // Check Forwards and Catches on action methods and exception-handler methods.
            //
            MethodDeclaration[] methods = decl.getMethods();
            for ( int i = 0; i < methods.length; i++ )
            {
                MethodDeclaration method = methods[i];
                AnnotationInstance ann = CompilerUtils.getAnnotation( method, ACTION_TAG_NAME);
                if ( ann == null ) ann = CompilerUtils.getAnnotation( method, EXCEPTION_HANDLER_TAG_NAME );
                
                if ( ann != null )
                {
                    List methodForwards = CompilerUtils.getAnnotationArray( ann, FORWARDS_ATTR, true );
                    String methodName = method.getSimpleName();
                    
                    if ( methodForwards != null )
                    {
                        for ( Iterator j = methodForwards.iterator(); j.hasNext(); )
                        {
                            AnnotationInstance methodForward = ( AnnotationInstance ) j.next();
                            checkRelativePath( methodName, methodForward, PATH_ATTR, jclass, decl, false );
                        }
                    }
                    
                    List methodCatches = CompilerUtils.getAnnotationArray( ann, CATCHES_ATTR, true );
                    
                    if ( methodCatches != null )
                    {
                        for ( Iterator j = methodCatches.iterator(); j.hasNext(); )
                        {
                            AnnotationInstance methodCatch = ( AnnotationInstance ) j.next();
                            checkRelativePath( methodName, methodCatch, PATH_ATTR, jclass, decl, false );
                        }
                    }
                }
            }
        }
    }
1328028
protected void renderGlobalBundleLinks(BundleRendererContext ctx, Writer out, boolean debugOn) throws IOException {

		if (debugOn) {
			addComment("Start adding global members.", out);
		}

		performGlobalBundleLinksRendering(ctx, out, debugOn);

		ctx.setGlobalBundleAdded(true);
		if (debugOn) {
			addComment("Finished adding global members.", out);
		}
	}
545910
public static List<String> getAvailableLocaleSuffixes(String messageBundle, ServletContext servletContext) {

		return getAvailableLocaleSuffixes(messageBundle, MSG_RESOURCE_BUNDLE_SUFFIX, servletContext);
	}
174567
protected void performGlobalBundleLinksRendering(BundleRendererContext ctx, Writer out, boolean debugOn)
			throws IOException {

		ResourceBundlePathsIterator resourceBundleIterator = bundler.getGlobalResourceBundlePaths(getDebugMode(debugOn),
				new ConditionalCommentRenderer(out), ctx.getVariants());
		renderBundleLinks(resourceBundleIterator, ctx, debugOn, out);
	}