code: public T preloadData(CmsObject cms, Set<CmsResource> openResources, Set<CmsResource> selectedResources)
      throws CmsException {
  
          assert m_cms == null : "Instance can't be used more than once!";
          if (openResources == null) {
              openResources = Sets.newHashSet();
          }
          if (selectedResources == null) {
              selectedResources = Sets.newHashSet();
          }
  
          boolean ignoreOpen = false;
          if (!selectedResources.isEmpty() && !openResources.isEmpty()) {
              // if selected and opened resources are in different sites,
              // we do *not* want to start from the common root folder (usually '/'),
              // so ignore the 'open' resources.
              String siteForSelected = getCommonSite(selectedResources);
              String siteForOpen = getCommonSite(openResources);
              if (!Objects.equal(siteForSelected, siteForOpen)) {
                  ignoreOpen = true;
              }
          }
  
          Set<CmsResource> allParamResources = Sets.newHashSet();
          if (!ignoreOpen) {
              allParamResources.addAll(openResources);
          }
          allParamResources.addAll(selectedResources);
          m_cms = OpenCms.initCmsObject(cms);
          m_cms.getRequestContext().setSiteRoot("");
          // first determine the common root of all open resources
          findRoot(allParamResources);
  
          m_mustLoadChildren.add(m_rootResource);
          m_mustLoadChildren.addAll(openResources);
          // now load ancestors of all open resources
          for (CmsResource resource : allParamResources) {
              loadAncestors(resource);
          }
          // ensure that all children of ancestors of open resources are loaded
          loadChildren();
          // finally create the beans for the loaded resources
          return createBeans();
      }
docs: Creates the preload data for a collection of resources which correspond to "opened" tree items.<p>
  
  @param cms the CMS context to use
  @param openResources the resources which correspond to opened tree items
  @param selectedResources resources which should be part of the tree, but not opened
  
  @return the root tree entry bean which was created
  
  @throws CmsException if something goes wrong