[GitHub] wicket pull request: WICKET-5827 - CssUrlReplacer supports base64 ...
Github user klopfdreh commented on the pull request: https://github.com/apache/wicket/pull/97#issuecomment-78459213 Integrated: https://github.com/apache/wicket/commit/8c9fd4efa2abdd774fd0e396131b4237a3bc528f --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] wicket pull request: WICKET-5827 - CssUrlReplacer supports base64 ...
Github user klopfdreh commented on the pull request: https://github.com/apache/wicket/pull/96#issuecomment-78459135 Integrated: https://github.com/apache/wicket/commit/aa859dee621959de98e39ecafda28d9ab7ccc7fa --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] wicket pull request: WICKET-5827 - CssUrlReplacer supports base64 ...
Github user klopfdreh closed the pull request at: https://github.com/apache/wicket/pull/96 --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] wicket pull request: WICKET-5827 - CssUrlReplacer supports base64 ...
Github user klopfdreh closed the pull request at: https://github.com/apache/wicket/pull/97 --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] wicket pull request: WICKET-5827 - CssUrlReplacer supports base64 ...
Github user martin-g commented on a diff in the pull request: https://github.com/apache/wicket/pull/97#discussion_r26283760 --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacer.java --- @@ -71,21 +82,67 @@ else if (imageCandidateUrl.isContextAbsolute()) // relativize against the url for the containing CSS file Url cssUrlCopy = new Url(cssUrl); cssUrlCopy.resolveRelative(imageCandidateUrl); - PackageResourceReference imageReference = new PackageResourceReference(scope, - cssUrlCopy.toString()); - processedUrl = cycle.urlFor(imageReference, null); + + // if the image should be processed as URL or base64 embedded + if (cssUrlCopy.getQueryString() != null && + cssUrlCopy.getQueryString().contains(EMBED_BASE64)) + { + embedded = true; + PackageResourceReference imageReference = new PackageResourceReference(scope, + cssUrlCopy.toString().replace("?" + EMBED_BASE64, "")); + try + { + processedUrl = createBase64EncodedImage(imageReference); + } + catch (Exception e) + { + throw new WicketRuntimeException( + "Error while embedding an image into the css: " + + imageReference.toString(), e); + } + } + else + { + PackageResourceReference imageReference = new PackageResourceReference(scope, + cssUrlCopy.toString()); + processedUrl = cycle.urlFor(imageReference, null); + } } - matcher.appendReplacement(output, "url('" + processedUrl + "')"); + matcher.appendReplacement(output, embedded ? "url(" + processedUrl + ")" : "url('" + + processedUrl + "')"); } matcher.appendTail(output); return output.toString(); } + /** +* Creates a base64 encoded image string based on the given image reference +* +* @param imageReference +*the image reference to create the base64 encoded image string of +* @return the base64 encoded image string +* @throws ResourceStreamNotFoundException +* if the resource couldn't be found +* @throws IOException +* if the stream couldn't be read +*/ + private CharSequence createBase64EncodedImage(PackageResourceReference imageReference) + throws ResourceStreamNotFoundException, IOException + { + IResourceStream resourceStream = imageReference.getResource().getResourceStream(); + byte[] bytes = new byte[(int)resourceStream.length().bytes()]; + DataInputStream dataInputStream = new DataInputStream(resourceStream.getInputStream()); + dataInputStream.readFully(bytes); --- End diff -- You can use org.apache.wicket.util.io.IOUtils#toByteArray(java.io.InputStream) instead. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] wicket pull request: WICKET-5827 - CssUrlReplacer supports base64 ...
Github user martin-g commented on the pull request: https://github.com/apache/wicket/pull/97#issuecomment-78437280 Good job, Tobias! I've made some minor comments. Please apply the suggested improvements and squash the commits into one. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] wicket pull request: WICKET-5827 - CssUrlReplacer supports base64 ...
Github user martin-g commented on a diff in the pull request: https://github.com/apache/wicket/pull/97#discussion_r26283695 --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacer.java --- @@ -71,21 +82,67 @@ else if (imageCandidateUrl.isContextAbsolute()) // relativize against the url for the containing CSS file Url cssUrlCopy = new Url(cssUrl); cssUrlCopy.resolveRelative(imageCandidateUrl); - PackageResourceReference imageReference = new PackageResourceReference(scope, - cssUrlCopy.toString()); - processedUrl = cycle.urlFor(imageReference, null); + + // if the image should be processed as URL or base64 embedded + if (cssUrlCopy.getQueryString() != null && + cssUrlCopy.getQueryString().contains(EMBED_BASE64)) + { + embedded = true; + PackageResourceReference imageReference = new PackageResourceReference(scope, + cssUrlCopy.toString().replace("?" + EMBED_BASE64, "")); + try + { + processedUrl = createBase64EncodedImage(imageReference); + } + catch (Exception e) + { + throw new WicketRuntimeException( + "Error while embedding an image into the css: " + + imageReference.toString(), e); --- End diff -- no need of `toString()`. It is called implicitly. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] wicket pull request: WICKET-5827 - CssUrlReplacer supports base64 ...
Github user martin-g commented on a diff in the pull request: https://github.com/apache/wicket/pull/97#discussion_r26283656 --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacer.java --- @@ -58,9 +66,12 @@ public String process(String input, Class scope, String name) { Url imageCandidateUrl = Url.parse(matcher.group(1)); CharSequence processedUrl; + boolean embedded = false; + if (imageCandidateUrl.isFull()) { processedUrl = imageCandidateUrl.toString(Url.StringMode.FULL); + --- End diff -- no need of the new extra line --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] wicket pull request: WICKET-5827 - CssUrlReplacer supports base64 ...
Github user martin-g commented on a diff in the pull request: https://github.com/apache/wicket/pull/97#discussion_r26283649 --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacer.java --- @@ -43,6 +49,8 @@ // The pattern to find URLs in CSS resources private static final Pattern URL_PATTERN = Pattern.compile("url\\(['|\"]*(.*?)['|\"]*\\)"); + private static final String EMBED_BASE64 = "embedBase64"; --- End diff -- Please make this `public`. An application developer may want to use ... And add javadoc what it is about. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] wicket pull request: WICKET-5827 - CssUrlReplacer supports base64 ...
Github user klopfdreh commented on the pull request: https://github.com/apache/wicket/pull/96#issuecomment-78379987 Forgot to close the resource stream. In the method private CharSequence createBase64EncodedImage(PackageResourceReference imageReference). May wrap all but the first line into try / finally and close the stream. Sorry for that. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] wicket pull request: WICKET-5827 - CssUrlReplacer supports base64 ...
Github user klopfdreh commented on the pull request: https://github.com/apache/wicket/pull/97#issuecomment-78379794 Forgot to close the resource stream. In the method private CharSequence createBase64EncodedImage(PackageResourceReference imageReference). May wrap all but the first line into try / finally and close the stream. Sorry for that. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] wicket pull request: WICKET-5827 - CssUrlReplacer supports base64 ...
GitHub user klopfdreh opened a pull request: https://github.com/apache/wicket/pull/97 WICKET-5827 - CssUrlReplacer supports base64 encoded images - 6.x http://apache-wicket.1842946.n4.nabble.com/CssUrlReplacer-improvement-base64-content-td4669546.html You can merge this pull request into a Git repository by running: $ git pull https://github.com/klopfdreh/wicket WICKET-5827-base64-6.x Alternatively you can review and apply these changes as the patch at: https://github.com/apache/wicket/pull/97.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #97 commit ebf81c9f1c80e28bffdb7921a2daacd71359b9ab Author: klopfdreh Date: 2015-02-18T15:33:21Z WICKET-5827 - CssUrlReplacer supports base64 encoded images --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] wicket pull request: WICKET-5827 - CssUrlReplacer supports base64 ...
GitHub user klopfdreh opened a pull request: https://github.com/apache/wicket/pull/96 WICKET-5827 - CssUrlReplacer supports base64 encoded images http://apache-wicket.1842946.n4.nabble.com/CssUrlReplacer-improvement-base64-content-td4669546.html You can merge this pull request into a Git repository by running: $ git pull https://github.com/klopfdreh/wicket WICKET-5827-base64 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/wicket/pull/96.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #96 commit 14e6cfa4fbe3b3e09e78fd74c4215fb4ce517b7c Author: klopfdreh Date: 2015-02-18T15:25:56Z WICKET-5827 - CssUrlReplacer supports base64 encoded images --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---