Package org.rssowl.core.persist

Examples of org.rssowl.core.persist.INews


  }

  public Object[] getChildren(Object parentElement) {

    if (parentElement instanceof INews) {
      INews lItem = (INews) parentElement;
      if (mPreparator != null) {
        // We get the personal enclosure instead, much better.
        // CB FIXME
        //        return PersonalCache.getInstance().getPersonalAttachments(lItem).toArray();
      } else {
View Full Code Here


    return null; // Parent not used.
  }

  public boolean hasChildren(Object element) {
    if (element instanceof INews) {
      INews lItem = (INews) element;
      // CB FIXME
//      PersonalCache.getInstance().getPersonalAttachments(lItem);
    }
    return false;
  }
View Full Code Here

  }

  public String getColumnText(Object element, int columnIndex) {

    if (element instanceof INews) {
      INews lItem = (INews) element;
      switch (columnIndex) {
      case 0: {
        return lItem.getTitle();
      }

      case 1: {
        Date lDate;
        lDate = lItem.getPublishDate();
        return Util.formatDate(lDate, "EEEE, MMM d hh:mm a");
      }
      }
    }
View Full Code Here

    InMemoryProtocolHandler.FEED = generateFeed("Title", "http://www.link.de", "http://www.guid.de", fDateFormat.format(d));
    fController.reload(createBookMark(feed), null, new NullProgressMonitor());

    assertEquals(1, feedRef.resolve().getNews().size());

    INews news = feedRef.resolve().getNews().get(0);
    assertEquals("Title", news.getTitle());
    assertEquals("http://www.link.de", news.getLink().toString());
    assertEquals("http://www.guid.de", news.getGuid().getValue());
    assertEquals(d.toString(), news.getPublishDate().toString());
  }
View Full Code Here

    IFeed feed = fFactory.createFeed(null, new URI("http://www.link.com"));
    feed.setTitle("Feed Name");
    DynamicDAO.save(feed);
   

    INews news1 = fFactory.createNews(null, feed, new Date());
    news1.setTitle("News 1");
    news1.setPublishDate(fToday);

    INews news2 = fFactory.createNews(null, feed, new Date());
    news2.setTitle("News 2");
    news2.setPublishDate(fYesterday);

    INews news3 = fFactory.createNews(null, feed, new Date());
    news3.setTitle("News 3");
    news3.setPublishDate(fEarlierThisWeek);

    INews news4 = fFactory.createNews(null, feed, new Date());
    news4.setTitle("News 4");
    news4.setPublishDate(fLastWeek);

    INews news5 = fFactory.createNews(null, feed, new Date());
    news5.setTitle("News 5");
    news5.setPublishDate(new Date(0));

    INews news6 = fFactory.createNews(null, feed, new Date());
    news6.setTitle("News 6");
    news6.setPublishDate(new Date(0));

    INews news7 = fFactory.createNews(null, feed, new Date());
    news7.setTitle("News 7");
    news7.setPublishDate(new Date(0));

    List<INews> input = new ArrayList<INews>();
    input.add(news1);
    input.add(news2);
    input.add(news3);
    input.add(news4);
    input.add(news5);
    input.add(news6);
    input.add(news7);

    /* Group by Date */
    {
      fGrouping.setType(NewsGrouping.Type.GROUP_BY_DATE);
      List<EntityGroup> group = fGrouping.group(input);

      assertEquals(fTodayIsFirstDayOfWeek || fYesterdayIsFirstDayOfWeek ? 4 : 5, group.size());
      assertEquals(input.size(), countEntities(group));

      for (EntityGroup entityGroup : group) {
        if (entityGroup.getId() == NewsGrouping.Group.TODAY.ordinal()) {
          List<IEntity> entities = entityGroup.getEntities();
          assertEquals(fTodayIsFirstDayOfWeek ? 2 : 1, entities.size());

          if (!fTodayIsFirstDayOfWeek)
            assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news1 })));
          else
            assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news1, news3 })));
        }

        else if (entityGroup.getId() == NewsGrouping.Group.YESTERDAY.ordinal()) {
          List<IEntity> entities = entityGroup.getEntities();
          assertEquals(fYesterdayIsFirstDayOfWeek ? 2 : 1, entities.size());

          if (!fYesterdayIsFirstDayOfWeek)
            assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news2 })));
          else
            assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news2, news3 })));
        }

        else if (!fTodayIsFirstDayOfWeek && !fYesterdayIsFirstDayOfWeek && entityGroup.getId() == NewsGrouping.Group.EARLIER_THIS_WEEK.ordinal()) {
          List<IEntity> entities = entityGroup.getEntities();
          assertEquals(1, entities.size());
          assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news3 })));
        }

        else if (entityGroup.getId() == NewsGrouping.Group.LAST_WEEK.ordinal()) {
          List<IEntity> entities = entityGroup.getEntities();
          assertEquals(1, entities.size());
          assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news4 })));
        }

        else if (entityGroup.getId() == NewsGrouping.Group.OLDER.ordinal()) {
          List<IEntity> entities = entityGroup.getEntities();
          assertEquals(3, entities.size());
          assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news5, news6, news7 })));
        }
      }
    }

    /* Group by State */
    {
      news1.setState(INews.State.UNREAD);
      news2.setState(INews.State.READ);
      news3.setState(INews.State.HIDDEN);
      news4.setState(INews.State.DELETED);
      news5.setState(INews.State.UPDATED);

      fGrouping.setType(NewsGrouping.Type.GROUP_BY_STATE);
      List<EntityGroup> group = fGrouping.group(input);

      assertEquals(4, group.size());
      assertEquals(5, countEntities(group));

      for (EntityGroup entityGroup : group) {
        if (entityGroup.getId() == NewsGrouping.Group.NEW.ordinal()) {
          List<IEntity> entities = entityGroup.getEntities();
          assertEquals(2, entities.size());
          assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news6, news7 })));
        }

        else if (entityGroup.getId() == NewsGrouping.Group.UNREAD.ordinal()) {
          List<IEntity> entities = entityGroup.getEntities();
          assertEquals(1, entities.size());
          assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news1 })));
        }

        else if (entityGroup.getId() == NewsGrouping.Group.UPDATED.ordinal()) {
          List<IEntity> entities = entityGroup.getEntities();
          assertEquals(1, entities.size());
          assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news5 })));
        }

        else if (entityGroup.getId() == NewsGrouping.Group.READ.ordinal()) {
          List<IEntity> entities = entityGroup.getEntities();
          assertEquals(1, entities.size());
          assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news2 })));
        }
      }

      news3.setState(INews.State.NEW);
      news4.setState(INews.State.NEW);
    }

    /* Group by Author */
    {
      IPerson author1 = fFactory.createPerson(null, news1);
      author1.setName("Author 1");

      IPerson author2 = fFactory.createPerson(null, news2);
      author2.setName("Author 2");

      fGrouping.setType(NewsGrouping.Type.GROUP_BY_AUTHOR);
      List<EntityGroup> group = fGrouping.group(input);

      assertEquals(3, group.size());
      assertEquals(input.size(), countEntities(group));

      for (EntityGroup entityGroup : group) {
        if (entityGroup.getId() == NewsGrouping.Group.UNKNOWN_AUTHOR.ordinal()) {
          List<IEntity> entities = entityGroup.getEntities();
          assertEquals(5, entities.size());
          assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news3, news4, news5, news6, news7 })));
        }

        else if (entityGroup.getName().equals("Author 1")) {
          List<IEntity> entities = entityGroup.getEntities();
          assertEquals(1, entities.size());
          assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news1 })));
        }

        else if (entityGroup.getName().equals("Author 2")) {
          List<IEntity> entities = entityGroup.getEntities();
          assertEquals(1, entities.size());
          assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news2 })));
        }
      }
    }

    /* Group by Category */
    {
      fFactory.createCategory(null, news1).setName("Category 1");
      fFactory.createCategory(null, news2).setName("Category 2");

      fGrouping.setType(NewsGrouping.Type.GROUP_BY_CATEGORY);
      List<EntityGroup> group = fGrouping.group(input);

      assertEquals(3, group.size());
      assertEquals(input.size(), countEntities(group));

      for (EntityGroup entityGroup : group) {
        if (entityGroup.getId() == NewsGrouping.Group.UNKNOWN_CATEGORY.ordinal()) {
          List<IEntity> entities = entityGroup.getEntities();
          assertEquals(5, entities.size());
          assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news3, news4, news5, news6, news7 })));
        }

        else if (entityGroup.getName().equals("Category 1")) {
          List<IEntity> entities = entityGroup.getEntities();
          assertEquals(1, entities.size());
          assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news1 })));
        }

        else if (entityGroup.getName().equals("Category 2")) {
          List<IEntity> entities = entityGroup.getEntities();
          assertEquals(1, entities.size());
          assertEquals(true, entities.containsAll(Arrays.asList(new IEntity[] { news2 })));
        }
      }
    }

    /* Group by Label */
    {
      ILabel label1 = fFactory.createLabel(null, "Label 1");
      ILabel label2 = fFactory.createLabel(null, "Label 2");
      news6.setLabel(label1);
      news7.setLabel(label2);

      fGrouping.setType(NewsGrouping.Type.GROUP_BY_LABEL);
      List<EntityGroup> group = fGrouping.group(input);

      assertEquals(3, group.size());
View Full Code Here

    /* In case Article is unavailable */
    if (articleReader == null)
      return;

    IModelFactory factory = Owl.getModelFactory();
    final INews news = factory.createNews(null, feed, new Date());
    final Map<String, StringBuilder> mimeToContent = new HashMap<String, StringBuilder>();

    /* Create parser for this message */
    final MimeStreamParser parser = new MimeStreamParser();
    parser.setContentHandler(new AbstractContentHandler() {
      boolean fBodyReached = false;

      @Override
      public void field(String fieldData) {

        /* Support early cancellation */
        if (monitor.isCanceled()) {
          parser.stop();
          return;
        }

        /* Not yet in Body */
        if (!fBodyReached) {

          /* From */
          if (fieldData.startsWith(HEADER_FROM))
            interpretFrom(news, DecoderUtil.decodeEncodedWords(fieldData.substring(HEADER_FROM.length())));

          /* Subject */
          else if (fieldData.startsWith(HEADER_SUBJECT))
            interpretSubject(news, DecoderUtil.decodeEncodedWords(fieldData.substring(HEADER_SUBJECT.length())));

          /* Date */
          else if (fieldData.startsWith(HEADER_DATE))
            interpretDate(news, DecoderUtil.decodeEncodedWords(fieldData.substring(HEADER_DATE.length())));

          /* Message ID */
          else if (fieldData.startsWith(HEADER_MESSAGE_ID))
            interpretMessageId(news, DecoderUtil.decodeEncodedWords(fieldData.substring(HEADER_MESSAGE_ID.length())));

          /* References */
          else if (fieldData.startsWith(HEADER_REFERENCES))
            interpretReferences(news, DecoderUtil.decodeEncodedWords(fieldData.substring(HEADER_REFERENCES.length())));
        }
      }

      @Override
      public void body(BodyDescriptor bd, InputStream is) throws IOException {

        /* Support early cancellation */
        if (monitor.isCanceled()) {
          parser.stop();
          return;
        }

        /* Require a mimetype */
        String mimeType = bd.getMimeType();
        if (mimeType == null)
          return;

        /* Require a text-mime */
        if (!mimeType.contains(MIME_TEXT))
          return;

        /* Assign StringBuilder with Mime-Type */
        StringBuilder strBuilder = mimeToContent.get(mimeType);
        if (strBuilder == null) {
          strBuilder = new StringBuilder();
          mimeToContent.put(mimeType, strBuilder);
        }

        /* Handle encodings */
        if (bd.isBase64Encoded())
          is = new Base64InputStream(is);
        else if (bd.isQuotedPrintableEncoded())
          is = new QuotedPrintableInputStream(is);

        /* Read Body */
        BufferedReader reader;
        if (!DEFAULT_ENCODING.equals(bd.getCharset()))
          reader = new BufferedReader(new InputStreamReader(is, bd.getCharset()));
        else
          reader = new BufferedReader(new InputStreamReader(is));

        String line = null;
        while ((line = reader.readLine()) != null && !monitor.isCanceled()) {

          /* Check for quote */
          boolean isQuote = line.startsWith(">");
          if (line.startsWith(">>>>"))
            strBuilder.append("<span class=\"quote_lvl4\">");
          else if (line.startsWith(">>>"))
            strBuilder.append("<span class=\"quote_lvl3\">");
          else if (line.startsWith(">>"))
            strBuilder.append("<span class=\"quote_lvl2\">");
          else if (line.startsWith(">"))
            strBuilder.append("<span class=\"quote_lvl1\">");

          /* Beautify Body (if non-html) */
          if (!MIME_TEXT_HTML.equals(mimeType))
            strBuilder.append(beautifyBody(line)).append("<br>\n");
          else
            strBuilder.append(line);

          /* Check for quote */
          if (isQuote)
            strBuilder.append("</span>");
        }
      }
    });

    /* Parse Body */
    ReaderInputStream inS = new ReaderInputStream(articleReader);
    parser.parse(inS);

    /* Prefer HTML over text/plain */
    if (mimeToContent.containsKey(MIME_TEXT_HTML))
      news.setDescription(mimeToContent.get(MIME_TEXT_HTML).toString());

    /* Use text/plain but replace links with HTML anchors */
    else if (mimeToContent.containsKey(MIME_TEXT_PLAIN)) {
      String description = mimeToContent.get(MIME_TEXT_PLAIN).toString();
      if (description.contains(PROTOCOL_SEPARATOR)) {
        List<String> links = RegExUtils.extractLinksFromText(description, true);
        for (String link : links) {
          StringBuilder strB = new StringBuilder("<a href=\"");
          strB.append(link).append("\"/>");
          strB.append(link).append("</a>");

          description = StringUtils.replaceAll(description, link, strB.toString());
        }
      }

      news.setDescription(description);
    }
  }
View Full Code Here

  @Test
  public void testNewsFiltering() throws Exception {
    IFeed feed = fFactory.createFeed(null, new URI("http://www.link.com"));
    feed.setTitle("Feed Name");

    INews news1 = fFactory.createNews(null, feed, new Date());
    news1.setTitle("News 1");
    news1.setPublishDate(fToday);

    INews news2 = fFactory.createNews(null, feed, new Date());
    news2.setTitle("News 2");
    news2.setPublishDate(fYesterday);

    INews news3 = fFactory.createNews(null, feed, new Date());
    news3.setTitle("News 3");
    news3.setPublishDate(new Date(0));

    INews news4 = fFactory.createNews(null, feed, new Date());
    news4.setTitle("News 4");
    news4.setPublishDate(new Date(0));

    INews news5 = fFactory.createNews(null, feed, new Date());
    news5.setTitle("News 5");
    news5.setPublishDate(new Date(0));

    /* Fill into Array */
    Object elements[] = new Object[] { news1, news2, news3, news4, news5 };

    /* Filter: Show All */
    {
      fFiltering.setType(NewsFilter.Type.SHOW_ALL);
      List< ? > result = Arrays.asList(fFiltering.filter(fNullViewer, (Object) null, elements));
      assertEquals(elements.length, result.size());
      assertEquals(true, result.containsAll(Arrays.asList(new IEntity[] { news1, news2, news3, news4, news5 })));
    }

    /* Filter: Show New */
    {
      news2.setState(INews.State.UNREAD);
      news3.setState(INews.State.READ);
      news4.setState(INews.State.HIDDEN);
      news5.setState(INews.State.DELETED);

      fFiltering.setType(NewsFilter.Type.SHOW_NEW);
      List< ? > result = Arrays.asList(fFiltering.filter(fNullViewer, (Object) null, elements));
      assertEquals(1, result.size());
      assertEquals(true, result.containsAll(Arrays.asList(new IEntity[] { news1 })));

      news4.setState(INews.State.UNREAD);
      news5.setState(INews.State.NEW);
    }

    /* Filter: Show Unread */
    {
      fFiltering.setType(NewsFilter.Type.SHOW_UNREAD);
View Full Code Here

      }
    }
  }

  private void processItems(Element element, IFeed feed) {
    INews news = Owl.getModelFactory().createNews(null, feed, new Date(System.currentTimeMillis() - (fNewsCounter++ * 1)));

    /* Check wether the Attributes are to be processed by a Contribution */
    processNamespaceAttributes(element, news);

    /* Interpret Children */
    List< ? > newsChilds = element.getChildren();
    for (Iterator< ? > iter = newsChilds.iterator(); iter.hasNext();) {
      Element child = (Element) iter.next();
      String name = child.getName().toLowerCase();

      /* Check wether this Element is to be processed by a Contribution */
      if (processElementExtern(child, news))
        continue;

      /* Title */
      else if ("title".equals(name)) { //$NON-NLS-1$
        news.setTitle(child.getText());
        processNamespaceAttributes(child, news);
      }

      /* Link */
      else if ("link".equals(name)) { //$NON-NLS-1$
        URI uri = URIUtils.createURI(child.getText());
        if (uri != null)
          news.setLink(uri);
        processNamespaceAttributes(child, news);
      }

      /* Description */
      else if ("description".equals(name)) { //$NON-NLS-1$
        news.setDescription(child.getText());
        processNamespaceAttributes(child, news);
      }

      /* Publish Date */
      else if ("pubdate".equals(name)) { //$NON-NLS-1$
        news.setPublishDate(DateUtils.parseDate(child.getText()));
        processNamespaceAttributes(child, news);
      }

      /* Author */
      else if ("author".equals(name)) { //$NON-NLS-1$
        IPerson person = Owl.getModelFactory().createPerson(null, news);
        person.setName(child.getText());

        processNamespaceAttributes(child, person);
      }

      /* Comments */
      else if ("comments".equals(name)) { //$NON-NLS-1$
        news.setComments(child.getText());
        processNamespaceAttributes(child, news);
      }

      /* Attachment */
      else if ("enclosure".equals(name)) //$NON-NLS-1$
View Full Code Here

    if (cleanUp) {
      newsToCleanUp = new ArrayList<Integer>(fNews.size() / 2);
    }
    ComplexMergeResult<List<INews>> mergeResult = ComplexMergeResult.create(newsListCopy);
    for (int i = 0, c = fNews.size(); i < c; ++i) {
      INews existingNews = fNews.get(i);
      int existingNewsIndex = findNews(newsListCopy, existingNews);

      if (existingNewsIndex > -1) {
        mergeResult.addAll(existingNews.merge(newsListCopy.get(existingNewsIndex)));
        newsListCopy.remove(existingNewsIndex);
      } else if ((newsToCleanUp != null) && (existingNews.getState() == INews.State.DELETED))
        newsToCleanUp.add(Integer.valueOf(i));

    }
    if (newsToCleanUp != null) {
      for (int i = newsToCleanUp.size() - 1; i >= 0; --i) {
        INews news = fNews.remove(newsToCleanUp.get(i).intValue());
        mergeResult.addRemovedObject(news);
        mergeResult.setStructuralChange(true);
      }

    }
    for (INews news : newsListCopy) {
      news.setParent(this);
      fNews.add(news);
      mergeResult.setStructuralChange(true);
      mergeResult.addUpdatedObject(news);
    }
    return mergeResult;
View Full Code Here

        processOutline(child, feed);
    }
  }

  private void processOutline(Element element, IFeed feed) {
    INews news = Owl.getModelFactory().createNews(null, feed, new Date(System.currentTimeMillis() - (fNewsCounter++ * 1)));

    /* Interpret Attributes */
    List< ? > outlineAttributes = element.getAttributes();
    for (Iterator< ? > iter = outlineAttributes.iterator(); iter.hasNext();) {
      Attribute attribute = (Attribute) iter.next();
      String name = attribute.getName().toLowerCase();

      /* Check wether this Attribute is to be processed by a Contribution */
      if (processAttributeExtern(attribute, news))
        continue;

      /* Title */
      else if ("title".equals(name)) //$NON-NLS-1$
        news.setTitle(attribute.getValue());

      /* URL */
      else if ("url".equals(name)) { //$NON-NLS-1$
        URI uri = URIUtils.createURI(attribute.getValue());
        if (uri != null)
          news.setLink(uri);
      }

      /* HTML URL - If not yet set as Link */
      else if ("htmlurl".equals(name) && news.getLink() == null) { //$NON-NLS-1$
        URI uri = URIUtils.createURI(attribute.getValue());
        if (uri != null)
          news.setLink(uri);
      }

      /* XML URL */
      else if ("xmlurl".equals(name)) { //$NON-NLS-1$
        URI uri = URIUtils.createURI(attribute.getValue());
        if (uri != null) {
          ISource source = Owl.getModelFactory().createSource(news);
          source.setLink(uri);
        }
      }

      /* Text */
      else if ("text".equals(name)) //$NON-NLS-1$
        news.setDescription(attribute.getValue());

      /* Description */
      else if ("description".equals(name)) //$NON-NLS-1$
        news.setDescription(attribute.getValue());
    }

    /* Interpret Children */
    List< ? > channelChildren = element.getChildren();
    for (Iterator< ? > iter = channelChildren.iterator(); iter.hasNext();) {
View Full Code Here

TOP

Related Classes of org.rssowl.core.persist.INews

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.