| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 import javax.xml.parsers.ParserConfigurationException; | 28 import javax.xml.parsers.ParserConfigurationException; |
| 29 import javax.xml.parsers.SAXParser; | 29 import javax.xml.parsers.SAXParser; |
| 30 import javax.xml.parsers.SAXParserFactory; | 30 import javax.xml.parsers.SAXParserFactory; |
| 31 | 31 |
| 32 import org.xml.sax.Attributes; | 32 import org.xml.sax.Attributes; |
| 33 import org.xml.sax.SAXException; | 33 import org.xml.sax.SAXException; |
| 34 import org.xml.sax.helpers.DefaultHandler; | 34 import org.xml.sax.helpers.DefaultHandler; |
| 35 | 35 |
| 36 final class DefaultSubscriptions | 36 final class DefaultSubscriptions |
| 37 { | 37 { |
| 38 private final List<DefaultSubscriptionInfo> subscriptions = new ArrayList<Defa
ultSubscriptionInfo>(); | 38 private final List<DefaultSubscriptionInfo> subscriptions = new ArrayList<>(); |
| 39 private final List<DefaultSubscriptionInfo> linearSubscriptions = new ArrayLis
t<DefaultSubscriptionInfo>(); | 39 private final List<DefaultSubscriptionInfo> linearSubscriptions = new ArrayLis
t<>(); |
| 40 private final HashMap<String, DefaultSubscriptionInfo> urlMap = new HashMap<St
ring, DefaultSubscriptionInfo>(); | 40 private final HashMap<String, DefaultSubscriptionInfo> urlMap = new HashMap<>(
); |
| 41 private final List<DefaultSubscriptionInfo> adsSubscriptions = new ArrayList<D
efaultSubscriptionInfo>(); | 41 private final List<DefaultSubscriptionInfo> adsSubscriptions = new ArrayList<>
(); |
| 42 private final List<DefaultSubscriptionInfo> otherSubscriptions = new ArrayList
<DefaultSubscriptionInfo>(); | 42 private final List<DefaultSubscriptionInfo> otherSubscriptions = new ArrayList
<>(); |
| 43 | 43 |
| 44 private DefaultSubscriptions initialize() | 44 private DefaultSubscriptions initialize() |
| 45 { | 45 { |
| 46 this.listSubscriptions(this.linearSubscriptions); | 46 this.listSubscriptions(this.linearSubscriptions); |
| 47 | 47 |
| 48 for (final DefaultSubscriptionInfo s : this.linearSubscriptions) | 48 for (final DefaultSubscriptionInfo s : this.linearSubscriptions) |
| 49 { | 49 { |
| 50 final String url = s.getUrl(); | 50 final String url = s.getUrl(); |
| 51 final String type = s.getType(); | 51 final String type = s.getType(); |
| 52 | 52 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 63 { | 63 { |
| 64 this.otherSubscriptions.add(s); | 64 this.otherSubscriptions.add(s); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 return this; | 68 return this; |
| 69 } | 69 } |
| 70 | 70 |
| 71 public List<Subscription> createSubscriptions() throws IOException | 71 public List<Subscription> createSubscriptions() throws IOException |
| 72 { | 72 { |
| 73 final ArrayList<Subscription> subs = new ArrayList<Subscription>(); | 73 final ArrayList<Subscription> subs = new ArrayList<>(); |
| 74 for (DefaultSubscriptionInfo info : this.linearSubscriptions) | 74 for (DefaultSubscriptionInfo info : this.linearSubscriptions) |
| 75 { | 75 { |
| 76 if (!info.getUrl().isEmpty()) | 76 if (!info.getUrl().isEmpty()) |
| 77 { | 77 { |
| 78 final Subscription sub = Subscription.create(info.getUrl()); | 78 final Subscription sub = Subscription.create(info.getUrl()); |
| 79 sub.putMeta(Subscription.KEY_TITLE, info.getTitle()); | 79 sub.putMeta(Subscription.KEY_TITLE, info.getTitle()); |
| 80 subs.add(sub); | 80 subs.add(sub); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 return subs; | 83 return subs; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 { | 119 { |
| 120 try | 120 try |
| 121 { | 121 { |
| 122 final SAXParserFactory factory = SAXParserFactory.newInstance(); | 122 final SAXParserFactory factory = SAXParserFactory.newInstance(); |
| 123 factory.setValidating(false); | 123 factory.setValidating(false); |
| 124 final SAXParser parser = factory.newSAXParser(); | 124 final SAXParser parser = factory.newSAXParser(); |
| 125 final SubscriptionParser handler = new SubscriptionParser(); | 125 final SubscriptionParser handler = new SubscriptionParser(); |
| 126 parser.parse(in, handler); | 126 parser.parse(in, handler); |
| 127 return handler.subscriptions.initialize(); | 127 return handler.subscriptions.initialize(); |
| 128 } | 128 } |
| 129 catch (final ParserConfigurationException e) | 129 catch (final ParserConfigurationException | SAXException e) |
| 130 { | 130 { |
| 131 throw new IOException("ParserConfigurationException: " + e.getMessage()); | 131 throw new IOException(e.getClass().getSimpleName() + ": " + e.getMessage()
); |
| 132 } | |
| 133 catch (final SAXException e) | |
| 134 { | |
| 135 e.printStackTrace(); | |
| 136 throw new IOException("SAXException: " + e.getMessage()); | |
| 137 } | 132 } |
| 138 } | 133 } |
| 139 | 134 |
| 140 private static class SubscriptionParser extends DefaultHandler | 135 private static class SubscriptionParser extends DefaultHandler |
| 141 { | 136 { |
| 142 private boolean inSubscriptions = false; | 137 private boolean inSubscriptions = false; |
| 143 private boolean inVariants = false; | 138 private boolean inVariants = false; |
| 144 | 139 |
| 145 private final static String KEY_SUPPLEMENTS = "supplements"; | 140 private final static String KEY_SUPPLEMENTS = "supplements"; |
| 146 private final static String KEY_SUBSCRIPTIONS = "subscriptions"; | 141 private final static String KEY_SUBSCRIPTIONS = "subscriptions"; |
| 147 private final static String KEY_SUBSCRIPTION = "subscription"; | 142 private final static String KEY_SUBSCRIPTION = "subscription"; |
| 148 private final static String KEY_VARIANTS = "variants"; | 143 private final static String KEY_VARIANTS = "variants"; |
| 149 private final static String KEY_VARIANT = "variant"; | 144 private final static String KEY_VARIANT = "variant"; |
| 150 | 145 |
| 151 private final DefaultSubscriptions subscriptions = new DefaultSubscriptions(
); | 146 private final DefaultSubscriptions subscriptions = new DefaultSubscriptions(
); |
| 152 private final LinkedList<DefaultSubscriptionInfo> subscriptionStack = new Li
nkedList<DefaultSubscriptionInfo>(); | 147 private final LinkedList<DefaultSubscriptionInfo> subscriptionStack = new Li
nkedList<>(); |
| 153 private DefaultSubscriptionInfo subscription = null; | 148 private DefaultSubscriptionInfo subscription = null; |
| 154 private DefaultSubscriptionInfo variant = null; | 149 private DefaultSubscriptionInfo variant = null; |
| 155 | 150 |
| 156 @Override | 151 @Override |
| 157 public void startElement(final String uri, final String localName, final Str
ing qName, | 152 public void startElement(final String uri, final String localName, final Str
ing qName, |
| 158 final Attributes attributes) throws SAXException | 153 final Attributes attributes) throws SAXException |
| 159 { | 154 { |
| 160 super.startElement(uri, localName, qName, attributes); | 155 super.startElement(uri, localName, qName, attributes); |
| 161 | 156 |
| 162 if (KEY_SUBSCRIPTIONS.equals(qName)) | 157 if (KEY_SUBSCRIPTIONS.equals(qName)) |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 279 } |
| 285 } | 280 } |
| 286 } | 281 } |
| 287 | 282 |
| 288 @Override | 283 @Override |
| 289 public String toString() | 284 public String toString() |
| 290 { | 285 { |
| 291 return this.linearSubscriptions.toString(); | 286 return this.linearSubscriptions.toString(); |
| 292 } | 287 } |
| 293 } | 288 } |
| OLD | NEW |