[ 
https://issues.apache.org/jira/browse/WICKET-5827?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14358246#comment-14358246
 ] 

ASF GitHub Bot commented on WICKET-5827:
----------------------------------------

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.


> Allow to apply multiple Javascript / CSS compressors
> ----------------------------------------------------
>
>                 Key: WICKET-5827
>                 URL: https://issues.apache.org/jira/browse/WICKET-5827
>             Project: Wicket
>          Issue Type: New Feature
>          Components: wicket
>    Affects Versions: 6.20.0, 7.0.0-M6
>            Reporter: Tobias Soloschenko
>            Assignee: Martin Grigorov
>            Priority: Minor
>              Labels: features
>             Fix For: 6.20.0, 7.0.0-M6
>
>
> It would be nice to be able to add several css and javascript compressions in 
> a chain. Example for CSS:
> CssRemoveCommentsCompressor > CssUrlReplacementCompressor > 
> CssMinifyCompressor
> The same would be nice for JavaScript files.
> https://github.com/apache/wicket/pull/88
> https://github.com/apache/wicket/pull/87



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to