Source Code Cross Referenced for AppWebAPIHandler.java in  » RSS-RDF » Feedzeo » app » 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 » Feedzeo » app 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:
003:            Feedzeo! 
004:            A free and open source RSS/Atom/RDF feed aggregator
005:
006:            Copyright (C) 2005-2006  Anand Rao (anandrao@users.sourceforge.net)
007:
008:            This library is free software; you can redistribute it and/or
009:            modify it under the terms of the GNU Lesser General Public
010:            License as published by the Free Software Foundation; either
011:            version 2.1 of the License, or (at your option) any later version.
012:
013:            This library is distributed in the hope that it will be useful,
014:            but WITHOUT ANY WARRANTY; without even the implied warranty of
015:            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:            Lesser General Public License for more details.
017:
018:            You should have received a copy of the GNU Lesser General Public
019:            License along with this library; if not, write to the Free Software
020:            Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
021:
022:         ************************************************************************************/package app;
023:
024:        import java.util.*;
025:        import java.io.*;
026:
027:        import NanoHttpd.*;
028:        import util.*;
029:        import data.DataElement;
030:
031:        /**
032:         *
033:         * @author  Anand Rao
034:         */
035:        public class AppWebAPIHandler extends FileServer implements 
036:                HTTPRequestHandlerIF {
037:            private boolean DEBUG = false; // debug flag
038:
039:            private String rootDir;
040:            private AppCommandIF cmdExecuter;
041:
042:            /** Creates a new instance of AppWebAPIHandler */
043:            public AppWebAPIHandler(String rootDir, AppCommandIF cmdIF) {
044:                super (rootDir);
045:                this .rootDir = rootDir;
046:                cmdExecuter = cmdIF;
047:            }
048:
049:            /* command=addlink&ctgy=<category>&link=<linkaddr>&output=<html|no> */
050:            private Response handleAddLinkCmd(int code, Properties params) {
051:                Response errResponseNoTxt = new Response(
052:                        HTTPCodes.HTTP_INTERNALERROR);
053:
054:                String category = params.getProperty("ctgy");
055:                String link = params.getProperty("link");
056:                String outputfrmt = params.getProperty("output");
057:
058:                if ((link == null) || (category == null)) {
059:                    if (outputfrmt.equalsIgnoreCase("html")) {
060:                        String op = "<HTML><BODY> <div class=cmdResponse>Invalid argument passed</div>"
061:                                + "</BODY></HTML>";
062:                        return new Response(HTTPCodes.HTTP_BADREQUEST,
063:                                MimeTypes.MIME_HTML, op);
064:
065:                    }
066:                    return errResponseNoTxt;
067:                }
068:
069:                Vector CmdInfo = new Vector();
070:                CmdInfo.addElement(new Integer(code));
071:                CmdInfo.addElement(category);
072:                CmdInfo.addElement(link);
073:
074:                CmdResult res = cmdExecuter.handleCommand(CmdInfo);
075:
076:                if (res.getReturnCode() == CmdResult.SUCESS_CODE) {
077:                    if (outputfrmt.equalsIgnoreCase("html")) {
078:                        String op = "<HTML><BODY> <div class=cmdResponse> Feed: <I>"
079:                                + link
080:                                + "</I> added"
081:                                + " successfully </div>"
082:                                + "</BODY></HTML>";
083:                        return new Response(HTTPCodes.HTTP_OK,
084:                                MimeTypes.MIME_HTML, op);
085:                    }
086:                } else { // cmd failed
087:                    if (outputfrmt.equalsIgnoreCase("html")) {
088:                        String op = "<HTML><BODY> <div class=cmdResponse> Error adding feed:"
089:                                + "<I>" + link + "</I> </B>" + "</BODY></HTML>";
090:                        return new Response(HTTPCodes.HTTP_INTERNALERROR,
091:                                MimeTypes.MIME_HTML, op);
092:                    }
093:                }
094:                return errResponseNoTxt;
095:            }
096:
097:            /* command=getcategories&output=<html|plain> */
098:            private Response handleGetCategoriesCmd(int code, Properties params) {
099:                StringBuffer buf = new StringBuffer();
100:
101:                String outputfrmt = params.getProperty("output");
102:                if (outputfrmt == null)
103:                    outputfrmt = new String("plain");
104:
105:                Vector CmdInfo = new Vector();
106:                CmdInfo.addElement(new Integer(code));
107:                CmdResult res = cmdExecuter.handleCommand(CmdInfo);
108:
109:                if (res.getReturnCode() == CmdResult.SUCESS_CODE) {
110:                    Vector catlist = res.getResult();
111:                    int NumCategories = res.getSize();
112:                    Response resp;
113:
114:                    if (outputfrmt.equalsIgnoreCase("html")) {
115:                        buf.append("<HTML><BODY>");
116:                        for (int i = 0; i < NumCategories; i++) {
117:                            buf.append("<B ");
118:                            buf
119:                                    .append(HTMLHelper
120:                                            .getClassString(DataElement.CATEGORY_TITLE_ELEM)
121:                                            + " >");
122:                            buf.append((String) catlist.elementAt(i));
123:                            buf.append("</B>");
124:                            buf.append("<BR>");
125:                        }
126:                        buf.append("</BODY> </HTML>");
127:                        resp = new Response(HTTPCodes.HTTP_OK,
128:                                MimeTypes.MIME_HTML, buf.toString());
129:                    } else {
130:                        for (int i = 0; i < NumCategories; i++) {
131:                            buf.append((String) catlist.elementAt(i));
132:                            buf.append("\n");
133:                        }
134:                        // remove the last '\n'
135:                        buf.deleteCharAt(buf.length() - 1);
136:                        //System.out.println("WEBAPI GETCAT RES:"+buf.toString());
137:
138:                        resp = new Response(HTTPCodes.HTTP_OK,
139:                                MimeTypes.MIME_PLAINTEXT, buf.toString());
140:                    }
141:                    return resp;
142:                } // success result
143:                else { //error
144:
145:                    if (outputfrmt.equalsIgnoreCase("html")) {
146:                        String errStr = "<HTML><BODY> <div class=cmdResponse> Error getting "
147:                                + "category names "
148:                                + "</div>"
149:                                + "</BODY></HTML>";
150:                        Response errResponse = new Response(
151:                                HTTPCodes.HTTP_INTERNALERROR,
152:                                MimeTypes.MIME_HTML, errStr);
153:                        return errResponse;
154:                    } else {
155:                        return new Response(HTTPCodes.HTTP_INTERNALERROR,
156:                                MimeTypes.MIME_PLAINTEXT,
157:                                "Error getting category names");
158:                    }
159:                }
160:            }
161:
162:            /* command=getfeednames&ctgy=<category name>&output=<html|plain> */
163:            private Response handleGetFeedNamesCmd(int code, Properties params) {
164:
165:                String outputfrmt = params.getProperty("output");
166:                if (outputfrmt == null)
167:                    outputfrmt = new String("plain");
168:                String category = params.getProperty("ctgy");
169:
170:                if (category == null) { // return error
171:                    if (outputfrmt.equalsIgnoreCase("html")) {
172:                        String op = "<HTML><BODY> <div class=cmdResponse>Invalid argument passed</div>"
173:                                + "</BODY></HTML>";
174:                        return new Response(HTTPCodes.HTTP_BADREQUEST,
175:                                MimeTypes.MIME_HTML, op);
176:                    } else {
177:                        return new Response(HTTPCodes.HTTP_BADREQUEST,
178:                                MimeTypes.MIME_PLAINTEXT,
179:                                "Invalid argument passed");
180:                    }
181:                }
182:
183:                Vector CmdInfo = new Vector();
184:                CmdInfo.addElement(new Integer(code));
185:                CmdInfo.addElement(category);
186:                CmdResult res = cmdExecuter.handleCommand(CmdInfo);
187:
188:                if (res.getReturnCode() == CmdResult.SUCESS_CODE) {
189:                    Vector feedNames = res.getResult();
190:                    int numFeeds = res.getSize();
191:                    StringBuffer op = new StringBuffer();
192:                    Response resp;
193:
194:                    if (outputfrmt.equalsIgnoreCase("html")) {
195:                        op.append("<HTML><BODY>");
196:                        for (int i = 0; i < numFeeds; i++) {
197:                            op.append("<B ");
198:                            op
199:                                    .append(HTMLHelper
200:                                            .getClassString(DataElement.FEED_TITLE_ELEM));
201:                            op.append(" >");
202:                            op.append((String) feedNames.elementAt(i));
203:                            op.append("</B>");
204:                            op.append("<BR>");
205:                        }
206:                        op.append("</BODY></HTML>");
207:                        resp = new Response(HTTPCodes.HTTP_OK,
208:                                MimeTypes.MIME_HTML, op.toString());
209:                    } else { //return o/p as plain text
210:                        for (int i = 0; i < numFeeds; i++) {
211:                            op.append((String) feedNames.elementAt(i));
212:                            op.append("\n");
213:                        }
214:                        // remove the last '\n'
215:                        op.deleteCharAt(op.length() - 1);
216:                        //System.out.println("WEBAPI GETFEEDNAMES RES:"+op.toString());
217:                        resp = new Response(HTTPCodes.HTTP_OK,
218:                                MimeTypes.MIME_PLAINTEXT, op.toString());
219:                    }
220:                    return resp;
221:                } else { //error
222:
223:                    if (outputfrmt.equalsIgnoreCase("html")) {
224:                        String errStr = "<HTML><BODY> <div class=cmdResponse> Error getting "
225:                                + "feed names  " + "</div>" + "</BODY></HTML>";
226:                        Response errResponse = new Response(
227:                                HTTPCodes.HTTP_INTERNALERROR,
228:                                MimeTypes.MIME_HTML, errStr);
229:                        return errResponse;
230:                    } else {
231:                        return new Response(HTTPCodes.HTTP_INTERNALERROR,
232:                                MimeTypes.MIME_PLAINTEXT,
233:                                "Error getting feed names");
234:                    }
235:                }
236:            }
237:
238:            /* 
239:             * Get feed names with the page link for the generated page;
240:             * If boolean allCategories is true, then the returned response
241:             * contains all the feed names across all categories
242:             * command=getfeednameswpagelink&ctgy=<category name>&output=<html|plain> 
243:             *    OR
244:             * command=getallfeednameswpagelink&output=<html|plain> 
245:             */
246:            private Response handleGetFeedNamesWithPageLinkCmd(int code,
247:                    Properties params, boolean allCategories) {
248:                String category = null;
249:
250:                String outputfrmt = params.getProperty("output");
251:                if (outputfrmt == null)
252:                    outputfrmt = new String("plain");
253:                if (allCategories == false) {
254:                    category = params.getProperty("ctgy");
255:                    if (category == null) {
256:                        if (outputfrmt.equalsIgnoreCase("html")) {
257:                            String op = "<HTML><BODY> <div class=cmdResponse>Invalid argument "
258:                                    + "passed</div>" + "</BODY></HTML>";
259:                            return new Response(HTTPCodes.HTTP_BADREQUEST,
260:                                    MimeTypes.MIME_HTML, op);
261:                        } else {
262:                            return new Response(HTTPCodes.HTTP_BADREQUEST,
263:                                    MimeTypes.MIME_PLAINTEXT,
264:                                    "Invalid argument passed");
265:                        }
266:                    }
267:                }
268:
269:                Vector CmdInfo = new Vector();
270:                CmdInfo.addElement(new Integer(code));
271:                if (category != null)
272:                    CmdInfo.addElement(category);
273:
274:                CmdResult res = cmdExecuter.handleCommand(CmdInfo);
275:                if (res.getReturnCode() == CmdResult.SUCESS_CODE) {
276:                    StringBuffer buf = new StringBuffer();
277:                    Vector feedlist = res.getResult();
278:                    Response resp;
279:                    /* 
280:                     * the result is given back in the form 
281:                     * feedname, pagelink
282:                     * ....
283:                     */
284:                    if (outputfrmt.equalsIgnoreCase("plain")) {
285:                        for (int i = 0; i < res.getSize(); i++) {
286:                            buf.append((String) feedlist.elementAt(i));
287:                            buf.append("\n");
288:                        }
289:                        // remove the last '\n'
290:                        buf.deleteCharAt(buf.length() - 1);
291:                        //System.out.println("WEBAPI GETFEEDPAGELNK RES:"+buf.toString());
292:                        resp = new Response(HTTPCodes.HTTP_OK,
293:                                MimeTypes.MIME_PLAINTEXT, buf.toString());
294:                    } else {
295:                        /*
296:                         * send out 
297:                         * <HTML> <BODY> 
298:                         * <a class=feedpagelink href=link> Feedname </a>
299:                         * ...
300:                         * </BODY> </HTML>
301:                         */
302:                        buf.append("<HTML> <BODY>");
303:                        for (int i = 0; i < res.getSize(); i++) {
304:                            StringTokenizer st = new StringTokenizer(
305:                                    (String) feedlist.elementAt(i), "\t");
306:                            String feedname = st.nextToken();
307:                            String link = st.nextToken();
308:
309:                            if (DEBUG) {
310:                                System.out.println("FEEDLIST:"
311:                                        + (String) feedlist.elementAt(i));
312:                                System.out.println("NAME:" + feedname
313:                                        + " LINK:" + link);
314:                            }
315:
316:                            buf.append("<A class=feedpagelink "
317:                                    + HTMLHelper.toHREFString(link) + ">"
318:                                    + feedname + "</A>");
319:                            buf.append("<BR>");
320:                        }
321:                        buf.append("</BODY> </HTML> ");
322:                        resp = new Response(HTTPCodes.HTTP_OK,
323:                                MimeTypes.MIME_HTML, buf.toString());
324:                    }
325:                    return resp;
326:                } else { //error
327:
328:                    if (outputfrmt.equalsIgnoreCase("html")) {
329:                        String errStr = "<HTML><BODY> <div class=cmdResponse> Error getting "
330:                                + "feednames and pagelinks "
331:                                + "</div>"
332:                                + "</BODY></HTML>";
333:                        Response errResponse = new Response(
334:                                HTTPCodes.HTTP_INTERNALERROR,
335:                                MimeTypes.MIME_HTML, errStr);
336:                        return errResponse;
337:                    } else {
338:                        return new Response(HTTPCodes.HTTP_INTERNALERROR,
339:                                MimeTypes.MIME_PLAINTEXT,
340:                                "Error getting feednames and pagelinks");
341:                    }
342:                }
343:            }
344:
345:            /* 
346:             * Get feed names with the tabledata page link for the generated page;
347:             * If boolean allCategories is true, then the returned response
348:             * contains all the feed names across all categories
349:             * command=getfeednameswtabledatapagelink&ctgy=<category name>&output=<html|plain> 
350:             *    OR
351:             * command=getallfeednameswtabledatapagelink&output=<html|plain> 
352:             */
353:            private Response handleGetFeedNamesWithTableDataPageLinkCmd(
354:                    int code, Properties params, boolean allCategories) {
355:                String category = null;
356:
357:                String outputfrmt = params.getProperty("output");
358:                if (outputfrmt == null)
359:                    outputfrmt = new String("plain");
360:                if (allCategories == false) {
361:                    category = params.getProperty("ctgy");
362:                    if (category == null) {
363:                        if (outputfrmt.equalsIgnoreCase("html")) {
364:                            String op = "<HTML><BODY> <div class=cmdResponse>Invalid argument "
365:                                    + "passed</div>" + "</BODY></HTML>";
366:                            return new Response(HTTPCodes.HTTP_BADREQUEST,
367:                                    MimeTypes.MIME_HTML, op);
368:                        } else {
369:                            return new Response(HTTPCodes.HTTP_BADREQUEST,
370:                                    MimeTypes.MIME_PLAINTEXT,
371:                                    "Invalid argument passed");
372:                        }
373:                    }
374:                }
375:
376:                Vector CmdInfo = new Vector();
377:                CmdInfo.addElement(new Integer(code));
378:                if (category != null)
379:                    CmdInfo.addElement(category);
380:
381:                CmdResult res = cmdExecuter.handleCommand(CmdInfo);
382:                if (res.getReturnCode() == CmdResult.SUCESS_CODE) {
383:                    StringBuffer buf = new StringBuffer();
384:                    Vector feedlist = res.getResult();
385:                    Response resp;
386:                    /* 
387:                     * the result is given back in the form 
388:                     * feedname, pagelink
389:                     * ....
390:                     */
391:                    if (outputfrmt.equalsIgnoreCase("plain")) {
392:                        for (int i = 0; i < res.getSize(); i++) {
393:                            buf.append((String) feedlist.elementAt(i));
394:                            buf.append("\n");
395:                        }
396:                        // remove the last '\n'
397:                        buf.deleteCharAt(buf.length() - 1);
398:                        //System.out.println("WEBAPI TABLEDATA RES:"+buf.toString());
399:
400:                        resp = new Response(HTTPCodes.HTTP_OK,
401:                                MimeTypes.MIME_PLAINTEXT, buf.toString());
402:                    } else {
403:                        /*
404:                         * send out 
405:                         * <HTML> <BODY> 
406:                         * <a class=feedtabledatapagelink href=link> Feedname </a>
407:                         * ...
408:                         * </BODY> </HTML>
409:                         */
410:                        buf.append("<HTML> <BODY>");
411:                        for (int i = 0; i < res.getSize(); i++) {
412:                            StringTokenizer st = new StringTokenizer(
413:                                    (String) feedlist.elementAt(i), "\t");
414:                            String feedname = st.nextToken();
415:                            String link = st.nextToken();
416:
417:                            if (DEBUG) {
418:                                System.out.println("FEEDLIST:"
419:                                        + (String) feedlist.elementAt(i));
420:                                System.out.println("NAME:" + feedname
421:                                        + " LINK:" + link);
422:                            }
423:
424:                            buf.append("<A class=feedtabledatapagelink "
425:                                    + HTMLHelper.toHREFString(link) + ">"
426:                                    + feedname + "</A>");
427:                            buf.append("<BR>");
428:                        }
429:                        buf.append("</BODY> </HTML> ");
430:                        resp = new Response(HTTPCodes.HTTP_OK,
431:                                MimeTypes.MIME_HTML, buf.toString());
432:                    }
433:                    return resp;
434:                } else { //error
435:
436:                    if (outputfrmt.equalsIgnoreCase("html")) {
437:                        String errStr = "<HTML><BODY> <div class=cmdResponse> Error getting "
438:                                + "feednames and tabledata "
439:                                + "</div>"
440:                                + "</BODY></HTML>";
441:                        Response errResponse = new Response(
442:                                HTTPCodes.HTTP_INTERNALERROR,
443:                                MimeTypes.MIME_HTML, errStr);
444:                        return errResponse;
445:                    } else {
446:                        return new Response(HTTPCodes.HTTP_INTERNALERROR,
447:                                MimeTypes.MIME_PLAINTEXT,
448:                                "Error getting feednames and tabledata");
449:                    }
450:                }
451:            }
452:
453:            private Response handleGetStyleInfoCmd(int code, Properties params) {
454:                String errStr = "<HTML><BODY> <div class=cmdResponse> Error retrieving style information "
455:                        + "</div>" + "</BODY></HTML>";
456:                Response errResponse = new Response(
457:                        HTTPCodes.HTTP_INTERNALERROR, MimeTypes.MIME_HTML,
458:                        errStr);
459:
460:                Vector CmdInfo = new Vector();
461:                CmdInfo.addElement(new Integer(code));
462:                CmdResult res = cmdExecuter.handleCommand(CmdInfo);
463:                if (res.getReturnCode() == CmdResult.SUCESS_CODE) {
464:                    String styledata = (String) (res.getResult()).elementAt(0);
465:                    return new Response(HTTPCodes.HTTP_OK,
466:                            MimeTypes.MIME_PLAINTEXT, styledata);
467:                }
468:                return errResponse;
469:            }
470:
471:            private Response handleSaveStyleInfoCmd(int code, Properties params) {
472:                String errStr = "<HTML><BODY> <div class=cmdResponse> Error saving style information "
473:                        + "</div>" + "</BODY></HTML>";
474:                Response errResponse = new Response(
475:                        HTTPCodes.HTTP_INTERNALERROR, MimeTypes.MIME_HTML,
476:                        errStr);
477:
478:                Vector CmdInfo = new Vector();
479:                CmdInfo.addElement(new Integer(code));
480:                CmdInfo.addElement(params.getProperty("data"));
481:                //System.out.println("handleSaveStyleInfoCmd: data= "+params.getProperty("data"));
482:                CmdResult res = cmdExecuter.handleCommand(CmdInfo);
483:                if (res.getReturnCode() == CmdResult.SUCESS_CODE) {
484:                    StringBuffer sb = new StringBuffer();
485:                    sb
486:                            .append("<html> <body> <b> Style information saved sucessfully </b> </body> </html>");
487:                    return new Response(HTTPCodes.HTTP_OK, MimeTypes.MIME_HTML,
488:                            sb.toString());
489:                }
490:                return errResponse;
491:            }
492:
493:            /* 
494:             * Get feed names with feedsource link for the generated page;
495:             * command=getfeednameswfeedsourcelink&ctgy=<category name> 
496:             */
497:            private Response handleGetFeedNamesWithFeedSourceLinkCmd(int code,
498:                    Properties params) {
499:                String category = null;
500:
501:                category = params.getProperty("ctgy");
502:                if (category == null) {
503:                    return new Response(HTTPCodes.HTTP_BADREQUEST,
504:                            MimeTypes.MIME_PLAINTEXT, "Invalid argument passed");
505:                }
506:
507:                Vector CmdInfo = new Vector();
508:                CmdInfo.addElement(new Integer(code));
509:                if (category != null)
510:                    CmdInfo.addElement(category);
511:
512:                CmdResult res = cmdExecuter.handleCommand(CmdInfo);
513:                if (res.getReturnCode() == CmdResult.SUCESS_CODE) {
514:                    StringBuffer buf = new StringBuffer();
515:                    Vector feedlist = res.getResult();
516:                    Response resp;
517:                    /* 
518:                     * the result is given back in the form 
519:                     * feedname, feedsourcelink
520:                     * ....
521:                     */
522:                    for (int i = 0; i < res.getSize(); i++) {
523:                        buf.append((String) feedlist.elementAt(i));
524:                        buf.append("\n");
525:                    }
526:                    // remove the last '\n'
527:                    buf.deleteCharAt(buf.length() - 1);
528:                    //System.out.println("WEBAPI GETFEEDNAMESOURCELNK RES:"+buf.toString());
529:
530:                    resp = new Response(HTTPCodes.HTTP_OK,
531:                            MimeTypes.MIME_PLAINTEXT, buf.toString());
532:                    return resp;
533:                } else { //error
534:
535:                    return new Response(HTTPCodes.HTTP_INTERNALERROR,
536:                            MimeTypes.MIME_PLAINTEXT,
537:                            "Error getting feednames and feedsource link");
538:                }
539:            }
540:
541:            /* command=dellink&ctgy=<category>&link=<linkaddr>&output=<html|no> */
542:            private Response handleDeleteLinkCmd(int code, Properties params) {
543:                Response errResponseNoTxt = new Response(
544:                        HTTPCodes.HTTP_INTERNALERROR);
545:
546:                String category = params.getProperty("ctgy");
547:                String link = params.getProperty("link");
548:                String outputfrmt = params.getProperty("output");
549:
550:                if ((link == null) || (category == null)) {
551:                    if (outputfrmt.equalsIgnoreCase("html")) {
552:                        String op = "<HTML><BODY> <div class=cmdResponse>Invalid argument passed</div>"
553:                                + "</BODY></HTML>";
554:                        return new Response(HTTPCodes.HTTP_BADREQUEST,
555:                                MimeTypes.MIME_HTML, op);
556:
557:                    }
558:                    return errResponseNoTxt;
559:                }
560:
561:                Vector CmdInfo = new Vector();
562:                CmdInfo.addElement(new Integer(code));
563:                CmdInfo.addElement(category);
564:                CmdInfo.addElement(link);
565:
566:                CmdResult res = cmdExecuter.handleCommand(CmdInfo);
567:
568:                if (res.getReturnCode() == CmdResult.SUCESS_CODE) {
569:                    if (outputfrmt.equalsIgnoreCase("html")) {
570:                        String op = "<HTML><BODY> <div class=cmdResponse> Feed:<I>"
571:                                + link
572:                                + "</I> deleted"
573:                                + " successfully </div>" + "</BODY></HTML>";
574:                        return new Response(HTTPCodes.HTTP_OK,
575:                                MimeTypes.MIME_HTML, op);
576:                    }
577:                } else { // cmd failed
578:                    if (outputfrmt.equalsIgnoreCase("html")) {
579:                        String op = "<HTML><BODY> <div class=cmdResponse> Error deleting feed:"
580:                                + "<I>" + link + "</I> </B>" + "</BODY></HTML>";
581:                        return new Response(HTTPCodes.HTTP_INTERNALERROR,
582:                                MimeTypes.MIME_HTML, op);
583:                    }
584:                }
585:                return errResponseNoTxt;
586:            }
587:
588:            /* command=getfeednameswtabledatapagelinkfrmsourceurl&ctgy=<category>&link=<linkaddr> */
589:            private Response handleGetFeednamesPageLinkFromSourceUrlCmd(
590:                    int code, Properties params) {
591:                Response errResponseNoTxt = new Response(
592:                        HTTPCodes.HTTP_INTERNALERROR);
593:
594:                String category = params.getProperty("ctgy");
595:                String link = params.getProperty("link");
596:                if ((link == null) || (category == null)) {
597:                    return errResponseNoTxt;
598:                }
599:
600:                Vector CmdInfo = new Vector();
601:                CmdInfo.addElement(new Integer(code));
602:                CmdInfo.addElement(category);
603:                CmdInfo.addElement(link);
604:
605:                CmdResult res = cmdExecuter.handleCommand(CmdInfo);
606:
607:                if (res.getReturnCode() == CmdResult.SUCESS_CODE) {
608:                    StringBuffer buf = new StringBuffer();
609:                    Vector feedlist = res.getResult();
610:                    Response resp;
611:                    /* 
612:                     * the result is given back in the form 
613:                     * feedname, pagelink
614:                     * ....
615:                     */
616:                    for (int i = 0; i < res.getSize(); i++) {
617:                        buf.append((String) feedlist.elementAt(i));
618:                        buf.append("\n");
619:                    }
620:                    // remove the last '\n'
621:                    buf.deleteCharAt(buf.length() - 1);
622:                    //System.out.println("WEBAPI GETFEEDNAMEPGLNKFRMSOURCEURL RES:"+buf.toString());
623:
624:                    resp = new Response(HTTPCodes.HTTP_OK,
625:                            MimeTypes.MIME_PLAINTEXT, buf.toString());
626:                    return resp;
627:                } else { //error
628:
629:                    return new Response(HTTPCodes.HTTP_INTERNALERROR,
630:                            MimeTypes.MIME_PLAINTEXT,
631:                            "Error getting feednames and page link");
632:                }
633:            }
634:
635:            /* command=opmlimport&ctgy=<category>&source=<inputfile> */
636:            private Response handleOpmlImportCmd(int code, Properties params) {
637:                Response errResponseNoTxt = new Response(
638:                        HTTPCodes.HTTP_INTERNALERROR);
639:
640:                String category = params.getProperty("ctgy");
641:                String source = params.getProperty("source");
642:                if ((source == null) || (category == null)) {
643:                    return errResponseNoTxt;
644:                }
645:
646:                Vector CmdInfo = new Vector();
647:                CmdInfo.addElement(new Integer(code));
648:                CmdInfo.addElement(category);
649:                CmdInfo.addElement(source);
650:
651:                CmdResult res = cmdExecuter.handleCommand(CmdInfo);
652:
653:                if (res.getReturnCode() == CmdResult.SUCESS_CODE) {
654:                    Response resp;
655:                    StringBuffer buf = new StringBuffer();
656:                    Vector retVect = res.getResult();
657:
658:                    buf.append("<html> <body> <div class=cmdResponse> ");
659:
660:                    for (int i = 0; i < res.getSize(); i++) {
661:                        buf.append((String) retVect.elementAt(i));
662:                        buf.append("<br>");
663:                    }
664:
665:                    buf.append(" </div> </body> </html>");
666:
667:                    resp = new Response(HTTPCodes.HTTP_OK, MimeTypes.MIME_HTML,
668:                            buf.toString());
669:                    return resp;
670:                } else { //error
671:
672:                    return new Response(
673:                            HTTPCodes.HTTP_INTERNALERROR,
674:                            MimeTypes.MIME_HTML,
675:                            "<html> <body> <div class=cmdResponse> Error occured during OPML import </div> </body> </html>");
676:                }
677:            }
678:
679:            private Response handleCGIRequest(String uri, String method,
680:                    Properties header, Properties params) {
681:                String command = params.getProperty("command");
682:                if (command == null)
683:                    return new Response();
684:                System.out.println("CGI cmd:" + command);
685:                int code = AppCmd.getOpCode(command);
686:
687:                switch (code) {
688:                case AppCmd.ADD_LINK:
689:                    return handleAddLinkCmd(code, params);
690:                case AppCmd.OPML_IMPORT:
691:                    return handleOpmlImportCmd(code, params);
692:                case AppCmd.GET_CATEGORIES:
693:                    return handleGetCategoriesCmd(code, params);
694:                case AppCmd.GET_FEEDNAMES:
695:                    return handleGetFeedNamesCmd(code, params);
696:                case AppCmd.GET_FEEDNAMES_W_PAGE_LINK:
697:                    return handleGetFeedNamesWithPageLinkCmd(code, params,
698:                            false);
699:                case AppCmd.GET_ALL_FEEDNAMES_W_PAGE_LINK:
700:                    return handleGetFeedNamesWithPageLinkCmd(code, params, true);
701:                case AppCmd.GET_FEEDNAMES_W_TABLEDATA_PAGE_LINK:
702:                    return handleGetFeedNamesWithTableDataPageLinkCmd(code,
703:                            params, false);
704:                case AppCmd.GET_ALL_FEEDNAMES_W_TABLEDATA_PAGE_LINK:
705:                    return handleGetFeedNamesWithTableDataPageLinkCmd(code,
706:                            params, true);
707:                case AppCmd.GET_STYLE_INFO:
708:                    return handleGetStyleInfoCmd(code, params);
709:                case AppCmd.SAVE_STYLE_INFO:
710:                    return handleSaveStyleInfoCmd(code, params);
711:                case AppCmd.GET_FEEDNAMES_W_FEEDSOURCE_LINK:
712:                    return handleGetFeedNamesWithFeedSourceLinkCmd(code, params);
713:                case AppCmd.DEL_LINK:
714:                    return handleDeleteLinkCmd(code, params);
715:                case AppCmd.GET_FEEDNAMES_W_TABLEDATA_PAGE_LINK_FRM_SOURCEURL:
716:                    return handleGetFeednamesPageLinkFromSourceUrlCmd(code,
717:                            params);
718:
719:                default:
720:                    break;
721:                }
722:
723:                return new Response();
724:            }
725:
726:            public Response serve(String uri, String method, Properties header,
727:                    Properties parms) {
728:                Enumeration e = parms.propertyNames();
729:
730:                if (DEBUG) {
731:                    int i = 0;
732:                    Enumeration tmp = parms.propertyNames();
733:                    while (tmp.hasMoreElements()) {
734:                        System.out.println("PARAM[" + i + "]=" + "<"
735:                                + tmp.nextElement() + ">");
736:                        i++;
737:                    }
738:                }
739:
740:                if (e.hasMoreElements()) // the user passed a CGI request 
741:                    // which results in parameters being
742:                    // sent through HTTP message.
743:                    return handleCGIRequest(uri, method, header, parms);
744:                else
745:                    return serveFile(uri, header, new File(rootDir), true);
746:            }
747:
748:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.