Author: shinsuke
Date: Mon Mar 23 03:10:08 2009
New Revision: 757305

URL: http://svn.apache.org/viewvc?rev=757305&view=rev
Log:
updated a parser for a gadgets rss.

Modified:
    
portals/applications/sandbox/widgets/trunk/src/main/java/org/apache/portals/applications/widget/google/builder/QueryBuilderImpl.java
    
portals/applications/sandbox/widgets/trunk/src/main/java/org/apache/portals/applications/widget/google/handler/WidgetListHandlerImpl.java
    
portals/applications/sandbox/widgets/trunk/src/main/webapp/WEB-INF/view/google/edit/index.jsp
    
portals/applications/sandbox/widgets/trunk/src/test/java/org/apache/portals/applications/widget/google/builder/QueryBuilderImplTest.java

Modified: 
portals/applications/sandbox/widgets/trunk/src/main/java/org/apache/portals/applications/widget/google/builder/QueryBuilderImpl.java
URL: 
http://svn.apache.org/viewvc/portals/applications/sandbox/widgets/trunk/src/main/java/org/apache/portals/applications/widget/google/builder/QueryBuilderImpl.java?rev=757305&r1=757304&r2=757305&view=diff
==============================================================================
--- 
portals/applications/sandbox/widgets/trunk/src/main/java/org/apache/portals/applications/widget/google/builder/QueryBuilderImpl.java
 (original)
+++ 
portals/applications/sandbox/widgets/trunk/src/main/java/org/apache/portals/applications/widget/google/builder/QueryBuilderImpl.java
 Mon Mar 23 03:10:08 2009
@@ -58,7 +58,7 @@
         String language = (String) params.get( "language" );
 
         url.append( "&start=" ).append( start );
-        url.append( "&num=" ).append( num );
+        url.append( "&num=" ).append( num + 1 ); // add 1 to check a next page
         if ( StringUtils.isNotBlank( category ) )
         {
             url.append( "&cat=" ).append( category );

Modified: 
portals/applications/sandbox/widgets/trunk/src/main/java/org/apache/portals/applications/widget/google/handler/WidgetListHandlerImpl.java
URL: 
http://svn.apache.org/viewvc/portals/applications/sandbox/widgets/trunk/src/main/java/org/apache/portals/applications/widget/google/handler/WidgetListHandlerImpl.java?rev=757305&r1=757304&r2=757305&view=diff
==============================================================================
--- 
portals/applications/sandbox/widgets/trunk/src/main/java/org/apache/portals/applications/widget/google/handler/WidgetListHandlerImpl.java
 (original)
+++ 
portals/applications/sandbox/widgets/trunk/src/main/java/org/apache/portals/applications/widget/google/handler/WidgetListHandlerImpl.java
 Mon Mar 23 03:10:08 2009
@@ -50,6 +50,21 @@
     public void endDocument()
         throws SAXException
     {
+        if ( widgetList != null )
+        {
+            if ( widgetList.size() >= num )
+            {
+                widgetList.remove( num );
+                widgetList.setExistNextPage( true );
+                widgetList.setAllPageCount( widgetList.getCurrentPageNumber() 
+ 1 );
+            }
+            else
+            {
+                widgetList.setExistNextPage( false );
+                widgetList.setAllPageCount( widgetList.getCurrentPageNumber() 
);
+            }
+        }
+
         stack = null;
     }
 
@@ -104,46 +119,26 @@
             String tagName = stack.get( stack.size() - 1 );
             if ( widget != null )
             {
+                String value = new String( ch, start, length );
+                if ( value != null )
+                {
+                    value = value.trim();
+                }
                 if ( "title".equals( tagName ) )
                 {
-                    widget.setName( widget.getName() + new String( ch, start, 
length ) );
+                    widget.setName( widget.getName() + value );
                 }
                 else if ( "guid".equals( tagName ) )
                 {
-                    widget.setUrl( new String( ch, start, length ) );
+                    widget.setUrl( value );
                 }
                 else if ( "description".equals( tagName ) )
                 {
-                    widget.setDescription( widget.getDescription() + new 
String( ch, start, length ) );
-                }
-                else if ( "ghapi:thumbnail".equals( tagName ) )
-                {
-                    widget.setThumbnail( new String( ch, start, length ) );
+                    widget.setDescription( widget.getDescription() + value );
                 }
-            }
-            else
-            {
-                if ( "ghapi:num_items".equals( tagName ) )
+                else if ( "gadgets:thumbnail".equals( tagName ) )
                 {
-                    int numOfAll = Integer.parseInt( new String( ch, start, 
length ) );
-                    widgetList.setAllRecordCount( numOfAll );
-
-                    if ( start + num < numOfAll )
-                    {
-                        widgetList.setExistNextPage( true );
-                    }
-                    else
-                    {
-                        widgetList.setExistNextPage( false );
-                    }
-
-                    int pageNum = numOfAll / num;
-                    if ( numOfAll % num != 0 )
-                    {
-                        pageNum++;
-                    }
-                    widgetList.setAllPageCount( pageNum );
-
+                    widget.setThumbnail( value );
                 }
             }
         }

Modified: 
portals/applications/sandbox/widgets/trunk/src/main/webapp/WEB-INF/view/google/edit/index.jsp
URL: 
http://svn.apache.org/viewvc/portals/applications/sandbox/widgets/trunk/src/main/webapp/WEB-INF/view/google/edit/index.jsp?rev=757305&r1=757304&r2=757305&view=diff
==============================================================================
--- 
portals/applications/sandbox/widgets/trunk/src/main/webapp/WEB-INF/view/google/edit/index.jsp
 (original)
+++ 
portals/applications/sandbox/widgets/trunk/src/main/webapp/WEB-INF/view/google/edit/index.jsp
 Mon Mar 23 03:10:08 2009
@@ -118,6 +118,3 @@
        </c:if>
        </span>
 </div>
-<div style="padding: 3px;">
-<span>${currentPageNumber}/${allPageCount} (${allRecordCount})</span>
-</div>
\ No newline at end of file

Modified: 
portals/applications/sandbox/widgets/trunk/src/test/java/org/apache/portals/applications/widget/google/builder/QueryBuilderImplTest.java
URL: 
http://svn.apache.org/viewvc/portals/applications/sandbox/widgets/trunk/src/test/java/org/apache/portals/applications/widget/google/builder/QueryBuilderImplTest.java?rev=757305&r1=757304&r2=757305&view=diff
==============================================================================
--- 
portals/applications/sandbox/widgets/trunk/src/test/java/org/apache/portals/applications/widget/google/builder/QueryBuilderImplTest.java
 (original)
+++ 
portals/applications/sandbox/widgets/trunk/src/test/java/org/apache/portals/applications/widget/google/builder/QueryBuilderImplTest.java
 Mon Mar 23 03:10:08 2009
@@ -42,17 +42,17 @@
 
         params.put( "start", 1 );
         params.put( "num", 1 );
-        assertEquals( QueryBuilderImpl.BASE_URL + "&start=1&num=1", 
googleGadgetqueryBuilder.build( params ) );
+        assertEquals( QueryBuilderImpl.BASE_URL + "&start=1&num=2", 
googleGadgetqueryBuilder.build( params ) );
 
         params.put( "category", "news" );
-        assertEquals( QueryBuilderImpl.BASE_URL + "&start=1&num=1&cat=news", 
googleGadgetqueryBuilder.build( params ) );
+        assertEquals( QueryBuilderImpl.BASE_URL + "&start=1&num=2&cat=news", 
googleGadgetqueryBuilder.build( params ) );
 
         params.put( "query", "hoge" );
-        assertEquals( QueryBuilderImpl.BASE_URL + 
"&start=1&num=1&cat=news&q=hoge", googleGadgetqueryBuilder
+        assertEquals( QueryBuilderImpl.BASE_URL + 
"&start=1&num=2&cat=news&q=hoge", googleGadgetqueryBuilder
             .build( params ) );
 
         params.put( "language", "ja" );
-        assertEquals( QueryBuilderImpl.BASE_URL + 
"&start=1&num=1&cat=news&q=hoge&lang=ja", googleGadgetqueryBuilder
+        assertEquals( QueryBuilderImpl.BASE_URL + 
"&start=1&num=2&cat=news&q=hoge&lang=ja", googleGadgetqueryBuilder
             .build( params ) );
     }
 


Reply via email to