Package org.rssowl.core.persist

Examples of org.rssowl.core.persist.IModelFactory


  }

  private void createAndOpenSearch(IFolder folder) {
    ISearchMark locationSearch = findSearch(folder);
    if (locationSearch == null) {
      IModelFactory factory = Owl.getModelFactory();
      List<ISearchCondition> conditions = new ArrayList<ISearchCondition>();

      ISearchField locationField = factory.createSearchField(INews.LOCATION, INews.class.getName());
      conditions.add(factory.createSearchCondition(locationField, SearchSpecifier.IS, ModelUtils.toPrimitive(Collections.singletonList((IFolderChild) folder))));

      SearchMarkDialog dialog = new SearchMarkDialog(fTargetPart.getSite().getShell(), folder.getParent(), folder, conditions, true, folder.getProperties());
      if (dialog.open() == IDialogConstants.OK_ID)
        locationSearch = dialog.getSearchMark();
      else
View Full Code Here


    /* Show Recent News if no teasing news present */
    if (newsToShow.isEmpty()) {

      /* Build the Search if not yet done */
      if (fTodaysNewsSearch == null) {
        IModelFactory factory = Owl.getModelFactory();

        String newsClassName = INews.class.getName();
        ISearchField ageInDaysField = factory.createSearchField(INews.AGE_IN_DAYS, newsClassName);
        ISearchField ageInMinutesField = factory.createSearchField(INews.AGE_IN_MINUTES, newsClassName);

        ISearchCondition dayCondition = factory.createSearchCondition(ageInDaysField, SearchSpecifier.IS_LESS_THAN, 1); // From Today after Midnight
        ISearchCondition recentCondition = factory.createSearchCondition(ageInMinutesField, SearchSpecifier.IS_LESS_THAN, -60 * 6); // Up to 6 Hours Ago

        fTodaysNewsSearch = factory.createSearch(null);
        fTodaysNewsSearch.setMatchAllConditions(false);
        fTodaysNewsSearch.addSearchCondition(dayCondition);
        fTodaysNewsSearch.addSearchCondition(recentCondition);
      }

View Full Code Here

  /*
   * @see org.rssowl.core.connection.IProtocolHandler#reload(java.net.URI,
   * org.eclipse.core.runtime.IProgressMonitor, java.util.Map)
   */
  public Triple<IFeed, IConditionalGet, URI> reload(URI link, IProgressMonitor monitor, Map<Object, Object> properties) throws CoreException {
    IModelFactory typesFactory = Owl.getModelFactory();

    /* Create a new empty feed from the existing one */
    IFeed feed = typesFactory.createFeed(null, link);

    /* Add Monitor to support early cancelation */
    if (properties == null)
      properties = new HashMap<Object, Object>();
    properties.put(IConnectionPropertyConstants.PROGRESS_MONITOR, monitor);
View Full Code Here

    /* Otherwise just use input URI */
    return Triple.create(feed, conditionalGet, link);
  }

  protected IConditionalGet getConditionalGet(URI link, InputStream inS) {
    IModelFactory typesFactory = Owl.getModelFactory();

    if (inS instanceof IConditionalGetCompatible) {
      String ifModifiedSince = ((IConditionalGetCompatible) inS).getIfModifiedSince();
      String ifNoneMatch = ((IConditionalGetCompatible) inS).getIfNoneMatch();

      if (ifModifiedSince != null || ifNoneMatch != null)
        return typesFactory.createConditionalGet(ifModifiedSince, link, ifNoneMatch);
    }

    return null;
  }
View Full Code Here

    }

    /* Read JSON Object from Response and parse */
    InputStreamReader reader = null;
    boolean isError = false;
    IModelFactory typesFactory = Owl.getModelFactory();
    IFeed feed = typesFactory.createFeed(null, link);
    feed.setBase(readerToHTTP(link));
    try {
      reader = new InputStreamReader(inS, UTF_8);
      JSONObject obj = new JSONObject(new JSONTokener(reader));
      Owl.getInterpreter().interpretJSONObject(obj, feed);
View Full Code Here

  /*
   * @see org.rssowl.core.interpreter.INamespaceHandler#processElement(org.jdom.Element,
   * org.rssowl.core.model.types.IExtendableType)
   */
  public void processElement(Element element, IPersistable type) {
    IModelFactory factory = Owl.getModelFactory();

    /* Category */
    if ("category".equals(element.getName())) { //$NON-NLS-1$

      /* Process Top-Category (Level 1) */
      processCategory(element, type);

      /* Look for Subcategories (Level 2) */
      List< ? > children = element.getChildren();
      for (Iterator< ? > iter = children.iterator(); iter.hasNext();) {
        Element child = (Element) iter.next();
        if ("category".equals(child.getName())) //$NON-NLS-1$
          processCategory(child, type);
      }
    }

    /* Author */
    else if ("author".equals(element.getName())) { //$NON-NLS-1$
      IPerson person = factory.createPerson(null, type);
      person.setName(element.getText());
    }
  }
View Full Code Here

      person.setName(element.getText());
    }
  }

  private void processCategory(Element element, IPersistable type) {
    IModelFactory factory = Owl.getModelFactory();

    ICategory category = factory.createCategory(null, (IEntity) type);
    List< ? > attributes = element.getAttributes();
    for (Iterator< ? > iter = attributes.iterator(); iter.hasNext();) {
      Attribute attribute = (Attribute) iter.next();
      String name = attribute.getName();
View Full Code Here

      }
    }
  }

  private void processItem(JSONObject item, IFeed feed) throws JSONException, URISyntaxException {
    IModelFactory factory = Owl.getModelFactory();
    INews news = factory.createNews(null, feed, new Date());
    news.setBase(feed.getBase());

    /* GUID */
    if (item.has(ID))
      news.setGuid(factory.createGuid(news, item.getString(ID), true));

    /* Origin */
    if (item.has(ORIGIN)) {
      JSONObject origin = item.getJSONObject(ORIGIN);
      news.setInReplyTo(getString(origin, STREAM_ID));
    }

    /* Title */
    news.setTitle(getString(item, TITLE));

    /* Publish Date */
    news.setPublishDate(getDate(item, UPDATED));

    /* Description */
    news.setDescription(getContent(item));

    /* Link */
    news.setLink(getAlternateLink(item, TEXT_HTML));

    /* Comments */
    URI commentsLink = getCommentsLink(item, TEXT_HTML);
    if (commentsLink != null)
      news.setComments(commentsLink.toString());

    /* Author */
    if (item.has(AUTHOR)) {
      String author = getString(item, AUTHOR);
      if (StringUtils.isSet(author)) {
        IPerson person = factory.createPerson(null, news);
        person.setName(author);
      }
    }

    /* Attachments */
    if (item.has(ENCLOSURE)) {
      JSONArray attachments = item.getJSONArray(ENCLOSURE);
      for (int i = 0; i < attachments.length(); i++) {
        JSONObject attachment = attachments.getJSONObject(i);
        if (attachment.has(HREF)) {
          IAttachment att = factory.createAttachment(null, news);
          att.setLink(new URI(attachment.getString(HREF)));

          if (attachment.has(LENGTH)) {
            try {
              att.setLength(attachment.getInt(LENGTH));
            } catch (JSONException e) {
              // Can happen if the length is larger than Integer.MAX_VALUE, in that case just ignore
            }
          }

          if (attachment.has(TYPE))
            att.setType(attachment.getString(TYPE));
        }
      }
    }

    /* Categories / Labels / State */
    Set<String> labels = new HashSet<String>(1);
    if (item.has(CATEGORIES)) {
      JSONArray categories = item.getJSONArray(CATEGORIES);
      for (int i = 0; i < categories.length(); i++) {
        if (categories.isNull(i))
          continue;

        String category = categories.getString(i);
        if (!StringUtils.isSet(category))
          continue;

        /* Normal user chosen category */
        if (!category.startsWith(GOOGLE_CATEGORY_PREFIX)) {
          ICategory cat = factory.createCategory(null, news);
          cat.setName(category);
        }

        /* News is marked read */
        else if (category.endsWith(GOOGLE_STATE_READ)) {
View Full Code Here

    return importedEntities;
  }

  private void processFilter(Element filterElement, List<IEntity> importedEntities, DateFormat dateFormat) {
    IModelFactory factory = Owl.getModelFactory();

    String name = filterElement.getAttributeValue(Attributes.NAME.get());
    int order = Integer.parseInt(filterElement.getAttributeValue(Attributes.ORDER.get()));
    boolean isEnabled = Boolean.parseBoolean(filterElement.getAttributeValue(Attributes.ENABLED.get()));
    boolean matchAllNews = Boolean.parseBoolean(filterElement.getAttributeValue(Attributes.MATCH_ALL_NEWS.get()));

    /* Search if provided */
    ISearch search = null;
    Element searchElement = filterElement.getChild(Tag.SEARCH.get(), RSSOWL_NS);
    if (searchElement != null) {
      search = factory.createSearch(null);
      search.setMatchAllConditions(Boolean.parseBoolean(searchElement.getAttributeValue(Attributes.MATCH_ALL_CONDITIONS.get())));

      /* Search Conditions */
      List<?> conditions = searchElement.getChildren(Tag.SEARCH_CONDITION.get(), RSSOWL_NS);
      for (int i = 0; i < conditions.size(); i++) {
        try {
          Element condition = (Element) conditions.get(i);

          ISearchCondition searchCondition = processSearchCondition(condition, dateFormat);
          if (searchCondition != null)
            search.addSearchCondition(searchCondition);
        } catch (NumberFormatException e) {
          Activator.getDefault().logError(e.getMessage(), e);
        } catch (ParseException e) {
          Activator.getDefault().logError(e.getMessage(), e);
        }
      }
    }

    /* Filter */
    ISearchFilter filter = factory.createSearchFilter(null, search, name);
    filter.setEnabled(isEnabled);
    filter.setMatchAllNews(matchAllNews);
    filter.setOrder(order);

    /* Filter Actions */
    List<?> actions = filterElement.getChildren(Tag.ACTION.get(), RSSOWL_NS);
    for (int i = 0; i < actions.size(); i++) {
      Element action = (Element) actions.get(i);
      String id = action.getAttributeValue(Attributes.ID.get());
      String data = action.getAttributeValue(Attributes.DATA.get());

      IFilterAction filterAction = factory.createFilterAction(id);
      if (data != null) {

        /* Special case Label Action */
        if (LabelNewsAction.ID.equals(id)) {
          Long labelId = Long.parseLong(data);
View Full Code Here

   * @throws Exception
   * See http://dev.rssowl.org/show_bug.cgi?id=1107
   */
  @Test
  public void testDeleteFolderHierarchyWithBin() throws Exception {
    IModelFactory factory = Owl.getModelFactory();
    IFolder root = factory.createFolder(null, null, "Root");
    IFolder folder = factory.createFolder(null, root, "Folder");
    IFolder childFolder = factory.createFolder(null, folder, "Child Folder");

    IFeed feed = factory.createFeed(null, new URI("http://www.rssowl.org/rssowl2dg/tests/manager/rss_2_0.xml"));

    DynamicDAO.save(feed);

    IBookMark mark = factory.createBookMark(null, childFolder, new FeedLinkReference(feed.getLink()), "Bookmark");
    INewsBin bin = factory.createNewsBin(null, folder, "Bin");

    DynamicDAO.save(root);

    Controller.getDefault().reload(mark, null, new NullProgressMonitor());

    /* Move News to Bin */
    INews copiedNews = factory.createNews(feed.getNews().get(0), bin);
    DynamicDAO.save(copiedNews);
    DynamicDAO.save(bin);

    DynamicDAO.getDAO(INewsDAO.class).setState(Collections.singletonList(feed.getNews().get(0)), INews.State.HIDDEN, false, false);

View Full Code Here

TOP

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

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.