Returns the context menu entries for the given URI.<p>

@param cms the cms context
@param structureId the currently requested structure id
@param context the ade context (sitemap or containerpage)

@return the context menu entries
166069
public static List<CmsContextMenuEntryBean> getContextMenuEntries(
        final CmsObject cms,
        CmsUUID structureId,
        final AdeContext context) {

        Map<String, CmsContextMenuEntryBean> entries = new LinkedHashMap<String, CmsContextMenuEntryBean>();
        try {
            final List<CmsResource> resources;
            CmsResource resource = cms.readResource(structureId, CmsResourceFilter.ONLY_VISIBLE_NO_DELETED);
            // in case of sitemap editor check visibility with empty list
            if (context.equals(AdeContext.sitemapeditor)) {
                resources = Collections.emptyList();
            } else {
                resources = Collections.singletonList(resource);
            }
            Locale locale = OpenCms.getWorkplaceManager().getWorkplaceLocale(cms);
            // context to check item visibility
            I_CmsDialogContext dcontext = new I_CmsDialogContextWithAdeContext() {

                public void error(Throwable error) {
                    // not supported
                }

                public void finish(CmsProject project, String siteRoot) {
                    // not supported
                }

                public void finish(Collection<CmsUUID> result) {
                    // not supported
                }

                public void focus(CmsUUID id) {
                    // not supported
                }

                public AdeContext getAdeContext() {

                    return context;
                }

                public List<CmsUUID> getAllStructureIdsInView() {

                    return null;
                }

                public String getAppId() {

                    return context.name();
                }

                public CmsObject getCms() {

                    return cms;
                }

                public ContextType getContextType() {

                    ContextType type;
                    switch (context) {
                        case pageeditor:
                        case editprovider:
                            type = ContextType.containerpageToolbar;
                            break;
                        case sitemapeditor:
                            type = ContextType.sitemapToolbar;
                            break;
                        default:
                            type = ContextType.fileTable;
                    }
                    return type;
                }

                public List<CmsResource> getResources() {

                    return resources;
                }

                public void navigateTo(String appId) {
                    // not supported
                }

                public void onViewChange() {
                    // not supported
                }

                public void reload() {
                    // not supported
                }

                public void setWindow(Window window) {
                    // not supported
                }

                public void start(String title, Component dialog) {
                    // not supported
                }

                public void start(String title, Component dialog, DialogWidth width) {
                    // not supported
                }

                public void updateUserInfo() {
                    // not supported
                }
            };
            Map<String, List<CmsContextMenuEntryBean>> submenus = new HashMap<String, List<CmsContextMenuEntryBean>>();
            List<I_CmsContextMenuItem> items = new ArrayList<I_CmsContextMenuItem>(
                OpenCms.getWorkplaceAppManager().getMenuItemProvider().getMenuItems());
            Collections.sort(items, new Comparator<I_CmsContextMenuItem>() {

                public int compare(I_CmsContextMenuItem arg0, I_CmsContextMenuItem arg1) {

                    return Float.compare(arg0.getOrder(), arg1.getOrder());
                }
            });

            for (I_CmsContextMenuItem item : items) {

                if (!item.isLeafItem()) {
                    CmsMenuItemVisibilityMode visibility = item.getVisibility(dcontext);
                    if (!visibility.isInVisible()) {
                        entries.put(
                            item.getId(),
                            new CmsContextMenuEntryBean(
                                visibility.isActive(),
                                true,
                                null,
                                item.getTitle(locale),
                                null,
                                CmsStringUtil.isEmptyOrWhitespaceOnly(visibility.getMessageKey())
                                ? null
                                : OpenCms.getWorkplaceManager().getMessages(locale).getString(
                                    visibility.getMessageKey()),
                                false,
                                new ArrayList<CmsContextMenuEntryBean>()));
                    }
                } else if ((item instanceof I_CmsADEAction) && ((I_CmsADEAction)item).isAdeSupported()) {
                    CmsMenuItemVisibilityMode visibility = item.getVisibility(dcontext);
                    if (!visibility.isInVisible()) {
                        String jspPath = ((I_CmsADEAction)item).getJspPath();
                        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(jspPath)) {
                            jspPath = OpenCms.getLinkManager().substituteLink(cms, jspPath);
                        }
                        CmsContextMenuEntryBean itemBean = new CmsContextMenuEntryBean(
                            visibility.isActive(),
                            true,
                            jspPath,
                            item.getTitle(locale),
                            ((I_CmsADEAction)item).getCommandClassName(),
                            CmsStringUtil.isEmptyOrWhitespaceOnly(visibility.getMessageKey())
                            ? null
                            : OpenCms.getWorkplaceManager().getMessages(locale).getString(visibility.getMessageKey()),
                            false,
                            null);
                        Map<String, String> params = ((I_CmsADEAction)item).getParams();
                        if (params != null) {
                            params = new HashMap<String, String>(params);
                            for (Entry<String, String> param : params.entrySet()) {
                                String value = CmsVfsService.prepareFileNameForEditor(cms, resource, param.getValue());
                                param.setValue(value);
                            }
                            itemBean.setParams(params);
                        }
                        entries.put(item.getId(), itemBean);
                        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(item.getParentId())) {
                            List<CmsContextMenuEntryBean> submenu;
                            if (submenus.containsKey(item.getParentId())) {
                                submenu = submenus.get(item.getParentId());
                            } else {
                                submenu = new ArrayList<CmsContextMenuEntryBean>();
                                submenus.put(item.getParentId(), submenu);
                            }
                            submenu.add(itemBean);
                        }
                    }
                }
            }
            List<CmsContextMenuEntryBean> result = new ArrayList<CmsContextMenuEntryBean>();
            for (I_CmsContextMenuItem item : items) {
                if (entries.containsKey(item.getId())) {
                    if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(item.getParentId())) {
                        if (entries.containsKey(item.getParentId())) {
                            CmsContextMenuEntryBean parent = entries.get(item.getParentId());
                            if (parent.getSubMenu() != null) {
                                parent.getSubMenu().add(entries.get(item.getId()));
                            }
                        }
                    } else {
                        result.add(entries.get(item.getId()));
                    }
                }
            }
            return result;
        } catch (CmsException e) {
            // ignore, the user probably has not enough permissions to read the resource
            LOG.debug(e.getLocalizedMessage(), e);
        }
        return Collections.emptyList();
    }
128249
public static I_CmsContextMenuCommand getContextMenuCommand() {

        return new I_CmsContextMenuCommand() {

            public void execute(
                CmsUUID structureId,
                final I_CmsContextMenuHandler handler,
                CmsContextMenuEntryBean bean) {

                CmsConfirmDialog dialog = new CmsConfirmDialog(
                    Messages.get().key(Messages.GUI_DIALOG_LOGOUT_TITLE_0),
                    Messages.get().key(Messages.GUI_DIALOG_LOGOUT_TEXT_0));
                dialog.setOkText(Messages.get().key(Messages.GUI_YES_0));
                dialog.setCloseText(Messages.get().key(Messages.GUI_NO_0));
                dialog.setHandler(new I_CmsConfirmDialogHandler() {

                    public void onClose() {

                        // nothing to do
                    }

                    public void onOk() {

                        String logoutTarget = CmsCoreProvider.get().link(CmsCoreProvider.get().getLoginURL())
                            + "?logout=true";
                        handler.leavePage(logoutTarget);
                    }
                });
                dialog.center();
            }

            public A_CmsContextMenuItem getItemWidget(
                CmsUUID structureId,
                I_CmsContextMenuHandler handler,
                CmsContextMenuEntryBean bean) {

                return null;
            }

            public boolean hasItemWidget() {

                return false;
            }
        };
    }
1225713
public void doEdit(final String filename, final CmsUUID structureId) {

        I_CmsEditableData editData = new I_CmsEditableData() {

            public String getContextId() {

                return "";
            }

            public String getEditId() {

                return null;
            }

            public String getElementId() {

                // TODO Auto-generated method stub
                return null;
            }

            public String getElementLanguage() {

                return null;
            }

            public String getElementName() {

                return null;
            }

            public String getNewLink() {

                return null;
            }

            public String getNewTitle() {

                return null;
            }

            public String getNoEditReason() {

                return null;
            }

            public String getPostCreateHandler() {

                return null;
            }

            public String getSitePath() {

                return filename;
            }

            public CmsUUID getStructureId() {

                return structureId;
            }

            public boolean hasEditHandler() {

                return false;
            }

            public boolean hasResource() {

                return true;
            }

            public boolean isUnreleasedOrExpired() {

                return false;
            }

            public void setSitePath(String sitePath) {

                // nothing to do
            }
        };
        if (m_useSelf) {
            FormElement form = CmsContentEditorDialog.generateForm(editData, false, "_self", null);
            RootPanel.getBodyElement().appendChild(form);
            form.submit();
        } else {

            I_CmsContentEditorHandler handler = new I_CmsContentEditorHandler() {

                @SuppressWarnings("synthetic-access")
                public void onClose(String sitePath, CmsUUID id, boolean isNew, boolean hasChangedSettings) {

                    if (!m_reload) {
                        return;
                    }

                    if (m_immediateReload) {
                        reloadTop();
                    }

                    // defer the window.location.reload until after the editor window has closed
                    // so we don't get another confirmation dialog
                    Timer timer = new Timer() {

                        @Override
                        public void run() {

                            reloadTop();

                        }

                    };
                    timer.schedule(10);
                }
            };
            CmsContentEditorDialog.get().openEditDialog(editData, false, null, new DialogOptions(), handler);
        }
    }
59398
public void createSubEntry(final CmsClientSitemapEntry parent, final CmsUUID structureId) {

        CmsSitemapTreeItem item = CmsSitemapTreeItem.getItemById(parent.getId());
        AsyncCallback<CmsClientSitemapEntry> callback = new AsyncCallback<CmsClientSitemapEntry>() {

            public void onFailure(Throwable caught) {

                // nothing to do
            }

            public void onSuccess(CmsClientSitemapEntry result) {

                makeNewEntry(parent, new I_CmsSimpleCallback<CmsClientSitemapEntry>() {

                    public void execute(CmsClientSitemapEntry newEntry) {

                        createSubEntry(newEntry, parent.getId(), structureId);
                    }
                });

            }

        };

        if (item.getLoadState().equals(LoadState.UNLOADED)) {
            getChildren(parent.getId(), true, callback);
        } else {
            callback.onSuccess(parent);
        }
    }
266251
public CmsUrlNameMappingFilter filterStructureId(CmsUUID structureId) {

        if (structureId == null) {
            throw new IllegalArgumentException();
        }
        CmsUrlNameMappingFilter result = new CmsUrlNameMappingFilter(this);
        result.m_structureId = structureId;
        return result;
    }
1207411
public static void loadDialog(final CmsUUID structureId, final I_CmsHistoryActionHandler handler) {

        CmsRpcAction<CmsHistoryResourceCollection> action = new CmsRpcAction<CmsHistoryResourceCollection>() {

            @Override
            public void execute() {

                start(200, true);
                CmsCoreProvider.getVfsService().getResourceHistory(structureId, this);
            }

            @Override
            protected void onResponse(CmsHistoryResourceCollection result) {

                stop(false);
                final CmsPopup popup = new CmsPopup(CmsHistoryMessages.dialogTitle(), 1150);
                popup.addDialogClose(null);
                CmsResourceHistoryView view = new CmsResourceHistoryView(result, handler);
                handler.setPostRevertAction(new Runnable() {

                    public void run() {

                        popup.hide();
                    }
                });
                popup.setMainContent(view);
                popup.setModal(true);
                popup.setGlassEnabled(true);
                popup.centerHorizontally(80);
            }

        };
        action.execute();

    }
679054
public CmsUrlNameMappingFilter filterRejectStructureId(CmsUUID id) {

        if (id == null) {
            throw new IllegalArgumentException();
        }
        if (m_structureId != null) {
            throw new IllegalStateException();
        }
        CmsUrlNameMappingFilter result = new CmsUrlNameMappingFilter(this);
        result.m_rejectStructureId = id;
        return result;
    }
1006265
public synchronized AllowableActions getAllowableActions(CmsCmisCallContext context, String objectId) {

        try {
            CmsObject cms = m_repository.getCmsObject(context);
            CmsUUID structureId = new CmsUUID(objectId);
            CmsResource file = cms.readResource(structureId);
            return collectAllowableActions(cms, file);
        } catch (CmsException e) {
            handleCmsException(e);
            return null;
        }
    }
113392
public List<CmsResource> getUsersPubList(CmsRequestContext context) throws CmsException {

        List<CmsResource> result = null;
        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
        try {
            result = m_driverManager.getUsersPubList(dbc, context.getCurrentUser().getId());
        } catch (Exception e) {
            dbc.report(
                null,
                Messages.get().container(Messages.ERR_READ_USER_PUBLIST_1, context.getCurrentUser().getName()),
                e);

        } finally {
            dbc.clear();
        }
        return result;
    }
418156
protected void initContent(final CmsUUID structureId) {

        CmsRpcAction<CmsReplaceInfo> action = new CmsRpcAction<CmsReplaceInfo>() {

            @Override
            public void execute() {

                start(0, true);
                CmsCoreProvider.getVfsService().getFileReplaceInfo(structureId, this);
            }

            @Override
            protected void onResponse(CmsReplaceInfo result) {

                initContent(result);
                stop(false);
            }
        };
        action.execute();
    }
349582
public static void openWorkplace(final CmsUUID structureId, final boolean classic) {

        CmsRpcAction<String> callback = new CmsRpcAction<String>() {

            /**
             * @see org.opencms.gwt.client.rpc.CmsRpcAction#execute()
             */
            @Override
            public void execute() {

                start(0, true);
                CmsCoreProvider.getService().getWorkplaceLink(structureId, this);
            }

            /**
             * @see org.opencms.gwt.client.rpc.CmsRpcAction#onResponse(java.lang.Object)
             */
            @Override
            protected void onResponse(String result) {

                stop(false);
                Window.Location.assign(result);
            }
        };
        callback.execute();
    }
496598
private CmsObject getAdminCms(CmsObject cms) throws CmsException {

        CmsObject adminCms = OpenCms.initCmsObject(m_adminCms);
        adminCms.getRequestContext().setSiteRoot(cms.getRequestContext().getSiteRoot());
        adminCms.getRequestContext().setRequestTime(cms.getRequestContext().getRequestTime());
        adminCms.getRequestContext().setCurrentProject(cms.getRequestContext().getCurrentProject());
        adminCms.getRequestContext().setEncoding(cms.getRequestContext().getEncoding());
        adminCms.getRequestContext().setUri(cms.getRequestContext().getUri());
        return adminCms;
    }
1465
protected CmsObject getCmsObject(CmsCmisCallContext context) {

        try {
            if (context.getUsername() == null) {
                // user name can be null
                CmsObject cms = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest());
                cms.getRequestContext().setCurrentProject(m_adminCms.getRequestContext().getCurrentProject());
                return cms;
            } else {
                CmsObject cms = OpenCms.initCmsObject(m_adminCms);
                CmsProject projectBeforeLogin = cms.getRequestContext().getCurrentProject();
                cms.loginUser(context.getUsername(), context.getPassword());
                cms.getRequestContext().setCurrentProject(projectBeforeLogin);
                return cms;
            }
        } catch (CmsException e) {
            throw new CmisPermissionDeniedException(e.getLocalizedMessage(), e);

        }
    }
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;
    }
1181279
public void removeResourceFromUsersPubList(CmsRequestContext context, Collection<CmsUUID> structureIds)
    throws CmsException {

        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
        try {
            m_driverManager.removeResourceFromUsersPubList(dbc, context.getCurrentUser().getId(), structureIds);
        } catch (Exception e) {
            dbc.report(
                null,
                Messages.get().container(
                    Messages.ERR_REMOVE_RESOURCE_FROM_PUBLIST_2,
                    context.getCurrentUser().getName(),
                    structureIds),
                e);

        } finally {
            dbc.clear();
        }
    }
1252115
public void insertContextMenu(List<CmsContextMenuEntryBean> menuBeans, CmsUUID structureId) {

        List<I_CmsContextMenuEntry> menuEntries = transformEntries(menuBeans, structureId);
        m_editor.getContext().showMenu(menuEntries);
    }
1030784
public static List<CmsResource> getDetailOnlyResources(CmsObject cms, CmsResource resource) {

        List<CmsResource> result = new ArrayList<CmsResource>();
        Set<String> resourcePaths = new HashSet<String>();
        String sitePath = cms.getSitePath(resource);
        for (Locale locale : OpenCms.getLocaleManager().getAvailableLocales()) {
            resourcePaths.add(getDetailOnlyPageNameWithoutLocaleCheck(sitePath, locale.toString()));
        }
        // in case the deprecated locale less detail container resource exists
        resourcePaths.add(getDetailOnlyPageNameWithoutLocaleCheck(sitePath, null));
        // add the locale independent detail container resource
        resourcePaths.add(getDetailOnlyPageNameWithoutLocaleCheck(sitePath, LOCALE_ALL));
        for (String path : resourcePaths) {
            try {
                CmsResource detailContainers = cms.readResource(path, CmsResourceFilter.IGNORE_EXPIRATION);
                result.add(detailContainers);
            } catch (CmsException e) {
                // will happen in case resource does not exist, ignore
            }
        }
        return result;
    }