/** * Starts bundle usage by creating new {@link BundleAction}. */ public BundleAction start(final String servletPath, final String bundleName) { return new BundleAction(this, servletPath, bundleName); }
/** * Process links. Returns bundle link if this is the first resource * of the same type. Otherwise, returns <code>null</code> indicating * that collection is going on and the original link should be removed. */ public String processLink(final String src) { if (newAction) { if (bundleId == null) { bundleId = bundlesManager.registerNewBundleId(); bundleId += '.' + bundleContentType; } sources.add(src); } if (firstScriptTag) { // this is the first tag, change the url to point to the bundle firstScriptTag = false; return buildStaplerUrl(); } else { // ignore all other script tags return null; } }
@Override public void script(final Tag tag, final CharSequence body) { if (!insideConditionalComment) { String src = Util.toString(tag.getAttributeValue("src")); if (src == null) { super.script(tag, body); return; } if (jsBundleAction.acceptLink(src)) { String link = jsBundleAction.processLink(src); if (link != null) { tag.setAttributeValue("src", link); super.script(tag, body); } return; } } super.script(tag, body); }
/** * Post process final content. Required for <code>RESOURCE_ONLY</code> strategy. */ public char[] postProcess(char[] content) { content = jsBundleAction.replaceBundleId(content); content = cssBundleAction.replaceBundleId(content); return content; } }
@Override public void tag(final Tag tag) { if (!insideConditionalComment) { if (tag.nameEquals(T_LINK)) { CharSequence type = tag.getAttributeValue("type"); if (type != null && CharSequenceUtil.equalsIgnoreCase(type, "text/css")) { String media = Util.toString(tag.getAttributeValue("media")); if (media == null || media.contains("screen")) { String href = Util.toString(tag.getAttributeValue("href")); if (cssBundleAction.acceptLink(href)) { String link = cssBundleAction.processLink(href); if (link != null) { tag.setAttribute("href", link); super.tag(tag); } return; } } } } } super.tag(tag); }
/** * Post process final content. Required for <code>RESOURCE_ONLY</code> strategy. */ public char[] postProcess(char[] content) { content = jsBundleAction.replaceBundleId(content); content = cssBundleAction.replaceBundleId(content); return content; } }
@Override public void script(final Tag tag, final CharSequence body) { if (!insideConditionalComment) { String src = Util.toString(tag.getAttributeValue("src")); if (src == null) { super.script(tag, body); return; } if (jsBundleAction.acceptLink(src)) { String link = jsBundleAction.processLink(src); if (link != null) { tag.setAttributeValue("src", link); super.script(tag, body); } return; } } super.script(tag, body); }
/** * Starts bundle usage by creating new {@link BundleAction}. */ public BundleAction start(final String servletPath, final String bundleName) { return new BundleAction(this, servletPath, bundleName); }
/** * Process links. Returns bundle link if this is the first resource * of the same type. Otherwise, returns <code>null</code> indicating * that collection is going on and the original link should be removed. */ public String processLink(final String src) { if (newAction) { if (bundleId == null) { bundleId = bundlesManager.registerNewBundleId(); bundleId += '.' + bundleContentType; } sources.add(src); } if (firstScriptTag) { // this is the first tag, change the url to point to the bundle firstScriptTag = false; return buildStaplerUrl(); } else { // ignore all other script tags return null; } }
@Override public void tag(final Tag tag) { if (!insideConditionalComment) { if (tag.nameEquals(T_LINK)) { CharSequence type = tag.getAttributeValue("type"); if (type != null && CharSequenceUtil.equalsIgnoreCase(type, "text/css")) { String media = Util.toString(tag.getAttributeValue("media")); if (media == null || media.contains("screen")) { String href = Util.toString(tag.getAttributeValue("href")); if (cssBundleAction.acceptLink(href)) { String link = cssBundleAction.processLink(href); if (link != null) { tag.setAttribute("href", link); super.tag(tag); } return; } } } } } super.tag(tag); }