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

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

import com.ptc.core.foundation.type.server.impl.TypeHelper;
import com.ptc.core.meta.server.TypeIdentifierUtility;
import com.ptc.windchill.enterprise.copy.server.CoreMetaUtility;
import java.beans.PropertyVetoException;
import java.io.*;
import java.util.*;
import wt.content.*;
import wt.facade.scm.ScmFacade;
import wt.fc.Persistable;
import wt.fc.WTObject;
import wt.htmlutil.TemplateOutputStream;
import wt.part.WTPart;
import wt.type.TypedUtility;
import wt.util.InstalledProperties;
import wt.util.WTException;

public class WTDocumentAttributesProcessor extends ContentProcessor
    implements Externalizable
{

    public WTDocumentAttributesProcessor()
    {
        locale = null;
        savedContextObject = null;
    }

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

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

    protected boolean readVersion(WTDocumentAttributesProcessor thisObject, ObjectInput input, long readSerialVersionUID, boolean passThrough, boolean superDone)
        throws IOException, ClassNotFoundException
    {
        boolean success = true;
        if(readSerialVersionUID == 0xc0ac2935b533216aL)
        {
            if(!superDone)
                super.readExternal(input);
        } else
        {
            success = readOldVersion(input, readSerialVersionUID, passThrough, superDone);
        }
        return success;
    }

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

    public void getTypeDisplay(Properties properties, Locale locale, OutputStream os)
        throws WTException
    {
        PrintWriter out = getPrintWriter(os, locale);
        Object obj = getContextObj();
        String localized_string = CoreMetaUtility.getLocalizedTypeString((WTObject)obj, locale);
        if(localized_string == null)
            localized_string = "";
        out.print(localized_string);
        out.flush();
    }

    public void getBaseType(Properties parameters, Locale locale, OutputStream os)
        throws WTException
    {
        PrintWriter out = TemplateOutputStream.getPrintWriter(os, locale);
        Persistable object = (Persistable)getContextObj();
        com.ptc.core.meta.common.TypeIdentifier typeID = TypeIdentifierUtility.getTypeIdentifier(object);
        String base_type = TypeHelper.getBaseType(typeID);
        out.print(base_type);
        out.flush();
    }

    public void displayURLAttachmentsTableBody(Properties parameters, Locale locale, OutputStream os)
        throws WTException
    {
        String urlPref = getPreferenceValue("/com/ptc/windchill/doc", "UrlContent");
        ContentHolder contentholder = (ContentHolder)getContextObj();
        try
        {
            contentholder = ContentHelper.service.getContents(contentholder);
        }
        catch(PropertyVetoException pve)
        {
            pve.printStackTrace();
        }
        if(contentholder != null && (contentholder instanceof WTPart))
        {
            if(InstalledProperties.isInstalled("Windchill.SoftwareConfigMgmtIntegration"))
            {
                String objectType = TypedUtility.getExternalTypeIdentifier(contentholder);
                if(ScmFacade.getInstance().isSoftwarePart(objectType) && ("true".equalsIgnoreCase(urlPref) || ContentHelper.getURLData(contentholder).size() > 0))
                {
                    if(parameters == null)
                        parameters = new Properties();
                    parameters.put("action", "AttachmentsURLTable");
                    processSubTemplate(parameters, locale, os);
                }
            }
        } else
        if(ContentHelper.getURLData(contentholder).size() > 0 || "true".equalsIgnoreCase(urlPref))
        {
            if(parameters == null)
                parameters = new Properties();
            parameters.put("action", "AttachmentsURLTable");
            processSubTemplate(parameters, locale, os);
        }
    }

    private static String CLASSNAME = "com.ptc.windchill.pdmlink.doc.server.processors.WTDocumentAttributesProcessor";
    private static final String RESOURCE = "com.ptc.windchill.pdmlink.doc.server.processors.processorsResource";
    private static final String PROCESSOR_CLASS = "wt.enterprise.URLProcessor";
    private static final String PROCESSOR_METHOD = "URLTemplateAction";
    private Locale locale;
    private Object savedContextObject;

}
