From 4b09e371b0a59ff2d093d1236afbf66ee7874402 Mon Sep 17 00:00:00 2001 From: Maxim Solodovnik Date: Fri, 7 Dec 2018 16:52:19 +0700 Subject: [PATCH] [WICKET-6620] deprecated classes/methods are removed --- .../core/request/handler/IPageProvider.java | 7 - .../core/request/handler/PageProvider.java | 11 - .../mapper/AbstractBookmarkableMapper.java | 2 +- .../wicket/core/util/lang/WicketObjects.java | 149 +-- .../org/apache/wicket/markup/WicketTag.java | 13 - .../apache/wicket/markup/html/form/Form.java | 8 - .../markup/html/form/FormComponent.java | 17 - .../markup/resolver/HtmlHeaderResolver.java | 17 +- .../migrate/StringResourceModelMigration.java | 175 --- .../http/mock/MockHttpServletRequest.java | 44 - .../http/mock/MockHttpServletResponse.java | 44 - .../handler/render/WebPageRenderer.java | 2 +- .../resource/JQueryResourceReference.java | 9 - .../wicket/util/tester/BaseWicketTester.java | 35 +- .../apache/wicket/util/tester/TagTester.java | 40 +- .../wicket/util/tester/WicketTester.java | 19 - .../request/mapper/MountedMapperTest.java | 20 +- .../html/image/ResponsiveImageTest.java | 8 +- .../markup/html/media/MediaTagsTest.java | 13 +- .../request/handler/PageProviderTest.java | 3 +- .../handler/render/WebPageRendererTest.java | 6 +- .../wicket/util/lang/WicketObjectsTest.java | 17 +- .../examples/guestbook/GuestbookTest.java | 4 +- .../ajax/markup/html/AjaxLazyLoadPanel.java | 34 - .../data/sort/AjaxFallbackOrderByLink.java | 52 - .../wizard/IDefaultButtonProvider.java | 47 - .../extensions/wizard/WizardButton.java | 17 - .../request/RequestHandlerExecutor.java | 29 - .../apache/wicket/util/IContextProvider.java | 47 - .../org/apache/wicket/util/IProvider.java | 36 - .../util/collections/ArrayListStack.java | 141 --- .../org/apache/wicket/util/crypt/Base64.java | 1108 ----------------- .../apache/wicket/util/crypt/Base64Test.java | 275 ---- 33 files changed, 36 insertions(+), 2413 deletions(-) delete mode 100644 wicket-core/src/main/java/org/apache/wicket/migrate/StringResourceModelMigration.java delete mode 100644 wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/repeater/data/sort/AjaxFallbackOrderByLink.java delete mode 100644 wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/IDefaultButtonProvider.java delete mode 100644 wicket-util/src/main/java/org/apache/wicket/util/IContextProvider.java delete mode 100644 wicket-util/src/main/java/org/apache/wicket/util/IProvider.java delete mode 100644 wicket-util/src/main/java/org/apache/wicket/util/collections/ArrayListStack.java delete mode 100644 wicket-util/src/main/java/org/apache/wicket/util/crypt/Base64.java delete mode 100644 wicket-util/src/test/java/org/apache/wicket/util/crypt/Base64Test.java diff --git a/wicket-core/src/main/java/org/apache/wicket/core/request/handler/IPageProvider.java b/wicket-core/src/main/java/org/apache/wicket/core/request/handler/IPageProvider.java index 28ccb3a14eb..47d72391aca 100644 --- a/wicket-core/src/main/java/org/apache/wicket/core/request/handler/IPageProvider.java +++ b/wicket-core/src/main/java/org/apache/wicket/core/request/handler/IPageProvider.java @@ -51,13 +51,6 @@ public interface IPageProvider */ PageParameters getPageParameters() throws PageExpiredException; - /** - * @return negates {@link PageProvider#hasPageInstance()} - * @deprecated use {@link PageProvider#hasPageInstance()} negation instead - */ - @Deprecated(since = "8.0", forRemoval = true) - boolean isNewPageInstance(); - /** * Returns whether the provided page was expired prior to this access. * diff --git a/wicket-core/src/main/java/org/apache/wicket/core/request/handler/PageProvider.java b/wicket-core/src/main/java/org/apache/wicket/core/request/handler/PageProvider.java index bb94682dac9..c08f0ad1451 100644 --- a/wicket-core/src/main/java/org/apache/wicket/core/request/handler/PageProvider.java +++ b/wicket-core/src/main/java/org/apache/wicket/core/request/handler/PageProvider.java @@ -195,17 +195,6 @@ else if (hasPageInstance()) } } - /** - * @return negates {@link PageProvider#hasPageInstance()} - * @deprecated use {@link PageProvider#hasPageInstance()} negation instead - */ - @Deprecated(since = "8.0", forRemoval = true) - @Override - public boolean isNewPageInstance() - { - return !hasPageInstance(); - } - /** * If this provider returns existing page, regardless if it was already created by PageProvider * itself or is or can be found in the data store. The only guarantee is that by calling diff --git a/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractBookmarkableMapper.java b/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractBookmarkableMapper.java index 9a39c10e754..63a27572581 100644 --- a/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractBookmarkableMapper.java +++ b/wicket-core/src/main/java/org/apache/wicket/core/request/mapper/AbstractBookmarkableMapper.java @@ -402,7 +402,7 @@ else if (requestHandler instanceof RenderPageRequestHandler) return null; } - if (handler.getPageProvider().isNewPageInstance()) + if (!handler.getPageProvider().hasPageInstance()) { // no existing page instance available, don't bother creating new page instance PageInfo info = new PageInfo(); diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/lang/WicketObjects.java b/wicket-core/src/main/java/org/apache/wicket/core/util/lang/WicketObjects.java index 6cf70677b2e..46491500fb4 100644 --- a/wicket-core/src/main/java/org/apache/wicket/core/util/lang/WicketObjects.java +++ b/wicket-core/src/main/java/org/apache/wicket/core/util/lang/WicketObjects.java @@ -16,27 +16,15 @@ */ package org.apache.wicket.core.util.lang; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.ObjectStreamClass; -import java.io.OutputStream; import java.io.Serializable; -import java.util.HashMap; import org.apache.wicket.Application; import org.apache.wicket.Component; import org.apache.wicket.WicketRuntimeException; -import org.apache.wicket.application.IClassResolver; import org.apache.wicket.model.IDetachable; import org.apache.wicket.serialize.ISerializer; import org.apache.wicket.serialize.java.JavaSerializer; -import org.apache.wicket.settings.ApplicationSettings; import org.apache.wicket.util.io.ByteCountingOutputStream; -import org.apache.wicket.util.lang.Generics; import org.apache.wicket.util.string.Strings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -143,141 +131,6 @@ public long sizeOf(Serializable object) } - private static final class ReplaceObjectInputStream extends ObjectInputStream - { - private final ClassLoader classloader; - private final HashMap replacedComponents; - - private ReplaceObjectInputStream(InputStream in, - HashMap replacedComponents, ClassLoader classloader) - throws IOException - { - super(in); - this.replacedComponents = replacedComponents; - this.classloader = classloader; - enableResolveObject(true); - } - - // This override is required to resolve classes inside in different - // bundle, i.e. - // The classes can be resolved by OSGI classresolver implementation - @Override - protected Class resolveClass(ObjectStreamClass desc) throws IOException, - ClassNotFoundException - { - String className = desc.getName(); - - try - { - return Class.forName(className, true, classloader); - } - catch (ClassNotFoundException ex1) - { - // ignore this exception. - log.debug("Class not found by using objects own classloader, trying the IClassResolver"); - } - - Application application = Application.get(); - ApplicationSettings applicationSettings = application.getApplicationSettings(); - IClassResolver classResolver = applicationSettings.getClassResolver(); - - Class candidate = null; - try - { - candidate = classResolver.resolveClass(className); - if (candidate == null) - { - candidate = super.resolveClass(desc); - } - } - catch (WicketRuntimeException ex) - { - if (ex.getCause() instanceof ClassNotFoundException) - { - throw (ClassNotFoundException)ex.getCause(); - } - } - return candidate; - } - - @Override - protected Object resolveObject(Object obj) throws IOException - { - Object replaced = replacedComponents.get(obj); - if (replaced != null) - { - return replaced; - } - return super.resolveObject(obj); - } - } - - private static final class ReplaceObjectOutputStream extends ObjectOutputStream - { - private final HashMap replacedComponents; - - private ReplaceObjectOutputStream(OutputStream out, - HashMap replacedComponents) throws IOException - { - super(out); - this.replacedComponents = replacedComponents; - enableReplaceObject(true); - } - - @Override - protected Object replaceObject(Object obj) throws IOException - { - if (obj instanceof Component) - { - final Component component = (Component)obj; - String name = component.getPath(); - replacedComponents.put(name, component); - return name; - } - return super.replaceObject(obj); - } - } - - /** - * Makes a deep clone of an object by serializing and deserializing it. The object must be fully - * serializable to be cloned. This method will not clone wicket Components, it will just reuse - * those instances so that the complete component tree is not copied over only the model data. - * - * Warning: this method uses Java Serialization APIs to be able to avoid cloning - * of {@link org.apache.wicket.Component} instances. If the application uses custom - * {@link org.apache.wicket.serialize.ISerializer} then most probably this method cannot be used. - * - * @param object - * The object to clone - * @return A deep copy of the object - * @deprecated Use {@linkplain #cloneObject(Object)} instead - */ - @Deprecated - public static T cloneModel(final T object) - { - if (object == null) - { - return null; - } - else - { - try - { - final ByteArrayOutputStream out = new ByteArrayOutputStream(256); - final HashMap replacedObjects = Generics.newHashMap(); - ObjectOutputStream oos = new ReplaceObjectOutputStream(out, replacedObjects); - oos.writeObject(object); - ObjectInputStream ois = new ReplaceObjectInputStream(new ByteArrayInputStream( - out.toByteArray()), replacedObjects, object.getClass().getClassLoader()); - return (T) ois.readObject(); - } - catch (ClassNotFoundException | IOException e) - { - throw new WicketRuntimeException("Internal error cloning object", e); - } - } - } - /** * Strategy for calculating sizes of objects. Note: I didn't make this an application setting as * we have enough of those already, and the typical way this probably would be used is that @@ -295,6 +148,7 @@ public static T cloneModel(final T object) * @return A deep copy of the object * @see #cloneModel(Object) */ + @SuppressWarnings("unchecked") public static T cloneObject(final T object) { if (object == null) @@ -334,6 +188,7 @@ public static T cloneObject(final T object) * The full class name * @return The new object instance */ + @SuppressWarnings("unchecked") public static T newInstance(final String className) { if (!Strings.isEmpty(className)) diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/WicketTag.java b/wicket-core/src/main/java/org/apache/wicket/markup/WicketTag.java index fe7cfe9f289..ddcf8757373 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/WicketTag.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/WicketTag.java @@ -64,19 +64,6 @@ public WicketTag(final ComponentTag tag) tag.copyPropertiesTo(this); } - - /** - * Get the tag's name attribute: e.g. <wicket:region name=panel> - * - * @return The tag's name attribute - * @deprecated This method is obsolete since a long time - */ - @Deprecated - public final String getNameAttribute() - { - return getAttributes().getString("name"); - } - /** * @return True, if tag name equals 'wicket:container' */ diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java index 86ba60f4093..5bc90d60180 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java @@ -505,14 +505,6 @@ public final Collection getFormValidators() return Collections.unmodifiableCollection(validators); } - /** - * @deprecated use {@link #getJsForListenerUrl(CharSequence)} instead. - */ - @Deprecated(since = "8.0", forRemoval = true) - public final CharSequence getJsForInterfaceUrl(CharSequence url) { - return getJsForListenerUrl(url); - } - /** * Generate a piece of JavaScript that submits the form to the given URL. * diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java index 37722d8f84b..8030344b953 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java @@ -50,7 +50,6 @@ import org.apache.wicket.util.convert.IConverter; import org.apache.wicket.util.lang.Args; import org.apache.wicket.util.lang.Classes; -import org.apache.wicket.util.lang.Objects; import org.apache.wicket.util.string.StringList; import org.apache.wicket.util.string.StringValue; import org.apache.wicket.util.string.Strings; @@ -1387,11 +1386,6 @@ protected void onComponentTag(final ComponentTag tag) onDisabled(tag); } - if (isRequired()) - { - onRequired(tag); - } - super.onComponentTag(tag); } @@ -1420,17 +1414,6 @@ protected void onDisabled(final ComponentTag tag) tag.put("disabled", "disabled"); } - /** - * Called by {@link #onComponentTag(ComponentTag)} when the component is required. - * - * @param tag - * the tag that is being rendered - */ - @Deprecated - protected void onRequired(final ComponentTag tag) - { - } - /** * Handle invalidation */ diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/resolver/HtmlHeaderResolver.java b/wicket-core/src/main/java/org/apache/wicket/markup/resolver/HtmlHeaderResolver.java index 5b84703b3fb..cbb4c470fac 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/resolver/HtmlHeaderResolver.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/resolver/HtmlHeaderResolver.java @@ -142,19 +142,6 @@ else if (container instanceof HtmlHeaderContainer) return null; } - /** - * Return a new HtmlHeaderContainer - * - * @param id - * @return HtmlHeaderContainer - * @deprecated Use #newHtmlHeaderContainer(String, ComponentTag) instead - */ - @Deprecated - protected HtmlHeaderContainer newHtmlHeaderContainer(String id) - { - return new HtmlHeaderContainer(id); - } - /** * Return a new HtmlHeaderContainer * @@ -170,7 +157,7 @@ protected HtmlHeaderContainer newHtmlHeaderContainer(String id, ComponentTag tag } else { - htmlHeaderContainer = newHtmlHeaderContainer(id); + htmlHeaderContainer = new HtmlHeaderContainer(id); } return htmlHeaderContainer; @@ -181,6 +168,8 @@ protected HtmlHeaderContainer newHtmlHeaderContainer(String id, ComponentTag tag */ private static class WicketHeadContainer extends WebMarkupContainer { + private static final long serialVersionUID = 1L; + /** * Constructor. */ diff --git a/wicket-core/src/main/java/org/apache/wicket/migrate/StringResourceModelMigration.java b/wicket-core/src/main/java/org/apache/wicket/migrate/StringResourceModelMigration.java deleted file mode 100644 index 7431254a1cd..00000000000 --- a/wicket-core/src/main/java/org/apache/wicket/migrate/StringResourceModelMigration.java +++ /dev/null @@ -1,175 +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.migrate; - -import org.apache.wicket.Component; -import org.apache.wicket.model.IModel; -import org.apache.wicket.model.StringResourceModel; - -/** - * Assistant class for migrating old Wicket 6.x style StringResourceModel instantiations to the - * Wicket 7.x fluent API. - * - * Replace your old invocation of {@code StringResourceModel}'s constructor: - * - *
- * new StringResourceModel(...);
- * 
- * - * with the following snippet: - * - *
- * StringResourceModelMigration.of(...);
- * 
- * - * and then use your IDE's Inline Method refactoring support to use the new fluent API. - * @since 7.0.0 - */ -public class StringResourceModelMigration -{ - /** - * @deprecated use 'inline method' to get rid of the deprecation warning and complete the - * migration to Wicket 7 API. - * Original JavaDoc: - * - * Creates a new string resource model using the supplied parameters.

The relative component - * parameter should generally be supplied, as without it resources can not be obtained from - * resource bundles that are held relative to a particular component or page. However, for - * application that use only global resources then this parameter may be null.

The model - * parameter is also optional and only needs to be supplied if value substitutions are to take - * place on either the resource key or the actual resource strings.

The parameters parameter - * is also optional and is used for substitutions. - * - * @param resourceKey The resource key for this string resource - * - * @param component The component that the resource is relative to - * - * @param model The model to use for property substitutions - * - * @param parameters The parameters to substitute using a Java MessageFormat object - */ - @Deprecated - @SuppressWarnings(value = "javadoc") - public static StringResourceModel of(final String resourceKey, final Component component, - final IModel model, final Object... parameters) - { - return new StringResourceModel(resourceKey, component).setModel(model).setParameters( - parameters); - } - - /** - * @deprecated use 'inline method' to get rid of the deprecation warning and complete the - * migration to Wicket 7 API. - */ - /* - * Original JavaDoc: - * - * Creates a new string resource model using the supplied parameters. - *

- * The relative component parameter should generally be supplied, as without it resources can - * not be obtained from resource bundles that are held relative to a particular component or - * page. However, for application that use only global resources then this parameter may be - * null. - *

- * The model parameter is also optional and only needs to be supplied if value substitutions are - * to take place on either the resource key or the actual resource strings. - *

- * The parameters parameter is also optional and is used for substitutions. - * - * @param resourceKey - * The resource key for this string resource - * @param component - * The component that the resource is relative to - * @param model - * The model to use for property substitutions - * @param defaultValue - * The default value if the resource key is not found. - * @param parameters - * The parameters to substitute using a Java MessageFormat object - */ - @Deprecated - @SuppressWarnings(value = "javadoc") - public static StringResourceModel of(final String resourceKey, final Component component, - final IModel model, final String defaultValue, final Object... parameters) - { - return new StringResourceModel(resourceKey, component).setModel(model) - .setDefaultValue(defaultValue) - .setParameters(parameters); - } - - /** - * @deprecated use 'inline method' to get rid of the deprecation warning and complete the - * migration to Wicket 7 API. - */ - /* - * Original JavaDoc: - * - * Creates a new string resource model using the supplied parameters. - *

- * The model parameter is also optional and only needs to be supplied if value substitutions are - * to take place on either the resource key or the actual resource strings. - *

- * The parameters parameter is also optional and is used for substitutions. - * - * @param resourceKey - * The resource key for this string resource - * @param model - * The model to use for property substitutions - * @param parameters - * The parameters to substitute using a Java MessageFormat object - */ - @Deprecated - @SuppressWarnings(value = "javadoc") - public static StringResourceModel of(final String resourceKey, final IModel model, - final Object... parameters) - { - return new StringResourceModel(resourceKey).setModel(model).setParameters(parameters); - } - - /** - * @deprecated use 'inline method' to get rid of the deprecation warning and complete the - * migration to Wicket 7 API. - */ - /* - * Original JavaDoc: - * - * Creates a new string resource model using the supplied parameters. - *

- * The model parameter is also optional and only needs to be supplied if value substitutions are - * to take place on either the resource key or the actual resource strings. - *

- * The parameters parameter is also optional and is used for substitutions. - * - * @param resourceKey - * The resource key for this string resource - * @param model - * The model to use for property substitutions - * @param parameters - * The parameters to substitute using a Java MessageFormat object - * @param defaultValue - * The default value if the resource key is not found. - */ - @Deprecated - @SuppressWarnings(value = "javadoc") - public static StringResourceModel of(final String resourceKey, final IModel model, - final String defaultValue, final Object... parameters) - { - return new StringResourceModel(resourceKey).setModel(model) - .setDefaultValue(defaultValue) - .setParameters(parameters); - } -} diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java index 2c42cd98ccf..aa86e8fada3 100755 --- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java +++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java @@ -70,8 +70,6 @@ import org.apache.wicket.util.string.StringValue; import org.apache.wicket.util.string.Strings; import org.apache.wicket.util.value.ValueMap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** @@ -89,7 +87,6 @@ public class MockHttpServletRequest implements HttpServletRequest */ private static class UploadedFile { - private String fieldName; private File file; private String contentType; @@ -102,7 +99,6 @@ private static class UploadedFile */ public UploadedFile(String fieldName, File file, String contentType) { - this.fieldName = fieldName; this.file = file; this.contentType = contentType; } @@ -115,31 +111,6 @@ public String getContentType() return contentType; } - /** - * @param contentType - * The content type. - */ - public void setContentType(String contentType) - { - this.contentType = contentType; - } - - /** - * @return The field name. - */ - public String getFieldName() - { - return fieldName; - } - - /** - * @param fieldName - */ - public void setFieldName(String fieldName) - { - this.fieldName = fieldName; - } - /** * @return The uploaded file. */ @@ -147,22 +118,8 @@ public File getFile() { return file; } - - /** - * @param file - */ - public void setFile(File file) - { - this.file = file; - } } - /** Logging object */ - private static final Logger log = LoggerFactory.getLogger(MockHttpServletRequest.class); - - /** The application */ - private final Application application; - private final ValueMap attributes = new ValueMap(); private String authType; @@ -217,7 +174,6 @@ public void setFile(File file) public MockHttpServletRequest(final Application application, final HttpSession session, final ServletContext context, Locale locale) { - this.application = application; this.session = session; this.context = context; initialize(locale); diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletResponse.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletResponse.java index 62888637f7e..6c5eafbb38c 100755 --- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletResponse.java +++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletResponse.java @@ -81,8 +81,6 @@ public class MockHttpServletResponse implements HttpServletResponse, IMetaDataBu private StringWriter stringWriter; - private final MockHttpServletRequest servletRequest; - /** * Create the response object. * @@ -90,7 +88,6 @@ public class MockHttpServletResponse implements HttpServletResponse, IMetaDataBu */ public MockHttpServletResponse(MockHttpServletRequest servletRequest) { - this.servletRequest = servletRequest; initialize(); } @@ -568,47 +565,6 @@ public void sendError(final int code, final String msg) throws IOException errorMessage = msg; } - /** - * @return url - * @see org.apache.wicket.request.Request#getUrl() - */ - private String getURL() - { - /* - * Servlet 2.3 specification : - * - * Servlet Path: The path section that directly corresponds to the mapping which activated - * this request. This path starts with a "/" character except in the case where the request - * is matched with the "/*" pattern, in which case it is the empty string. - * - * PathInfo: The part of the request path that is not part of the Context Path or the - * Servlet Path. It is either null if there is no extra path, or is a string with a leading - * "/". - */ - String url = servletRequest.getServletPath(); - final String pathInfo = servletRequest.getPathInfo(); - - if (pathInfo != null) - { - url += pathInfo; - } - - final String queryString = servletRequest.getQueryString(); - - if (queryString != null) - { - url += ("?" + queryString); - } - - // If url is non-empty it will start with '/', which we should lose - if (url.length() > 0 && url.charAt(0) == '/') - { - // Remove leading '/' - url = url.substring(1); - } - return url; - } - /** * Indicate sending of a redirectLocation to a particular named resource. This implementation * just keeps hold of the redirectLocation info and makes it available for query. diff --git a/wicket-core/src/main/java/org/apache/wicket/request/handler/render/WebPageRenderer.java b/wicket-core/src/main/java/org/apache/wicket/request/handler/render/WebPageRenderer.java index 544fc340d47..ad50546c1ba 100644 --- a/wicket-core/src/main/java/org/apache/wicket/request/handler/render/WebPageRenderer.java +++ b/wicket-core/src/main/java/org/apache/wicket/request/handler/render/WebPageRenderer.java @@ -289,7 +289,7 @@ protected boolean isPageStateless() protected boolean isNewPageInstance() { - return getPageProvider().isNewPageInstance(); + return !getPageProvider().hasPageInstance(); } protected boolean shouldPreserveClientUrl(RequestCycle requestCycle) diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/JQueryResourceReference.java b/wicket-core/src/main/java/org/apache/wicket/resource/JQueryResourceReference.java index 1ddd90bf9d5..a88c70d5b30 100644 --- a/wicket-core/src/main/java/org/apache/wicket/resource/JQueryResourceReference.java +++ b/wicket-core/src/main/java/org/apache/wicket/resource/JQueryResourceReference.java @@ -66,15 +66,6 @@ public static JQueryResourceReference getV3() return INSTANCE_3; } - /** - * @deprecated Use {@link #JQueryResourceReference(String)} instead - */ - @Deprecated - protected JQueryResourceReference() - { - super(JQueryResourceReference.class, VERSION_1); - } - protected JQueryResourceReference(final String version) { super(JQueryResourceReference.class, version); diff --git a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java index 48712529787..4b3c6b8d2bd 100644 --- a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java +++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java @@ -88,7 +88,6 @@ import org.apache.wicket.markup.html.link.ExternalLink; import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.markup.html.link.ResourceLink; -import org.apache.wicket.markup.html.list.ListView; import org.apache.wicket.markup.parser.XmlPullParser; import org.apache.wicket.markup.parser.XmlTag; import org.apache.wicket.mock.MockApplication; @@ -1717,7 +1716,7 @@ public void assertNotExists(final String path) } } - private FormComponent assertFormComponent(final String path) + private FormComponent assertFormComponent(final String path) { Component component = assertExists(path); @@ -1807,23 +1806,6 @@ public Result ifContainsNot(String pattern) getLastResponseAsString().matches("(?s).*" + pattern + ".*")); } - /** - * assert the model of {@link ListView} use expectedList - * - * @param path - * path to {@link ListView} component - * @param expectedList - * expected list in the model of {@link ListView} - * @deprecated use {@link WicketTester#assertComponent(String, Class) combined with - * {@link WicketTester#assertModelValue(String, Object)} instead - */ - @Deprecated - public void assertListView(String path, List expectedList) - { - ListView listView = (ListView)getComponentFromLastRenderedPage(path); - WicketTesterHelper.assertEquals(expectedList, listView.getList()); - } - /** * Click the {@link Link} in the last rendered Page. *

@@ -2645,21 +2627,6 @@ private void notNull(String message, Object object) } } - /** - * - * @param message - * @param object - * @return fail with message if not null - */ - private Result isNull(String message, Object object) - { - if (object != null) - { - return Result.fail(message); - } - return Result.pass(); - } - /** * Checks whether a component is visible and/or enabled before usage * diff --git a/wicket-core/src/main/java/org/apache/wicket/util/tester/TagTester.java b/wicket-core/src/main/java/org/apache/wicket/util/tester/TagTester.java index ca851ae61ad..db2542ae6d1 100644 --- a/wicket-core/src/main/java/org/apache/wicket/util/tester/TagTester.java +++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/TagTester.java @@ -304,7 +304,7 @@ public TagTester getChild(String tagName) int endPos = closeTag.getPos(); String markup = parser.getInput(startPos, endPos).toString(); - childTagTester = createTagByAttribute(markup, tagName); + childTagTester = createTagByName(markup, tagName); } return childTagTester; @@ -391,23 +391,6 @@ public static TagTester createTagByName(String markup, String tagName) return tester.get(0); } - /** - * Static factory method for creating a TagTester based on a tag name. Please note - * that it will return the first tag which matches the criteria. - * - * @param markup - * the markup to look for the tag to create the TagTester from the value - * which the attribute must have - * @return the TagTester which matches the tag by name in the markup - * - * @deprecated use {@link #createTagByName(String, String)} instead - */ - @Deprecated - public static TagTester createTagByAttribute(String markup, String tagName) - { - return createTagByName(markup, tagName); - } - /** * Static factory method for creating a TagTester based on a tag found by an * attribute with a specific value. Please note that it will return the first tag which matches @@ -433,27 +416,6 @@ public static TagTester createTagByAttribute(String markup, String attribute, St return tester.get(0); } - /** - * Static factory method for creating a TagTester based on a tag found by an - * attribute with a specific value. Please note that it will return the first tag which matches - * the criteria. It's therefore good for attributes suck as "id" or "wicket:id", but only if - * "wicket:id" is unique in the specified markup. - * - * @param markup - * the markup to look for the tag to create the TagTester from - * @param attribute - * the attribute which should be on the tag in the markup - * @param value - * the value which the attribute must have - * @return the TagTester which matches the tag in the markup, that has the given - * value on the given attribute - */ - @Deprecated - public static TagTester createTagsByAttribute(String markup, String attribute, String value) - { - return createTagByAttribute(markup, attribute, value); - } - /** * find the correct openTag to the given closeTag and remove all unclosed openTags between both * in given array {@code stack} diff --git a/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java index df096ae18be..1addc55f699 100644 --- a/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java +++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java @@ -45,7 +45,6 @@ import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.ValidationErrorFeedback; import org.apache.wicket.markup.html.link.BookmarkablePageLink; -import org.apache.wicket.markup.html.list.ListView; import org.apache.wicket.markup.html.panel.FeedbackPanel; import org.apache.wicket.model.IModel; import org.apache.wicket.protocol.http.WebApplication; @@ -666,24 +665,6 @@ public void assertModelValue(String path, Object expectedValue) assertEquals(expectedValue, component.getDefaultModelObject()); } - /** - * Asserts the model of a {@link ListView}. - * - * @param path - * path to a {@link ListView} Component - * @param expectedList - * expected List in the model of the given {@link ListView} - * @Deprecated use {@link #assertComponent(String, Class) combined with - * {@link #assertModelValue(String, Object)} instead - */ - @Deprecated - @Override - public void assertListView(String path, List expectedList) - { - ListView listView = (ListView)getComponentFromLastRenderedPage(path); - WicketTesterHelper.assertEquals(expectedList, listView.getList()); - } - /** * Asserts no error-level feedback messages. */ diff --git a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/MountedMapperTest.java b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/MountedMapperTest.java index 1b91f8a17db..3cfd257c046 100644 --- a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/MountedMapperTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/MountedMapperTest.java @@ -590,7 +590,7 @@ void encode8() void construct1() { assertThrows(IllegalArgumentException.class, () -> { - IRequestMapper e = new MountedMapper("", MockPage.class); + new MountedMapper("", MockPage.class); }); } @@ -700,14 +700,7 @@ void placeholderEncode3() parameters.set("param1", "p1", INamedParameters.Type.PATH); parameters.set("param2", "p2", INamedParameters.Type.PATH); - PageProvider provider = new PageProvider(MockPage.class, parameters) - { - @Override - public boolean isNewPageInstance() - { - return false; - } - }; + PageProvider provider = new PageProvider(1, MockPage.class, parameters, null); provider.setPageSource(context); IRequestHandler handler = new RenderPageRequestHandler(provider); Url url = placeholderEncoder.mapHandler(handler); @@ -720,14 +713,7 @@ public boolean isNewPageInstance() @Test void placeholderEncode4() { - PageProvider provider = new PageProvider(MockPage.class) - { - @Override - public boolean isNewPageInstance() - { - return false; - } - }; + PageProvider provider = new PageProvider(MockPage.class); provider.setPageSource(context); IRequestHandler handler = new RenderPageRequestHandler(provider); Url url = placeholderEncoder.mapHandler(handler); diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/image/ResponsiveImageTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/image/ResponsiveImageTest.java index c2e330c35dc..a1db8de8a4c 100644 --- a/wicket-core/src/test/java/org/apache/wicket/markup/html/image/ResponsiveImageTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/image/ResponsiveImageTest.java @@ -38,7 +38,7 @@ void testSrcSetIsNotAvailableOnDefaultUsage() { tester.startPage(ImageResourceReferenceTestPage.class); String lastResponseAsString = tester.getLastResponse().getDocument(); - TagTester createTagByAttribute = TagTester.createTagByAttribute(lastResponseAsString, "img"); + TagTester createTagByAttribute = TagTester.createTagByName(lastResponseAsString, "img"); assertFalse(createTagByAttribute.hasAttribute("srcset")); assertEquals(Image.Cors.ANONYMOUS.getRealName(), createTagByAttribute.getAttribute("crossorigin")); } @@ -48,10 +48,10 @@ void testPictureTagIsRenderedRight() { tester.startPage(ImagePictureTestPage.class); String lastResponseAsString = tester.getLastResponse().getDocument(); - TagTester pictureTagTester = TagTester.createTagByAttribute(lastResponseAsString, "picture"); + TagTester pictureTagTester = TagTester.createTagByName(lastResponseAsString, "picture"); assertTrue(pictureTagTester.hasChildTag("img")); assertTrue(pictureTagTester.hasChildTag("source")); - TagTester sourceTagTester = TagTester.createTagByAttribute(lastResponseAsString, "source"); + TagTester sourceTagTester = TagTester.createTagByName(lastResponseAsString, "source"); assertTrue(sourceTagTester.hasAttribute("media")); assertEquals("(min-width: 650px)", sourceTagTester.getAttribute("media")); assertEquals("(min-width: 50em) 33vw", sourceTagTester.getAttribute("sizes")); @@ -62,7 +62,7 @@ void testImageTagIsRenderedWithXValuesAndSrcSet() { tester.startPage(ImageSrcSetTestPage.class); String lastResponseAsString = tester.getLastResponse().getDocument(); - TagTester imgTagTester = TagTester.createTagByAttribute(lastResponseAsString, "img"); + TagTester imgTagTester = TagTester.createTagByName(lastResponseAsString, "img"); assertTrue(imgTagTester.hasAttribute("src")); assertTrue(imgTagTester.hasAttribute("srcset")); String attribute = imgTagTester.getAttribute("srcset"); diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/media/MediaTagsTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/media/MediaTagsTest.java index 9e95dc3cea6..efebe32eebe 100644 --- a/wicket-core/src/test/java/org/apache/wicket/markup/html/media/MediaTagsTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/media/MediaTagsTest.java @@ -37,8 +37,7 @@ void audioTagIsRenderedRight() { tester.startPage(MediaTagsTestPage.class); String lastResponseAsString = tester.getLastResponse().getDocument(); - TagTester createTagByAttribute = TagTester.createTagByAttribute(lastResponseAsString, - "audio"); + TagTester createTagByAttribute = TagTester.createTagByName(lastResponseAsString, "audio"); assertTrue(createTagByAttribute.hasAttribute("autoplay")); assertTrue(createTagByAttribute.hasAttribute("controls")); assertTrue(createTagByAttribute.hasAttribute("loop")); @@ -54,8 +53,7 @@ void videoTagIsRenderedRight() { tester.startPage(MediaTagsTestPage.class); String lastResponseAsString = tester.getLastResponse().getDocument(); - TagTester createTagByAttribute = TagTester.createTagByAttribute(lastResponseAsString, - "video"); + TagTester createTagByAttribute = TagTester.createTagByName(lastResponseAsString, "video"); String attribute = createTagByAttribute.getAttribute("poster"); assertTrue(attribute.contains("test2=test2"), "page parameter is in the url of the poster"); String attributesrc = createTagByAttribute.getAttribute("src"); @@ -69,18 +67,17 @@ void extendedVideoTagIsRenderedRight() { tester.startPage(MediaTagsExtendedTestPage.class); String lastResponseAsString = tester.getLastResponse().getDocument(); - TagTester createTagByAttribute = TagTester.createTagByAttribute(lastResponseAsString, - "video"); + TagTester createTagByAttribute = TagTester.createTagByName(lastResponseAsString, "video"); assertTrue(createTagByAttribute.hasChildTag("source")); assertTrue(createTagByAttribute.hasChildTag("track")); - TagTester sourceTag = TagTester.createTagByAttribute(lastResponseAsString, "source"); + TagTester sourceTag = TagTester.createTagByName(lastResponseAsString, "source"); assertEquals("video/mp4", sourceTag.getAttribute("type")); assertEquals("screen and (device-width:500px)", sourceTag.getAttribute("media")); assertEquals("http://www.mytestpage.xc/video.m4a", sourceTag.getAttribute("src")); - TagTester trackTag = TagTester.createTagByAttribute(lastResponseAsString, "track"); + TagTester trackTag = TagTester.createTagByName(lastResponseAsString, "track"); assertTrue(trackTag.getAttribute("src").contains("dummySubtitles")); assertEquals("subtitles", trackTag.getAttribute("kind")); diff --git a/wicket-core/src/test/java/org/apache/wicket/request/handler/PageProviderTest.java b/wicket-core/src/test/java/org/apache/wicket/request/handler/PageProviderTest.java index b7ad145926e..2e1795ebdbc 100644 --- a/wicket-core/src/test/java/org/apache/wicket/request/handler/PageProviderTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/request/handler/PageProviderTest.java @@ -74,7 +74,7 @@ void pageProviderDontDeserializeOnePageTwice() PageProvider pageProvider = mapperContext.new TestPageProvider(testPage.getPageId(), 0); // simulation an test call to isNewPageInstance - boolean isNewPageInstance = pageProvider.isNewPageInstance(); + boolean isNewPageInstance = !pageProvider.hasPageInstance(); assertFalse(isNewPageInstance, "test page is already stored"); // changing some sate @@ -94,6 +94,7 @@ void pageProviderDontDeserializeOnePageTwice() private static class StatefullMockPage extends MockPage { + private static final long serialVersionUID = 1L; int state = 0; } diff --git a/wicket-core/src/test/java/org/apache/wicket/request/handler/render/WebPageRendererTest.java b/wicket-core/src/test/java/org/apache/wicket/request/handler/render/WebPageRendererTest.java index a4048857d95..caea6676be2 100644 --- a/wicket-core/src/test/java/org/apache/wicket/request/handler/render/WebPageRendererTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/request/handler/render/WebPageRendererTest.java @@ -277,7 +277,7 @@ protected boolean isRedirectToRender() @Test void testSameUrlsAndStatefulPage() { - when(provider.isNewPageInstance()).thenReturn(false); + when(!provider.hasPageInstance()).thenReturn(false); when(page.isPageStateless()).thenReturn(false); PageRenderer renderer = new TestPageRenderer(handler); @@ -918,7 +918,7 @@ protected void storeBufferedResponse(Url url, BufferedWebResponse response) } }; - when(provider.isNewPageInstance()).thenReturn(true); + when(!provider.hasPageInstance()).thenReturn(true); Url sameUrl = Url.parse("same"); @@ -975,7 +975,7 @@ protected void storeBufferedResponse(Url url, BufferedWebResponse response) }; when(page.isPageStateless()).thenReturn(false); - when(provider.isNewPageInstance()).thenReturn(false); + when(!provider.hasPageInstance()).thenReturn(false); // needed for earlier checks when(urlRenderer.getBaseUrl()).thenReturn(Url.parse("url1")); diff --git a/wicket-core/src/test/java/org/apache/wicket/util/lang/WicketObjectsTest.java b/wicket-core/src/test/java/org/apache/wicket/util/lang/WicketObjectsTest.java index 0808a91b295..00f491963d3 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/lang/WicketObjectsTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/lang/WicketObjectsTest.java @@ -18,7 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -44,7 +43,7 @@ class WicketObjectsTest extends WicketTestCase @Test void cloneModelNull() { - Object clone = WicketObjects.cloneModel(null); + Object clone = WicketObjects.cloneObject(null); assertEquals(null, clone); } @@ -66,7 +65,7 @@ void cloneModelString() { String cloneMe = "Mini-me"; - Object clone = WicketObjects.cloneModel(cloneMe); + Object clone = WicketObjects.cloneObject(cloneMe); assertEquals(cloneMe, clone); assertNotSame(cloneMe, clone); } @@ -94,7 +93,7 @@ void cloneModelNonSerializableObject() try { - WicketObjects.cloneModel(cloneMe); + WicketObjects.cloneObject(cloneMe); fail("Exception expected"); } catch (RuntimeException e) @@ -125,14 +124,12 @@ void cloneObjectNonSerializableObject() /** * Test method for component cloning */ - @SuppressWarnings({ "unchecked" }) @Test void componentClone() { - PropertyModel pm = new PropertyModel<>(new TextField<>("test", - Model.of("test")), "modelObject"); - PropertyModel pm2 = WicketObjects.cloneModel(pm); - assertSame(pm.getObject(), pm2.getObject()); + PropertyModel pm = new PropertyModel<>(new TextField<>("test", Model.of("test")), "modelObject"); + PropertyModel pm2 = WicketObjects.cloneObject(pm); + assertEquals(pm.getObject(), pm2.getObject()); } /** @@ -144,7 +141,7 @@ void cloneCloneObject() CloneObject cloneMe = new CloneObject(); cloneMe.nr = 1; - Object clone = WicketObjects.cloneModel(cloneMe); + Object clone = WicketObjects.cloneObject(cloneMe); assertEquals(cloneMe, clone); assertNotSame(cloneMe, clone); } diff --git a/wicket-examples/src/test/java/org/apache/wicket/examples/guestbook/GuestbookTest.java b/wicket-examples/src/test/java/org/apache/wicket/examples/guestbook/GuestbookTest.java index d3d64aed2e1..ba5f8970b71 100644 --- a/wicket-examples/src/test/java/org/apache/wicket/examples/guestbook/GuestbookTest.java +++ b/wicket-examples/src/test/java/org/apache/wicket/examples/guestbook/GuestbookTest.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.list.ListView; import org.apache.wicket.util.tester.FormTester; import org.apache.wicket.util.tester.WicketTestCase; import org.junit.jupiter.api.BeforeEach; @@ -49,7 +50,8 @@ public void test_1() { tester.assertContains("Wicket Examples - guestbook"); // check if the list of comments is empty - tester.assertListView("comments", new ArrayList<>()); + tester.assertComponent("comments", ListView.class); + tester.assertModelValue("comments", new ArrayList<>()); tester.assertComponent("commentForm", Form.class); FormTester formTester = tester.newFormTester("commentForm"); formTester.setValue("text", "test-1"); diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanel.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanel.java index 36bc514860c..cdf39ab837e 100644 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanel.java +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanel.java @@ -23,8 +23,6 @@ import org.apache.wicket.ajax.AbstractAjaxTimerBehavior; import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior; import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.ajax.attributes.AjaxRequestAttributes; -import org.apache.wicket.markup.head.IHeaderResponse; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.model.IModel; @@ -58,12 +56,6 @@ public abstract class AjaxLazyLoadPanel extends Panel * The component id which will be used to load the lazily loaded component. */ private static final String CONTENT_ID = "content"; - - /** - * @deprecated will be removed in Wicket 9 - */ - @Deprecated - public static final String LAZY_LOAD_COMPONENT_ID = CONTENT_ID; private boolean loaded; @@ -103,24 +95,6 @@ protected boolean isContentReady() return true; } - /** - * @deprecated this method is not called, and will be removed in Wicket 9 - */ - @Deprecated(since = "8.0", forRemoval = true) - protected final void updateAjaxAttributes(AjaxRequestAttributes attributes) - { - } - - /** - * @deprecated this method is not called, and will be removed in Wicket 9 - */ - @Deprecated(since = "8.0", forRemoval = true) - protected final void handleCallbackScript(final IHeaderResponse response, - final CharSequence callbackScript, final Component component) - { - - } - /** * Create a loading component shown instead of the actual content until it is {@link #isContentReady()}. * @@ -148,14 +122,6 @@ public Component getLoadingComponent(final String id) */ public abstract T getLazyLoadComponent(String markupId); - /** - * @deprecated override {@link #onContentLoaded(Component, Optional)} instead - will be removed in Wicket 9 - */ - @Deprecated - protected final void onComponentLoaded(Component component, AjaxRequestTarget target) - { - } - /** * Called after the loading component was replaced with the lazy loaded content. *

diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/repeater/data/sort/AjaxFallbackOrderByLink.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/repeater/data/sort/AjaxFallbackOrderByLink.java deleted file mode 100644 index 503d226f301..00000000000 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/repeater/data/sort/AjaxFallbackOrderByLink.java +++ /dev/null @@ -1,52 +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.extensions.ajax.markup.html.repeater.data.sort; - -import org.apache.wicket.extensions.markup.html.repeater.data.sort.ISortStateLocator; -import org.apache.wicket.extensions.markup.html.repeater.data.sort.OrderByLink; - - -/** - * Ajaxified {@link OrderByLink} - * - * @param - * the type of the sort property - * @see OrderByLink - * - * @since 1.2.1 - * - * @author Igor Vaynberg (ivaynberg) - * @deprecated Use {@link AjaxOrderByLink} instead - */ -@Deprecated -public abstract class AjaxFallbackOrderByLink extends AjaxOrderByLink -{ - private static final long serialVersionUID = 1L; - - /** - * Constructor - * - * @param id - * @param sortProperty - * @param stateLocator - */ - public AjaxFallbackOrderByLink(final String id, final S sortProperty, - final ISortStateLocator stateLocator) - { - super(id, sortProperty, stateLocator); - } -} diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/IDefaultButtonProvider.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/IDefaultButtonProvider.java deleted file mode 100644 index e4bcf89a0c9..00000000000 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/IDefaultButtonProvider.java +++ /dev/null @@ -1,47 +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.extensions.wizard; - -import org.apache.wicket.markup.html.form.Form; -import org.apache.wicket.markup.html.form.IFormSubmittingComponent; - -/** - * Optional interface that can be implemented by button bars if they can provide what button should - * be the 'default' one - the one that is selected when a user presses enter. Note that this is not - * completely water proof as it depends on non-standard browser behavior (i.e. the fact that most - * browsers select the first button they encounter). - * - * @see Form#setDefaultButton(IFormSubmittingComponent) - * - * @author eelcohillenius - */ -@Deprecated -public interface IDefaultButtonProvider -{ - /** - * Gets the default button - the button that is selected when a user presses enter - based on - * the current state. - * - * @param model - * wizard model - * @return the default button - */ - IFormSubmittingComponent getDefaultButton(IWizardModel model); -} diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/WizardButton.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/WizardButton.java index 61f21098f4b..2b6c50dd6bf 100644 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/WizardButton.java +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/wizard/WizardButton.java @@ -18,7 +18,6 @@ import org.apache.wicket.markup.html.form.Button; import org.apache.wicket.model.IModel; -import org.apache.wicket.model.ResourceModel; /** * Base class for buttons that work with {@link IWizard the wizard component}. It uses resource @@ -39,22 +38,6 @@ public abstract class WizardButton extends Button */ private final IWizard wizard; - /** - * Construct. - * - * @param id - * The component id - * @param wizard - * The wizard - * @param labelResourceKey - * The resource key of the button's label - */ - @Deprecated - public WizardButton(final String id, final IWizard wizard, final String labelResourceKey) - { - this(id, wizard, new ResourceModel(labelResourceKey)); - } - /** * Construct. * diff --git a/wicket-request/src/main/java/org/apache/wicket/request/RequestHandlerExecutor.java b/wicket-request/src/main/java/org/apache/wicket/request/RequestHandlerExecutor.java index eacdd29ea0f..f60b27a18fc 100644 --- a/wicket-request/src/main/java/org/apache/wicket/request/RequestHandlerExecutor.java +++ b/wicket-request/src/main/java/org/apache/wicket/request/RequestHandlerExecutor.java @@ -19,8 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.wicket.util.lang.Args; -import org.apache.wicket.util.lang.Exceptions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -75,24 +73,6 @@ public IRequestHandler execute(final IRequestHandler handler) return scheduled; } - /** - * Certain exceptions can carry a request handler they wish to be executed, this method tries to - * resolve such a handler given an exception. - * - * @param exception - * @return request handler or null} if one cannot be resolved - * @deprecated - */ - @Deprecated(since = "8.0", forRemoval = true) - public final IRequestHandler resolveHandler(RuntimeException exception) - { - Args.notNull(exception, "exception"); - - ReplaceHandlerException replacer = Exceptions.findCause(exception, - ReplaceHandlerException.class); - return replacer != null ? replacer.replacementRequestHandler : null; - } - /** * Allows the request handler to respond to the request * @@ -201,15 +181,6 @@ public ReplaceHandlerException(final IRequestHandler replacementRequestHandler, this.replacementRequestHandler = replacementRequestHandler; this.removeScheduled = removeScheduled; } - - /** - * @deprecated use {@link #getRemoveScheduled()} instead - */ - @Deprecated(since = "8.0", forRemoval = true) - public boolean isRemoveAll() - { - return removeScheduled; - } /** * Should a scheduled handler be removed before replacing the handler diff --git a/wicket-util/src/main/java/org/apache/wicket/util/IContextProvider.java b/wicket-util/src/main/java/org/apache/wicket/util/IContextProvider.java deleted file mode 100644 index cf2b4139146..00000000000 --- a/wicket-util/src/main/java/org/apache/wicket/util/IContextProvider.java +++ /dev/null @@ -1,47 +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.util; - -import java.util.function.Function; - -/** - * An object that can provide instances of type {@code T} depending on context parameter of type - * {@code C} - * - * @param - * the type of the instance - * @param - * the type of the context parameter - * @deprecated Use {@link Function} instead - */ -@Deprecated -public interface IContextProvider extends Function -{ - /** - * Provides an instance of type {@code T} - * - * @param context - * the context parameter on which the instance depends - * @return instance of type {@code T} - */ - T get(C context); - - @Override - default T apply(C context) { - return get(context); - } -} diff --git a/wicket-util/src/main/java/org/apache/wicket/util/IProvider.java b/wicket-util/src/main/java/org/apache/wicket/util/IProvider.java deleted file mode 100644 index eedd38dc251..00000000000 --- a/wicket-util/src/main/java/org/apache/wicket/util/IProvider.java +++ /dev/null @@ -1,36 +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.util; - -/** - * An object that can provide instances of type {@code T} - * - * @author igor.vaynberg - * @param - * - * @deprecated Use {@code java.util.function.Supplier} instead - */ -@Deprecated(since = "8.0", forRemoval = true) -public interface IProvider -{ - /** - * Provides an instance of type {@code T} - * - * @return instance of type {@code T} - */ - T get(); -} diff --git a/wicket-util/src/main/java/org/apache/wicket/util/collections/ArrayListStack.java b/wicket-util/src/main/java/org/apache/wicket/util/collections/ArrayListStack.java deleted file mode 100644 index a57e675296d..00000000000 --- a/wicket-util/src/main/java/org/apache/wicket/util/collections/ArrayListStack.java +++ /dev/null @@ -1,141 +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.util.collections; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.EmptyStackException; - -/** - * A faster, smaller stack implementation. ArrayListStack is final and unsynchronized (the JDK's - * methods are synchronized). In addition you can set the initial capacity if you want via the - * ArrayListStack(int) constructor. - * - * @author Jonathan Locke - * @param - * @deprecated Scheduled to be removed with Wicket 9.x, use {@link java.util.ArrayDeque} instead. - */ -@Deprecated -public class ArrayListStack extends ArrayList -{ - private static final long serialVersionUID = 1L; - - /** - * Construct. - * - * @param initialCapacity - * Initial capacity of the stack - */ - public ArrayListStack(final int initialCapacity) - { - super(initialCapacity); - } - - /** - * Construct. - */ - public ArrayListStack() - { - this(10); - } - - /** - * Construct. - * - * @param collection - * The collection to add - */ - public ArrayListStack(final Collection collection) - { - super(collection); - } - - /** - * Pushes an item onto the top of this stack. - * - * @param item - * the item to be pushed onto this stack. - */ - public final void push(final T item) - { - add(item); - } - - /** - * Removes the object at the top of this stack and returns that object. - * - * @return The object at the top of this stack - * @exception EmptyStackException - * If this stack is empty. - */ - public final T pop() - { - final T top = peek(); - remove(size() - 1); - return top; - } - - /** - * Looks at the object at the top of this stack without removing it. - * - * @return The object at the top of this stack - * @exception EmptyStackException - * If this stack is empty. - */ - public final T peek() - { - int size = size(); - if (size == 0) - { - throw new EmptyStackException(); - } - return get(size - 1); - } - - /** - * Tests if this stack is empty. - * - * @return true if and only if this stack contains no items; false - * otherwise. - */ - public final boolean empty() - { - return size() == 0; - } - - /** - * Returns the 1-based position where an object is on this stack. If the object o - * occurs as an item in this stack, this method returns the distance from the top of the stack - * of the occurrence nearest the top of the stack; the topmost item on the stack is considered - * to be at distance 1. The equals method is used to compare o to the - * items in this stack. - * - * @param o - * the desired object. - * @return the 1-based position from the top of the stack where the object is located; the - * return value -1 indicates that the object is not on the stack. - */ - public final int search(final T o) - { - int i = lastIndexOf(o); - if (i >= 0) - { - return size() - i; - } - return -1; - } -} diff --git a/wicket-util/src/main/java/org/apache/wicket/util/crypt/Base64.java b/wicket-util/src/main/java/org/apache/wicket/util/crypt/Base64.java deleted file mode 100644 index 358db3794e1..00000000000 --- a/wicket-util/src/main/java/org/apache/wicket/util/crypt/Base64.java +++ /dev/null @@ -1,1108 +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.util.crypt; - -import java.math.BigInteger; - -/** - * Provides Base64 encoding and decoding with URL and filename safe alphabet as defined by RFC 3548, - * section 4. - *

- * This Base64 encoder is modified to meet URL requirements. The changes are: '+' => '*', '/' => - * '-', and no padding. - *

- *

- * This class is taken from the Apache commons-codec, and adjusted to fit the Wicket framework's - * needs, especially external dependencies have been removed. - *

- *

- * This class implements section 4. Base 64 Encoding with URL and Filename Safe - * Alphabet from RFC 3548 The Base16, Base32, and Base64 Data Encodings by Simon - * Josefsson. - *

- * - * @author Apache Software Foundation - * @author Juergen Donnerstag - * - * @since 1.2 - * @deprecated Use {@link java.util.Base64} instead. - */ -@Deprecated -public class Base64 -{ - private static final int DEFAULT_BUFFER_RESIZE_FACTOR = 2; - - private static final int DEFAULT_BUFFER_SIZE = 8192; - - /** - * Chunk size per RFC 2045 section 6.8. - * - *

- * The {@value} character limit does not count the trailing CRLF, but counts all other - * characters, including any equal signs. - *

- * - * @see RFC 2045 section 6.8 - */ - static final int CHUNK_SIZE = 76; - - /** - * Chunk separator per RFC 2045 section 2.1. - * - *

- * N.B. The next major release may break compatibility and make this field private. - *

- * - * @see RFC 2045 section 2.1 - */ - static final byte[] CHUNK_SEPARATOR = { '\r', '\n' }; - - /** - * This array is a lookup table that translates 6-bit positive integer index values into their - * "Base64 Alphabet" equivalents as specified in Table 1 of RFC 2045. - * - * Thanks to "commons" project in ws.apache.org for this code. - * http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/ - */ - private static final byte[] STANDARD_ENCODE_TABLE = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', - 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', - 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', - 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', - '7', '8', '9', '+', '/' }; - - /** - * This is a copy of the STANDARD_ENCODE_TABLE above, but with + and / changed to - and _ to - * make the encoded Base64 results more URL-SAFE. This table is only used when the Base64's mode - * is set to URL-SAFE. - */ - private static final byte[] URL_SAFE_ENCODE_TABLE = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', - 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', - 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', - 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', - '7', '8', '9', '-', '_' }; - - /** - * Byte used to pad output. - */ - private static final byte PAD = '='; - - /** - * This array is a lookup table that translates Unicode characters drawn from the - * "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into their 6-bit positive integer - * equivalents. Characters that are not in the Base64 alphabet but fall within the bounds of the - * array are translated to -1. - * - * Note: '+' and '-' both decode to 62. '/' and '_' both decode to 63. This means decoder - * seamlessly handles both URL_SAFE and STANDARD base64. (The encoder, on the other hand, needs - * to know ahead of time what to emit). - * - * Thanks to "commons" project in ws.apache.org for this code. - * http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/ - */ - private static final byte[] DECODE_TABLE = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, - 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, -1, 26, 27, 28, 29, 30, - 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 }; - - /** Mask used to extract 6 bits, used when encoding */ - private static final int MASK_6BITS = 0x3f; - - /** Mask used to extract 8 bits, used in decoding base64 bytes */ - private static final int MASK_8BITS = 0xff; - - // The static final fields above are used for the original static byte[] methods on Base64. - // The private member fields below are used with the new streaming approach, which requires - // some state be preserved between calls of encode() and decode(). - - /** - * Encode table to use: either STANDARD or URL_SAFE. Note: the DECODE_TABLE above remains static - * because it is able to decode both STANDARD and URL_SAFE streams, but the encodeTable must be - * a member variable so we can switch between the two modes. - */ - private final byte[] encodeTable; - - /** - * Line length for encoding. Not used when decoding. A value of zero or less implies no chunking - * of the base64 encoded data. - */ - private final int lineLength; - - /** - * Line separator for encoding. Not used when decoding. Only used if lineLength > 0. - */ - private final byte[] lineSeparator; - - /** - * Convenience variable to help us determine when our buffer is going to run out of room and - * needs resizing. decodeSize = 3 + lineSeparator.length; - */ - private final int decodeSize; - - /** - * Convenience variable to help us determine when our buffer is going to run out of room and - * needs resizing. encodeSize = 4 + lineSeparator.length; - */ - private final int encodeSize; - - /** - * Buffer for streaming. - */ - private byte[] buffer; - - /** - * Position where next character should be written in the buffer. - */ - private int pos; - - /** - * Position where next character should be read from the buffer. - */ - private int readPos; - - /** - * Variable tracks how many characters have been written to the current line. Only used when - * encoding. We use it to make sure each encoded line never goes beyond lineLength (if - * lineLength > 0). - */ - private int currentLinePos; - - /** - * Writes to the buffer only occur after every 3 reads when encoding, an every 4 reads when - * decoding. This variable helps track that. - */ - private int modulus; - - /** - * Boolean flag to indicate the EOF has been reached. Once EOF has been reached, this Base64 - * object becomes useless, and must be thrown away. - */ - private boolean eof; - - /** - * Place holder for the 3 bytes we're dealing with for our base64 logic. Bitwise operations - * store and extract the base64 encoding or decoding from this variable. - */ - private int x; - - /** - * Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode. - *

- * When encoding the line length is 76, the line separator is CRLF, and the encoding table is - * STANDARD_ENCODE_TABLE. - *

- * - *

- * When decoding all variants are supported. - *

- */ - public Base64() - { - this(false); - } - - /** - * Creates a Base64 codec used for decoding (all modes) and encoding in the given URL-safe mode. - *

- * When encoding the line length is 76, the line separator is CRLF, and the encoding table is - * STANDARD_ENCODE_TABLE. - *

- * - *

- * When decoding all variants are supported. - *

- * - * @param urlSafe - * if true, URL-safe encoding is used. In most cases this should be set - * to false. - * @since 1.4 - */ - public Base64(final boolean urlSafe) - { - this(CHUNK_SIZE, CHUNK_SEPARATOR, urlSafe); - } - - /** - * Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode. - *

- * When encoding the line length is given in the constructor, the line separator is CRLF, and - * the encoding table is STANDARD_ENCODE_TABLE. - *

- *

- * Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4 in - * the encoded data. - *

- *

- * When decoding all variants are supported. - *

- * - * @param lineLength - * Each line of encoded data will be at most of the given length (rounded down to - * nearest multiple of 4). If lineLength <= 0, then the output will not be divided - * into lines (chunks). Ignored when decoding. - * @since 1.4 - */ - public Base64(final int lineLength) - { - this(lineLength, CHUNK_SEPARATOR); - } - - /** - * Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode. - *

- * When encoding the line length and line separator are given in the constructor, and the - * encoding table is STANDARD_ENCODE_TABLE. - *

- *

- * Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4 in - * the encoded data. - *

- *

- * When decoding all variants are supported. - *

- * - * @param lineLength - * Each line of encoded data will be at most of the given length (rounded down to - * nearest multiple of 4). If lineLength <= 0, then the output will not be divided - * into lines (chunks). Ignored when decoding. - * @param lineSeparator - * Each line of encoded data will end with this sequence of bytes. - * @throws IllegalArgumentException - * Thrown when the provided lineSeparator included some base64 characters. - * @since 1.4 - */ - public Base64(final int lineLength, final byte[] lineSeparator) - { - this(lineLength, lineSeparator, false); - } - - /** - * Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode. - *

- * When encoding the line length and line separator are given in the constructor, and the - * encoding table is STANDARD_ENCODE_TABLE. - *

- *

- * Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4 in - * the encoded data. - *

- *

- * When decoding all variants are supported. - *

- * - * @param lineLength - * Each line of encoded data will be at most of the given length (rounded down to - * nearest multiple of 4). If lineLength <= 0, then the output will not be divided - * into lines (chunks). Ignored when decoding. - * @param lineSeparator - * Each line of encoded data will end with this sequence of bytes. - * @param urlSafe - * Instead of emitting '+' and '/' we emit '-' and '_' respectively. urlSafe is only - * applied to encode operations. Decoding seamlessly handles both modes. - * @throws IllegalArgumentException - * The provided lineSeparator included some base64 characters. That's not going to - * work! - * @since 1.4 - */ - public Base64(int lineLength, byte[] lineSeparator, final boolean urlSafe) - { - if (lineSeparator == null) - { - lineLength = 0; // disable chunk-separating - lineSeparator = CHUNK_SEPARATOR; // this just gets ignored - } - this.lineLength = lineLength > 0 ? (lineLength / 4) * 4 : 0; - this.lineSeparator = new byte[lineSeparator.length]; - System.arraycopy(lineSeparator, 0, this.lineSeparator, 0, lineSeparator.length); - if (lineLength > 0) - { - encodeSize = 4 + lineSeparator.length; - } - else - { - encodeSize = 4; - } - decodeSize = encodeSize - 1; - if (containsBase64Byte(lineSeparator)) - { - String sep = StringUtils.newStringUtf8(lineSeparator); - throw new IllegalArgumentException( - "lineSeperator must not contain base64 characters: [" + sep + "]"); - } - encodeTable = urlSafe ? URL_SAFE_ENCODE_TABLE : STANDARD_ENCODE_TABLE; - } - - /** - * Returns our current encode mode. True if we're URL-SAFE, false otherwise. - * - * @return true if we're in URL-SAFE mode, false otherwise. - * @since 1.4 - */ - public boolean isUrlSafe() - { - return encodeTable == URL_SAFE_ENCODE_TABLE; - } - - /** - * Returns true if this Base64 object has buffered data for reading. - * - * @return true if there is Base64 object still available for reading. - */ - boolean hasData() - { - return buffer != null; - } - - /** - * Returns the amount of buffered data available for reading. - * - * @return The amount of buffered data available for reading. - */ - int avail() - { - return buffer != null ? pos - readPos : 0; - } - - /** Doubles our buffer. */ - private void resizeBuffer() - { - if (buffer == null) - { - buffer = new byte[DEFAULT_BUFFER_SIZE]; - pos = 0; - readPos = 0; - } - else - { - byte[] b = new byte[buffer.length * DEFAULT_BUFFER_RESIZE_FACTOR]; - System.arraycopy(buffer, 0, b, 0, buffer.length); - buffer = b; - } - } - - /** - * Extracts buffered data into the provided byte[] array, starting at position bPos, up to a - * maximum of bAvail bytes. Returns how many bytes were actually extracted. - * - * @param b - * byte[] array to extract the buffered data into. - * @param bPos - * position in byte[] array to start extraction at. - * @param bAvail - * amount of bytes we're allowed to extract. We may extract fewer (if fewer are - * available). - * @return The number of bytes successfully extracted into the provided byte[] array. - */ - int readResults(final byte[] b, final int bPos, final int bAvail) - { - if (buffer != null) - { - int len = Math.min(avail(), bAvail); - if (buffer != b) - { - System.arraycopy(buffer, readPos, b, bPos, len); - readPos += len; - if (readPos >= pos) - { - buffer = null; - } - } - else - { - // Re-using the original consumer's output array is only - // allowed for one round. - buffer = null; - } - return len; - } - return eof ? -1 : 0; - } - - /** - * Sets the streaming buffer. This is a small optimization where we try to buffer directly to - * the consumer's output array for one round (if the consumer calls this method first) instead - * of starting our own buffer. - * - * @param out - * byte[] array to buffer directly to. - * @param outPos - * Position to start buffering into. - * @param outAvail - * Amount of bytes available for direct buffering. - */ - void setInitialBuffer(final byte[] out, final int outPos, final int outAvail) - { - // We can re-use consumer's original output array under - // special circumstances, saving on some System.arraycopy(). - if ((out != null) && (out.length == outAvail)) - { - buffer = out; - pos = outPos; - readPos = outPos; - } - } - - /** - *

- * Encodes all of the provided data, starting at inPos, for inAvail bytes. Must be called at - * least twice: once with the data to encode, and once with inAvail set to "-1" to alert encoder - * that EOF has been reached, so flush last remaining bytes (if not multiple of 3). - *

- *

- * Thanks to "commons" project in ws.apache.org for the bitwise operations, and general - * approach. http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/ - *

- * - * @param in - * byte[] array of binary data to base64 encode. - * @param inPos - * Position to start reading data from. - * @param inAvail - * Amount of bytes available from input for encoding. - */ - void encode(final byte[] in, int inPos, final int inAvail) - { - if (eof) - { - return; - } - // inAvail < 0 is how we're informed of EOF in the underlying data we're - // encoding. - if (inAvail < 0) - { - eof = true; - if ((buffer == null) || (buffer.length - pos < encodeSize)) - { - resizeBuffer(); - } - switch (modulus) - { - case 1 : - buffer[pos++] = encodeTable[(x >> 2) & MASK_6BITS]; - buffer[pos++] = encodeTable[(x << 4) & MASK_6BITS]; - // URL-SAFE skips the padding to further reduce size. - if (encodeTable == STANDARD_ENCODE_TABLE) - { - buffer[pos++] = PAD; - buffer[pos++] = PAD; - } - break; - - case 2 : - buffer[pos++] = encodeTable[(x >> 10) & MASK_6BITS]; - buffer[pos++] = encodeTable[(x >> 4) & MASK_6BITS]; - buffer[pos++] = encodeTable[(x << 2) & MASK_6BITS]; - // URL-SAFE skips the padding to further reduce size. - if (encodeTable == STANDARD_ENCODE_TABLE) - { - buffer[pos++] = PAD; - } - break; - } - if ((lineLength > 0) && (pos > 0)) - { - System.arraycopy(lineSeparator, 0, buffer, pos, lineSeparator.length); - pos += lineSeparator.length; - } - } - else - { - for (int i = 0; i < inAvail; i++) - { - if ((buffer == null) || (buffer.length - pos < encodeSize)) - { - resizeBuffer(); - } - modulus = (++modulus) % 3; - int b = in[inPos++]; - if (b < 0) - { - b += 256; - } - x = (x << 8) + b; - if (0 == modulus) - { - buffer[pos++] = encodeTable[(x >> 18) & MASK_6BITS]; - buffer[pos++] = encodeTable[(x >> 12) & MASK_6BITS]; - buffer[pos++] = encodeTable[(x >> 6) & MASK_6BITS]; - buffer[pos++] = encodeTable[x & MASK_6BITS]; - currentLinePos += 4; - if ((lineLength > 0) && (lineLength <= currentLinePos)) - { - System.arraycopy(lineSeparator, 0, buffer, pos, lineSeparator.length); - pos += lineSeparator.length; - currentLinePos = 0; - } - } - } - } - } - - /** - *

- * Decodes all of the provided data, starting at inPos, for inAvail bytes. Should be called at - * least twice: once with the data to decode, and once with inAvail set to "-1" to alert decoder - * that EOF has been reached. The "-1" call is not necessary when decoding, but it doesn't hurt, - * either. - *

- *

- * Ignores all non-base64 characters. This is how chunked (e.g. 76 character) data is handled, - * since CR and LF are silently ignored, but has implications for other bytes, too. This method - * subscribes to the garbage-in, garbage-out philosophy: it will not check the provided data for - * validity. - *

- *

- * Thanks to "commons" project in ws.apache.org for the bitwise operations, and general - * approach. http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/ - *

- * - * @param in - * byte[] array of ascii data to base64 decode. - * @param inPos - * Position to start reading data from. - * @param inAvail - * Amount of bytes available from input for encoding. - */ - void decode(final byte[] in, int inPos, final int inAvail) - { - if (eof) - { - return; - } - if (inAvail < 0) - { - eof = true; - } - for (int i = 0; i < inAvail; i++) - { - if ((buffer == null) || (buffer.length - pos < decodeSize)) - { - resizeBuffer(); - } - byte b = in[inPos++]; - if (b == PAD) - { - // We're done. - eof = true; - break; - } - else - { - if ((b >= 0) && (b < DECODE_TABLE.length)) - { - int result = DECODE_TABLE[b]; - if (result >= 0) - { - modulus = (++modulus) % 4; - x = (x << 6) + result; - if (modulus == 0) - { - buffer[pos++] = (byte)((x >> 16) & MASK_8BITS); - buffer[pos++] = (byte)((x >> 8) & MASK_8BITS); - buffer[pos++] = (byte)(x & MASK_8BITS); - } - } - } - } - } - - // Two forms of EOF as far as base64 decoder is concerned: actual - // EOF (-1) and first time '=' character is encountered in stream. - // This approach makes the '=' padding characters completely optional. - if (eof && (modulus != 0)) - { - x = x << 6; - switch (modulus) - { - case 2 : - x = x << 6; - buffer[pos++] = (byte)((x >> 16) & MASK_8BITS); - break; - case 3 : - buffer[pos++] = (byte)((x >> 16) & MASK_8BITS); - buffer[pos++] = (byte)((x >> 8) & MASK_8BITS); - break; - } - } - } - - /** - * Returns whether or not the octet is in the base 64 alphabet. - * - * @param octet - * The value to test - * @return true if the value is defined in the the base 64 alphabet, - * false otherwise. - * @since 1.4 - */ - public static boolean isBase64(final byte octet) - { - return (octet == PAD) || - ((octet >= 0) && (octet < DECODE_TABLE.length) && (DECODE_TABLE[octet] != -1)); - } - - /** - * Tests a given byte array to see if it contains only valid characters within the Base64 - * alphabet. Currently the method treats whitespace as valid. - * - * @param arrayOctet - * byte array to test - * @return true if all bytes are valid characters in the Base64 alphabet or if the - * byte array is empty; false, otherwise - */ - public static boolean isArrayByteBase64(final byte[] arrayOctet) - { - for (byte octet : arrayOctet) - { - if (!isBase64(octet) && !isWhiteSpace(octet)) - { - return false; - } - } - return true; - } - - /** - * Tests a given byte array to see if it contains only valid characters within the Base64 - * alphabet. - * - * @param arrayOctet - * byte array to test - * @return true if any byte is a valid character in the Base64 alphabet; false - * herwise - */ - private static boolean containsBase64Byte(final byte[] arrayOctet) - { - for (byte octet : arrayOctet) - { - if (isBase64(octet)) - { - return true; - } - } - return false; - } - - /** - * Encodes binary data using the base64 algorithm but does not chunk the output. - * - * @param binaryData - * binary data to encode - * @return byte[] containing Base64 characters in their UTF-8 representation. - */ - public static byte[] encodeBase64(final byte[] binaryData) - { - return encodeBase64(binaryData, false); - } - - /** - * Encodes binary data using the base64 algorithm into 76 character blocks separated by CRLF. - * - * @param binaryData - * binary data to encode - * @return String containing Base64 characters. - * @since 1.4 - */ - public static String encodeBase64String(final byte[] binaryData) - { - return StringUtils.newStringUtf8(encodeBase64(binaryData, true)); - } - - /** - * Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the - * output. The url-safe variation emits - and _ instead of + and / characters. - * - * @param binaryData - * binary data to encode - * @return byte[] containing Base64 characters in their UTF-8 representation. - * @since 1.4 - */ - public static byte[] encodeBase64URLSafe(final byte[] binaryData) - { - return encodeBase64(binaryData, false, true); - } - - /** - * Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the - * output. The url-safe variation emits - and _ instead of + and / characters. - * - * @param binaryData - * binary data to encode - * @return String containing Base64 characters - * @since 1.4 - */ - public static String encodeBase64URLSafeString(final byte[] binaryData) - { - return StringUtils.newStringUtf8(encodeBase64(binaryData, false, true)); - } - - /** - * Encodes binary data using the base64 algorithm and chunks the encoded output into 76 - * character blocks - * - * @param binaryData - * binary data to encode - * @return Base64 characters chunked in 76 character blocks - */ - public static byte[] encodeBase64Chunked(final byte[] binaryData) - { - return encodeBase64(binaryData, true); - } - - /** - * Decodes a String containing containing characters in the Base64 alphabet. - * - * @param pArray - * A String containing Base64 character data - * @return a byte array containing binary data - * @since 1.4 - */ - public byte[] decode(final String pArray) - { - return decode(StringUtils.getBytesUtf8(pArray)); - } - - /** - * Decodes a byte[] containing containing characters in the Base64 alphabet. - * - * @param pArray - * A byte array containing Base64 character data - * @return a byte array containing binary data - */ - public byte[] decode(final byte[] pArray) - { - reset(); - if ((pArray == null) || (pArray.length == 0)) - { - return pArray; - } - long len = Math.max(1, (pArray.length * 3) / 4); - byte[] buf = new byte[(int)len]; - setInitialBuffer(buf, 0, buf.length); - decode(pArray, 0, pArray.length); - decode(pArray, 0, -1); // Notify decoder of EOF. - - // Would be nice to just return buf (like we sometimes do in the encode - // logic), but we have no idea what the line-length was (could even be - // variable). So we cannot determine ahead of time exactly how big an - // array is necessary. Hence the need to construct a 2nd byte array to - // hold the final result: - - byte[] result = new byte[pos]; - readResults(result, 0, result.length); - return result; - } - - /** - * Encodes binary data using the base64 algorithm, optionally chunking the output into 76 - * character blocks. - * - * @param binaryData - * Array containing binary data to encode. - * @param isChunked - * if true this encoder will chunk the base64 output into 76 character - * blocks - * @return Base64-encoded data. - * @throws IllegalArgumentException - * Thrown when the input array needs an output array bigger than - * {@link Integer#MAX_VALUE} - */ - public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked) - { - return encodeBase64(binaryData, isChunked, false); - } - - /** - * Encodes binary data using the base64 algorithm, optionally chunking the output into 76 - * character blocks. - * - * @param binaryData - * Array containing binary data to encode. - * @param isChunked - * if true this encoder will chunk the base64 output into 76 character - * blocks - * @param urlSafe - * if true this encoder will emit - and _ instead of the usual + and / - * characters. - * @return Base64-encoded data. - * @throws IllegalArgumentException - * Thrown when the input array needs an output array bigger than - * {@link Integer#MAX_VALUE} - * @since 1.4 - */ - public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, - final boolean urlSafe) - { - return encodeBase64(binaryData, isChunked, urlSafe, Integer.MAX_VALUE); - } - - /** - * Encodes binary data using the base64 algorithm, optionally chunking the output into 76 - * character blocks. - * - * @param binaryData - * Array containing binary data to encode. - * @param isChunked - * if true this encoder will chunk the base64 output into 76 character - * blocks - * @param urlSafe - * if true this encoder will emit - and _ instead of the usual + and / - * characters. - * @param maxResultSize - * The maximum result size to accept. - * @return Base64-encoded data. - * @throws IllegalArgumentException - * Thrown when the input array needs an output array bigger than maxResultSize - * @since 1.4 - */ - public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, - final boolean urlSafe, final int maxResultSize) - { - if ((binaryData == null) || (binaryData.length == 0)) - { - return binaryData; - } - - long len = getEncodeLength(binaryData, CHUNK_SIZE, CHUNK_SEPARATOR); - if (len > maxResultSize) - { - throw new IllegalArgumentException( - "Input array too big, the output array would be bigger (" + len + - ") than the specified maximum size of " + maxResultSize); - } - - Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe); - return b64.encode(binaryData); - } - - /** - * Decodes a Base64 String into octets - * - * @param base64String - * String containing Base64 data - * @return Array containing decoded data. - * @since 1.4 - */ - public static byte[] decodeBase64(final String base64String) - { - return new Base64().decode(base64String); - } - - /** - * Decodes Base64 data into octets - * - * @param base64Data - * Byte array containing Base64 data - * @return Array containing decoded data. - */ - public static byte[] decodeBase64(final byte[] base64Data) - { - return new Base64().decode(base64Data); - } - - /** - * Checks if a byte value is whitespace or not. - * - * @param byteToCheck - * the byte to check - * @return true if byte is whitespace, false otherwise - */ - private static boolean isWhiteSpace(final byte byteToCheck) - { - switch (byteToCheck) - { - case ' ' : - case '\n' : - case '\r' : - case '\t' : - return true; - default : - return false; - } - } - - // Implementation of the Encoder Interface - - /** - * Encodes a byte[] containing binary data, into a String containing characters in the Base64 - * alphabet. - * - * @param pArray - * a byte array containing binary data - * @return A String containing only Base64 character data - * @since 1.4 - */ - public String encodeToString(final byte[] pArray) - { - return StringUtils.newStringUtf8(encode(pArray)); - } - - /** - * Encodes a byte[] containing binary data, into a byte[] containing characters in the Base64 - * alphabet. - * - * @param pArray - * a byte array containing binary data - * @return A byte array containing only Base64 character data - */ - public byte[] encode(final byte[] pArray) - { - reset(); - if ((pArray == null) || (pArray.length == 0)) - { - return pArray; - } - long len = getEncodeLength(pArray, lineLength, lineSeparator); - byte[] buf = new byte[(int)len]; - setInitialBuffer(buf, 0, buf.length); - encode(pArray, 0, pArray.length); - encode(pArray, 0, -1); // Notify encoder of EOF. - // Encoder might have resized, even though it was unnecessary. - if (buffer != buf) - { - readResults(buf, 0, buf.length); - } - // In URL-SAFE mode we skip the padding characters, so sometimes our - // final length is a bit smaller. - if (isUrlSafe() && (pos < buf.length)) - { - byte[] smallerBuf = new byte[pos]; - System.arraycopy(buf, 0, smallerBuf, 0, pos); - buf = smallerBuf; - } - return buf; - } - - /** - * Pre-calculates the amount of space needed to base64-encode the supplied array. - * - * @param pArray - * byte[] array which will later be encoded - * @param chunkSize - * line-length of the output (<= 0 means no chunking) between each chunkSeparator - * (e.g. CRLF). - * @param chunkSeparator - * the sequence of bytes used to separate chunks of output (e.g. CRLF). - * - * @return amount of space needed to encoded the supplied array. Returns a long since a max-len - * array will require Integer.MAX_VALUE + 33%. - */ - private static long getEncodeLength(final byte[] pArray, int chunkSize, - final byte[] chunkSeparator) - { - // base64 always encodes to multiples of 4. - chunkSize = (chunkSize / 4) * 4; - - long len = (pArray.length * 4) / 3; - long mod = len % 4; - if (mod != 0) - { - len += 4 - mod; - } - if (chunkSize > 0) - { - boolean lenChunksPerfectly = len % chunkSize == 0; - len += (len / chunkSize) * chunkSeparator.length; - if (!lenChunksPerfectly) - { - len += chunkSeparator.length; - } - } - return len; - } - - // Implementation of integer encoding used for crypto - /** - * Decodes a byte64-encoded integer according to crypto standards such as W3C's XML-Signature - * - * @param pArray - * a byte array containing base64 character data - * @return A BigInteger - * @since 1.4 - */ - public static BigInteger decodeInteger(final byte[] pArray) - { - return new BigInteger(1, decodeBase64(pArray)); - } - - /** - * Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature - * - * @param bigInt - * a BigInteger - * @return A byte array containing base64 character data - * @throws NullPointerException - * if null is passed in - * @since 1.4 - */ - public static byte[] encodeInteger(final BigInteger bigInt) - { - if (bigInt == null) - { - throw new NullPointerException("encodeInteger called with null parameter"); - } - return encodeBase64(toIntegerBytes(bigInt), false); - } - - /** - * Returns a byte-array representation of a BigInteger without sign bit. - * - * @param bigInt - * BigInteger to be converted - * @return a byte array representation of the BigInteger parameter - */ - static byte[] toIntegerBytes(final BigInteger bigInt) - { - int bitlen = bigInt.bitLength(); - // round bitlen - bitlen = ((bitlen + 7) >> 3) << 3; - byte[] bigBytes = bigInt.toByteArray(); - - if (((bigInt.bitLength() % 8) != 0) && (((bigInt.bitLength() / 8) + 1) == (bitlen / 8))) - { - return bigBytes; - } - // set up params for copying everything but sign bit - int startSrc = 0; - int len = bigBytes.length; - - // if bigInt is exactly byte-aligned, just skip signbit in copy - if ((bigInt.bitLength() % 8) == 0) - { - startSrc = 1; - len--; - } - int startDst = bitlen / 8 - len; // to pad w/ nulls as per spec - byte[] resizedBytes = new byte[bitlen / 8]; - System.arraycopy(bigBytes, startSrc, resizedBytes, startDst, len); - return resizedBytes; - } - - /** - * Resets this Base64 object to its initial newly constructed state. - */ - private void reset() - { - buffer = null; - pos = 0; - readPos = 0; - currentLinePos = 0; - modulus = 0; - eof = false; - } -} diff --git a/wicket-util/src/test/java/org/apache/wicket/util/crypt/Base64Test.java b/wicket-util/src/test/java/org/apache/wicket/util/crypt/Base64Test.java deleted file mode 100644 index 15c5a046608..00000000000 --- a/wicket-util/src/test/java/org/apache/wicket/util/crypt/Base64Test.java +++ /dev/null @@ -1,275 +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.util.crypt; - -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Random; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * - * @author Juergen Donnerstag - */ -public class Base64Test -{ - /** - * @throws IOException - */ - @Test - public void test_1() throws IOException - { - for (int i = 0; i < 200; i++) - { - byte bytes1[] = new byte[200]; - new Random().nextBytes(bytes1); - - byte[] s = new Base64().encode(bytes1); - - byte[] bytes2 = new Base64().decode(s); - boolean isEqual = ByteBuffer.wrap(bytes1).equals(ByteBuffer.wrap(bytes2)); - assertEquals(true, isEqual); - } - } - - /** - * @throws IOException - */ - @Test - public void test_1a() throws IOException - { - String input = "wicket:interface=:2:entityTree:node:node:0:node:nodeLink::IBehaviorListener"; - - byte[] s = new Base64().encode(input.getBytes()); - - byte[] bytes2 = new Base64().decode(s); - String output = new String(bytes2); - boolean isEqual = input.equals(output); - assertEquals(true, isEqual); - } - - /** - * @throws IOException - */ - @Test - public void test_1b() throws IOException - { - String input = "wicket:interface=:2:entityTree:node:node:0:node:nodeLink::IBehaviorListenerA"; - - byte[] s = new Base64().encode(input.getBytes()); - - byte[] bytes2 = new Base64().decode(s); - String output = new String(bytes2); - boolean isEqual = input.equals(output); - assertEquals(true, isEqual); - } - - /** - * @throws IOException - */ - @Test - public void test_1c() throws IOException - { - String input = "wicket:interface=:2:entityTree:node:node:0:node:nodeLink::IBehaviorListenerAB"; - - byte[] s = new Base64().encode(input.getBytes()); - - byte[] bytes2 = new Base64().decode(s); - String output = new String(bytes2); - boolean isEqual = input.equals(output); - assertEquals(true, isEqual); - } - - /** - * @throws IOException - */ - @Test - public void test_1d() throws IOException - { - String input = "wicket:interface=:2:entityTree:node:node:0:node:nodeLink::IBehaviorListenerABC"; - - byte[] s = new Base64().encode(input.getBytes()); - - byte[] bytes2 = new Base64().decode(s); - String output = new String(bytes2); - boolean isEqual = input.equals(output); - assertEquals(true, isEqual); - } - - /** - * @throws IOException - */ - @Test - public void test_2() throws IOException - { - String input = "This is a text which is longer than 76 character and which contains some none-ascii chars like these: �����?�`="; - String s = new NoCrypt().encryptUrlSafe(input); - - String output = new NoCrypt().decryptUrlSafe(s); - assertEquals(input, output); - } - - /** - * @throws IOException - */ - @Test - public void test_3() throws IOException - { - String input = "wicket:interface=:2:entityTree:node:node:0:node:nodeLink::IBehaviorListener"; - ICrypt crypt = new CachingSunJceCryptFactory("WiCkEt-FRAMEwork").newCrypt(); - String s = crypt.encryptUrlSafe(input); - - String output = crypt.decryptUrlSafe(s); - assertEquals(input, output); - } - - /** - * @throws IOException - */ - @Test - public void test_UrlSafe_1() throws IOException - { - for (int i = 0; i < 200; i++) - { - byte bytes1[] = new byte[200]; - new Random().nextBytes(bytes1); - - byte[] s = new Base64().encode(bytes1); - - byte[] bytes2 = new Base64().decode(s); - boolean isEqual = ByteBuffer.wrap(bytes1).equals(ByteBuffer.wrap(bytes2)); - assertEquals(true, isEqual); - } - } - - /** - * @throws IOException - */ - @Test - public void test_UrlSafe_1a() throws IOException - { - String input = "wicket:interface=:2:entityTree:node:node:0:node:nodeLink::IBehaviorListener"; - - byte[] s = new Base64().encode(input.getBytes()); - - byte[] bytes2 = new Base64().decode(s); - String output = new String(bytes2); - boolean isEqual = input.equals(output); - assertEquals(true, isEqual); - } - - /** - * @throws IOException - */ - @Test - public void test_UrlSafe_1b() throws IOException - { - String input = "wicket:interface=:2:entityTree:node:node:0:node:nodeLink::IBehaviorListenerA"; - - byte[] s = new Base64().encode(input.getBytes()); - - byte[] bytes2 = new Base64().decode(s); - String output = new String(bytes2); - boolean isEqual = input.equals(output); - assertEquals(true, isEqual); - } - - /** - * @throws IOException - */ - @Test - public void test_UrlSafe_1c() throws IOException - { - String input = "wicket:interface=:2:entityTree:node:node:0:node:nodeLink::IBehaviorListenerAB"; - - byte[] s = new Base64().encode(input.getBytes()); - - byte[] bytes2 = new Base64().decode(s); - String output = new String(bytes2); - boolean isEqual = input.equals(output); - assertEquals(true, isEqual); - } - - /** - * @throws IOException - */ - @Test - public void test_UrlSafe_1d() throws IOException - { - String input = "wicket:interface=:2:entityTree:node:node:0:node:nodeLink::IBehaviorListenerABC"; - - byte[] s = new Base64().encode(input.getBytes()); - - byte[] bytes2 = new Base64().decode(s); - String output = new String(bytes2); - boolean isEqual = input.equals(output); - assertEquals(true, isEqual); - } - - /** - * @throws IOException - */ - @Test - public void test_UrlSafe_2() throws IOException - { - String input = "This is a text which is longer than 76 character and which contains some none-ascii chars like these: �����?�`="; - String s = new NoCrypt().encryptUrlSafe(input); - - String output = new NoCrypt().decryptUrlSafe(s); - assertEquals(input, output); - } - - /** - * @throws IOException - */ - @Test - public void test_4() throws IOException - { - String input = "wicket-sep-wicket"; - for (int i = input.length(); i >= 0; i--) - { - String in = input.substring(i); - byte[] s = Base64.encodeBase64URLSafe(in.getBytes()); - - byte[] output = Base64.decodeBase64(s); - String out = new String(output); - assertEquals(in, out); - } - } - - /** - * @throws IOException - */ - @Test - public void test_5() throws IOException - { - ICrypt crypt = new CachingSunJceCryptFactory("WiCkEt-FRAMEwork").newCrypt(); - - String input = "wicket-sep-wicket"; - for (int i = input.length(); i >= 0; i--) - { - String in = input.substring(i); - String encrypted = crypt.encryptUrlSafe(in); - - String output = crypt.decryptUrlSafe(encrypted); - assertEquals(in, output); - } - } -}