/** * @return charset setting */ protected final Charset getCharset() { if (Application.exists()) { return Bootstrap.getSettings().getBootstrapLessCompilerSettings().getCharset(); } else { LOG.warn("no application assigned to current thread, return default charset: {}", Charsets.UTF_8); return Charsets.UTF_8; } } }
/** * Gets the {@link LessJsLessCompiler} to be used. By default returns the configured compiler on * application level, but can be overridden by the user application to provide compiler * specific to the resource. * * @return the configured application level less compiler. May be {@code null}. */ private static IBootstrapLessCompiler getCompiler() { if (Application.exists()) { return Bootstrap.getSettings().getBootstrapLessCompilerSettings().getLessCompiler(); } throw new IllegalStateException("there is no application assigned to current thread."); }
@Override protected IBootstrapSettings createBootstrapSettings() { IBootstrapSettings settings = super.createBootstrapSettings(); settings.getBootstrapLessCompilerSettings() .setUseLessCompiler(true) .setCacheStrategy(IBootstrapLessCompilerSettings.CacheStrategy.Never); return settings; }
/** * use fixed variation value to trigger {@link LessResourceStreamLocator} * * @return static string {@link LessResourceReference#VARIATION} if less is active */ @Override public final String getVariation() { return Bootstrap.getSettings().getBootstrapLessCompilerSettings().useLessCompiler() ? VARIATION : null; } }
/** * @return true if less compiler should be used. */ private static boolean useLessCompiler() { return Bootstrap.getSettings().getBootstrapLessCompilerSettings().useLessCompiler(); }
@Override protected void onBefore() { try { cssContent = IOUtils.toString(BootswatchCssReference.CERULEAN.getResource().getResourceStream().getInputStream()); } catch (IOException e) { throw new RuntimeException(e); } catch (ResourceStreamNotFoundException e) { throw new RuntimeException(e); } getBootstrapSettings().getBootstrapLessCompilerSettings() .setCacheStrategy(IBootstrapLessCompilerSettings.CacheStrategy.Never) .setUseLessCompiler(true); }
/** * updates the security manager to allow fonts and less files if necessary. * * @param app The current application * @param settings The settings to use */ private static void updateSecurityManager(final Application app, final IBootstrapSettings settings) { final IPackageResourceGuard packageResourceGuard = app.getResourceSettings().getPackageResourceGuard(); if (packageResourceGuard instanceof SecurePackageResourceGuard) { SecurePackageResourceGuard guard = (SecurePackageResourceGuard) packageResourceGuard; guard.addPattern("+*.woff"); guard.addPattern("+*.eot"); guard.addPattern("+*.svg"); guard.addPattern("+*.ttf"); if (settings.getBootstrapLessCompilerSettings().useLessCompiler()) { guard.addPattern("+*.less"); } } }
@Override public String asText() { InputStream stream = null; try { stream = getInputStream(); return IOUtils.toString(stream, Bootstrap.getSettings(Application.get()).getBootstrapLessCompilerSettings().getCharset().name()); } catch (IOException e) { throw new WicketRuntimeException(e); } finally { IOUtils.closeQuietly(stream); } }
/** * Installs given settings for given application * * @param app The current application * @param settings The settings to use */ public static void install(final Application app, final IBootstrapSettings settings) { app.setMetaData(BOOTSTRAP_SETTINGS_METADATA_KEY, settings); if (settings.getBootstrapLessCompilerSettings().useLessCompiler()) { app.getResourceSettings().setResourceStreamLocator(new CachingResourceStreamLocator(new LessResourceStreamLocator())); } if (settings.updateSecurityManger()) { updateSecurityManager(app, settings); } }