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

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

import com.ptc.core.HTMLtemplateutil.server.processors.UtilProcessorService;
import com.ptc.windchill.pdmlink.search.PLMLinkSearchAttributeList;
import java.beans.PropertyDescriptor;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.*;
import wt.clients.beans.query.WTBusinessInfo;
import wt.doc.*;
import wt.fc.*;
import wt.htmlutil.HtmlUtil;
import wt.htmlutil.TemplateOutputStream;
import wt.httpgw.GatewayServletHelper;
import wt.identity.IdentityFactory;
import wt.inf.container.WTContainerHelper;
import wt.inf.container.WTContainerService;
import wt.introspection.*;
import wt.org.WTPrincipal;
import wt.pds.PDSObjectInput;
import wt.query.SearchTask;
import wt.session.SessionHelper;
import wt.templateutil.processor.GenerateFormProcessor;
import wt.templateutil.processor.HTTPState;
import wt.templateutil.table.*;
import wt.util.*;

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

public class DocumentAssociationSearchProcessor extends GenerateFormProcessor
    implements Externalizable
{

    public DocumentAssociationSearchProcessor()
    {
        results = null;
    }

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

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

    protected boolean readVersion(DocumentAssociationSearchProcessor thisObject, ObjectInput input, long readSerialVersionUID, boolean passThrough, boolean superDone)
        throws IOException, ClassNotFoundException
    {
        boolean success = true;
        if(readSerialVersionUID == 0x5c9ab67f442bc0d1L)
        {
            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 != 0x173e79b4979d8e21L)
            if(!superDone)
            {
                success = super.readVersion(this, input, readSerialVersionUID, false, false);
                if(success && !passThrough && readSerialVersionUID != 0x5c76dbfc74a584b3L)
                    readVersion(this, input, input.readLong(), false, true);
            } else
            {
                throw new InvalidClassException(CLASSNAME, "Local class not compatible: stream classdesc externalizationVersionUID=" + readSerialVersionUID + " local class externalizationVersionUID=" + 0x5c9ab67f442bc0d1L);
            }
        return success;
    }

    public void generateSearchForm(Properties parameters, Locale locale, OutputStream os)
        throws WTIntrospectionException, WTException, WTPropertyVetoException
    {
        String tempQuery = null;
        if(getFormData() != null)
            tempQuery = getFormData().getProperty("QUERY");
        if((tempQuery == null || tempQuery.length() == 0 || tempQuery.equals("")) && getQueryData() != null)
            tempQuery = getQueryData().getProperty("QUERY");
        if(tempQuery == null || tempQuery.length() == 0 || tempQuery.equals(""))
            throw new WTException("com.ptc.windchill.pdmlink.doc.server.processors.processorsResource", "61", null);
        PrintWriter out = getPrintWriter(os, locale);
        DocumentSearchAttributeList search_list = new DocumentSearchAttributeList(locale);
        String query_value = tempQuery;
        Vector input_attributes;
        Vector input_processing;
        Vector display_attributes;
        Class class_name;
        try
        {
            Vector pick_list = search_list.getPickList();
            Vector pick_values = search_list.getPickValues();
            int query_type = search_list.getQueryType(query_value);
            Vector classes = search_list.getQueryClass(query_type);
            class_name = (Class)classes.elementAt(0);
            input_attributes = search_list.getInputAttributes(query_type);
            input_processing = search_list.getInputProcessing(query_type);
            display_attributes = PLMLinkSearchAttributeList.getPropertyDescriptors(input_attributes, class_name);
        }
        catch(WTException wte)
        {
            String big_mesg = WTMessage.getLocalizedMessage("wt.query.queryResource", "28", null, locale);
            out.println(big_mesg);
            out.println("</FORM>");
            out.flush();
            handleExceptionTP("localSearch", wte, true, parameters, locale, os);
            return;
        }
        out.println("\n<SCRIPT LANGUAGE=\"Javascript1.1\" SRC=\"templates/pdmlink/search/FindUsersSharedFunctions.js\"></SCRIPT>\n");
        out.println("<TABLE ALIGN=LEFT BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=90%> <TR><TD>");
        out.println("</TD></TR><TR><TD>&nbsp;</TD></TR><TR><TD>&nbsp;</TD></TR>");
        out.println("<TR><TD>");
        out.println("<TABLE BORDER=\"0\" CELLPADDING=\"1\">");
        ClassInfo contextInfo = WTIntrospector.getClassInfo(class_name);
        String bgColor = getWCColor("t1-bg-evenrow");
        for(int i = 0; i < input_attributes.size(); i++)
        {
            String attrib = (String)input_attributes.elementAt(i);
            PropertyDescriptor pd = (PropertyDescriptor)display_attributes.elementAt(i);
            if(pd == null)
            {
                Object param[] = {
                    attrib, class_name
                };
                String mesg = WTMessage.getLocalizedMessage("wt.query.queryResource", "2", param);
                out.println("<TR>");
                out.println("<TD ALIGN=RIGHT>");
                out.println("</TD>");
                out.println("<TD ALIGN=LEFT>");
                out.println("<B>" + mesg);
                out.println("</TD>");
                out.println("</TR>");
                continue;
            }
            String display_name = ClassInfo.getPropertyDisplayName(pd, locale);
            out.println("<TR>");
            out.println("<TD ALIGN=RIGHT>");
            out.println("<B>" + display_name + ":");
            out.println("</TD>");
            out.println("<TD>");
            Class att_class = pd.getPropertyType();
            if(att_class.getName().equals((wt.org.WTPrincipalReference.class).getName()))
            {
                String trail_id = HtmlUtil.createTrlIdAttribute("PDML", "DocAssociationsSearch_" + attrib, "InputText", "docmgmt_" + attrib);
                out.println("<table><tr><td>");
                out.println("<INPUT NAME = \"" + attrib + "\"" + trail_id + " TYPE=\"text\" onblur='checkForm(this)'>");
                out.println("</td><td align=\"left\">");
                out.flush();
                wt.httpgw.URLFactory url_factory = getState().getURLFactory();
                String url = "";
                try
                {
                    HashMap map = new HashMap();
                    map.put("action", "FindUsers");
                    url = GatewayServletHelper.buildAuthenticatedURL(url_factory, "wt.enterprise.URLProcessor", "URLTemplateAction", map).toExternalForm();
                }
                catch(Exception e)
                {
                    throw new WTException(e);
                }
                String finalURL = "javascript:void(0);\" onclick=\"javascript: findUsers('" + url + "','" + attrib + "', false, false)";
                UtilProcessorService utilProc = new UtilProcessorService();
                utilProc.setState(getState());
                if(parameters == null)
                    parameters = new Properties();
                parameters.setProperty("buttonURL", finalURL);
                parameters.setProperty("resourceClass", "com.ptc.windchill.pdmlink.search.server.processors.htmlsearchResource");
                parameters.setProperty("resourceKey", "FIND_USERS_BUTTON");
                utilProc.getButton(parameters, locale, os);
                out.println("</td></tr></table></TD>");
            } else
            if(att_class.getName().equals((java.sql.Timestamp.class).getName()))
            {
                String trail_id = HtmlUtil.createTrlIdAttribute("PDML", "DocAssociationsSearch_" + attrib, "InputText", "docmgmt_" + attrib);
                String message = WTMessage.getLocalizedMessage("wt.query.dateHelperResource", "dateInputFormat", null, locale);
                out.println("<INPUT NAME = \"" + attrib + "\" " + trail_id + " TYPE=\"text\">");
                out.println("<FONT SIZE=-2>(" + message + ")</FONT></TD>");
            } else
            {
                String method_name = (String)input_processing.elementAt(i);
                Vector lists = getValueList(pd, locale);
                Vector value_list = (Vector)lists.elementAt(0);
                Vector trail_id_vector = (Vector)lists.elementAt(1);
                if(value_list.size() > 0)
                {
                    String trail_id = HtmlUtil.createTrlIdAttribute("PDML", "DocAssociationsSearch_" + attrib, "DropDown", "");
                    Vector sel = new Vector();
                    sel.add(new Integer(0));
                    out.print(HtmlUtil.createSelectHTML(attrib, trail_id, value_list, null, trail_id_vector, true, sel));
                    out.flush();
                } else
                if(!method_name.equals("0"))
                {
                    try
                    {
                        Vector legal_list = getLegalValueList(method_name);
                        String trail_id = HtmlUtil.createTrlIdAttribute("PDML", "DocAssociationsSearch_" + attrib, "DropDown", "");
                        Vector sel = new Vector();
                        sel.add(new Integer(0));
                        out.print(HtmlUtil.createSelectHTML(attrib, trail_id, legal_list, null, null, true, sel));
                        out.flush();
                    }
                    catch(WTException wte)
                    {
                        String trail_id = HtmlUtil.createTrlIdAttribute("PDML", "DocAssociationsSearch_" + attrib, "InputText", "docmgmt_" + attrib);
                        out.println("<INPUT NAME = \"" + attrib + "\" " + trail_id + " TYPE=\"text\">");
                    }
                } else
                {
                    String trail_id = HtmlUtil.createTrlIdAttribute("PDML", "DocAssociationsSearch_" + attrib, "InputText", "docmgmt_" + attrib);
                    out.println("<INPUT NAME = \"" + attrib + "\" " + trail_id + " TYPE=\"text\">");
                }
                out.println("</TD>");
            }
            out.println("</TR>");
        }

        out.println("</TABLE>");
        out.println("</TD></TR>");
        out.println("</TABLE>");
        ReferenceFactory refFactory = new ReferenceFactory();
        String currentOID = refFactory.getReferenceString((Persistable)getContextObj());
        out.println("<INPUT TYPE=\"hidden\" name=\"oid\" value=\"" + currentOID + "\">");
        out.println("<INPUT TYPE=\"hidden\" name=\"query\" value=\"" + query_value + "\">");
        out.flush();
    }

    public void doObjectSearch(Properties parameters, Locale locale, OutputStream os)
        throws WTIntrospectionException, WTException, WTPropertyVetoException
    {
        results = null;
        String tempQuery = null;
        getState().setFormData(addQueryDataToFormData(getState().getFormData(), getQueryData()));
        if(getFormData() != null)
            tempQuery = getFormData().getProperty("QUERY");
        if((tempQuery == null || tempQuery.length() == 0 || tempQuery.equals("")) && getQueryData() != null)
            tempQuery = getQueryData().getProperty("QUERY");
        if(tempQuery == null || tempQuery.length() == 0 || tempQuery.equals(""))
            throw new WTException("com.ptc.windchill.pdmlink.doc.server.processors.processorsResource", "61", null);
        PrintWriter out = getPrintWriter(os, locale);
        DocumentSearchAttributeList search_list = new DocumentSearchAttributeList(locale);
        Vector output_attributes = null;
        Vector classes = null;
        Vector output_pd = null;
        Vector output_links = null;
        try
        {
            int query_type = search_list.getQueryType(tempQuery);
            classes = search_list.getQueryClass(query_type);
            output_attributes = search_list.getOutputAttributes(query_type);
            output_pd = PLMLinkSearchAttributeList.getPropertyDescriptors(output_attributes, classes);
            output_links = search_list.getOutputProcessing(query_type);
        }
        catch(WTException e)
        {
            String msg = WTMessage.getLocalizedMessage("wt.query.queryResource", "28", null, locale);
            addExceptionToFooters(e);
            return;
        }
        Hashtable criteria = new Hashtable();
        Enumeration enum = getFormData().keys();
        do
        {
            if(!enum.hasMoreElements())
                break;
            String name = (String)enum.nextElement();
            String value = getFormData().getProperty(name);
            if(!name.equals(name.toUpperCase()) && notOtherFields(name) && notHiddenFields(name) && !value.equals("") && value != null)
                criteria.put(name, value);
        } while(true);
        WTContainerHelper.setOrgContainerSearchScope(WTContainerHelper.service.getOrgContainerRef(SessionHelper.getPrincipal().getOrganization()));
        SearchTask st = new SearchTask();
        try
        {
            st.setSearchFilter("CHANGEABLE_VERSIONS");
            Vector container_list = new Vector(2);
            container_list.add((wt.inf.library.WTLibrary.class).getName());
            container_list.add((wt.pdmlink.PDMLinkProduct.class).getName());
            results = st.search(classes, criteria, output_attributes, null, locale, null, container_list);
        }
        catch(WTPropertyVetoException wte)
        {
            addExceptionToFooters(wte);
            return;
        }
        catch(WTException wte)
        {
            addExceptionToFooters(wte);
            return;
        }
    }

    public void showObjectSearch(Properties parameters, Locale locale, OutputStream os)
        throws WTException, WTPropertyVetoException
    {
        Vector resultsVector = new Vector();
        for(; results != null && results.hasMoreElements(); resultsVector.addElement(results.nextElement()));
        String tempQuery = null;
        if(getFormData() != null)
            tempQuery = getFormData().getProperty("QUERY");
        if((tempQuery == null || tempQuery.length() == 0 || tempQuery.equals("")) && getQueryData() != null)
            tempQuery = getQueryData().getProperty("QUERY");
        if(tempQuery == null || tempQuery.length() == 0 || tempQuery.equals(""))
            throw new WTException("com.ptc.windchill.pdmlink.doc.server.processors.processorsResource", "61", null);
        DocumentSearchAttributeList search_list = new DocumentSearchAttributeList(locale);
        int query_type = search_list.getQueryType(tempQuery);
        Vector queryClass = search_list.getQueryClass(query_type);
        Vector output_attributes = search_list.getOutputAttributes(query_type);
        Class outputClass = (Class)queryClass.elementAt(0);
        String outputClazz = outputClass.getName();
        PDMLinkHTMLTable table = new PDMLinkHTMLTable();
        table.setSuppressLink(true);
        table.setPendingIcon(true);
        table.setPresentActionsIconColumn(false);
        table.setName("DocumentAssociationTable");
        table.setPresentCheckBox(true);
        RowDataTableModel rowDataTableModel = new RowDataTableModel();
        rowDataTableModel.setRowDataObjects(resultsVector);
        rowDataTableModel.setTableColumns(output_attributes);
        rowDataTableModel.setLocale(locale);
        Enumeration enum = output_attributes.elements();
        int ctr = 1;
        String myKey;
        for(; enum.hasMoreElements(); rowDataTableModel.setHeaderFromTargetClass(outputClazz, myKey))
            myKey = (String)enum.nextElement();

        table.setLocale(locale);
        SortedTableModel sortedModel = new SortedTableModel();
        sortedModel.setModel(rowDataTableModel);
        table.setTableModel(sortedModel);
        table.setTableColumnModel(new DefaultHTMLTableColumnModel());
        table.createDefaultColumnsFromModel();
        ColumnSortService sortService = new ColumnSortService(getState());
        String columnName = sortService.getSortedColumnName(table.getName());
        if(columnName != null)
        {
            int i = table.getTableColumnModel().getColumnIndex(columnName);
            if(i > -1)
                sortedModel.sortByColumn(i, sortService.isSortAscending(table.getName(), columnName));
        }
        table.setState(getState());
        table.setOutputStream(os);
        table.init(null, null, null, null, null);
        getHTMLTableService().setHtmlTable(table);
    }

    public void initializeUsesDocTable(Properties parameters, Locale locale, OutputStream os)
        throws WTException
    {
        if(VERBOSE)
            System.out.println("DocumentAssociationSearchProcessor.initializeUsesDocTable starting.");
        PrintWriter out = TemplateOutputStream.getPrintWriter(os, locale);
        WTDocument doc = (WTDocument)getContextObj();
        Enumeration result = WTDocumentHelper.service.getOrderedUsesWTDocumentMasters(doc);
        Vector rowDataObjects = new Vector();
        for(; result.hasMoreElements(); rowDataObjects.addElement(result.nextElement()));
        PDMLinkHTMLTable table = new PDMLinkHTMLTable();
        table.setSuppressLink(true);
        table.setPendingIcon(true);
        table.setPresentActionsIconColumn(false);
        table.setName("DocumentUsesTable");
        table.setPresentCheckBox(true);
        table.setFormData(parameters);
        RowDataTableModel tableModel = new RowDataTableModel();
        tableModel.setRowDataObjects(rowDataObjects);
        Vector columnVector = new Vector();
        columnVector.addElement("name");
        columnVector.addElement("number");
        tableModel.setTableColumns(columnVector);
        tableModel.setLocale(locale);
        String doc_class = (wt.doc.WTDocument.class).getName();
        Enumeration enum = columnVector.elements();
        int ctr = 1;
        String myKey;
        for(; enum.hasMoreElements(); tableModel.setHeaderFromTargetClass(doc_class, myKey))
            myKey = (String)enum.nextElement();

        table.setLocale(locale);
        SortedTableModel sortedModel = new SortedTableModel();
        sortedModel.setModel(tableModel);
        table.setTableModel(sortedModel);
        table.setTableColumnModel(new DefaultHTMLTableColumnModel());
        table.createDefaultColumnsFromModel();
        ColumnSortService sortService = new ColumnSortService(getState());
        String columnName = sortService.getSortedColumnName(table.getName());
        if(columnName != null)
        {
            int i = table.getTableColumnModel().getColumnIndex(columnName);
            if(i > -1)
                sortedModel.sortByColumn(i, sortService.isSortAscending(table.getName(), columnName));
        }
        table.setState(getState());
        table.setOutputStream(os);
        table.init(null, null, null, null, null);
        getHTMLTableService().setHtmlTable(table);
        out.flush();
        if(VERBOSE)
            System.out.println("DocumentAssociationSearchProcessor.initializeUsesDocTable ending.");
    }

    public void generateFormTag(Properties parameters, Locale locale, OutputStream os)
        throws WTException
    {
        PrintWriter out = getPrintWriter(os, locale);
        try
        {
            String url = GatewayServletHelper.buildAuthenticatedHREF(getState().getURLFactory(), "wt.enterprise.URLProcessor", "URLTemplateAction", (HashMap)null);
            out.println("<FORM name=\"SearchForm\" ACTION=\"" + url + "\" METHOD=\"POST\">");
            out.flush();
        }
        catch(Exception e)
        {
            throw new WTException(e);
        }
    }

    public void addHiddenFields(Properties parameters, Locale locale, OutputStream os)
        throws WTException
    {
        int length = hiddenFields.length;
        String name = "";
        String value = "";
        PrintWriter out = getPrintWriter(os, locale);
        for(int i = 0; i < length; i++)
        {
            name = hiddenFields[i];
            if(getFormData() != null)
                value = getFormData().getProperty(name);
            if((value == null || value.length() == 0 || value.equals("")) && getQueryData() != null)
                value = getQueryData().getProperty(name);
            if(value != null)
                out.println("<INPUT TYPE=\"hidden\" name=\"" + name + "\" value=\"" + value + "\">");
        }

        out.flush();
    }

    public void getReorderList(Properties parameters, Locale locale, OutputStream os)
    {
        PrintWriter out;
        if(VERBOSE)
            System.out.println("DocumentAssociationSearchProcessor.getReorderList starting.");
        out = TemplateOutputStream.getPrintWriter(os, locale);
        WTDocument doc = (WTDocument)getContextObj();
        Enumeration result;
        Vector children;
        int size;
        String trail_id;
        WTDocumentMaster first_doc_master;
        String id_string;
        ReferenceFactory refFactory;
        String oid_string;
        String trail_option;
        int i;
        WTDocumentMaster doc_master;
        String id;
        String oid;
        try
        {
            result = WTDocumentHelper.service.getOrderedUsesWTDocumentMasters(doc);
            if(!result.hasMoreElements())
            {
                out.println(getResourceString("78", locale, "com.ptc.windchill.pdmlink.doc.server.processors.processorsResource", "78"));
                return;
            }
        }
        catch(WTException wte)
        {
            out.println(getResourceString("79", locale, "com.ptc.windchill.pdmlink.doc.server.processors.processorsResource", "79"));
            addExceptionToFooters(wte);
            return;
        }
        children = new Vector();
        for(; result.hasMoreElements(); children.addElement(result.nextElement()));
        size = children.size();
        trail_id = HtmlUtil.createTrlIdAttribute("PDML", "DocStructReorderList", "DropDown", "docmgmt_s1");
        out.println("<SELECT name=reorderList " + trail_id + " size=12>");
        first_doc_master = (WTDocumentMaster)children.get(0);
        id_string = IdentityFactory.getDisplayIdentifier(first_doc_master).getLocalizedMessage(locale);
        refFactory = new ReferenceFactory();
        oid_string = refFactory.getReferenceString(first_doc_master);
        trail_option = HtmlUtil.createTrlIdAttribute("PDML", "DocStructReorderList", "DropDownItem", "doc_position_0");
        out.println("<OPTION " + trail_option + " value=" + oid_string + " selected>" + HtmlUtil.encodeEscapeCharacters(id_string));
        for(i = 1; i < size; i++)
        {
            doc_master = (WTDocumentMaster)children.get(i);
            id = IdentityFactory.getDisplayIdentifier(doc_master).getLocalizedMessage(locale);
            oid = refFactory.getReferenceString(doc_master);
            trail_option = HtmlUtil.createTrlIdAttribute("PDML", "DocStructReorderList", "DropDownItem", "doc_position_" + i);
            out.println("<OPTION " + trail_option + " value=" + oid + ">" + HtmlUtil.encodeEscapeCharacters(id));
        }

        out.println("</SELECT>");
        out.flush();
        return;
    }

    public void getAddAndReorderList(Properties parameters, Locale locale, OutputStream os)
        throws WTException
    {
        if(VERBOSE)
            System.out.println("DocumentAssociationSearchProcessor.getAddAndReorderList starting.");
        PrintWriter out = TemplateOutputStream.getPrintWriter(os, locale);
        WTDocument doc = (WTDocument)getContextObj();
        Properties form_data = getFormData();
        String form_name = parameters.getProperty("formName");
        if(form_name == null || form_name.equals(""))
            form_name = form_data.getProperty("formName");
        if(form_name == null || form_name.equals(""))
            throw new WTException("com.ptc.windchill.pdmlink.doc.server.processors.processorsResource", "2", null);
        String doc_string = getFormData().getProperty("selectedDocs");
        if(doc_string == null)
            doc_string = getFormValueFromSession(form_name, "selectedDocs", "false");
        Vector selected_docs = null;
        if(doc_string == null || doc_string.length() <= 0)
            throw new WTException("com.ptc.windchill.pdmlink.doc.server.processors.processorsResource", "78", null);
        selected_docs = stringToVector(doc_string, DELIM);
        try
        {
            Enumeration result = WTDocumentHelper.service.getOrderedUsesWTDocumentMasters(doc);
            Vector children = new Vector();
            if(result.hasMoreElements())
                for(; result.hasMoreElements(); children.addElement(result.nextElement()));
            int size = children.size();
            String trail_select = HtmlUtil.createTrlIdAttribute("PDML", form_name + "_select", "DropDown", "docmgmt_s1");
            out.println("<SELECT " + trail_select + " name=reorderList size=12>");
            Vector masters = new Vector(size);
            ReferenceFactory refFactory = new ReferenceFactory();
            if(size > 0)
            {
                WTDocumentMaster first_doc_master = (WTDocumentMaster)children.get(0);
                String id_string = IdentityFactory.getDisplayIdentifier(first_doc_master).getLocalizedMessage(locale);
                masters.add(id_string);
                String oid_string = refFactory.getReferenceString(first_doc_master);
                String trail_option = HtmlUtil.createTrlIdAttribute("PDML", form_name, "DropDownItem", "doc_position_0");
                out.println("<OPTION " + trail_option + " value=" + oid_string + " selected>" + HtmlUtil.encodeEscapeCharacters(id_string));
                for(int i = 1; i < size; i++)
                {
                    WTDocumentMaster doc_master = (WTDocumentMaster)children.get(i);
                    String id = IdentityFactory.getDisplayIdentifier(doc_master).getLocalizedMessage(locale);
                    masters.add(id);
                    String oid = refFactory.getReferenceString(doc_master);
                    trail_option = HtmlUtil.createTrlIdAttribute("PDML", form_name, "DropDownItem", "doc_position_" + i);
                    out.println("<OPTION " + trail_option + " value=" + oid + ">" + HtmlUtil.encodeEscapeCharacters(id));
                }

            }
            int select_size = selected_docs.size();
            for(int i = 0; i < select_size; i++)
            {
                String oid = (String)selected_docs.elementAt(i);
                WTReference ref = refFactory.getReference(oid);
                WTDocumentMaster child_master = (WTDocumentMaster)ref.getObject();
                String id = IdentityFactory.getDisplayIdentifier(child_master).getLocalizedMessage(locale);
                String trail_option = HtmlUtil.createTrlIdAttribute("PDML", form_name, "DropDownItem", "doc_position_" + (i + size));
                if(masters.indexOf(id) == -1)
                {
                    out.println("<OPTION " + trail_option + " value=" + oid + ">" + HtmlUtil.encodeEscapeCharacters(id));
                    continue;
                }
                if(VERBOSE)
                    System.out.println("New document matches one already in this relationship." + id);
            }

            out.println("</SELECT>");
        }
        catch(WTException wte)
        {
            out.println(getResourceString("79", locale, "com.ptc.windchill.pdmlink.doc.server.processors.processorsResource", "79"));
            addExceptionToFooters(wte);
            return;
        }
        out.flush();
    }

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

    private Vector getValueList(PropertyDescriptor pd, Locale locale)
    {
        Vector vector = new Vector();
        Vector locale_values = new Vector();
        Vector trail_values = new Vector();
        Class type = pd.getPropertyType();
        if(type == WTBusinessInfo.BoolTYPE)
        {
            locale_values.addElement(WTMessage.getLocalizedMessage("wt.clients.beans.query.BeansQueryRB", "17", null, locale));
            locale_values.addElement(WTMessage.getLocalizedMessage("wt.clients.beans.query.BeansQueryRB", "16", null, locale));
            trail_values.addElement("true");
            trail_values.addElement("false");
        } else
        if(SearchTask.isEnumType(type))
        {
            EnumeratedType e[] = WTBusinessInfo.getAttributeValueSet(pd);
            if(e.length != 0)
            {
                for(int i = 0; i < e.length; i++)
                {
                    locale_values.addElement(e[i].getDisplay(locale));
                    trail_values.addElement(e[i].toString());
                }

            }
        }
        vector.addElement(locale_values);
        vector.addElement(trail_values);
        return vector;
    }

    private Vector getLegalValueList(String method_name)
        throws WTException
    {
        String method_path;
        String just_method;
        int i = method_name.lastIndexOf('.');
        method_path = method_name.substring(0, i);
        just_method = method_name.substring(i + 1);
        Vector vector;
        Method method_to_run = Class.forName(method_path).getMethod(just_method, null);
        vector = (Vector)method_to_run.invoke(null, null);
        return vector;
        InvocationTargetException ite;
        ite;
        throw new WTException(ite);
        IllegalAccessException iae;
        iae;
        throw new WTException(iae);
        NoSuchMethodException nsme;
        nsme;
        throw new WTException(nsme);
        ClassNotFoundException cnfe;
        cnfe;
        throw new WTException(cnfe);
    }

    protected void addExceptionToFooters(Exception e)
    {
        e.printStackTrace();
        Throwable nestedThrowable = null;
        if(e instanceof WTException)
            nestedThrowable = ((WTException)e).getNestedThrowable();
        else
        if(e instanceof WTPropertyVetoException)
            nestedThrowable = ((WTPropertyVetoException)e).getNestedThrowable();
        if(nestedThrowable != null)
        {
            if(nestedThrowable instanceof WTException)
                addToResponseFooters((WTException)nestedThrowable);
            else
            if(nestedThrowable instanceof WTPropertyVetoException)
                addToResponseFooters((WTPropertyVetoException)nestedThrowable);
            else
            if((e instanceof WTException) || (e instanceof WTPropertyVetoException))
                addToResponseFooters((LocalizableMessage)e);
        } else
        if((e instanceof WTException) || (e instanceof WTPropertyVetoException))
            addToResponseFooters((LocalizableMessage)e);
    }

    protected boolean notOtherFields(String name)
    {
        int length = otherFields.length;
        for(int i = 0; i < length; i++)
            if(name.equals(otherFields[i]))
                return false;

        return true;
    }

    protected boolean notHiddenFields(String name)
    {
        int length = hiddenFields.length;
        for(int i = 0; i < length; i++)
            if(name.equals(hiddenFields[i]))
                return false;

        return true;
    }

    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);
            String item;
            if(cur_pos == -1)
            {
                done = true;
                if(start_pos >= s.length())
                    continue;
                item = s.substring(start_pos);
                if(item != null && item.length() > 0)
                    strings.addElement(item);
                continue;
            }
            item = s.substring(start_pos, cur_pos);
            if(item != null && item.length() > 0)
                strings.addElement(item);
        }

        return strings;
    }

    protected Properties addQueryDataToFormData(Properties formData, Properties queryData)
    {
        String name = null;
        String value = null;
        if(formData == null)
            formData = new Properties();
        if(queryData != null && queryData.size() > 0)
        {
            Enumeration e = queryData.propertyNames();
            do
            {
                if(!e.hasMoreElements())
                    break;
                name = (String)e.nextElement();
                value = queryData.getProperty(name);
                if(!name.equals(name.toUpperCase()) && notOtherFields(name) && notHiddenFields(name))
                    formData.setProperty(name, value);
            } while(true);
        }
        return formData;
    }

    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 = 0x5c9ab67f442bc0d1L;
    protected static final long OLD_FORMAT_VERSION_UID = 0x173e79b4979d8e21L;
    protected SortedEnumeration results;
    protected String hiddenFields[] = {
        "linkclass", "collapse", "sortby"
    };
    protected String otherFields[] = {
        "query", "action", "submit", "oid"
    };
    private static final String FORMNAME = "formName";
    protected static boolean VERBOSE = false;
    protected static String DELIM;

    static 
    {
        CLASSNAME = (com.ptc.windchill.pdmlink.doc.server.processors.DocumentAssociationSearchProcessor.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)
        {
            System.err.println("com.ptc.windchill.pdmlink.doc.server.processors.DocumentAssociationSearchProcessor : Error reading com.ptc.windchill.pdmlink.doc.client.* properties");
            t.printStackTrace(System.err);
            throw new ExceptionInInitializerError(t);
        }
    }
}
