code: public void setMainDocument(CmsDocumentDependency mainDocument) {
  
          if (m_mainDocument == null) {
              // we currently have no main document at all
              m_mainDocument = mainDocument;
          } else {
              // check if we find a better match for the main document locale
              if (mainDocument.getLocale().equals(getLocale())) {
                  // mainDocument.addVariant(m_mainDocument);
                  // main document locale is the "best" one
                  m_mainDocument = mainDocument;
              } else {
                  // check if the new document is a "better" one
                  List<Locale> locales = OpenCms.getLocaleManager().getDefaultLocales();
                  int pos1 = locales.indexOf(m_mainDocument.getLocale());
                  if (pos1 > 0) {
                      int pos2 = locales.indexOf(mainDocument.getLocale());
                      if (pos2 < pos1) {
                          mainDocument.addVariant(m_mainDocument);
                          // locale is closer to the default
                          m_mainDocument = mainDocument;
                      }
                  } else {
                      m_mainDocument.addVariant(mainDocument);
                  }
              }
          }
      }
docs: Sets the main document in case this document is an attachment.<p>
  
  @param mainDocument the main document to set