Package com.vst.webapp.action

Source Code of com.vst.webapp.action.ShowHintController

package com.vst.webapp.action;

import com.vst.model.Hint;
import com.vst.service.HintManager;
import com.vst.util.FileHelper;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.sql.Blob;
import java.util.ArrayList;
import java.util.List;

/**
* Created by IntelliJ IDEA.
* User: ALEXEI
* Date: 18.03.2008
* Time: 21:29:37
* To change this template use File | Settings | File Templates.
*/
public class ShowHintController implements Controller {
    private HintManager hintManager = null;

    public void setHintManager(HintManager hintManager) {
        this.hintManager = hintManager;
    }

    public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        String questionId = httpServletRequest.getParameter("questionId");
        List hints = new ArrayList();
        if (questionId != null) {
            hints = hintManager.getHintByQuestionId(questionId);
        }

        for (int i = 0; i < hints.size(); i++) {
            Hint hint = (Hint) hints.get(i);
            if (hint.getWayToPhoto() != null && !hint.getWayToPhoto().trim().equals("")) {
                File file = new File(FileHelper.getCurrentPath(httpServletRequest) + hint.getWayToPhoto());
                if (file.exists()) {
                    file.delete();
                }
                file.createNewFile();
                FileOutputStream fileOutputStream = new FileOutputStream(FileHelper.getCurrentPath(httpServletRequest) + hint.getWayToPhoto());
                Blob blob = hint.getPhotoBlob();
                byte[] bufer = new byte[62000];
                InputStream inputStream = blob.getBinaryStream();
                while (inputStream.read(bufer) != -1) {
                    fileOutputStream.write(bufer);
                }
                inputStream.close();
                fileOutputStream.close();
            }
        }

        return new ModelAndView("showHint", "hints", hints);
    }
}
TOP

Related Classes of com.vst.webapp.action.ShowHintController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.