コード例 #1
0
  /**
   * Sets the name of the class to schedule.
   *
   * <p>
   *
   * @param className the class name to set
   */
  public void setClassName(String className) {

    checkFrozen();
    if (!CmsStringUtil.isValidJavaClassName(className)) {
      CmsMessageContainer message =
          Messages.get().container(Messages.ERR_BAD_JOB_CLASS_NAME_1, className);
      if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) {
        throw new CmsIllegalArgumentException(message);
      } else {
        LOG.warn(message.key());
      }
    } else {
      Class<?> jobClass;
      try {
        jobClass = Class.forName(className);
        if (!I_CmsScheduledJob.class.isAssignableFrom(jobClass)) {
          CmsMessageContainer message =
              Messages.get()
                  .container(
                      Messages.ERR_JOB_CLASS_BAD_INTERFACE_2,
                      className,
                      I_CmsScheduledJob.class.getName());

          if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) {
            throw new CmsIllegalArgumentException(message);
          } else {
            LOG.warn(message.key());
          }
        }
      } catch (ClassNotFoundException e) {
        CmsMessageContainer message =
            Messages.get().container(Messages.ERR_JOB_CLASS_NOT_FOUND_1, className);
        if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) {
          throw new CmsIllegalArgumentException(message);
        } else {
          LOG.warn(message.key());
        }
      }
    }
    m_className = className;
    if (getJobName() == null) {
      // initialize job name with class name as default
      setJobName(className);
    }
  }
コード例 #2
0
  /**
   * Processing method for this cached entry.
   *
   * <p>If this method is called, it delivers the contents of the cached entry to the given request
   * / response. This includes calls to all included resources.
   *
   * <p>
   *
   * @param req the request from the client
   * @param res the server response
   * @throws CmsFlexCacheException is thrown when problems writing to the response output-stream
   *     occur
   * @throws ServletException might be thrown from call to RequestDispatcher.include()
   * @throws IOException might be thrown from call to RequestDispatcher.include() or from
   *     Response.sendRedirect()
   */
  public void service(CmsFlexRequest req, CmsFlexResponse res)
      throws CmsFlexCacheException, ServletException, IOException {

    if (!m_completed) {
      return;
    }

    if (m_redirectTarget != null) {
      res.setOnlyBuffering(false);
      // redirect the response, no further output required
      res.sendRedirect(m_redirectTarget);
    } else {
      // process cached headers first
      CmsFlexResponse.processHeaders(m_headers, res);
      // check if this cache entry is a "leaf" (i.e. no further includes)
      boolean hasNoSubElements = (m_elements.size() == 1);
      // write output to stream and process all included elements
      for (int i = 0; i < m_elements.size(); i++) {
        Object o = m_elements.get(i);
        if (o instanceof String) {
          // handle cached parameters
          i++;
          Map<String, String[]> paramMap = CmsCollectionsGenericWrapper.map(m_elements.get(i));
          Map<String, String[]> oldParamMap = null;
          if (paramMap.size() > 0) {
            oldParamMap = req.getParameterMap();
            req.addParameterMap(paramMap);
          }
          // handle cached attributes
          i++;
          Map<String, Object> attrMap = CmsCollectionsGenericWrapper.map(m_elements.get(i));
          Map<String, Object> oldAttrMap = null;
          if (attrMap.size() > 0) {
            oldAttrMap = req.getAttributeMap();
            req.addAttributeMap(attrMap);
          }
          // do the include call
          req.getRequestDispatcher((String) o).include(req, res);
          // reset parameters if necessary
          if (oldParamMap != null) {
            req.setParameterMap(oldParamMap);
          }
          // reset attributes if necessary
          if (oldAttrMap != null) {
            req.setAttributeMap(oldAttrMap);
          }
        } else {
          try {
            res.writeToOutputStream((byte[]) o, hasNoSubElements);
          } catch (IOException e) {
            CmsMessageContainer message =
                Messages.get()
                    .container(Messages.LOG_FLEXCACHEKEY_NOT_FOUND_1, getClass().getName());
            if (LOG.isDebugEnabled()) {
              LOG.debug(message.key());
            }

            throw new CmsFlexCacheException(message, e);
          }
        }
      }
    }
  }