Example usage for org.apache.commons.digester.rss RSSDigester RSSDigester

List of usage examples for org.apache.commons.digester.rss RSSDigester RSSDigester

Introduction

In this page you can find the example usage for org.apache.commons.digester.rss RSSDigester RSSDigester.

Prototype

RSSDigester

Source Link

Usage

From source file:org.apache.struts.scaffold.rss.ParseRss.java

/**
 * Read and parse RSS file found at a given
 * path, save the Channel bean in request scope,
 * and forward to "success"./*from www .  ja v  a  2s . c o  m*/
 *
 * @expects path={uri} on command line or as parameter property to ActionMapping.
 * @expects an input page or error forwarding if exception digesting RSS
 * @param mapping The ActionMapping used to select this instance
 * @param actionForm The optional ActionForm bean for this request (if any)
 * @param request The HTTP request we are processing
 * @param response The resonse we are creating
 * @param errors Our ActionErrors collection
 */
public void executeLogic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    Channel channel = null;

    String path = request.getParameter(Tokens.PATH);
    if (path == null)
        path = mapping.getParameter();

    RSSDigester digester = new RSSDigester();
    channel = (Channel) digester.parse(path);

    request.setAttribute(CHANNEL_KEY, channel);

}

From source file:org.apache.struts.webapp.tiles.rssChannel.Channels.java

/**
 * Main process of class. Reads, parses/* w w  w .  j a v  a  2 s .  co  m*/
 */
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    log.debug("Enter Rss Channel Action");

    // Try to retrieve tile context
    ComponentContext context = ComponentContext.getContext(request);
    if (context == null) {
        throw new ServletException("This action must be called by a Tile, not directly");
    }

    ActionMessages errors = new ActionMessages();

    // -- Retrieve parameters --
    // Urls can come from a list, or from a single attribute.

    List channels = (List) context.getAttribute(CHANNEL_URLS_KEY);
    if (channels == null) {
        Object url = context.getAttribute(CHANNEL_URL_KEY);
        channels = new ArrayList(1);
        channels.add(url);
    }

    log.debug("urls count" + channels.size());

    // -- Loop through channels --
    ArrayList channelBeans = new ArrayList(channels.size());
    try {
        for (int i = 0; i < channels.size(); i++) {
            RSSDigester digester = new RSSDigester();
            String url = (String) channels.get(i);
            // Add application path if needed
            if (url.startsWith("/")) {
                url = toFullUrl(request, url);
            }

            log.debug("Channel url=" + url);

            Channel obj = (Channel) digester.parse(url);

            log.debug("Channel:" + obj);

            channelBeans.add(obj);
        }
    } catch (Throwable t) {
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("rss.access.error"));

        servlet.log(t.toString());
    }

    // -- Handle Errors ---
    if (!errors.isEmpty()) {
        this.saveErrors(request, errors);

        if (mapping.getInput() != null) {
            return new ActionForward(mapping.getInput());
        }

        // If no input page, use error forwarding

        log.debug("Exit Rss Channel Action : error");

        return mapping.findForward("error");
    }

    // -- Save Bean, and Continue  ---

    log.debug("Exit Rss Channel Action");

    // Use Tile context to pass channels
    context.putAttribute(CHANNELS_KEY, channelBeans);

    return mapping.findForward("continue");
}

From source file:org.apache.struts.webapp.tiles.rssChannel.RssChannelsAction.java

/**
 * Main process of class. Reads, parses//from ww w . jav a2 s .  co  m
 * @param context The current Tile context, containing Tile attributes.
 * @param mapping The ActionMapping used to select this instance.
 * @param form The optional ActionForm bean for this request (if any).
 * @param request The HTTP request we are processing.
 * @param response The HTTP response we are creating.
 *
 * @exception Exception if the application business logic throws
 *  an exception
 * @since Struts 1.1
 */
public ActionForward execute(ComponentContext context, ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    log.debug("Enter Rss Channel Action");

    ActionMessages errors = new ActionMessages();

    // -- Retrieve parameters --
    // Urls can come from a list, or from a single attribute.

    List channels = (List) context.getAttribute(CHANNEL_URLS_KEY);
    if (channels == null) {
        Object url = context.getAttribute(CHANNEL_URL_KEY);
        channels = new ArrayList(1);
        channels.add(url);
    }

    log.debug("urls count" + channels.size());

    // -- Loop through channels --
    List channelBeans = new ArrayList(channels.size());
    try {
        for (int i = 0; i < channels.size(); i++) {
            RSSDigester digester = new RSSDigester();
            String url = (String) channels.get(i);
            // Add application path if needed
            if (url.startsWith("/")) {
                url = toFullUrl(request, url);
            }

            log.debug("Channel url=" + url);

            Channel obj = (Channel) digester.parse(url);

            log.debug("Channel:" + obj);

            channelBeans.add(obj);
        }

    } catch (Throwable t) {
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("rss.access.error"));

        servlet.log(t.toString());
    }

    // -- Handle Errors ---
    if (!errors.isEmpty()) {
        this.saveErrors(request, errors);
        // If no input page, use error forwarding

        log.debug("Exit Rss Channel Action : error");

        return null;
    }

    // -- Save Bean, and Continue  ---

    log.debug("Exit Rss Channel Action");

    // Use Tile context to pass channels
    context.putAttribute(CHANNELS_KEY, channelBeans);

    return null;
}

From source file:org.openamf.examples.RSS.java

public Channel getChannel(String rssURL) throws IOException, SAXException {

    Channel channel = null;//ww  w. ja va 2  s.c  om

    RSSDigester digester = new RSSDigester();

    channel = (Channel) digester.parse(rssURL);
    String url = "http://www.openamf.org/javadocs/index.html";
    String desc = channel.getDescription() + "<br/><br/>Click <A href='" + url
            + "' target='_blank'><U>here</U></A> to view Java Doc's";

    channel.setDescription(desc);

    return channel;
}