コード例 #1
0
  public void setAdsResource(Resource resource)
      throws ParserConfigurationException, IOException, SAXException {
    advertisementBlocks.clear();

    if (resource != null && resource.exists() && resource.isReadable()) {
      final DocumentBuilder builder = BUILDER_FACTORY.newDocumentBuilder();
      final Document document = builder.parse(resource.getInputStream());

      final Element root = document.getDocumentElement();
      final String client = root.getAttribute("client");

      final NodeList blocks = root.getElementsByTagName("block");
      for (int i = 0; i < blocks.getLength(); i++) {
        final Element block = (Element) blocks.item(i);
        final String name = block.getAttribute("name");

        final NodeList items = block.getElementsByTagName("item");
        for (int j = 0; j < items.getLength(); j++) {
          final Element item = (Element) items.item(j);
          final String slot = item.getAttribute("slot");
          final Language language = Language.byCode(item.getAttribute("language"));
          final int width = Integer.valueOf(item.getAttribute("width"));
          final int height = Integer.valueOf(item.getAttribute("height"));

          advertisementBlocks.put(
              new AdsBlockKey(name, language),
              new AdvertisementBlock(client, slot, width, height, AdvertisementProvider.GOOGLE));
        }
      }
    }
  }
コード例 #2
0
 private AdsBlockKey(String name, Language language) {
   this(name, language.getLocale());
 }
コード例 #3
0
 @Override
 public AdvertisementBlock getAdvertisementBlock(String name, Language language) {
   return getAdvertisementBlock(name, language.getLocale());
 }