Returns the container for the currently selected Principal group.<p>

@param type to be shown
@param realOnly true->get only real principals
@param ou ou
@return indexed container
@throws CmsException exception
544295
private IndexedContainer getContainerForType(WidgetType type, boolean realOnly, String ou) throws CmsException {

        IndexedContainer res = null;
        List<FontIcon> icon = new ArrayList<FontIcon>();
        if (!OpenCms.getRoleManager().hasRole(m_cms, CmsRole.ACCOUNT_MANAGER)) {
            List<CmsGroup> groups = OpenCms.getOrgUnitManager().getGroups(
                m_cms,
                m_cms.getRequestContext().getOuFqn(),
                false);
            return CmsVaadinUtils.getPrincipalContainer(
                A_CmsUI.getCmsObject(),
                groups,
                ID_CAPTION,
                ID_DESC,
                ID_ICON,
                ID_OU,
                OpenCmsTheme.ICON_GROUP,
                icon);
        }

        if (type.equals(WidgetType.groupwidget) | type.equals(WidgetType.principalwidget)) {
            List<CmsGroup> groups = OpenCms.getRoleManager().getManageableGroups(m_cms, ou, false);
            if (!realOnly) {
                groups.add(
                    0,
                    new CmsGroup(
                        CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID,
                        null,
                        CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_LABEL_ALLOTHERS_0),
                        CmsVaadinUtils.getMessageText(
                            org.opencms.workplace.commons.Messages.GUI_DESCRIPTION_ALLOTHERS_0),
                        0));
                icon.add(new CmsCssIcon(OpenCmsTheme.ICON_PRINCIPAL_ALL));
                if (OpenCms.getRoleManager().hasRole(m_cms, CmsRole.VFS_MANAGER)) {
                    groups.add(
                        0,
                        new CmsGroup(
                            CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID,
                            null,
                            CmsVaadinUtils.getMessageText(
                                org.opencms.workplace.commons.Messages.GUI_LABEL_OVERWRITEALL_0),
                            CmsVaadinUtils.getMessageText(
                                org.opencms.workplace.commons.Messages.GUI_DESCRIPTION_OVERWRITEALL_0),
                            0));
                    icon.add(0, new CmsCssIcon(OpenCmsTheme.ICON_PRINCIPAL_OVERWRITE));
                }
            }

            res = CmsVaadinUtils.getPrincipalContainer(
                A_CmsUI.getCmsObject(),
                groups,
                ID_CAPTION,
                ID_DESC,
                ID_ICON,
                ID_OU,
                OpenCmsTheme.ICON_GROUP,
                icon);
        }
        if (type.equals(WidgetType.userwidget)) {
            List<CmsUser> users = OpenCms.getRoleManager().getManageableUsers(m_cms, ou, false, true);
            if (!realOnly) {
                CmsUser user = new CmsUser(
                    CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID,
                    CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_LABEL_ALLOTHERS_0),
                    "",
                    "",
                    "",
                    "",
                    0,
                    0,
                    0,
                    null);
                user.setDescription(
                    CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_DESCRIPTION_ALLOTHERS_0));
                users.add(0, user);
                icon.add(new CmsCssIcon(OpenCmsTheme.ICON_PRINCIPAL_ALL));
                if (OpenCms.getRoleManager().hasRole(m_cms, CmsRole.VFS_MANAGER)) {
                    user = new CmsUser(
                        CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID,
                        CmsVaadinUtils.getMessageText(org.opencms.workplace.commons.Messages.GUI_LABEL_OVERWRITEALL_0),
                        "",
                        "",
                        "",
                        "",
                        0,
                        0,
                        0,
                        null);
                    user.setDescription(
                        CmsVaadinUtils.getMessageText(
                            org.opencms.workplace.commons.Messages.GUI_DESCRIPTION_OVERWRITEALL_0));
                    users.add(0, user);
                    icon.add(0, new CmsCssIcon(OpenCmsTheme.ICON_PRINCIPAL_OVERWRITE));
                }
            }
            res = CmsVaadinUtils.getPrincipalContainer(
                A_CmsUI.getCmsObject(),
                users,
                ID_CAPTION,
                ID_DESC,
                ID_ICON,
                ID_OU,
                OpenCmsTheme.ICON_USER,
                icon);
        }

        return res;
    }
398785
@SuppressWarnings("deprecation")
    public static int getContainerPageTypeId() throws CmsLoaderException {

        if (containerPageTypeId == 0) {
            I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(getStaticTypeName());
            if (resType != null) {
                containerPageTypeId = resType.getTypeId();
            }
        }
        return containerPageTypeId;
    }
912546
public ContainerPointer getContainerPointer(final int startIndex) {
    return new ContainerPointer() {
      int k = startIndex;

      @Override
      public void advance() {
        ++k;

      }

      @Override
      public ContainerPointer clone() {
        try {
          return (ContainerPointer) super.clone();
        } catch (CloneNotSupportedException e) {
          return null;// will not happen
        }
      }

      @Override
      public int compareTo(ContainerPointer o) {
        if (key() != o.key()) {
          return Util.toIntUnsigned(key()) - Util.toIntUnsigned(o.key());
        }
        return o.getCardinality() - getCardinality();
      }

      @Override
      public int getCardinality() {
        return getContainer().getCardinality();
      }

      @Override
      public Container getContainer() {
        if (k >= RoaringArray.this.size) {
          return null;
        }
        return RoaringArray.this.values[k];
      }


      @Override
      public boolean isBitmapContainer() {
        return getContainer() instanceof BitmapContainer;
      }

      @Override
      public boolean isRunContainer() {
        return getContainer() instanceof RunContainer;
      }


      @Override
      public short key() {
        return RoaringArray.this.keys[k];

      }
    };
  }
190811
private RetrieveResult containerViewByType(final ManagedObjectReference container,
                                               final String morefType,
                                               final RetrieveOptions retrieveOptions
    ) throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
        return this.containerViewByType(container, morefType, retrieveOptions, ManagedObjectType.NAME.getValue());
    }
1204236
protected boolean isRootContainer(CmsContainer container) {

        boolean isRoot = false;
        if (!container.isSubContainer()) {
            isRoot = true;
        } else if (container.isDetailOnly()) {
            CmsContainer parent = getContainer(container.getParentContainerName());
            isRoot = (parent != null) && !parent.isDetailOnly();
        }
        return isRoot;
    }
115572
private List<CmsContainerElementBean> getGroupContainerElements(CmsResource resource) throws CmsException {

        CmsXmlGroupContainer xmlGroupContainer = CmsXmlGroupContainerFactory.unmarshal(
            getCmsObject(),
            resource,
            getRequest());
        CmsGroupContainerBean groupContainer = xmlGroupContainer.getGroupContainer(getCmsObject());
        return groupContainer.getElements();
    }
570377
public CmsAccessControlEntry toAccessControlEntry(CmsObject cms, CmsUUID resID) {

        CmsUUID id = null;
        if (isRealPrinciple()) {
            if (CmsRole.PRINCIPAL_ROLE.equals(m_principalType)) {
                CmsRole role = CmsRole.valueOfRoleName(m_principalName);
                if (role != null) {
                    id = role.getId();
                }
            } else {
                try {
                    id = CmsPrincipal.readPrincipal(cms, m_principalName).getId();
                } catch (CmsException e) {
                    //
                }
            }
        } else {
            if (m_principalName.equals(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME)) {
                id = CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID;
            }
            if (m_principalName.equals(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME)) {
                id = CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID;
            }
        }

        if (m_permissionString == null) {
            return new CmsAccessControlEntry(resID, id, m_allowed, m_denied, m_flags);
        }
        CmsAccessControlEntry entry = new CmsAccessControlEntry(resID, id, m_permissionString);
        return entry;
    }
107404
protected List<CmsOrganizationalUnit> getOrgUnits() throws CmsException {

        if (m_ous == null) {
            m_ous = OpenCms.getRoleManager().getOrgUnitsForRole(getCms(), CmsRole.ACCOUNT_MANAGER.forOrgUnit(""), true);
        }
        return m_ous;
    }
170547
public Format getFormatForContainer(CmsObject cms, String type, int width) {

        IdentityHashMap<CmsFormatterBean, Format> formatsByFormatter = new IdentityHashMap<CmsFormatterBean, Format>();
        // relate formatters to formats so we can pick the corresponding format after a formatter has been selected
        CmsFormatterBean mainFormatter = createFormatterBean(m_mainFormat, true);
        formatsByFormatter.put(mainFormatter, m_mainFormat);
        List<I_CmsFormatterBean> formatters = new ArrayList<I_CmsFormatterBean>();
        for (Format format : m_otherFormats) {
            CmsFormatterBean formatter = createFormatterBean(format, false);
            formatsByFormatter.put(formatter, format);
            formatters.add(formatter);
        }
        formatters.add(0, mainFormatter);
        CmsFormatterConfiguration formatterConfiguration = CmsFormatterConfiguration.create(cms, formatters);
        I_CmsFormatterBean matchingFormatter = formatterConfiguration.getDefaultFormatter(type, width);
        if (matchingFormatter == null) {
            return null;
        }
        return formatsByFormatter.get(matchingFormatter);
    }
1246842
public void createAccessControlList(String resourceType) throws CmsException {

        if (OpenCms.getRunLevel() < OpenCms.RUNLEVEL_2_INITIALIZING) {
            // we don't need this for simple test cases
            return;
        }
        if (m_permissionsCache == null) {
            m_permissionsCache = CmsMemoryMonitor.createLRUCacheMap(2048);
            OpenCms.getMemoryMonitor().register(this.getClass().getName() + "." + resourceType, m_permissionsCache);
        } else {
            m_permissionsCache.clear();
        }

        m_accessControlList = new CmsAccessControlList();
        Iterator<String> i = m_accessControl.keySet().iterator();
        while (i.hasNext()) {
            String key = i.next();
            if (!PRINCIPAL_DEFAULT.equals(key)) {
                String value = m_accessControl.get(key);
                // get the principal name from the principal String
                String principal = key.substring(key.indexOf('.') + 1, key.length());

                // create an OpenCms user context with "Guest" permissions
                CmsObject cms = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest());

                CmsUUID principalId = null;
                if (key.startsWith(I_CmsPrincipal.PRINCIPAL_GROUP)) {
                    // read the group
                    principal = OpenCms.getImportExportManager().translateGroup(principal);
                    try {
                        principalId = cms.readGroup(principal).getId();
                    } catch (CmsException e) {
                        if (LOG.isErrorEnabled()) {
                            LOG.error(e.getLocalizedMessage(), e);
                        }
                    }
                } else if (key.startsWith(I_CmsPrincipal.PRINCIPAL_USER)) {
                    // read the user
                    principal = OpenCms.getImportExportManager().translateUser(principal);
                    try {
                        principalId = cms.readUser(principal).getId();
                    } catch (CmsException e) {
                        if (LOG.isErrorEnabled()) {
                            LOG.error(e.getLocalizedMessage(), e);
                        }
                    }
                } else {
                    // read the role with role name
                    CmsRole role = CmsRole.valueOfRoleName(principal);
                    if (role == null) {
                        // try to read the role in the old fashion with group name
                        role = CmsRole.valueOfGroupName(principal);
                    }
                    principalId = role.getId();
                }
                if (principalId != null) {
                    // create a new entry for the principal
                    CmsAccessControlEntry entry = new CmsAccessControlEntry(null, principalId, value);
                    m_accessControlList.add(entry);
                }
            }
        }
    }
869015
public void update(String ou, I_CmsOuTreeType type, CmsUUID roleOrGroupID, String filter) {

        CmsStateBean stateBean = new CmsStateBean(ou, type, roleOrGroupID, filter);
        openSubView(stateBean.getState(), true);

    }
713079
public Map<?, ?> getByType() {

        if (m_byType == null) {
            m_byType = CmsCollectionsGenericWrapper.createLazyMap(new Transformer() {

                @SuppressWarnings("synthetic-access")
                public Object transform(Object arg0) {

                    String key = (String)arg0;
                    List<CmsContainerElementBean> result = Lists.newArrayList();
                    for (Map.Entry<String, CmsContainerBean> entry : getPage().getContainers().entrySet()) {
                        CmsContainerBean value = entry.getValue();
                        for (CmsContainerElementBean element : value.getElements()) {
                            try {
                                element.initResource(m_cms);
                                if (key.equals(element.getTypeName())) {
                                    result.add(element);
                                }
                            } catch (CmsException e) {
                                LOG.error(
                                    "Could not initialize resource with site path \""
                                        + element.getSitePath()
                                        + "\" to determine the container elements type.",
                                    e);
                            }
                        }
                    }
                    return result;
                }
            });
        }
        return m_byType;
    }
1159560
private EntityContainer getEntityContainer() throws ODataRenderException {
        EntityContainer entityContainer = entityDataModel.getEntityContainer();
        if (entityContainer == null) {
            String message = "EntityContainer should not be null";
            LOG.error(message);
            throw new ODataRenderException(message);
        }
        return entityContainer;
    }
135846
public CmsHistoryResourceCollection getResourceHistoryInternal(CmsUUID structureId) throws CmsException {

        CmsHistoryResourceCollection result = new CmsHistoryResourceCollection();
        CmsObject cms = getCmsObject();
        CmsResource resource = cms.readResource(structureId, CmsResourceFilter.ALL);
        List<I_CmsHistoryResource> versions = cms.readAllAvailableVersions(resource);
        if (!resource.getState().isUnchanged()) {
            result.add(createHistoryResourceBean(cms, resource, true, -1));
        }
        int maxVersion = 0;

        if (versions.isEmpty()) {
            try {
                CmsProject online = cms.readProject(CmsProject.ONLINE_PROJECT_ID);
                CmsObject onlineCms = OpenCms.initCmsObject(cms);
                onlineCms.getRequestContext().setCurrentProject(online);
                CmsResource onlineResource = onlineCms.readResource(structureId, CmsResourceFilter.ALL);
                CmsHistoryResourceBean onlineResBean = createHistoryResourceBean(onlineCms, onlineResource, false, 0);
                result.add(onlineResBean);
            } catch (CmsVfsResourceNotFoundException e) {
                LOG.info(e.getLocalizedMessage(), e);
            } catch (Exception e) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        } else {
            for (I_CmsHistoryResource historyRes : versions) {
                maxVersion = Math.max(maxVersion, historyRes.getVersion());
            }
            for (I_CmsHistoryResource historyRes : versions) {
                CmsHistoryResourceBean historyBean = createHistoryResourceBean(
                    cms,
                    (CmsResource)historyRes,
                    false,
                    maxVersion);
                result.add(historyBean);
            }
        }
        return result;
    }
1122540
protected Map<String, String> getFolderTypes() throws CmsException {

        Map<String, String> result = new HashMap<String, String>();
        CmsObject cms = OpenCms.initCmsObject(getCms());
        if (m_data.isModuleConfig()) {
            Set<String> siteRoots = OpenCms.getSiteManager().getSiteRoots();
            for (String siteRoot : siteRoots) {
                cms.getRequestContext().setSiteRoot(siteRoot);
                for (CmsResourceTypeConfig config : getResourceTypes()) {
                    if (!config.isDetailPagesDisabled()) {
                        String typeName = config.getTypeName();
                        if (!config.isPageRelative()) { // elements stored with container pages can not be used as detail contents
                            String folderPath = config.getFolderPath(cms, null);
                            result.put(CmsStringUtil.joinPaths(folderPath, "/"), typeName);
                        }
                    }
                }
            }
        } else {
            for (CmsResourceTypeConfig config : getResourceTypes()) {
                if (!config.isDetailPagesDisabled()) {
                    String typeName = config.getTypeName();
                    if (!config.isPageRelative()) { // elements stored with container pages can not be used as detail contents
                        String folderPath = config.getFolderPath(getCms(), null);
                        result.put(CmsStringUtil.joinPaths(folderPath, "/"), typeName);
                    }
                }
            }
        }
        return result;
    }
848535
public List<CmsDetailPageInfo> getInfosForType(String type) {

        return new ArrayList<CmsDetailPageInfo>(m_map.get(type));
    }
166074
public static EntityContainer getRootContainer(final EntityContainer container) {
	Objects.requireNonNull(container);

	if (container instanceof Entity) {
	    final EntityContainer parent = ((Entity) container).getContainer();
	    if (parent != null) {
		return getRootContainer(parent);
	    }
	}
	return container;
    }