Source Code Cross Referenced for Technorati.java in  » Blogger-System » apache-roller-3.1 » org » apache » roller » util » 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.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 David M Johnson
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not 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.
015:         */
016:        package org.apache.roller.util;
017:
018:        import java.io.BufferedReader;
019:        import java.io.IOException;
020:        import java.io.InputStream;
021:        import java.io.InputStreamReader;
022:        import java.net.URL;
023:        import java.net.URLConnection;
024:        import java.util.ArrayList;
025:        import java.util.Collection;
026:        import java.util.HashMap;
027:        import java.util.Iterator;
028:        import java.util.Map;
029:        import org.jdom.Document;
030:        import org.jdom.Element;
031:        import org.jdom.input.SAXBuilder;
032:        import org.jdom.xpath.XPath;
033:        import org.xml.sax.EntityResolver;
034:        import org.xml.sax.InputSource;
035:        import org.xml.sax.SAXException;
036:
037:        /** Simple Technorati wrapper for Java. @author David M Johnson */
038:        public class Technorati {
039:            private String mKey = null;
040:
041:            public Technorati(String key) {
042:                mKey = key;
043:            }
044:
045:            public Technorati(String key, String proxy, int proxyPort) {
046:                this (key);
047:                System.setProperty("proxySet", "true");
048:                System.setProperty("http.proxyHost", proxy);
049:                System.setProperty("http.proxyPort", Integer
050:                        .toString(proxyPort));
051:            }
052:
053:            /** Looks for key in classpath using "/technorati.license" */
054:            public Technorati() throws IOException {
055:                InputStream is = getClass().getResourceAsStream(
056:                        "/technorati.license");
057:                BufferedReader br = new BufferedReader(
058:                        new InputStreamReader(is));
059:                mKey = br.readLine();
060:            }
061:
062:            public Technorati(String proxy, int proxyPort) throws Exception {
063:                this ();
064:                System.setProperty("proxySet", "true");
065:                System.setProperty("http.proxyHost", proxy);
066:                System.setProperty("http.proxyPort", Integer
067:                        .toString(proxyPort));
068:            }
069:
070:            public Result getLinkCosmos(String url) throws Exception {
071:                return new Result("http://api.technorati.com/cosmos", url,
072:                        "links");
073:            }
074:
075:            public Result getWeblogCosmos(String url) throws Exception {
076:                return new Result("http://api.technorati.com/cosmos", url,
077:                        "weblog");
078:            }
079:
080:            public Result getBloginfo(String url) throws Exception {
081:                return new Result("http://api.technorati.com/bloginfo", url,
082:                        null);
083:            }
084:
085:            public Result getOutbound(String url) throws Exception {
086:                return new Result("http://api.technorati.com/outbound", url,
087:                        null);
088:            }
089:
090:            /** Technorati result with header info and collection of weblog items */
091:            public class Result {
092:                private Weblog mWeblog = null;
093:                private Collection mWeblogs = new ArrayList();
094:
095:                protected Result(String apiUrl, String url, String type)
096:                        throws Exception {
097:                    Map args = new HashMap();
098:                    args.put("url", url);
099:                    args.put("type", type);
100:                    args.put("format", "xml");
101:                    args.put("key", mKey);
102:
103:                    int start = 0;
104:                    boolean repeat = true;
105:                    XPath itemsPath = XPath
106:                            .newInstance("/tapi/document/item/weblog");
107:
108:                    while (repeat) {
109:                        Document doc = getRawResults(apiUrl, args);
110:                        Element elem = doc.getRootElement();
111:                        String error = getString(elem,
112:                                "/tapi/document/result/error");
113:                        if (error != null)
114:                            throw new Exception(error);
115:                        if (mWeblog == null) {
116:                            XPath p = XPath
117:                                    .newInstance("/tapi/document/result/weblog");
118:                            Element w = (Element) p.selectSingleNode(doc);
119:                            mWeblog = new Weblog(w);
120:                        }
121:                        int count = 0;
122:                        Iterator iter = itemsPath.selectNodes(doc).iterator();
123:                        while (iter.hasNext()) {
124:                            Element element = (Element) iter.next();
125:                            Weblog w = new Weblog(element);
126:                            mWeblogs.add(w);
127:                            count++;
128:                        }
129:                        if (count < 20) {
130:                            repeat = false;
131:                        } else {
132:                            start += 20;
133:                            args.put("start", new Integer(start));
134:                        }
135:                    }
136:                }
137:
138:                public Weblog getWeblog() {
139:                    return mWeblog;
140:                }
141:
142:                public Collection getWeblogs() {
143:                    return mWeblogs;
144:                }
145:            }
146:
147:            /** Technorati weblog representation */
148:            public class Weblog {
149:                private String mName = null;
150:                private String mUrl = null;
151:                private String mRssurl = null;
152:                private String mLastupdate = null;
153:                private String mNearestpermalink = null;
154:                private String mExcerpt = null;
155:                private int mInboundlinks = 0;
156:                private int mInboundblogs = 0;
157:
158:                public Weblog(Element elem) throws Exception {
159:                    mName = getString(elem, "name");
160:                    mUrl = getString(elem, "url");
161:                    mRssurl = getString(elem, "rssurl");
162:                    mLastupdate = getString(elem, "lastupdate");
163:                    mNearestpermalink = getString(elem, "nearestpermalink");
164:                    mExcerpt = getString(elem, "excerpt");
165:                    try {
166:                        mInboundlinks = getInt(elem, "inboundlinks");
167:                    } catch (Exception ignored) {
168:                    }
169:                    try {
170:                        mInboundblogs = getInt(elem, "inboundblogs");
171:                    } catch (Exception ignored) {
172:                    }
173:                }
174:
175:                public String getName() {
176:                    return mName;
177:                }
178:
179:                public String getUrl() {
180:                    return mUrl;
181:                }
182:
183:                public String getRssurl() {
184:                    return mRssurl;
185:                }
186:
187:                public int getInboundblogs() {
188:                    return mInboundblogs;
189:                }
190:
191:                public int getInboundlinks() {
192:                    return mInboundlinks;
193:                }
194:
195:                public String getLastupdate() {
196:                    return mLastupdate;
197:                }
198:
199:                public String getNearestpermalink() {
200:                    return mNearestpermalink;
201:                }
202:
203:                public String getExcerpt() {
204:                    return mExcerpt;
205:                }
206:            }
207:
208:            protected Document getRawResults(String urlString, Map args)
209:                    throws Exception {
210:                int count = 0;
211:                Iterator keys = args.keySet().iterator();
212:                while (keys.hasNext()) {
213:                    String sep = count++ == 0 ? "?" : "&";
214:                    String name = (String) keys.next();
215:                    if (args.get(name) != null) {
216:                        urlString += sep + name + "=" + args.get(name);
217:                    }
218:                }
219:                URL url = new URL(urlString);
220:                URLConnection conn = url.openConnection();
221:                conn.connect();
222:                SAXBuilder builder = new SAXBuilder();
223:                return builder.build(conn.getInputStream());
224:            }
225:
226:            protected String getString(Element elem, String path)
227:                    throws Exception {
228:                XPath xpath = XPath.newInstance(path);
229:                Element e = (Element) xpath.selectSingleNode(elem);
230:                return e != null ? e.getText() : null;
231:            }
232:
233:            protected int getInt(Element elem, String path) throws Exception {
234:                XPath xpath = XPath.newInstance(path);
235:                Element e = (Element) xpath.selectSingleNode(elem);
236:                return e != null ? Integer.parseInt(e.getText()) : 0;
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.