velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henn...@apache.org
Subject svn commit: r1029858 - in /velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site: news/ news/macro/ news/model/ news/plugin/ plexus/
Date Mon, 01 Nov 2010 21:50:21 GMT
Author: henning
Date: Mon Nov  1 21:50:20 2010
New Revision: 1029858

URL: http://svn.apache.org/viewvc?rev=1029858&view=rev
Log:
Remove the old plugin code, make the report work without running the plugin first. Simplify
the macro and remove
all the kludges.


Removed:
    velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/NewsManagerUtils.java
    velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/plugin/VelocityNewsPlugin.java
    velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/plexus/
Modified:
    velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/macro/VelocityNewsMacro.java
    velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/model/NewsManager.java
    velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/plugin/VelocityNewsReport.java

Modified: velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/macro/VelocityNewsMacro.java
URL: http://svn.apache.org/viewvc/velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/macro/VelocityNewsMacro.java?rev=1029858&r1=1029857&r2=1029858&view=diff
==============================================================================
--- velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/macro/VelocityNewsMacro.java
(original)
+++ velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/macro/VelocityNewsMacro.java
Mon Nov  1 21:50:20 2010
@@ -88,11 +88,12 @@ public class VelocityNewsMacro extends A
         try
         {
 
-            String newsFileName = (String) request.getParameter("fileName");
-            if (newsFileName == null)
+            String name1 = (String) request.getParameter("fileName");
+            if (name1 == null)
             {
-                newsFileName = DEFAULT_NEWS_FILENAME;
+                name1 = DEFAULT_NEWS_FILENAME;
             }
+            final String newsFileName = name1;
 
             String siteDirectoryString = (String) request.getParameter("siteDirectory");
             if (siteDirectoryString == null)
@@ -101,8 +102,7 @@ public class VelocityNewsMacro extends A
             }
             File siteDirectory = new File(request.getBasedir(), siteDirectoryString);
 
-            final NewsManager newsManager = new NewsManager();
-            newsManager.load(siteDirectory, newsFileName);
+            final NewsModel newsModel = NewsManager.load(siteDirectory, newsFileName);
 
             NewsBlockGenerator newsBlockGenerator = new NewsBlockGenerator(new NewsReport()
             {
@@ -137,23 +137,11 @@ public class VelocityNewsMacro extends A
 
                 public String getOutputName()
                 {
-                    try
-                    {
-                        return (String) newsManager.getNewsFileName();
-                    }
-                    catch (RuntimeException re)
-                    {
-                        throw re;
-                    }
-                    catch (Exception e)
-                    {
-                        throw new IllegalStateException("Could not retrieve page name from
model!");
-                    }
+                    return newsFileName;
                 }
 
             }, Locale.ENGLISH);
 
-            NewsModel newsModel = newsManager.getNewsModel();
 
             for (ListIterator it = VelocityNewsUtils.sortItemsByReverseDate(newsModel.getItems()).listIterator();
it.hasNext()
                     && it.nextIndex() < maxCount;)

Modified: velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/model/NewsManager.java
URL: http://svn.apache.org/viewvc/velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/model/NewsManager.java?rev=1029858&r1=1029857&r2=1029858&view=diff
==============================================================================
--- velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/model/NewsManager.java
(original)
+++ velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/model/NewsManager.java
Mon Nov  1 21:50:20 2010
@@ -24,61 +24,24 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.velocity.site.news.VelocityNewsException;
 import org.apache.velocity.site.news.model.io.xpp3.NewsXpp3Reader;
-import org.codehaus.plexus.logging.LogEnabled;
-import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
-/**
- * This is the container that keeps the news model for us.
- *
- * @plexus.component role="org.apache.velocity.site.news.model.NewsManager"
- */
-public class NewsManager implements LogEnabled
+public abstract class NewsManager
 {
-
-    public static final String ROLE = NewsManager.class.getName();
-
-    public static final String NEWS_FILE_NAME_METHOD = "getNewsFileName";
-
-    public static final String NEWS_SITE_DIRECTORY_METHOD = "getSiteDirectory";
-
-    public static final String NEWS_MODEL_METHOD = "getNewsModel";
-
-    private NewsModel newsModel = null;
-
-    private Logger logger = null;
-
-    private String newsFileName = null;
-
-    private File siteDirectory = null;
-
-    /**
-     * Plexus lifecycle.
-     */
-    public void enableLogging(final Logger logger)
+    public static NewsModel load(final File siteDirectory, final String newsFileName) throws
VelocityNewsException
     {
-        this.logger = logger;
-    }
-
-    public void load(final File siteDirectory, final String newsFileName) throws VelocityNewsException
-    {
-
-        if (StringUtils.isEmpty(newsFileName))
-        {
+        if (StringUtils.isEmpty(newsFileName)) {
             throw new IllegalArgumentException("Filename can not be empty!");
         }
 
-        setNewsFileName(newsFileName);
-        setSiteDirectory(siteDirectory);
-
-        File newsFile = new File(siteDirectory, newsFileName + ".xml");
+        final File newsFile = new File(siteDirectory, newsFileName + ".xml");
 
         if (newsFile.exists() && newsFile.canRead())
         {
-
             FileInputStream fis = null;
             InputStreamReader isr = null;
 
@@ -87,7 +50,7 @@ public class NewsManager implements LogE
                 fis = new FileInputStream(newsFile);
                 isr = new InputStreamReader(fis);
 
-                newsModel = new NewsXpp3Reader().read(isr);
+                return new NewsXpp3Reader().read(isr);
             }
             catch (XmlPullParserException xppe)
             {
@@ -99,61 +62,11 @@ public class NewsManager implements LogE
             }
             finally
             {
-                if (fis != null)
-                {
-                    try
-                    {
-                        fis.close();
-                    }
-                    catch (IOException ioe)
-                    {
-                        logger.error("While closing news stream: ", ioe);
-                    }
-                }
-                if (isr != null)
-                {
-                    try
-                    {
-                        isr.close();
-                    }
-                    catch (IOException ioe)
-                    {
-                        logger.error("While closing news reader: ", ioe);
-                    }
-                }
+                IOUtils.closeQuietly(fis);
+                IOUtils.closeQuietly(isr);
             }
         }
 
-        setNewsModel(newsModel);
-    }
-
-    protected void setNewsFileName(final String newsFileName)
-    {
-        this.newsFileName = newsFileName;
-    }
-
-    public String getNewsFileName()
-    {
-        return newsFileName;
-    }
-
-    public File getSiteDirectory()
-    {
-        return this.siteDirectory;
-    }
-
-    public void setSiteDirectory(final File siteDirectory)
-    {
-        this.siteDirectory = siteDirectory;
-    }
-
-    public NewsModel getNewsModel()
-    {
-        return this.newsModel;
-    }
-
-    protected void setNewsModel(final NewsModel newsModel)
-    {
-        this.newsModel = newsModel;
+        return null;
     }
 }

Modified: velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/plugin/VelocityNewsReport.java
URL: http://svn.apache.org/viewvc/velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/plugin/VelocityNewsReport.java?rev=1029858&r1=1029857&r2=1029858&view=diff
==============================================================================
--- velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/plugin/VelocityNewsReport.java
(original)
+++ velocity/site/tools/velocity-site-news-plugin/src/main/java/org/apache/velocity/site/news/plugin/VelocityNewsReport.java
Mon Nov  1 21:50:20 2010
@@ -53,7 +53,6 @@ import org.codehaus.plexus.personality.p
  */
 public class VelocityNewsReport extends AbstractMavenReport implements NewsReport, NewsFeed,
Contextualizable
 {
-
     /**
      * @component
      * @required
@@ -69,7 +68,7 @@ public class VelocityNewsReport extends 
     private Parser aptParser;
 
     /**
-     * Specifies the directory where the report will be generated
+     * Specifies the directory where the report will be generated.
      *
      * @parameter default-value="${project.reporting.outputDirectory}"
      * @required
@@ -77,7 +76,7 @@ public class VelocityNewsReport extends 
     private File outputDirectory;
 
     /**
-     * The Maven Project Object
+     * The Maven Project Object.
      *
      * @parameter default-value="${project}"
      * @required
@@ -86,11 +85,19 @@ public class VelocityNewsReport extends 
     private MavenProject project;
 
     /**
-     * The component which keeps all the news information for us.
+     * Directory containing the site files.
+     *
+     * @parameter expression="${basedir}/src/site"
+     * @required
+     */
+    private File siteDirectory;
+
+    /**
+     * Configuration of the name of the news file to read.
      *
-     * @component role="org.apache.velocity.site.news.model.NewsManager"
+     * @parameter expression="${newsfile}" default-value="news"
      */
-    private NewsManager newsManager;
+    private String newsFileName;
 
     /**
      * Configuration of the base URL of the feed
@@ -136,7 +143,7 @@ public class VelocityNewsReport extends 
      */
     public String getOutputName()
     {
-        return newsManager.getNewsFileName();
+        return newsFileName;
     }
 
     public ResourceBundle getBundle(final Locale locale)
@@ -175,7 +182,7 @@ public class VelocityNewsReport extends 
 
         try
         {
-            NewsModel newsModel = newsManager.getNewsModel();
+            final NewsModel newsModel = NewsManager.load(siteDirectory, newsFileName);
 
             if (newsModel != null)
             {
@@ -184,6 +191,10 @@ public class VelocityNewsReport extends 
             }
 
         }
+        catch (VelocityNewsException vne)
+        {
+            throw new MavenReportException("While loading news information: ", vne);
+        }
         catch (RuntimeException re)
         {
             throw re;
@@ -196,8 +207,7 @@ public class VelocityNewsReport extends 
 
     private void generateNewsPage(final NewsModel newsModel, final Locale locale) throws
VelocityNewsException
     {
-
-        NewsPageGenerator newsPageGenerator = new NewsPageGenerator(this, locale);
+        final NewsPageGenerator newsPageGenerator = new NewsPageGenerator(this, locale);
 
         newsPageGenerator.openPage();
         newsPageGenerator.displayHeader();
@@ -206,7 +216,7 @@ public class VelocityNewsReport extends 
 
         for (Iterator it = items.iterator(); it.hasNext();)
         {
-            Item newsItem = (Item) it.next();
+            final Item newsItem = (Item) it.next();
             newsPageGenerator.displayItem(newsItem);
         }
 
@@ -215,26 +225,25 @@ public class VelocityNewsReport extends 
 
     private void generateNewsRssFeed(final NewsModel newsModel) throws VelocityNewsException
     {
-        String outputDirectory = getOutputDirectory();
+        final String outputDirectory = getOutputDirectory();
 
         if (outputDirectory == null)
         {
             throw new VelocityNewsException("No output directory specified!");
         }
 
-        NewsFeedGenerator newsFeedGenerator = new NewsFeedGenerator(this);
+        final NewsFeedGenerator newsFeedGenerator = new NewsFeedGenerator(this);
 
         newsFeedGenerator.openFeed();
 
-        List items = VelocityNewsUtils.sortItemsByReverseDate(newsModel.getItems());
+        final List items = VelocityNewsUtils.sortItemsByReverseDate(newsModel.getItems());
 
         for (Iterator it = items.iterator(); it.hasNext();)
         {
-            Item newsItem = (Item) it.next();
+            final Item newsItem = (Item) it.next();
             newsFeedGenerator.publishItem(newsItem);
         }
 
         newsFeedGenerator.publishFeed();
     }
-
 }



Mime
View raw message