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

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

import com.ptc.core.HTMLtemplateutil.server.processors.WizardProcessor;
import com.ptc.windchill.enterprise.nativeapp.server.ApplicationIntegrationFactory;
import java.beans.PropertyVetoException;
import java.io.*;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.*;
import wt.content.*;
import wt.doc.DocumentFormData;
import wt.doc.WTDocument;
import wt.enterprise.TemplateInfo;
import wt.fc.*;
import wt.htmlutil.HtmlUtil;
import wt.httpgw.HTTPRequest;
import wt.identity.IdentityFactory;
import wt.locks.LockHelper;
import wt.method.MethodContext;
import wt.pds.PDSObjectInput;
import wt.taglib.util.PluginTagGenerator;
import wt.templateutil.processor.HTTPState;
import wt.util.*;
import wt.vc.Iterated;
import wt.vc.VersionReference;
import wt.vc.wip.WorkInProgressHelper;
import wt.vc.wip.Workable;

public class DocumentProcessor extends WizardProcessor
    implements Externalizable
{

    public DocumentProcessor()
    {
    }

    public void writeExternal(ObjectOutput output)
        throws IOException
    {
        output.writeLong(0xa6700984c6548630L);
        super.writeExternal(output);
    }

    public void readExternal(ObjectInput input)
        throws IOException, ClassNotFoundException
    {
        long readSerialVersionUID = input.readLong();
        readVersion(this, input, readSerialVersionUID, false, false);
    }

    protected boolean readVersion(DocumentProcessor thisObject, ObjectInput input, long readSerialVersionUID, boolean passThrough, boolean superDone)
        throws IOException, ClassNotFoundException
    {
        boolean success = true;
        if(readSerialVersionUID == 0xa6700984c6548630L)
        {
            if(!superDone)
                super.readExternal(input);
        } else
        {
            success = readOldVersion(input, readSerialVersionUID, passThrough, superDone);
            if(input instanceof PDSObjectInput)
                EvolvableHelper.requestRewriteOfEvolvedBlobbedObject();
        }
        return success;
    }

    private boolean readOldVersion(ObjectInput input, long readSerialVersionUID, boolean passThrough, boolean superDone)
        throws IOException, ClassNotFoundException
    {
        boolean success = true;
        if(readSerialVersionUID != 0xdf925d04f702e856L)
            if(!superDone)
            {
                success = super.readVersion(this, input, readSerialVersionUID, false, false);
                if(success && !passThrough && readSerialVersionUID != 0x5c9ab67f442bc0d1L)
                    readVersion(this, input, input.readLong(), false, true);
            } else
            {
                throw new InvalidClassException(CLASSNAME, "Local class not compatible: stream classdesc externalizationVersionUID=" + readSerialVersionUID + " local class externalizationVersionUID=" + 0xa6700984c6548630L);
            }
        return success;
    }

    public void createDocument(Properties properties, Locale locale1, OutputStream outputstream)
        throws WTException
    {
    }

    public void updateDocument(Properties parameters, Locale locale, OutputStream os)
        throws WTException
    {
        WTDocument doc = (WTDocument)getContextObj();
        Properties formData = getFormData();
        if(doc != null && formData != null)
        {
            HashMap input_data = new HashMap(5);
            if(VERBOSE)
                System.out.println("Updating document ...");
            String title = formData.getProperty("Title");
            if(title != null)
            {
                title = title.trim();
                if(VERBOSE)
                    System.out.println("title = " + title);
                input_data.put("title", title);
            }
            String description = formData.getProperty("Description");
            if(description != null)
            {
                description = description.trim();
                if(VERBOSE)
                    System.out.println("description = " + description);
                input_data.put("description", description);
            }
            doc = ApplicationIntegrationFactory.updateDocument(doc, input_data, locale, "html");
            if(VERBOSE)
                System.out.println("Document updated successfully.  " + doc.getDisplayIdentifier().getLocalizedMessage(locale));
            setContextObj(doc);
        }
        setContextAction("ObjProps");
    }

    public void getCreateDocumentIdentity(Properties parameters, Locale locale, OutputStream os)
        throws WTException
    {
        String docIdentity = "";
        String name = getFormData().getProperty("Name");
        if(VERBOSE)
            System.out.println("name=" + name);
        Object param[] = {
            name
        };
        docIdentity = WTMessage.getLocalizedMessage("com.ptc.windchill.pdmlink.doc.server.processors.processorsResource", "0", param, locale);
        PrintWriter out = getPrintWriter(os, locale);
        out.print(docIdentity);
        out.flush();
    }

    public void getDocumentDisplayIdentity(Properties parameters, Locale locale, OutputStream os)
        throws WTException
    {
        String identity = IdentityFactory.getDisplayIdentifier(getContextObj()).getLocalizedMessage(locale);
        if(VERBOSE)
            System.out.println("Identity in display identity = " + identity);
        Object param[] = {
            identity
        };
        String key = parameters.getProperty("resourceKey");
        if(VERBOSE)
            System.out.println("resourceKey = " + key);
        String bundle = parameters.getProperty("resourceClass");
        if(VERBOSE)
            System.out.println("resourceClass = " + bundle);
        MethodContext ctx = MethodContext.getContext();
        boolean encodeForHTMLDisplay = false;
        if(ctx.get("preserveFormatting") != null && ctx.get("preserveFormatting").toString().equalsIgnoreCase("true"))
            encodeForHTMLDisplay = true;
        String docIdentity = getLocalizedResourceParameterString(key, bundle, param, locale);
        if(encodeForHTMLDisplay)
            docIdentity = HtmlUtil.encodeEscapeCharacters(docIdentity);
        if(VERBOSE)
            System.out.println("Localized version of the identity and string = " + docIdentity);
        PrintWriter out = getPrintWriter(os, locale);
        out.print(docIdentity);
        out.flush();
    }

    public void getContextPropertyValue(Properties parameters, Locale locale, OutputStream os)
        throws WTException
    {
        if(parameters != null)
        {
            String key = parameters.getProperty("key");
            if(key != null)
            {
                Properties contextProperties = getFormData();
                String value = null;
                if(contextProperties != null)
                {
                    if(VERBOSE)
                        System.out.println("DocumentAssociationSearchProcessor.getContextPropertyValue contextProperties=" + contextProperties);
                    value = contextProperties.getProperty(key);
                    if(value == null)
                    {
                        Properties context = getContextProperties();
                        value = context.getProperty(key);
                        if(value == null)
                            value = "undefined";
                    }
                    PrintWriter out = getPrintWriter(os, locale);
                    out.print(value);
                    out.flush();
                } else
                {
                    if(VERBOSE)
                    {
                        System.out.println("DocumentAssociationSearchProcessor.getContextPropertyValue getContextAction()=" + getContextAction());
                        System.out.println("DocumentAssociationSearchProcessor.getContextPropertyValue getContextObj()=" + getContextObj());
                    }
                    throw new WTException("com.ptc.windchill.pdmlink.doc.server.processors.processorsResource", "88", null);
                }
            } else
            {
                throw new WTException("com.ptc.windchill.pdmlink.doc.server.processors.processorsResource", "87", null);
            }
        } else
        {
            throw new WTException("com.ptc.windchill.pdmlink.doc.server.processors.processorsResource", "87", null);
        }
    }

    private static String getLocalizedResourceParameterString(String resource_key, String resource_class, Object params[], Locale locale)
        throws WTException
    {
        if(VERBOSE)
            System.out.println("Entering getStringFromResourceBundle()...");
        Class resourceKeyClass = null;
        try
        {
            resourceKeyClass = Class.forName(resource_class);
        }
        catch(ClassNotFoundException e)
        {
            throw new WTException(e, WTMessage.getLocalizedMessage("wt.enterprise.enterpriseResource", "74", null, locale));
        }
        Field attributeField = null;
        try
        {
            attributeField = resourceKeyClass.getField(resource_key);
        }
        catch(NoSuchFieldException e)
        {
            throw new WTException(e, WTMessage.getLocalizedMessage("wt.enterprise.enterpriseResource", "75", null, locale));
        }
        if(VERBOSE)
            System.out.println("  attributeField -> " + attributeField);
        String attrName = null;
        try
        {
            attrName = (String)attributeField.get(null);
        }
        catch(IllegalAccessException e)
        {
            throw new WTException(e);
        }
        if(VERBOSE)
            System.out.println("  attrName -> " + attrName);
        return WTMessage.getLocalizedMessage(resource_class, attrName, params, locale);
    }

    public void getDebug(Properties params, Locale locale, OutputStream os)
    {
        PrintWriter out = getPrintWriter(os, locale);
        out.print(DEBUG);
        out.flush();
    }

    private String getRepository(String form_name)
        throws WTException
    {
        return getFormValueFromSession(form_name, "Repository", "");
    }

    private String getObjectType(String form_name)
        throws WTException
    {
        return getFormValueFromSession(form_name, "ObjectType", "");
    }

    public void getDownloadTags(Properties params, Locale locale, OutputStream os)
        throws WTException, PropertyVetoException, IOException
    {
        PrintWriter out = getPrintWriter(os, locale);
        out.print(getDownloadTags(params, locale));
        out.flush();
    }

    public String getDownloadTags(Properties params, Locale locale)
        throws WTException, PropertyVetoException, IOException
    {
        FormatContentHolder holder = null;
        String skipDownloadString = null;
        String formName = null;
        String action = null;
        String method = null;
        if(VERBOSE)
            System.out.println("***1 getDownloadTags formName=" + formName);
        boolean skipDownload = false;
        if(params != null)
        {
            action = params.getProperty("action");
            formName = params.getProperty("formName");
            method = params.getProperty("method");
            if(VERBOSE)
                System.out.println("***2 getDownloadTags formName=" + formName + " action=" + action + "method=" + method);
            skipDownloadString = params.getProperty("skipDownload");
            if(skipDownloadString != null)
                skipDownload = skipDownloadString.equalsIgnoreCase("true");
        }
        if(formName == null)
            formName = "ViewDocumentWizard";
        if(action == null)
            action = "CloseWindow";
        if(method == null)
            method = "invokeAction";
        if(VERBOSE)
            System.out.println("***3 getDownloadTags formName=" + formName);
        Object obj = getContextObj();
        if(!(obj instanceof FormatContentHolder))
            throw new WTException("DocumentProcessor.getDownloadTags(): Objects that have primary content must implement FormatContentHolder");
        try
        {
            if(VERBOSE)
                System.out.println("***4 getDownloadTags formName=" + formName);
            holder = (FormatContentHolder)obj;
            holder = (FormatContentHolder)ContentHelper.service.getContents(holder);
            setContentHolder(holder);
        }
        catch(PropertyVetoException pve)
        {
            System.err.println(pve);
        }
        String primary = "";
        wt.content.ContentItem item = ContentHelper.getPrimary(holder);
        String refreshPage = "";
        String remember = "";
        if(params != null)
        {
            refreshPage = params.getProperty("refreshPage");
            if(refreshPage != null && refreshPage.equalsIgnoreCase("true"))
                refreshPage = "window.opener.location.reload(true);";
            else
                refreshPage = "";
            remember = params.getProperty("remember", "false");
        }
        Properties new_params = new Properties();
        new_params.put("action", action);
        new_params.put("formName", formName);
        Persistable context_obj = (Persistable)getContextObj();
        String contextOid = null;
        if(context_obj != null)
            contextOid = (new ReferenceFactory()).getReferenceString(context_obj);
        if(contextOid != null)
            new_params.put("OID", contextOid);
        else
            new_params.put("class", "wt.doc.WTDocument");
        String closeUrl = getURLProcessorLink(method, new_params, true);
        params.put("completionUrl", closeUrl);
        if(!skipDownload && (item instanceof ApplicationData))
        {
            if(VERBOSE)
                System.out.println("***5 getDownloadTags formName=" + formName);
            ApplicationData app = (ApplicationData)item;
            primary = app.getFileName();
            if(primary != null && primary.length() > 0)
            {
                if(VERBOSE)
                    System.out.println("***5.5 getDownloadTags before getDownloadDetectionBlock");
                int downloadRouting = 2;
                try
                {
                    String downloadRoutingString = getQueryData().getProperty("downloadRouting");
                    if(VERBOSE)
                        System.out.println("DocumentProcessor.getDownloadTags() - downloadRoutingString = " + downloadRoutingString);
                    String appletOption = params.getProperty("appletOption", "false");
                    if(VERBOSE)
                        System.out.println("DocumentProcessor.getDownloadTags() - appletOption = " + appletOption);
                    if(downloadRoutingString != null)
                        downloadRouting = Integer.parseInt(downloadRoutingString);
                    else
                    if(appletOption.equalsIgnoreCase("true"))
                        downloadRouting = 3;
                }
                catch(Exception e)
                {
                    downloadRouting = 2;
                }
                if(VERBOSE)
                    System.out.println("DocumentProcessor.getDownloadTags() - downloadRouting = " + downloadRouting);
                return ContentHtmlUtils.getDownloadDetectionBlock(params, holder, app, downloadRouting, remember.equalsIgnoreCase("true"), false, true, locale);
            }
        } else
        if(!skipDownload && (item instanceof URLData))
        {
            if(VERBOSE)
                System.out.println("***6 getDownloadTags formName=" + formName);
            URLData url = (URLData)item;
            return ContentHtmlUtils.initiateURLDownloadHtml(holder, url, closeUrl, VERBOSE);
        }
        if(VERBOSE)
            System.out.println("***7 getDownloadTags formName=" + formName);
        String closeWindowUrl = null;
        if(skipDownload)
        {
            if(VERBOSE)
                System.out.println("***8 getDownloadTags formName=" + formName);
            new_params = new Properties();
            new_params.put("action", "CloseWindow");
            new_params.put("formName", formName);
            new_params.put("class", "wt.doc.WTDocument");
            closeWindowUrl = getURLProcessorLink("invokeAction", new_params, true);
            if(VERBOSE)
                System.out.println("***9 getDownloadTags formName=" + formName);
            return "<SCRIPT language=Javascript1.1>" + refreshPage + "window.location=\"" + closeWindowUrl + "\";</script>";
        }
        if(VERBOSE)
            System.out.println("***10 getDownloadTags formName=" + formName);
        if(params != null)
            action = params.getProperty("action");
        Object param[] = {
            holder.getIdentity()
        };
        String message = WTMessage.getLocalizedMessage("wt.doc.docResource", "66", param, locale);
        closeUrl = null;
        new_params = new Properties();
        new_params.put("action", action);
        new_params.put("formName", formName);
        context_obj = (Persistable)getContextObj();
        contextOid = null;
        if(context_obj != null)
            contextOid = (new ReferenceFactory()).getReferenceString(context_obj);
        if(contextOid != null)
            new_params.put("OID", contextOid);
        else
            new_params.put("class", "wt.doc.WTDocument");
        closeUrl = getURLProcessorLink("invokeAction", new_params, true);
        return "<SCRIPT language=Javascript1.1>wfalert('" + message + "');" + refreshPage + "window.location=\"" + closeUrl + "\";</script>";
    }

    public String getDownloadAppletTags(Properties properties, FormatContentHolder holder, ApplicationData appData, Locale locale)
        throws WTException, PropertyVetoException, IOException
    {
        String remember = null;
        String refreshPage = null;
        String formName = null;
        String action = null;
        String method = null;
        String workspacePath = getPreferenceValue("/wt/content", "workspacePath");
        String downloadOpType = getPreferenceValue("/wt/content", "downloadOpType");
        String localeString = locale.toString();
        if(properties != null)
        {
            remember = properties.getProperty("remember");
            refreshPage = properties.getProperty("refreshPage");
            formName = properties.getProperty("formName");
            action = properties.getProperty("action");
            method = properties.getProperty("method");
        }
        Properties params = new Properties();
        params.put("code", "wt/clients/util/http/DownloadApplet");
        params.put("codebase", WTProperties.getServerCodebase().toExternalForm());
        params.put("name", "formApplet");
        params.put("width", "2");
        params.put("height", "2");
        params.put("archive", "wt/security/security.jar");
        params.put("param.cabinets", "wt/security/security.cab");
        if(action == null)
            action = "CloseWindow";
        if(formName == null)
            formName = "ViewDocumentWizard";
        if(method == null)
            method = "invokeAction";
        if(VERBOSE)
            System.out.println("*** getDownloadAppletTags formName=" + formName + " action=" + action);
        Properties props = new Properties();
        props.put("action", action);
        props.put("formName", formName);
        String contextOid = null;
        String contextClass = null;
        Persistable context_obj = (Persistable)getContextObj();
        contextClass = getContextClassName();
        if(context_obj != null)
            contextOid = (new ReferenceFactory()).getReferenceString(context_obj);
        if(contextOid != null)
            props.put("OID", contextOid);
        else
        if(contextClass != null)
            props.put("class", contextClass);
        params.put("param.url", getURLProcessorLink(method, props, true));
        params.put("param.bgcolor", getWCColorDec("wizBody"));
        if(remember != null && remember.length() != 0)
            params.put("param.remember", remember);
        if(localeString != null && localeString.length() != 0)
            params.put("param.wt.context.locale", localeString);
        if(workspacePath != null && workspacePath.length() != 0)
            params.put("param.defaultPath", workspacePath);
        if(downloadOpType != null && downloadOpType.length() != 0)
            params.put("param.downloadOpType", downloadOpType);
        params.put("param.path", appData.getUploadedFromPath());
        params.put("param.filename", appData.getFileName());
        params.put("param.downloadURL", ContentHelper.getDownloadURL(holder, appData).toString());
        String debugString = "false";
        if(DEBUG)
            debugString = "true";
        params.put("param.debug", debugString);
        params.put("param.cache_option", "Plugin");
        params.put("param.cache_archive", "content.jar");
        String appletTags = PluginTagGenerator.createPluginTag(params, locale);
        if(DEBUG)
            System.out.println("DEBUG: GetContentDelegate - initiateDownloadHtml ... " + appletTags);
        return appletTags;
    }

    public void checkOutDocument(Properties params, Locale locale, OutputStream os)
        throws WTException, PropertyVetoException, IOException
    {
        if(DEBUG)
            System.out.println("DEBUG: DocumentProcessor.checkOutDocument -> enter");
        Workable vcObj = (Workable)getContextObj();
        Workable old_obj = vcObj;
        boolean allowed = false;
        boolean doDownload = true;
        try
        {
            if(!WorkInProgressHelper.isWorkingCopy(vcObj))
                allowed = !WorkInProgressHelper.isCheckedOut(vcObj) && !LockHelper.isLocked(vcObj);
            if(allowed)
            {
                String message = "";
                if(vcObj instanceof FormatContentHolder)
                    vcObj = ApplicationIntegrationFactory.checkout(vcObj, "", locale, "html");
                setContextObj(vcObj);
                if(params == null)
                    params = new Properties();
                Properties context_properties = getContextProperties();
                if(context_properties == null)
                    context_properties = new Properties();
                ReferenceFactory factory = new ReferenceFactory();
                String newOid = factory.getReferenceString(ObjectReference.newObjectReference(vcObj.getPersistInfo().getObjectIdentifier()));
                String oldOid = factory.getReferenceString(ObjectReference.newObjectReference(old_obj.getPersistInfo().getObjectIdentifier()));
                context_properties.put("newOid", newOid);
                context_properties.put("oldOid", oldOid);
                setContextProperties(context_properties);
                params.put("refreshPage", "true");
                PrintWriter out = getPrintWriter(os, locale);
                if(getPreferenceValue("/wt/content", "noDownloadOnCheckout").equalsIgnoreCase("true"))
                    doDownload = false;
                else
                if(vcObj instanceof FormatContentHolder)
                {
                    FormatContentHolder holder = (FormatContentHolder)vcObj;
                    try
                    {
                        holder = (FormatContentHolder)ContentHelper.service.getContents(holder);
                        setContentHolder(holder);
                    }
                    catch(PropertyVetoException pve)
                    {
                        System.err.println(pve);
                    }
                    wt.content.ContentItem item = ContentHelper.getPrimary(holder);
                    if(item == null)
                    {
                        doDownload = false;
                    } else
                    {
                        if(params == null)
                            params = new Properties();
                        params.put("remember", "true");
                        doDownload = true;
                    }
                }
                if(doDownload)
                {
                    getDownloadTags(params, locale, os);
                } else
                {
                    out.print("<SCRIPT language=Javascript1.1>\n refreshMainPage( \"");
                    out.flush();
                    Properties props_params = new Properties();
                    props_params.put("method", "URLTemplateAction");
                    props_params.put("action", "ObjProps");
                    props_params.put("fullyQualified", "true");
                    getURLProcessorLinkForObj(props_params, locale, os);
                    out.print("\", \"");
                    out.flush();
                    Properties struct_params = new Properties();
                    struct_params.put("method", "URLTemplateAction");
                    struct_params.put("fullyQualified", "true");
                    struct_params.put("action", "DocumentStructure_plm");
                    getURLProcessorLinkForObj(struct_params, locale, os);
                    out.print("\", \"" + oldOid + "\", \"" + newOid + "\" ); wfWindowClose()\n</SCRIPT>");
                    out.flush();
                }
            } else
            {
                if(DEBUG)
                    System.out.println("DEBUG: checkOutDocument - checkout failed for  " + vcObj.getIdentity());
                Object param[] = {
                    vcObj.getIdentity()
                };
                throw new WTException("wt.enterprise.enterpriseResource", "51", param);
            }
        }
        catch(WTException e)
        {
            if(DEBUG)
                System.out.println("DEBUG: checkOutDocument - checkout failed for  " + vcObj.getIdentity());
            Object param[] = {
                vcObj.getIdentity()
            };
            String message = e.getLocalizedMessage(locale, true);
            PrintWriter out = getPrintWriter(os, locale);
            out.print("<SCRIPT language=Javascript1.1>\n window.opener.wfalert('" + message + "');\n wfWindowClose();\n</SCRIPT>");
            out.flush();
        }
    }

    public void getReviseDownloadTags(Properties params, Locale locale, OutputStream os)
        throws WTException, PropertyVetoException, IOException
    {
        if(params == null)
            params = new Properties();
        params.put("refreshPage", "true");
        if(getPreferenceValue("/wt/content", "noDownloadOnCheckout").equalsIgnoreCase("true"))
            params.put("skipDownload", "true");
        params.put("remember", "true");
        params.put("action", "ReviseObjectCloseWindow");
        params.put("method", "URLTemplateAction");
        getDownloadTags(params, locale, os);
    }

    private DocumentFormData getFormData(Properties props)
        throws WTPropertyVetoException
    {
        Hashtable form_data = new Hashtable();
        String key;
        for(Enumeration e = props.keys(); e.hasMoreElements(); form_data.put(key, props.get(key)))
            key = (String)e.nextElement();

        return new DocumentFormData(form_data);
    }

    public void getCreateProcessorLink(Properties params, Locale locale, OutputStream os)
        throws WTException
    {
        String next_url = null;
        Properties formData = getFormData();
        boolean keep_checked_out = false;
        String keep = getFormValueFromSession("CreateDocumentWizard", "KeepCheckedOut", "");
        if(keep != null && keep.equalsIgnoreCase("KeepCheckedOut"))
            keep_checked_out = true;
        Properties new_params = new Properties();
        new_params.put("refresh", "true");
        new_params.put("fullyQualified", "true");
        if(keep_checked_out)
        {
            new_params.put("action", "CheckOutDocument");
            new_params.put("method", "generateForm");
            Object object = getContextObj();
            ReferenceFactory rf = new ReferenceFactory();
            VersionReference ref = VersionReference.newVersionReference((Iterated)object);
            String oid = rf.getReferenceString(ref);
            new_params.put("oid", oid);
            new_params.put("skipDownload", "true");
        } else
        {
            new_params.put("method", "invokeAction");
            String uploadToCacheOnly = null;
            if(params != null)
                uploadToCacheOnly = (String)params.get("uploadToCacheOnly");
            if(uploadToCacheOnly != null && uploadToCacheOnly.equalsIgnoreCase("true"))
                new_params.put("action", "CommitDocumentCreation");
            else
                new_params.put("action", "CreateDocCloseWindow");
            new_params.put("formName", "CreateDocumentWizard");
            new_params.put("class", "wt.doc.WTDocument");
        }
        getURLProcessorLinkForObj(new_params, locale, os);
    }

    public void getCallingAction(Properties params, Locale locale, OutputStream os)
        throws WTException
    {
        String formName = getFormName(params);
        String callingAction = "create";
        String fileString = getFormValueFromSession(formName, "File", "");
        if(fileString != null && fileString.length() > 0)
        {
            FormatContentHolder holder = null;
            Object obj = getContextObj();
            if(obj instanceof FormatContentHolder)
            {
                try
                {
                    holder = (FormatContentHolder)obj;
                    holder = (FormatContentHolder)ContentHelper.service.getContents(holder);
                    setContentHolder(holder);
                }
                catch(PropertyVetoException pve)
                {
                    System.err.println(pve);
                }
                wt.content.ContentItem item = ContentHelper.getPrimary(holder);
                if(item instanceof ApplicationData)
                {
                    ApplicationData app = (ApplicationData)item;
                    String primary = app.getFileName();
                    if(primary != null && primary.length() > 0)
                        callingAction = "updateReplace";
                }
            }
        }
        PrintWriter out = getPrintWriter(os, locale);
        out.print(callingAction);
        out.flush();
    }

    public void getReviseDownloadText(Properties params, Locale locale, OutputStream os)
    {
        if(!getPreferenceValue("/wt/content", "noDownloadOnCheckout").equalsIgnoreCase("true"))
        {
            Properties props = new Properties();
            props.put("resourceKey", "DOWNLOADING_REVISED_DOC_TITLE");
            props.put("resourceClass", "com.ptc.windchill.pdmlink.doc.client.clientRB");
            getLocalizedMessage(props, locale, os);
        }
    }

    public void getAppletAttachments(Properties props, Locale locale, OutputStream os)
        throws WTException
    {
        String formName = getFormName(props);
        String addAttachments = getFormValueFromSession(formName, "addAttachments", "");
        String removeAttachments = getFormValueFromSession(formName, "removeAttachments", "");
        if(addAttachments != null && addAttachments.length() > 0)
            addAttachments = wrapperPathsForAppletAdd(addAttachments);
        if(removeAttachments != null && removeAttachments.length() > 0)
            removeAttachments = wrapperOidsForAppletRemove(removeAttachments);
        String output = addAttachments;
        if(removeAttachments != null && removeAttachments.length() > 0)
            if(output != null && output.length() > 0)
                output = removeAttachments + RECORD_DELIM + output;
            else
                output = removeAttachments;
        if(output != null && output.length() > 0)
        {
            PrintWriter out = getPrintWriter(os, locale);
            out.print(output);
            out.flush();
        }
    }

    public String wrapperPathsForAppletAdd(String addAttachments)
    {
        StringBuffer output = new StringBuffer();
        String curElement = "";
        if(VERBOSE)
            System.out.println("in wrapperPathsForAppletAdd, addAttachments = \"" + addAttachments + "\"");
        int curPos = 0;
        int startPos = 0;
        int count = 0;
        do
        {
            curPos = addAttachments.indexOf(RECORD_DELIM, startPos);
            if(curPos >= 0)
                curElement = addAttachments.substring(startPos, curPos);
            else
                curElement = addAttachments.substring(startPos, addAttachments.length());
            if(VERBOSE)
                System.out.println("curElement " + count + " = \"" + curElement + "\"");
            if(output.length() > 0)
                output.append(RECORD_DELIM);
            output.append("FILE" + DELIM + "newFile" + DELIM + curElement + DELIM + "ADD");
            startPos = curPos + RECORD_DELIM.length();
            count++;
        } while(curPos != -1);
        if(VERBOSE)
            System.out.println("wrapperPathsForAppletAdd output = \"" + output + "\"");
        return output.toString();
    }

    public String wrapperOidsForAppletRemove(String removeAttachments)
    {
        StringBuffer output = new StringBuffer();
        String curElement = "";
        if(VERBOSE)
            System.out.println("in wrapperOidsForAppletRemove, removeAttachments = \"" + removeAttachments + "\"");
        int curPos = 0;
        int startPos = 0;
        int count = 0;
        do
        {
            curPos = removeAttachments.indexOf(RECORD_DELIM, startPos);
            if(curPos >= 0)
                curElement = removeAttachments.substring(startPos, curPos);
            else
                curElement = removeAttachments.substring(startPos, removeAttachments.length());
            if(VERBOSE)
                System.out.println("curElement " + count + " = \"" + curElement + "\"");
            if(output.length() > 0)
                output.append(RECORD_DELIM);
            output.append("FILE" + DELIM + curElement + DELIM + DELIM + "REMOVE");
            startPos = curPos + RECORD_DELIM.length();
            count++;
        } while(curPos != -1);
        if(VERBOSE)
            System.out.println("wrapperOidsForAppletRemove output = \"" + output + "\"");
        return output.toString();
    }

    public String getFormName(Properties parameters)
        throws WTException
    {
        String form_name = parameters.getProperty("formName");
        if(form_name == null || form_name.equals(""))
            throw new WTException("com.ptc.windchill.pdmlink.doc.server.processors.processorsResource", "2", null);
        else
            return form_name;
    }

    public void getDelim(Properties params, Locale locale, OutputStream os)
    {
        if(DELIM != null && DELIM.length() > 0)
        {
            PrintWriter out = getPrintWriter(os, locale);
            out.print(DELIM);
            out.flush();
        }
    }

    public void getRecordDelim(Properties params, Locale locale, OutputStream os)
    {
        if(RECORD_DELIM != null && RECORD_DELIM.length() > 0)
        {
            PrintWriter out = getPrintWriter(os, locale);
            out.print(RECORD_DELIM);
            out.flush();
        }
    }

    public void getUpdateDocumentDisplayIdentity(Properties parameters, Locale locale, OutputStream os)
        throws WTException
    {
        TemplateInfo template = null;
        WTDocument doc = (WTDocument)getContextObj();
        if(doc != null)
            template = doc.getTemplate();
        if(template != null && template.isTemplated())
            parameters.put("resourceKey", "UPDATE_DOCUMENT_TEMPLATE_TITLE");
        else
            parameters.put("resourceKey", "UPDATE_DOCUMENT_TITLE");
        getDocumentDisplayIdentity(parameters, locale, os);
    }

    public void processSubTemplateforUpdateDocument(Properties parameters, Locale locale, OutputStream os)
    {
        TemplateInfo template = null;
        WTDocument doc = (WTDocument)getContextObj();
        if(doc != null)
            template = doc.getTemplate();
        if(template != null && template.isTemplated())
            parameters.put("titleResourceKey", "UPDATE_DOCUMENT_TEMPLATE_TITLE");
        else
            parameters.put("titleResourceKey", "UPDATE_DOCUMENT_TITLE");
        processSubTemplate(parameters, locale, os);
    }

    public void getCheckinDocumentDisplayIdentity(Properties parameters, Locale locale, OutputStream os)
        throws WTException
    {
        TemplateInfo template = null;
        WTDocument doc = (WTDocument)getContextObj();
        if(doc != null)
            template = doc.getTemplate();
        if(template != null && template.isTemplated())
            parameters.put("resourceKey", "CHECKIN_DOCUMENT_TEMPLATE_TITLE");
        else
            parameters.put("resourceKey", "CHECKIN_DOCUMENT_TITLE");
        getDocumentDisplayIdentity(parameters, locale, os);
    }

    public void processSubTemplateforCheckinDocument(Properties parameters, Locale locale, OutputStream os)
    {
        TemplateInfo template = null;
        WTDocument doc = (WTDocument)getContextObj();
        if(doc != null)
            template = doc.getTemplate();
        if(template != null && template.isTemplated())
            parameters.put("titleResourceKey", "CHECKIN_DOCUMENT_TEMPLATE_TITLE");
        else
            parameters.put("titleResourceKey", "CHECKIN_DOCUMENT_TITLE");
        processSubTemplate(parameters, locale, os);
    }

    public void getHostName(Properties params, Locale locale, OutputStream os)
    {
        HTTPRequest request = getState().getRequestObj();
        String hostName = request.getProperty("cgi.remote_host");
        PrintWriter out = getPrintWriter(os, locale);
        out.print(hostName);
        out.flush();
    }

    public void getSessionID(Properties params, Locale locale, OutputStream os)
    {
        HTTPRequest request = getState().getRequestObj();
        String sessionId = request.getProperty("cgi.servlet.session");
        PrintWriter out = getPrintWriter(os, locale);
        out.print(sessionId);
        out.flush();
    }

    public void getUploadURL(Properties params, Locale locale, OutputStream os)
        throws WTException
    {
        String uploadURL = String.valueOf(ContentHelper.getUploadURL((ContentHolder)getContextObj()));
        if(uploadURL != null)
        {
            PrintWriter out = getPrintWriter(os, locale);
            out.print(uploadURL);
            out.flush();
        }
    }

    public void getPrimaryContentForUpload(Properties params, Locale locale, OutputStream os)
        throws WTException
    {
        if(params != null)
        {
            String form_name = params.getProperty("formName");
            String targetType = getFormData().getProperty("targetType");
            if(targetType == null || targetType == "")
                targetType = getFormValueFromSession(form_name, "targetType", "");
            if("".equals(targetType) || "FILE".equals(targetType))
                getFormValueFromSession(params, locale, os);
        }
    }

    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;
    static final long serialVersionUID = 1L;
    public static final long EXTERNALIZATION_VERSION_UID = 0xa6700984c6548630L;
    protected static final long OLD_FORMAT_VERSION_UID = 0xdf925d04f702e856L;
    private static final String ERESOURCE = "wt.enterprise.enterpriseResource";
    private static final String FORMNAME = "formName";
    protected static boolean VERBOSE = false;
    protected static boolean DEBUG = false;
    protected static boolean SHOWUPLOADAPPLET = true;
    public static String DELIM;
    public static String RECORD_DELIM;

    static 
    {
        CLASSNAME = (com.ptc.windchill.pdmlink.doc.server.processors.DocumentProcessor.class).getName();
        try
        {
            WTProperties properties = WTProperties.getLocalProperties();
            VERBOSE = properties.getProperty("wt.doc.verbose", false);
            DEBUG = properties.getProperty("wt.clients.debug", false);
            DELIM = properties.getProperty("wt.doc.hiddenFieldDelimiter", ";;;qqq");
            RECORD_DELIM = properties.getProperty("wt.doc.hiddenFieldRecordDelimiter", ";;;zzz");
            SHOWUPLOADAPPLET = properties.getProperty("wt.clients.showUploadApplet", true);
        }
        catch(Throwable t)
        {
            System.err.println("com.ptc.windchill.pdmlink.doc.server.processors.DocumentProcessor : Error reading wt.doc.* properties");
            t.printStackTrace(System.err);
            throw new ExceptionInInitializerError(t);
        }
    }
}
