本文整理匯總了Java中com.sun.syndication.io.FeedException類的典型用法代碼示例。如果您正苦於以下問題:Java FeedException類的具體用法?Java FeedException怎麽用?Java FeedException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FeedException類屬於com.sun.syndication.io包,在下文中一共展示了FeedException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readInternal
import com.sun.syndication.io.FeedException; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
protected 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);
}
}
示例2: checkNotNullAndLength
import com.sun.syndication.io.FeedException; //導入依賴的package包/類
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);
}
示例3: checkLength
import com.sun.syndication.io.FeedException; //導入依賴的package包/類
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");
}
}
}
示例4: checkChannelConstraints
import com.sun.syndication.io.FeedException; //導入依賴的package包/類
protected void checkChannelConstraints(Element eChannel) throws FeedException {
checkNotNullAndLength(eChannel,"title", 1, 100);
checkNotNullAndLength(eChannel,"description", 1, 500);
checkNotNullAndLength(eChannel,"link", 1, 500);
checkNotNullAndLength(eChannel,"language", 2, 5);
checkLength(eChannel,"rating", 20, 500);
checkLength(eChannel,"copyright", 1, 100);
checkLength(eChannel,"pubDate", 1, 100);
checkLength(eChannel,"lastBuildDate", 1, 100);
checkLength(eChannel,"docs", 1, 500);
checkLength(eChannel,"managingEditor", 1, 100);
checkLength(eChannel,"webMaster", 1, 100);
Element skipHours = eChannel.getChild("skipHours");
if (skipHours!=null) {
List hours = skipHours.getChildren();
for (int i=0;i<hours.size();i++) {
Element hour = (Element) hours.get(i);
int value = Integer.parseInt(hour.getText());
if (isHourFormat24()) {
if (value<1 || value>24) {
throw new FeedException("Invalid hour value "+value+", it must be between 1 and 24");
}
}
else {
if (value<0 || value>23) {
throw new FeedException("Invalid hour value "+value+", it must be between 0 and 23");
}
}
}
}
}
示例5: doGet
import com.sun.syndication.io.FeedException; //導入依賴的package包/類
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException {
try {
SyndFeed feed = getFeed(req);
String feedType = req.getParameter(FEED_TYPE);
feedType = (feedType!=null) ? feedType : _defaultFeedType;
feed.setFeedType(feedType);
res.setContentType(MIME_TYPE);
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed,res.getWriter());
}
catch (FeedException ex) {
String msg = COULD_NOT_GENERATE_FEED_ERROR;
log(msg,ex);
res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,msg);
}
}
示例6: getFeedDocuments
import com.sun.syndication.io.FeedException; //導入依賴的package包/類
/**
* Get feed documents
*/
private SyndFeed getFeedDocuments(List<DashboardDocumentResult> result) throws FeedException, SQLException,
IOException {
List<SyndEntry> entries = new ArrayList<SyndEntry>();
SyndFeed feed = new SyndFeedImpl();
for (DashboardDocumentResult item : result) {
SyndEntry entry = new SyndEntryImpl();
entry.setTitle(item.getDocument().getPath());
entry.setAuthor(item.getDocument().getActualVersion().getAuthor());
entry.setPublishedDate(item.getDate().getTime());
entry.setLink(Config.APPLICATION_URL + "?docPath="
+ URLEncoder.encode(item.getDocument().getPath(), "UTF-8"));
entries.add(entry);
}
feed.setEntries(entries);
return feed;
}
示例7: getFeedFolders
import com.sun.syndication.io.FeedException; //導入依賴的package包/類
/**
* Get feed folders
*/
private SyndFeed getFeedFolders(List<DashboardFolderResult> result) throws FeedException, SQLException, IOException {
List<SyndEntry> entries = new ArrayList<SyndEntry>();
SyndFeed feed = new SyndFeedImpl();
for (DashboardFolderResult item : result) {
SyndEntry entry = new SyndEntryImpl();
entry.setTitle(item.getFolder().getPath());
entry.setAuthor(item.getFolder().getAuthor());
entry.setPublishedDate(item.getDate().getTime());
entry.setLink(Config.APPLICATION_URL + "?fldPath=" + URLEncoder.encode(item.getFolder().getPath(), "UTF-8"));
entries.add(entry);
}
feed.setEntries(entries);
return feed;
}
示例8: getFeedMails
import com.sun.syndication.io.FeedException; //導入依賴的package包/類
/**
* Get feed mails
*/
private SyndFeed getFeedMails(List<DashboardMailResult> result) throws FeedException, SQLException, IOException {
List<SyndEntry> entries = new ArrayList<SyndEntry>();
SyndFeed feed = new SyndFeedImpl();
for (DashboardMailResult item : result) {
SyndEntry entry = new SyndEntryImpl();
entry.setTitle(item.getMail().getPath());
entry.setAuthor(item.getMail().getFrom());
entry.setPublishedDate(item.getDate().getTime());
entry.setLink(Config.APPLICATION_URL + "?docPath=" + URLEncoder.encode(item.getMail().getPath(), "UTF-8"));
entries.add(entry);
}
feed.setEntries(entries);
return feed;
}
示例9: createFeed
import com.sun.syndication.io.FeedException; //導入依賴的package包/類
@Override
public @Nonnull FeedCreatorImpl createFeed(@Nullable String itemSelector, @Nullable String titleSelector,
@Nullable String linkSelector, @Nullable String authorSelector)
throws MalformedURLException, FeedException, IOException {
if(itemSelector == null) {
throw new IllegalArgumentException(String.format("The item selector for the page %s must not be null.", pageUrl));
}
String pageContent = urlLoaderFactory.getUrlLoader(pageUrl).getContentAsString();
feed.setFeedType("atom_0.3");
feed.setEntries(new PageContentExtractor(itemSelector)
.extractPageElements(pageContent, pageUrl)
.getGroupedPageElements()
.stream()
.map(extractedPageElement -> createFeedEntry(extractedPageElement, titleSelector, linkSelector, authorSelector))
.collect(Collectors.toList()));
return this;
}
示例10: parseEntry
import com.sun.syndication.io.FeedException; //導入依賴的package包/類
/**
* Parse entry from reader.
*/
public static Entry parseEntry(Reader rd, String baseURI)
throws JDOMException, IOException, IllegalArgumentException, FeedException {
// Parse entry into JDOM tree
SAXBuilder builder = new SAXBuilder();
Document entryDoc = builder.build(rd);
Element fetchedEntryElement = entryDoc.getRootElement();
fetchedEntryElement.detach();
// Put entry into a JDOM document with 'feed' root so that Rome can handle it
Feed feed = new Feed();
feed.setFeedType("atom_1.0");
WireFeedOutput wireFeedOutput = new WireFeedOutput();
Document feedDoc = wireFeedOutput.outputJDom(feed);
feedDoc.getRootElement().addContent(fetchedEntryElement);
if (baseURI != null) {
feedDoc.getRootElement().setAttribute("base", baseURI, Namespace.XML_NAMESPACE);
}
WireFeedInput input = new WireFeedInput();
Feed parsedFeed = (Feed)input.build(feedDoc);
return (Entry)parsedFeed.getEntries().get(0);
}
示例11: serializeEntry
import com.sun.syndication.io.FeedException; //導入依賴的package包/類
/**
* Utility method to serialize an entry to writer.
*/
public static void serializeEntry(Entry entry, Writer writer)
throws IllegalArgumentException, FeedException, IOException {
// Build a feed containing only the entry
List entries = new ArrayList();
entries.add(entry);
Feed feed1 = new Feed();
feed1.setFeedType("atom_1.0");
feed1.setEntries(entries);
// Get Rome to output feed as a JDOM document
WireFeedOutput wireFeedOutput = new WireFeedOutput();
Document feedDoc = wireFeedOutput.outputJDom(feed1);
// Grab entry element from feed and get JDOM to serialize it
Element entryElement= (Element)feedDoc.getRootElement().getChildren().get(0);
XMLOutputter outputter = new XMLOutputter();
outputter.output(entryElement, writer);
}
示例12: read
import com.sun.syndication.io.FeedException; //導入依賴的package包/類
public void read() {
try {
URL source = new URL(Defaults.FEEDURL);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(source));
@SuppressWarnings("unchecked")
List<SyndEntry> entries = feed.getEntries();
urls = new ArrayList<String>();
for(SyndEntry entry : entries) {
String sURL = entry.getLink();
urls.add(sURL);
} // for
} catch (IllegalArgumentException | FeedException | IOException e) {
e.printStackTrace();
}
long seed = System.nanoTime();
Collections.shuffle(urls, new Random(seed));
}
示例13: doGet
import com.sun.syndication.io.FeedException; //導入依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String sourceConfigurationId = req.getPathInfo();
log.info("Received " + sourceConfigurationId);
SourceConfiguration sourceConfiguration = Configuration.sourceConfigurations.get(sourceConfigurationId);
if (sourceConfiguration == null) {
log.severe("Wrong resource " + req.getPathInfo());
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
List<SourceItem> items = DatabaseService.getItems(sourceConfigurationId, 25);
SyndFeed feed = FeedUtils.createFeed(sourceConfigurationId, sourceConfiguration, items);
SyndFeedOutput output = new SyndFeedOutput();
resp.setCharacterEncoding("UTF-8");
PrintWriter writer = resp.getWriter();
try {
output.output(feed, writer);
} catch (FeedException e) {
e.printStackTrace();
}
writer.close();
}
示例14: writeInternal
import com.sun.syndication.io.FeedException; //導入依賴的package包/類
@Override
protected void writeInternal(T wireFeed, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
String wireFeedEncoding = wireFeed.getEncoding();
if (!StringUtils.hasLength(wireFeedEncoding)) {
wireFeedEncoding = DEFAULT_CHARSET.name();
}
MediaType contentType = outputMessage.getHeaders().getContentType();
if (contentType != null) {
Charset wireFeedCharset = Charset.forName(wireFeedEncoding);
contentType = new MediaType(contentType.getType(), contentType.getSubtype(), wireFeedCharset);
outputMessage.getHeaders().setContentType(contentType);
}
WireFeedOutput feedOutput = new WireFeedOutput();
try {
Writer writer = new OutputStreamWriter(outputMessage.getBody(), wireFeedEncoding);
feedOutput.output(wireFeed, writer);
}
catch (FeedException ex) {
throw new HttpMessageNotWritableException("Could not write WireFeed: " + ex.getMessage(), ex);
}
}
示例15: parse
import com.sun.syndication.io.FeedException; //導入依賴的package包/類
/**
* Parses the data from the supplied InputStream, using the supplied baseURI
* to resolve any relative URI references.
*
* @param in The InputStream from which to read the data.
* @param baseURI The URI associated with the data in the InputStream.
* @throws java.io.IOException If an I/O error occurred while data was read from the InputStream.
* @throws org.openrdf.rio.RDFParseException
* If the parser has found an unrecoverable parse error.
* @throws org.openrdf.rio.RDFHandlerException
* If the configured statement handler has encountered an
* unrecoverable error.
*/
@Override
public void parse(InputStream in, String baseURI) throws IOException, RDFParseException, RDFHandlerException {
Preconditions.checkNotNull(baseURI);
setBaseURI(baseURI);
WireFeedInput input = new WireFeedInput();
try {
WireFeed feed = input.build(new InputSource(in));
if(feed instanceof Channel) {
parseFeed((Channel) feed);
} else {
throw new RDFParseException("data stream is not an RSS feed");
}
} catch (FeedException e) {
throw new RDFParseException(e);
}
}