<%-- 
  Copyright 2001 Sun Microsystems, Inc.  All rights reserved. 
  PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms. 
--%> 
<%-- doedit.jsp  --%>

<%@ page import="java.net.URL" %>
<%@ page import="java.net.URLEncoder" %>

<%@ page import="com.sun.portal.providers.containers.jsp.single.JSPSingleContainerProvider" %>
<%@ page import="com.sun.portal.providers.InvalidEditFormDataException" %>
<%@ page import="com.sun.portal.desktop.taglib.DesktopTaglibException" %>
<%@ page import="com.sun.portal.desktop.util.IURLEncoder" %>

<%@ taglib uri="/tld/desktop.tld" prefix="dt" %>
<%@ taglib uri="/tld/desktopContainerProviderContext.tld" prefix="dtcpc" %>
<%@ taglib uri="/tld/desktopProviderContext.tld" prefix="dtpc" %>

<%@ page session="false" %>

<%
   String provider = request.getParameter("provider");
   String targetprovider = request.getParameter("targetprovider");
   pageContext.setAttribute( "targetChannel", targetprovider );
   JSPSingleContainerProvider scp = (JSPSingleContainerProvider)pageContext.getAttribute("JSPProvider");
   String editArgs = request.getParameter("editArgs");
%>

<dt:obtainContainer container="$JSPProvider">
  <dtcpc:containerProviderContext>
    <dtcpc:obtainChannelFromContainer channel="$targetChannel">
                <dtpc:getDesktopURL id="desktopURL" scope="request"/>
                <%
                        String desktopURL = (String)pageContext.getAttribute("desktopURL", PageContext.REQUEST_SCOPE);
                %>
                <% try {  %>
                        <dt:processEdit id="url"/>
                <%  } catch (DesktopTaglibException dte) {
                                if (dte.getWrapped() instanceof InvalidEditFormDataException) {
                                String error = IURLEncoder.encode(dte.getMessage());
                                        StringBuffer args = new StringBuffer(64);
                                        int errIndex = editArgs.indexOf("&error=");
                                        if (errIndex > 1) {
                                                args.append(desktopURL)
                                                        .append(editArgs.substring(0, errIndex))
                                                        .append("&error=")
                                                        .append(error);
                                        } else {
                                                args.append(desktopURL)
                                                        .append(editArgs)
                                                        .append("&error=")
                                                        .append(error);
                                        }
                                        response.sendRedirect(args.toString());
                                } else {
                                        throw dte;
                                }
                        }
                if (((URL)pageContext.getAttribute("url")) != null) {
                        response.sendRedirect(((URL)pageContext.getAttribute("url")).toString());
                }
        %>
    </dtcpc:obtainChannelFromContainer>
  </dtcpc:containerProviderContext>
</dt:obtainContainer>
