diff options
author | Damian Minkov <damencho@jitsi.org> | 2007-06-01 15:45:11 +0000 |
---|---|---|
committer | Damian Minkov <damencho@jitsi.org> | 2007-06-01 15:45:11 +0000 |
commit | 03262f0dd4b61a20d5e13832e70a10e8b3889b7b (patch) | |
tree | d03f92e081236e5307d8f6902b28ded71d665ae8 /src/net/java/sip/communicator/plugin | |
parent | 2dfda989832e5daf4a72a39a2b41f23a533ef806 (diff) | |
download | jitsi-03262f0dd4b61a20d5e13832e70a10e8b3889b7b.zip jitsi-03262f0dd4b61a20d5e13832e70a10e8b3889b7b.tar.gz jitsi-03262f0dd4b61a20d5e13832e70a10e8b3889b7b.tar.bz2 |
RSS ProtocolProvider.
Diffstat (limited to 'src/net/java/sip/communicator/plugin')
7 files changed, 789 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/plugin/rssaccregwizz/FirstWizardPage.java b/src/net/java/sip/communicator/plugin/rssaccregwizz/FirstWizardPage.java new file mode 100644 index 0000000..49c7c44 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/rssaccregwizz/FirstWizardPage.java @@ -0,0 +1,265 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.rssaccregwizz; + +import java.util.*; + +import java.awt.*; +import javax.swing.*; +import javax.swing.event.*; + +import net.java.sip.communicator.service.gui.*; +import net.java.sip.communicator.service.protocol.*; + +/** + * The <tt>FirstWizardPage</tt> is the page, where user could enter the user ID + * and the password of the account. + * + * @author Emil Ivov/Jean-Albert Vescovo + */ +public class FirstWizardPage + extends JPanel implements WizardPage, DocumentListener +{ + + public static final String FIRST_PAGE_IDENTIFIER = "FirstPageIdentifier"; + + private JPanel userPassPanel = new JPanel(new BorderLayout(10, 10)); + + private JPanel labelsPanel = new JPanel(); + + private JLabel existingAccountLabel = + new JLabel("RSS account already exists !"); + + private JLabel creatingAccountLabel = + new JLabel("Press next to creat your RSS account..."); + + private JTextField userIDField = new JTextField(); + + private JPanel mainPanel = new JPanel(); + + private Object nextPageIdentifier = WizardPage.SUMMARY_PAGE_IDENTIFIER; + + private RssAccountRegistration registration = null; + + private WizardContainer wizardContainer; + + /** + * Creates an instance of <tt>FirstWizardPage</tt>. + * @param registration the <tt>RssAccountRegistration</tt>, where + * all data through the wizard are stored + * @param wizardContainer the wizardContainer, where this page will + * be added + */ + public FirstWizardPage(RssAccountRegistration registration, + WizardContainer wizardContainer) + { + + super(new BorderLayout()); + + this.wizardContainer = wizardContainer; + + this.registration = registration; + + this.setPreferredSize(new Dimension(300, 150)); + + mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); + + this.init(); + + this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + + this.labelsPanel.setLayout(new BoxLayout(labelsPanel, BoxLayout.Y_AXIS)); + } + + /** + * Initializes all panels, buttons, etc. + */ + private void init() + { + this.userIDField.getDocument().addDocumentListener(this); + + this.existingAccountLabel.setForeground(Color.RED); + + this.creatingAccountLabel.setForeground(Color.BLUE); + + labelsPanel.add(creatingAccountLabel); + + if(!isExistingAccount("rss")){ + labelsPanel.remove(existingAccountLabel); + labelsPanel.add(creatingAccountLabel); + setNextButtonAccordingToUserID(true); + } + else{ + labelsPanel.remove(creatingAccountLabel); + labelsPanel.add(existingAccountLabel); + setNextButtonAccordingToUserID(false); + } + + userPassPanel.add(labelsPanel, BorderLayout.CENTER); + + userPassPanel.setBorder(BorderFactory + .createTitledBorder("RSS account creation...")); + + this.add(userPassPanel, BorderLayout.CENTER); + } + + /** + * Implements the <code>WizardPage.getIdentifier</code> to return + * this page identifier. + * + * @return the Identifier of the first page in this wizard. + */ + public Object getIdentifier() + { + return FIRST_PAGE_IDENTIFIER; + } + + /** + * Implements the <code>WizardPage.getNextPageIdentifier</code> to return + * the next page identifier - the summary page. + * + * @return the identifier of the page following this one. + */ + public Object getNextPageIdentifier() + { + return nextPageIdentifier; + } + + /** + * Implements the <code>WizardPage.getBackPageIdentifier</code> to return + * the next back identifier - the default page. + * + * @return the identifier of the default wizard page. + */ + public Object getBackPageIdentifier() + { + return WizardPage.DEFAULT_PAGE_IDENTIFIER; + } + + /** + * Implements the <code>WizardPage.getWizardForm</code> to return + * this panel. + * + * @return the component to be displayed in this wizard page. + */ + public Object getWizardForm() + { + return this; + } + + /** + * Before this page is displayed enables or disables the "Next" wizard + * button according to whether the UserID field is empty. + */ + public void pageShowing() + { + if(isExistingAccount("Rss")) setNextButtonAccordingToUserID(false); + else setNextButtonAccordingToUserID(true); + } + + /** + * Saves the user input when the "Next" wizard buttons is clicked. + */ + public void pageNext() + { + nextPageIdentifier = SUMMARY_PAGE_IDENTIFIER; + userPassPanel.remove(existingAccountLabel); + registration.setUserID("Rss"); + registration.setPassword("rss"); + } + + /** + * Enables or disables the "Next" wizard button according to whether the + * User ID field is empty. + */ + private void setNextButtonAccordingToUserID(boolean newOne) + { + if(!newOne) + { + wizardContainer.setNextFinishButtonEnabled(false); + } + else + { + wizardContainer.setNextFinishButtonEnabled(true); + } + } + + /** + * Handles the <tt>DocumentEvent</tt> triggered when user types in the + * User ID field. Enables or disables the "Next" wizard button according to + * whether the User ID field is empty. + * + * @param event the event containing the update. + */ + public void insertUpdate(DocumentEvent event) + { + } + + /** + * Handles the <tt>DocumentEvent</tt> triggered when user deletes letters + * from the UserID field. Enables or disables the "Next" wizard button + * according to whether the UserID field is empty. + * + * @param event the event containing the update. + */ + public void removeUpdate(DocumentEvent event) + { + } + + public void changedUpdate(DocumentEvent event) + { + } + + public void pageHiding() + { + } + + public void pageShown() + { + } + + public void pageBack() + { + } + + /** + * Fills the UserID and Password fields in this panel with the data comming + * from the given protocolProvider. + * @param protocolProvider The <tt>ProtocolProviderService</tt> to load the + * data from. + */ + public void loadAccount(ProtocolProviderService protocolProvider) + { + } + + /** + * Verifies whether there is already an account installed with the same + * details as the one that the user has just entered. + * + * @param userID the name of the user that the account is registered for + * @return true if there is already an account for this userID and false + * otherwise. + */ + private boolean isExistingAccount(String userID) + { + ProtocolProviderFactory factory + = RssAccRegWizzActivator.getRssProtocolProviderFactory(); + + ArrayList registeredAccounts = factory.getRegisteredAccounts(); + + for (int i = 0; i < registeredAccounts.size(); i++) + { + AccountID accountID = (AccountID) registeredAccounts.get(i); + + if (userID.equalsIgnoreCase(accountID.getUserID())) + { + return true; + } + } + return false; + } +} diff --git a/src/net/java/sip/communicator/plugin/rssaccregwizz/Resources.java b/src/net/java/sip/communicator/plugin/rssaccregwizz/Resources.java new file mode 100644 index 0000000..cde8560 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/rssaccregwizz/Resources.java @@ -0,0 +1,95 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.rssaccregwizz; + +import java.io.*; +import java.util.*; + +import net.java.sip.communicator.util.*; + +/** + * The Messages class manages the access to the internationalization + * properties files. + * + * @author Emil Ivov + */ +public class Resources +{ + + private static Logger log = Logger.getLogger(Resources.class); + + private static final String BUNDLE_NAME + = "net.java.sip.communicator.plugin.rssaccregwizz.resources"; + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle + .getBundle(BUNDLE_NAME); + + public static ImageID GIBBERISH_LOGO = new ImageID("protocolIcon"); + + public static ImageID PAGE_IMAGE = new ImageID("pageImage"); + + /** + * Returns an internationalized string corresponding to the given key. + * @param key The key of the string. + * @return An internationalized string corresponding to the given key. + */ + public static String getString(String key) + { + try + { + return RESOURCE_BUNDLE.getString(key); + + } + catch (MissingResourceException exc) + { + return '!' + key + '!'; + } + } + + /** + * Loads an image from a given image identifier. + * @param imageID The identifier of the image. + * @return The image for the given identifier. + */ + public static byte[] getImage(ImageID imageID) + { + byte[] image = new byte[100000]; + + String path = Resources.getString(imageID.getId()); + try + { + Resources.class.getClassLoader() + .getResourceAsStream(path).read(image); + + } + catch (IOException exc) + { + log.error("Failed to load image:" + path, exc); + } + + return image; + } + + /** + * Represents the Image Identifier. + */ + public static class ImageID + { + private String id; + + private ImageID(String id) + { + this.id = id; + } + + public String getId() + { + return id; + } + } + +} diff --git a/src/net/java/sip/communicator/plugin/rssaccregwizz/RssAccRegWizzActivator.java b/src/net/java/sip/communicator/plugin/rssaccregwizz/RssAccRegWizzActivator.java new file mode 100644 index 0000000..b68dd37 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/rssaccregwizz/RssAccRegWizzActivator.java @@ -0,0 +1,109 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.rssaccregwizz; + +import org.osgi.framework.*; +import net.java.sip.communicator.service.configuration.*; +import net.java.sip.communicator.service.gui.*; +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.util.*; + +/** + * Registers the <tt>RssAccountRegistrationWizard</tt> in the UI Service. + * + * @author Emil Ivov + */ +public class RssAccRegWizzActivator + implements BundleActivator +{ + private static Logger logger = Logger.getLogger( + RssAccRegWizzActivator.class.getName()); + + /** + * A currently valid bundle context. + */ + public static BundleContext bundleContext; + + /** + * A currently valid reference to the configuration service. + */ + private static ConfigurationService configService; + + /** + * Starts this bundle. + * @param bc the currently valid <tt>BundleContext</tt>. + */ + public void start(BundleContext bc) + { + logger.info("Loading rss account wizard."); + + bundleContext = bc; + + ServiceReference uiServiceRef = bundleContext + .getServiceReference(UIService.class.getName()); + + UIService uiService + = (UIService) bundleContext.getService(uiServiceRef); + + AccountRegistrationWizardContainer wizardContainer + = uiService.getAccountRegWizardContainer(); + + RssAccountRegistrationWizard rssWizard + = new RssAccountRegistrationWizard(wizardContainer); + + wizardContainer.addAccountRegistrationWizard(rssWizard); + + logger.info("Rss account registration wizard [STARTED]."); + } + + /** + * Called when this bundle is stopped so the Framework can perform the + * bundle-specific activities necessary to stop the bundle. + * + * @param context The execution context of the bundle being stopped. + */ + public void stop(BundleContext context) + { + + } + + /** + * Returns the <tt>ProtocolProviderFactory</tt> for the Rss protocol. + * @return the <tt>ProtocolProviderFactory</tt> for the Rss protocol + */ + public static ProtocolProviderFactory getRssProtocolProviderFactory() + { + + ServiceReference[] serRefs = null; + + String osgiFilter = "(" + + ProtocolProviderFactory.PROTOCOL + + "=" + "Rss" + ")"; + + try + { + serRefs = bundleContext.getServiceReferences( + ProtocolProviderFactory.class.getName(), osgiFilter); + } + catch (InvalidSyntaxException ex) + { + logger.error(ex); + } + + return (ProtocolProviderFactory) bundleContext.getService(serRefs[0]); + } + + /** + * Returns the bundleContext that we received when we were started. + * + * @return a currently valid instance of a bundleContext. + */ + public BundleContext getBundleContext() + { + return bundleContext; + } +} diff --git a/src/net/java/sip/communicator/plugin/rssaccregwizz/RssAccountRegistration.java b/src/net/java/sip/communicator/plugin/rssaccregwizz/RssAccountRegistration.java new file mode 100644 index 0000000..b815f1b --- /dev/null +++ b/src/net/java/sip/communicator/plugin/rssaccregwizz/RssAccountRegistration.java @@ -0,0 +1,82 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +/** + * The <tt>RssAccountRegistration</tt> is used to store all user input data + * through the <tt>RssAccountRegistrationWizard</tt>. + * + * @author Emil Ivov/Jean-Albert Vescovo + */ +package net.java.sip.communicator.plugin.rssaccregwizz; + +public class RssAccountRegistration +{ + private String userID; + private String password; + private boolean rememberPassword; + + /** + * Returns the User ID of the rss registration account. + * @return the User ID of the rss registration account. + */ + public String getUserID() + { + return userID; + } + + /** + * Sets the user ID of the rss registration account. + * @param userID the userID of the rss registration account. + */ + public void setUserID(String userID) + { + this.userID = userID; + } + + /** + * Returns the password of the Rss registration account. + * + * @return the password of the Rss registration account. + */ + public String getPassword() + { + return password; + } + + /** + * Sets the password of the Rss registration account. + * + * @param password the password of the Rss registration account. + */ + public void setPassword(String password) + { + this.password = password; + } + + /** + * Returns <tt>true</tt> if password has to remembered, <tt>false</tt> + * otherwise. + * + * @return <tt>true</tt> if password has to remembered, <tt>false</tt> + * otherwise. + */ + public boolean isRememberPassword() + { + return true; + } + + /** + * Sets the rememberPassword value of this Rss account registration. + * + * @param rememberPassword <tt>true</tt> if password has to remembered, + * <tt>false</tt> otherwise. + */ + public void setRememberPassword(boolean rememberPassword) + { + this.rememberPassword = true; + } + +} diff --git a/src/net/java/sip/communicator/plugin/rssaccregwizz/RssAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/rssaccregwizz/RssAccountRegistrationWizard.java new file mode 100644 index 0000000..5c0dd77 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/rssaccregwizz/RssAccountRegistrationWizard.java @@ -0,0 +1,198 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.rssaccregwizz; + +import java.util.*; + +import org.osgi.framework.*; +import net.java.sip.communicator.impl.gui.customcontrols.*; +import net.java.sip.communicator.service.gui.*; +import net.java.sip.communicator.service.protocol.*; + +/** + * The <tt>RssAccountRegistrationWizard</tt> is an implementation of the + * <tt>AccountRegistrationWizard</tt> for the Rss protocol. It allows + * the user to create and configure a new Rss account. + * + * @author Emil Ivov + */ +public class RssAccountRegistrationWizard + implements AccountRegistrationWizard +{ + + /** + * The first page of the rss account registration wizard. + */ + private FirstWizardPage firstWizardPage; + + /** + * The object that we use to store details on an account that we will be + * creating. + */ + private RssAccountRegistration registration + = new RssAccountRegistration(); + + private WizardContainer wizardContainer; + + private ProtocolProviderService protocolProvider; + + private String propertiesPackage + = "net.java.sip.communicator.plugin.rssaccregwizz"; + + private boolean isModification; + + /** + * Creates an instance of <tt>RssAccountRegistrationWizard</tt>. + * @param wizardContainer the wizard container, where this wizard + * is added + */ + public RssAccountRegistrationWizard(WizardContainer wizardContainer) + { + this.wizardContainer = wizardContainer; + } + + /** + * Implements the <code>AccountRegistrationWizard.getIcon</code> method. + * Returns the icon to be used for this wizard. + * @return byte[] + */ + public byte[] getIcon() + { + return Resources.getImage(Resources.GIBBERISH_LOGO); + } + + /** + * Implements the <code>AccountRegistrationWizard.getPageImage</code> method. + * Returns the image used to decorate the wizard page + * + * @return byte[] the image used to decorate the wizard page + */ + public byte[] getPageImage() + { + return Resources.getImage(Resources.PAGE_IMAGE); + } + + /** + * Implements the <code>AccountRegistrationWizard.getProtocolName</code> + * method. Returns the protocol name for this wizard. + * @return String + */ + public String getProtocolName() + { + return Resources.getString("protocolName"); + } + + /** + * Implements the <code>AccountRegistrationWizard.getProtocolDescription + * </code> method. Returns the description of the protocol for this wizard. + * @return String + */ + public String getProtocolDescription() + { + return Resources.getString("protocolDescription"); + } + + /** + * Returns the set of pages contained in this wizard. + * @return Iterator + */ + public Iterator getPages() + { + ArrayList pages = new ArrayList(); + firstWizardPage = new FirstWizardPage(registration, wizardContainer); + + pages.add(firstWizardPage); + + return pages.iterator(); + } + + /** + * Returns the set of data that user has entered through this wizard. + * @return Iterator + */ + public Iterator getSummary() + { + Hashtable summaryTable = new Hashtable(); + + summaryTable.put("User ID", registration.getUserID()); + + return summaryTable.entrySet().iterator(); + } + + /** + * Installs the account created through this wizard. + * @return ProtocolProviderService + */ + public ProtocolProviderService finish() + { + firstWizardPage = null; + ProtocolProviderFactory factory + = RssAccRegWizzActivator.getRssProtocolProviderFactory(); + + return this.installAccount(factory, + registration.getUserID()); + } + + /** + * Creates an account for the given user and password. + * @param providerFactory the ProtocolProviderFactory which will create + * the account + * @param user the user identifier + * @return the <tt>ProtocolProviderService</tt> for the new account. + */ + public ProtocolProviderService installAccount( + ProtocolProviderFactory providerFactory, + String user) + { + + Hashtable accountProperties = new Hashtable(); + + if (registration.isRememberPassword()) + { + accountProperties.put(ProtocolProviderFactory.PASSWORD + , registration.getPassword()); + } + + try + { + AccountID accountID = providerFactory.installAccount( + user, accountProperties); + + ServiceReference serRef = providerFactory + .getProviderForAccount(accountID); + + protocolProvider = (ProtocolProviderService) + RssAccRegWizzActivator.bundleContext + .getService(serRef); + } + catch (IllegalArgumentException exc) + { + new ErrorDialog(null, exc.getMessage(), exc).showDialog(); + } + catch (IllegalStateException exc) + { + new ErrorDialog(null, exc.getMessage(), exc).showDialog(); + } + + return protocolProvider; + } + + /** + * Fills the UserID and Password fields in this panel with the data comming + * from the given protocolProvider. + * @param protocolProvider The <tt>ProtocolProviderService</tt> to load the + * data from. + */ + + public void loadAccount(ProtocolProviderService protocolProvider) + { + + this.protocolProvider = protocolProvider; + + isModification = true; + } +} diff --git a/src/net/java/sip/communicator/plugin/rssaccregwizz/resources.properties b/src/net/java/sip/communicator/plugin/rssaccregwizz/resources.properties new file mode 100644 index 0000000..5cf3b0b --- /dev/null +++ b/src/net/java/sip/communicator/plugin/rssaccregwizz/resources.properties @@ -0,0 +1,10 @@ +protocolName=Rss +protocolDescription=Add your preferred RSS feeds into SIP Communicator ! +userID=User ID: +password=Password: +rememberPassword=Remember password +userAndPassword=Identification +existingAccount=* The account you entered is already installed. + +protocolIcon=resources/images/rss/rss-online.png +pageImage=resources/images/rss/rss64x64.png diff --git a/src/net/java/sip/communicator/plugin/rssaccregwizz/rssaccregwizz.manifest.mf b/src/net/java/sip/communicator/plugin/rssaccregwizz/rssaccregwizz.manifest.mf new file mode 100644 index 0000000..71bebc6 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/rssaccregwizz/rssaccregwizz.manifest.mf @@ -0,0 +1,30 @@ +Bundle-Activator: net.java.sip.communicator.plugin.rssaccregwizz.RssAccRegWizzActivator +Bundle-Name: Rss account registration wizard +Bundle-Description: Rss account registration wizard. +Bundle-Vendor: sip-communicator.org +Bundle-Version: 0.0.1 +Import-Package: org.osgi.framework, + net.java.sip.communicator.util, + net.java.sip.communicator.service.configuration, + net.java.sip.communicator.service.configuration.event, + net.java.sip.communicator.service.protocol, + net.java.sip.communicator.service.protocol.event, + net.java.sip.communicator.service.contactlist, + net.java.sip.communicator.service.contactlist.event, + net.java.sip.communicator.service.gui, + net.java.sip.communicator.service.gui.event, + net.java.sip.communicator.service.browserlauncher, + javax.swing, + javax.swing.event, + javax.swing.table, + javax.swing.text, + javax.swing.text.html, + javax.accessibility, + javax.swing.plaf, + javax.swing.plaf.metal, + javax.swing.plaf.basic, + javax.imageio, + javax.swing.filechooser, + javax.swing.tree, + javax.swing.undo, + javax.swing.border |