Examples of ItemIF


Examples of de.nava.informa.core.ItemIF

   * @see de.nava.informa.core.ItemIF#equals
   *
   * @throws Exception in case of any exceptions
   */
  public void testHowDifferentImplementationsMatching() throws Exception {
    ItemIF item1, item2;

    item1 = new Item("a", "b", new URL("file://a"));
    item2 = new SimpleItem("a", "b", new URL("file://a"));
    assertTrue(item1.equals(item2));

    item1 = new Item("a", "b", new URL("file://a"));
    item2 = new SimpleItem("a", "b", new URL("file://b"));
    assertFalse(item1.equals(item2));

    item1 = new Item("a", "b", new URL("file://a"));
    item2 = new SimpleItem("a", "b", new URL("file://A"));
    assertTrue(item1.equals(item2));
  }
View Full Code Here

Examples of de.nava.informa.core.ItemIF

    ChannelIF channelA = new Channel("example.org");
    channelId = channelA.getId();
    itemA = new Item("Java 1.5 out", "Long awaited...",
                     new URL("http://example.org/1234"));
    channelA.addItem(itemA);
    ItemIF itemB = new Item("XML virus found", "All about it here.",
                            new URL("http://example.org/2345"));
    channelA.addItem(itemB);
    ItemIF itemC = new Item("Quiet Slashdot", "No news today.",
                            new URL("http://example.org/3456"));
    channelA.addItem(itemC);
    channels = new ChannelGroup("Default");
    channels.add(channelA);
  }
View Full Code Here

Examples of de.nava.informa.core.ItemIF

  }

  public void testCreateItem() throws MalformedURLException {
    ChannelBuilderIF builder = new ChannelBuilder();
    ChannelIF chA = builder.createChannel("myChannel");
    ItemIF itA = builder.createItem(chA, "first item", "descr of item",
                                    new URL("http://sf.net/projects/informa"));
    itA.setCreator("TestChannelBuilder");
    assertEquals("first item", itA.getTitle());
    itA = null;
    // test retrieval
    ItemIF itB = (ItemIF) chA.getItems().iterator().next();
    assertEquals("first item", itB.getTitle());
    assertEquals("TestChannelBuilder", itB.getCreator());   
  }
View Full Code Here

Examples of de.nava.informa.core.ItemIF

      // get description element
      String strDesc = getDescription(item, defNS);

      // generate new news item (link to article)
      ItemIF curItem = cBuilder.createItem(item, chnl, strTitle, strDesc,
                                           ParserUtils.getURL(strLink));

      curItem.setFound(dateParsed);

      // get issued element (required)
      Element elIssued = item.getChild("issued", defNS);

      if (elIssued == null) {
        // [adewale@gmail.com, 01-May-2005] Fix for blogs which have
        // 'created' dates, but not 'issued' dates -- in clear contravention
        // of the Atom 0.3 spec.
        Element elCreated = item.getChild("created", defNS);

        if (elCreated != null) {
          curItem.setDate(ParserUtils.getDate(elCreated.getTextTrim()));
        }
      } else {
        curItem.setDate(ParserUtils.getDate(elIssued.getTextTrim()));
      }

      // get subject element
      Element elSubject = item.getChild("subject", dcNS);

      if (elSubject != null) {
        // TODO: Mulitple subject elements not handled currently
        curItem.setSubject(elSubject.getTextTrim());
      }
    }

    // set to current date
    chnl.setLastUpdated(dateParsed);
View Full Code Here

Examples of de.nava.informa.core.ItemIF

    System.out.println("Channel format: " + channel.getFormat().toString());
    System.out.println(channel);
    System.out.println("containing " + channel.getItems().size() + " items");
    Iterator items = channel.getItems().iterator();
    while (items.hasNext()) {
      ItemIF item = (ItemIF) items.next();
      System.out.println("  - " + item);
    }
  }
View Full Code Here

Examples of de.nava.informa.core.ItemIF

      if (elDesc != null) {
        strDesc = elDesc.getTextTrim();
      }

      // generate new RSS item (link to article)
      ItemIF rssItem = cBuilder.createItem(item, chnl, strTitle, strDesc,
          ParserUtils.getURL(strLink));

      // get subject element
      Element elSubject = item.getChild("subject", defNS);
      if (elSubject == null) {
        // fallback mechanism: get dc:subject element
        elSubject = item.getChild("subject", dcNS);
      }
      if (elSubject != null) {
        rssItem.setSubject(elSubject.getTextTrim());
      }

      // get category list
      // get list of <category> elements
      List listCategory = item.getChildren("category", defNS);
      if (listCategory.size() < 1) {
        // fallback mechanism: get dc:category element
        listCategory = item.getChildren("category", dcNS);
      }
      if (listCategory.size() > 0) {
        RecursiveHashtable<String> catTable = new RecursiveHashtable<String>();

        // for each category, parse hierarchy
        Iterator itCat = listCategory.iterator();
        while (itCat.hasNext()) {
          RecursiveHashtable<String> currTable = catTable;
          Element elCategory = (Element) itCat.next();
          // get contents of category element
          String[] titles = elCategory.getTextNormalize().split("/");
          for (int x = 0; x < titles.length; x++) {
            // tokenize category string to extract out hierarchy
            if (currTable.containsKey(titles[x]) == false) {
              // if token does not exist in current map, add it with child Hashtable
              currTable.put(titles[x], new RecursiveHashtable<String>());
            }
            // reset current Hashtable to child's Hashtable then iterate to next token
            currTable = currTable.get(titles[x]);
          }
        }
        ArrayList<CategoryIF> catList = new ArrayList<CategoryIF>();
        // transform cat list & hierarchy into list of CategoryIF elements
        Enumeration<String> enumCategories = catTable.keys();
        while (enumCategories.hasMoreElements()) {
          String key = enumCategories.nextElement();
          // build category list: getCategoryList(parent, title, children)
          CategoryIF cat = getCategoryList(null, key, catTable.get(key));
          catList.add(cat);
        }
        if (catList.size() > 0) {
          // if categories were actually created, then add list to item node
          rssItem.setCategories(catList);
        }
      }

      // get publication date
      Element elDate = item.getChild("pubDate", defNS);
      if (elDate == null) {
        // fallback mechanism: get dc:date element
        elDate = item.getChild("date", dcNS);
      }
      if (elDate != null) {
        rssItem.setDate(ParserUtils.getDate(elDate.getTextTrim()));
      }

      rssItem.setFound(dateParsed);

      // get Author element
      Element elAuthor = item.getChild("author", defNS);
      if (elAuthor == null) {
        // fallback mechanism: get dc:creator element
        elAuthor = item.getChild("creator", dcNS);
      }
      if (elAuthor != null)
        rssItem.setCreator(elAuthor.getTextTrim());

      // get Comments element
      Element elComments = item.getChild("comments", defNS);
      String strComments = "";
      if (elComments != null) {
        strComments = elComments.getTextTrim();
      }
      rssItem.setComments(ParserUtils.getURL(strComments));

      // get guid element
      Element elGuid = item.getChild("guid", defNS);
      if (elGuid != null) {
        String guidUrl = elGuid.getTextTrim();
        if (guidUrl != null) {
          boolean permaLink = true;
          Attribute permaLinkAttribute = elGuid.getAttribute("isPermaLink",
              defNS);
          if (permaLinkAttribute != null) {
            String permaLinkStr = permaLinkAttribute.getValue();
            if (permaLinkStr != null) {
              permaLink = Boolean.valueOf(permaLinkStr).booleanValue();
            }
          }
          ItemGuidIF itemGuid = cBuilder.createItemGuid(rssItem, guidUrl,
              permaLink);
          rssItem.setGuid(itemGuid);
        }
      }

      // get source element
      Element elSource = item.getChild("source", defNS);
      if (elSource != null) {
        String sourceName = elSource.getTextTrim();
        Attribute sourceAttribute = elSource.getAttribute("url", defNS);
        if (sourceAttribute != null) {
          String sourceLocation = sourceAttribute.getValue().trim();
          ItemSourceIF itemSource = cBuilder.createItemSource(rssItem,
              sourceName, sourceLocation, null);
          rssItem.setSource(itemSource);
        }
      }

      // get enclosure element
      Element elEnclosure = item.getChild("enclosure", defNS);
      if (elEnclosure != null) {
        URL location = null;
        String type = null;
        int length = -1;
        Attribute urlAttribute = elEnclosure.getAttribute("url", defNS);
        if (urlAttribute != null) {
          location = ParserUtils.getURL(urlAttribute.getValue().trim());
        }
        Attribute typeAttribute = elEnclosure.getAttribute("type", defNS);
        if (typeAttribute != null) {
          type = typeAttribute.getValue().trim();
        }
        Attribute lengthAttribute = elEnclosure.getAttribute("length", defNS);
        if (lengthAttribute != null) {
          try {
            length = Integer.parseInt(lengthAttribute.getValue().trim());
          } catch (NumberFormatException e) {
            logger.warn(e);
          }
        }
        ItemEnclosureIF itemEnclosure = cBuilder.createItemEnclosure(rssItem,
            location, type, length);
        rssItem.setEnclosure(itemEnclosure);
      }
    }

    // 0..1 image element
    Element image = channel.getChild("image", defNS);
View Full Code Here

Examples of de.nava.informa.core.ItemIF

   * @param channel channel to put new item into.
   * @param ethalon object to copy properties values from.
   * @return new item object.
   */
  public final ItemIF createItem(ChannelIF channel, ItemIF ethalon) {
    final ItemIF item = createItem(channel, ethalon.getTitle());

    // Copy values
    InformaUtils.copyItemProperties(ethalon, item);

    // Copy guid if present
    final ItemGuidIF ethalonGuid = ethalon.getGuid();
    if (ethalonGuid != null) {
      item.setGuid(new ItemGuid(item, ethalonGuid.getLocation(), ethalonGuid.isPermaLink()));
    }

    return item;
  }
View Full Code Here

Examples of de.nava.informa.core.ItemIF

   * @throws PersistenceManagerException in case of any problems.
   */
  public ItemIF createItem(ChannelIF channel, String title)
    throws PersistenceManagerException {

    final ItemIF item = new Item(channel, title, null, null);

    saveCreatedItem(channel, item);

    return item;
  }
View Full Code Here

Examples of de.nava.informa.core.ItemIF

   */
  public ItemIF createItem(ChannelIF channel, ItemIF ethalon)
    throws PersistenceManagerException {

    // Create item by copying another's properties and save
    final ItemIF item = new Item(channel, null, null, null);
    InformaUtils.copyItemProperties(ethalon, item);

    saveCreatedItem(channel, item);

    return item;
View Full Code Here

Examples of de.nava.informa.core.ItemIF

    }

    // Delete all items
    final ItemIF[] items = (ItemIF[]) channel.getItems().toArray(new ItemIF[0]);
    for (int i = 0; i < items.length; i++) {
      ItemIF item = items[i];
      channel.removeItem(item);
      HibernateUtil.deleteObject(item, session);
    }

    // Delete object
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.