// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   TypeReferenceTag.java

package com.ptc.windchill.enterprise.doc.tags;

import com.ptc.netmarkets.model.NmOid;
import com.ptc.netmarkets.type.NmTypeServiceFwd;
import com.ptc.netmarkets.util.beans.*;
import com.ptc.netmarkets.util.misc.NmAction;
import java.util.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import org.apache.log4j.Logger;
import wt.doc.WTDocument;
import wt.lifecycle.LifeCycleServiceFwd;
import wt.lifecycle.State;
import wt.log4j.LogR;
import wt.session.SessionHelper;
import wt.util.WTException;

public class TypeReferenceTag extends SimpleTagSupport
{

    public TypeReferenceTag()
    {
    }

    public void doTag()
        throws JspException
    {
        String s;
        commandBean = getClientData();
        s = null;
        if(getPageId() == null || !getPageId().equalsIgnoreCase("pasteShared"))
            break MISSING_BLOCK_LABEL_67;
        setClipped();
        s = getClassnameForPaste();
        if(emptyClipboard)
            return;
        List list;
        try
        {
            setAttribute("pasteFloatingRef", Boolean.valueOf(isShowFloatingRef()));
            if(!isShowFloatingRef())
                return;
        }
        catch(Exception exception)
        {
            LOGGER.debug((new StringBuilder()).append("Exception processing body for typeReferenceTag: ").append(this).toString());
            if(exception instanceof JspException)
                throw (JspException)exception;
            else
                throw new JspException(exception);
        }
        break MISSING_BLOCK_LABEL_72;
        s = getClassnameForCreate();
        if(s == null)
            s = "wt.doc.WTDocument";
        list = getLifeCycleStates(s);
        setAttribute("states", list);
    }

    public String getPageId()
    {
        if(pageId == null)
            return "";
        else
            return pageId;
    }

    public void setPageId(String s)
    {
        pageId = s;
    }

    public Object getClipboardBean()
    {
        return clipboardBean;
    }

    public void setClipboardBean(Object obj)
    {
        clipboardBean = obj;
    }

    protected String getClassnameForPaste()
        throws JspException
    {
        String s = null;
        NmOid nmoid = null;
        ArrayList arraylist = commandBean.getClipped();
        Iterator iterator;
        WTDocument wtdocument;
        try
        {
            if(arraylist == null || arraylist.size() == 0)
            {
                emptyClipboard = true;
                sendErrorMsg();
                return null;
            }
        }
        catch(Exception exception)
        {
            LOGGER.debug((new StringBuilder()).append("Exception processing body for typeReferenceTag: ").append(this).toString());
            if(exception instanceof JspException)
                throw (JspException)exception;
            else
                throw new JspException(exception);
        }
        for(iterator = arraylist.iterator(); iterator.hasNext() && !showFloatingRef; setShowFloatingRef(nmoid))
            nmoid = getOid(iterator.next());

        if(!showFloatingRef)
            return null;
        wtdocument = (WTDocument)nmoid.getRef();
        if(wtdocument == null)
            return null;
        s = wtdocument.getClass().getName();
        return s;
    }

    protected String getClassnameForCreate()
    {
        Object obj = ((List)commandBean.getComboBox().get("createType")).get(0);
        if(obj == null)
            return null;
        else
            return obj.toString();
    }

    protected void sendErrorMsg()
        throws Exception
    {
        ResourceBundle resourcebundle = ResourceBundle.getBundle("com.ptc.netmarkets.object.objectResource", SessionHelper.getLocale());
        JspWriter jspwriter = ((PageContext)getJspContext()).getOut();
        NmAction.showError(resourcebundle.getString("52"), jspwriter);
        jspwriter.print("<script type=\"text/javascript\">wfWindowClose()</script>");
    }

    protected NmOid getOid(Object obj)
        throws WTException
    {
        return NmCommandBean.getOidFromObject(obj);
    }

    protected void setAttribute(String s, Object obj)
    {
        getJspContext().setAttribute(s, obj);
    }

    protected NmCommandBean getClientData()
        throws WTException
    {
        NmHelperBean nmhelperbean = new NmHelperBean();
        nmhelperbean.setJspContext(getJspContext());
        NmCommandBean nmcommandbean = nmhelperbean.getNmCommandBean();
        return nmcommandbean;
    }

    protected void setClipped()
    {
        commandBean.setClipboardBean((NmClipboardBean)getClipboardBean());
    }

    protected boolean isShowFloatingRef()
    {
        return showFloatingRef;
    }

    protected void setShowFloatingRef(boolean flag)
    {
        showFloatingRef = flag;
    }

    protected void setShowFloatingRef(NmOid nmoid)
    {
        if(nmoid == null || !nmoid.isA(wt/doc/WTDocument))
            setShowFloatingRef(false);
        else
            setShowFloatingRef(true);
    }

    protected List getLifeCycleStates(String s)
        throws Exception
    {
        String s1 = (new NmTypeServiceFwd()).getSelectedLifeCycleName(s, commandBean.getContainerRef());
        LifeCycleServiceFwd lifecycleservicefwd = new LifeCycleServiceFwd();
        wt.lifecycle.LifeCycleTemplate lifecycletemplate = lifecycleservicefwd.getLifeCycleTemplate(s1, commandBean.getContainerRef());
        Vector vector = lifecycleservicefwd.findStates(lifecycletemplate);
        ArrayList arraylist = new ArrayList(vector.size());
        ArrayList arraylist1 = new ArrayList(vector.size());
        java.util.Locale locale = SessionHelper.getLocale();
        for(int i = 0; i < vector.size(); i++)
        {
            State state = (State)vector.get(i);
            arraylist.add(state.getDisplay(locale));
            arraylist1.add(state.toString());
        }

        setAttribute("internal", arraylist1);
        return arraylist;
    }

    protected boolean isEmptyClipboard()
    {
        return emptyClipboard;
    }

    protected void setEmptyClipboard(boolean flag)
    {
        emptyClipboard = flag;
    }

    private String pageId;
    private Object clipboardBean;
    private NmCommandBean commandBean;
    private boolean showFloatingRef;
    private boolean emptyClipboard;
    private static final Logger LOGGER;
    private static final String RESOURCE = "com.ptc.netmarkets.object.objectResource";

    static 
    {
        try
        {
            LOGGER = LogR.getLogger(com/ptc/windchill/enterprise/doc/tags/TypeReferenceTag.getName());
        }
        catch(Exception exception)
        {
            throw new ExceptionInInitializerError(exception);
        }
    }
}
