Hi Bertrand,

Looks like a usefull approach. You should probably also include the
Version interface, which also extends from Node and might also pose
problems.

Thanks and Regards
Felix

Am Dienstag, den 15.04.2008, 13:05 +0000 schrieb [EMAIL PROTECTED]:
> Author: bdelacretaz
> Date: Tue Apr 15 06:05:02 2008
> New Revision: 648231
> 
> URL: http://svn.apache.org/viewvc?rev=648231&view=rev
> Log:
> SLING-382 - VersionHistoryImpl was incorrectly wrapped as a Node in 
> server-side javascript - contributed by Gert Vanthienen, thanks!
> 
> Added:
>     
> incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/SlingWrapFactoryTest.java
>    (with props)
> Modified:
>     
> incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/SlingWrapFactory.java
> 
> Modified: 
> incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/SlingWrapFactory.java
> URL: 
> http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/SlingWrapFactory.java?rev=648231&r1=648230&r2=648231&view=diff
> ==============================================================================
> --- 
> incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/SlingWrapFactory.java
>  (original)
> +++ 
> incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/SlingWrapFactory.java
>  Tue Apr 15 06:05:02 2008
> @@ -21,6 +21,8 @@
>  import java.util.HashMap;
>  import java.util.Map;
>  
> +import javax.jcr.version.VersionHistory;
> +
>  import org.mozilla.javascript.Context;
>  import org.mozilla.javascript.Scriptable;
>  import org.mozilla.javascript.WrapFactory;
> @@ -30,6 +32,8 @@
>  public class SlingWrapFactory extends WrapFactory {
>  
>      public static final SlingWrapFactory INSTANCE = new SlingWrapFactory();
> +    
> +    private static final Class<?>[] EXCLUDED_CLASSES = 
> {VersionHistory.class};
>  
>      /** default log */
>      private final Logger log = LoggerFactory.getLogger(getClass());
> @@ -73,7 +77,7 @@
>      }
>  
>      private String getHostObjectName(Class<?> javaClass) {
> -        if(javaClass==null) {
> +        if(javaClass==null || isExcluded(javaClass)) {
>              return null;
>          }
>          String hostObjectName = wrappers.get(javaClass);
> @@ -90,6 +94,18 @@
>          }
>  
>          return hostObjectName;
> +    }
> +
> +    /*
> +     * Is this class in the excluded class  list?
> +     */
> +    private boolean isExcluded(Class<?> javaClass) {
> +        for (Class<?> type : EXCLUDED_CLASSES) {
> +            if (type.isAssignableFrom(javaClass)) {
> +                return true;
> +            }
> +        }
> +        return false;
>      }
>  
>      public void registerWrapper(Class<?> javaClass, String hostObjectName) {
> 
> Added: 
> incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/SlingWrapFactoryTest.java
> URL: 
> http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/SlingWrapFactoryTest.java?rev=648231&view=auto
> ==============================================================================
> --- 
> incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/SlingWrapFactoryTest.java
>  (added)
> +++ 
> incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/SlingWrapFactoryTest.java
>  Tue Apr 15 06:05:02 2008
> @@ -0,0 +1,49 @@
> +/*
> + * 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.sling.scripting.wrapper;
> +
> +import javax.jcr.Node;
> +
> +import org.apache.sling.scripting.RepositoryScriptingTestBase;
> +import org.apache.sling.scripting.ScriptEngineHelper;
> +
> +public class SlingWrapFactoryTest extends RepositoryScriptingTestBase {
> +
> +    private Node node;
> +
> +    @Override
> +    protected void setUp() throws Exception {
> +        super.setUp();
> +
> +        node = getNewNode();
> +        node.addMixin("mix:versionable");
> +        getSession().save();
> +
> +        node.setProperty("Modified", "Just making sure we have a second 
> version");
> +        getSession().save();
> +    }
> +
> +    public void testGetVersionHistoryNotWrapped() throws Exception {
> +        final ScriptEngineHelper.Data data = new ScriptEngineHelper.Data();
> +        data.put("node", node);
> +        Object result = 
> script.eval("node.getVersionHistory().getAllVersions()", data);
> +        assertNotNull(result);
> +    }
> +
> +}
> 
> Propchange: 
> incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/SlingWrapFactoryTest.java
> ------------------------------------------------------------------------------
>     svn:eol-style = native
> 
> Propchange: 
> incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/SlingWrapFactoryTest.java
> ------------------------------------------------------------------------------
>     svn:keywords = Author Date Id Revision Rev URL
> 
> 

Reply via email to