Source Code Cross Referenced for SyncWebsitesTask.java in  » Blogger-System » apache-roller-3.1 » org » apache » roller » planet » tasks » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Blogger System » apache roller 3.1 » org.apache.roller.planet.tasks 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  The ASF licenses this file to You
004:         * under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.  For additional information regarding
015:         * copyright in this work, please see the NOTICE file in the top level
016:         * directory of this distribution.
017:         */
018:
019:        package org.apache.roller.planet.tasks;
020:
021:        import java.util.ArrayList;
022:        import java.util.Date;
023:        import java.util.Iterator;
024:        import java.util.List;
025:        import java.util.Properties;
026:        import org.apache.commons.logging.Log;
027:        import org.apache.commons.logging.LogFactory;
028:        import org.apache.roller.RollerException;
029:        import org.apache.roller.business.runnable.RollerTask;
030:        import org.apache.roller.config.RollerRuntimeConfig;
031:        import org.apache.roller.planet.business.PlanetManager;
032:        import org.apache.roller.business.RollerFactory;
033:        import org.apache.roller.business.UserManager;
034:        import org.apache.roller.planet.pojos.PlanetGroupData;
035:        import org.apache.roller.planet.pojos.PlanetSubscriptionData;
036:        import org.apache.roller.pojos.WebsiteData;
037:        import org.apache.roller.util.URLUtilities;
038:
039:        /**
040:         * Ensure that every weblog has a subscription in Planet Roller database.
041:         */
042:        public class SyncWebsitesTask extends RollerTask {
043:
044:            private static Log log = LogFactory.getLog(SyncWebsitesTask.class);
045:
046:            // a String description of when to start this task
047:            private String startTimeDesc = "startOfDay";
048:
049:            // interval at which the task is run, default is 1 day
050:            private int interval = 1440;
051:
052:            // lease time given to ping task lock, default is 30 minutes
053:            private int leaseTime = 30;
054:
055:            public String getName() {
056:                return "SyncWebsitesTask";
057:            }
058:
059:            public Date getStartTime(Date currentTime) {
060:                return getAdjustedTime(currentTime, startTimeDesc);
061:            }
062:
063:            public int getInterval() {
064:                return this .interval;
065:            }
066:
067:            public int getLeaseTime() {
068:                return this .leaseTime;
069:            }
070:
071:            public void init() throws RollerException {
072:
073:                // get relevant props
074:                Properties props = this .getTaskProperties();
075:
076:                // extract start time
077:                String startTimeStr = props.getProperty("startTime");
078:                if (startTimeStr != null) {
079:                    this .startTimeDesc = startTimeStr;
080:                }
081:
082:                // extract interval
083:                String intervalStr = props.getProperty("interval");
084:                if (intervalStr != null) {
085:                    try {
086:                        this .interval = Integer.parseInt(intervalStr);
087:                    } catch (NumberFormatException ex) {
088:                        log.warn("Invalid interval: " + intervalStr);
089:                    }
090:                }
091:
092:                // extract lease time
093:                String leaseTimeStr = props.getProperty("leaseTime");
094:                if (leaseTimeStr != null) {
095:                    try {
096:                        this .leaseTime = Integer.parseInt(leaseTimeStr);
097:                    } catch (NumberFormatException ex) {
098:                        log.warn("Invalid leaseTime: " + leaseTimeStr);
099:                    }
100:                }
101:            }
102:
103:            /**
104:             * Ensure there's a subscription in the "all" group for every Roller weblog.
105:             */
106:            public void runTask() {
107:
108:                // make sure we have an absolute url value
109:                String absUrl = RollerRuntimeConfig
110:                        .getProperty("site.absoluteurl");
111:                if (absUrl == null || absUrl.trim().length() == 0) {
112:                    log
113:                            .error("ERROR: cannot sync websites with Planet Roller - "
114:                                    + "absolute URL not specified in Roller Config");
115:                    return;
116:                }
117:
118:                try {
119:                    PlanetManager planet = RollerFactory.getRoller()
120:                            .getPlanetManager();
121:                    UserManager userManager = RollerFactory.getRoller()
122:                            .getUserManager();
123:
124:                    // first, make sure there is an "all" planet group
125:                    PlanetGroupData group = planet.getGroup("all");
126:                    if (group == null) {
127:                        group = new PlanetGroupData();
128:                        group.setHandle("all");
129:                        group.setTitle("all");
130:                        planet.saveGroup(group);
131:                    }
132:
133:                    // walk through all enable weblogs and add/update subs as needed
134:                    List liveUserFeeds = new ArrayList();
135:                    Iterator websites = userManager.getWebsites(null,
136:                            Boolean.TRUE, Boolean.TRUE, null, null, 0, -1)
137:                            .iterator();
138:                    while (websites.hasNext()) {
139:                        WebsiteData weblog = (WebsiteData) websites.next();
140:
141:                        String siteUrl = URLUtilities.getWeblogURL(weblog,
142:                                null, true);
143:                        String feedUrl = URLUtilities
144:                                .getWeblogFeedURL(weblog, null, "entries",
145:                                        "rss", null, null, false, true);
146:
147:                        // add feed url to the "live" list
148:                        liveUserFeeds.add(feedUrl);
149:
150:                        // if sub already exists then update it, otherwise add it
151:                        PlanetSubscriptionData sub = planet
152:                                .getSubscription(feedUrl);
153:                        if (sub == null) {
154:                            log.info("ADDING feed: " + feedUrl);
155:
156:                            sub = new PlanetSubscriptionData();
157:                            sub.setTitle(weblog.getName());
158:                            sub.setFeedURL(feedUrl);
159:                            sub.setSiteURL(siteUrl);
160:                            sub.setAuthor(weblog.getHandle());
161:
162:                            planet.saveSubscription(sub);
163:                            group.getSubscriptions().add(sub);
164:                        } else {
165:                            sub.setTitle(weblog.getName());
166:                            sub.setAuthor(weblog.getHandle());
167:
168:                            planet.saveSubscription(sub);
169:                        }
170:                    }
171:
172:                    // new subs added, existing subs updated, now delete old subs
173:                    Iterator subs = group.getSubscriptions().iterator();
174:                    while (subs.hasNext()) {
175:                        PlanetSubscriptionData sub = (PlanetSubscriptionData) subs
176:                                .next();
177:                        if (!liveUserFeeds.contains(sub.getFeedURL())) {
178:                            log.info("DELETING feed: " + sub.getFeedURL());
179:                            planet.deleteSubscription(sub);
180:                            group.getSubscriptions().remove(sub);
181:                        }
182:                    }
183:
184:                    // all done, lets save
185:                    planet.saveGroup(group);
186:                    RollerFactory.getRoller().flush();
187:
188:                } catch (RollerException e) {
189:                    log.error("ERROR refreshing entries", e);
190:                } finally {
191:                    // don't forget to release
192:                    RollerFactory.getRoller().release();
193:                }
194:            }
195:
196:            /** 
197:             * Task may be run from the command line 
198:             */
199:            public static void main(String[] args) {
200:                try {
201:                    SyncWebsitesTask task = new SyncWebsitesTask();
202:                    task.init();
203:                    task.run();
204:                    System.exit(0);
205:                } catch (Throwable t) {
206:                    t.printStackTrace();
207:                    System.exit(-1);
208:                }
209:            }
210:
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.