Initializes a CMS context for the authentication data contained in a call context.<p>

@param context the call context
@return the initialized CMS context
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);

        }
    }
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();
    }
1281395
public Map<String, String[]> initAdminTool() throws CmsRoleViolationException {

        Map<String, String[]> params = new HashMap<String, String[]>(getParameterMap());
        // initialize
        getToolManager().initParams(this);

        // adjust parameters if called as default
        if (!useNewStyle()) {
            params.put(PARAM_STYLE, new String[] {CmsToolDialog.STYLE_NEW});
            setParamStyle(CmsToolDialog.STYLE_NEW);
        }

        try {
            // a dialog just to access the close link parameter
            CmsDialog wp = (CmsDialog)this;
            // set close link
            if (CmsStringUtil.isEmptyOrWhitespaceOnly(wp.getParamCloseLink())) {
                if (!getToolManager().getBaseToolPath(this).equals(getToolManager().getCurrentToolPath(this))) {
                    Map<String, String[]> args = getToolManager().resolveAdminTool(
                        getParamRoot(),
                        getParentPath()).getHandler().getParameters(wp);
                    wp.setParamCloseLink(CmsToolManager.linkForToolPath(getJsp(), getParentPath(), args));
                    params.put(CmsDialog.PARAM_CLOSELINK, new String[] {wp.getParamCloseLink()});
                }
            }
        } catch (Exception e) {
            // ignore
        }

        if (!getToolManager().getCurrentTool(this).getHandler().isEnabled(this)) {
            throw new CmsRoleViolationException(Messages.get().container(Messages.ERR_ADMIN_INSUFFICIENT_RIGHTS_0));
        }

        return params;
    }
387694
public HttpSessionTokensSet getHttpSessionTokensSetForContext(Context context){
		//TODO: Proper implementation. Hack for now
		for (Entry<String, HttpSessionTokensSet> e : this.sessionTokens.entrySet()) {
			String siteName = e.getKey();
			siteName = "http://" + siteName;
			if (context.isInContext(siteName))
				return e.getValue();
		}
		return null;
	}
433824
public String getStaticResourceContext() {

        if (m_staticResourcePathFragment == null) {
            m_staticResourcePathFragment = CmsStaticResourceHandler.getStaticResourceContext(
                OpenCms.getStaticExportManager().getVfsPrefix(),
                getVersionNumber());
        }
        return m_staticResourcePathFragment;
    }
267727
protected void init() {

        // initialize OpenCms access objects
        CmsFlexController controller = CmsFlexController.getController(pageContext.getRequest());
        m_cms = controller.getCmsObject();

        int startLevel = m_startLevel == null ? Integer.MIN_VALUE : Integer.parseInt(m_startLevel);
        int endLevel = m_endLevel == null ? Integer.MIN_VALUE : Integer.parseInt(m_endLevel);

        // load navigation bean in the JSP context
        CmsJspNavigationBean bean = new CmsJspNavigationBean(
            m_cms,
            m_type,
            startLevel,
            endLevel,
            m_resource,
            m_param,
            m_locale);
        storeAttribute(getVar(), bean);
    }
459260
public CmsTemplateContext getTemplateContext(
        String providerName,
        CmsObject cms,
        HttpServletRequest request,
        CmsResource resource) {

        I_CmsTemplateContextProvider provider = getTemplateContextProvider(providerName);
        if (provider == null) {
            return null;
        }
        String cookieName = provider.getOverrideCookieName();
        String forcedValue = null;
        if (request != null) {
            String paramTemplateContext = request.getParameter(CmsGwtConstants.PARAM_TEMPLATE_CONTEXT);
            if (!CmsStringUtil.isEmptyOrWhitespaceOnly(paramTemplateContext)) {
                forcedValue = paramTemplateContext;
            } else if (cookieName != null) {
                forcedValue = CmsRequestUtil.getCookieValue(request.getCookies(), cookieName);
            }
        }
        if (forcedValue != null) {
            Map<String, CmsTemplateContext> contextMap = provider.getAllContexts();
            if (contextMap.containsKey(forcedValue)) {
                CmsTemplateContext contextBean = contextMap.get(forcedValue);
                return new CmsTemplateContext(
                    contextBean.getKey(),
                    contextBean.getTemplatePath(),
                    contextBean.getMessageContainer(),
                    contextBean.getProvider(),
                    contextBean.getClientVariants().values(),
                    true);

            }
        }
        return provider.getTemplateContext(cms, request, resource);
    }
420160
@SuppressWarnings("null")
    private void init(CmsObject cms) throws Exception {

        CmsFile configFile = cms.readFile(m_resource);
        CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, configFile);
        m_title = content.getValue(N_TITLE, CmsConfigurationReader.DEFAULT_LOCALE).getStringValue(cms);
        I_CmsXmlContentValue titleKey = content.getValue(N_TITLE_KEY, CmsConfigurationReader.DEFAULT_LOCALE);
        if ((titleKey != null) && CmsStringUtil.isNotEmptyOrWhitespaceOnly(titleKey.getStringValue(cms))) {
            m_titleKey = titleKey.getStringValue(cms);
        }
        I_CmsXmlContentValue orderVal = content.getValue(N_ORDER, CmsConfigurationReader.DEFAULT_LOCALE);
        if (orderVal != null) {
            try {
                m_order = Integer.parseInt(orderVal.getStringValue(cms));
            } catch (Exception e) {
                LOG.error(e.getLocalizedMessage(), e);
                m_order = DEFAULT_ORDER;
            }
        } else {
            m_order = DEFAULT_ORDER;
        }

        I_CmsXmlContentValue parentView = content.getValue("Parent", CmsConfigurationReader.DEFAULT_LOCALE);
        if (parentView != null) {
            CmsUUID parentViewId = null;
            try {
                CmsXmlVarLinkValue elementViewValue = (CmsXmlVarLinkValue)parentView;
                String stringValue = elementViewValue.getStringValue(cms);
                if (CmsStringUtil.isEmpty(stringValue)) {
                    parentViewId = CmsUUID.getNullUUID();
                } else if (stringValue.equals(PARENT_NONE)) {
                    parentViewId = null;
                } else if (stringValue.startsWith(CmsConfigurationReader.VIEW_SCHEME)) {
                    parentViewId = new CmsUUID(stringValue.substring(CmsConfigurationReader.VIEW_SCHEME.length()));
                } else {
                    parentViewId = elementViewValue.getLink(cms).getStructureId();
                }
            } catch (Exception e) {
                LOG.error(e.getLocalizedMessage(), e);
            }
            m_parentViewId = parentViewId;
        }

    }
314239
@com.fasterxml.jackson.annotation.JsonProperty("Context")
    public void setContext(String context) {
        this.context = context;
    }
691165
public static CmsWorkplaceSettings initSiteAndProject(CmsObject cms) {

        CmsWorkplaceSettings workplaceSettings = CmsWorkplace.initWorkplaceSettings(cms, null, false);
        String startSite = CmsWorkplace.getStartSiteRoot(cms, workplaceSettings);
        // switch to the preferred site
        workplaceSettings.setSite(startSite);
        cms.getRequestContext().setSiteRoot(startSite);
        // store the workplace settings
        CmsUserSettings settings = workplaceSettings.getUserSettings();
        // get the direct edit path

        try {
            CmsProject project = cms.readProject(settings.getStartProject());
            if (OpenCms.getOrgUnitManager().getAllAccessibleProjects(cms, project.getOuFqn(), false).contains(
                project)) {
                // user has access to the project, set this as current project
                workplaceSettings.setProject(project.getUuid());
                cms.getRequestContext().setCurrentProject(project);
            }
        } catch (CmsException e) {
            // unable to set the startup project, bad but not critical
            LOG.warn(
                Messages.get().getBundle().key(
                    Messages.LOG_LOGIN_NO_STARTUP_PROJECT_2,
                    cms.getRequestContext().getCurrentUser().getName(),
                    settings.getStartProject()),
                e);
        }
        return workplaceSettings;
    }
936772
public void init(CmsObject cms, Locale locale, I_CmsXmlDocument content, CmsResource resource) {

        m_cms = cms;
        m_requestedLocale = locale;
        m_content = content;
        m_resource = resource;
    }
777508
private ContextModel getOrCreateContext(final HttpContext httpContext) {
		// org.osgi.service.http.HttpContext -> org.ops4j.pax.web.service.WebContainerContext
		final WebContainerContext context;
		if (httpContext == null) {
			context = createDefaultHttpContext();
		} else if (!(httpContext instanceof WebContainerContext)) {
			context = new WebContainerContextWrapper(serviceBundle, httpContext);
		} else {
			context = (WebContainerContext) httpContext;
		}

		// sanity check - non shared context should be associated to single bundle
		serverModel.associateHttpContext(context, serviceBundle, httpContext instanceof SharedWebContainerContext);

		ContextModel contextModel = serviceModel.getContextModel(context);
		if (contextModel == null) {
			contextModel = new ContextModel(context, serviceBundle,
					bundleClassLoader);
			contextModel.setVirtualHosts(serverController.getConfiguration()
					.getVirtualHosts());
		}
		return contextModel;
	}
338052
public void init(HttpInboundServiceContext context) {
        this.message = context.getRequest();
        if (this.useEE7Streams) {
            this.body = new HttpInputStreamEE7(context);
        } else {
            this.body = new HttpInputStreamImpl(context);
        }
    }
667249
private static CmsDocumentDependency readFromContext(CmsObject cms, String rootPath) {

        return (CmsDocumentDependency)cms.getRequestContext().getAttribute(getAttributeKey(rootPath));
    }
798766
public void initializeOrgUnit(CmsRequestContext context, CmsOrganizationalUnit ou) {

        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
        m_driverManager.initOrgUnit(dbc, ou);

    }
171836
protected void initUserObject() {

        if (m_fieldconfiguration == null) {
            try {
                m_fieldconfiguration = m_searchManager.getFieldConfiguration(
                    getParamFieldconfiguration());
                if (m_fieldconfiguration == null) {
                    m_fieldconfiguration = new CmsLuceneFieldConfiguration();
                }
            } catch (Exception e) {
                m_fieldconfiguration = new CmsLuceneFieldConfiguration();
            }
        }

        if (m_field == null) {
            try {
                Iterator<CmsSearchField> itFields = m_fieldconfiguration.getFields().iterator();
                while (itFields.hasNext()) {
                    CmsLuceneField curField = (CmsLuceneField)itFields.next();
                    if (curField.getName().equals(getParamField())) {
                        m_field = curField;
                        break;
                    }
                }
                if (m_field == null) {
                    m_field = new CmsLuceneField();
                }
            } catch (Exception e) {
                m_field = new CmsLuceneField();
            }
        }
    }
533389
public static I_CmsDirectEditProvider getDirectEditProvider(PageContext context) {

        // get the direct edit provider from the request attributes
        return (I_CmsDirectEditProvider)context.getRequest().getAttribute(
            I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER);
    }