com.pureinfo.tgirls.servlet.GetScriptServlet.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.tgirls.servlet.GetScriptServlet.java

Source

/**
 * PureInfo TGirls
 * @(#)GetUserInfoScriptServlet.java   1.0 2009-3-5
 * 
 * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. 
 * All rights reserved, see the license file.
 * 
 * www.pureinfo.com.cn
 */

package com.pureinfo.tgirls.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.pureinfo.tgirls.utils.script.ScriptManager;
import com.pureinfo.tgirls.utils.script.ScriptManager.ScriptType;

public class GetScriptServlet extends HttpServlet {

    private Logger logger = Logger.getLogger(this.getClass().getName());

    /**
     * Comment for <code>serialVersionUID</code>
     */
    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String scriptType = request.getParameter("scriptType");
        if (StringUtils.isEmpty(scriptType)) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }

        String location = null;
        String userId = null;
        String photoId = null;
        ScriptType st = null;//

        try {
            st = ScriptType.getScriptType(Integer.parseInt(scriptType));
        } catch (Exception e) {
        }

        switch (st) {
        case UserInfo:
            userId = request.getParameter("utid");
            location = ScriptManager.mapUserInfoScriptLocation(userId);
            break;
        case UserUpload:
            userId = request.getParameter("utid");
            location = ScriptManager.mapUserUploadScriptLocation(userId);
            break;
        case UserBuy:
            userId = request.getParameter("utid");
            location = ScriptManager.mapUserBuyScriptLocation(userId);
            break;
        case Pic:
            photoId = request.getParameter("picId");
            location = ScriptManager.mapPhotoScriptLocation(photoId);
            break;

        default:
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }

        if (StringUtils.isEmpty(location)) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }

        location += "?version=" + Math.random();
        logger.debug("return script:" + location);

        response.setHeader("Location", location);
        response.setHeader("Content-Encoding", "gzip");
        response.setStatus(HttpServletResponse.SC_SEE_OTHER);
        response.setHeader("Cache-Control", "no-cache"); //HTTP 1.1
        response.setHeader("Pragma", "no-cache"); //HTTP 1.0
        response.setDateHeader("Expires", -1);
        response.setDateHeader("max-age", 0);

        return;

    }

}