Logo Search packages:      
Sourcecode: libpodofo version File versions  Download package

PdfObject * PoDoFo::PdfNamesTree::GetKeyValue ( PdfObject pObj,
const PdfString key 
) const [private]

Recursively walk through the name tree and find the value for key.

Parameters:
pObjthe name tree
keythe key to find a value for
Returns:
the value for the key or NULL if it was not found

Definition at line 359 of file PdfNamesTree.cpp.

References PoDoFo::PdfArray::begin(), CheckLimits(), PoDoFo::eLogSeverity_Debug, PoDoFo::PdfArray::end(), PoDoFo::PdfVariant::GetArray(), PoDoFo::PdfVariant::GetDictionary(), PoDoFo::PdfDictionary::GetKey(), PoDoFo::PdfVecObjects::GetObject(), PoDoFo::PdfElement::GetObject(), PoDoFo::PdfObject::GetOwner(), PoDoFo::PdfDictionary::HasKey(), and PoDoFo::PdfError::LogMessage().

Referenced by GetValue().

{
    if( PdfNamesTree::CheckLimits( pObj, key ) != ePdfNameLimits_Inside )
        return NULL;

    if( pObj->GetDictionary().HasKey("Kids") )
    {
        const PdfArray & kids       = pObj->GetDictionary().GetKey("Kids")->GetArray();
        PdfArray::const_iterator it = kids.begin();

        while( it != kids.end() )
        {
            PdfObject* pChild = this->GetObject()->GetOwner()->GetObject( (*it).GetReference() );
            if( pChild ) 
            {
                PdfObject* pResult = GetKeyValue( pChild, key );
                if( pResult ) // If recursive call returns NULL, 
                              // continue with the next element
                              // in the kids array.
                    return pResult;
            }
            else
                PdfError::LogMessage( eLogSeverity_Debug, "Object %lu %lu is child of nametree but was not found!", 
                                      (*it).GetReference().ObjectNumber(), 
                                      (*it).GetReference().GenerationNumber() );

            ++it;
        }
    }
    else
    {
        const PdfArray & names      = pObj->GetDictionary().GetKey("Names")->GetArray();
        PdfArray::const_iterator it = names.begin();

        // a names array is a set of PdfString/PdfObject pairs
        // so we loop in sets of two - getting each pair
        while( it != names.end() ) 
        {
            if( (*it).GetString() == key ) 
            {
                ++it;
                return this->GetObject()->GetOwner()->GetObject( (*it).GetReference() );
            }

            it += 2;
        }
        
    }

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index