How can I find out if a PDF document is a PDF Collection (a.k.a. PDF Package)?

Q: I would like to detect is a PDF document is a PDF Collection
(a.k.a. PDF Package) so that we can popup a warning to our users. At
this point, we don't necessarily need to open the PDF package files,
just to detect them. Could you point me to any relevant sample code?
----
A: You could use the following line to detect is a PDF document
contains a portable collection (i.e.PDF package)

Obj collection = doc.GetRoot().FindObj("Collection");
if (collection != NULL) {
   // This PDF contains a collection.
}

When a PDF viewer first opens a PDF document containing a collection,
it should display the contents of the initial document, along with a
list of the documents present in the "EmbeddedFiles" name tree.

#include <SDF/NameTree.h>
#include <Filters/FilterReader.h>

...

// C++ Pseudocode to traverse the list of embedded files

pdftron::SDF::NameTree files = NameTree::Find(*doc.GetSDFDoc(),
"EmbeddedFiles");
if(files.IsValid()) { // Traverse the list of embedded files.
  for (DictIterator i = files.GetIterator(); i.HasNext(); i.Next()) {
    UString entry_name;
    i.Key().GetAsPDFText(entry_name);

    if (extract_emebdded_files) {
      FileSpec file_spec(i.Value());
      AutoPtr<Filter> stm = file_spec.GetFileData();
      if (stm.get()) {
        FilterReader reader(*stm);
        Reader.Read(...);
      }
    }
  }
}

You can also access content of 'Collection' dictionary to find more
info about the embedded files in the collection.