jawr-bundle-processor/src/main/java/net/jawr/web/bundle/processor/BundleProcessor.java
/**
	 * Creates the bundles in the destination directory
	 * 
	 * @param servlet
	 *            the servlet
	 * @param bundleHandler
	 *            the bundles handler
	 * @param destDirPath
	 *            the destination directory path
	 * @param servletMapping
	 *            the mapping of the servlet
	 * @param keepUrlMapping
	 *            the flag indicating if we must keep the URL mapping
	 * @throws IOException
	 *             if an IO exception occurs
	 * @throws ServletException
	 *             if a servlet exception occurs
	 */
Creates the bundles in the destination directory


Creates the bundles in the destination directory
protected void createBundles(HttpServlet servlet,
			ResourceBundlesHandler bundleHandler, String destDirPath,
			String servletMapping, boolean keepUrlMapping) throws IOException,
			ServletException {
		List<JoinableResourceBundle> bundles = bundleHandler
				.getContextBundles();
		Iterator<JoinableResourceBundle> bundleIterator = bundles.iterator();
		MockServletResponse response = new MockServletResponse();
		MockServletRequest request = new MockServletRequest(
				JAWR_BUNDLE_PROCESSOR_CONTEXT_PATH);
		MockServletSession session = new MockServletSession(
				servlet.getServletContext());
		request.setSession(session);
		String resourceType = servlet.getServletConfig().getInitParameter(
				TYPE_INIT_PARAMETER);
		if (resourceType == null) {
			resourceType = JawrConstant.JS_TYPE;
		}
		while (bundleIterator.hasNext()) {
			JoinableResourceBundle bundle = (JoinableResourceBundle) bundleIterator
					.next();
			URL url = servlet.getServletContext().getResource(bundle.getId());
			if (url != null) {
				logger.error("It is not recommended to use a bundle name which could be in conflict with a resource.\n"
						+ "Please rename your bundle '"
						+ bundle.getId()
						+ "' to avoid any issue");
			}
			List<Map<String, String>> allVariants = VariantUtils
					.getAllVariants(bundle.getVariants());
			if (allVariants == null) {
				allVariants = new ArrayList<Map<String, String>>();
			}
			if (allVariants.isEmpty()) {
				allVariants.add(new HashMap<String, String>());
			}
			for (Iterator<Map<String, String>> it = allVariants.iterator(); it
					.hasNext();) {
				Map<String, String> variantMap = (Map<String, String>) it
						.next();
				List<RenderedLink> linksToBundle = createLinkToBundle(
						bundleHandler, bundle.getId(), resourceType, variantMap);
				for (Iterator<RenderedLink> iteratorLinks = linksToBundle
						.iterator(); iteratorLinks.hasNext();) {
					RenderedLink renderedLink = iteratorLinks.next();
					String path = renderedLink.getLink();
					JawrConfig config = bundleHandler.getConfig();
					config.setDebugModeOn(renderedLink.isDebugMode());
					String finalBundlePath = null;
					if (keepUrlMapping) {
						finalBundlePath = path;
					} else {
						finalBundlePath = getFinalBundlePath(path, config,
								variantMap);
					}
					setRequestUrl(request, variantMap, path, config);
					if (!(path.indexOf("?") != -1) || !keepUrlMapping) {
						File bundleFile = new File(destDirPath, finalBundlePath);
						createBundleFile(servlet, response, request, path,
								bundleFile, servletMapping);
					}
				}
			}
		}
	}
protected void createBundles ( HttpServlet servlet , ResourceBundlesHandler bundleHandler , String destDirPath , String servletMapping , boolean keepUrlMapping ) throws IOException , ServletException { List < JoinableResourceBundle > bundles = bundleHandler . getContextBundles ( ) ; Iterator < JoinableResourceBundle > bundleIterator = bundles . iterator ( ) ; MockServletResponse response = new MockServletResponse ( ) ; MockServletRequest request = new MockServletRequest ( JAWR_BUNDLE_PROCESSOR_CONTEXT_PATH ) ; MockServletSession session = new MockServletSession ( servlet . getServletContext ( ) ) ; request . setSession ( session ) ; String resourceType = servlet . getServletConfig ( ) . getInitParameter ( TYPE_INIT_PARAMETER ) ; if ( resourceType == null ) { resourceType = JawrConstant . JS_TYPE ; } while ( bundleIterator . hasNext ( ) ) { JoinableResourceBundle bundle = ( JoinableResourceBundle ) bundleIterator . next ( ) ; URL url = servlet . getServletContext ( ) . getResource ( bundle . getId ( ) ) ; if ( url != null ) { logger . error ( "It is not recommended to use a bundle name which could be in conflict with a resource.\n" + "Please rename your bundle '" + bundle . getId ( ) + "' to avoid any issue" ) ; } List < Map < String , String > > allVariants = VariantUtils . getAllVariants ( bundle . getVariants ( ) ) ; if ( allVariants == null ) { allVariants = new ArrayList < Map < String , String > > ( ) ; } if ( allVariants . isEmpty ( ) ) { allVariants . add ( new HashMap < String , String > ( ) ) ; } for ( Iterator < Map < String , String > > it = allVariants . iterator ( ) ; it . hasNext ( ) ; ) { Map < String , String > variantMap = ( Map < String , String > ) it . next ( ) ; List < RenderedLink > linksToBundle = createLinkToBundle ( bundleHandler , bundle . getId ( ) , resourceType , variantMap ) ; for ( Iterator < RenderedLink > iteratorLinks = linksToBundle . iterator ( ) ; iteratorLinks . hasNext ( ) ; ) { RenderedLink renderedLink = iteratorLinks . next ( ) ; String path = renderedLink . getLink ( ) ; JawrConfig config = bundleHandler . getConfig ( ) ; config . setDebugModeOn ( renderedLink . isDebugMode ( ) ) ; String finalBundlePath = null ; if ( keepUrlMapping ) { finalBundlePath = path ; } else { finalBundlePath = getFinalBundlePath ( path , config , variantMap ) ; } setRequestUrl ( request , variantMap , path , config ) ; if ( ! ( path . indexOf ( "?" ) != - 1 ) || ! keepUrlMapping ) { File bundleFile = new File ( destDirPath , finalBundlePath ) ; createBundleFile ( servlet , response , request , path , bundleFile , servletMapping ) ; } } } } }
Creates the bundles in the destination directory
Creates the bundles in the destination directory
// For the list of bundle defines, create the file associated // Check if there is a resource file, which could be in conflict // with the bundle name // Creates the bundle file for each local variant // Force the debug mode of the config to match what was used // in the generated link // Sets the request URL // We can't use path for generated resources because it's // not a valid file path ( /jawr_generator.js?xxx.... )