001package org.nuxeo.ecm.webapp.tree;
002
003import java.io.IOException;
004import java.io.Serializable;
005
006import javax.faces.context.FacesContext;
007import javax.servlet.http.HttpServletResponse;
008
009import org.jboss.seam.annotations.Install;
010import org.jboss.seam.annotations.Name;
011import org.jboss.seam.annotations.Scope;
012
013import static org.jboss.seam.ScopeType.SESSION;
014
015@Name("treeInvalidator")
016@Scope(SESSION)
017@Install(precedence = Install.FRAMEWORK)
018public class TreeInvalidatorBean implements Serializable {
019
020    private static final long serialVersionUID = 1L;
021
022    protected boolean needsInvalidation = false;
023
024    public String forceTreeRefresh() throws IOException {
025
026        needsInvalidation = true;
027
028        FacesContext context = FacesContext.getCurrentInstance();
029        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
030        response.setContentType("application/xml; charset=UTF-8");
031        response.getWriter().write("<response>OK</response>");
032        context.responseComplete();
033
034        return null;
035    }
036
037    public boolean needsInvalidation() {
038        return needsInvalidation;
039    }
040
041    public void invalidationDone() {
042        needsInvalidation = false;
043    }
044
045}