コード例 #1
0
ファイル: SearchAct.java プロジェクト: qzzsunly/cms
 @RequestMapping(value = "/search*.jspx", method = RequestMethod.GET)
 public String index(HttpServletRequest request, HttpServletResponse response, ModelMap model) {
   CmsSite site = CmsUtils.getSite(request);
   // 将request中所有参数保存至model中。
   model.putAll(RequestUtils.getQueryParams(request));
   FrontUtils.frontData(request, model, site);
   FrontUtils.frontPageData(request, model);
   String q = RequestUtils.getQueryParam(request, "q");
   if (q.equals("?") || q.equals("*")) {
     return FrontUtils.getTplPath(request, site.getSolutionPath(), TPLDIR_SPECIAL, SEARCH_ERROR);
   }
   if (q.startsWith("?") || q.startsWith("*")) {
     model.addAttribute("oldq", q);
     q = q.substring(1);
     // 替换关键词
     model.addAttribute("q", q);
   }
   String channelId = RequestUtils.getQueryParam(request, "channelId");
   if (StringUtils.isBlank(q) && StringUtils.isBlank(channelId)) {
     model.remove("q");
     model.remove("channelId");
     return FrontUtils.getTplPath(request, site.getSolutionPath(), TPLDIR_SPECIAL, SEARCH_INPUT);
   } else {
     return FrontUtils.getTplPath(request, site.getSolutionPath(), TPLDIR_SPECIAL, SEARCH_RESULT);
   }
 }
コード例 #2
0
ファイル: FireWallInterceptor.java プロジェクト: qzzsunly/cms
  @Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
      throws Exception {
    Boolean configFileModified = false;
    Long configLastModifiedTime = getFireWallConfigFileLastModifiedTime(request);
    if (configLastModifiedTime == null
        || fireWallConfigFile.lastModified() > configLastModifiedTime) {
      configFileModified = true;
      changeConfigModifiedTime(request);
    }
    String open;
    String domain;
    String ips;
    String week;
    String hour;
    if (configFileModified) {
      in = new FileInputStream(realPathResolver.get(Constants.FIREWALL_CONFIGPATH));
      p.load(in);
      in.close();
    }
    open = p.getProperty(property_firewall_open);
    domain = p.getProperty(property_firewall_domain);
    ips = p.getProperty(property_firewall_ips);
    week = p.getProperty(property_firewall_week);
    hour = p.getProperty(property_firewall_hour);
    String[] ipArrays = StringUtils.split(ips, ",");
    String[] weekArrays = StringUtils.split(week, ",");
    String[] hourArrays = StringUtils.split(hour, ",");

    String requestIp = RequestUtils.getIpAddr(request);
    if (open.equals("1")) {
      if (!isAuthDomain(domain, request.getServerName())) {
        return false;
      } else {
        if (!isAuthIp(ipArrays, requestIp)) {
          return false;
        } else {
          if (!isAuthWeek(weekArrays)) {
            return false;
          } else {
            if (!isAuthHour(hourArrays)) {
              return false;
            }
          }
        }
      }
    }
    return true;
  }
コード例 #3
0
ファイル: CosMultipartRequest.java プロジェクト: qzzsunly/cms
  /**
   * Constructs a new MultipartRequest to handle the specified request, saving any uploaded files to
   * the given directory, and limiting the upload size to the specified length. If the content is
   * too large, an IOException is thrown. This constructor actually parses the
   * <tt>multipart/form-data</tt> and throws an IOException if there's any problem reading or
   * parsing the request.
   *
   * <p>To avoid file collisions, this constructor takes an implementation of the FileRenamePolicy
   * interface to allow a pluggable rename policy.
   *
   * @param request the servlet request.
   * @param saveDirectory the directory in which to save any uploaded files.
   * @param maxPostSize the maximum size of the POST content.
   * @param encoding the encoding of the response, such as ISO-8859-1
   * @param policy a pluggable file rename policy
   * @exception IOException if the uploaded content is larger than <tt>maxPostSize</tt> or there's a
   *     problem reading or parsing the request.
   */
  public CosMultipartRequest(
      HttpServletRequest request,
      String saveDirectory,
      int maxPostSize,
      String encoding,
      FileRenamePolicy policy)
      throws IOException {
    // Sanity check values
    if (request == null) throw new IllegalArgumentException("request cannot be null");
    if (saveDirectory == null) throw new IllegalArgumentException("saveDirectory cannot be null");
    if (maxPostSize <= 0) {
      throw new IllegalArgumentException("maxPostSize must be positive");
    }

    // Save the dir
    File dir = new File(saveDirectory);

    // Check saveDirectory is truly a directory
    if (!dir.isDirectory()) throw new IllegalArgumentException("Not a directory: " + saveDirectory);

    // Check saveDirectory is writable
    if (!dir.canWrite()) throw new IllegalArgumentException("Not writable: " + saveDirectory);

    // Parse the incoming multipart, storing files in the dir provided,
    // and populate the meta objects which describe what we found
    MultipartParser parser = new MultipartParser(request, maxPostSize, true, true, encoding);

    // Some people like to fetch query string parameters from
    // MultipartRequest, so here we make that possible.  Thanks to
    // Ben Johnson, [email protected], for the idea.
    if (request.getQueryString() != null) {
      // Let HttpUtils create a name->String[] structure
      Map<String, String[]> queryParameters =
          RequestUtils.parseQueryString(request.getQueryString());
      // For our own use, name it a name->Vector structure
      for (Entry<String, String[]> entry : queryParameters.entrySet()) {
        parameters.put(entry.getKey(), Arrays.asList(entry.getValue()));
      }
    }

    Part part;
    while ((part = parser.readNextPart()) != null) {
      String name = part.getName();
      if (name == null) {
        throw new IOException("Malformed input: parameter name missing (known Opera 7 bug)");
      }
      if (part.isParam()) {
        // It's a parameter part, add it to the vector of values
        ParamPart paramPart = (ParamPart) part;
        String value = paramPart.getStringValue();
        List<String> existingValues = parameters.get(name);
        if (existingValues == null) {
          existingValues = new ArrayList<String>();
          parameters.put(name, existingValues);
        }
        existingValues.add(value);
      } else if (part.isFile()) {
        // It's a file part
        FilePart filePart = (FilePart) part;
        String fileName = filePart.getFileName();
        if (fileName != null) {
          filePart.setRenamePolicy(policy); // null policy is OK
          // The part actually contained a file
          filePart.writeTo(dir);
          files.put(
              name,
              new UploadedFile(
                  dir.toString(), filePart.getFileName(), fileName, filePart.getContentType()));
        } else {
          // The field did not contain a file
          files.put(name, new UploadedFile(null, null, null, null));
        }
      }
    }
  }