// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) deadcode 
// Source File Name:   AddToBaselineFormTaskDelegate.java

package com.ptc.windchill.pdmlink.doc.server.processors;

import java.io.Serializable;
import java.util.*;
import wt.content.ContentHTTPStream;
import wt.enterprise.BasicTemplateProcessor;
import wt.fc.WTObject;
import wt.templateutil.processor.*;
import wt.templateutil.table.TreeTableNode;
import wt.util.WTException;
import wt.util.WTMessage;
import wt.vc.baseline.Baselineable;

// Referenced classes of package com.ptc.windchill.pdmlink.doc.server.processors:
//            StructuredDocumentProcessor

public class AddToBaselineFormTaskDelegate extends FormTaskDelegate
    implements Serializable
{

    public AddToBaselineFormTaskDelegate()
    {
    }

    /**
     * @deprecated Method processAction is deprecated
     */

    public void processAction(ContentHTTPStream contentStream)
        throws Exception
    {
        Object save_context_object = getContextObj();
        HTTPState state = getState();
        Properties form_data = getFormData();
        String document_cookie = null;
        String url_string = null;
        if(form_data != null)
        {
            document_cookie = form_data.getProperty(StructuredDocumentProcessor.BASELINE_COOKIE);
            url_string = form_data.getProperty("RETURN_URL");
        }
        ServletSessionCookie cookie = state.getCookieManager().getCookie(document_cookie);
        List baselineable_objects = getSelectedBaselineableObjects(cookie);
        int size = baselineable_objects.size();
        if(size > 0)
        {
            cookie.put("AddToBaseline", "AddToBaseline");
            cookie.put("BaselineableObjects", baselineable_objects);
            state.getCookieManager().saveCookies();
        } else
        {
            addToResponseHeaders(new WTMessage("com.ptc.windchill.pdmlink.doc.server.processors.processorsResource", "103", null));
        }
        RedirectObject redirectObj = new RedirectObject();
        redirectObj.setRedirection(url_string, form_data, state);
    }

    private List getSelectedBaselineableObjects(ServletSessionCookie cookie)
        throws WTException
    {
        List return_list = new ArrayList();
        Properties form_data = getFormData();
        Enumeration keys = form_data.keys();
        HTTPState state = getState();
        Vector row_data_objects = null;
        String reference = null;
        if(cookie != null)
            row_data_objects = (Vector)cookie.get("rowDataObjects");
        if(row_data_objects == null)
            return return_list;
label0:
        do
        {
            if(!keys.hasMoreElements())
                break;
            String name = (String)keys.nextElement();
            if(!name.startsWith("checkbox__"))
                continue;
            String item = form_data.getProperty(name);
            form_data.remove(name);
            if(item.startsWith("HtmlTable_TreeTableNode_"))
            {
                int target_id = (new Integer(item.substring(StructuredDocumentProcessor.NODE_VALUE_PREFIX_LEN))).intValue();
                int size = row_data_objects.size();
                int k = 0;
                do
                {
                    if(k >= size)
                        continue label0;
                    if(row_data_objects.elementAt(k) instanceof TreeTableNode)
                    {
                        TreeTableNode currentNode = (TreeTableNode)row_data_objects.elementAt(k);
                        if(currentNode.getIdentifier() == target_id)
                        {
                            Object an_object = currentNode.getCentralObject();
                            if(an_object instanceof Baselineable)
                            {
                                reference = BasicTemplateProcessor.getReferenceString((WTObject)an_object);
                                if(!return_list.contains(reference))
                                    return_list.add(reference);
                            }
                            continue label0;
                        }
                    }
                    k++;
                } while(true);
            }
            Object top_row_object = row_data_objects.elementAt(0);
            if(top_row_object != null && (top_row_object instanceof Baselineable))
            {
                reference = BasicTemplateProcessor.getReferenceString((WTObject)top_row_object);
                if(!return_list.contains(reference))
                    return_list.add(reference);
            }
        } while(true);
        return return_list;
    }

    static Class _mthclass$(String x0)
    {
        return Class.forName(x0);
        ClassNotFoundException x1;
        x1;
        throw (new NoClassDefFoundError()).initCause(x1);
    }

    private static final String RESOURCE = "com.ptc.windchill.pdmlink.doc.server.processors.processorsResource";
    private static final String CLASSNAME;
    protected static boolean VERBOSE = false;

    static 
    {
        CLASSNAME = (com.ptc.windchill.pdmlink.doc.server.processors.AddToBaselineFormTaskDelegate.class).getName();
    }
}
