/** * Initialize this bean with the current page context, request and response.<p> * * It is required to call one of the init() methods before you can use the * instance of this bean. * * @param context the JSP page context object * @param req the JSP request * @param res the JSP response */ public void init(PageContext context, HttpServletRequest req, HttpServletResponse res) { // call initialization of super class super.init(context, req, res); // initialize members from request m_pageUri = req.getParameter(CmsTemplateBean.PARAM_URI); if (m_pageUri == null) { m_pageUri = getRequestContext().getUri(); } m_searchAll = Boolean.valueOf(req.getParameter(PARAM_SEARCHALL)).booleanValue(); // change URI to point at page that called the search getRequestContext().setUri(m_pageUri); }
/** * Returns the URI of the style file.<p> * * @param cms the current OpenCms user context * @param editedResourcePath the absolute VFS path of the currently edited resource * @return the URI of the CSS style sheet configuration file */ protected String getStyleUri(CmsObject cms, String editedResourcePath) { String originalUri = cms.getRequestContext().getUri(); String styleUri = null; try { cms.getRequestContext().setUri(editedResourcePath); styleUri = cms.readPropertyObject(editedResourcePath, CmsTemplateLayout.PROPERTY_STYLE, true).getValue(""); } catch (CmsException e) { if (LOG.isWarnEnabled()) { // TODO } } finally { cms.getRequestContext().setUri(originalUri); } return styleUri; }
/** * Initializes the URI of the current template page.<p> * * This checks for the presence of a special <code>uri</code> parameter. * If this parameter is found, the OpenCms request context URI is switched to this value.<p> */ public void initUri() { String uri = getRequest().getParameter(CmsTemplateBean.PARAM_URI); if (CmsStringUtil.isNotEmpty(uri)) { getRequest().setAttribute(ATTRIBUTE_ORIGINAL_URI, getRequestContext().getUri()); getRequestContext().setUri(uri); } }
/** * Returns the template configuration path in the OpenCms VFS.<p> * * Overwrites the method in the super class because the uri is set to the * form uri in the module.<p> * * @return the template configuration path */ public String getConfigPath() { // store form uri String uri = getRequestContext().getUri(); // set uri to page uri to obtain configuration path getRequestContext().setUri(getPageUri(true)); String path = property(PROPERTY_CONFIGPATH, "search", ""); // reset uri to form uri getRequestContext().setUri(uri); return path; }
/** * @see org.opencms.xml.content.I_CmsXmlContentHandler#getModelFolder(org.opencms.file.CmsObject, java.lang.String) */ public String getModelFolder(CmsObject cms, String currentFolder) { String result = m_modelFolder; // store the original URI String uri = cms.getRequestContext().getUri(); try { // set URI to current folder cms.getRequestContext().setUri(currentFolder); CmsMacroResolver resolver = CmsMacroResolver.newInstance().setCmsObject(cms); // resolve eventual macros result = resolver.resolveMacros(m_modelFolder); } finally { // switch back to stored uri cms.getRequestContext().setUri(uri); } return result; }
/** * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ public int compare(Object o1, Object o2) { CmsResourceSelectWidgetOption option1 = (CmsResourceSelectWidgetOption)o1; CmsResourceSelectWidgetOption option2 = (CmsResourceSelectWidgetOption)o2; CmsResource resource1 = option1.getResource(); CmsResource resource2 = option2.getResource(); String sort1, sort2; // fool the macro resolver: CmsRequestContext requestContext = m_macroCmsObjectInner.getRequestContext(); requestContext.setUri(resource1.getRootPath()); // implant the resource name for macro "%(opencms.filename): m_macroResolverInner.setResourceName(resource1.getName()); sort1 = m_macroResolverInner.resolveMacros(m_comparatorMacro); requestContext.setUri(resource2.getRootPath()); m_macroResolverInner.setResourceName(resource2.getName()); sort2 = m_macroResolverInner.resolveMacros(m_comparatorMacro); return sort1.compareTo(sort2); }
/** * Gets the detail link for a given container page and detail content.<p> * * @param pageRes the container page * @param detailRes the detail content * @param locale the locale for which we want the link * * @return the detail page link */ protected String getDetailLink(CmsResource pageRes, CmsResource detailRes, Locale locale) { String pageSitePath = m_siteGuestCms.getSitePath(pageRes); String detailSitePath = m_siteGuestCms.getSitePath(detailRes); CmsRequestContext requestContext = m_siteGuestCms.getRequestContext(); String originalUri = requestContext.getUri(); Locale originalLocale = requestContext.getLocale(); try { requestContext.setUri(pageSitePath); requestContext.setLocale(locale); return OpenCms.getLinkManager().getOnlineLink(m_siteGuestCms, detailSitePath, true); } finally { requestContext.setUri(originalUri); requestContext.setLocale(originalLocale); } }
/** * Changes the current folder (i.e. the URI in the VFS).<p> * * @param target the new URI * @throws Exception if something goes wrong * @see org.opencms.file.CmsRequestContext#setUri(String) */ public void cd(String target) throws Exception { String folder = CmsResource.getFolderPath(m_cms.getRequestContext().getUri()); if (!target.endsWith("/")) { target += "/"; } String resolvedTarget = CmsLinkManager.getAbsoluteUri(target, folder); CmsResource res = m_cms.readResource(resolvedTarget); if (!res.isFolder()) { throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_NOT_A_FOLDER_1, resolvedTarget)); } m_cms.getRequestContext().setUri(resolvedTarget); System.out.println('\n' + getMessages().key(Messages.GUI_SHELL_CURRENT_FOLDER_1, new Object[] {resolvedTarget})); System.out.println(); }
uri = oldUri; getRequestContext().setUri(uri);
/** * Changes the current folder (i.e. the URI in the VFS).<p> * * @param target the new URI * @throws Exception if something goes wrong * @see org.opencms.file.CmsRequestContext#setUri(String) */ public void cd(String target) throws Exception { String folder = CmsResource.getFolderPath(m_cms.getRequestContext().getUri()); if (!target.endsWith("/")) { target += "/"; } String resolvedTarget = CmsLinkManager.getAbsoluteUri(target, folder); CmsResource res = m_cms.readResource(resolvedTarget); if (!res.isFolder()) { throw new CmsIllegalArgumentException( Messages.get().container(Messages.ERR_NOT_A_FOLDER_1, resolvedTarget)); } m_cms.getRequestContext().setUri(resolvedTarget); m_shell.getOut().println( '\n' + getMessages().key(Messages.GUI_SHELL_CURRENT_FOLDER_1, new Object[] {resolvedTarget})); m_shell.getOut().println(); }
/** * Include a template part to display on the error page.<p> * * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute) * @param element the element (template selector) to display from the target * @param parameterMap a map of the request parameters * * @throws JspException in case there were problems including the target */ public void includeTemplatePart(String target, String element, Map<String, Object> parameterMap) throws JspException { // store current site root and URI String currentSiteRoot = getRequestContext().getSiteRoot(); String currentUri = getRequestContext().getUri(); try { // set site root and URI to display template part correct getRequestContext().setSiteRoot(getSiteRoot()); getRequestContext().setUri(getTemplateUri()); // include the template part include(target, element, parameterMap); } finally { // reset site root and requested URI to status JSP getRequestContext().setSiteRoot(currentSiteRoot); getRequestContext().setUri(currentUri); } }
/** * Include a template part to display on the error page.<p> * * @param target the target uri of the file in the OpenCms VFS (can be relative or absolute) * @param element the element (template selector) to display from the target * @param parameterMap a map of the request parameters * * @throws JspException in case there were problems including the target */ public void includeTemplatePart(String target, String element, Map parameterMap) throws JspException { // store current site root and URI String currentSiteRoot = getRequestContext().getSiteRoot(); String currentUri = getRequestContext().getUri(); try { // set site root and URI to display template part correct getRequestContext().setSiteRoot(getSiteRoot()); getRequestContext().setUri(getTemplateUri()); // include the template part include(target, element, parameterMap); } finally { // reset site root and requested URI to status JSP getRequestContext().setSiteRoot(currentSiteRoot); getRequestContext().setUri(currentUri); } }
String relPath = cms.getRequestContext().removeSiteRoot(rootPath); if (cms.existsResource(relPath)) { cms.getRequestContext().setUri(relPath); OpenCms.getResourceManager().loadResource(cms, cms.readResource(relPath), req, res); return true;
/** * Returns the CMS object.<p> * * @param req the request * * @return the CMS object * * @throws CmsException if something goes wrong */ protected CmsObject getCmsObject(HttpServletRequest req) throws CmsException { CmsObject cms = OpenCmsCore.getInstance().initCmsObjectFromSession(req); // use the guest user as fall back if (cms == null) { cms = OpenCmsCore.getInstance().initCmsObject(OpenCms.getDefaultUsers().getUserGuest()); String siteRoot = OpenCmsCore.getInstance().getSiteManager().matchRequest(req).getSiteRoot(); cms.getRequestContext().setSiteRoot(siteRoot); } String baseUri = getBaseUri(req, cms); if (baseUri != null) { cms.getRequestContext().setUri(baseUri); } return cms; }
/** * Returns the CMS object.<p> * * @param req the request * * @return the CMS object * * @throws CmsException if something goes wrong */ protected CmsObject getCmsObject(HttpServletRequest req) throws CmsException { CmsObject cms = OpenCmsCore.getInstance().initCmsObjectFromSession(req); // use the guest user as fall back if (cms == null) { cms = OpenCmsCore.getInstance().initCmsObject(OpenCms.getDefaultUsers().getUserGuest()); String siteRoot = OpenCmsCore.getInstance().getSiteManager().matchRequest(req).getSiteRoot(); cms.getRequestContext().setSiteRoot(siteRoot); } String baseUri = getBaseUri(req, cms); if (baseUri != null) { cms.getRequestContext().setUri(baseUri); } return cms; }
/** * Creates a copy of the admin cms object which is initialize with the data of the current cms object.<p> * * @param cms the current cms object * @return the new admin cms object * * @throws CmsException if something goes wrong */ 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; }
/** * Creates a copy of the admin cms object which is initialize with the data of the current cms object.<p> * * @param cms the current cms object * @return the new admin cms object * * @throws CmsException if something goes wrong */ 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().currentProject()); adminCms.getRequestContext().setEncoding(cms.getRequestContext().getEncoding()); adminCms.getRequestContext().setUri(cms.getRequestContext().getUri()); return adminCms; }
cms.getRequestContext().setUri(currentUri);