⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transformstring.java

📁 在线考试系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package jinghua;

import java.io.*;
import java.sql.*;

// Referenced classes of package jinghua:
//            JinghuaConn

public class TransformString
{
    private String clientString;
    private Connection con;
    private int dBID;
    private StringBuffer dbg;
    private String message;
    private String serverString;

    public TransformString()
    {
        message = "OK";
        dbg = new StringBuffer("Debug:");
        clientString = "";
        serverString = "";
        dBID = -1;
    }

    public static String DeleteBR(String test)
    {
        if(test == null)
            return new String("No data");
        String temp = test;
        int pos1 = 0;
        int pos2 = 0;
        int pos3 = 0;
        System.out.println("test0=" + test);
        while(pos1 != -1 || pos2 != -1) 
        {
            temp = temp.trim();
            pos1 = temp.lastIndexOf("<br>");
            pos2 = temp.lastIndexOf("<BR>");
            if(pos1 > 0)
            {
                if(pos1 >= temp.length() - 5)
                    temp = temp.substring(0, pos1);
                else
                    pos1 = -1;
            } else
            if(pos1 == 0)
            {
                temp = temp.substring(4);
                temp = temp.trim();
            }
            if(pos2 > 0)
            {
                if(pos2 >= temp.length() - 5)
                    temp = temp.substring(0, pos2);
                else
                    pos2 = -1;
            } else
            if(pos2 == 0)
            {
                temp = temp.substring(4);
                temp = temp.trim();
            }
        }
        return temp;
    }

    public static String Replace(String source, String oldString, String newString)
    {
        StringBuffer output = new StringBuffer();
        int lengthOfSource = source.length();
        int lengthOfOld = oldString.length();
        int posStart;
        int i;
        for(posStart = 0; (i = source.indexOf(oldString, posStart)) >= 0; posStart = i + lengthOfOld)
        {
            output.append(source.substring(posStart, i));
            output.append(newString);
        }

        if(posStart < lengthOfSource)
            output.append(source.substring(posStart));
        return output.toString();
    }

    public static String ReplaceFirst(String source, String oldString, String newString)
    {
        StringBuffer output = new StringBuffer();
        int lengthOfSource = source.length();
        int lengthOfOld = oldString.length();
        int posStart = 0;
        int pos;
        if((pos = source.indexOf(oldString, posStart)) >= 0)
        {
            output.append(source.substring(posStart, pos));
            output.append(newString);
            posStart = pos + lengthOfOld;
        }
        if(posStart < lengthOfSource)
            output.append(source.substring(posStart));
        return output.toString();
    }

    public static String TransformSelction(String strHtml, int dBID)
    {
        String tempfile = strHtml;
        int fend = 0;
        int pos = 0;
        int answer = 0;
        int ansbase = 65;
        String Answer[] = {
            "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", 
            "K", "L", "M", "N"
        };
        while(pos != -1) 
        {
            pos = tempfile.indexOf("##", pos);
            if(pos > 0)
            {
                String tempans = "<input type=\"radio\" name=\"radio" + dBID + "\"  value=\"" + Answer[answer++] + "\">";
                tempfile = ReplaceFirst(tempfile, "##", tempans);
                pos += 50;
            }
        }
        return tempfile;
    }

    public void TransformSelction()
    {
        if(clientString == null)
            return;
        String tempfile = serverString;
        int fend = 0;
        int pos = 0;
        int answer = 1;
        while(pos != -1) 
        {
            pos = tempfile.indexOf("##", pos);
            if(pos > 0)
            {
                String tempans = "<input type=\"radio\" name=\"radio" + dBID + "\"  value=\"" + answer + "\">";
                answer++;
                tempfile = ReplaceFirst(tempfile, "##", tempans);
                pos += 50;
            }
        }
        serverString = tempfile;
    }

    public synchronized void UpdateQuest()
    {
        PreparedStatement ps = null;
        ps = con.prepareStatement("update question set QuestText=? where ID=" + dBID);
        serverString = Replace(serverString, "'", "''");
        ps.setString(1, serverString);
        ps.executeUpdate();
        if(ps == null)
            break MISSING_BLOCK_LABEL_106;
        ps.close();
        break MISSING_BLOCK_LABEL_105;
        SQLException sqlEx;
        sqlEx;
        message = "Update Question Text Error!";
        dbg.append("Update Question Text Error!");
        ps = null;
        break MISSING_BLOCK_LABEL_219;
        SQLException e;
        e;
        message = "Update Question Text Error!";
        dbg.append("Update Question Text Error!");
        e.printStackTrace();
        if(ps == null)
            break MISSING_BLOCK_LABEL_170;
        ps.close();
        break MISSING_BLOCK_LABEL_169;
        SQLException sqlEx;
        sqlEx;
        message = "Update Question Text Error!";
        dbg.append("Update Question Text Error!");
        ps = null;
        break MISSING_BLOCK_LABEL_219;
        Exception exception;
        exception;
        if(ps == null)
            break MISSING_BLOCK_LABEL_215;
        ps.close();
        break MISSING_BLOCK_LABEL_214;
        SQLException sqlEx;
        sqlEx;
        message = "Update Question Text Error!";
        dbg.append("Update Question Text Error!");
        ps = null;
        throw exception;
        return;
    }

    public synchronized int UploadPic(String fileName)
    {
        int photoID;
        FileInputStream fis;
        BufferedInputStream bis;
        PreparedStatement ps;
        photoID = -1;
        File file = null;
        fis = null;
        bis = null;
        ps = null;
        File file = new File(fileName);
        fis = new FileInputStream(file);
        bis = new BufferedInputStream(fis);
        ps = con.prepareStatement("insert into photos(photo,QuestID) values(?,?)");
        ps.setBinaryStream(1, bis, bis.available());
        ps.setInt(2, dBID);
        ps.execute();
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("select LAST_INSERT_ID() as newID");
        if(rs.next())
            photoID = rs.getInt("newID");
        dbg.append("File Name is:" + fileName + "   Is OK\n");
        if(ps == null)
            break MISSING_BLOCK_LABEL_245;
        ps.close();
        break MISSING_BLOCK_LABEL_192;
        SQLException sqlEx;
        sqlEx;
        ps = null;
        if(bis == null)
            break MISSING_BLOCK_LABEL_218;
        bis.close();
        break MISSING_BLOCK_LABEL_217;
        IOException e;
        e;
        e.printStackTrace();
        if(fis == null)
            break MISSING_BLOCK_LABEL_244;
        fis.close();
        break MISSING_BLOCK_LABEL_243;
        e;
        e.printStackTrace();
        break MISSING_BLOCK_LABEL_783;
        e;
        new StringBuffer();
        this;
        JVM INSTR dup_x1 ;
        message;
        append();
        e.toString();
        append();
        toString();
        message;
        dbg.append(e.toString());
        e.printStackTrace();
        if(ps == null)
            break MISSING_BLOCK_LABEL_377;
        ps.close();
        break MISSING_BLOCK_LABEL_324;
        SQLException sqlEx;
        sqlEx;
        ps = null;
        if(bis == null)
            break MISSING_BLOCK_LABEL_350;
        bis.close();
        break MISSING_BLOCK_LABEL_349;
        IOException e;
        e;
        e.printStackTrace();
        if(fis == null)
            break MISSING_BLOCK_LABEL_376;
        fis.close();
        break MISSING_BLOCK_LABEL_375;
        e;
        e.printStackTrace();
        break MISSING_BLOCK_LABEL_783;
        FileNotFoundException e2;
        e2;
        new StringBuffer();
        this;
        JVM INSTR dup_x1 ;
        message;
        append();
        "File Name is:";
        append();
        fileName;
        append();
        "   Is Error\n";
        append();
        toString();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -