Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote-tracking branch 'origin/master'

  • Loading branch information...
commit 6f8e3f02b72292412ebca739c6bb5e3b4dc44c3b 2 parents d3df4c5 + 5284dcc
@jesse-gallagher jesse-gallagher authored
Showing with 847 additions and 22 deletions.
  1. BIN  DOTSFeedMonster/_builds/org.openntf.news.monster_0.0.1.201212091335.jar
  2. +11 −0 DOTSFeedMonster/org.openntf.news.monster/.classpath
  3. +28 −0 DOTSFeedMonster/org.openntf.news.monster/.project
  4. +8 −0 DOTSFeedMonster/org.openntf.news.monster/.settings/org.eclipse.jdt.core.prefs
  5. +4 −0 DOTSFeedMonster/org.openntf.news.monster/.settings/org.eclipse.pde.core.prefs
  6. +16 −0 DOTSFeedMonster/org.openntf.news.monster/META-INF/MANIFEST.MF
  7. +26 −0 DOTSFeedMonster/org.openntf.news.monster/build.properties
  8. BIN  DOTSFeedMonster/org.openntf.news.monster/lib/commons-logging-api-1.1.1.jar
  9. BIN  DOTSFeedMonster/org.openntf.news.monster/lib/jdom.jar
  10. BIN  DOTSFeedMonster/org.openntf.news.monster/lib/jericho-html-3.1.jar
  11. BIN  DOTSFeedMonster/org.openntf.news.monster/lib/rome-1.0.jar
  12. +13 −0 DOTSFeedMonster/org.openntf.news.monster/plugin.xml
  13. +171 −0 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/Story.java
  14. +38 −0 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/dots/activator/Activator.java
  15. +64 −0 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/monster/DOTSFeedMonster.java
  16. +149 −0 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/monster/FeedMonster.java
  17. +182 −0 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/monster/RSSReader.java
  18. +31 −0 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/shared/Constants.java
  19. +14 −0 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/shared/MonsterException.java
  20. +14 −0 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/shared/StoryReaderException.java
  21. +49 −0 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/shared/Utilities.java
  22. +7 −0 DOTSFeedMonster/readme.txt
  23. +1 −1  disk-collaborationtoday/.settings/org.eclipse.core.resources.prefs
  24. +2 −2 disk-collaborationtoday/Code/Java/org/openntf/news/http/core/NewsEntriesJson.java
  25. +9 −9 disk-collaborationtoday/CustomControls/leftColumnLineItems.xsp.metadata
  26. +10 −10 disk-collaborationtoday/XPages/author.xsp.metadata
View
BIN  DOTSFeedMonster/_builds/org.openntf.news.monster_0.0.1.201212091335.jar
Binary file not shown
View
11 DOTSFeedMonster/org.openntf.news.monster/.classpath
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry exported="true" kind="lib" path="lib/rome-1.0.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/jdom.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/commons-logging-api-1.1.1.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/jericho-html-3.1.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
28 DOTSFeedMonster/org.openntf.news.monster/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.openntf.news.monster</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
8 DOTSFeedMonster/org.openntf.news.monster/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Sun Dec 09 11:05:27 VET 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
View
4 DOTSFeedMonster/org.openntf.news.monster/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,4 @@
+#Mon Feb 08 11:29:33 EST 2010
+eclipse.preferences.version=1
+pluginProject.extensions=true
+resolve.requirebundle=false
View
16 DOTSFeedMonster/org.openntf.news.monster/META-INF/MANIFEST.MF
@@ -0,0 +1,16 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.openntf.news.monster;singleton:=true
+Bundle-Version: 0.0.1.qualifier
+Bundle-Activator: org.openntf.news.dots.activator.Activator
+Bundle-Vendor: OpenNTF
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6,
+ J2SE-1.5
+Bundle-ActivationPolicy: lazy
+Require-Bundle: com.ibm.dots
+Bundle-ClassPath: lib/rome-1.0.jar,
+ .,
+ lib/jdom.jar,
+ lib/commons-logging-api-1.1.1.jar,
+ lib/jericho-html-3.1.jar
+
View
26 DOTSFeedMonster/org.openntf.news.monster/build.properties
@@ -0,0 +1,26 @@
+# ***********************************************************************
+# © Copyright IBM Corp. 2009,2010
+#
+# Licensed 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.
+# *************************************************************************
+
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ lib/rome-1.0.jar,\
+ lib/jdom.jar,\
+ lib/jericho-html-3.1.jar,\
+ lib/commons-logging-api-1.1.1.jar
+jre.compilation.profile = J2SE-1.5
View
BIN  DOTSFeedMonster/org.openntf.news.monster/lib/commons-logging-api-1.1.1.jar
Binary file not shown
View
BIN  DOTSFeedMonster/org.openntf.news.monster/lib/jdom.jar
Binary file not shown
View
BIN  DOTSFeedMonster/org.openntf.news.monster/lib/jericho-html-3.1.jar
Binary file not shown
View
BIN  DOTSFeedMonster/org.openntf.news.monster/lib/rome-1.0.jar
Binary file not shown
View
13 DOTSFeedMonster/org.openntf.news.monster/plugin.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="com.ibm.dots.task">
+ <task id="org.openntf.news.readFeeds"
+ description=""
+ class="org.openntf.news.monster.DOTSFeedMonster"
+ runOnStart="false">
+ <!--<run every="30" unit="second" />-->
+ </task>
+ </extension>
+</plugin>
View
171 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/Story.java
@@ -0,0 +1,171 @@
+package org.openntf.news;
+
+import java.io.IOException;
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TimeZone;
+
+import lotus.domino.Database;
+import lotus.domino.Document;
+import lotus.domino.NotesException;
+import lotus.domino.Session;
+
+import org.openntf.news.shared.Constants;
+import org.openntf.news.shared.StoryReaderException;
+import org.openntf.news.shared.Utilities;
+
+// Story element for news items
+public class Story {
+
+ //From Entry
+ private String id;
+ private String link;
+ private Calendar date;
+ private String title;
+ private String abstractContent;
+ private String fullContent;
+
+ //Set on Save
+ private Calendar creationDate;
+
+ private HashMap<String,Object> additionalFields;
+ private boolean redirectEnabled=false;
+
+ public Story() {
+ additionalFields=new HashMap<String,Object>();
+
+ // setting all things GMT to prevent time zone inconsistencies...
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ }
+
+ public void addField(String name, Object value) {
+ additionalFields.put(name, value);
+ }
+
+ public Object getField(String name) {
+ return additionalFields.get(name);
+ }
+
+ public void addFields(Map<String,Object> values) {
+ additionalFields.putAll(values);
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getLink() {
+ return link;
+ }
+
+
+ public void setLink(String link) {
+ this.link = link;
+ }
+
+
+ public Calendar getDate() {
+ return date;
+ }
+
+ public void setDate(Calendar date) {
+ this.date = date;
+ }
+
+
+ public String getTitle() {
+ return title;
+ }
+
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+
+ public String getAbstractContent() {
+ return abstractContent;
+ }
+
+ public void setAbstractContent(String abstractContent) {
+ this.abstractContent = abstractContent;
+ }
+
+ public String getFullContent() {
+ return fullContent;
+ }
+
+ public void setFullContent(String fullContent) {
+ this.fullContent = fullContent;
+ }
+
+ public Calendar getCreationDate() {
+ return creationDate;
+ }
+
+ public void setCreationDate(Calendar creationDate) {
+ this.creationDate = creationDate;
+ }
+
+ public String toString() {
+ DateFormat sdf = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
+ return getTitle() + " (" + getLink() + " - " + sdf.format(getDate().getTime()) + ")";
+ }
+
+ public boolean saveToDatabase(Database db) throws StoryReaderException {
+ try {
+ setCreationDate(Calendar.getInstance());
+
+ Session session=db.getParent();
+
+ Document storyDoc = db.createDocument();
+ storyDoc.replaceItemValue("Form", "News");
+ storyDoc.replaceItemValue("NID", Utilities.generateUniqueId());
+
+ if(isRedirectEnabled()) {
+ try {
+ setLink(Utilities.followRedirect(getLink()));
+ } catch (IOException e) {
+ throw new StoryReaderException(Constants.EXCEPTION_COMM_ERROR + ": "+getLink());
+ }
+ }
+
+ storyDoc.replaceItemValue("NLink", getLink());
+
+ storyDoc.replaceItemValue("NCreationDate", session.createDateTime(getCreationDate()));
+ storyDoc.replaceItemValue("NPublicationDate", session.createDateTime(getDate()));
+ storyDoc.replaceItemValue("NTitle", getTitle());
+ storyDoc.replaceItemValue("NAbstract", getAbstractContent());
+ storyDoc.replaceItemValue("NContent", getFullContent());
+
+ for (Map.Entry<String, Object> entry : additionalFields.entrySet()) {
+ storyDoc.replaceItemValue(entry.getKey(), entry.getValue());
+ }
+
+ storyDoc.save();
+ storyDoc.recycle();
+
+
+ return true;
+ } catch (NotesException e) {
+ throw new StoryReaderException(Constants.EXCEPTION_SAVE_STORY + ": "+ e.getMessage());
+ }
+
+ }
+
+ public boolean isRedirectEnabled() {
+ return redirectEnabled;
+ }
+
+ public void setRedirectEnabled(boolean redirectEnabled) {
+ this.redirectEnabled = redirectEnabled;
+ }
+
+
+}
View
38 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/dots/activator/Activator.java
@@ -0,0 +1,38 @@
+/*
+ * © Copyright IBM Corp. 2009,2010
+ *
+ * Licensed 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.openntf.news.dots.activator;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ }
+
+}
View
64 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/monster/DOTSFeedMonster.java
@@ -0,0 +1,64 @@
+package org.openntf.news.monster;
+
+import lotus.domino.Database;
+import lotus.domino.NotesException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.openntf.news.shared.Constants;
+import org.openntf.news.shared.MonsterException;
+import org.openntf.news.shared.Utilities;
+
+import com.ibm.dots.task.AbstractServerTask;
+import com.ibm.dots.task.RunWhen;
+
+
+public class DOTSFeedMonster extends AbstractServerTask {
+
+ Database db;
+
+ public DOTSFeedMonster() {
+ }
+
+ /* (non-Javadoc)
+ * @see com.ibm.dots.task.IServerTaskRunnable#dispose()
+ */
+ public void dispose() throws NotesException {
+ if(db!=null) db.recycle();
+ }
+
+ /* (non-Javadoc)
+ * This is version 1
+ */
+ public void run(RunWhen runWhen, String[] args, IProgressMonitor monitor) throws NotesException {
+
+ monitor.beginTask(Constants.APPLICATION_NAME + ": " + Constants.TASK_ID, 0 );
+ logMessage(Constants.APPLICATION_NAME + ": " + Constants.TASK_ID + " started");
+ if(Constants.memory_dump) logMessage("Launching: " + Utilities.getMemoryStatus());
+
+ String dbname=getSession().getEnvironmentString("Monster_TargetDB", true);
+
+ if(null == dbname || dbname.equals("")) {
+ dbname=Constants.DATABASE_PATH_AND_NAME;
+ }
+
+ logMessage(Constants.APPLICATION_NAME + ": Using database '" + dbname + "'");
+
+ db = getSession().getDatabase("", dbname );
+
+ try {
+ if(!db.isOpen()) {
+ throw new MonsterException(Constants.EXCEPTION_NEWSDB_ERROR + ": "+dbname);
+ }
+
+ new FeedMonster(db).ReadFeeds();
+ } catch(MonsterException e) {
+ if(Constants.debug) e.printStackTrace();
+ logMessage(e.getMessage());
+ }
+
+ logMessage(Constants.APPLICATION_NAME + ": " + Constants.TASK_ID + " finished");
+ if(Constants.memory_dump) logMessage("Run Success: " + Utilities.getMemoryStatus());
+ monitor.worked( 1 );
+
+ }
+}
View
149 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/monster/FeedMonster.java
@@ -0,0 +1,149 @@
+package org.openntf.news.monster;
+
+import java.util.Calendar;
+import java.util.Date;
+
+import lotus.domino.Database;
+import lotus.domino.DateTime;
+import lotus.domino.Document;
+import lotus.domino.NotesException;
+import lotus.domino.Session;
+import lotus.domino.View;
+import lotus.domino.ViewEntry;
+import lotus.domino.ViewNavigator;
+import lotus.domino.Item;
+
+import org.openntf.news.Story;
+import org.openntf.news.shared.Constants;
+import org.openntf.news.shared.MonsterException;
+import org.openntf.news.shared.StoryReaderException;
+
+public final class FeedMonster {
+
+ private Session session;
+ private Database newsDB;
+ private View viewCheck;
+ private View viewBlogsAll;
+ private ViewNavigator viewNavigator;
+ private DateTime now;
+
+ public FeedMonster(Database _newsDB) throws NotesException {
+ newsDB = _newsDB;
+ }
+
+ public final void ReadFeeds() throws MonsterException, NotesException {
+
+ try {
+ try {
+ if (!newsDB.isOpen()) {
+ newsDB.open();
+ }
+ session=newsDB.getParent();
+ } catch(NotesException e) {
+ if(Constants.debug) e.printStackTrace();
+ throw new MonsterException(Constants.EXCEPTION_NEWSDB_ERROR + ": "+ e.getMessage());
+ }
+ now=session.createDateTime(Calendar.getInstance());
+
+ viewCheck = newsDB.getView(Constants.VIEW_NEWS_CHECK);
+ viewBlogsAll = newsDB.getView(Constants.VIEW_BLOGS_ALL);
+ viewNavigator = viewBlogsAll.createViewNav();
+ ViewEntry tmpEntry;
+ ViewEntry entry = viewNavigator.getFirst();
+ while (entry != null) {
+ Date startTime=new Date();
+ int storyCount=0;
+
+ Document blogDocument = entry.getDocument();
+ String blogId=blogDocument.getItemValueString("BID");
+
+ try {
+ blogDocument.replaceItemValue("BLastTry", now);
+
+ DateTime lastStoryDate=null;
+
+ Item lastSuccess=blogDocument.getFirstItem("BLastSuccess");
+
+ if(null != lastSuccess && lastSuccess.getType()==Item.DATETIMES) {
+ lastStoryDate=lastSuccess.getDateTimeValue();
+ }
+
+ RSSReader rss=new RSSReader(blogDocument.getItemValueString("BFeed"));
+
+ // Setting default values
+ rss.addStoryField("BID", blogId); //blogId
+ rss.addStoryField("PID", blogDocument.getItemValueString("PID")); //authorId
+ rss.addStoryField("NState", "queued"); //State
+
+ if(blogDocument.getItemValueString("BFeedHasRedirection").equals("1")) {
+ rss.setRedirectEnabled(true);
+ }
+
+ rss.loadFeed();
+
+ blogDocument.replaceItemValue("BLastError", "");
+ blogDocument.replaceItemValue("BLastErrorMessage", "");
+
+ for(int i=0; i<rss.getSize(); i++) {
+ Story s=rss.getNthStory(i);
+ DateTime storyDate=session.createDateTime(s.getDate());
+ boolean saveToDB=lastStoryDate == null || storyDate.timeDifference(lastStoryDate) > 0;
+ storyDate.recycle();
+
+ if(saveToDB) {
+ storyCount++;
+ s.saveToDatabase(newsDB);
+ }
+ }
+
+ if(storyCount>0) {
+ blogDocument.replaceItemValue("BLastSuccess", now);
+ }
+ blogDocument.save();
+
+ } catch (NotesException e) {
+ if(Constants.debug) e.printStackTrace();
+ System.out.println(Constants.EXCEPTION_BLOG_SAVE + " : " + e.getMessage());
+ } catch(StoryReaderException sre) {
+ System.out.println("Error reading RSSEntry: ["+blogDocument.getItemValueString("BID")+"]: "+sre.getMessage());
+ try {
+ blogDocument.replaceItemValue("BLastError", now);
+ blogDocument.replaceItemValue("BLastErrorMessage", sre.getMessage());
+ blogDocument.save();
+ } catch (NotesException e) {
+ if(Constants.debug) e.printStackTrace();
+ System.out.println(Constants.EXCEPTION_BLOG_SAVE + " : " + e.getMessage());
+ }
+ }
+
+ tmpEntry = viewNavigator.getNext();
+ entry.recycle();
+ blogDocument.recycle();
+ entry = tmpEntry;
+
+ long duration=((new Date().getTime()) - startTime.getTime())/1000;
+ System.out.println("Fetched " + String.valueOf(storyCount) + " stories from '" + blogId + "' in " + String.valueOf(duration) + " secs...");
+ }
+ }
+ catch (Exception e) {
+ if(Constants.debug) e.printStackTrace();
+ throw new MonsterException(Constants.EXCEPTION_NEWSDB_FEEDS + ": "+ e.getMessage());
+ }
+ finally {
+ if (viewNavigator != null) {
+ viewNavigator.recycle();
+ }
+ if (viewBlogsAll != null) {
+ viewBlogsAll.recycle();
+ }
+ if (viewCheck != null) {
+ viewCheck.recycle();
+ }
+ if(now!=null) {
+ now.recycle();
+ }
+ }
+
+ }
+
+}
View
182 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/monster/RSSReader.java
@@ -0,0 +1,182 @@
+package org.openntf.news.monster;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import net.htmlparser.jericho.Renderer;
+import net.htmlparser.jericho.Source;
+
+import org.openntf.news.Story;
+import org.openntf.news.shared.Constants;
+import org.openntf.news.shared.StoryReaderException;
+
+import com.sun.syndication.feed.synd.SyndContent;
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.io.FeedException;
+import com.sun.syndication.io.SyndFeedInput;
+import com.sun.syndication.io.XmlReader;
+
+public class RSSReader {
+
+ private String feedUrl;
+
+ private HashMap<String,Object> storyFields;
+
+ private int size=0;
+ private boolean loaded=false;
+ private SyndFeed feed;
+ private boolean redirectEnabled=false;
+
+ public RSSReader(String _feedUrl) throws StoryReaderException {
+
+ this.feedUrl=_feedUrl;
+ this.storyFields=new HashMap<String,Object>();
+
+ // Initialize Jericho
+// Config.LoggerProvider=LoggerProvider.DISABLED;
+ }
+
+ public void addStoryField(String name, Object value) {
+ storyFields.put(name, value);
+ }
+
+ public Object getStoryField(String name) {
+ return storyFields.get(name);
+ }
+
+ public void addStoryFields(Map<String,Object> values) {
+ storyFields.putAll(values);
+ }
+
+ // TODO: should add error trapping if there is no call loadFeed before getting stories.
+ public void loadFeed() throws StoryReaderException {
+ try {
+ URL url = new URL(feedUrl);
+
+ HttpURLConnection httpSource = (HttpURLConnection)url.openConnection();
+ SyndFeedInput input = new SyndFeedInput();
+ XmlReader reader = new XmlReader(httpSource);
+
+ this.feed = input.build(reader);
+ this.size = feed.getEntries().size();
+ setLoaded(true);
+
+ } catch (MalformedURLException e) {
+ if(Constants.debug) e.printStackTrace();
+ throw new StoryReaderException(Constants.EXCEPTION_INVALID_URL + ": "+ e.getMessage());
+ } catch (IOException e) {
+ if(Constants.debug) e.printStackTrace();
+ throw new StoryReaderException(Constants.EXCEPTION_COMM_ERROR + ": "+ e.getMessage());
+ } catch (IllegalArgumentException e) {
+ if(Constants.debug) e.printStackTrace();
+ throw new StoryReaderException(Constants.EXCEPTION_FEED_ERROR + ": "+ e.getMessage());
+ } catch (FeedException e) {
+ if(Constants.debug) e.printStackTrace();
+ throw new StoryReaderException(Constants.EXCEPTION_FEED_ERROR + ": "+ e.getMessage());
+ }
+ }
+
+ public Story getNthStory(int index) {
+
+ if(! isLoaded()) {
+ throw new IllegalStateException("RSSReader has not been loaded yet");
+ }
+
+ if(index < 0 || index >=size) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ SyndEntry entry=(SyndEntry)feed.getEntries().get(index);
+ return entryToStory(entry);
+
+ }
+
+ private Story entryToStory(SyndEntry entry) {
+ Story story=new Story();
+
+ story.addFields(storyFields);
+
+ story.setLink(entry.getLink());
+ story.setRedirectEnabled(isRedirectEnabled());
+
+ Calendar date = Calendar.getInstance();
+
+ if (entry.getPublishedDate()!=null) {
+ date.setTime(entry.getPublishedDate());
+ }
+ else if (entry.getUpdatedDate()!=null) {
+ date.setTime(entry.getUpdatedDate());
+ }
+
+ story.setDate(date);
+ story.setTitle(entry.getTitle());
+
+ String content=getFeedContent(entry);
+ String abstractContent=cleanHTML(content);
+
+ if(abstractContent.length() >= Constants.STORY_ABSTRACT_MAXLENGTH) {
+ abstractContent = abstractContent.substring(0, Constants.STORY_ABSTRACT_MAXLENGTH - 1) + "[...]";
+ }
+
+ story.setAbstractContent(abstractContent);
+// story.setFullContent(content); // Currently we won't have full content due to possible legal implications.
+
+ return story;
+ }
+
+ @SuppressWarnings("unchecked")
+ private String getFeedContent(SyndEntry entry) {
+ StringBuffer output = new StringBuffer();
+ if(entry.getDescription() == null) {
+ Iterator<SyndContent> contentIterator = entry.getContents().iterator();
+
+ while (contentIterator.hasNext()) {
+ SyndContent content = contentIterator.next();
+ output.append(content.getValue());
+ }
+ }
+ else {
+ SyndContent content = entry.getDescription();
+ output.append(content.getValue());
+ }
+ return output.toString();
+ }
+
+ private String cleanHTML(String input) {
+ Renderer renderer=new Source(input).getRenderer();
+
+ // We don't want it to be wrapped
+ renderer.setMaxLineLength(Integer.MAX_VALUE);
+ renderer.setIncludeHyperlinkURLs(false);
+
+ return renderer.toString();
+ }
+
+ public int getSize() {
+ return size;
+ }
+
+ public boolean isLoaded() {
+ return loaded;
+ }
+
+ private void setLoaded(boolean loaded) {
+ this.loaded = loaded;
+ }
+
+ private boolean isRedirectEnabled() {
+ return redirectEnabled;
+ }
+
+ public void setRedirectEnabled(boolean redirectEnabled) {
+ this.redirectEnabled = redirectEnabled;
+ }
+
+}
View
31 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/shared/Constants.java
@@ -0,0 +1,31 @@
+package org.openntf.news.shared;
+
+public final class Constants {
+ public static final String DATABASE_PATH_AND_NAME = "openntf/news1.nsf";
+ public static final String APPLICATION_NAME = "News";
+ public static final String TASK_ID = "org.openntf.news.readFeeds";
+
+ public static final int STORY_ABSTRACT_MAXLENGTH=400;
+
+ public static final int SO_CLIENT_ID = 636;
+ public static final String SO_CLIENT_SECRET = "UJJvYYZ)Fdf1o7IMwOLa4Q((";
+ public static final String SO_APP_KEY = "WyYv8IMhY28eyZdIDcbZfw((";
+
+
+ public static String EXCEPTION_NO_BLOG_DOCUMENT = "No blog document";
+ public static String EXCEPTION_NO_SESSION = "Unable to obtain Notes Session";
+ public static String EXCEPTION_BLOG_SAVE = "Blog document cannot be updated";
+ public static String EXCEPTION_INVALID_URL = "Invalid URL specified";
+ public static String EXCEPTION_INVALID_CONFIG = "Feed document cannot be read";
+ public static String EXCEPTION_COMM_ERROR = "Communication Error";
+ public static String EXCEPTION_FEED_ERROR = "Feed cannot be read";
+ public static String EXCEPTION_SAVE_STORY = "Story cannot be saved";
+ public static String EXCEPTION_NEWSDB_ERROR = "News Database cannot be opened";
+ public static String EXCEPTION_NEWSDB_FEEDS = "Error in Feeds";
+
+ public static String VIEW_BLOGS_ALL = "BlogsAll";
+ public static String VIEW_NEWS_CHECK = "NewsByIdDate";
+
+ public static boolean debug=false;
+ public static boolean memory_dump=true;
+}
View
14 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/shared/MonsterException.java
@@ -0,0 +1,14 @@
+package org.openntf.news.shared;
+
+public class MonsterException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public MonsterException(String message) {
+ super(message);
+ }
+
+}
View
14 ...eedMonster/org.openntf.news.monster/src/org/openntf/news/shared/StoryReaderException.java
@@ -0,0 +1,14 @@
+package org.openntf.news.shared;
+
+public class StoryReaderException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public StoryReaderException(String message) {
+ super(message);
+ }
+
+}
View
49 DOTSFeedMonster/org.openntf.news.monster/src/org/openntf/news/shared/Utilities.java
@@ -0,0 +1,49 @@
+package org.openntf.news.shared;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.text.NumberFormat;
+import java.util.Locale;
+import java.util.Random;
+
+public final class Utilities {
+
+ private static String UNIQUEID_LETTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ private static int UNIQUEID_DEFAULTSIZE = 6;
+
+ public static String generateUniqueId() {
+ StringBuilder sb = new StringBuilder(UNIQUEID_DEFAULTSIZE);
+ Random random = new Random();
+ for (int i=0; i < UNIQUEID_DEFAULTSIZE; i++) {
+ sb.append(UNIQUEID_LETTERS.charAt(random.nextInt(UNIQUEID_LETTERS.length())));
+ }
+ return sb.toString().toLowerCase(Locale.US);
+ }
+
+ public static String followRedirect(String urlString) throws IOException {
+ URL url=new URL(urlString);
+ HttpURLConnection conn=(HttpURLConnection) url.openConnection();
+ conn.setInstanceFollowRedirects(false);
+
+ if(conn.getResponseCode()==301 && conn.getHeaderField("Location")!=null) {
+ return conn.getHeaderField("Location");
+ }
+
+ return urlString;
+ }
+
+ public static String getMemoryStatus() {
+ Runtime rt = Runtime.getRuntime();
+ NumberFormat nf = NumberFormat.getInstance();
+ nf.setGroupingUsed(true);
+ nf.setMinimumFractionDigits(0);
+ long total_mem = rt.totalMemory();
+ long free_mem = rt.freeMemory();
+ long used_mem = total_mem - free_mem;
+ return "Amount of used memory/free memory: " + nf.format(used_mem/1000) + "KB / " + nf.format(free_mem/1000)+" KB";
+
+
+ }
+
+}
View
7 DOTSFeedMonster/readme.txt
@@ -0,0 +1,7 @@
+Collaboration Today DOTS-FeedMonster Project
+
+DOTS Task for the CollaborationToday project gets configured feed entries into CT database.
+
+Initial version uses Rome library to read feed entries. Because of OSGi incompatibilities in Rome library, it currently does not support scheduled DOTS operations. So to schedule working, you might use Program configuration in names.nsf.
+
+To set up the CT database, you might either use Constants.java or notes.ini variable "Monster_TargetDB" which points to the nsf file (relative path to the data folder).
View
2  disk-collaborationtoday/.settings/org.eclipse.core.resources.prefs
@@ -1,4 +1,4 @@
-#Mon Nov 26 07:09:02 EST 2012
+#Wed Dec 19 09:45:05 CET 2012
encoding//Resources/StyleSheets/jquery.Jcrop.css=UTF-8
encoding//Resources/Files/TestWidget.html=UTF-8
encoding//Resources/Files/TestJSONP.html=UTF-8
View
4 disk-collaborationtoday/Code/Java/org/openntf/news/http/core/NewsEntriesJson.java
@@ -30,8 +30,8 @@
public NewsEntriesJson() { }
private String _count = DEFAULT_COUNT;
- private String _filter = FORMAT_JSONP;
- private String _format = FILTER_ALL;
+ private String _filter = FILTER_ALL;
+ private String _format = FORMAT_JSONP;
public static final String FORMAT_JSON = "json";
public static final String FORMAT_JSONP = "jsonp";
View
18 disk-collaborationtoday/CustomControls/leftColumnLineItems.xsp.metadata
@@ -1,12 +1,12 @@
-<?xml version="1.0" encoding="UTF-8"?><note class="form" maintenanceversion="3.0" replicaid="85257AA6004F5595" version="8.5" xmlns="http://www.lotus.com/dxl">
-<noteinfo noteid="2ba" sequence="4" unid="E22D3630A4A4373085257AA6004F6E69">
-<created><datetime dst="true">20121029T102736,09-04</datetime></created>
-<modified><datetime dst="true">20121029T102736,54-04</datetime></modified>
-<revised><datetime dst="true">20121029T102736,53-04</datetime></revised>
-<lastaccessed><datetime dst="true">20121029T102736,53-04</datetime></lastaccessed>
-<addedtofile><datetime dst="true">20121029T102736,17-04</datetime></addedtofile></noteinfo>
-<updatedby><name>CN=Jesse Gallagher/O=MTC</name></updatedby>
-<wassignedby><name>CN=Jesse Gallagher/O=MTC</name></wassignedby>
+<?xml version="1.0" encoding="UTF-8"?><note class="form" replicaid="86257A780060902F" version="9.0" xmlns="http://www.lotus.com/dxl">
+<noteinfo noteid="276" sequence="82" unid="586475E56C4B2345C1257A64002E9211">
+<created><datetime dst="true">20120824T102840,49+02</datetime></created>
+<modified><datetime>20121219T094502,00+01</datetime></modified>
+<revised><datetime>20121219T094501,99+01</datetime></revised>
+<lastaccessed><datetime>20121219T094502,00+01</datetime></lastaccessed>
+<addedtofile><datetime dst="true">20120914T085927,21+02</datetime></addedtofile></noteinfo>
+<updatedby><name>CN=Niklas Heidloff/OU=Germany/O=IBM</name></updatedby>
+<wassignedby><name>CN=Niklas Heidloff/OU=Germany/O=IBM</name></wassignedby>
<item name="$Flags"><text>gC~4;</text></item>
<item name="$TITLE"><text>leftColumnLineItems.xsp</text></item>
<item name="$DesignerVersion"><text>8.5.3</text></item>
View
20 disk-collaborationtoday/XPages/author.xsp.metadata
@@ -1,19 +1,19 @@
-<?xml version="1.0" encoding="UTF-8"?><note class="form" maintenanceversion="3.0" replicaid="85257AA6004F5595" version="8.5" xmlns="http://www.lotus.com/dxl">
-<noteinfo noteid="1b2" sequence="48" unid="769F9306FB9F367085257AA6004F5CC5">
-<created><datetime dst="true">20121029T102650,93-04</datetime></created>
-<modified><datetime>20121119T124350,61-05</datetime></modified>
-<revised><datetime>20121119T124350,59-05</datetime></revised>
-<lastaccessed><datetime>20121119T124350,59-05</datetime></lastaccessed>
-<addedtofile><datetime dst="true">20121029T102651,03-04</datetime></addedtofile></noteinfo>
-<updatedby><name>CN=Jesse Gallagher/O=Frost</name></updatedby>
-<wassignedby><name>CN=Jesse Gallagher/O=Frost</name></wassignedby>
+<?xml version="1.0" encoding="UTF-8"?><note class="form" replicaid="86257A780060902F" version="9.0" xmlns="http://www.lotus.com/dxl">
+<noteinfo noteid="2fa" sequence="188" unid="E83357506AD4E760C1257A4800225D71">
+<created><datetime dst="true">20120727T081521,45+02</datetime></created>
+<modified><datetime>20121219T094516,76+01</datetime></modified>
+<revised><datetime>20121219T094516,75+01</datetime></revised>
+<lastaccessed><datetime>20121219T094516,76+01</datetime></lastaccessed>
+<addedtofile><datetime dst="true">20120914T085934,96+02</datetime></addedtofile></noteinfo>
+<updatedby><name>CN=Niklas Heidloff/OU=Germany/O=IBM</name></updatedby>
+<wassignedby><name>CN=Niklas Heidloff/OU=Germany/O=IBM</name></wassignedby>
<item name="$Flags"><text>gC~4K</text></item>
<item name="$TITLE"><text>author.xsp</text></item>
<item name="$Comment" sign="true"><text>Moderators Only</text></item>
-
<item name="$FileNames" sign="true"><text>author.xsp</text></item>
+
<item name="$DesignerVersion"><text>8.5.3</text></item>
Please sign in to comment.
Something went wrong with that request. Please try again.