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

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

import java.io.PrintStream;
import java.io.Serializable;
import java.util.Properties;
import java.util.Vector;
import wt.content.ContentHTTPStream;
import wt.doc.*;
import wt.fc.*;
import wt.templateutil.processor.FormTaskDelegate;
import wt.templateutil.processor.RedirectObject;
import wt.util.WTException;
import wt.util.WTProperties;

public class ReorderDocumentsDelegate extends FormTaskDelegate
    implements Serializable
{

    public ReorderDocumentsDelegate()
    {
    }

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

    public void processAction(ContentHTTPStream contentStream)
        throws Exception
    {
        if(VERBOSE)
            System.out.println("DEBUG:ReorderDocumentsDelegate.processAction");
        WTDocument doc;
        String list;
        Properties formData = getFormData();
        doc = null;
        Persistable ci = (Persistable)getContextObj();
        ReferenceFactory ref_fact = new ReferenceFactory();
        if(ci instanceof WTDocument)
        {
            doc = (WTDocument)getContextObj();
            if(VERBOSE)
                System.out.println("DEBUG:ReorderDocumentsDelegate.processAction ci doc = " + doc);
        } else
        {
            String doc_ref = (String)formData.get("documentOid");
            WTReference ref = ref_fact.getReference(doc_ref);
            doc = (WTDocument)ref.getObject();
            if(VERBOSE)
                System.out.println("DEBUG:ReorderDocumentsDelegate.processAction ref doc = " + doc);
        }
        list = (String)formData.get("newOrder");
        if(VERBOSE)
            System.out.println("DEBUG:ReorderDocumentsDelegate.processAction newOrder = " + list);
        if(list != null && list.length() > 0)
            break MISSING_BLOCK_LABEL_241;
        if(VERBOSE)
            System.out.println("DEBUG:ReorderDocumentsDelegate.processAction list is empty.");
        RedirectObject redirectObj = new RedirectObject();
        redirectObj.setRedirection(getState());
        return;
        Vector documents = stringToVector(list, DELIM);
        WTDocument new_doc = WTDocumentHelper.service.orderUsageLinks(doc, documents, "", "");
        Properties context_properties = getContextProperties();
        if(context_properties == null)
            context_properties = new Properties();
        ReferenceFactory factory = new ReferenceFactory();
        context_properties.put("oldOid", factory.getReferenceString(ObjectReference.newObjectReference(doc.getPersistInfo().getObjectIdentifier())));
        if(new_doc != null)
            context_properties.put("newOid", factory.getReferenceString(ObjectReference.newObjectReference(new_doc.getPersistInfo().getObjectIdentifier())));
        else
            context_properties.put("newOid", factory.getReferenceString(ObjectReference.newObjectReference(doc.getPersistInfo().getObjectIdentifier())));
        setContextProperties(context_properties);
        setContextAction("ReorderDocAssocationsSuccess");
        setContextObj(doc);
        if(VERBOSE)
        {
            System.out.println("DEBUG:ReorderDocumentsDelegate set\n\toldOid=" + context_properties.getProperty("oldOid") + "\n\tnewOid=" + context_properties.getProperty("newOid"));
            System.out.println("DEBUG:ReorderDocumentsDelegate set\n\tcontext_properties=" + context_properties);
        }
        RedirectObject redirectObj = new RedirectObject();
        redirectObj.setRedirection(getState());
        return;
        WTException wte;
        wte;
        wte.printStackTrace();
        addToResponseHeaders(wte);
        setContextAction("ReorderDocAssociationFailed");
        RedirectObject redirectObj = new RedirectObject();
        redirectObj.setRedirection(getState());
        break MISSING_BLOCK_LABEL_551;
        Exception exception;
        exception;
        RedirectObject redirectObj = new RedirectObject();
        redirectObj.setRedirection(getState());
        throw exception;
    }

    protected Vector stringToVector(String s, String delimiter)
    {
        int cur_pos = 0;
        int start_pos = 0;
        Vector strings = new Vector();
        boolean done = false;
        int delim_length = delimiter.length();
        for(; !done; start_pos = cur_pos + delim_length)
        {
            cur_pos = s.indexOf(delimiter, start_pos);
            if(cur_pos == -1)
            {
                done = true;
                continue;
            }
            String item = s.substring(start_pos, cur_pos);
            if(item != null && item.length() > 0)
                strings.addElement(item);
        }

        return strings;
    }

    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;
    protected static String DELIM;

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