Author: scottbw
Date: Wed Jun  8 19:52:56 2011
New Revision: 1133531

URL: http://svn.apache.org/viewvc?rev=1133531&view=rev
Log:
Added deprecation notices for legacy API methods for widgets that have been 
superseded by the W3C and Wave Gadget specs (e.g. widget.sharedDataForKey, 
widget.preferenceForKey) and extended the syntax analyzer to generate warnings 
both for these and for any calls to the (undocumented) Wookie-specific 
extensions such as widget.show, widget.lock.

Modified:
    incubator/wookie/trunk/src/org/apache/wookie/ajaxmodel/IWidgetAPI.java
    
incubator/wookie/trunk/src/org/apache/wookie/ajaxmodel/impl/WidgetAPIImpl.java
    
incubator/wookie/trunk/src/org/apache/wookie/util/WidgetJavascriptSyntaxAnalyzer.java

Modified: incubator/wookie/trunk/src/org/apache/wookie/ajaxmodel/IWidgetAPI.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/ajaxmodel/IWidgetAPI.java?rev=1133531&r1=1133530&r2=1133531&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/ajaxmodel/IWidgetAPI.java 
(original)
+++ incubator/wookie/trunk/src/org/apache/wookie/ajaxmodel/IWidgetAPI.java Wed 
Jun  8 19:52:56 2011
@@ -31,6 +31,10 @@ public interface IWidgetAPI {        
        /**
         * Appends a string to the string contained in the shared data value in 
the DB, obtained
         * from the given "key" 
+        * 
+        * Note that this method is retained only as a workaround for some 
issues in the Wave Gadget API implementation
+        * and is likely to be deprecated in the future.
+        * 
         * @param id_key - the unique instance id key for a widget instance
         * @param key - key for the value to change
         * @param key - the value to change to
@@ -39,15 +43,10 @@ public interface IWidgetAPI {       
        public String appendSharedDataForKey(String id_key, String key, String 
value);  
        
        /**
-        * ? not implemented yet
-        * @param id_key
-        * @param key
-        * @return
-        */
-       public String contextPropertyForKey(String id_key, String key);
-       
-       /**
         * Call to hide a widget instance based on the instance_key
+        * 
+        * Note this is not a part of the W3C standard interface, but a 
Wookie-specific extension
+        * 
         * @param id_key
         * @return
         */
@@ -55,6 +54,9 @@ public interface IWidgetAPI { 
        
        /**
         * Call to lock a widget instance
+        * 
+   * Note this is not a part of the W3C standard interface, but a 
Wookie-specific extension
+   * 
         * @param id_key
         * @return
         */
@@ -89,18 +91,10 @@ public interface IWidgetAPI {       
         * @param key - key for the value to retrieve
         * @return - a string value found in the DB or an error message
         */
+        @Deprecated
        public String preferenceForKey(String id_key, String key);
        
        /**
-        * ? not implemented yet
-        * @param id_key
-        * @param key
-        * @param value
-        * @return
-        */
-       public String setContextPropertyForKey(String id_key, String key, 
String value);
-       
-       /**
         * Sets a string preference value in the DB, obtained
         * from the given "key" 
         * @param id_key - the unique instance id key for a widget instance
@@ -108,6 +102,7 @@ public interface IWidgetAPI {       
         * @param key - the value to change to
         * @return - a string value marking status or an error message
         */
+        @Deprecated
        public String setPreferenceForKey(String id_key, String key, String 
value);
                
        /**
@@ -118,18 +113,10 @@ public interface IWidgetAPI {     
         * @param key - the value to change to
         * @return - a string value marking status or an error message
         */
+       @Deprecated
        public String setSharedDataForKey(String id_key, String key, String 
value);
        
        /**
-        * ? not implemented yet
-        * @param id_key
-        * @param key
-        * @param value
-        * @return
-        */
-       public String setUserPropertyForKey(String id_key, String key, String 
value);
-       
-       /**
         * Returns a string value from the DB, obtained
         * from the given "key". This is a shared data value
         * between widgets using the same data 
@@ -137,10 +124,14 @@ public interface IWidgetAPI {     
         * @param key - key for the value to retrieve
         * @return - a string value found in the DB or an error message
         */
+        @Deprecated
        public String sharedDataForKey(String id_key, String key);      
        
        /**
         * show a widget instance based on the id_key
+        * 
+        * Note this is not a part of the W3C standard interface, but a 
Wookie-specific extension
+        * 
         * @param id_key
         * @return
         */
@@ -148,18 +139,12 @@ public interface IWidgetAPI {     
        
        /**
         * Unlock a widget instance based on the id_key
+        * 
+        * Note this is not a part of the W3C standard interface, but a 
Wookie-specific extension
+        * 
         * @param id_key
         * @return
         */
        public String unlock(String id_key);
        
-       /**
-        * ? not implemented yet
-        * @param id_key
-        * @param key
-        * @param value
-        * @return
-        */
-       public String userPropertyForKey(String id_key, String key);
-       
 }

Modified: 
incubator/wookie/trunk/src/org/apache/wookie/ajaxmodel/impl/WidgetAPIImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/ajaxmodel/impl/WidgetAPIImpl.java?rev=1133531&r1=1133530&r2=1133531&view=diff
==============================================================================
--- 
incubator/wookie/trunk/src/org/apache/wookie/ajaxmodel/impl/WidgetAPIImpl.java 
(original)
+++ 
incubator/wookie/trunk/src/org/apache/wookie/ajaxmodel/impl/WidgetAPIImpl.java 
Wed Jun  8 19:52:56 2011
@@ -145,7 +145,10 @@ public class WidgetAPIImpl implements IW
        /*
         * (non-Javadoc)
         * @see 
org.apache.wookie.ajaxmodel.IWidgetAPI#preferenceForKey(java.lang.String, 
java.lang.String)
+        * 
+        * DEPRECATED: This was replaced by the W3C Storage API
         */
+       @Deprecated
        public String preferenceForKey(String id_key, String key) {
                HttpServletRequest request = 
WebContextFactory.get().getHttpServletRequest();
                Messages localizedMessages = 
LocaleHandler.localizeMessages(request);
@@ -164,7 +167,10 @@ public class WidgetAPIImpl implements IW
        /*
         * (non-Javadoc)
         * @see 
org.apache.wookie.ajaxmodel.IWidgetAPI#sharedDataForKey(java.lang.String, 
java.lang.String)
+        * 
+        * DEPRECATED: This was replaced by the Wave Gadget API
         */
+       @Deprecated
        public String sharedDataForKey(String id_key, String key) {
                HttpServletRequest request = 
WebContextFactory.get().getHttpServletRequest();
                Messages localizedMessages = 
LocaleHandler.localizeMessages(request);
@@ -181,7 +187,12 @@ public class WidgetAPIImpl implements IW
        /*
         * (non-Javadoc)
         * @see 
org.apache.wookie.ajaxmodel.IWidgetAPI#setPreferenceForKey(java.lang.String, 
java.lang.String, java.lang.String)
+        *    
+        * DEPRECATED: This was replaced by the W3C Storage API. We do require 
a method to respond to preference storage events on
+        * the client so this method will be retained unless/until an 
alternative is implemented, but widget authors are strongly discouraged
+        * from invoking this method in client code.
         */
+       @Deprecated
        @SuppressWarnings("static-access")
        public String setPreferenceForKey(String id_key, String key, String 
value) {
                HttpServletRequest request = 
WebContextFactory.get().getHttpServletRequest();
@@ -201,7 +212,10 @@ public class WidgetAPIImpl implements IW
        /*
         * (non-Javadoc)
         * @see 
org.apache.wookie.ajaxmodel.IWidgetAPI#setSharedDataForKey(java.lang.String, 
java.lang.String, java.lang.String)
+        * 
+        * DEPRECATED: This was replaced by the Wave Gadget API
         */
+       @Deprecated
        @SuppressWarnings("static-access")
        public String setSharedDataForKey(String id_key, String key, String 
value) {
                HttpServletRequest request = 
WebContextFactory.get().getHttpServletRequest();
@@ -224,6 +238,8 @@ public class WidgetAPIImpl implements IW
        /*
         * (non-Javadoc)
         * @see 
org.apache.wookie.ajaxmodel.IWidgetAPI#appendSharedDataForKey(java.lang.String, 
java.lang.String, java.lang.String)
+        * 
+        * Note: this method may be deprecated in a future release 
         */
        @SuppressWarnings("static-access")
        public String appendSharedDataForKey(String id_key, String key, String 
value) {
@@ -308,38 +324,6 @@ public class WidgetAPIImpl implements IW
 
        /*
         * (non-Javadoc)
-        * @see 
org.apache.wookie.ajaxmodel.IWidgetAPI#contextPropertyForKey(java.lang.String, 
java.lang.String)
-        */
-       public String contextPropertyForKey(String id_key, String key) {
-               return "Not available"; //$NON-NLS-1$
-       }
-
-       /*
-        * (non-Javadoc)
-        * @see 
org.apache.wookie.ajaxmodel.IWidgetAPI#setContextPropertyForKey(java.lang.String,
 java.lang.String, java.lang.String)
-        */
-       public String setContextPropertyForKey(String id_key, String key, 
String value) {
-               return "Not available"; //$NON-NLS-1$
-       }
-
-       /*
-        * (non-Javadoc)
-        * @see 
org.apache.wookie.ajaxmodel.IWidgetAPI#setUserPropertyForKey(java.lang.String, 
java.lang.String, java.lang.String)
-        */
-       public String setUserPropertyForKey(String id_key, String key, String 
value) {
-               return "Not available"; //$NON-NLS-1$
-       }
-
-       /*
-        * (non-Javadoc)
-        * @see 
org.apache.wookie.ajaxmodel.IWidgetAPI#userPropertyForKey(java.lang.String, 
java.lang.String)
-        */
-       public String userPropertyForKey(String id_key, String key) {
-               return "Not available"; //$NON-NLS-1$
-       }
-
-       /*
-        * (non-Javadoc)
         * @see org.apache.wookie.ajaxmodel.IWidgetAPI#openURL(java.lang.String)
         */
        // DEPRICATED - implemented in local js object instead

Modified: 
incubator/wookie/trunk/src/org/apache/wookie/util/WidgetJavascriptSyntaxAnalyzer.java
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/WidgetJavascriptSyntaxAnalyzer.java?rev=1133531&r1=1133530&r2=1133531&view=diff
==============================================================================
--- 
incubator/wookie/trunk/src/org/apache/wookie/util/WidgetJavascriptSyntaxAnalyzer.java
 (original)
+++ 
incubator/wookie/trunk/src/org/apache/wookie/util/WidgetJavascriptSyntaxAnalyzer.java
 Wed Jun  8 19:52:56 2011
@@ -64,6 +64,8 @@ public class WidgetJavascriptSyntaxAnaly
        public void parse() throws IOException {
                if(_searchFolder != null){
                        parseIEIncompatibilities();
+                       parseDeprecatedMethods();
+                       parseNonstandardMethods();
                        // parse for browser X 
                        // parse for browser Y
                        // other things to parse for....
@@ -71,6 +73,60 @@ public class WidgetJavascriptSyntaxAnaly
        }
        
        /**
+        * Raise a warning for deprecated API calls in the Widget
+        * @throws IOException
+        */
+       private void parseDeprecatedMethods() throws IOException {
+         // Pattern match on the syntax 'widget.preferemces.name=value' - 
including optional quotes & spaces around the value
+    Pattern pattern = 
Pattern.compile("Widget.preferenceForKey|Widget.setPreferenceForKey|Widget.sharedDataForKey|Widget.setSharedDataForKey|Widget.openURL",
 Pattern.CASE_INSENSITIVE);
+    Matcher matcher = pattern.matcher("");
+    // Search .js files, but also any html files
+    Iterator<?> iter =  FileUtils.iterateFiles(_searchFolder, new 
String[]{"js","htm","html"}, true);
+    while(iter.hasNext()) {
+      File file = (File) iter.next();
+      LineNumberReader lineReader = new LineNumberReader(new FileReader(file));
+      String line = null;
+      while ((line = lineReader.readLine()) != null){
+        matcher.reset(line);
+        if (matcher.find()){                
+          String message= "\n(Line " + lineReader.getLineNumber() + ") in file 
" + file;
+          message+= "\n\t "+line+"\n";
+          message+= "This file contains calls to Widget API methods that are 
deprecated and likely to be removed in future releases.\n";                     
        
+          FlashMessage.getInstance().message(formatWebMessage(message));
+          _logger.warn(message);
+        }
+      }
+    }
+       }
+       
+        /**
+   * Raise a warning for API calls in the Widget that use non-standard 
Wookie-specific extensions
+   * @throws IOException
+   */
+  private void parseNonstandardMethods() throws IOException {
+    // Pattern match on the syntax 'widget.preferemces.name=value' - including 
optional quotes & spaces around the value
+    Pattern pattern = 
Pattern.compile("Widget.appendSharedDataForKey|Widget.lock|Widget.unlock|Widget.show|Widget.hide",
 Pattern.CASE_INSENSITIVE);
+    Matcher matcher = pattern.matcher("");
+    // Search .js files, but also any html files
+    Iterator<?> iter =  FileUtils.iterateFiles(_searchFolder, new 
String[]{"js","htm","html"}, true);
+    while(iter.hasNext()) {
+      File file = (File) iter.next();
+      LineNumberReader lineReader = new LineNumberReader(new FileReader(file));
+      String line = null;
+      while ((line = lineReader.readLine()) != null){
+        matcher.reset(line);
+        if (matcher.find()){                
+          String message= "\n(Line " + lineReader.getLineNumber() + ") in file 
" + file;
+          message+= "\n\t "+line+"\n";
+          message+= "This file contains calls to Widget API methods that are 
Wookie-specific extensions to the W3C Widget API, making it less likely the 
widget will work in other environments\n";                             
+          FlashMessage.getInstance().message(formatWebMessage(message));
+          _logger.warn(message);
+        }
+      }
+    }
+  }
+       
+       /**
         * Find occurrences of incompatible setter syntax for Internet explorer
         * i.e. Widget.preferences.foo=bar;
         * 


Reply via email to