public static void setAttributes()

in java/src/org/apache/qetest/xslwrapper/TraxWrapperUtils.java [113:166]


    public static void setAttributes(Object setPropsOn, 
                                     Hashtable attrs)
                                     throws IllegalArgumentException
    {
        if ((null == setPropsOn) || (null == attrs))
            return;

        Enumeration attrKeys = null;
        try
        {
            // Attempt to use as a Properties block..
            attrKeys = ((Properties)attrs).propertyNames();
        }
        catch (ClassCastException cce)
        {
            // .. but fallback to get as Hashtable instead
            attrKeys = attrs.keys();
        }

        while (attrKeys.hasMoreElements())
        {
            String key = (String) attrKeys.nextElement();
            // Only attempt to set the attr if it matches our marker
            if ((null != key)
                && (key.startsWith(TransformWrapper.SET_PROCESSOR_ATTRIBUTES)))
            {
                Object value = null;
                try
                {
                    // Attempt to use as a Properties block..
                    value = ((Properties)attrs).getProperty(key);
                    // But, if null, then try getting as hash anyway
                    if (null == value)
                    {
                        value = attrs.get(key);
                    }
                }
                catch (ClassCastException cce)
                {
                    // .. but fallback to get as Hashtable instead
                    value = attrs.get(key);
                }
                // Strip off our marker for the property name
                String processorKey = key.substring(TransformWrapper.SET_PROCESSOR_ATTRIBUTES.length());
                // Ugly, but it works -sc
                if (setPropsOn instanceof TransformerFactory)
                    setAttribute((TransformerFactory)setPropsOn, processorKey, value);
                else if (setPropsOn instanceof Transformer)
                    setAttribute((Transformer)setPropsOn, processorKey, value);
                // else - ignore it, no-op    
            }
        }

    }