Search in sources :

Example 1 with SubscriptionException

use of com.biglybt.pif.utils.subscriptions.SubscriptionException in project BiglyBT by BiglySoftware.

the class UtilitiesImpl method getSubscriptionManager.

@Override
public SubscriptionManager getSubscriptionManager() throws SubscriptionException {
    try {
        Method m = Class.forName("com.biglybt.core.subs.SubscriptionManagerFactory").getMethod("getSingleton");
        final PluginSubscriptionManager sm = (PluginSubscriptionManager) m.invoke(null);
        return (new SubscriptionManager() {

            @Override
            public void requestSubscription(URL url) {
                sm.requestSubscription(url, new HashMap<String, Object>());
            }

            @Override
            public void requestSubscription(URL url, Map<String, Object> options) {
                sm.requestSubscription(url, options);
            }

            @Override
            public void requestSubscription(SearchProvider sp, Map<String, Object> search_parameters) throws SubscriptionException {
                sm.requestSubscription(sp, search_parameters);
            }

            @Override
            public Subscription[] getSubscriptions() {
                PluginSubscription[] p_subs = sm.getSubscriptions(true);
                Subscription[] subs = new Subscription[p_subs.length];
                for (int i = 0; i < subs.length; i++) {
                    final PluginSubscription p_sub = p_subs[i];
                    subs[i] = new Subscription() {

                        @Override
                        public String getID() {
                            return (p_sub.getID());
                        }

                        @Override
                        public String getName() {
                            return (p_sub.getName());
                        }

                        @Override
                        public boolean isSearchTemplate() {
                            return (p_sub.isSearchTemplate());
                        }

                        @Override
                        public SubscriptionResult[] getResults() {
                            PluginSubscriptionResult[] p_results = p_sub.getResults(false);
                            SubscriptionResult[] results = new SubscriptionResult[p_results.length];
                            for (int i = 0; i < results.length; i++) {
                                final PluginSubscriptionResult p_res = p_results[i];
                                results[i] = new SubscriptionResult() {

                                    private Map<Integer, Object> map = p_res.toPropertyMap();

                                    @Override
                                    public Object getProperty(int property_name) {
                                        return (map.get(property_name));
                                    }

                                    @Override
                                    public boolean isRead() {
                                        return (p_res.getRead());
                                    }

                                    @Override
                                    public void setRead(boolean read) {
                                        p_res.setRead(read);
                                    }
                                };
                            }
                            return (results);
                        }
                    };
                }
                return (subs);
            }
        });
    } catch (Throwable e) {
        throw (new SubscriptionException("Subscriptions unavailable", e));
    }
}
Also used : SubscriptionException(com.biglybt.pif.utils.subscriptions.SubscriptionException) SubscriptionResult(com.biglybt.pif.utils.subscriptions.SubscriptionResult) SearchProvider(com.biglybt.pif.utils.search.SearchProvider) Method(java.lang.reflect.Method) SubscriptionManager(com.biglybt.pif.utils.subscriptions.SubscriptionManager) URL(java.net.URL) Subscription(com.biglybt.pif.utils.subscriptions.Subscription)

Aggregations

SearchProvider (com.biglybt.pif.utils.search.SearchProvider)1 Subscription (com.biglybt.pif.utils.subscriptions.Subscription)1 SubscriptionException (com.biglybt.pif.utils.subscriptions.SubscriptionException)1 SubscriptionManager (com.biglybt.pif.utils.subscriptions.SubscriptionManager)1 SubscriptionResult (com.biglybt.pif.utils.subscriptions.SubscriptionResult)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1