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

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

import java.io.PrintStream;
import java.util.Properties;
import wt.content.*;
import wt.fc.*;
import wt.templateutil.processor.FormTaskDelegate;
import wt.util.WTProperties;
import wt.vc.wip.*;

/**
 * @deprecated Class CheckOutDocCloseWindowFormTaskDelegate is deprecated
 */

public class CheckOutDocCloseWindowFormTaskDelegate extends FormTaskDelegate
{

    public CheckOutDocCloseWindowFormTaskDelegate()
    {
    }

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

    public void processAction(ContentHTTPStream contentStream)
        throws Exception
    {
        if(VERBOSE)
            System.err.println("Entering CloseWindowFormTaskDelegate.processAction");
        Properties props = getQueryData();
        String formName = (String)props.get("formName");
        String downloaded = (String)props.get("downloaded");
        if(downloaded != null && downloaded.equalsIgnoreCase("true"))
        {
            String downloadPath = (String)props.get("downloadPath");
            long checksum = 0L;
            String checksumString = (String)props.get("checksum");
            if(checksumString != null)
                try
                {
                    checksum = Long.parseLong(checksumString);
                    FormatContentHolder holder = (FormatContentHolder)getContextObj();
                    holder = (FormatContentHolder)ContentHelper.service.getContents(holder);
                    wt.content.ContentItem item = ContentHelper.getPrimary(holder);
                    if(item instanceof ApplicationData)
                    {
                        ApplicationData app = (ApplicationData)item;
                        app.setChecksum(checksum);
                        app.setUploadedFromPath(downloadPath);
                        try
                        {
                            ContentHelper.service.updateAppData(holder, app);
                        }
                        catch(Exception e)
                        {
                            e.printStackTrace();
                        }
                    }
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
        }
        ReferenceFactory factory = new ReferenceFactory();
        Persistable ci = (Persistable)getContextObj();
        String new_oid = (String)props.get("newOid");
        String old_oid = (String)props.get("oldOid");
        if(new_oid == null)
        {
            Properties context = getContextProperties();
            new_oid = (String)context.get("newOid");
            old_oid = (String)context.get("oldOid");
        }
        if(new_oid == null)
            if((ci instanceof Workable) && WorkInProgressHelper.isWorkingCopy((Workable)ci))
            {
                new_oid = factory.getReferenceString(ObjectReference.newObjectReference(ci.getPersistInfo().getObjectIdentifier()));
            } else
            {
                Workable work = WorkInProgressHelper.service.workingCopyOf((Workable)ci);
                new_oid = factory.getReferenceString(ObjectReference.newObjectReference(work.getPersistInfo().getObjectIdentifier()));
            }
        if(old_oid == null)
            if((ci instanceof Workable) && !WorkInProgressHelper.isWorkingCopy((Workable)ci))
            {
                old_oid = factory.getReferenceString(ObjectReference.newObjectReference(ci.getPersistInfo().getObjectIdentifier()));
            } else
            {
                Workable orig = WorkInProgressHelper.service.originalCopyOf((Workable)ci);
                old_oid = factory.getReferenceString(ObjectReference.newObjectReference(orig.getPersistInfo().getObjectIdentifier()));
            }
        deleteFormDataFromSession(formName);
        setContextAction("CheckOutDocCloseWindow");
        Properties context_properties = getContextProperties();
        if(context_properties == null)
            context_properties = new Properties();
        context_properties.put("newOid", new_oid);
        context_properties.put("oldOid", old_oid);
        setContextProperties(context_properties);
    }

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

    private static final String RESOURCE = "com.ptc.core.HTMLtemplateutil.server.processors.processorsResource";
    private static final String CLASSNAME;
    private static boolean VERBOSE;

    static 
    {
        CLASSNAME = (com.ptc.windchill.pdmlink.doc.server.processors.CheckOutDocCloseWindowFormTaskDelegate.class).getName();
        try
        {
            WTProperties properties = WTProperties.getLocalProperties();
            VERBOSE = properties.getProperty("com.ptc.core.HTMLtemplateutil.verbose", false);
        }
        catch(Throwable t)
        {
            t.printStackTrace(System.err);
            throw new ExceptionInInitializerError(t);
        }
    }
}
