com.rometools.opml.feed.opml.Opml Java Examples
The following examples show how to use
com.rometools.opml.feed.opml.Opml.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OPMLExporterTest.java From commafeed with Apache License 2.0 | 6 votes |
@Test public void generates_OPML_correctly() { when(feedCategoryDAO.findAll(user)).thenReturn(categories); when(feedSubscriptionDAO.findAll(user)).thenReturn(subscriptions); Opml opml = new OPMLExporter(feedCategoryDAO, feedSubscriptionDAO).export(user); List<Outline> rootOutlines = opml.getOutlines(); assertEquals(2, rootOutlines.size()); assertTrue(containsCategory(rootOutlines, "cat1")); assertTrue(containsFeed(rootOutlines, "rootFeed", "rootFeed.com")); Outline cat1Outline = getCategoryOutline(rootOutlines, "cat1"); List<Outline> cat1Children = cat1Outline.getChildren(); assertEquals(2, cat1Children.size()); assertTrue(containsCategory(cat1Children, "cat2")); assertTrue(containsFeed(cat1Children, "cat1Feed", "cat1Feed.com")); Outline cat2Outline = getCategoryOutline(cat1Children, "cat2"); List<Outline> cat2Children = cat2Outline.getChildren(); assertEquals(1, cat2Children.size()); assertTrue(containsFeed(cat2Children, "cat2Feed", "cat2Feed.com")); }
Example #2
Source File: FeedREST.java From commafeed with Apache License 2.0 | 6 votes |
@GET @Path("/export") @UnitOfWork @Produces(MediaType.APPLICATION_XML) @ApiOperation(value = "OPML export", notes = "Export an OPML file of the user's subscriptions") @Timed public Response exportOpml(@ApiParam(hidden = true) @SecurityCheck User user) { Opml opml = opmlExporter.export(user); WireFeedOutput output = new WireFeedOutput(); String opmlString = null; try { opmlString = output.outputString(opml); } catch (Exception e) { return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e).build(); } return Response.ok(opmlString).build(); }
Example #3
Source File: OPML20GeneratorTest.java From rome with Apache License 2.0 | 6 votes |
private NodeList categoryOf(final String... categories) { try { final Outline outline = new Outline("outline1", null); outline.setCategories(Arrays.asList(categories)); final Opml opml = new Opml(); opml.setFeedType("opml_2.0"); opml.setTitle("title"); opml.setOutlines(Arrays.asList(outline)); final WireFeedOutput output = new WireFeedOutput(); final String xml = output.outputString(opml); final Document document = XMLUnit.buildControlDocument(xml); return XMLUnit.newXpathEngine().getMatchingNodes("/opml/body/outline/@category", document); } catch (final Exception e) { throw new RuntimeException(e); } }
Example #4
Source File: ConverterForOPML10.java From rome with Apache License 2.0 | 5 votes |
protected void addOwner(final Opml opml, final SyndFeed syndFeed) { if (opml.getOwnerEmail() != null || opml.getOwnerName() != null) { final List<SyndPerson> authors = new ArrayList<SyndPerson>(); final SyndPerson person = new SyndPersonImpl(); person.setEmail(opml.getOwnerEmail()); person.setName(opml.getOwnerName()); authors.add(person); syndFeed.setAuthors(authors); } }
Example #5
Source File: OPMLExporter.java From commafeed with Apache License 2.0 | 5 votes |
public Opml export(User user) { Opml opml = new Opml(); opml.setFeedType("opml_1.1"); opml.setTitle(String.format("%s subscriptions in CommaFeed", user.getName())); opml.setCreated(new Date()); List<FeedCategory> categories = feedCategoryDAO.findAll(user); Collections.sort(categories, (e1, e2) -> ObjectUtils.firstNonNull(e1.getPosition(), 0) - ObjectUtils.firstNonNull(e2.getPosition(), 0)); List<FeedSubscription> subscriptions = feedSubscriptionDAO.findAll(user); Collections.sort(subscriptions, (e1, e2) -> ObjectUtils.firstNonNull(e1.getPosition(), 0) - ObjectUtils.firstNonNull(e2.getPosition(), 0)); // export root categories for (FeedCategory cat : categories.stream().filter(c -> c.getParent() == null).collect(Collectors.toList())) { opml.getOutlines().add(buildCategoryOutline(cat, categories, subscriptions)); } // export root subscriptions for (FeedSubscription sub : subscriptions.stream().filter(s -> s.getCategory() == null).collect(Collectors.toList())) { opml.getOutlines().add(buildSubscriptionOutline(sub)); } return opml; }
Example #6
Source File: OPMLImporter.java From commafeed with Apache License 2.0 | 5 votes |
public void importOpml(User user, String xml) { xml = xml.substring(xml.indexOf('<')); WireFeedInput input = new WireFeedInput(); try { Opml feed = (Opml) input.build(new StringReader(xml)); List<Outline> outlines = feed.getOutlines(); for (int i = 0; i < outlines.size(); i++) { handleOutline(user, outlines.get(i), null, i); } } catch (Exception e) { log.error(e.getMessage(), e); } }
Example #7
Source File: OpmlConverter.java From SimpleNews with Apache License 2.0 | 5 votes |
public static Opml convertCategoriesToOpml(List<Category> categories) { List<Outline> children = new ArrayList<>(); for (Category category : categories){ children.add(convertFeedsToOutline(category.getName(), category.getFeeds())); } Opml opml = new Opml(); opml.setTitle("SimpleNews - OPML"); opml.setOutlines(children); return opml; }
Example #8
Source File: OpmlConverter.java From SimpleNews with Apache License 2.0 | 5 votes |
public static List<Feed> convertOpmlListToFeedList(Opml opml) { List<Feed> feeds = new ArrayList<>(); for (Outline element : opml.getOutlines()) { feeds.addAll(convertOutlineToFeedList(element)); } return feeds; }
Example #9
Source File: CategorySelectionFragment.java From SimpleNews with Apache License 2.0 | 5 votes |
private void shareCategories(List<Category> categories) { Opml opml = OpmlConverter.convertCategoriesToOpml(categories); String finalMessage = ""; try { finalMessage = new XMLOutputter().outputString(new OPML20Generator().generate(opml)); } catch (FeedException e) { e.printStackTrace(); } Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/xml"); shareIntent.putExtra(Intent.EXTRA_TEXT, finalMessage); startActivity(shareIntent); }
Example #10
Source File: CategoryFeedsFragment.java From SimpleNews with Apache License 2.0 | 5 votes |
private void shareOpml(Opml opml) { String finalMessage = null; try { finalMessage = new XMLOutputter().outputString(new OPML20Generator().generate(opml)); } catch (FeedException e) { e.printStackTrace(); } Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/xml"); shareIntent.putExtra(Intent.EXTRA_TEXT, finalMessage); startActivity(shareIntent); }
Example #11
Source File: OPML20Generator.java From rome with Apache License 2.0 | 5 votes |
@Override protected Element generateHead(final Opml opml) { final Element docsElement = new Element("docs"); docsElement.setText(opml.getDocs()); final Element headElement = super.generateHead(opml); headElement.addContent(docsElement); return headElement; }
Example #12
Source File: OPML10Generator.java From rome with Apache License 2.0 | 5 votes |
protected Element generateHead(final Opml opml) { final Element head = new Element("head"); boolean hasHead = false; if (opml.getCreated() != null) { hasHead |= addNotNullSimpleElement(head, "dateCreated", DateParser.formatRFC822(opml.getCreated(), Locale.US)); } hasHead |= addNotNullSimpleElement(head, "expansionState", intArrayToCsvString(opml.getExpansionState())); if (opml.getModified() != null) { hasHead |= addNotNullSimpleElement(head, "dateModified", DateParser.formatRFC822(opml.getModified(), Locale.US)); } hasHead |= addNotNullSimpleElement(head, "ownerEmail", opml.getOwnerEmail()); hasHead |= addNotNullSimpleElement(head, "ownerName", opml.getOwnerName()); hasHead |= addNotNullSimpleElement(head, "title", opml.getTitle()); hasHead |= addNotNullSimpleElement(head, "vertScrollState", opml.getVerticalScrollState()); hasHead |= addNotNullSimpleElement(head, "windowBottom", opml.getWindowBottom()); hasHead |= addNotNullSimpleElement(head, "windowLeft", opml.getWindowLeft()); hasHead |= addNotNullSimpleElement(head, "windowRight", opml.getWindowRight()); hasHead |= addNotNullSimpleElement(head, "windowTop", opml.getWindowTop()); if (hasHead) { return head; } else { return null; } }
Example #13
Source File: OPML10Generator.java From rome with Apache License 2.0 | 5 votes |
/** * Creates an XML document (JDOM) for the given feed bean. * * @param feed the feed bean to generate the XML document from. * @return the generated XML document (JDOM). * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the * WireFeedGenerator. * @throws FeedException thrown if the XML Document could not be created. */ @Override public Document generate(final WireFeed feed) throws IllegalArgumentException, FeedException { if (!(feed instanceof Opml)) { throw new IllegalArgumentException("Not an OPML file"); } final Opml opml = (Opml) feed; final Document doc = new Document(); final Element root = new Element("opml"); root.setAttribute("version", "1.0"); doc.addContent(root); final Element head = generateHead(opml); if (head != null) { root.addContent(head); } final Element body = new Element("body"); root.addContent(body); super.generateFeedModules(opml.getModules(), root); body.addContent(generateOutlines(opml.getOutlines())); return doc; }
Example #14
Source File: ConverterForOPML10.java From rome with Apache License 2.0 | 5 votes |
/** * Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl. * <p> * It assumes the given SyndFeedImpl has no properties set. * <p> * * @param feed real feed to copy/convert. * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed. */ @Override public void copyInto(final WireFeed feed, final SyndFeed syndFeed) { final Opml opml = (Opml) feed; syndFeed.setTitle(opml.getTitle()); addOwner(opml, syndFeed); syndFeed.setPublishedDate(opml.getModified() != null ? opml.getModified() : opml.getCreated()); syndFeed.setFeedType(opml.getFeedType()); syndFeed.setModules(opml.getModules()); syndFeed.setFeedType(getType()); createEntries(new Stack<Integer>(), syndFeed.getEntries(), opml.getOutlines()); }
Example #15
Source File: OpmlReader.java From reactor-workshop with GNU General Public License v3.0 | 5 votes |
/** * TODO Return {@link reactor.core.publisher.Flux} */ public List<Outline> allFeeds() throws FeedException, IOException { WireFeedInput input = new WireFeedInput(); try(final InputStream inputStream = OpmlReader.class.getResourceAsStream("/feed-jvm-bloggers.xml")) { final InputStreamReader streamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); final Reader reader = new BufferedReader(streamReader); Opml feed = (Opml) input.build(reader); return feed.getOutlines(); } }
Example #16
Source File: CategoryFeedsFragment.java From SimpleNews with Apache License 2.0 | 4 votes |
private void shareFeeds(List<Feed> feeds) { Opml opml = OpmlConverter.convertFeedsToOpml("SimpleNews - OPML", feeds); shareOpml(opml); }
Example #17
Source File: CategoryFeedsFragment.java From SimpleNews with Apache License 2.0 | 4 votes |
private void shareCategory() { List<Category> categories = new ArrayList<>(); categories.add(mCategory); Opml opml = OpmlConverter.convertCategoriesToOpml(categories); shareOpml(opml); }
Example #18
Source File: OpmlConverter.java From SimpleNews with Apache License 2.0 | 4 votes |
public static Opml convertFeedsToOpml(String name, List<Feed> feeds) { Opml opml = new Opml(); opml.setTitle("SimpleNews - OPML"); opml.getOutlines().add(convertFeedsToOutline(name, feeds)); return opml; }
Example #19
Source File: OPML11Generator.java From commafeed with Apache License 2.0 | 4 votes |
@Override protected Element generateHead(Opml opml) { Element head = new Element("head"); addNotNullSimpleElement(head, "title", opml.getTitle()); return head; }