Package de.nava.informa.core

Examples of de.nava.informa.core.ChannelIF


    ChannelIF channel = prepare();
    assertEquals(8, channel.getItems().size());
  }
 
  public void testCreatedItemInOrder() throws MalformedURLException {
    ChannelIF channel = prepare();
    Iterator it = channel.getItems().iterator();
    int idx = 1;
    while (it.hasNext()) {
      ItemIF item = (ItemIF) it.next();
      assertEquals("http://" + idx + ".net/", item.getLink().toString());
      idx++;
View Full Code Here


      idx++;
    }
  }

  public void testCreatedItemAddOne() throws MalformedURLException {
    ChannelIF channel = prepare();
    ItemIF firstItem = (ItemIF) channel.getItems().iterator().next();
    channel.removeItem(firstItem);
    assertEquals(7, channel.getItems().size());
    builder.createItem(channel, "another one", "9", new URL("http://9.net/"));
    assertEquals(8, channel.getItems().size());
    Iterator it = channel.getItems().iterator();
    int idx = 2;
    while (it.hasNext()) {
      ItemIF item = (ItemIF) it.next();
      assertEquals("http://" + idx + ".net/", item.getLink().toString());
      idx++;
View Full Code Here

      idx++;
    }
  }

  public void testRetrieveItem() throws MalformedURLException {
    ChannelIF channel = prepare();
    ItemIF firstItem = (ItemIF) channel.getItems().iterator().next();
    long firstId = firstItem.getId();   
    ItemIF retrievedItem = channel.getItem(firstId);
    assertEquals(firstItem, retrievedItem);
  }
View Full Code Here

  public TestChannelSearcher(String name) {
    super("TestChannelSearcher", name);
  }

  protected void setUp() throws MalformedURLException {
    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

    channels.add(channelA);
  }
 
  public void testIndexItems() throws IOException, QueryParseException {
    assertEquals("Default", channels.getTitle());
    ChannelIF channelA = channels.getById(channelId);
    assertEquals(3, channelA.getItems().size());
    // create the full-text index
    ChannelIndexer indexer = new ChannelIndexer(getIndexDir());
    indexer.indexChannels(true, channels.getAll());
    assertEquals(getIndexDir(), indexer.getIndexDir());
    assertEquals(3, indexer.getNrOfIndexedItems());
View Full Code Here

    super("TestChannelBuilder", testname);
  }

  public void testCreateChannel() {
    ChannelBuilderIF builder = new ChannelBuilder();
    ChannelIF chA = builder.createChannel("myChannel");
    assertEquals("myChannel", chA.getTitle());
  }
View Full Code Here

    assertEquals("myChannel", chA.getTitle());
  }

  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

    List<?> groups = getHibernateTemplate().find("from ChannelGroup"); //  group order by group.title");
    return groups.toArray(new ChannelGroupIF[groups.size()]);
  }

  public ChannelIF createChannel(String title, URL location) throws PersistenceManagerException {
    ChannelIF channel = new Channel(title, location);
    getHibernateTemplate().save(channel);
    return channel;
  }
View Full Code Here

                                      "modified", "author", "generator",
                                      "copyright", "link", "entry"
                                    });

    // title element
    ChannelIF chnl = cBuilder.createChannel(channel,
                                            channel.getChildTextTrim("title",
                                                                     defNS));

    // TODO: support attributes: type, mode
    chnl.setFormat(ChannelFormat.ATOM_0_3);

    // language
    String language = channel.getAttributeValue("lang", Namespace.XML_NAMESPACE);

    if (language != null) {
      chnl.setLanguage(language);
    }

    // description element
    if (channel.getChild("description") != null) {
      chnl.setDescription(channel.getChildTextTrim("description", defNS));
    } else {
      // fallback
      chnl.setDescription(channel.getChildTextTrim("tagline", defNS));
    }

    // ttl in dc namespace
    Element ttl = channel.getChild("ttl", dcNS);

    if (ttl != null) {
      String ttlString = ttl.getTextTrim();

      if (ttlString != null) {
        chnl.setTtl(Integer.parseInt(ttlString));
      }
    }

    //  lastbuild element : modified ?
    Element modified = channel.getChild("modified", defNS);

    if (modified != null) {
      chnl.setPubDate(ParserUtils.getDate(modified.getTextTrim()));
    }

    // TODO : issued value
    /*
    if (modified != null) {
      modified = channel.getChild("issued", defNS);
      chnl.setLastBuildDate (ParserUtils.getDate(modified.getTextTrim()));
    }
    */

    // author element
    Element author = channel.getChild("author", defNS);

    if (author != null) {
      ParserUtils.matchCaseOfChildren(author, "name");
      chnl.setCreator(author.getChildTextTrim("name", defNS));
    }

    // generator element
    Element generator = channel.getChild("generator", defNS);

    if (generator != null) {
      chnl.setGenerator(generator.getTextTrim());
    }

    // copyright element
    Element copyright = channel.getChild("copyright", defNS);

    if (copyright != null) {
      chnl.setCopyright(getCopyright(copyright));
    }

    // n link elements
    // TODO : type attribut of link (text, application...)
    List links = channel.getChildren("link", defNS);
    Iterator i = links.iterator();

    while (i.hasNext()) {
      Element linkElement = (Element) i.next();

      // use first 'alternate' link
      String rel = linkElement.getAttributeValue("rel");
      String href = linkElement.getAttributeValue("href");

      if ((rel != null) && (href != null) && rel.equals("alternate")) {
        URL linkURL = ParserUtils.getURL(href);

        chnl.setSite(linkURL);

        break;
      }

      // TODO: further extraction of link information
    }

    // 1..n entry elements
    List items = channel.getChildren("entry", defNS);

    i = items.iterator();

    while (i.hasNext()) {
      Element item = (Element) i.next();

      // Lower the case of these tags to simulate case-insensitive parsing
      ParserUtils.matchCaseOfChildren(item,
                                      new String[] {
                                        "title", "link", "content", "summary",
                                        "issued", "subject"
                                      });

      // get title element
      // TODO : deal with type attribut
      Element elTitle = item.getChild("title", defNS);
      String strTitle = "<No Title>";

      if (elTitle != null) {
        strTitle = getTitle(elTitle);
        LOGGER.debug("Parsing title " + elTitle.getTextTrim() + "->" +
                     strTitle);
      }

      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Entry element found (" + strTitle + ").");
      }

      // get link element
      String strLink = AtomParserUtils.getItemLink(item, defNS);

      // 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);

    return chnl;
  }
View Full Code Here

    // turn off DTD loading                    
    saxBuilder.setEntityResolver(new NoOpEntityResolver());

    try {
      Document doc = saxBuilder.build(inpSource);
      ChannelIF channel = parse(cBuilder, doc);
      channel.setLocation(baseLocation);
      return channel;
    } catch (JDOMException e) {
      throw new ParseException("Problem parsing " + inpSource.getSystemId() + ": "+ e);
    }
  }
View Full Code Here

TOP

Related Classes of de.nava.informa.core.ChannelIF

Copyright © 2018 www.massapicom. 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.