private Object toTreeObject()

in debugger/src/main/java/org/apache/pdfbox/debugger/ui/PDFTreeCellRenderer.java [87:191]


    private Object toTreeObject(Object nodeValue)
    {
        Object result = nodeValue;
        if (nodeValue instanceof MapEntry || nodeValue instanceof ArrayEntry)
        {
            String key;
            Object object;
            Object value;
            COSBase item;
            if (nodeValue instanceof MapEntry)
            {
                MapEntry entry = (MapEntry) nodeValue;
                key = entry.getKey().getName();
                object = toTreeObject(entry.getValue());
                value = entry.getValue();
                item = entry.getItem();
            }
            else
            {
                ArrayEntry entry = (ArrayEntry) nodeValue;
                key = Integer.toString(entry.getIndex());
                object = toTreeObject(entry.getValue());
                value = entry.getValue();
                item = entry.getItem();
            }
            
            String stringResult = key;
            if (object instanceof String && !((String) object).isEmpty())
            {
                stringResult += ":  " + object;
                if (item instanceof COSObject)
                {
                    COSObject indirect = (COSObject)item;
                    stringResult += " [" + indirect.getKey() + "]";
                }
                stringResult += toTreePostfix(value);
                
            }
            result = stringResult;
        }
        else if (nodeValue instanceof COSBoolean)
        {
            result = Boolean.toString(((COSBoolean) nodeValue).getValue());
        }
        else if (nodeValue instanceof COSFloat)
        {
            result = Float.toString(((COSFloat) nodeValue).floatValue());
        }
        else if (nodeValue instanceof COSInteger)
        {
            result = Long.toString(((COSInteger) nodeValue).longValue());
        }
        else if (nodeValue instanceof COSString)
        {
            String text = ((COSString) nodeValue).getString();
            // display unprintable strings as hex
            for (char c : text.toCharArray())
            {
                if (Character.isISOControl(c))
                {
                    text = "<" + ((COSString) nodeValue).toHexString() + ">";
                    break;
                }
            }
            result = text;
        }
        else if (nodeValue instanceof COSName)
        {
            result = ((COSName) nodeValue).getName();
        }
        else if (nodeValue instanceof COSNull || nodeValue == null)
        {
            result = "";
        }
        else if (nodeValue instanceof COSDictionary)
        {
            COSDictionary dict = (COSDictionary) nodeValue;
            if (COSName.XREF.equals(dict.getCOSName(COSName.TYPE)))
            {
                result = "";
            }
            else
            {
                result = "(" + dict.size() + ")";
            }
        }
        else if (nodeValue instanceof COSArray)
        {
            COSArray array = (COSArray) nodeValue;
            result = "(" + array.size() + ")";
        }
        else if (nodeValue instanceof DocumentEntry)
        {
            result = nodeValue.toString();
        }
        else if (nodeValue instanceof XrefEntries)
        {
            result = nodeValue.toString();
        }
        else if (nodeValue instanceof XrefEntry)
        {
            result = nodeValue.toString();
        }
        return result;
    }