Compile the LESS source to a CSS source

@param bundle
the bundle
@param content
the resource content to compile
@param path
the compiled resource path
@param context
the generator context
@return the compiled CSS content
18332
public String compile(JoinableResourceBundle bundle, String content, String path, GeneratorContext context) {

		JawrLessSource source = new JawrLessSource(bundle, content, path, rsHandler);
		try {
			CompilationResult result = compiler.compile(source, lessConfig);
			addLinkedResources(path, context, source.getLinkedResources());
			return result.getCss();
		} catch (Less4jException e) {
			throw new BundlingProcessException("Unable to generate content for resource path : '" + path + "'", e);
		}

	}
512754
public File getGeneratedCssFile(String path) {

		String rootDir = tempDir + JawrConstant.CSS_SMARTSPRITES_TMP_DIR;
		String fPath = null;
		if (jawrConfig.isWorkingDirectoryInWebApp()) {
			fPath = jawrConfig.getContext().getRealPath(rootDir + getCssPath(path));

		} else {
			fPath = rootDir + getCssPath(path);
		}

		return new File(fPath);
	}
1062740
function compileFile( sourceBundle, bundleFile, config, callback ) {
	var fname = sourceBundle + "/bundle.json";
	fs.readFile(fname, 'utf8', function (err,data) {
		if (err) {
			console.error("Unable to load file",fname);
			if (callback) callback( err, null );
			return;
		}

		// Update path if missing
		if (!config['path'])
			config['path'] = path.dirname( sourceBundle );

		// Compile
		compile( JSON.parse(data), bundleFile, config, callback );

	});
}
400482
public static IPath getBundlePath(Bundle bundle) {
		IPath path = getBinFolderPath(bundle);
		if (path == null) {
			// common jar file case, no bin folder
			try {
				path = new Path(FileLocator.getBundleFile(bundle).getAbsolutePath());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return path;
	}
282593
public static ResourceBundle getResourceBundle(String bundleName, Locale locale) {
        ResourceBundle bundle = null;

        boolean isDev = false;
        if (Ameba.getApp() != null) {
            isDev = Ameba.getApp().getMode().isDev();
            BUNDLE_CONTROL.noCache = isDev;
        }
        if (!isDev) {
            bundle = RESOURCE_BUNDLES.get(bundleName, locale);
        }
        if (bundle == null) {
            try {
                bundle = ResourceBundle.getBundle(
                        bundleName,
                        locale,
                        ClassUtils.getContextClassLoader(),
                        BUNDLE_CONTROL
                );
            } catch (MissingResourceException e) {
                // no op
            }
        }

        if (bundle != null && !isDev) {
            RESOURCE_BUNDLES.put(bundleName, locale, bundle);
        }

        return bundle;
    }
443605
function compileLess(lessPaths, cb) {

        if (lessPaths.length > 0) {

            var path = pathModule.join(base, lessPaths.shift());
            var content = fs.readFileSync(path, 'utf8');

            less.render(
              content,

            function(err, result) {
                if (err) {
                    cb(FOUND_ERROR, 'Error while compiling less template "' + path + '". Error from "less" plugin: ' + err);
                }

                if (options.autoprefixer) {
                  // Call autoprefixer on current built css
                  postcss([ autoprefixer(options.autoprefixer) ])
                    .process(result.css)
                    .then(function(prefixedResult) {
                      // escape any backticks that comeup in the compiled css
                      cb(FOUND_SUCCESS, prefixedResult.css.toString().replace(/\\([\s\S])|(`)/g,"\\$1$2"), lessPaths);
                    });
                } else {
                  // escape any backticks that comeup in the compiled css
                  cb(FOUND_SUCCESS, result.css.toString().replace(/\\([\s\S])|(`)/g,"\\$1$2"), lessPaths);
                }
            });
        }
        else {
            cb(CODE_EXIT);
        }
    }
468738
public static BundleContext getBundleContextByBundleId(long bundleId) {
        Bundle bundle = bundleContext.getBundle(bundleId);
        if (bundle != null) {
            return bundle.getBundleContext();
        } else {
            return null;
        }
    }
595578
protected String rewriteUrl(GeneratorContext context, String content) throws IOException {

		JawrConfig jawrConfig = context.getConfig();
		CssImageUrlRewriter rewriter = new CssImageUrlRewriter(jawrConfig);
		String bundlePath = PathNormalizer.joinPaths(jawrConfig.getServletMapping(), ResourceGenerator.CSS_DEBUGPATH);

		StringBuffer result = rewriter.rewriteUrl(context.getPath(), bundlePath, content);
		return result.toString();
	}
1297159
protected List<RenderedLink> createLinkToBundle(
			ResourceBundlesHandler handler, String path, String resourceType,
			Map<String, String> variantMap) throws IOException {

		ArrayList<RenderedLink> linksToBundle = new ArrayList<RenderedLink>();

		BasicBundleRenderer bundleRenderer = new BasicBundleRenderer(handler,
				resourceType);
		StringWriter sw = new StringWriter();

		// The gzip compression will be made by the CDN server
		// So we force it to false.
		boolean useGzip = false;

		// The generation of bundle is the same in SSL and non SSL mode
		boolean isSslRequest = false;

		// First deals with the production mode
		handler.getConfig().setDebugModeOn(false);
		handler.getConfig().setGzipResourcesModeOn(useGzip);

		BundleRendererContext ctx = new BundleRendererContext("", variantMap,
				useGzip, isSslRequest);
		bundleRenderer.renderBundleLinks(path, ctx, sw);

		// Then take in account the debug mode
		handler.getConfig().setDebugModeOn(true);
		ctx = new BundleRendererContext("", variantMap, useGzip, isSslRequest);
		bundleRenderer.renderBundleLinks(path, ctx, sw);

		List<RenderedLink> renderedLinks = bundleRenderer.getRenderedLinks();
		// Remove context override path if it's defined.
		String contextPathOverride = handler.getConfig()
				.getContextPathOverride();
		for (Iterator<RenderedLink> iterator = renderedLinks.iterator(); iterator
				.hasNext();) {
			RenderedLink renderedLink = iterator.next();
			String renderedLinkPath = renderedLink.getLink();
			// Remove the context path override
			if (StringUtils.isNotEmpty(contextPathOverride)
					&& renderedLinkPath.startsWith(contextPathOverride)) {
				renderedLinkPath = renderedLinkPath
						.substring(contextPathOverride.length());
			}
			renderedLink.setLink(PathNormalizer.asPath(renderedLinkPath));
			linksToBundle.add(renderedLink);
		}

		return linksToBundle;
	}
1183715
function CSSPluginBase(compileCSS) {
  this.compileCSS = compileCSS;

  this.translate = function(load, opts) {
    var loader = this;
    if (loader.builder && loader.buildCSS === false) {
      load.metadata.build = false;
      return;
    }

    var path = this._nodeRequire && this._nodeRequire('path');

    return Promise.resolve(compileCSS.call(loader, load.source, load.address, load.metadata.loaderOptions || {}))
    .then(function(result) {
      load.metadata.style = result.css;
      load.metadata.styleSourceMap = result.map;
      if (result.moduleFormat)
        load.metadata.format = result.moduleFormat;
      return result.moduleSource || '';
    });
  };
}
1354495
public function compile($path)
	{
		switch (pathinfo($path, PATHINFO_EXTENSION)) {
			case 'less':
				$less = new Less_Parser;
				$content = '/*' . md5(File::get($path)) . "*/\n" . $less->parseFile($path)->getCss();
				
				break;
				
			default:
				$content = File::get($path);
		}
		
		return $content;
	}
1293008
protected String createBundleLink(String bundleId, String contextPath) {
    	
    	// When debug mode is on and the resource is generated the path must include a parameter
    	JawrConfig config = bundler.getConfig();
		if( config.isDebugModeOn() && 
    		config.getGeneratorRegistry().isPathGenerated(bundleId)) {
    		bundleId = PathNormalizer.createGenerationPath(bundleId, config.getGeneratorRegistry(), null);
    	}
    	String fullPath = PathNormalizer.joinPaths(config.getServletMapping(), bundleId);
    	fullPath = PathNormalizer.joinPaths(contextPath,fullPath);

    	return renderLink(fullPath);
    }
1122601
public static BundleContext getBundleContext(Class<?> clazz) {
        BundleContext context = null; //we'll return null if not running inside an OSGi framework (e.g. unit test)
        if (FrameworkState.isValid()) {
            Bundle bundle = FrameworkUtil.getBundle(clazz);

            if (bundle != null) {
                context = bundle.getBundleContext();
            }
        }
        return context;
    }
921247
public Reader generateResource(String path, GeneratorContext context) {
	
		Locale locale = null == context.getLocale() ? Locale.getDefault()
				: context.getLocale();
		String validators = context.getPath();
		String validatorParams = context.getParenthesesParam();

		String messagesNS = MessageBundleScriptCreator.DEFAULT_NAMESPACE;
		boolean stopOnErrors = true;

		StringTokenizer valparams = new StringTokenizer(validatorParams, "|");
		String validatorMappingKey = valparams.nextToken();
		if (valparams.hasMoreTokens())
			messagesNS = valparams.nextToken();
		if (valparams.hasMoreTokens())
			stopOnErrors = Boolean.valueOf(valparams.nextToken())
					.booleanValue();

		// Build the ValidatorResources if it doesn't exist yet
		if (!validatorResourcesMap.containsKey(validatorMappingKey)) {
			createValidatorResources(validatorMappingKey, context.getConfig());
		}

		ValidatorResources validatorResources = (ValidatorResources) validatorResourcesMap
				.get(validatorMappingKey);
		StringBuffer sb = new StringBuffer();
		StringTokenizer tk = new StringTokenizer(validators, "|");
		while (tk.hasMoreTokens()) {
			String validator = tk.nextToken();
			if (STATIC_JAVASCRIPT_KEY.equals(validator)) {
				sb.append(buildStaticJavascript(validatorResources));
			} else
				sb.append(buildFormJavascript(validatorResources, validator,
						locale, messagesNS, stopOnErrors));

		}

		return new StringReader(sb.toString());
	}
879629
@Override
	protected BundleRenderer createRenderer(FacesContext context) {

		ResourceBundlesHandler rsHandler = getResourceBundlesHandler(context);

		String media = (String) getAttributes().get(JawrConstant.MEDIA_ATTR);
		boolean alternate = Boolean.parseBoolean((String) getAttributes().get(JawrConstant.ALTERNATE_ATTR));
		boolean displayAlternate = Boolean
				.parseBoolean((String) getAttributes().get(JawrConstant.DISPLAY_ALTERNATE_ATTR));
		String title = (String) getAttributes().get(JawrConstant.TITLE_ATTR);

		return RendererFactory.getCssBundleRenderer(rsHandler, getUseRandomParamFlag(rsHandler.getConfig()), media,
				alternate, displayAlternate, title);
	}
711023
@Override
	protected Reader generateResource(String path, GeneratorContext context) {

		Reader reader = null;
		ResourceReaderHandler readerHandler = context.getResourceReaderHandler();

		String skinRootDir = getSkinRootDir(path, skinMapping.keySet());
		Map<String, VariantSet> ctxVariantSetMap = skinMapping.get(skinRootDir);

		String skinVariantPath = path.substring(skinRootDir.length());
		String[] paths = skinVariantPath.split(JawrConstant.URL_SEPARATOR);

		VariantResourceReaderStrategy strategy = getVariantStrategy(context, ctxVariantSetMap);
		Map<String, String> variantMap = null;
		do {
			variantMap = strategy.nextVariantMapConbination();
			if (variantMap != null) {
				JoinableResourceBundle bundle = context.getBundle();
				reader = getResourceReader(bundle, path, readerHandler, skinRootDir, paths, variantMap);
			}
		} while (variantMap != null && reader == null);

		return reader;
	}
346992
protected Reader generateResourceForDebug(Reader rd, GeneratorContext context) {

		// Rewrite the image URL
		StringWriter writer = new StringWriter();
		try {
			IOUtils.copy(rd, writer);
			String content = rewriteUrl(context, writer.toString());
			rd = new StringReader(content);
		} catch (IOException e) {
			throw new BundlingProcessException(e);
		}

		return rd;
	}