📄 rssmacro.java
字号:
}
buf.append(NEWLINE).append("</div>"); // close rss.item
}
/**
* Render the 'title' of the given RSS Channel to the <code>Writer</code>.
* @param feed the RSS Channel we retrieved via the Feed URL
* @param writer the output writer
* @param paramObj our parameter helper object
* @throws java.io.IOException from calls to <code>writer.write()</code>
*/
private void renderTitle(SyndFeed feed, Writer writer, RSSMacroParameters paramObj) throws java.io.IOException
{
StringBuffer buf = new StringBuffer();
if (paramObj.isCss())
{
renderTitleCSS(feed, buf);
} else {
renderTitleDefault(feed, buf);
}
writer.write(buf.toString());
}
/**
* Render the title from the given Channel to the given StringBuffer,
* using standard Radeox filtering tags.
* @param feed the RSS Channel we retrieved via the Feed URL
* @param buf the StringBuffer we're using to prepare the output
*/
private void renderTitleDefault(SyndFeed feed, StringBuffer buf) {
buf.append("__");
if (feed.getLink() != null) buf.append("{link:");
buf.append(feed.getTitle());
if (feed.getLink() != null)
{
buf.append("|")
.append(feed.getLink())
.append("}");
}
buf.append("__\n\n");
}
/**
* Render the title from the given Channel to the given StringBuffer,
* using CSS styled 'div' tags. In this case, the title will be enclosed
* in a <div> with the class <code>rss.channel.title</code>. If
* the channel includes a link, the title will be rendered as a link to
* that URL, and the <a> tag will also be of class
* <code>rss.channel.title</code>
* @param feed the RSS Channel we retrieved via the Feed URL
* @param buf the StringBuffer we're using to prepare the output
* TODO Figure out how to stop Radeox from filtering the URLs
*/
private void renderTitleCSS(SyndFeed feed, StringBuffer buf) {
buf.append(NEWLINE).append("<div class='rsschanneltitle'>");
if (feed.getLink() != null)
{
buf.append("<a class='rsschanneltitle' href=\"")
.append(Encoder.escape(feed.getLink()))
.append("\">");
}
buf.append(feed.getTitle());
if (feed.getLink() != null) buf.append("</a>");
buf.append(NEWLINE).append("</div>");
}
/**
* If a parameter was passed with the name "img" and the literal value "true",
* render the image from the channel (if it has one.) This requires the use
* of named parameters.
* @param feed the RSS Channel we retrieved via the Feed URL
* @param writer the output writer
* @param paramObj our parameter helper object
* @throws java.io.IOException from calls to <code>writer.write()</code>
*/
private void renderImage(SyndFeed feed, Writer writer, RSSMacroParameters paramObj) throws java.io.IOException
{
if (feed.getImage() == null) return;
if (!(paramObj.isImg())) return;
SyndImage rssImage = feed.getImage();
StringBuffer buf = new StringBuffer(NEWLINE + "{image:");
buf.append("img=").append(rssImage.getUrl());
buf.append("|link=").append(feed.getLink());
buf.append("|align=").append(paramObj.getAlign());
if (rssImage.getDescription() != null)
{
buf.append("|alt=").append(rssImage.getDescription());
}
buf.append("}");
Logger.debug("*** RSS image: " + buf);
writer.write(buf.toString());
}
/**
* CSS styles are used because there is no way
* to render this using 'default' because org.snipsnap.render.macro.FieldMacro
* only permits form submission to other snips. Body of this method
* essentially adapted from that implementation.
* Entire block will be wrapped in a div, class 'rss.textinput'.
* Description will be in a div, class 'rss.textinput.description'.
* <form> element will be class 'rss.textinput.form'.
* Field will be an HTML <input> (type text) tag, class 'rss.textinput.field'.
* Submit button will be an HTML <input> (type submit), class
* 'rss.textinput.submit'.
* @param feed the RSS Channel we retrieved via the Feed URL
* @param writer the output writer
* @param paramObj our parameter helper object
* @throws java.io.IOException from calls to <code>writer.write()</code>
*/
private void renderSearch(SyndFeed feed, Writer writer, RSSMacroParameters paramObj) throws java.io.IOException
{
if (!(paramObj.isSearch())) return;
WireFeed wireFeed = feed.createWireFeed();
if (!(wireFeed instanceof Channel)) return;
TextInput textInput = ((Channel)wireFeed).getTextInput();
if (textInput == null) return;
writer.write(NEWLINE);
writer.write("\\\\");
writer.write(NEWLINE);
writer.write("<div class='rsstextinput'>");
writer.write(NEWLINE);
writer.write("<div class='rsstextinputdescription'>");
writer.write(textInput.getDescription());
writer.write("</div>"); // end rss.textinput.description
writer.write(NEWLINE);
writer.write("<form class='rsstextinputform' action=\"");
writer.write(Encoder.escape(textInput.getLink()));
writer.write("\" method=\"get\">");
writer.write(NEWLINE);
writer.write("<input class='rsstextinputfield' size=\"18\" name=\"");
writer.write(textInput.getName());
writer.write("\"");
writer.write("/>");
writer.write(NEWLINE);
writer.write(" <input class='rsstextinputsubmit' type=\"submit\" name=\"submit\" value=\"");
writer.write(textInput.getTitle());
writer.write("\"/>");
writer.write("</form>");
writer.write(NEWLINE);
writer.write("</div>"); // end rss.textinput
}
/**
* @return the MacroFilter's parameter descriptions:
* <ul>
* <li>feed: url of an RSS feed</li>
* <li>?img: if 'true' and if feed has an image, image will be included</li>
* <li>?align: if an image will be included, use this alignment</li>
* <li>?css: if 'true', elements will be created with CSS styles; otherwise, static formatting methods will be used</li>
* <li>?count: an integer, the maximum number of feed items to display</li>
* <li>?full: if 'true', descriptions for each item will be included. Otherwise, just titles.</li>
* <li>?search: if 'true' and if feed has a search field, field will be included</li>
* </ul>
* Note that all parameters must be passed using names.
*/
public String[] getParamDescription() {
return PARAM_DESCRIPTION;
}
/**
* @return the MacroFilter's description: 'Use to aggregate RSS feeds'.
*/
public String getDescription() {
return DESCRIPTION;
}
/**
* Transform the input parameters into <code>RSSMacroParameters</code> object.
* @param parameter the parameters as prepared by the Radeox system.
* @throws java.lang.IllegalArgumentException if the 'feed' named parameter
* is missing, or is a malformed URL, or if any of the other parameter values
* are not of the correct types. Note that unknown parameters will simply
* be ignored, and all parameters must be passed using names.
* @return a parameters helper object
* @see RSSMacroParameters
*/
private RSSMacroParameters processParameters(MacroParameter parameter) throws java.lang.IllegalArgumentException
{
java.util.HashMap paramMap = new java.util.HashMap();
RSSMacroParameters paramObj = new RSSMacroParameters();
String feedURLString = parameter.get("feed");
if (feedURLString == null)
{
throw new IllegalArgumentException("Requires at least one named parameter,'feed', a URL of an RSS feed.");
}
try {
paramObj.setFeed(feedURLString);
}
catch (MalformedURLException ex) {
Logger.warn("Invalid feed URL: " + feedURLString, ex);
throw new IllegalArgumentException("Invalid feed URL: " + feedURLString);
}
for (int i = 0; i < PARAM_NAMES.length; i++) {
String paramName = parameter.get(PARAM_NAMES[i]);
if (paramName != null)
{
paramMap.put(PARAM_NAMES[i],paramName);
}
}
try {
BeanUtils.populate(paramObj, paramMap);
}
catch (NoClassDefFoundError e) {
throw new IllegalStateException("Some libraries are not installed: " + e.getMessage());
}
catch (Exception ex) {
throw new IllegalArgumentException("Error processing arguments: " + ex.getMessage());
}
return paramObj;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -