congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
HtmlStaplerBundlesManager
Code IndexAdd Tabnine to your IDE (free)

How to use
HtmlStaplerBundlesManager
in
jodd.htmlstapler

Best Java code snippets using jodd.htmlstapler.HtmlStaplerBundlesManager (Showing top 18 results out of 315)

origin: oblac/jodd

  @Test
  void testRandomDigest() {
    HtmlStaplerBundlesManager hsbm = new HtmlStaplerBundlesManager("/ctx", "/", RESOURCES_ONLY);

    String digest = hsbm.createDigest("source");

    hsbm.setRandomDigestChars(5);

    String digest2 = hsbm.createDigest("source");
    String digest3 = hsbm.createDigest("source");

    assertEquals(digest2, digest3);
    assertTrue(digest2.startsWith(digest));


    hsbm.setRandomDigestChars(0);

    digest2 = hsbm.createDigest("source");

    assertEquals(digest, digest2);
  }
}
origin: oblac/jodd

String bundleId = createDigest(sourcesString);
bundleId += '.' + bundleContentType;
  createBundle(contextPath, actionPath, bundleId, sources);
} catch (IOException ioex) {
  throw new HtmlStaplerException("Can't create bundle", ioex);
origin: oblac/jodd

/**
 * Lookups for bundle file.
 */
public File lookupBundleFile(String bundleId) {
  if ((mirrors != null) && (!mirrors.isEmpty())) {
    String realBundleId = mirrors.remove(bundleId);
    if (realBundleId != null) {
      bundleId = realBundleId;
    }
  }
  return createBundleFile(bundleId);
}
origin: oblac/jodd

/**
 * Creates new bundle action.
 */
public BundleAction(final HtmlStaplerBundlesManager bundlesManager, final String servletPath, final String bundleContentType) {
  this.bundlesManager = bundlesManager;
  this.bundleContentType = bundleContentType;
  this.strategy = bundlesManager.getStrategy();
  String realActionPath = bundlesManager.resolveRealActionPath(servletPath);
  actionPath = realActionPath + '*' + bundleContentType;
  contextPath = bundlesManager.contextPath;
  if (strategy == ACTION_MANAGED) {
    bundleId = bundlesManager.lookupBundleId(actionPath);
    newAction = (bundleId == null);
    if (newAction) {
      sources = new ArrayList<>();
    }
  } else {
    bundleId = BUNDLE_ID_MARKER + bundleContentType;
    bundleIdMark = bundleId.toCharArray();
    newAction = true;
    sources = new ArrayList<>();
  }
  firstScriptTag = true;
}
origin: oblac/jodd

@Override
protected boolean processActionPath(final HttpServletRequest servletRequest, final HttpServletResponse servletResponse, final String actionPath) throws IOException {
  String bundlePath = '/' + bundlesManager.getStaplerPath() + '/';
  if (!actionPath.startsWith(bundlePath)) {
    return false;
  }
  String bundleId = actionPath.substring(bundlePath.length());
  File file = bundlesManager.lookupBundleFile(bundleId);
  if (log.isDebugEnabled()) {
    log.debug("bundle: " + bundleId);
  }
  int ndx = bundleId.lastIndexOf('.');
  String extension = bundleId.substring(ndx + 1);
  String contentType = MimeTypes.getMimeType(extension);
  servletResponse.setContentType(contentType);
  if (useGzip && ServletUtil.isGzipSupported(servletRequest)) {
    file = bundlesManager.lookupGzipBundleFile(file);
    servletResponse.setHeader("Content-Encoding", "gzip");
  }
  if (!file.exists()) {
    throw new IOException("bundle not found: " + bundleId);
  }
  servletResponse.setHeader("Content-Length", String.valueOf(file.length()));
  servletResponse.setHeader("Last-Modified", TimeUtil.formatHttpDate(file.lastModified()));
  if (cacheMaxAge > 0) {
    servletResponse.setHeader("Cache-Control", "max-age=" + cacheMaxAge);
  }
  sendBundleFile(servletResponse, file);
  return true;
}
origin: oblac/jodd

File bundleFile = createBundleFile(bundleId);
if (bundleFile.exists()) {
  return;
  if (isExternalResource(src)) {
    try {
      content = NetUtil.downloadString(src, localFilesEncoding);
      if (isCssResource(src)) {
        content = fixCssRelativeUrls(content, src);
    content = onResourceContent(content);
    sb.append(content);
origin: oblac/jodd

  @Test
  void testRelativeCssUrls() {


    HtmlStaplerBundlesManager htmlStapler = new HtmlStaplerBundlesManager("/", "", HtmlStaplerBundlesManager.Strategy.RESOURCES_ONLY);

    assertEquals(
        "background: url('/absolute/path')",
        htmlStapler.fixCssRelativeUrls("background: url(/absolute/path)", "css/"));

    assertEquals(
        "background: url('../css/relative/path')",
        htmlStapler.fixCssRelativeUrls("background: url(relative/path)", "css/"));
  }
}
origin: oblac/jodd

/**
 * Creates {@link HtmlStaplerBundlesManager} instance.
 */
protected HtmlStaplerBundlesManager createBundleManager(final ServletContext servletContext, final Strategy strategy) {
  String webRoot = servletContext.getRealPath(StringPool.EMPTY);
  String contextPath = ServletUtil.getContextPath(servletContext);
  return new HtmlStaplerBundlesManager(contextPath, webRoot, strategy);
}
origin: oblac/jodd

/**
 * Builds stapler URL based on bundle action data.
 */
protected String buildStaplerUrl() {
  return contextPath + '/' + bundlesManager.getStaplerPath() + '/' + bundleId;
}
origin: oblac/jodd

/**
 * Returns the content with all relative URLs fixed.
 */
protected String fixCssRelativeUrls(final String content, final String src) {
  String path = FileNameUtil.getPath(src);
  Matcher matcher = CSS_URL_PATTERN.matcher(content);
  StringBuilder sb = new StringBuilder(content.length());
  int start = 0;
  while (matcher.find()) {
    sb.append(content.substring(start, matcher.start()));
    String url = fixRelativeUrl(matcher.group(1), path);
    sb.append(url);
    start = matcher.end();
  }
  sb.append(content.substring(start));
  return sb.toString();
}
origin: org.jodd/jodd-htmlstapler

File bundleFile = createBundleFile(bundleId);
if (bundleFile.exists()) {
  return;
  if (isExternalResource(src)) {
    try {
      content = NetUtil.downloadString(src, localFilesEncoding);
      if (isCssResource(src)) {
        content = fixCssRelativeUrls(content, src);
    content = onResourceContent(content);
    sb.append(content);
origin: org.jodd/jodd-htmlstapler

/**
 * Creates new bundle action.
 */
public BundleAction(final HtmlStaplerBundlesManager bundlesManager, final String servletPath, final String bundleContentType) {
  this.bundlesManager = bundlesManager;
  this.bundleContentType = bundleContentType;
  this.strategy = bundlesManager.getStrategy();
  String realActionPath = bundlesManager.resolveRealActionPath(servletPath);
  actionPath = realActionPath + '*' + bundleContentType;
  contextPath = bundlesManager.contextPath;
  if (strategy == ACTION_MANAGED) {
    bundleId = bundlesManager.lookupBundleId(actionPath);
    newAction = (bundleId == null);
    if (newAction) {
      sources = new ArrayList<>();
    }
  } else {
    bundleId = BUNDLE_ID_MARKER + bundleContentType;
    bundleIdMark = bundleId.toCharArray();
    newAction = true;
    sources = new ArrayList<>();
  }
  firstScriptTag = true;
}
origin: org.jodd/jodd-htmlstapler

@Override
protected boolean processActionPath(final HttpServletRequest servletRequest, final HttpServletResponse servletResponse, final String actionPath) throws IOException {
  String bundlePath = '/' + bundlesManager.getStaplerPath() + '/';
  if (!actionPath.startsWith(bundlePath)) {
    return false;
  }
  String bundleId = actionPath.substring(bundlePath.length());
  File file = bundlesManager.lookupBundleFile(bundleId);
  if (log.isDebugEnabled()) {
    log.debug("bundle: " + bundleId);
  }
  int ndx = bundleId.lastIndexOf('.');
  String extension = bundleId.substring(ndx + 1);
  String contentType = MimeTypes.getMimeType(extension);
  servletResponse.setContentType(contentType);
  if (useGzip && ServletUtil.isGzipSupported(servletRequest)) {
    file = bundlesManager.lookupGzipBundleFile(file);
    servletResponse.setHeader("Content-Encoding", "gzip");
  }
  if (!file.exists()) {
    throw new IOException("bundle not found: " + bundleId);
  }
  servletResponse.setHeader("Content-Length", String.valueOf(file.length()));
  servletResponse.setHeader("Last-Modified", TimeUtil.formatHttpDate(file.lastModified()));
  if (cacheMaxAge > 0) {
    servletResponse.setHeader("Cache-Control", "max-age=" + cacheMaxAge);
  }
  sendBundleFile(servletResponse, file);
  return true;
}
origin: org.jodd/jodd-htmlstapler

/**
 * Creates {@link HtmlStaplerBundlesManager} instance.
 */
protected HtmlStaplerBundlesManager createBundleManager(final ServletContext servletContext, final Strategy strategy) {
  String webRoot = servletContext.getRealPath(StringPool.EMPTY);
  String contextPath = ServletUtil.getContextPath(servletContext);
  return new HtmlStaplerBundlesManager(contextPath, webRoot, strategy);
}
origin: org.jodd/jodd-htmlstapler

/**
 * Builds stapler URL based on bundle action data.
 */
protected String buildStaplerUrl() {
  return contextPath + '/' + bundlesManager.getStaplerPath() + '/' + bundleId;
}
origin: org.jodd/jodd-htmlstapler

/**
 * Returns the content with all relative URLs fixed.
 */
protected String fixCssRelativeUrls(final String content, final String src) {
  String path = FileNameUtil.getPath(src);
  Matcher matcher = CSS_URL_PATTERN.matcher(content);
  StringBuilder sb = new StringBuilder(content.length());
  int start = 0;
  while (matcher.find()) {
    sb.append(content.substring(start, matcher.start()));
    String url = fixRelativeUrl(matcher.group(1), path);
    sb.append(url);
    start = matcher.end();
  }
  sb.append(content.substring(start));
  return sb.toString();
}
origin: org.jodd/jodd-htmlstapler

String bundleId = createDigest(sourcesString);
bundleId += '.' + bundleContentType;
  createBundle(contextPath, actionPath, bundleId, sources);
} catch (IOException ioex) {
  throw new HtmlStaplerException("Can't create bundle", ioex);
origin: org.jodd/jodd-htmlstapler

/**
 * Lookups for bundle file.
 */
public File lookupBundleFile(String bundleId) {
  if ((mirrors != null) && (!mirrors.isEmpty())) {
    String realBundleId = mirrors.remove(bundleId);
    if (realBundleId != null) {
      bundleId = realBundleId;
    }
  }
  return createBundleFile(bundleId);
}
jodd.htmlstaplerHtmlStaplerBundlesManager

Javadoc

HTML resources bundles manager.

Most used methods

  • <init>
    Creates new instance and initialize it.
  • createDigest
    Creates digest i.e. bundle id from given string. Returned digest must be filename safe, for all plat
  • fixCssRelativeUrls
    Returns the content with all relative URLs fixed.
  • createBundle
    Creates bundle file by loading resource files content. If bundle file already exist it will not be r
  • createBundleFile
    Creates bundle file in bundleFolder/staplerPath. Only file object is created, not the file content.
  • fixRelativeUrl
    For a given URL (optionally quoted), produces CSS URL where relative paths are fixed and prefixed wi
  • getStaplerPath
    Returns stapler path. It is both the file system folder name and the web folder name.
  • getStrategy
    Returns current Strategy.
  • isCssResource
    Returns true if resource is CSS, so the CSS urls can be fixed.
  • isExternalResource
    Returns true if resource link has to be downloaded. By default, if resource link starts with "http:/
  • lookupBundleFile
    Lookups for bundle file.
  • lookupBundleId
    Lookups for a bundle id for a given action. Returns null if action still has no bundle. Returns an e
  • lookupBundleFile,
  • lookupBundleId,
  • lookupGzipBundleFile,
  • onResourceContent,
  • registerBundle,
  • registerNewBundleId,
  • reset,
  • resolveRealActionPath,
  • start,
  • setRandomDigestChars

Popular in Java

  • Reading from database using SQL prepared statement
  • onRequestPermissionsResult (Fragment)
  • getSystemService (Context)
  • onCreateOptionsMenu (Activity)
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now