Source Code Cross Referenced for EditWizardHandler.java in  » Portal » Open-Portal » com » sun » portal » app » blog » handler » 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 » Portal » Open Portal » com.sun.portal.app.blog.handler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright ? 2006 Sun Microsystems, Inc. All rights reserved.
003:         *
004:         * Sun Microsystems, Inc. has intellectual property rights relating to
005:         * technology embodied in the product that is described in this document.
006:         * In particular, and without limitation, these intellectual property
007:         * rights may include one or more of the U.S. patents listed at
008:         * http://www.sun.com/patents and one or more additional patents or
009:         * pending patent applications in the U.S. and in other countries.
010:         *
011:         * U.S. Government Rights - Commercial software. Government users are subject
012:         * to the Sun Microsystems, Inc. standard license agreement and applicable
013:         * provisions of the FAR and its supplements. Use is subject to license terms.
014:         * This distribution may include materials developed by third parties.
015:         * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
016:         * trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
017:         */
018:        package com.sun.portal.app.blog.handler;
019:
020:        import com.sun.portal.app.blog.BlogPortletException;
021:        import com.sun.portal.app.blog.Resources;
022:        import com.sun.portal.app.blog.env.AbstractPrefs;
023:        import com.sun.portal.app.blog.env.AbstractSearch;
024:        import com.sun.portal.app.blog.env.User;
025:        import com.sun.portal.app.blog.env.App;
026:        import com.sun.portal.app.blog.httpverb.Delete;
027:        import com.sun.portal.app.blog.httpverb.Get;
028:        import com.sun.portal.app.blog.httpverb.HttpVerbException;
029:        import com.sun.portal.app.blog.httpverb.Post;
030:        import com.sun.portal.app.blog.model.EditUserBean;
031:        import com.sun.portal.app.blog.model.EditWeblogBean;
032:        import com.sun.portal.app.blog.model.FeedBean;
033:        import java.io.ByteArrayInputStream;
034:        import java.io.IOException;
035:        import java.io.InputStream;
036:        import java.io.UnsupportedEncodingException;
037:        import java.net.MalformedURLException;
038:        import java.net.URL;
039:        import java.util.Collections;
040:        import java.util.HashSet;
041:        import java.util.Set;
042:        import com.sun.syndication.feed.atom.Feed;
043:        import com.sun.syndication.feed.atom.Link;
044:        import com.sun.syndication.io.FeedException;
045:        import com.sun.syndication.io.WireFeedInput;
046:        import java.util.List;
047:        import java.util.regex.Pattern;
048:        import javax.faces.application.FacesMessage;
049:        import javax.faces.component.UIComponent;
050:        import javax.faces.component.UIInput;
051:        import javax.faces.context.FacesContext;
052:        import org.apache.roller.webservices.adminapi.sdk.Entry;
053:        import org.apache.roller.webservices.adminapi.sdk.MemberEntry;
054:        import org.apache.roller.webservices.adminapi.sdk.MemberEntrySet;
055:        import org.apache.roller.webservices.adminapi.sdk.UnexpectedRootElementException;
056:        import org.apache.roller.webservices.adminapi.sdk.UserEntry;
057:        import org.apache.roller.webservices.adminapi.sdk.UserEntrySet;
058:        import org.apache.roller.webservices.adminapi.sdk.WeblogEntry;
059:        import org.apache.roller.webservices.adminapi.sdk.WeblogEntrySet;
060:        import org.jdom.JDOMException;
061:        import org.xml.sax.InputSource;
062:        import javax.faces.context.ExternalContext;
063:        import javax.faces.context.FacesContext;
064:        import javax.portlet.PortletRequest;
065:
066:        public class EditWizardHandler {
067:            private static final AbstractPrefs prefs = AbstractPrefs
068:                    .getInstance();
069:            private static final AbstractSearch search = AbstractSearch
070:                    .getInstance();
071:            private static final User user = User.getInstance();
072:            private static final App app = App.getInstance();
073:
074:            private static Resources resources = new Resources(
075:                    "com.sun.portal.app.blog.handler.EditWizardHandler");
076:            private static final Pattern USER_NAME_PATTERN = Pattern
077:                    .compile("[a-zA-Z0-9]{3,32}");
078:            private static final Pattern WEBLOG_HANDLE_PATTERN = Pattern
079:                    .compile("[a-zA-Z0-9]{3,16}");
080:
081:            private EditUserBean editUserBean;
082:            private EditWeblogBean editWeblogBean;
083:            private MessageHandler messageHandler;
084:            private FeedBean feedBean;
085:            private FeedHandler feedHandler;
086:
087:            public String editUserNextAction() {
088:                if (getEditUserBean().isNewSelected()) {
089:                    return "editUserNew";
090:                } else if (getEditUserBean().isExistingSelected()) {
091:                    return "editUserExisting";
092:                }
093:
094:                // nothing selected, do not advance
095:                getMessageHandler().addError(
096:                        resources.get("editUserNextAction.makeSelection"));
097:                return "failure";
098:            }
099:
100:            public String editUserNewNextAction() {
101:                try {
102:                    if (userExists()) {
103:                        getMessageHandler()
104:                                .addError(
105:                                        resources
106:                                                .get("editUserNewNextAction.userExists"));
107:                        return "failure";
108:                    } else {
109:                        getEditUserBean().setHasMembership(false);
110:                        if (getFeedHandler().isWizardConfigMode()) {
111:                            return "editWeblog";
112:                        } else {
113:                            return "editSummary";
114:                        }
115:                    }
116:                } catch (BlogPortletException bpe) {
117:                    getMessageHandler().addError(
118:                            resources.get("editUserNewNextAction.exception"),
119:                            bpe.getMessage());
120:                    return "failure";
121:                }
122:            }
123:
124:            public String editUserExistingNextAction() {
125:                try {
126:                    if (!userExists()) {
127:                        getMessageHandler()
128:                                .addError(
129:                                        resources
130:                                                .get("editUserExistingNextAction.userDoesNotExist"));
131:                        return "failure";
132:                    } else {
133:                        getEditUserBean().setHasMembership(
134:                                userHasPermission(prefs.getMemberPermission()));
135:                        if (getFeedHandler().isWizardConfigMode()) {
136:                            return "editWeblog";
137:                        } else {
138:                            return "editSummary";
139:                        }
140:                    }
141:                } catch (BlogPortletException bpe) {
142:                    getMessageHandler()
143:                            .addError(
144:                                    resources
145:                                            .get("editUserExistingNextAction.exception"),
146:                                    bpe.getMessage());
147:                    return "failure";
148:                }
149:            }
150:
151:            public String editWeblogNextAction() {
152:                if (getEditWeblogBean().isNewSelected()) {
153:                    return "editWeblogNew";
154:                } else if (getEditWeblogBean().isExistingSelected()) {
155:                    return "editWeblogExisting";
156:                }
157:
158:                // nothing selected, do not advance
159:                getMessageHandler().addError(
160:                        resources.get("editWeblogNextAction.makeSelection"));
161:                return "nop";
162:            }
163:
164:            public String editWeblogPreviousAction() {
165:                if (getEditUserBean().isNewSelected()) {
166:                    return "editUserNew";
167:                } else if (getEditUserBean().isExistingSelected()) {
168:                    return "editUserExisting";
169:                }
170:
171:                // if neither selected, return to start
172:                return "edit";
173:            }
174:
175:            public String editWeblogNewNextAction() {
176:                try {
177:                    if (weblogExists()) {
178:                        getMessageHandler()
179:                                .addError(
180:                                        resources
181:                                                .get("editWeblogNewNextAction.weblogExists"));
182:                        return "failure";
183:                    } else {
184:                        return "editSummary";
185:                    }
186:                } catch (BlogPortletException bpe) {
187:                    getMessageHandler().addError(
188:                            resources.get("editWeblogNewNextAction.exception"),
189:                            bpe.getMessage());
190:                    return "failure";
191:                }
192:            }
193:
194:            public String editWeblogExistingNextAction() {
195:                try {
196:                    if (!weblogExists()) {
197:                        getMessageHandler()
198:                                .addError(
199:                                        resources
200:                                                .get("editWeblogExistingNextAction.weblogDoesNotExist"));
201:                        return "failure";
202:                    } else {
203:                        return "editSummary";
204:                    }
205:                } catch (BlogPortletException bpe) {
206:                    getMessageHandler()
207:                            .addError(
208:                                    resources
209:                                            .get("editWeblogExistingNextAction.exception"),
210:                                    bpe.getMessage());
211:                    return "failure";
212:                }
213:            }
214:
215:            public String editSummaryPreviousAction() {
216:                if (getFeedHandler().isWizardConfigMode()) {
217:                    if (getEditWeblogBean().isNewSelected()) {
218:                        return "editWeblogNew";
219:                    } else {
220:                        return "editWeblogExisting";
221:                    }
222:                } else {
223:                    if (getEditUserBean().isNewSelected()) {
224:                        return "editUserNew";
225:                    } else {
226:                        return "editUserExisting";
227:                    }
228:
229:                }
230:            }
231:
232:            public String editSummaryFinishedAction() {
233:                // keep track of the operations we perform, so we know what to backout
234:                // if there was a problem
235:                boolean setCredentials = false;
236:                boolean createdWeblog = false;
237:                boolean setWeblog = false;
238:                boolean createdUser = false;
239:
240:                // keep track of original preferences, so we can re-set to old
241:                // values if there was a problem
242:                String currentAppUserName = null;
243:                String currentAppUserPassword = null;
244:                String currentHandle = null;
245:                String currentAppEntriesUrl = null;
246:
247:                try {
248:                    currentAppUserName = prefs.getAppUserName();
249:                    currentAppUserPassword = prefs.getAppUserPassword();
250:                    currentHandle = prefs.getHandle();
251:                    currentAppEntriesUrl = prefs.getAppEntriesUrl();
252:
253:                    // set first, so other operations can reference
254:                    // the values from the prefs object
255:                    // always re-set
256:                    // if there are no changes, this is a no-op
257:
258:                    // user name / pass
259:                    setCredentials = true;
260:                    prefs.setAppUserName(getEditUserBean().getUserName());
261:                    prefs.setAppUserPassword(getEditUserBean().getPassword());
262:                    prefs.store();
263:
264:                    // weblog handle / entries url
265:                    try {
266:                        setWeblog = true;
267:                        String handle = getEditWeblogBean().getHandle();
268:                        if (handle == null) {
269:                            // wizard-user-only case
270:                            handle = prefs.getHandle();
271:                        }
272:                        String appEntriesUrl = app.getInstance().getEntriesUrl(
273:                                new URL(prefs.getAppUrl()), handle).toString();
274:
275:                        prefs.setHandle(handle);
276:                        prefs.setAppEntriesUrl(appEntriesUrl);
277:                        prefs.store();
278:                    } catch (MalformedURLException mfue) {
279:                        throw new BlogPortletException(mfue);
280:                    }
281:
282:                    if (getEditUserBean().isNewSelected()) {
283:                        createdUser = true;
284:                        createUser();
285:                    }
286:
287:                    if (getEditWeblogBean().isNewSelected()) {
288:                        createdWeblog = true;
289:                        createWeblog();
290:                    }
291:
292:                    if (!getEditUserBean().isHasMembership()) {
293:                        addMembership();
294:                    }
295:                } catch (BlogPortletException bpe) {
296:                    getMessageHandler()
297:                            .addError(
298:                                    resources
299:                                            .get("editSummaryFinishedAction.exception"),
300:                                    bpe);
301:
302:                    // attempt to backout operations performed above
303:                    try {
304:                        prefs.setAppUserName(currentAppUserName);
305:                        prefs.setAppUserPassword(currentAppUserPassword);
306:                        prefs.setHandle(currentHandle);
307:                        prefs.setAppEntriesUrl(currentAppEntriesUrl);
308:
309:                        prefs.store();
310:                    } catch (BlogPortletException bpe2) {
311:                        // nothing
312:                    }
313:
314:                    if (createdWeblog) {
315:                        try {
316:                            deleteWeblog();
317:                        } catch (BlogPortletException bpe4) {
318:                            // nothing
319:                        }
320:                    }
321:                    if (createdUser) {
322:                        try {
323:                            deleteUser();
324:                        } catch (BlogPortletException bpe3) {
325:                            // nothing
326:                        }
327:                    }
328:
329:                    // do not need to backout added membership,
330:                    // removal of weblog will handle this
331:                    return "failure";
332:                }
333:
334:                // re-initialize feed bean
335:                getFeedBean().setInitialized(false);
336:                return "editResults";
337:            }
338:
339:            private void createUser() throws BlogPortletException {
340:                UserEntry userEntry = new UserEntry(getEditUserBean()
341:                        .getUserName(), prefs.getAappUrl());
342:
343:                userEntry.setFullName(getEditUserBean().getFullName());
344:                userEntry.setPassword(getEditUserBean().getPassword());
345:                userEntry.setLocale(user.getLocale().toString());
346:                userEntry.setTimezone(user.getTimeZone().getID());
347:                userEntry.setEmailAddress(getEditUserBean().getEmail());
348:                userEntry.setEnabled(Boolean.TRUE);
349:
350:                UserEntrySet ues = new UserEntrySet(prefs.getAappUrl());
351:                ues.setEntries(new UserEntry[] { userEntry });
352:
353:                String url = ues.getHref();
354:                String body = ues.toString();
355:
356:                try {
357:                    InputStream bodyStream = new ByteArrayInputStream(body
358:                            .getBytes("UTF-8"));
359:
360:                    Post post = new Post(new URL(url), prefs.getAappUserName(),
361:                            prefs.getAappUserPassword(), bodyStream,
362:                            "application/xml; utf8");
363:                    int status = post.execute();
364:                    if (!post.success()) {
365:                        throw new BlogPortletException(
366:                                "POST failed, HTTP status code: " + status);
367:                    }
368:                } catch (UnsupportedEncodingException uec) {
369:                    throw new BlogPortletException(uec);
370:                } catch (MalformedURLException mfue) {
371:                    throw new BlogPortletException(mfue);
372:                } catch (HttpVerbException ve) {
373:                    throw new BlogPortletException(ve);
374:                }
375:            }
376:
377:            private void deleteUser() throws BlogPortletException {
378:                UserEntry userEntry = new UserEntry(getEditUserBean()
379:                        .getUserName(), prefs.getAappUrl());
380:
381:                String url = userEntry.getHref();
382:
383:                try {
384:                    Delete delete = new Delete(new URL(url), prefs
385:                            .getAappUserName(), prefs.getAappUserPassword());
386:                    int status = delete.execute();
387:                    if (!delete.success()) {
388:                        throw new BlogPortletException(
389:                                "DELETE failed, HTTP status code: " + status);
390:                    }
391:                } catch (MalformedURLException mfue) {
392:                    throw new BlogPortletException(mfue);
393:                } catch (HttpVerbException ve) {
394:                    throw new BlogPortletException(ve);
395:                }
396:            }
397:
398:            private void addMembership() throws BlogPortletException {
399:                try {
400:                    MemberEntry memberEntry = new MemberEntry(
401:                            prefs.getHandle(), prefs.getAppUserName(), prefs
402:                                    .getAappUrl());
403:
404:                    memberEntry.setPermission(prefs.getMemberPermission());
405:
406:                    MemberEntrySet mes = new MemberEntrySet(prefs.getAappUrl());
407:                    mes.setEntries(new MemberEntry[] { memberEntry });
408:
409:                    String url = mes.getHref();
410:                    String body = mes.toString();
411:
412:                    InputStream bodyStream = new ByteArrayInputStream(body
413:                            .getBytes("UTF-8"));
414:
415:                    Post post = new Post(new URL(url), prefs.getAappUserName(),
416:                            prefs.getAappUserPassword(), bodyStream,
417:                            "application/xml; utf8");
418:                    int status = post.execute();
419:                    if (!post.success()) {
420:                        throw new BlogPortletException(
421:                                "POST failed, HTTP status code: " + status);
422:                    }
423:                } catch (UnsupportedEncodingException uec) {
424:                    throw new BlogPortletException(uec);
425:                } catch (MalformedURLException mfue) {
426:                    throw new BlogPortletException(mfue);
427:                } catch (HttpVerbException ve) {
428:                    throw new BlogPortletException(ve);
429:                }
430:            }
431:
432:            private boolean userExists() throws BlogPortletException {
433:                UserEntry ue = new UserEntry(getEditUserBean().getUserName(),
434:                        prefs.getAappUrl());
435:                String url = ue.getHref();
436:
437:                try {
438:                    Get get = new Get(new URL(url), prefs.getAappUserName(),
439:                            prefs.getAappUserPassword());
440:                    int status = get.execute();
441:                    if (!get.success()) {
442:                        return false;
443:                    }
444:                    return true;
445:                } catch (MalformedURLException mfue) {
446:                    throw new BlogPortletException(mfue);
447:                } catch (HttpVerbException ve) {
448:                    throw new BlogPortletException(ve);
449:                }
450:            }
451:
452:            private boolean userHasPermission(String perm)
453:                    throws BlogPortletException {
454:                Set perms = getUserPermissions();
455:                boolean contains = perms.contains(perm);
456:
457:                return contains;
458:            }
459:
460:            private Set getUserPermissions() throws BlogPortletException {
461:                MemberEntry me = new MemberEntry(prefs.getHandle(),
462:                        getEditUserBean().getUserName(), prefs.getAappUrl());
463:                String url = me.getHref();
464:
465:                try {
466:                    Get get = new Get(new URL(url), prefs.getAappUserName(),
467:                            prefs.getAappUserPassword());
468:                    int status = get.execute();
469:                    if (!get.success()) {
470:                        return Collections.EMPTY_SET;
471:                    }
472:                    InputStream bodyStream = get.getResponseBody();
473:                    MemberEntrySet mes = new MemberEntrySet(bodyStream, prefs
474:                            .getAappUrl());
475:                    Entry[] entries = mes.getEntries();
476:                    Set perms = null;
477:                    if (entries != null) {
478:                        perms = new HashSet();
479:                        for (int i = 0; i < entries.length; i++) {
480:                            MemberEntry entry = (MemberEntry) entries[i];
481:                            perms.add(entry.getPermission());
482:                        }
483:                    }
484:
485:                    return perms;
486:                } catch (MalformedURLException mfue) {
487:                    throw new BlogPortletException(mfue);
488:                } catch (HttpVerbException ve) {
489:                    throw new BlogPortletException(ve);
490:                } catch (JDOMException je) {
491:                    throw new BlogPortletException(je);
492:                } catch (IOException ioe) {
493:                    throw new BlogPortletException(ioe);
494:                } catch (UnexpectedRootElementException uree) {
495:                    throw new BlogPortletException(uree);
496:                }
497:
498:            }
499:
500:            private boolean weblogExists() throws BlogPortletException {
501:                WeblogEntry we = new WeblogEntry(getEditWeblogBean()
502:                        .getHandle(), prefs.getAappUrl());
503:                String url = we.getHref();
504:
505:                try {
506:                    Get get = new Get(new URL(url), prefs.getAappUserName(),
507:                            prefs.getAappUserPassword());
508:                    int status = get.execute();
509:                    if (!get.success()) {
510:                        return false;
511:                    }
512:                    return true;
513:                } catch (MalformedURLException mfue) {
514:                    throw new BlogPortletException(mfue);
515:                } catch (HttpVerbException ve) {
516:                    throw new BlogPortletException(ve);
517:                }
518:            }
519:
520:            private WeblogEntry createWeblog() throws BlogPortletException {
521:                try {
522:                    WeblogEntry weblogEntry = new WeblogEntry(
523:                            getEditWeblogBean().getHandle(), prefs.getAappUrl());
524:
525:                    weblogEntry.setHandle(getEditWeblogBean().getHandle());
526:                    weblogEntry.setCreatingUser(prefs.getAppUserName());
527:                    weblogEntry.setName(getEditWeblogBean().getName());
528:                    weblogEntry.setDescription(getEditWeblogBean()
529:                            .getDescription());
530:                    weblogEntry.setEmailAddress(getEditWeblogBean().getEmail());
531:                    weblogEntry.setLocale(user.getLocale().toString());
532:                    weblogEntry.setTimezone(user.getTimeZone().getID());
533:                    weblogEntry.setEnabled(Boolean.TRUE);
534:
535:                    WeblogEntrySet wes = new WeblogEntrySet(prefs.getAappUrl());
536:                    wes.setEntries(new WeblogEntry[] { weblogEntry });
537:
538:                    String url = wes.getHref();
539:                    String body = wes.toString();
540:
541:                    InputStream bodyStream = new ByteArrayInputStream(body
542:                            .getBytes("UTF-8"));
543:
544:                    Post post = new Post(new URL(url), prefs.getAappUserName(),
545:                            prefs.getAappUserPassword(), bodyStream,
546:                            "application/xml; utf8");
547:                    int status = post.execute();
548:                    if (!post.success()) {
549:                        throw new BlogPortletException(
550:                                "POST failed, HTTP status code: " + status);
551:                    }
552:
553:                    InputStream responseStream = post.getResponseBody();
554:                    WeblogEntrySet wesResponse = new WeblogEntrySet(
555:                            responseStream, prefs.getAappUrl());
556:                    if (wesResponse.getEntries() == null
557:                            && wesResponse.getEntries().length == 0) {
558:                        throw new BlogPortletException(
559:                                "failed to get response after weblog creation");
560:                    }
561:
562:                    WeblogEntry weResponse = (WeblogEntry) wesResponse
563:                            .getEntries()[0];
564:                    Feed feed = getWeblogFeed(weResponse);
565:                    indexWeblog(feed);
566:
567:                    return weResponse;
568:                } catch (UnsupportedEncodingException uec) {
569:                    throw new BlogPortletException(uec);
570:                } catch (MalformedURLException mfue) {
571:                    throw new BlogPortletException(mfue);
572:                } catch (HttpVerbException ve) {
573:                    throw new BlogPortletException(ve);
574:                } catch (JDOMException je) {
575:                    throw new BlogPortletException(je);
576:                } catch (IOException ioe) {
577:                    throw new BlogPortletException(ioe);
578:                } catch (UnexpectedRootElementException uree) {
579:                    throw new BlogPortletException(uree);
580:                }
581:
582:            }
583:
584:            private void indexWeblog(Feed feed) throws BlogPortletException {
585:                String weblogLink = getWeblogLink(feed);
586:                String title = feed.getTitle();
587:                String content = null;
588:
589:                // if we can't get the link or the title, we cannot index
590:                // feed is not required to give us those
591:                if (weblogLink != null && weblogLink.length() > 0
592:                        && title != null && title.length() > 0) {
593:                    AbstractSearch srch = search.getNewInstance();
594:                    srch.setPortletRequest(getPortletRequest());
595:                    srch.insert(weblogLink, title, content);
596:                }
597:            }
598:
599:            private void deindexWeblog(Feed feed) throws BlogPortletException {
600:                String weblogLink = getWeblogLink(feed);
601:
602:                // if we can't get the link or the title, we cannot index
603:                // feed is not required to give us those
604:                if (weblogLink != null && weblogLink.length() > 0) {
605:                    search.delete(weblogLink);
606:                }
607:            }
608:
609:            private Feed getWeblogFeed(WeblogEntry we)
610:                    throws BlogPortletException {
611:                String u = we.getAppEntriesUrl();
612:                String user = prefs.getAppUserName();
613:                String pw = prefs.getAppUserPassword();
614:
615:                URL url;
616:                try {
617:                    url = new URL(u);
618:                } catch (MalformedURLException mue) {
619:                    throw new BlogPortletException(mue);
620:                }
621:
622:                Get get = new Get(url, user, pw);
623:                int status = get.execute();
624:                if (!get.success()) {
625:                    throw new BlogPortletException(
626:                            "GET failed, HTTP status code: " + status);
627:                }
628:
629:                try {
630:                    InputStream is = get.getResponseBody();
631:                    InputSource src = new InputSource(is);
632:                    WireFeedInput input = new WireFeedInput();
633:                    Feed feed = (Feed) input.build(src);
634:
635:                    return feed;
636:                } catch (FeedException fe) {
637:                    throw new BlogPortletException(fe);
638:                }
639:            }
640:
641:            private String getWeblogLink(Feed feed) throws BlogPortletException {
642:                List altLinks = feed.getAlternateLinks();
643:                if (altLinks == null || altLinks.size() == 0) {
644:                    return null;
645:                }
646:
647:                Link link = (Link) altLinks.get(0);
648:                return link.getHref();
649:            }
650:
651:            private void deleteWeblog() throws BlogPortletException {
652:                try {
653:                    WeblogEntry weblogEntry = new WeblogEntry(
654:                            getEditWeblogBean().getHandle(), prefs.getAappUrl());
655:
656:                    String url = weblogEntry.getHref();
657:
658:                    Delete delete = new Delete(new URL(url), prefs
659:                            .getAappUserName(), prefs.getAappUserPassword());
660:                    int status = delete.execute();
661:                    if (!delete.success()) {
662:                        throw new BlogPortletException(
663:                                "DELETE failed, HTTP status code: " + status);
664:                    }
665:
666:                    InputStream responseStream = delete.getResponseBody();
667:                    WeblogEntrySet wesResponse = new WeblogEntrySet(
668:                            responseStream, prefs.getAappUrl());
669:                    if (wesResponse.getEntries() == null
670:                            && wesResponse.getEntries().length == 0) {
671:                        throw new BlogPortletException(
672:                                "failed to get response after weblog creation");
673:                    }
674:
675:                    WeblogEntry weResponse = (WeblogEntry) wesResponse
676:                            .getEntries()[0];
677:                    Feed feed = getWeblogFeed(weResponse);
678:                    deindexWeblog(feed);
679:                } catch (HttpVerbException ve) {
680:                    throw new BlogPortletException(ve);
681:                } catch (IOException ioe) {
682:                    throw new BlogPortletException(ioe);
683:                } catch (JDOMException je) {
684:                    throw new BlogPortletException(je);
685:                } catch (UnexpectedRootElementException uree) {
686:                    throw new BlogPortletException(uree);
687:                }
688:            }
689:
690:            public void validateUserName(FacesContext context,
691:                    UIComponent component, Object value) {
692:                String userName = (String) value;
693:
694:                FacesMessage message = null;
695:                if (!USER_NAME_PATTERN.matcher(userName).matches()) {
696:                    ((UIInput) component).setValid(false);
697:                    message = new FacesMessage(resources
698:                            .get("validateUserName.failure"));
699:                    message.setSeverity(FacesMessage.SEVERITY_ERROR);
700:                }
701:
702:                if (message != null) {
703:                    context.addMessage(component.getClientId(context), message);
704:                }
705:            }
706:
707:            public void validateWeblogHandle(FacesContext context,
708:                    UIComponent component, Object value) {
709:                String userName = (String) value;
710:
711:                FacesMessage message = null;
712:                if (!WEBLOG_HANDLE_PATTERN.matcher(userName).matches()) {
713:                    ((UIInput) component).setValid(false);
714:                    message = new FacesMessage(resources
715:                            .get("validateWeblogHandle.failure"));
716:                    message.setSeverity(FacesMessage.SEVERITY_ERROR);
717:                }
718:
719:                if (message != null) {
720:                    context.addMessage(component.getClientId(context), message);
721:                }
722:            }
723:
724:            public void validateConfirmPassword(FacesContext context,
725:                    UIComponent component, Object value) {
726:                String confirm = (String) value;
727:                UIComponent passwordComponent = component
728:                        .findComponent("passwordInputSecret");
729:                String password = (String) passwordComponent.getAttributes()
730:                        .get("value");
731:
732:                FacesMessage message = null;
733:                if (!confirm.equals(password)) {
734:                    ((UIInput) component).setValid(false);
735:                    message = new FacesMessage(resources
736:                            .get("validateConfirmPassword.failure"));
737:                    message.setSeverity(FacesMessage.SEVERITY_ERROR);
738:                }
739:
740:                if (message != null) {
741:                    context.addMessage(component.getClientId(context), message);
742:                }
743:            }
744:
745:            public EditUserBean getEditUserBean() {
746:                return editUserBean;
747:            }
748:
749:            public void setEditUserBean(EditUserBean editUserBean) {
750:                this .editUserBean = editUserBean;
751:            }
752:
753:            public EditWeblogBean getEditWeblogBean() {
754:                return editWeblogBean;
755:            }
756:
757:            public void setEditWeblogBean(EditWeblogBean editWeblogBean) {
758:                this .editWeblogBean = editWeblogBean;
759:            }
760:
761:            public MessageHandler getMessageHandler() {
762:                return messageHandler;
763:            }
764:
765:            public void setMessageHandler(MessageHandler messageHandler) {
766:                this .messageHandler = messageHandler;
767:            }
768:
769:            public FeedBean getFeedBean() {
770:                return feedBean;
771:            }
772:
773:            public void setFeedBean(FeedBean feedBean) {
774:                this .feedBean = feedBean;
775:            }
776:
777:            public FeedHandler getFeedHandler() {
778:                return feedHandler;
779:            }
780:
781:            public void setFeedHandler(FeedHandler feedHandler) {
782:                this .feedHandler = feedHandler;
783:            }
784:
785:            private PortletRequest getPortletRequest() {
786:                ExternalContext econtext = FacesContext.getCurrentInstance()
787:                        .getExternalContext();
788:                PortletRequest preq = (PortletRequest) econtext.getRequest();
789:
790:                return preq;
791:            }
792:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.