Source Code Cross Referenced for MetaWeblogPublisher.java in  » RSS-RDF » nntp-rss » org » methodize » nntprss » rss » publish » 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 » RSS RDF » nntp rss » org.methodize.nntprss.rss.publish 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.methodize.nntprss.rss.publish;
002:
003:        /* -----------------------------------------------------------
004:         * nntp//rss - a bridge between the RSS world and NNTP clients
005:         * Copyright (c) 2002, 2003 Jason Brome.  All Rights Reserved.
006:         *
007:         * email: nntprss@methodize.org
008:         * mail:  Methodize Solutions
009:         *        PO Box 3865
010:         *        Grand Central Station
011:         *        New York NY 10163
012:         * 
013:         * This file is part of nntp//rss
014:         * 
015:         * nntp//rss is free software; you can redistribute it 
016:         * and/or modify it under the terms of the GNU General 
017:         * Public License as published by the Free Software Foundation; 
018:         * either version 2 of the License, or (at your option) any 
019:         * later version.
020:         *
021:         * This program is distributed in the hope that it will be 
022:         * useful, but WITHOUT ANY WARRANTY; without even the implied 
023:         * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
024:         * PURPOSE.  See the GNU General Public License for more 
025:         * details.
026:         *
027:         * You should have received a copy of the GNU General Public 
028:         * License along with this program; if not, write to the 
029:         * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
030:         * Boston, MA  02111-1307  USA
031:         * ----------------------------------------------------- */
032:
033:        import java.io.BufferedReader;
034:        import java.io.InputStreamReader;
035:        import java.util.HashMap;
036:        import java.util.Hashtable;
037:        import java.util.Map;
038:        import java.util.Vector;
039:
040:        import org.apache.xmlrpc.XmlRpcClient;
041:        import org.methodize.nntprss.rss.Item;
042:
043:        /**
044:         * @author Jason Brome <jason@methodize.org>
045:         * @version $Id: MetaWeblogPublisher.java,v 1.1 2003/03/22 16:33:26 jasonbrome Exp $
046:         */
047:
048:        public class MetaWeblogPublisher implements  Publisher {
049:
050:            private static final String METHOD_NEWPOST = "metaWeblog.newPost";
051:
052:            private static final String BLOGGER_APP_KEY = "0B18094ACF9546D113015FD8376930FA62A827";
053:
054:            private static final String METHOD_GETUSERINFO = "blogger.getUserInfo";
055:
056:            private static final String METHOD_GETCATEGORIES = "metaWeblog.getCategories";
057:
058:            private static final String STRUCT_TITLE = "title";
059:            private static final String STRUCT_DESCRIPTION = "description";
060:            private static final String STRUCT_LINK = "link";
061:
062:            /**
063:             * @see org.methodize.nntprss.rss.publish.Publisher#publish(Map, String)
064:             */
065:            public void publish(Map profile, Item content)
066:                    throws PublisherException {
067:
068:                // blogger.newPost takes the following parameters. All are required: 
069:                //
070:                try {
071:                    XmlRpcClient xmlrpc = new XmlRpcClient((String) profile
072:                            .get(PROP_PUBLISHER_URL));
073:                    Vector params = new Vector();
074:
075:                    // blogid (string): Unique identifier of the blog the post will be added to. 
076:                    params.addElement(profile.get(PROP_BLOG_ID));
077:
078:                    // username (string): Login for a Blogger user who has permission to post to the blog. 
079:                    params.addElement(profile.get(PROP_USERNAME));
080:
081:                    // password (string): Password for said username. 
082:                    params.addElement(profile.get(PROP_PASSWORD));
083:
084:                    // struct - title, link, description
085:                    Map struct = new Hashtable();
086:
087:                    if (content.getTitle() != null) {
088:                        struct.put(STRUCT_TITLE, content.getTitle());
089:                    }
090:
091:                    if (content.getDescription() != null) {
092:                        struct
093:                                .put(STRUCT_DESCRIPTION, content
094:                                        .getDescription());
095:                    }
096:
097:                    if (content.getLink() != null) {
098:                        struct.put(STRUCT_LINK, content.getLink());
099:                    }
100:
101:                    // content (string): Contents of the post. 
102:                    params.addElement(struct);
103:
104:                    // publish (boolean): If true, the blog will be published immediately after the post is made. 
105:                    params.addElement(Boolean.valueOf((String) profile
106:                            .get(PROP_PUBLISH)));
107:
108:                    String postId = (String) xmlrpc.execute(METHOD_NEWPOST,
109:                            params);
110:
111:                } catch (Exception e) {
112:                    throw new PublisherException(e);
113:                }
114:            }
115:
116:            /**
117:             * @see org.methodize.nntprss.rss.publish.Publisher#validate(Map)
118:             */
119:            public void validate(Map profile) throws PublisherException {
120:                // MetaWebLog API does not currently expose an endpoint
121:                // that can be used for URL / username / password validation
122:                // Can't use blogger.getUserInfo, as not supported by Radio
123:                // Use metaWeblog.getCategories
124:
125:                try {
126:                    XmlRpcClient xmlrpc = new XmlRpcClient((String) profile
127:                            .get(PROP_PUBLISHER_URL));
128:                    Vector params = new Vector();
129:                    // blogid (string): Unique identifier of the blog the post will be added to. 
130:                    params.addElement(profile.get(PROP_BLOG_ID));
131:
132:                    // username (string): Login for a Blogger user who has permission to post to the blog. 
133:                    params.addElement(profile.get(PROP_USERNAME));
134:
135:                    // password (string): Password for said username. 
136:                    params.addElement(profile.get(PROP_PASSWORD));
137:
138:                    Map userInfo = (Map) xmlrpc.execute(METHOD_GETCATEGORIES,
139:                            params);
140:
141:                } catch (Exception e) {
142:                    throw new PublisherException(e);
143:                }
144:
145:            }
146:
147:            public static void main(String args[]) {
148:                // Tester...
149:                MetaWeblogPublisher pub = new MetaWeblogPublisher();
150:
151:                Map profile = new HashMap();
152:
153:                try {
154:                    BufferedReader reader = new BufferedReader(
155:                            new InputStreamReader(System.in));
156:                    System.out.println("Blog id?");
157:                    String blogId = reader.readLine();
158:
159:                    System.out.println("Username?");
160:                    String userName = reader.readLine();
161:
162:                    System.out.println("Password?");
163:                    String password = reader.readLine();
164:
165:                    System.out.println("Description?");
166:                    String description = reader.readLine();
167:
168:                    System.out.println("Publish (true/false)?");
169:                    String publishStr = reader.readLine();
170:                    boolean publish = publishStr.equalsIgnoreCase("true");
171:
172:                    profile.put(PROP_BLOG_ID, blogId);
173:                    profile.put(PROP_PASSWORD, password);
174:                    profile.put(PROP_PUBLISH, new Boolean(publish));
175:                    profile.put(PROP_USERNAME, userName);
176:
177:                    profile.put(Publisher.PROP_PUBLISHER_URL,
178:                            "http://192.168.1.103:5335/RPC2");
179:
180:                    pub.validate(profile);
181:
182:                    Item content = new Item();
183:                    content.setDescription(description);
184:
185:                    pub.publish(profile, content);
186:                } catch (Exception e) {
187:                    e.printStackTrace();
188:
189:                }
190:
191:            }
192:
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.