// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
package test;

import javax.portlet.*;
import java.io.*;

public class LinksPortlet extends GenericPortlet
{
    private final static String ADD = "add";
    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
        if(request.getParameter(ADD) != null) {
            PortletPreferences prefs = request.getPreferences();
            prefs.setValue(request.getParameter("title"), request.getParameter("url"));
            prefs.store();
        }
    }
    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
    {
        response.setContentType("text/html");
        String jspName = getPortletConfig().getInitParameter("jspView");
        PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(jspName);
        rd.include(request,response);
    }
    public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException
    {
        response.setContentType("text/html");
        String jspName = getPortletConfig().getInitParameter("jspEdit");
        PortletURL action = response.createActionURL();
        action.setPortletMode(PortletMode.VIEW);
        action.setParameter(ADD, "yes");
        request.setAttribute("action", action.toString());
        PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(jspName);
        rd.include(request,response);
    }
}
