Several fixes Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/2ac0c640 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/2ac0c640 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/2ac0c640
Branch: refs/heads/master Commit: 2ac0c6401a0e9abd9232342e790d15aac8091501 Parents: deeb453 Author: klopfdreh <klopfdreh@tobiass-mbp> Authored: Wed Feb 4 17:34:03 2015 +0100 Committer: klopfdreh <klopfdreh@tobiass-mbp> Committed: Wed Feb 4 17:34:03 2015 +0100 ---------------------------------------------------------------------- ...rg.eclipse.wst.common.project.facet.core.xml | 2 +- .../wicket/resource/CompositeCssCompressor.java | 11 +- .../resource/CompositeJavaScriptCompressor.java | 11 +- .../resource/CssUrlReplacementCompressor.java | 144 ------------------- .../apache/wicket/resource/CssUrlReplacer.java | 127 ++++++++++++++++ 5 files changed, 132 insertions(+), 163 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/2ac0c640/wicket-core/.settings/org.eclipse.wst.common.project.facet.core.xml ---------------------------------------------------------------------- diff --git a/wicket-core/.settings/org.eclipse.wst.common.project.facet.core.xml b/wicket-core/.settings/org.eclipse.wst.common.project.facet.core.xml index c78d932..4f92af5 100644 --- a/wicket-core/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/wicket-core/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <faceted-project> - <installed facet="java" version="1.6"/> <installed facet="jst.utility" version="1.0"/> + <installed facet="java" version="1.7"/> </faceted-project> http://git-wip-us.apache.org/repos/asf/wicket/blob/2ac0c640/wicket-core/src/main/java/org/apache/wicket/resource/CompositeCssCompressor.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/CompositeCssCompressor.java b/wicket-core/src/main/java/org/apache/wicket/resource/CompositeCssCompressor.java index bb61687..a288596 100644 --- a/wicket-core/src/main/java/org/apache/wicket/resource/CompositeCssCompressor.java +++ b/wicket-core/src/main/java/org/apache/wicket/resource/CompositeCssCompressor.java @@ -45,14 +45,7 @@ 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() - { - } + private final List<ICssCompressor> compressors = new ArrayList<>(); /** * Initializes the composite CSS compressor with the given {@link ICssCompressor} @@ -62,7 +55,7 @@ public class CompositeCssCompressor implements ICssCompressor */ public CompositeCssCompressor(ICssCompressor... compressors) { - this.compressors = Arrays.asList(compressors); + this.compressors.addAll(Arrays.asList(compressors)); } /** http://git-wip-us.apache.org/repos/asf/wicket/blob/2ac0c640/wicket-core/src/main/java/org/apache/wicket/resource/CompositeJavaScriptCompressor.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/CompositeJavaScriptCompressor.java b/wicket-core/src/main/java/org/apache/wicket/resource/CompositeJavaScriptCompressor.java index cb1d101..c1888e2 100644 --- a/wicket-core/src/main/java/org/apache/wicket/resource/CompositeJavaScriptCompressor.java +++ b/wicket-core/src/main/java/org/apache/wicket/resource/CompositeJavaScriptCompressor.java @@ -45,14 +45,7 @@ public class CompositeJavaScriptCompressor implements IJavaScriptCompressor { /* Compressors to compress javascript content */ - private List<IJavaScriptCompressor> compressors = new ArrayList<>(); - - /** - * Initializes an empty composite javascript compressor - */ - public CompositeJavaScriptCompressor() - { - } + private final List<IJavaScriptCompressor> compressors = new ArrayList<>(); /** * Initializes the composite javascript compressor with the given {@link IJavaScriptCompressor} @@ -63,7 +56,7 @@ public class CompositeJavaScriptCompressor implements IJavaScriptCompressor */ public CompositeJavaScriptCompressor(IJavaScriptCompressor... compressors) { - this.compressors = Arrays.asList(compressors); + this.compressors.addAll(Arrays.asList(compressors)); } /** http://git-wip-us.apache.org/repos/asf/wicket/blob/2ac0c640/wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java b/wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java deleted file mode 100644 index ce89f53..0000000 --- a/wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacementCompressor.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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()); - } - } - - } - return original; - } - - /** - * Prints the stack trace to a print writer - * - * @param exception - * the exception - * @return the string writer containing the stack trace - */ - private StringWriter printStack(Exception exception) - { - StringWriter stringWriter = new StringWriter(); - PrintWriter printWriter = new PrintWriter(stringWriter); - exception.printStackTrace(printWriter); - return stringWriter; - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/2ac0c640/wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacer.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacer.java b/wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacer.java new file mode 100644 index 0000000..c39dcea --- /dev/null +++ b/wicket-core/src/main/java/org/apache/wicket/resource/CssUrlReplacer.java @@ -0,0 +1,127 @@ +/* + * 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.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 CssUrlReplacer 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 CssUrlReplacer(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())) + { + CssUrlReplacer.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) + { + throw new WicketRuntimeException( + "A problem occurred during CSS url replacement.", e); + } + } + + } + return original; + } +}