// 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:   DocumentAddReferenceDelegate.java

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

import java.io.PrintStream;
import java.io.Serializable;
import java.util.*;
import wt.content.ContentHTTPStream;
import wt.doc.*;
import wt.fc.Persistable;
import wt.introspection.ClassInfo;
import wt.templateutil.components.CheckBoxCellComponent;
import wt.templateutil.processor.FormTaskDelegate;
import wt.templateutil.processor.RedirectObject;
import wt.util.WTException;
import wt.util.WTProperties;

public class DocumentAddReferenceDelegate extends FormTaskDelegate
    implements Serializable
{

    public DocumentAddReferenceDelegate()
    {
    }

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

    public void processAction(ContentHTTPStream contentStream)
        throws Exception
    {
        if(VERBOSE)
            System.out.println("DEBUG:DocumentAddReferenceDelegate.processAction object ci:" + getContextObj());
        String token = CheckBoxCellComponent.CONTEXT_SEPARATOR;
        Properties formData = getFormData();
        String keyName = null;
        WTDocument doc = null;
        Persistable ci = (Persistable)getContextObj();
        if(ci instanceof WTDocument)
        {
            doc = (WTDocument)getContextObj();
        } else
        {
            Object params[] = {
                ci.getClassInfo().getClassname()
            };
            throw new WTException("com.ptc.windchill.pdmlink.doc.server.processors.processorsResource", "67", params);
        }
        Vector documents = new Vector();
        Vector comments = new Vector();
        Enumeration enum = formData.keys();
        do
        {
            if(!enum.hasMoreElements())
                break;
            keyName = (String)enum.nextElement();
            if(keyName.startsWith(CheckBoxCellComponent.BEGIN_CHECKBOX_NAME))
            {
                String id = formData.getProperty(keyName);
                if(VERBOSE)
                    System.out.println("DEBUG:DocumentAddReferenceDelegate ID = " + id);
                int start_pos = id.indexOf(token, 0);
                start_pos += token.length();
                String oid = id.substring(start_pos);
                if(VERBOSE)
                    System.out.println("DEBUG:DocumentAddReferenceDelegate OID = " + oid);
                documents.addElement(oid);
                comments.addElement("");
            }
        } while(true);
        WTDocument new_doc = WTDocumentHelper.service.createDependencyLink(doc, documents, comments, "", "");
        if(VERBOSE)
            System.out.println("New dependency links created.");
        setContextAction("DocumentAddReferenceSuccess");
        setContextObj(new_doc);
        RedirectObject redirectObj = new RedirectObject();
        redirectObj.setRedirection(getState());
        return;
        WTException wte;
        wte;
        wte.printStackTrace();
        addToResponseHeaders(wte);
        setContextAction("CreateDocAssociationFailed");
        RedirectObject redirectObj = new RedirectObject();
        redirectObj.setRedirection(getState());
        break MISSING_BLOCK_LABEL_410;
        Exception exception;
        exception;
        RedirectObject redirectObj = new RedirectObject();
        redirectObj.setRedirection(getState());
        throw exception;
    }

    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.DocumentAddReferenceDelegate.class).getName();
        try
        {
            WTProperties properties = WTProperties.getLocalProperties();
            VERBOSE = properties.getProperty("com.ptc.windchill.pdmlink.doc.client.verbose", false);
        }
        catch(Throwable t)
        {
            t.printStackTrace(System.err);
            throw new ExceptionInInitializerError(t);
        }
    }
}
