/** * Returns the encoding.<p> * * @return the encoding */ public String getEncoding() { return m_context.getEncoding(); }
/** * Returns the encoding.<p> * * @return the encoding */ public String getEncoding() { return m_context.getEncoding(); }
/** * Returns all parameters of the current workplace class * as hidden field tags that can be inserted in a form.<p> * * @return all parameters of the current workplace class * as hidden field tags that can be inserted in a html form */ public String allParamsAsHidden() { StringBuffer result = new StringBuffer(512); Map params = allParamValues(); Iterator i = params.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry)i.next(); result.append("<input type=\"hidden\" name=\""); result.append(entry.getKey()); result.append("\" value=\""); String encoded = CmsEncoder.encode(entry.getValue().toString(), getCms().getRequestContext().getEncoding()); result.append(encoded); result.append("\">\n"); } return result.toString(); }
/** * Returns all parameters of the current workplace class * as hidden field tags that can be inserted in a form.<p> * * @return all parameters of the current workplace class * as hidden field tags that can be inserted in a html form */ public String allParamsAsHidden() { StringBuffer result = new StringBuffer(512); Map<String, Object> params = allParamValues(); Iterator<Entry<String, Object>> i = params.entrySet().iterator(); while (i.hasNext()) { Entry<String, Object> entry = i.next(); result.append("<input type=\"hidden\" name=\""); result.append(entry.getKey()); result.append("\" value=\""); String encoded = CmsEncoder.encode(entry.getValue().toString(), getCms().getRequestContext().getEncoding()); result.append(encoded); result.append("\">\n"); } return result.toString(); }
/** * Returns all initialized parameters of the current workplace class * as request parameters, i.e. in the form <code>key1=value1&key2=value2</code> etc. * * @return all initialized parameters of the current workplace class * as request parameters */ public String paramsAsRequest() { StringBuffer result = new StringBuffer(512); Map<String, Object> params = paramValues(); Iterator<Entry<String, Object>> i = params.entrySet().iterator(); while (i.hasNext()) { Entry<String, Object> entry = i.next(); result.append(entry.getKey()); result.append("="); result.append(CmsEncoder.encode(entry.getValue().toString(), getCms().getRequestContext().getEncoding())); if (i.hasNext()) { result.append("&"); } } return result.toString(); }
/** * Returns all present request parameters as String.<p> * * The String is formatted as a parameter String (<code>param1=val1&param2=val2</code>) with UTF-8 encoded values.<p> * * @return all present request parameters as String */ public String allParamsAsRequest() { StringBuffer retValue = new StringBuffer(512); HttpServletRequest request = getJsp().getRequest(); Iterator paramNames = request.getParameterMap().keySet().iterator(); while (paramNames.hasNext()) { String paramName = (String)paramNames.next(); String paramValue = request.getParameter(paramName); retValue.append(paramName + "=" + CmsEncoder.encode(paramValue, getCms().getRequestContext().getEncoding())); if (paramNames.hasNext()) { retValue.append("&"); } } return retValue.toString(); }
/** * Returns all present request parameters as String.<p> * * The String is formatted as a parameter String (<code>param1=val1&param2=val2</code>) with UTF-8 encoded values.<p> * * @return all present request parameters as String */ public String allParamsAsRequest() { StringBuffer retValue = new StringBuffer(512); HttpServletRequest request = getJsp().getRequest(); Iterator<String> paramNames = request.getParameterMap().keySet().iterator(); while (paramNames.hasNext()) { String paramName = paramNames.next(); String paramValue = request.getParameter(paramName); retValue.append( paramName + "=" + CmsEncoder.encode(paramValue, getCms().getRequestContext().getEncoding())); if (paramNames.hasNext()) { retValue.append("&"); } } return retValue.toString(); }
/** * @see org.opencms.file.collectors.I_CmsResourceCollector#getResults(org.opencms.file.CmsObject, java.lang.String, java.lang.String) */ public List<CmsResource> getResults(CmsObject cms, String name, String param, int numResults) throws CmsException { name = name == null ? COLLECTORS[1] : name; Map<String, String> paramsAsMap = getParamsAsMap(param); Map<String, String[]> pm = CmsRequestUtil.createParameterMap( paramsAsMap.get(SOLR_PART), Boolean.valueOf(paramsAsMap.get(PARAM_DECODE_URL)).booleanValue(), cms.getRequestContext().getEncoding()); CmsSolrQuery q = COLLECTORS_LIST.indexOf(name) == 0 ? new CmsSolrQuery(null, pm) : new CmsSolrQuery(cms, pm); boolean excludeTimerange = Boolean.valueOf( paramsAsMap.get(CmsCollectorData.PARAM_EXCLUDETIMERANGE)).booleanValue(); if (excludeTimerange) { q.removeExpiration(); } if (numResults > 0) { q.setRows(Integer.valueOf(numResults)); } CmsSolrIndex index = CmsSearchManager.getIndexSolr(cms, pm); return new ArrayList<CmsResource>(index.search(cms, q, true)); }
/** * Decodes an individual parameter value.<p> * * In special cases some parameters might require a different-from-default * encoding. This is the case if the content of the parameter was * encoded using the JavaScript encodeURIComponent() method on the client, * which always encodes in UTF-8.<p> * * @param paramName the name of the parameter * @param paramValue the unencoded value of the parameter * * @return the encoded value of the parameter */ protected String decodeParamValue(String paramName, String paramValue) { if ((paramName != null) && (paramValue != null)) { return CmsEncoder.decode(paramValue, getCms().getRequestContext().getEncoding()); } else { return null; } }
/** * Decodes an individual parameter value.<p> * * In special cases some parameters might require a different-from-default * encoding. This is the case if the content of the parameter was * encoded using the JavaScript encodeURIComponent() method on the client, * which always encodes in UTF-8.<p> * * @param paramName the name of the parameter * @param paramValue the unencoded value of the parameter * * @return the encoded value of the parameter */ protected String decodeParamValue(String paramName, String paramValue) { if ((paramName != null) && (paramValue != null)) { return CmsEncoder.decode(paramValue, getCms().getRequestContext().getEncoding()); } else { return null; } }
/** * @see org.opencms.file.collectors.A_CmsResourceCollector#getCreateTypeId(org.opencms.file.CmsObject, java.lang.String, java.lang.String) */ @Override public int getCreateTypeId(CmsObject cms, String collectorName, String param) throws CmsException { int result = -1; Map<String, String> paramsAsMap = getParamsAsMap(param); if (paramsAsMap.get(PARAM_CREATE_PATH) != null) { String solrParams = paramsAsMap.get(SOLR_PART); CmsSolrQuery q = new CmsSolrQuery( null, CmsRequestUtil.createParameterMap( solrParams, Boolean.valueOf(paramsAsMap.get(PARAM_DECODE_URL)).booleanValue(), cms.getRequestContext().getEncoding())); String type = CmsSolrQuery.getResourceType(q.getFilterQueries()); if (type != null) { result = OpenCms.getResourceManager().getResourceType(type).getTypeId(); } } return result; }
/** * Loads the requested resource and writes the contents to the response stream.<p> * * @param req the current HTTP request * @param res the current HTTP response * @param cms the current OpenCms user context * @param resource the requested resource * @throws ServletException if something goes wrong * @throws IOException if something goes wrong * @throws CmsException if something goes wrong */ public void loadResource(CmsObject cms, CmsResource resource, HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException, CmsException { res.setContentType(getMimeType(resource.getName(), cms.getRequestContext().getEncoding())); I_CmsResourceLoader loader = getLoader(resource); loader.load(cms, resource, req, res); }
/** * Loads the requested resource and writes the contents to the response stream.<p> * * @param req the current HTTP request * @param res the current HTTP response * @param cms the current OpenCms user context * @param resource the requested resource * @throws ServletException if something goes wrong * @throws IOException if something goes wrong * @throws CmsException if something goes wrong */ public void loadResource(CmsObject cms, CmsResource resource, HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException, CmsException { res.setContentType(getMimeType(resource.getName(), cms.getRequestContext().getEncoding())); I_CmsResourceLoader loader = getLoader(resource); loader.load(cms, resource, req, res); }
/** * Creates a new data source for the given VFS resource.<p> * * @param cms the current users OpenCms context * @param resource the resource to use * * @throws CmsException in case of errors accessing the resource in the VFS */ public CmsVfsDataSource(CmsObject cms, CmsResource resource) throws CmsException { m_file = cms.readFile(resource); // identify the mime-type for the data source m_contentType = OpenCms.getResourceManager().getMimeType( m_file.getName(), cms.getRequestContext().getEncoding()); }
/** * Creates a new data source for the given VFS resource.<p> * * @param cms the current users OpenCms context * @param resource the resource to use * * @throws CmsException in case of errors accessing the resource in the VFS */ public CmsVfsDataSource(CmsObject cms, CmsResource resource) throws CmsException { m_file = cms.readFile(resource); // identify the mime-type for the data source m_contentType = OpenCms.getResourceManager().getMimeType( m_file.getName(), cms.getRequestContext().getEncoding()); }
/** * Creates a new instance with all context variables initialized from the given request context.<p> * * @param requestContext the request context to initialize this context info with */ public CmsContextInfo(CmsRequestContext requestContext) { setUserName(requestContext.currentUser().getName()); setProjectName(requestContext.currentProject().getName()); setRequestedUri(requestContext.getUri()); setSiteRoot(requestContext.getSiteRoot()); setLocale(requestContext.getLocale()); setEncoding(requestContext.getEncoding()); setRemoteAddr(requestContext.getRemoteAddress()); setRequestTime(requestContext.getRequestTime()); setOuFqn(requestContext.getOuFqn()); }
/** * 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; }
/** * Sends the given message to the given addresses.<p> * * @param cms the cms context * * @throws Exception if something goes wrong */ public void sendEmail(CmsObject cms) throws Exception { // create a plain text email CmsSimpleMail theMail = new CmsSimpleMail(); theMail.setCharset(cms.getRequestContext().getEncoding()); theMail.setFrom(cms.getRequestContext().getCurrentUser().getEmail(), getFrom()); theMail.setTo(createInternetAddresses(getTo())); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCc())) { theMail.setCc(createInternetAddresses(getCc())); } theMail.setSubject("[" + OpenCms.getSystemInfo().getServerName() + "] " + getSubject()); theMail.setMsg(getMsg()); // send the mail theMail.send(); }
/** * Creates a new instance with all context variables initialized from the given request context.<p> * * @param requestContext the request context to initialize this context info with */ public CmsContextInfo(CmsRequestContext requestContext) { setUserName(requestContext.getCurrentUser().getName()); setProjectName(requestContext.getCurrentProject().getName()); setRequestedUri(requestContext.getUri()); setSiteRoot(requestContext.getSiteRoot()); setRequestMatcher(requestContext.getRequestMatcher()); setLocale(requestContext.getLocale()); setEncoding(requestContext.getEncoding()); setRemoteAddr(requestContext.getRemoteAddress()); setRequestTime(requestContext.getRequestTime()); setIsSecureRequest(requestContext.isSecureRequest()); setOuFqn(requestContext.getOuFqn()); setDetailResource(requestContext.getDetailResource()); }