Package org.olat.modules.webFeed.models

Examples of org.olat.modules.webFeed.models.Item


   * @see org.olat.core.gui.control.generic.dtabs.Activateable#activate(org.olat.core.gui.UserRequest, java.lang.String)
   */
  public void activate(UserRequest ureq, String itemId) {
    int index = feed.getItemIds().indexOf(itemId);
    if (index >= 0) {
      Item item = feed.getItems().get(index);
      itemsCtr.activate(ureq, item);
    }
  }
View Full Code Here


    if (feed.isExternal() && (feed.getItemIds() == null || feed.getItemIds().size() == 0)) {
      items = getItemsFromFeed(feed);
    } else if (feed.getItemIds() != null) {
      for (String itemId : feed.getItemIds()) {
        // No sync needed here
        Item item = (Item) initFeedCache().get(itemKey(itemId, feed.getId().toString()));
        if (item != null) {
          items.add(item);
        } else {
          // reload all items
          items = loadItems(feed);
View Full Code Here

      // Load from virtual file system
      VFSContainer itemsContainer = getItemsContainer(feed);

      for (String itemId : feed.getItemIds()) {
        VFSItem itemContainer = itemsContainer.resolve(itemId);
        Item item = loadItem(itemContainer);
        if (item != null) {
          items.add(item);
        }
      }
    }
View Full Code Here

    List<Item> items = new ArrayList<Item>();
    SyndFeed feed = getSyndFeed(extFeed);
    if (feed != null) {
      List<SyndEntry> entries = feed.getEntries();
      for (SyndEntry entry : entries) {
        Item item = convertToItem(entry);
        items.add(item);
      }
    }
    return items;
  }
View Full Code Here

  private Item convertToItem(SyndEntry entry) {
    // A SyncEntry can potentially have many attributes like title, description,
    // guid, link, enclosure or content. In OLAT, however, items are limited
    // to the attributes, title, description and one media file (called
    // enclosure in RSS) for simplicity.
    Item e = new Item();
    e.setTitle(entry.getTitle());
    e.setDescription(entry.getDescription() != null ? entry.getDescription().getValue() : null);
    // Extract content objects from syndication item
    StringBuffer sb = new StringBuffer();
    for (SyndContent content : (List<SyndContent>) entry.getContents()) {
      // we don't check for type, assume it is html or txt
      if (sb.length() > 0) {
        sb.append("<p />");
      }
      sb.append(content.getValue());
    }
    // Set aggregated content from syndication item as our content
    if (sb.length() > 0) {
      e.setContent(sb.toString());     
    }
    e.setGuid(entry.getUri());
    e.setExternalLink(entry.getLink());
    e.setLastModified(entry.getUpdatedDate());
    e.setPublishDate(entry.getPublishedDate());

    for (Object enclosure : entry.getEnclosures()) {
      if (enclosure instanceof SyndEnclosure) {
        SyndEnclosure syndEnclosure = (SyndEnclosure) enclosure;
        Enclosure media = new Enclosure();
        media.setExternalUrl(syndEnclosure.getUrl());
        media.setType(syndEnclosure.getType());
        media.setLength(syndEnclosure.getLength());
        e.setEnclosure(media);
      }
      // Break after one cycle because only one media file is supported
      break;
    }
    return e;
View Full Code Here

   * @param container
   * @return The item
   */
  public static Item loadItem(VFSItem container) {
    VFSLeaf itemLeaf = null;
    Item item = null;

    if (container != null) {
      itemLeaf = (VFSLeaf) container.resolve(ITEM_FILE_NAME);
      if (itemLeaf != null) {
        item = (Item) XStreamHelper.readObject(xstream, itemLeaf.getInputStream());
View Full Code Here

  @Override
  protected void event(UserRequest ureq, Component source, @SuppressWarnings("unused") Event event) {
    FeedManager feedManager = FeedManager.getInstance();
    Feed feed = feedManager.readFeed(feedResource);
    if (source == addItemButton) {
      currentItem = new Item();
      currentItem.setDraft(true);
      currentItem.setAuthorKey(ureq.getIdentity().getKey());
      // Generate new GUID for item, needed for media files that are stored relative to the GUID
      currentItem.setGuid(CodeHelper.getGlobalForeverUniqueID());
      // Create item and media containers
      feedManager.createItemContainer(feed, currentItem);
      itemFormCtr = uiFactory.createItemFormController(ureq, getWindowControl(), currentItem, feed);
      activateModalDialog(itemFormCtr);

    } else if (editButtons != null && editButtons.contains(source)) {
      currentItem = (Item) ((Link) source).getUserObject();
      lock = feedManager.acquireLock(feed, currentItem, getIdentity());
      if (lock.isSuccess()) {

        itemFormCtr = uiFactory.createItemFormController(ureq, getWindowControl(), currentItem, feed);
        activateModalDialog(itemFormCtr);
      } else {
        showInfo("feed.item.is.being.edited.by", lock.getOwner().getName());
      }
    } else if (deleteButtons != null && deleteButtons.contains(source)) {
      Item item = (Item) ((Link) source).getUserObject();
      confirmDialogCtr = activateYesNoDialog(ureq, null, translate("feed.item.confirm.delete"), confirmDialogCtr);
      confirmDialogCtr.setUserObject(item);

    } else if (itemLinks != null && itemLinks.contains(source)) {
      Item item = (Item) ((Link) source).getUserObject();
      displayItemController(ureq, item);

    } else if (source == makeInternalButton) {
      feedManager.updateFeedMode(Boolean.FALSE, feed);
      addItemButton = LinkFactory.createButton("feed.add.item", vcItems, this);
      currentItem = new Item();
      currentItem.setAuthorKey(ureq.getIdentity().getKey());
      // Generate new GUID for item, needed for media files that are stored relative to the GUID
      currentItem.setGuid(CodeHelper.getGlobalForeverUniqueID());
      // Create item and media containers
      feedManager.createItemContainer(feed, currentItem);
View Full Code Here

          makeInternalAndExternalButtons();
        }
      }
    } else if (source == confirmDialogCtr && DialogBoxUIFactory.isYesEvent(event)) {
      // The user confirmed that the item shall be deleted
      Item item = (Item) ((DialogBoxController) source).getUserObject();
      lock = feedManager.acquireLock(feed, item, getIdentity());
      if (lock.isSuccess()) {
        // remove the item from the naviCtr
        naviCtr.remove(item);
        // remove the item also from the helper (cached selection)
        helper.removeItem(item);
        // permanently remove item
        feedManager.remove(item, feed);
        // remove delete and edit buttons of this item
        deleteButtons.remove(source);
        for (Link editButton : editButtons) {
          if (editButton.getUserObject() == item) {
            editButtons.remove(editButton);
            break;
          }
        }
        // If the last item has been deleted, provide buttons for adding
        // items manually or from an external source/feed.
        if (!feed.hasItems()) {
          makeInternalAndExternalButtons();
          // The subscription/feed url from the feed info is obsolete
          fireEvent(ureq, ItemsController.FEED_INFO_IS_DIRTY_EVENT);
        }
        vcItems.setDirty(true);
        // in case we were in single item view, show all items
        mainPanel.setContent(vcItems);
        feedManager.releaseLock(lock);
        lock = null;       
        // do logging
        ThreadLocalUserActivityLogger.log(FeedLoggingAction.FEED_ITEM_DELETE, getClass(), LoggingResourceable.wrap(item));

      } else {
        showInfo("feed.item.is.being.edited.by", lock.getOwner().getName());
      }

    } else if (source == itemFormCtr) {
      if (event.equals(Event.CHANGED_EVENT) || event.equals(Event.CANCELLED_EVENT)) {
        if (event.equals(Event.CHANGED_EVENT)) {
          FileElement mediaFile = currentItem.getMediaFile();
          if (!feed.getItems().contains(currentItem)) {
            // Add the modified item if it is not part of the feed
            feedManager.addItem(currentItem, mediaFile, feed);
            createButtonsForItem(currentItem);
            createItemLink(currentItem);
            // Add date component
            String guid = currentItem.getGuid();
            if(currentItem.getDate() != null) {
              DateComponentFactory.createDateComponentWithYear("date." + guid, currentItem.getDate(), vcItems);
            }
            // Add comments and rating
            createCommentsAndRatingsLink(ureq, feed, currentItem);
            // add it to the navigation controller
            naviCtr.add(currentItem);
            // ... and also to the helper
            helper.addItem(currentItem);
            if (feed.getItems().size() == 1) {
              // First item added, show feed url (for subscription)
              fireEvent(ureq, ItemsController.FEED_INFO_IS_DIRTY_EVENT);
              // Set the base URI of the feed for the current user. All users
              // have unique URIs.
              helper.setURIs();
            }
            // do logging
            ThreadLocalUserActivityLogger.log(FeedLoggingAction.FEED_ITEM_CREATE, getClass(), LoggingResourceable.wrap(currentItem));
          } else {
            // write item file
            feedManager.updateItem(currentItem, mediaFile, feed);
            // do logging
            ThreadLocalUserActivityLogger.log(FeedLoggingAction.FEED_ITEM_EDIT, getClass(), LoggingResourceable.wrap(currentItem));
          }
          vcItems.setDirty(true);
          // if the current item is displayed, update the view
          if (itemCtr != null) {
            itemCtr.getInitialComponent().setDirty(true);
          }

        } else if (event.equals(Event.CANCELLED_EVENT)) {
          // Check if this item has ever been added to the feed. If not, remove the temp dir
          cleanupTmpItemMediaDir(currentItem, feed, feedManager);
          // If there were no items and the user doesn't want to save the
          // first item, go back to the decision whether to make the feed
          // internally or subscribe to an external feed.
          if (!feed.hasItems()) {
            feedManager.updateFeedMode(null, feed);
            makeInternalAndExternalButtons();
          }
        }
        // release the lock
        feedManager.releaseLock(lock);

        // Dispose the cmc and the podcastFormCtr.
        cmc.deactivate();
        removeAsListenerAndDispose(cmc);
        cmc = null;
        removeAsListenerAndDispose(itemFormCtr);
        itemFormCtr = null;
      }
    } else if (source == naviCtr && event instanceof NavigationEvent) {
      List<? extends Dated> selItems = ((NavigationEvent) event).getSelectedItems();
      List<Item> items = new ArrayList<Item>();
      for (Dated item : selItems) {
        if (item instanceof Item) {
          items.add((Item) item);
        }
      }
      // make sure items are sorted properly
      Collections.sort(items, new ItemPublishDateComparator());
      helper.setSelectedItems(items);
      vcItems.setDirty(true);
      mainPanel.setContent(vcItems);

    } else if (source == itemCtr) {
      if (event == Event.BACK_EVENT) {
        mainPanel.setContent(vcItems);
      }
     
    } else if (source instanceof UserCommentsAndRatingsController) {
      UserCommentsAndRatingsController commentsRatingsCtr = (UserCommentsAndRatingsController) source;
      if (event == UserCommentsAndRatingsController.EVENT_COMMENT_LINK_CLICKED) {
        // go to details page
        Item item = (Item) commentsRatingsCtr.getUserObject();
        ItemController myItemCtr = displayItemController(ureq, item);
        myItemCtr.activate(ureq, ItemController.ACTIVATION_KEY_COMMENTS);
      }
    }
  }
View Full Code Here

    for (int i = 0; i < allItems.size(); i++) {
      if (items.size() == itemsToDisplay) {
        break;
      }
      // add item itself if published
      Item item = allItems.get(i);
      if (item.isPublished()) {
        items.add(item);
        // add link to item
        // Add link to jump to course node
        Link nodeLink = LinkFactory.createLink("nodeLink_" + item.getGuid(), peekviewVC, this);
        nodeLink.setCustomDisplayText(item.getTitle());
        nodeLink.setCustomEnabledLinkCSS("b_with_small_icon_left o_feed_item_icon o_gotoNode");
        nodeLink.setUserObject(item.getGuid());
      }
    }
    peekviewVC.contextPut("items", items);
    // Add link to show all items (go to node)
    Link allItemsLink = LinkFactory.createLink("peekview.allItemsLink", peekviewVC, this);
View Full Code Here

            } else {
              int validItemsCount = 0;
              for (String itemId : itemIds) {
                // Try loading each item
                VFSItem itemContainer = itemsContainer.resolve(itemId);
                Item item = FeedManagerImpl.loadItem(itemContainer);
                if (item != null) {
                  // This item is valid, increase the counter
                  validItemsCount++;
                }
              }
View Full Code Here

TOP

Related Classes of org.olat.modules.webFeed.models.Item

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.