package net.sf.flock.webapp;
import java.net.URL;
import net.sf.flock.FlockResourceException;
import net.sf.flock.MetaData;
import net.sf.flock.SubscriptionI;
import net.sf.tapestry.IRequestCycle;
import net.sf.tapestry.html.BasePage;
import net.sf.tapestry.valid.IValidationDelegate;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
public class SubscriptionsPage extends BasePage {
private final static Logger LOGGER = LogManager.getLogger(SubscriptionsPage.class);
private URL feedUrl;
private String path;
/**
* @see net.sf.tapestry.IPage#detach()
*/
public void detach() {
this.feedUrl = null;
this.path = null;
super.detach();
}
public URL getFeedUrl() {
return this.feedUrl;
public void setFeedUrl(URL feedUrl) {
this.feedUrl = feedUrl;
this.fireObservedChange("feedUrl", feedUrl);
public String getPath() {
return path;
public void setPath(String path) {
this.path = path;
this.fireObservedChange("path", path);
public void formSubmit(IRequestCycle requestCycle) {
IValidationDelegate delegate = (IValidationDelegate) getBeans().getBean("delegate");
if (!delegate.getHasErrors()) {
LOGGER.info("Subscribing to " + this.getFeedUrl() + " path: " + this.getPath());
try {
MetaData md = new MetaData();
md.set("path", this.getPath());
SubscriptionI[] subscriptions =
FlockContext.getSubscriptionManager().subscribe( this.getFeedUrl(), md );
LOGGER.info("Added "+subscriptions.length+" feeds");
} catch (FlockResourceException e) {
LOGGER.warn("Unable to add feed", e);
delegate.setFormComponent(null);
delegate.record(e.getMessage(), null, null);
return;
HomePage browsePage = (HomePage)requestCycle.getPage("Home");
browsePage.setSelectedPath( this.getPath() );
requestCycle.setPage(browsePage);
public void refreshAll(IRequestCycle cycle) {
FlockContext.getSubscriptionManager().refreshAll();