// @Transactional public int importData( final SyndFeed feed, Set<KiWiUriResource> types, Set<ContentItem> tags, final User user, final Collection<ContentItem> output) { log.info( "importing entries from #0 feed '#1' found at '#2'", feed.getFeedType(), feed.getTitle(), feed.getUri()); if (types == null) { types = new HashSet<KiWiUriResource>(); } if (tags == null) { tags = new HashSet<ContentItem>(); } final Set<ContentItem> my_tags = tags; final Set<KiWiUriResource> my_types = types; // a hack for importing facebook activity streams: if the type is kiwi:FacebookPost, // turn facebook activity stream mode on; in this mode, we will skip all entries where // the remote author name and local user name are not identical boolean facebookImport = false; String t_facebookPost = Constants.NS_KIWI_CORE + "FacebookPost"; for (KiWiUriResource r : types) { if (r.getUri().equals(t_facebookPost)) { facebookImport = true; break; } } for (final SyndEntry entry : (List<SyndEntry>) feed.getEntries()) { // facebook hack ... (see above) if (facebookImport && !entry.getAuthor().equalsIgnoreCase(user.getFirstName() + " " + user.getLastName())) { log.info("Facebook import: skipping friend post with title", entry.getTitle()); continue; } new RunAsOperation() { @Override public void execute() { importEntry(feed, entry, my_types, my_tags, user, output); } }.addRole("admin").run(); } // entityManager.flush(); log.info("#0 content items have been imported from RSS/Atom feed", feed.getEntries().size()); return feed.getEntries().size(); }
@Override protected void processModel( Map<String, Object> model, DecoratorRequest request, DecoratorResponse response) throws Exception { super.processModel(model, request, response); Map<String, Object> conf = new HashMap<String, Object>(); String urls = request.getStringParameter(Parameter.URLS.getId()); if (urls == null) { throw new DecoratorComponentException("Component parameter 'urls' is required"); } String feedTitle = request.getStringParameter(Parameter.FEED_TITLE.getId()); if (feedTitle != null) { conf.put("feedTitleValue", feedTitle.trim()); } if (parameterHasValue(PARAMETER_ITEM_PICTURE, "true", request)) { conf.put("itemPicture", true); } if (!parameterHasValue(Parameter.DISPLAY_CHANNEL.getId(), "false", request)) { conf.put("displayChannel", true); } if (parameterHasValue(Parameter.ITEM_DESCRIPTION.getId(), "true", request)) { conf.put("itemDescription", true); } conf.put("maxMsgs", 10); String maxMsgsString = request.getStringParameter(Parameter.MAX_MESSAGES.getId()); if (maxMsgsString != null) { try { int tmpInt = Integer.parseInt(maxMsgsString); if (tmpInt > 0) { conf.put("maxMsgs", tmpInt); } } catch (Exception e) { } } String publishedDateString = request.getStringParameter(Parameter.PUBLISHED_DATE.getId()); if ("none".equals(publishedDateString)) { conf.put("publishedDate", null); } else if ("date".equals(publishedDateString)) { conf.put("publishedDate", "short"); } else { conf.put("publishedDate", "long"); } // Typical sort strings we handle: // asc // item-title // item-title desc // desc item-title // etc.. String sortString = request.getStringParameter(Parameter.SORT.getId()); // Indicates explicitly set sort direction boolean directionSpecified = false; if (sortString != null) { StringTokenizer tokenizer = new StringTokenizer(sortString); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if ("item-title".equals(token)) { conf.put("sortByTitle", true); if (!directionSpecified) { // Set to default for title, if not already specified. conf.put("sortAscending", true); } } else if ("asc".equalsIgnoreCase(token)) { conf.put("sortAscending", true); directionSpecified = true; } else if ("desc".equalsIgnoreCase(token)) { conf.remove("sortAscending"); directionSpecified = true; } } } boolean includeIfEmpty = true; String includeIfEmptyParam = request.getStringParameter(Parameter.INCLUDE_IF_EMPTY.getId()); if ("false".equalsIgnoreCase(includeIfEmptyParam)) { includeIfEmpty = false; } conf.put("includeIfEmpty", includeIfEmpty); String displayCategoriesParam = request.getStringParameter(Parameter.DISPLAY_CATEGORIES.getId()); if (displayCategoriesParam != null && "true".equalsIgnoreCase(displayCategoriesParam)) { conf.put("displayCategories", true); } SyndFeed feed = new SyndFeedImpl(); feed.setTitle("Aggregated Feed"); feed.setDescription("Vortex Aggregated Feed"); feed.setAuthor("Vortex"); feed.setLink("http://www.uio.no"); List<SyndEntry> entries = new ArrayList<SyndEntry>(); feed.setEntries(entries); Map<SyndEntry, SyndFeed> feedMapping = new HashMap<SyndEntry, SyndFeed>(); boolean displayChannel = conf.get("displayChannel") != null && (Boolean) conf.get("displayChannel"); if (displayChannel) { model.put("feedMapping", new FeedMapping(feedMapping)); } URL requestURL = RequestContext.getRequestContext().getRequestURL(); String[] urlArray = urls.split(","); Map<String, String> imgMap = new HashMap<String, String>(); Map<String, String> descriptionNoImage = new HashMap<String, String>(); parseFeeds(request, entries, feedMapping, imgMap, descriptionNoImage, requestURL, urlArray); try { sort(entries); } catch (MissingPublishedDateException e) { SyndFeed f = feedMapping.get(e.getEntry()); throw new MissingPublishedDateException( "Unable to sort feed '" + f.getUri() + "': does not contain published date"); } List<String> elementOrder = getElementOrder(PARAMETER_FEED_ELEMENT_ORDER, request); model.put("elementOrder", elementOrder); model.put("descriptionNoImage", descriptionNoImage); model.put("imageMap", imgMap); String displayIfEmptyMessage = request.getStringParameter(PARAMETER_IF_EMPTY_MESSAGE); if (displayIfEmptyMessage != null && displayIfEmptyMessage.length() > 0) { model.put("displayIfEmptyMessage", displayIfEmptyMessage); } /* Temp fix for auth variable in ftl. */ conf.put("auth", true); model.put("feed", feed); model.put("conf", conf); }