You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by klopfdreh <gi...@git.apache.org> on 2015/02/04 13:29:26 UTC

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

GitHub user klopfdreh opened a pull request:

    https://github.com/apache/wicket/pull/87

    WICKET-5827 Allow to apply multiple Javascript / CSS compressors

    - Allow multiple ICssCompressors and IJavaScriptCompressors
    - CssUrlReplacementCompressor

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/klopfdreh/wicket css_js_compression

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/wicket/pull/87.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 #87
    
----
commit 9752eac7fb63e83ffceb9969a1b4f6aa9305b5e7
Author: klopfdreh <kl...@tobiass-mbp>
Date:   2015-02-04T12:15:11Z

    Compression
    - Allow multiple ICssCompressors and IJavaScriptCompressors
    - CssUrlReplacer

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24096980
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    --- End diff --
    
    done


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24095087
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    +
    +	public CssUrlReplacementCompressor(Application application)
    +	{
    +
    +		// Create an instantiation listener which filters only pages.
    +		application.getComponentInitializationListeners().add(
    +			new IComponentInitializationListener()
    +			{
    +
    +				@Override
    +				public void onInitialize(Component component)
    +				{
    +					if (Page.class.isAssignableFrom(component.getClass()))
    +					{
    +						CssUrlReplacementCompressor.this.pageNames.put(component.getClass()
    +							.getName(), component.getClass().getSimpleName());
    +					}
    +				}
    +			});
    +	}
    +
    +	/**
    +	 * Replaces the URLs of CSS resources with Wicket representatives.
    +	 */
    +	@SuppressWarnings("unchecked")
    +	@Override
    +	public String compress(String original)
    +	{
    +		Matcher matcher = this.urlPattern.matcher(original);
    +		// Search for urls
    +		while (matcher.find())
    +		{
    +			Collection<String> pageNames = this.pageNames.keySet();
    --- End diff --
    
    Mhh, any other suggestions? - the matcher has to be applied once so that I can find all url positions.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24095885
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    +
    +	public CssUrlReplacementCompressor(Application application)
    +	{
    +
    +		// Create an instantiation listener which filters only pages.
    +		application.getComponentInitializationListeners().add(
    +			new IComponentInitializationListener()
    +			{
    +
    +				@Override
    +				public void onInitialize(Component component)
    +				{
    +					if (Page.class.isAssignableFrom(component.getClass()))
    +					{
    +						CssUrlReplacementCompressor.this.pageNames.put(component.getClass()
    +							.getName(), component.getClass().getSimpleName());
    +					}
    +				}
    +			});
    +	}
    +
    +	/**
    +	 * Replaces the URLs of CSS resources with Wicket representatives.
    +	 */
    +	@SuppressWarnings("unchecked")
    +	@Override
    +	public String compress(String original)
    +	{
    +		Matcher matcher = this.urlPattern.matcher(original);
    +		// Search for urls
    +		while (matcher.find())
    +		{
    +			Collection<String> pageNames = this.pageNames.keySet();
    +			for (String pageName : pageNames)
    +			{
    +				try
    +				{
    +					Class<Page> pageClass = (Class<Page>)Class.forName(pageName);
    +					String url = matcher.group(1);
    +					if (!url.contains("/"))
    +					{
    +						URL urlResource = pageClass.getResource(url);
    +						// If the resource is not found for a page skip it
    +						if (urlResource != null)
    +						{
    +							PackageResourceReference packageResourceReference = new PackageResourceReference(
    +								pageClass, url);
    +							String replacedUrl = RequestCycle.get()
    +								.urlFor(packageResourceReference, null)
    +								.toString();
    +							StringBuilder urlBuilder = new StringBuilder();
    +							urlBuilder.append("url('");
    +							urlBuilder.append(replacedUrl);
    +							urlBuilder.append("')");
    +							original = matcher.replaceFirst(urlBuilder.toString());
    +						}
    +					}
    +				}
    +				catch (Exception e)
    +				{
    +					StringWriter stringWriter = this.printStack(e);
    +					throw new WicketRuntimeException(stringWriter.toString());
    --- End diff --
    
    Why ?! :-)
    Just do: `throw new WicketRuntimeException("A problem occurred during CSS url replacement.", e);`


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24095985
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CompositeJavaScriptCompressor.java ---
    @@ -0,0 +1,94 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.List;
    +
    +import org.apache.wicket.javascript.IJavaScriptCompressor;
    +
    +/**
    + * Used to apply several {@link IJavaScriptCompressor} to the javascript compression.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * CompositeJavaScriptCompressor compositeJavaScriptCompressor = new CompositeJavaScriptCompressor();
    + * 
    + * compositeJavaScriptCompressor.getCompressors().add(new MyJavaScriptCompressor());
    + * compositeJavaScriptCompressor.getCompressors().add(new AnotherJavaScriptCompressor());
    + * 
    + * this.getResourceSettings().setJavaScriptCompressor(compositeJavaScriptCompressor);
    + * </pre>
    + * The compressors can also be given as constructor arguments.
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + *
    + */
    +public class CompositeJavaScriptCompressor implements IJavaScriptCompressor
    +{
    +
    +	/* Compressors to compress javascript content */
    +	private List<IJavaScriptCompressor> compressors = new ArrayList<>();
    +
    +	/**
    +	 * Initializes an empty composite javascript compressor
    +	 */
    +	public CompositeJavaScriptCompressor()
    +	{
    +	}
    +
    +	/**
    +	 * Initializes the composite javascript compressor with the given {@link IJavaScriptCompressor}
    +	 * 
    +	 * @param compressors
    +	 *            several {@link IJavaScriptCompressor} the composite javascript compressor is
    +	 *            initialized with
    +	 */
    +	public CompositeJavaScriptCompressor(IJavaScriptCompressor... compressors)
    +	{
    +		this.compressors = Arrays.asList(compressors);
    --- End diff --
    
    Same as CompositeCssCompressor.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24095694
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    +
    +	public CssUrlReplacementCompressor(Application application)
    +	{
    +
    +		// Create an instantiation listener which filters only pages.
    +		application.getComponentInitializationListeners().add(
    +			new IComponentInitializationListener()
    +			{
    +
    +				@Override
    +				public void onInitialize(Component component)
    +				{
    +					if (Page.class.isAssignableFrom(component.getClass()))
    +					{
    +						CssUrlReplacementCompressor.this.pageNames.put(component.getClass()
    +							.getName(), component.getClass().getSimpleName());
    +					}
    +				}
    +			});
    +	}
    +
    +	/**
    +	 * Replaces the URLs of CSS resources with Wicket representatives.
    +	 */
    +	@SuppressWarnings("unchecked")
    +	@Override
    +	public String compress(String original)
    +	{
    +		Matcher matcher = this.urlPattern.matcher(original);
    +		// Search for urls
    +		while (matcher.find())
    +		{
    +			Collection<String> pageNames = this.pageNames.keySet();
    +			for (String pageName : pageNames)
    +			{
    +				try
    +				{
    +					Class<Page> pageClass = (Class<Page>)Class.forName(pageName);
    +					String url = matcher.group(1);
    +					if (!url.contains("/"))
    +					{
    +						URL urlResource = pageClass.getResource(url);
    --- End diff --
    
    I'm not even sure this will work for all cases.
    Imagine I have a Panel in `com.example.panels.MyPanel`, it contributes a CSS from `res/css/my.css`, and this CSS has image: `../images/my.png`.
    My pages are in `com.example.pages.**`.
    So having knowledge about pages won't help me to find the image.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24093233
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CompositeCssCompressor.java ---
    @@ -0,0 +1,82 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.util.ArrayList;
    +import java.util.List;
    +
    +import org.apache.wicket.css.ICssCompressor;
    +
    +/**
    + * Used to apply several {@link ICssCompressor} to the css compression.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * CompositeCssCompressor compositeCssCompressor = new CompositeCssCompressor();
    + * 
    + * compositeCssCompressor.getCompressors().add(new MyCssCompressor());
    + * compositeCssCompressor.getCompressors().add(new AnotherCssCompressor());
    + * 
    + * this.getResourceSettings().setCssCompressor(compositeCssCompressor);
    + * </pre>
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CompositeCssCompressor implements ICssCompressor
    +{
    +
    +	/* Compressors to compress the CSS content */
    +	private List<ICssCompressor> compressors;
    +
    --- End diff --
    
    Done


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on the pull request:

    https://github.com/apache/wicket/pull/87#issuecomment-72895940
  
    What do you think of leaving the check of page away in the first step and then implement your suggestions in a further pull request?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24094203
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    --- End diff --
    
    This is not possible because of Arrays.asList(compressors); in constructor


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24094145
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    --- End diff --
    
    static final


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24096192
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    +
    +	public CssUrlReplacementCompressor(Application application)
    +	{
    +
    +		// Create an instantiation listener which filters only pages.
    +		application.getComponentInitializationListeners().add(
    +			new IComponentInitializationListener()
    +			{
    +
    +				@Override
    +				public void onInitialize(Component component)
    +				{
    +					if (Page.class.isAssignableFrom(component.getClass()))
    +					{
    +						CssUrlReplacementCompressor.this.pageNames.put(component.getClass()
    +							.getName(), component.getClass().getSimpleName());
    +					}
    +				}
    +			});
    +	}
    +
    +	/**
    +	 * Replaces the URLs of CSS resources with Wicket representatives.
    +	 */
    +	@SuppressWarnings("unchecked")
    +	@Override
    +	public String compress(String original)
    +	{
    +		Matcher matcher = this.urlPattern.matcher(original);
    +		// Search for urls
    +		while (matcher.find())
    +		{
    +			Collection<String> pageNames = this.pageNames.keySet();
    +			for (String pageName : pageNames)
    +			{
    +				try
    +				{
    +					Class<Page> pageClass = (Class<Page>)Class.forName(pageName);
    +					String url = matcher.group(1);
    +					if (!url.contains("/"))
    +					{
    +						URL urlResource = pageClass.getResource(url);
    --- End diff --
    
    Yes thats right - thats a limitation. 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24094502
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CompositeCssCompressor.java ---
    @@ -0,0 +1,93 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.List;
    +
    +import org.apache.wicket.css.ICssCompressor;
    +
    +/**
    + * Used to apply several {@link ICssCompressor} to the CSS compression.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * CompositeCssCompressor compositeCssCompressor = new CompositeCssCompressor();
    + * 
    + * compositeCssCompressor.getCompressors().add(new MyCssCompressor());
    + * compositeCssCompressor.getCompressors().add(new AnotherCssCompressor());
    + * 
    + * this.getResourceSettings().setCssCompressor(compositeCssCompressor);
    + * </pre>
    + * The compressors can also be given as constructor arguments.
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CompositeCssCompressor implements ICssCompressor
    +{
    +
    +	/* Compressors to compress the CSS content */
    +	private List<ICssCompressor> compressors = new ArrayList<>();
    +
    +	/**
    +	 * Initializes an empty composite CSS compressor
    +	 */
    +	public CompositeCssCompressor()
    --- End diff --
    
    This constructor can be removed. The second one covers the use case of empty argument list.
    Define the field as: `private final List<ICssCompressor> compressors;`


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24094314
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CompositeCssCompressor.java ---
    @@ -0,0 +1,93 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.List;
    +
    +import org.apache.wicket.css.ICssCompressor;
    +
    +/**
    + * Used to apply several {@link ICssCompressor} to the CSS compression.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * CompositeCssCompressor compositeCssCompressor = new CompositeCssCompressor();
    + * 
    + * compositeCssCompressor.getCompressors().add(new MyCssCompressor());
    + * compositeCssCompressor.getCompressors().add(new AnotherCssCompressor());
    + * 
    + * this.getResourceSettings().setCssCompressor(compositeCssCompressor);
    + * </pre>
    + * The compressors can also be given as constructor arguments.
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CompositeCssCompressor implements ICssCompressor
    +{
    +
    +	/* Compressors to compress the CSS content */
    +	private List<ICssCompressor> compressors = new ArrayList<>();
    --- End diff --
    
    This is not possible because of Arrays.asList(compressors); in constructor.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by bitstorm <gi...@git.apache.org>.
Github user bitstorm commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24089981
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CompositeCssCompressor.java ---
    @@ -0,0 +1,82 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.util.ArrayList;
    +import java.util.List;
    +
    +import org.apache.wicket.css.ICssCompressor;
    +
    +/**
    + * Used to apply several {@link ICssCompressor} to the css compression.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * CompositeCssCompressor compositeCssCompressor = new CompositeCssCompressor();
    + * 
    + * compositeCssCompressor.getCompressors().add(new MyCssCompressor());
    + * compositeCssCompressor.getCompressors().add(new AnotherCssCompressor());
    + * 
    + * this.getResourceSettings().setCssCompressor(compositeCssCompressor);
    + * </pre>
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CompositeCssCompressor implements ICssCompressor
    +{
    +
    +	/* Compressors to compress the CSS content */
    +	private List<ICssCompressor> compressors;
    +
    --- End diff --
    
    Personally I would initialize compressors in-line so we can skip 'if (compressors != null)'  checks. In addition I would also add a constructor with  multiple args for compressors : 'CompositeCssCompressor(ICssCompressor...)' .
    Same for CompositeJavaScriptCompressor.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24095452
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    +
    +	public CssUrlReplacementCompressor(Application application)
    +	{
    +
    +		// Create an instantiation listener which filters only pages.
    +		application.getComponentInitializationListeners().add(
    +			new IComponentInitializationListener()
    +			{
    +
    +				@Override
    +				public void onInitialize(Component component)
    +				{
    +					if (Page.class.isAssignableFrom(component.getClass()))
    +					{
    +						CssUrlReplacementCompressor.this.pageNames.put(component.getClass()
    +							.getName(), component.getClass().getSimpleName());
    +					}
    +				}
    +			});
    +	}
    +
    +	/**
    +	 * Replaces the URLs of CSS resources with Wicket representatives.
    +	 */
    +	@SuppressWarnings("unchecked")
    +	@Override
    +	public String compress(String original)
    +	{
    +		Matcher matcher = this.urlPattern.matcher(original);
    +		// Search for urls
    +		while (matcher.find())
    +		{
    +			Collection<String> pageNames = this.pageNames.keySet();
    +			for (String pageName : pageNames)
    +			{
    +				try
    +				{
    +					Class<Page> pageClass = (Class<Page>)Class.forName(pageName);
    +					String url = matcher.group(1);
    +					if (!url.contains("/"))
    +					{
    +						URL urlResource = pageClass.getResource(url);
    --- End diff --
    
    I used this solution because then you don't need to add PackageResourceReferences to be resolved to the CssUrlReplacer


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24095270
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    +
    +	public CssUrlReplacementCompressor(Application application)
    +	{
    +
    +		// Create an instantiation listener which filters only pages.
    +		application.getComponentInitializationListeners().add(
    +			new IComponentInitializationListener()
    +			{
    +
    +				@Override
    +				public void onInitialize(Component component)
    +				{
    +					if (Page.class.isAssignableFrom(component.getClass()))
    +					{
    +						CssUrlReplacementCompressor.this.pageNames.put(component.getClass()
    +							.getName(), component.getClass().getSimpleName());
    +					}
    +				}
    +			});
    +	}
    +
    +	/**
    +	 * Replaces the URLs of CSS resources with Wicket representatives.
    +	 */
    +	@SuppressWarnings("unchecked")
    +	@Override
    +	public String compress(String original)
    +	{
    +		Matcher matcher = this.urlPattern.matcher(original);
    +		// Search for urls
    +		while (matcher.find())
    +		{
    +			Collection<String> pageNames = this.pageNames.keySet();
    +			for (String pageName : pageNames)
    +			{
    +				try
    +				{
    +					Class<Page> pageClass = (Class<Page>)Class.forName(pageName);
    --- End diff --
    
    Or even better store org.apache.wicket.util.reference.ClassReference


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24094955
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CompositeCssCompressor.java ---
    @@ -0,0 +1,93 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.List;
    +
    +import org.apache.wicket.css.ICssCompressor;
    +
    +/**
    + * Used to apply several {@link ICssCompressor} to the CSS compression.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * CompositeCssCompressor compositeCssCompressor = new CompositeCssCompressor();
    + * 
    + * compositeCssCompressor.getCompressors().add(new MyCssCompressor());
    + * compositeCssCompressor.getCompressors().add(new AnotherCssCompressor());
    + * 
    + * this.getResourceSettings().setCssCompressor(compositeCssCompressor);
    + * </pre>
    + * The compressors can also be given as constructor arguments.
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CompositeCssCompressor implements ICssCompressor
    +{
    +
    +	/* Compressors to compress the CSS content */
    +	private List<ICssCompressor> compressors = new ArrayList<>();
    --- End diff --
    
    Changed the line to:
    this.compressors.addAll(Arrays.asList(compressors));


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on the pull request:

    https://github.com/apache/wicket/pull/87#issuecomment-72903920
  
    Ok I think I got it, but the changes are not backward compatible to wicket 6.x


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24094208
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    --- End diff --
    
    I think `"` and `'` are optional. I.e. `url(some/path/name.png)` is also valid.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on the pull request:

    https://github.com/apache/wicket/pull/87#issuecomment-72892809
  
    The knowledge is there: https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/request/resource/CssPackageResource.java#L65
    The problem is that it is not propagated.
    I.e. CssPackageResource knows the scope class, but it doesn't give it to the ICssCompressor.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on the pull request:

    https://github.com/apache/wicket/pull/87#issuecomment-73007971
  
    Thank you very much! I also applied the changes we discussed here for the wicket-6.x branch - https://github.com/apache/wicket/pull/88 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24095338
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    +
    +	public CssUrlReplacementCompressor(Application application)
    +	{
    +
    +		// Create an instantiation listener which filters only pages.
    +		application.getComponentInitializationListeners().add(
    +			new IComponentInitializationListener()
    +			{
    +
    +				@Override
    +				public void onInitialize(Component component)
    +				{
    +					if (Page.class.isAssignableFrom(component.getClass()))
    +					{
    +						CssUrlReplacementCompressor.this.pageNames.put(component.getClass()
    +							.getName(), component.getClass().getSimpleName());
    +					}
    +				}
    +			});
    +	}
    +
    +	/**
    +	 * Replaces the URLs of CSS resources with Wicket representatives.
    +	 */
    +	@SuppressWarnings("unchecked")
    +	@Override
    +	public String compress(String original)
    +	{
    +		Matcher matcher = this.urlPattern.matcher(original);
    +		// Search for urls
    +		while (matcher.find())
    +		{
    +			Collection<String> pageNames = this.pageNames.keySet();
    +			for (String pageName : pageNames)
    +			{
    +				try
    +				{
    +					Class<Page> pageClass = (Class<Page>)Class.forName(pageName);
    --- End diff --
    
    done


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24091717
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CompositeCssCompressor.java ---
    @@ -0,0 +1,82 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.util.ArrayList;
    +import java.util.List;
    +
    +import org.apache.wicket.css.ICssCompressor;
    +
    +/**
    + * Used to apply several {@link ICssCompressor} to the css compression.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * CompositeCssCompressor compositeCssCompressor = new CompositeCssCompressor();
    + * 
    + * compositeCssCompressor.getCompressors().add(new MyCssCompressor());
    + * compositeCssCompressor.getCompressors().add(new AnotherCssCompressor());
    + * 
    + * this.getResourceSettings().setCssCompressor(compositeCssCompressor);
    + * </pre>
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CompositeCssCompressor implements ICssCompressor
    +{
    +
    +	/* Compressors to compress the CSS content */
    +	private List<ICssCompressor> compressors;
    +
    --- End diff --
    
    Just one moment. :-)


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24094462
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    --- End diff --
    
    ok I check it and change the regex so that ' and " are optional


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24096380
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CompositeJavaScriptCompressor.java ---
    @@ -0,0 +1,94 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.List;
    +
    +import org.apache.wicket.javascript.IJavaScriptCompressor;
    +
    +/**
    + * Used to apply several {@link IJavaScriptCompressor} to the javascript compression.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * CompositeJavaScriptCompressor compositeJavaScriptCompressor = new CompositeJavaScriptCompressor();
    + * 
    + * compositeJavaScriptCompressor.getCompressors().add(new MyJavaScriptCompressor());
    + * compositeJavaScriptCompressor.getCompressors().add(new AnotherJavaScriptCompressor());
    + * 
    + * this.getResourceSettings().setJavaScriptCompressor(compositeJavaScriptCompressor);
    + * </pre>
    + * The compressors can also be given as constructor arguments.
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + *
    + */
    +public class CompositeJavaScriptCompressor implements IJavaScriptCompressor
    +{
    +
    +	/* Compressors to compress javascript content */
    +	private List<IJavaScriptCompressor> compressors = new ArrayList<>();
    +
    +	/**
    +	 * Initializes an empty composite javascript compressor
    +	 */
    +	public CompositeJavaScriptCompressor()
    +	{
    +	}
    +
    +	/**
    +	 * Initializes the composite javascript compressor with the given {@link IJavaScriptCompressor}
    +	 * 
    +	 * @param compressors
    +	 *            several {@link IJavaScriptCompressor} the composite javascript compressor is
    +	 *            initialized with
    +	 */
    +	public CompositeJavaScriptCompressor(IJavaScriptCompressor... compressors)
    +	{
    +		this.compressors = Arrays.asList(compressors);
    --- End diff --
    
    done


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24094954
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    +
    +	public CssUrlReplacementCompressor(Application application)
    +	{
    +
    +		// Create an instantiation listener which filters only pages.
    +		application.getComponentInitializationListeners().add(
    +			new IComponentInitializationListener()
    +			{
    +
    +				@Override
    +				public void onInitialize(Component component)
    +				{
    +					if (Page.class.isAssignableFrom(component.getClass()))
    +					{
    +						CssUrlReplacementCompressor.this.pageNames.put(component.getClass()
    +							.getName(), component.getClass().getSimpleName());
    +					}
    +				}
    +			});
    +	}
    +
    +	/**
    +	 * Replaces the URLs of CSS resources with Wicket representatives.
    +	 */
    +	@SuppressWarnings("unchecked")
    +	@Override
    +	public String compress(String original)
    +	{
    +		Matcher matcher = this.urlPattern.matcher(original);
    +		// Search for urls
    +		while (matcher.find())
    +		{
    +			Collection<String> pageNames = this.pageNames.keySet();
    --- End diff --
    
    This logic looks very expensive :-/


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on the pull request:

    https://github.com/apache/wicket/pull/87#issuecomment-72907386
  
    So for now, yep the CssUrlReplacer is a bit slow, because it is scanning for the images in different scopes and it is a limitation that you could not put images in other packages as those of the components, but I would recommend the changes of @martin-g in a separate pull request, because they require changes in various classes and they are not backward compatible. What do you think?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24096363
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    +
    +	public CssUrlReplacementCompressor(Application application)
    +	{
    +
    +		// Create an instantiation listener which filters only pages.
    +		application.getComponentInitializationListeners().add(
    +			new IComponentInitializationListener()
    +			{
    +
    +				@Override
    +				public void onInitialize(Component component)
    +				{
    +					if (Page.class.isAssignableFrom(component.getClass()))
    +					{
    +						CssUrlReplacementCompressor.this.pageNames.put(component.getClass()
    +							.getName(), component.getClass().getSimpleName());
    +					}
    +				}
    +			});
    +	}
    +
    +	/**
    +	 * Replaces the URLs of CSS resources with Wicket representatives.
    +	 */
    +	@SuppressWarnings("unchecked")
    +	@Override
    +	public String compress(String original)
    +	{
    +		Matcher matcher = this.urlPattern.matcher(original);
    +		// Search for urls
    +		while (matcher.find())
    +		{
    +			Collection<String> pageNames = this.pageNames.keySet();
    +			for (String pageName : pageNames)
    +			{
    +				try
    +				{
    +					Class<Page> pageClass = (Class<Page>)Class.forName(pageName);
    +					String url = matcher.group(1);
    +					if (!url.contains("/"))
    +					{
    +						URL urlResource = pageClass.getResource(url);
    +						// If the resource is not found for a page skip it
    +						if (urlResource != null)
    +						{
    +							PackageResourceReference packageResourceReference = new PackageResourceReference(
    +								pageClass, url);
    +							String replacedUrl = RequestCycle.get()
    +								.urlFor(packageResourceReference, null)
    +								.toString();
    +							StringBuilder urlBuilder = new StringBuilder();
    +							urlBuilder.append("url('");
    +							urlBuilder.append(replacedUrl);
    +							urlBuilder.append("')");
    +							original = matcher.replaceFirst(urlBuilder.toString());
    +						}
    +					}
    +				}
    +				catch (Exception e)
    +				{
    +					StringWriter stringWriter = this.printStack(e);
    +					throw new WicketRuntimeException(stringWriter.toString());
    --- End diff --
    
    done


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24094994
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CompositeCssCompressor.java ---
    @@ -0,0 +1,93 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.List;
    +
    +import org.apache.wicket.css.ICssCompressor;
    +
    +/**
    + * Used to apply several {@link ICssCompressor} to the CSS compression.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * CompositeCssCompressor compositeCssCompressor = new CompositeCssCompressor();
    + * 
    + * compositeCssCompressor.getCompressors().add(new MyCssCompressor());
    + * compositeCssCompressor.getCompressors().add(new AnotherCssCompressor());
    + * 
    + * this.getResourceSettings().setCssCompressor(compositeCssCompressor);
    + * </pre>
    + * The compressors can also be given as constructor arguments.
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CompositeCssCompressor implements ICssCompressor
    +{
    +
    +	/* Compressors to compress the CSS content */
    +	private List<ICssCompressor> compressors = new ArrayList<>();
    +
    +	/**
    +	 * Initializes an empty composite CSS compressor
    +	 */
    +	public CompositeCssCompressor()
    --- End diff --
    
    Done


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24094660
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    --- End diff --
    
    If the class doesn't compress then I think it should not have `Compressor` as a suffix.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24095075
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    +
    +	public CssUrlReplacementCompressor(Application application)
    +	{
    +
    +		// Create an instantiation listener which filters only pages.
    +		application.getComponentInitializationListeners().add(
    +			new IComponentInitializationListener()
    +			{
    +
    +				@Override
    +				public void onInitialize(Component component)
    +				{
    +					if (Page.class.isAssignableFrom(component.getClass()))
    +					{
    +						CssUrlReplacementCompressor.this.pageNames.put(component.getClass()
    +							.getName(), component.getClass().getSimpleName());
    +					}
    +				}
    +			});
    +	}
    +
    +	/**
    +	 * Replaces the URLs of CSS resources with Wicket representatives.
    +	 */
    +	@SuppressWarnings("unchecked")
    +	@Override
    +	public String compress(String original)
    +	{
    +		Matcher matcher = this.urlPattern.matcher(original);
    +		// Search for urls
    +		while (matcher.find())
    +		{
    +			Collection<String> pageNames = this.pageNames.keySet();
    +			for (String pageName : pageNames)
    +			{
    +				try
    +				{
    +					Class<Page> pageClass = (Class<Page>)Class.forName(pageName);
    +					String url = matcher.group(1);
    +					if (!url.contains("/"))
    +					{
    +						URL urlResource = pageClass.getResource(url);
    --- End diff --
    
    This is the heavy part.
    I'll have to think for a better solution.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/wicket/pull/87


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24098307
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    +
    +	public CssUrlReplacementCompressor(Application application)
    +	{
    +
    +		// Create an instantiation listener which filters only pages.
    +		application.getComponentInitializationListeners().add(
    +			new IComponentInitializationListener()
    +			{
    +
    +				@Override
    +				public void onInitialize(Component component)
    +				{
    +					if (Page.class.isAssignableFrom(component.getClass()))
    +					{
    +						CssUrlReplacementCompressor.this.pageNames.put(component.getClass()
    +							.getName(), component.getClass().getSimpleName());
    +					}
    +				}
    +			});
    +	}
    +
    +	/**
    +	 * Replaces the URLs of CSS resources with Wicket representatives.
    +	 */
    +	@SuppressWarnings("unchecked")
    +	@Override
    +	public String compress(String original)
    +	{
    +		Matcher matcher = this.urlPattern.matcher(original);
    +		// Search for urls
    +		while (matcher.find())
    +		{
    +			Collection<String> pageNames = this.pageNames.keySet();
    +			for (String pageName : pageNames)
    +			{
    +				try
    +				{
    +					Class<Page> pageClass = (Class<Page>)Class.forName(pageName);
    +					String url = matcher.group(1);
    +					if (!url.contains("/"))
    +					{
    +						URL urlResource = pageClass.getResource(url);
    --- End diff --
    
    Mhh, the problem here is that you can use any scope in PackageResourceReferences, even classes which are not the components that use the image. In this case it is hard to find a generic way to get those images. What we could do is let away the check of pages so that the images of panels could also be found.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24095007
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    +
    +	public CssUrlReplacementCompressor(Application application)
    +	{
    +
    +		// Create an instantiation listener which filters only pages.
    +		application.getComponentInitializationListeners().add(
    +			new IComponentInitializationListener()
    +			{
    +
    +				@Override
    +				public void onInitialize(Component component)
    +				{
    +					if (Page.class.isAssignableFrom(component.getClass()))
    +					{
    +						CssUrlReplacementCompressor.this.pageNames.put(component.getClass()
    +							.getName(), component.getClass().getSimpleName());
    +					}
    +				}
    +			});
    +	}
    +
    +	/**
    +	 * Replaces the URLs of CSS resources with Wicket representatives.
    +	 */
    +	@SuppressWarnings("unchecked")
    +	@Override
    +	public String compress(String original)
    +	{
    +		Matcher matcher = this.urlPattern.matcher(original);
    +		// Search for urls
    +		while (matcher.find())
    +		{
    +			Collection<String> pageNames = this.pageNames.keySet();
    +			for (String pageName : pageNames)
    +			{
    +				try
    +				{
    +					Class<Page> pageClass = (Class<Page>)Class.forName(pageName);
    --- End diff --
    
    Use `WicketObjects.resolveClass()` instead.
    OSGi users will be happier!


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by klopfdreh <gi...@git.apache.org>.
Github user klopfdreh commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24094780
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.io.PrintWriter;
    +import java.io.StringWriter;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import org.apache.wicket.Application;
    +import org.apache.wicket.Component;
    +import org.apache.wicket.Page;
    +import org.apache.wicket.WicketRuntimeException;
    +import org.apache.wicket.application.IComponentInitializationListener;
    +import org.apache.wicket.css.ICssCompressor;
    +import org.apache.wicket.request.cycle.RequestCycle;
    +import org.apache.wicket.request.resource.PackageResourceReference;
    +
    +/**
    + * This compressor is used to replace url within css files with resources that belongs to their
    + * corresponding page classes. The compress method is not compressing any content, but replacing the
    + * URLs with Wicket representatives.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * this.getResourceSettings().setCssCompressor(new CssUrlReplacementCompressor(this));
    + * </pre>
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CssUrlReplacementCompressor implements ICssCompressor
    +{
    +
    +	// Holds the names of pages
    +	private Map<String, String> pageNames = Collections.synchronizedMap(new LinkedHashMap<String, String>());
    +
    +	// The pattern to find URLs in CSS resources
    +	private Pattern urlPattern = Pattern.compile("url\\(['|\"](.*)['|\"]\\)");
    --- End diff --
    
    url\\(['|\"]*(.*)['|\"]*\\)


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/87#discussion_r24094000
  
    --- Diff: wicket-core/src/main/java/org/apache/wicket/resource/CompositeCssCompressor.java ---
    @@ -0,0 +1,93 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.resource;
    +
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.List;
    +
    +import org.apache.wicket.css.ICssCompressor;
    +
    +/**
    + * Used to apply several {@link ICssCompressor} to the CSS compression.<br>
    + * <br>
    + * Usage:
    + * 
    + * <pre>
    + * CompositeCssCompressor compositeCssCompressor = new CompositeCssCompressor();
    + * 
    + * compositeCssCompressor.getCompressors().add(new MyCssCompressor());
    + * compositeCssCompressor.getCompressors().add(new AnotherCssCompressor());
    + * 
    + * this.getResourceSettings().setCssCompressor(compositeCssCompressor);
    + * </pre>
    + * The compressors can also be given as constructor arguments.
    + * 
    + * @since 6.20.0
    + * @author Tobias Soloschenko
    + * 
    + */
    +public class CompositeCssCompressor implements ICssCompressor
    +{
    +
    +	/* Compressors to compress the CSS content */
    +	private List<ICssCompressor> compressors = new ArrayList<>();
    --- End diff --
    
    final


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on the pull request:

    https://github.com/apache/wicket/pull/87#issuecomment-72893477
  
    A possible improvement:
    - introduce IScopeAwareCssProcessor {process(String nonCompressed, Class scope, String cssName)}
    - check if the resolved ICssCompressor implements the new interface and use it if it does


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] wicket pull request: WICKET-5827 Allow to apply multiple Javascrip...

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on the pull request:

    https://github.com/apache/wicket/pull/87#issuecomment-73004275
  
    I'll take of this PR!


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---