/** * Returns the current CMS context.<p> * * @return the CMS context */ private CmsObject getCmsObject() { CmsFlexController controller = CmsFlexController.getController(pageContext.getRequest()); return controller.getCmsObject(); }
/** * Wrapper for the standard servlet API call.<p> * * Forward calls are actually NOT wrapped by OpenCms as of now. * So they should not be used in JSP pages or servlets.<p> * * @param req the servlet request * @param res the servlet response * @throws ServletException in case something goes wrong * @throws IOException in case something goes wrong * * @see javax.servlet.RequestDispatcher#forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse) */ public void forward(ServletRequest req, ServletResponse res) throws ServletException, IOException { CmsFlexController controller = CmsFlexController.getController(req); controller.setForwardMode(true); m_rd.forward(req, res); }
/** * Wrapper for the standard servlet API call.<p> * * Forward calls are actually NOT wrapped by OpenCms as of now. * So they should not be used in JSP pages or servlets.<p> * * @param req the servlet request * @param res the servlet response * @throws ServletException in case something goes wrong * @throws IOException in case something goes wrong * * @see javax.servlet.RequestDispatcher#forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse) */ public void forward(ServletRequest req, ServletResponse res) throws ServletException, IOException { CmsFlexController controller = CmsFlexController.getController(req); controller.setForwardMode(true); m_rd.forward(req, res); }
/** * 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) { m_controller = CmsFlexController.getController(req); if (m_controller == null) { handleMissingFlexController(); } m_context = context; m_request = req; m_response = res; m_isNotInitialized = false; }
/** * @return <code>EVAL_PAGE</code> * * @see javax.servlet.jsp.tagext.Tag#doEndTag() * * @throws JspException by interface default */ @Override public int doEndTag() throws JspException { ServletRequest req = pageContext.getRequest(); CmsFlexController controller = CmsFlexController.getController(req); CmsObject cms = controller.getCmsObject(); try { if (TYPE_CSS.equals(m_type)) { tagCssAction(cms, req); } if (TYPE_JAVASCRIPT.equals(m_type)) { tagJSAction(cms, req); } } catch (Exception e) { throw new JspException(e); } finally { m_parameterMap = null; } return EVAL_PAGE; }
/** * Initializes this formatter tag.<p> */ 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); } }
/** * 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) { m_controller = CmsFlexController.getController(req); if (m_controller == null) { // controller not found - this request was not initialized properly throw new CmsRuntimeException(Messages.get().container( Messages.ERR_MISSING_CMS_CONTROLLER_1, CmsJspBean.class.getName())); } m_context = context; m_request = req; m_response = res; m_isNotInitialized = false; }
/** * Checks if the provided request is running in OpenCms and the current users project is the online project.<p> * * @param req the current request * * @return <code>true</code> if the request is running in OpenCms and the current users project is * the online project, <code>false</code> otherwise */ public static boolean isCmsOnlineRequest(ServletRequest req) { if (req == null) { return false; } return getController(req).getCmsObject().getRequestContext().getCurrentProject().isOnlineProject(); }
/** * Checks if the provided request is running in OpenCms and the current users project is the online project.<p> * * @param req the current request * * @return <code>true</code> if the request is running in OpenCms and the current users project is * the online project, <code>false</code> otherwise */ public static boolean isCmsOnlineRequest(ServletRequest req) { if (req == null) { return false; } return getController(req).getCmsObject().getRequestContext().currentProject().isOnlineProject(); }
/** * Internal action method.<p> * * @param req the current request * * @return a map that contains the element settings */ public static Map<String, String> elementSettingTagAction(ServletRequest req) { CmsFlexController controller = CmsFlexController.getController(req); CmsObject cms = controller.getCmsObject(); // try to find element setting on the container element try { CmsContainerElementBean currentElement = OpenCms.getADEManager().getCurrentElement(req); currentElement.initResource(cms); return currentElement.getSettings(); } catch (CmsException e) { // most likely we are not in a container page LOG.debug(e.getLocalizedMessage(), e); return Collections.emptyMap(); } }
/** * Creates a new standard JSP context bean. * * @param req the current servlet request */ private CmsJspStandardContextBean(ServletRequest req) { CmsFlexController controller = CmsFlexController.getController(req); m_request = req; CmsObject cms; if (controller != null) { cms = controller.getCmsObject(); } else { cms = (CmsObject)req.getAttribute(ATTRIBUTE_CMS_OBJECT); } if (cms == null) { // cms object unavailable - this request was not initialized properly throw new CmsRuntimeException( Messages.get().container(Messages.ERR_MISSING_CMS_CONTROLLER_1, CmsJspBean.class.getName())); } updateCmsObject(cms); m_detailContentResource = CmsDetailPageResourceHandler.getDetailResource(req); }
/** * Constructor.<p> * * @param context the page context * @param req the request * @param res the response */ public CmsMacroFormatterResolver(PageContext context, HttpServletRequest req, HttpServletResponse res) { m_context = context; m_request = req; m_response = res; CmsFlexController controller = CmsFlexController.getController(req); if (controller == null) { handleMissingFlexController(); return; } m_cms = controller.getCmsObject(); m_contextBean = CmsJspStandardContextBean.getInstance(m_request); m_element = m_contextBean.getElement(); }
/** * @see org.opencms.loader.I_CmsResourceLoader#service(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.ServletRequest, javax.servlet.ServletResponse) */ public void service(CmsObject cms, CmsResource resource, ServletRequest req, ServletResponse res) throws ServletException, IOException, CmsLoaderException { Lock lock = m_purgeLock.readLock(); try { lock.lock(); CmsFlexController controller = CmsFlexController.getController(req); // get JSP target name on "real" file system String target = updateJsp(resource, controller, new HashSet<String>(8)); // important: Indicate that all output must be buffered controller.getCurrentResponse().setOnlyBuffering(true); // initialize the standard contex bean to be available for all requests CmsJspStandardContextBean.getInstance(controller.getCurrentRequest()); // dispatch to external file controller.getCurrentRequest().getRequestDispatcherToExternal(cms.getSitePath(resource), target).include( req, res); } finally { lock.unlock(); } }
/** * The implementation of the tag.<p> * * @param request the current request * @param file the path to the PDF * @param width the thumbnail width * @param height the thumbnail height * @param format the image format * * @throws CmsException if something goes wrong * * @return the link to the PDF thumbnail */ public static String pdfTagAction(ServletRequest request, String file, int width, int height, String format) throws CmsException { CmsFlexController controller = CmsFlexController.getController(request); CmsObject cms = controller.getCmsObject(); CmsResource pdfRes = cms.readResource(file); CmsPdfThumbnailLink linkObj = new CmsPdfThumbnailLink(cms, pdfRes, width, height, format); return linkObj.getLinkWithOptions(); }
/** * @see org.opencms.loader.I_CmsResourceLoader#service(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.ServletRequest, javax.servlet.ServletResponse) */ public void service(CmsObject cms, CmsResource resource, ServletRequest req, ServletResponse res) throws ServletException, IOException, CmsLoaderException { CmsFlexController controller = CmsFlexController.getController(req); // get JSP target name on "real" file system String target = updateJsp(resource, controller, new HashSet(8)); // important: Indicate that all output must be buffered controller.getCurrentResponse().setOnlyBuffering(true); // dispatch to external file controller.getCurrentRequest().getRequestDispatcherToExternal(cms.getSitePath(resource), target).include( req, res); }
/** * Internal action method.<p> * * @param action the search action * @param req the current request * * @return String the value of the property or <code>null</code> if not found (and no defaultValue provided) * * @throws CmsException if something goes wrong */ public static Map<String, String> propertiesTagAction(String action, ServletRequest req) throws CmsException { CmsFlexController controller = CmsFlexController.getController(req); // now read the property from the VFS Map<String, String> value = new HashMap<String, String>(); CmsPropertyAction propertyAction = new CmsPropertyAction(req, action); if (null != propertyAction.getVfsUri()) { value = CmsProperty.toMap( controller.getCmsObject().readPropertyObjects(propertyAction.getVfsUri(), propertyAction.isSearch())); } return value; }
/** * @see org.opencms.workplace.editors.directedit.I_CmsDirectEditProvider#insertDirectEditEmptyList(javax.servlet.jsp.PageContext, org.opencms.workplace.editors.directedit.CmsDirectEditParams) */ public void insertDirectEditEmptyList(PageContext context, CmsDirectEditParams params) throws JspException { insertDirectEditStart(context, params); ServletRequest req = context.getRequest(); CmsFlexController controller = CmsFlexController.getController(req); CmsObject cms = controller.getCmsObject(); print( context, "<div style=\"minHeight:24px\">" + Messages.get().getBundle(OpenCms.getWorkplaceManager().getWorkplaceLocale(cms)).key( Messages.GUI_CLICK_TO_ADD_ELEMENT_TO_EMPTY_LIST_0) + "</div>"); insertDirectEditEnd(context); }
/** * Returns a link to a file in the OpenCms VFS * that has been adjusted according to the web application path and the * OpenCms static export rules.<p> * * Since OpenCms version 7.0.2, you can also use this method in case you are not sure * if the link is internal or external, as * {@link CmsLinkManager#substituteLinkForUnknownTarget(org.opencms.file.CmsObject, String)} * is used to calculate the link target.<p> * * Relative links are converted to absolute links, using the current element URI as base.<p> * * @param target the link that should be calculated, can be relative or absolute * @param req the current request * * @return the target link adjusted according to the web application path and the OpenCms static export rules * * @see org.opencms.staticexport.CmsLinkManager#substituteLinkForUnknownTarget(org.opencms.file.CmsObject, String) */ public static String linkTagAction(String target, ServletRequest req) { CmsFlexController controller = CmsFlexController.getController(req); return OpenCms.getLinkManager().substituteLinkForUnknownTarget( controller.getCmsObject(), CmsLinkManager.getAbsoluteUri(target, controller.getCurrentRequest().getElementUri())); }
/** * Checks if the current request should be direct edit enabled.<p> * * @param req the servlet request * * @return <code>true</code> if the current request should be direct edit enabled */ public static boolean isEditableRequest(ServletRequest req) { boolean result = false; if (CmsHistoryResourceHandler.isHistoryRequest(req) || CmsJspTagEnableAde.isDirectEditDisabled(req)) { // don't display direct edit buttons on an historical resource result = false; } else { CmsFlexController controller = CmsFlexController.getController(req); CmsObject cms = controller.getCmsObject(); result = !cms.getRequestContext().getCurrentProject().isOnlineProject() && !CmsResource.isTemporaryFileName(cms.getRequestContext().getUri()); } return result; }
/** * The implementation of the tag.<p> * * @param request the current request * @param format the format path * @param content the content path * @param localeStr the name of the locale to include in the PDF link * * @return the link to the PDF * * @throws CmsException if something goes wrong */ public static String pdfTagAction(ServletRequest request, String format, String content, String localeStr) throws CmsException { CmsFlexController controller = CmsFlexController.getController(request); CmsObject cms = OpenCms.initCmsObject(controller.getCmsObject()); if (localeStr != null) { Locale localeObj = CmsLocaleManager.getLocale(localeStr); cms.getRequestContext().setLocale(localeObj); } CmsResource formatterRes = cms.readResource(format); CmsResource contentRes = cms.readResource(content, CmsResourceFilter.ignoreExpirationOffline(cms)); CmsPdfLink pdfLink = new CmsPdfLink(cms, formatterRes, contentRes); return pdfLink.getLink(); }