martin-g commented on code in PR #1146:
URL: https://github.com/apache/wicket/pull/1146#discussion_r2041446230


##########
wicket-core/src/main/java/org/apache/wicket/core/request/mapper/HashBasedResourceReferenceMapper.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.core.request.mapper;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.request.mapper.ParentPathReferenceRewriter;
+import org.apache.wicket.request.mapper.parameter.IPageParametersEncoder;
+import org.apache.wicket.request.resource.caching.IResourceCachingStrategy;
+
+/**
+ * <p>
+ * Resource reference {@link org.apache.wicket.request.IRequestMapper} that 
encodes class names as hash codes.
+ * This allows hiding the class name from resource references. i.e., instead 
of <em>/wicket/resource/org.xxx.yyy.ZPanel/a.js</em> the
+ * URL will display  <em>/wicket/resource/ddd/a.js</em>, where ddd = 
hash(org.xxx.yyy.ZPanel). This allows globally hiding
+ * class structure of your application (not displaying it via URLs).
+ * </p>
+ *
+ * <p>
+ *     Caveat: we don't take into account has collisions. I.e. to to different 
class names having the same hash code.
+ * </p>
+ * <p>
+ *     Note: if you want to hide the "wicket" part of URL for "xxx" you can do:
+ *        <code>
+ *    protected IMapperContext newMapperContext() {
+ *             return new DefaultMapperContext(this) {
+ *            public String getNamespace() {
+ *                             return "xxx";
+ *            }
+ *        };
+ *    }
+ *    </code>
+ *    on your Application class.
+ * </p>
+ */
+public class HashBasedResourceReferenceMapper extends 
ParentPathReferenceRewriter

Review Comment:
   This class needs unit tests!



##########
wicket-core/src/main/java/org/apache/wicket/core/request/mapper/HashBasedResourceReferenceMapper.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.core.request.mapper;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.request.mapper.ParentPathReferenceRewriter;
+import org.apache.wicket.request.mapper.parameter.IPageParametersEncoder;
+import org.apache.wicket.request.resource.caching.IResourceCachingStrategy;
+
+/**
+ * <p>
+ * Resource reference {@link org.apache.wicket.request.IRequestMapper} that 
encodes class names as hash codes.
+ * This allows hiding the class name from resource references. i.e., instead 
of <em>/wicket/resource/org.xxx.yyy.ZPanel/a.js</em> the
+ * URL will display  <em>/wicket/resource/ddd/a.js</em>, where ddd = 
hash(org.xxx.yyy.ZPanel). This allows globally hiding
+ * class structure of your application (not displaying it via URLs).
+ * </p>
+ *
+ * <p>
+ *     Caveat: we don't take into account has collisions. I.e. to to different 
class names having the same hash code.
+ * </p>
+ * <p>
+ *     Note: if you want to hide the "wicket" part of URL for "xxx" you can do:
+ *        <code>
+ *    protected IMapperContext newMapperContext() {
+ *             return new DefaultMapperContext(this) {
+ *            public String getNamespace() {
+ *                             return "xxx";
+ *            }
+ *        };
+ *    }
+ *    </code>
+ *    on your Application class.
+ * </p>
+ */
+public class HashBasedResourceReferenceMapper extends 
ParentPathReferenceRewriter
+{
+
+       private static class HashBasedBasicResourceReferenceMapper extends 
BasicResourceReferenceMapper
+       {
+
+               private final Map<Long, String> hashMap = new 
ConcurrentHashMap<>();
+
+               private final boolean checkHashCollision;
+
+               /**
+                * Construct.
+                *
+                * @param pageParametersEncoder {@link IPageParametersEncoder}
+                * @param cachingStrategy {@link 
Supplier<IResourceCachingStrategy>}
+                */
+               public 
HashBasedBasicResourceReferenceMapper(IPageParametersEncoder 
pageParametersEncoder, Supplier<? extends IResourceCachingStrategy> 
cachingStrategy, boolean checkHashCollision)
+               {
+                       super(pageParametersEncoder, cachingStrategy);
+            this.checkHashCollision = checkHashCollision;
+        }
+
+               @Override
+               protected Class<?> resolveClass(String name)
+               {
+                       try
+                       {
+                               long hash = Long.parseLong(name);
+                               String className = hashMap.get(hash);
+                               if (className == null)
+                               {
+                                       return super.getPageClass(name);
+                               }
+                               return super.resolveClass(className);
+                       }
+                       catch (NumberFormatException e)
+                       {
+                               return super.getPageClass(name);
+                       }
+               }
+
+               @Override
+               protected String getClassName(Class<?> scope)
+               {
+                       String name = super.getClassName(scope);
+                       long hash = scope.hashCode();

Review Comment:
   The class javadoc says `that encodes class names as hash codes`, i.e. 
`String.hashCode()`, but it is actualy `Class.hashCode()`
   
   Probably you want:
   ```suggestion
                        long hash = name.hashCode();
   ```
   ?!



##########
wicket-core/src/main/java/org/apache/wicket/core/request/mapper/HashBasedResourceReferenceMapper.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.core.request.mapper;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.request.mapper.ParentPathReferenceRewriter;
+import org.apache.wicket.request.mapper.parameter.IPageParametersEncoder;
+import org.apache.wicket.request.resource.caching.IResourceCachingStrategy;
+
+/**
+ * <p>
+ * Resource reference {@link org.apache.wicket.request.IRequestMapper} that 
encodes class names as hash codes.
+ * This allows hiding the class name from resource references. i.e., instead 
of <em>/wicket/resource/org.xxx.yyy.ZPanel/a.js</em> the
+ * URL will display  <em>/wicket/resource/ddd/a.js</em>, where ddd = 
hash(org.xxx.yyy.ZPanel). This allows globally hiding
+ * class structure of your application (not displaying it via URLs).
+ * </p>
+ *
+ * <p>
+ *     Caveat: we don't take into account has collisions. I.e. to to different 
class names having the same hash code.

Review Comment:
   `I.e. to to different class` sounds wrong. Please re-phrase it.



##########
wicket-core/src/main/java/org/apache/wicket/core/request/mapper/HashBasedResourceReferenceMapper.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.core.request.mapper;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.request.mapper.ParentPathReferenceRewriter;
+import org.apache.wicket.request.mapper.parameter.IPageParametersEncoder;
+import org.apache.wicket.request.resource.caching.IResourceCachingStrategy;
+
+/**
+ * <p>
+ * Resource reference {@link org.apache.wicket.request.IRequestMapper} that 
encodes class names as hash codes.
+ * This allows hiding the class name from resource references. i.e., instead 
of <em>/wicket/resource/org.xxx.yyy.ZPanel/a.js</em> the
+ * URL will display  <em>/wicket/resource/ddd/a.js</em>, where ddd = 
hash(org.xxx.yyy.ZPanel). This allows globally hiding
+ * class structure of your application (not displaying it via URLs).
+ * </p>
+ *
+ * <p>
+ *     Caveat: we don't take into account has collisions. I.e. to to different 
class names having the same hash code.

Review Comment:
   ```suggestion
    *     Caveat: we don't take into account hash collisions. I.e. to to 
different class names having the same hash code.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to