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.model.EditManualBean;
024: import com.sun.portal.app.blog.model.FeedBean;
025: import java.net.MalformedURLException;
026: import java.net.URL;
027: import javax.faces.application.FacesMessage;
028: import javax.faces.component.UIComponent;
029: import javax.faces.component.UIInput;
030: import javax.faces.context.FacesContext;
031:
032: public class EditManualHandler {
033: private static final AbstractPrefs prefs = AbstractPrefs
034: .getInstance();
035: private static Resources resources = new Resources(
036: "com.sun.portal.app.blog.handler.EditManualHandler");
037:
038: private EditManualBean editManualBean;
039: private FeedBean feedBean;
040: private MessageHandler messageHandler;
041:
042: public String submitAction() {
043: try {
044: String appEntriesUrl = getEditManualBean()
045: .getAppEntriesUrl();
046: String userName = getEditManualBean().getAppUserName();
047: String userPassword = getEditManualBean()
048: .getAppUserPassword();
049:
050: prefs.setAppEntriesUrl(appEntriesUrl);
051: prefs.setAppUserName(userName);
052: prefs.setAppUserPassword(userPassword);
053:
054: prefs.store();
055:
056: // re-initialize feed bean
057: getFeedBean().setInitialized(false);
058: return "success";
059: } catch (BlogPortletException bpe) {
060: getMessageHandler().addError(
061: resources.get("editAction.exception"), bpe);
062: return "failure";
063: }
064: }
065:
066: public void validateUrl(FacesContext context,
067: UIComponent component, Object value) {
068: String url = (String) value;
069:
070: FacesMessage message = null;
071: try {
072: URL u = new URL(url);
073: } catch (MalformedURLException mfue) {
074: ((UIInput) component).setValid(false);
075: message = new FacesMessage(resources
076: .get("validateUrl.failure"));
077: message.setSeverity(FacesMessage.SEVERITY_ERROR);
078: }
079:
080: if (message != null) {
081: context.addMessage(component.getClientId(context), message);
082: }
083: }
084:
085: public EditManualBean getEditManualBean() {
086: return editManualBean;
087: }
088:
089: public void setEditManualBean(EditManualBean editManualBean) {
090: this .editManualBean = editManualBean;
091: }
092:
093: public FeedBean getFeedBean() {
094: return feedBean;
095: }
096:
097: public void setFeedBean(FeedBean feedBean) {
098: this .feedBean = feedBean;
099: }
100:
101: public MessageHandler getMessageHandler() {
102: return messageHandler;
103: }
104:
105: public void setMessageHandler(MessageHandler messageHandler) {
106: this.messageHandler = messageHandler;
107: }
108: }
|