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

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

import com.ptc.core.HTMLtemplateutil.server.processors.WindowUtils;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyVetoException;
import java.io.Externalizable;
import java.net.URL;
import java.util.*;
import wt.content.*;
import wt.doc.WTDocument;
import wt.fc.ReferenceFactory;
import wt.httpgw.GatewayURL;
import wt.introspection.PropertyDisplayName;
import wt.templateutil.processor.*;
import wt.util.WTException;
import wt.util.WTPropertyVetoException;
import wt.vc.Iterated;
import wt.vc.VersionReference;

// Referenced classes of package com.ptc.windchill.pdmlink.doc.server.processors:
//            ViewDocumentActionDelegate

public class ViewDocumentURLActionDelegate extends ViewDocumentActionDelegate
    implements NavBarURLActionDelegate, Externalizable
{

    public ViewDocumentURLActionDelegate()
    {
        actionName = null;
        classURL = null;
        helper = null;
        helper = new NavBarURLActionDelegateHelper();
    }

    public boolean isURLProvider(HashMap queryValueMap, Object object)
    {
        return helper.isURLProvider(queryValueMap, object);
    }

    public void setResourceKey(String key)
    {
        helper.setResourceKey(key);
    }

    public void setResourceBundleStr(String resourceBundle)
    {
        helper.setResourceBundleStr(resourceBundle);
    }

    public void setState(HTTPState state)
    {
        helper.setState(state);
    }

    public void setMethod(String method)
    {
        helper.setMethod(method);
    }

    public String getClassURL()
    {
        return classURL;
    }

    public void setClassURL(String a_ClassURL)
        throws WTPropertyVetoException
    {
        classURLValidate(a_ClassURL);
        classURL = a_ClassURL;
    }

    private void classURLValidate(String a_ClassURL)
        throws WTPropertyVetoException
    {
        if(a_ClassURL != null && a_ClassURL.length() > 200)
        {
            Object args[] = {
                new PropertyDisplayName(CLASSNAME, "classURL"), "200"
            };
            throw new WTPropertyVetoException("wt.introspection.introspectionResource", "20", args, new PropertyChangeEvent(this, "classURL", classURL, a_ClassURL));
        } else
        {
            return;
        }
    }

    public String URL(Object object)
        throws WTException
    {
        Object param[] = {
            (com.ptc.windchill.pdmlink.doc.server.processors.ViewDocumentURLActionDelegate.class).getName()
        };
        Boolean validation = enableable(object);
        String url_string = null;
        if(validation != null && validation.booleanValue())
        {
            URL url = null;
            try
            {
                if(object instanceof WTDocument)
                {
                    FormatContentHolder holder = (FormatContentHolder)object;
                    holder = (FormatContentHolder)ContentHelper.service.getContents(holder);
                    wt.content.ContentItem item = ContentHelper.getPrimary(holder);
                    if(item instanceof ApplicationData)
                    {
                        ApplicationData app = (ApplicationData)item;
                        url_string = ContentHtmlUtils.getFileDownloadLaunchURL(holder, app, String.valueOf(app.getViewContentURL(holder)), 3, false);
                    } else
                    if(item instanceof URLData)
                    {
                        URLData contentUrl = (URLData)item;
                        url_string = contentUrl.getUrlLocation();
                    }
                }
                if(url_string == null || url_string.length() == 0)
                {
                    Properties props = new Properties();
                    props.put("Action", "GetContent_plm");
                    ReferenceFactory rf = new ReferenceFactory();
                    VersionReference ref = VersionReference.newVersionReference((Iterated)object);
                    String oid = rf.getReferenceString(ref);
                    props.put("oid", oid);
                    Class urlp = Class.forName("wt.enterprise.URLProcessor");
                    url = GatewayURL.buildAuthenticatedURL(urlp.getName(), "generateForm", props);
                    url_string = url.toString();
                    url_string = WindowUtils.getLaunchWindowURLWrapper(url_string, "viewDocWindow", 500, 200);
                }
            }
            catch(WTException wte)
            {
                throw new WTException(wte, "wt.enterprise.enterpriseResource", "0", param);
            }
            catch(ClassNotFoundException cnfe)
            {
                throw new WTException(cnfe, "wt.enterprise.enterpriseResource", "0", param);
            }
            catch(PropertyVetoException pve)
            {
                throw new WTException(pve, "wt.enterprise.enterpriseResource", "0", param);
            }
            finally
            {
                throw exception;
            }
        }
        return url_string;
    }

    public String getURLLabel(Locale locale)
    {
        return helper.getURLLabel(locale);
    }

    public void setActionName(String action)
    {
        try
        {
            helper.setActionName(action);
        }
        catch(WTPropertyVetoException wpve)
        {
            wpve.printStackTrace();
        }
    }

    public String getActionName()
    {
        return helper.getActionName();
    }

    private static final String RESOURCE = "com.ptc.windchill.pdmlink.doc.server.processors.processorsResource";
    private static final String CLASSNAME;
    private String actionName;
    private String classURL;
    protected NavBarURLActionDelegateHelper helper;
    private static final String ENT_RESOURCE = "wt.enterprise.enterpriseResource";

    static 
    {
        CLASSNAME = (com.ptc.windchill.pdmlink.doc.server.processors.ViewDocumentURLActionDelegate.class).getName();
    }
}
