/** * Constructor that parses the given feed representation. * * @param feedRepresentation * The feed representation to parse. * @throws IOException */ public SyndFeedRepresentation(Representation feedRepresentation) throws IOException { super(null); InputSource source = new InputSource(feedRepresentation.getStream()); try { this.feed = new SyndFeedInput().build(source); } catch (IllegalArgumentException e) { IOException ioe = new IOException( "Couldn't read the feed representation. " + e.getMessage()); ioe.initCause(e); throw ioe; } catch (FeedException e) { IOException ioe = new IOException( "Couldn't read the feed representation. " + e.getMessage()); ioe.initCause(e); throw ioe; } setMediaType(getMediaType(this.feed.getFeedType())); }
protected void checkItemsConstraints(Element parent) throws FeedException { int count = parent.getChildren("item",getFeedNamespace()).size(); if (count<1 || count>15) { throw new FeedException("Invalid "+getType()+" feed, item count is "+count+" it must be between 1 an 15"); } }
@Override public String getResultsString(Context context, String format, String query, int totalResults, int start, int pageSize, DSpaceObject scope, List<DSpaceObject> results, Map<String, String> labels) throws IOException { try { return getResults(context, format, query, totalResults, start, pageSize, scope, results, labels) .outputString(); } catch (FeedException e) { log.error(e.toString(), e); throw new IOException("Unable to generate feed", e); } }
public static void writeFeed(SyndFeed feed, FeedType feedType, Writer outputWriter) throws FeedException, IOException { try { feed.setFeedType(feedType.getType()); SyndFeedOutput output = new SyndFeedOutput(); output.output(feed, outputWriter); } catch (FeedException ex) { ex.printStackTrace(); } }
private void doWrite() throws IOException { SyndFeed feed = createSyndFeed(); List<SyndEntry> entries = new ArrayList<SyndEntry>(); if (tgwfeed.isListAccess()) { for (TgwEntry elem : tgwfeed.getEntryList()) { entries.add(toSyndEntry(elem)); } } else { entries.add(toSyndEntry(tgwfeed.getEntry())); } feed.setEntries(entries); try { doWrite(feed); } catch (FeedException e) { e.printStackTrace(); } }
protected void checkItemsConstraints(Element parent) throws FeedException { int count = parent.getChildren("item",getFeedNamespace()).size(); if (count<1 || count>15) { throw new FeedException("Invalid "+getType()+" feed, item count is "+count+" it must be between 1 an 15"); } }
@Override protected void validate(Document document) { try { SyndFeedInput input = new SyndFeedInput(); input.build(getDocument()); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (FeedException e) { if (e instanceof ParsingFeedException) { ParsingFeedException pfe = (ParsingFeedException) e; addError(Type.ERROR, pfe.getLineNumber(), pfe.getColumnNumber(), e.getMessage()); } else { addError(Type.ERROR, -1, -1, e.getMessage()); } } }
@Override public Document getResultsDoc(Context context, String format, String query, int totalResults, int start, int pageSize, DSpaceObject scope, List<DSpaceObject> results, Map<String, String> labels) throws IOException { try { return getResults(context, format, query, totalResults, start, pageSize, scope, results, labels) .outputW3CDom(); } catch (FeedException e) { log.error(e.toString(), e); throw new IOException("Unable to generate feed", e); } }
protected void checkLength(Element parent, String childName, int minLen, int maxLen) throws FeedException { Element child = parent.getChild(childName,getFeedNamespace()); if (child != null) { if (minLen>0 && child.getText().length()<minLen) { throw new FeedException("Invalid "+getType()+" feed, "+parent.getName()+" "+childName + "short of "+minLen+" length"); } if (maxLen>-1 && child.getText().length()>maxLen) { throw new FeedException("Invalid "+getType()+" feed, "+parent.getName()+" "+childName + "exceeds "+maxLen+" length"); } } }
log.info("Failed to fetch the feed:" + te.getMessage()); } catch (FeedException fe) { log.info("Failed to parse the feed:" + fe.getMessage());
protected void checkLength(Element parent, String childName, int minLen, int maxLen) throws FeedException { Element child = parent.getChild(childName,getFeedNamespace()); if (child != null) { if (minLen>0 && child.getText().length()<minLen) { throw new FeedException("Invalid "+getType()+" feed, "+parent.getName()+" "+childName + "short of "+minLen+" length"); } if (maxLen>-1 && child.getText().length()>maxLen) { throw new FeedException("Invalid "+getType()+" feed, "+parent.getName()+" "+childName + "exceeds "+maxLen+" length"); } } }
/** * {@inheritDoc} * * @see org.xwiki.validator.framework.AbstractXMLValidator#validate(org.w3c.dom.Document) */ @Override protected void validate(Document document) { try { SyndFeedInput input = new SyndFeedInput(); input.build(getDocument()); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (FeedException e) { if (e instanceof ParsingFeedException) { ParsingFeedException pfe = (ParsingFeedException) e; addError(Type.ERROR, pfe.getLineNumber(), pfe.getColumnNumber(), e.getMessage()); } else { addError(Type.ERROR, -1, -1, e.getMessage()); } } }
protected void checkNotNullAndLength(Element parent, String childName, int minLen, int maxLen) throws FeedException { Element child = parent.getChild(childName,getFeedNamespace()); if (child == null) { throw new FeedException("Invalid "+getType()+" feed, missing "+parent.getName()+" "+childName); } checkLength(parent,childName,minLen,maxLen); }
public void run ( ) { while ( isActive( ) ) { try { Thread.sleep( rate ); rss_input = new SyndFeedInput(); feed = rss_input.build(new XmlReader(url)); for (SyndEntry entry: (List<SyndEntry>) feed.getEntries()) { String title = entry.getTitle(); String link = entry.getLink(); String description= entry.getDescription().getValue(); String author = entry.getAuthor(); long publish_date = entry.getPublishedDate().getTime(); postStreamElement(publish_date,new Serializable[] {title,author,description,link}); } }catch (com.sun.syndication.io.FeedException e){ logger.error( e.getMessage( ) , e ); }catch ( InterruptedException e ) { logger.error( e.getMessage( ) , e ); }catch (IOException e) { logger.error( e.getMessage( ) , e ); } } }
protected void checkNotNullAndLength(Element parent, String childName, int minLen, int maxLen) throws FeedException { Element child = parent.getChild(childName,getFeedNamespace()); if (child == null) { throw new FeedException("Invalid "+getType()+" feed, missing "+parent.getName()+" "+childName); } checkLength(parent,childName,minLen,maxLen); }
LOG.error( "Feed exception while attempting to write out the final xml file. " + "for site: " + siteId + ". " + e.getMessage(), e); throw new PodcastException(e);
protected void checkItemsConstraints(Element parent) throws FeedException { int count = parent.getChildren("item",getFeedNamespace()).size(); if (count<1 || count>15) { throw new FeedException("Invalid "+getType()+" feed, item count is "+count+" it must be between 1 an 15"); } }
throw new IOException(fex.getMessage(), fex);
protected void checkItemsConstraints(Element parent) throws FeedException { int count = parent.getChildren("item",getFeedNamespace()).size(); if (count<1 || count>15) { throw new FeedException("Invalid "+getType()+" feed, item count is "+count+" it must be between 1 an 15"); } }
@Override @SuppressWarnings("unchecked") public T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { WireFeedInput feedInput = new WireFeedInput(); MediaType contentType = inputMessage.getHeaders().getContentType(); Charset charset; if (contentType != null && contentType.getCharSet() != null) { charset = contentType.getCharSet(); } else { charset = DEFAULT_CHARSET; } try { Reader reader = new InputStreamReader(inputMessage.getBody(), charset); return (T) feedInput.build(reader); } catch (FeedException ex) { throw new HttpMessageNotReadableException("Could not read WireFeed: " + ex.getMessage(), ex); } }