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

📄 shopservlet.java

📁 Sun公司Dream项目
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                                int existingRecordNum = Integer.parseInt(rightsInfoTo.verbElements[k].verbArgValue);

                                Integer argToVal = new Integer(existingRecordNum+numRecordInt);

                                rightsInfoTo.verbElements[k].verbArgValue = argToVal.toString();

                            }

                        }

                    }

                    if (playMode.equals("UnrestrictedPlay")){

                        if (!fwdInsert) {

                            VerbElement fwdElement = new VerbElement();

                            fwdElement.verbName = "ForwardPlay";

                            fwdElement.verbArgName = "COUNT";

                            fwdElement.verbArgValue = numPlays;

                            rightsInfoTo.InsertVerbElement (fwdElement);

                        }

                        if (!revInsert) {

                            VerbElement revElement = new VerbElement();

                            revElement.verbName = "ReversePlay";

                            revElement.verbArgName = "COUNT";

                            revElement.verbArgValue = numPlays;

                            rightsInfoTo.InsertVerbElement (revElement);

                        }

                    }

                } else {

                    if (playMode.equals("UnrestrictedPlay"))

                        numRights = 4;

                    else 

                        numRights = 2;

                    rightsInfoTo.verbElements = new VerbElement[numRights];

                    rightsInfoTo.verbElements[0] = new VerbElement();

                    rightsInfoTo.verbElements[0].verbName = "SimplePlay";

                    rightsInfoTo.verbElements[0].verbArgName = "COUNT";

                    rightsInfoTo.verbElements[0].verbArgValue = numPlays;

                    rightsInfoTo.verbElements[1] = new VerbElement();

                    rightsInfoTo.verbElements[1].verbName = "Record";

                    rightsInfoTo.verbElements[1].verbArgName = "COUNT";

                    rightsInfoTo.verbElements[1].verbArgValue = numRecord;

                    if (playMode.equals("UnrestrictedPlay")){

                        rightsInfoTo.verbElements[2] = new VerbElement();

                        rightsInfoTo.verbElements[2].verbName = "ForwardPlay";

                        rightsInfoTo.verbElements[2].verbArgName = "COUNT";

                        rightsInfoTo.verbElements[2].verbArgValue = numPlays;

                        rightsInfoTo.verbElements[3] = new VerbElement();

                        rightsInfoTo.verbElements[3].verbName = "ReversePlay";

                        rightsInfoTo.verbElements[3].verbArgName = "COUNT";

                        rightsInfoTo.verbElements[3].verbArgValue = numPlays;

                    }                    

                }

            } else {

                System.out.println("ShopServlet: doTransferRights : creating new rightsInfo");

                rightsInfoTo = new RightsInfo();

                rightsInfoTo.userID = transferTo;

                rightsInfoTo.movieName = itemID;

                rightsInfoTo.movieid = 0;

                rightsInfoTo.rightsType = 0;

                rightsInfoTo.expired = false;

                rightsInfoTo.remainingRights = 1;

                rightsInfoTo.rightsStartDate = new Date();

                rightsInfoTo.rightsEndDate = new Date(rightsInfoTo.rightsStartDate.getTime() +  1000 * 60 * 60 * 24 * 365);

                if (playMode.equals("UnrestrictedPlay"))

                    numRights = 4;

                else

                    numRights = 2;

                rightsInfoTo.verbElements = new VerbElement[numRights];

                rightsInfoTo.verbElements[0] = new VerbElement();

                rightsInfoTo.verbElements[0].verbName = "SimplePlay";

                rightsInfoTo.verbElements[0].verbArgName = "COUNT";

                rightsInfoTo.verbElements[0].verbArgValue = numPlays;

                rightsInfoTo.verbElements[1] = new VerbElement();

                rightsInfoTo.verbElements[1].verbName = "Record";

                rightsInfoTo.verbElements[1].verbArgName = "COUNT";

                rightsInfoTo.verbElements[1].verbArgValue = numRecord;

                if (playMode.equals("UnrestrictedPlay")){

                    rightsInfoTo.verbElements[2] = new VerbElement();

                    rightsInfoTo.verbElements[2].verbName = "ForwardPlay";

                    rightsInfoTo.verbElements[2].verbArgName = "COUNT";

                    rightsInfoTo.verbElements[2].verbArgValue = numPlays;

                    rightsInfoTo.verbElements[3] = new VerbElement();

                    rightsInfoTo.verbElements[3].verbName = "ReversePlay";

                    rightsInfoTo.verbElements[3].verbArgName = "COUNT";

                    rightsInfoTo.verbElements[3].verbArgValue = numPlays;

                }                

            }

        }

        //System.out.println("RightsInfo "+rightsInfo.userID+" "+rightsInfo.movieName+" "+rightsInfo.verbElements[0].verbName);

        System.out.println("Final RightsInfoFrom");

        printRightsInfo(rightsInfoFrom);

        System.out.println("Final RightsInfoTo");

        printRightsInfo(rightsInfoTo);



        sms.updateFixedRightsInfo(rightsInfoFrom);

        sms.updateFixedRightsInfo(rightsInfoTo);        

        

        forwardToJSP(request, response, jspPath);

    }



    protected void doFairUse(

            HttpServletRequest request,

            HttpServletResponse response)

            throws ServletException, IOException, ShopException, SQLException {

        

        String jspPath = request.getParameter("jsp_path");

        if (jspPath == null)

            jspPath = "/shop/index.jsp";

        System.out.println("Print inputs to ShopServlet : doFairUse ");

        String userID = request.getParameter("userID");

        System.out.println("In doBuyRights : userID : "+userID);

        String itemID = request.getParameter("item_id");

        System.out.println("In doBuyRights : item_id : "+itemID);

        String itemTitle = request.getParameter("item_title");

        logStrMessage("itemTitle",itemTitle);        

        boolean criticalReview = false;

        boolean educationalUse = false;

        boolean parody  = false;

        boolean other  = false;

        String otherPurpose = "Did not specify";

        String address = null;

        if (request.getParameter("CriticalReview")!=null) {

            criticalReview = true;

        }

        if (request.getParameter("EducationalUse")!=null) {

            educationalUse = true;

        }        

        if (request.getParameter("Parody")!=null) {

            parody = true;

        }

        if (request.getParameter("Other")!=null) {

            other = true;

            otherPurpose = request.getParameter("OtherPurpose");

            logStrMessage("otherPurose", otherPurpose);

        }

        address = request.getParameter("Address");

        //TODO: Store identifying info such as purpose and address in a different database

        logStrMessage("address",address);

        

        RightsInfo rightsInfo = conductor1.getUserRightsForContent(userID,itemID);

        if (rightsInfo != null) {

            System.out.println("ShopServlet: doBuyRights : rightsInfo is not null");

            rightsInfo.remainingRights += 1;

            if (rightsInfo.verbElements !=null){

                boolean assertInsert = false;

                for (int k=0; k< rightsInfo.verbElements.length; k++) {

                    if (rightsInfo.verbElements[k].verbName.equals("ClearCopy") && rightsInfo.verbElements[k].verbArgName.equals("COUNT")) {

                        int existingPlayNum = Integer.parseInt(rightsInfo.verbElements[k].verbArgValue);

                        Integer argVal = new Integer(existingPlayNum+1);

                        rightsInfo.verbElements[k].verbArgValue = argVal.toString();

                    }

                }

                if (!assertInsert) {

                        VerbElement fuElement = new VerbElement();

                        fuElement.verbName = "ClearCopy";

                        fuElement.verbArgName = "COUNT";

                        fuElement.verbArgValue = "1";

                        rightsInfo.InsertVerbElement(fuElement);                    

                }

            } 

        } 

        

        printRightsInfo(rightsInfo);

        sms.updateFixedRightsInfo(rightsInfo);

        //conductor1.updateFairuseDB(rightsInfo);

        String faURL = conductor1.getFairuseUrl(itemID);

        //if content begins with rtsp://, forward to jsp_path

        logStrMessage("faURL",faURL);

        // else forward to fairuse_download.jsp with itemid, itemtitle and contenturl

        //if (!faURL.startsWith("rtsp://")) {

            jspPath = "/shop/download_fairuse.jsp?item_id="+itemID+"&item_title="+itemTitle+"&fa_url="+faURL;

        //}

        

        request.setAttribute("dispatcher", "ShopServlet");

        forwardToJSP(request, response, jspPath);

    }

    

    

    private void printRightsInfo (RightsInfo rightsInfo) {

        if (rightsInfo != null) {

            logStrMessage("rightsInfo.userID", rightsInfo.userID);

            logStrMessage("rightsInfo.movieName", rightsInfo.movieName);

            System.out.println("rightsInfo.expired "+rightsInfo.expired);

            System.out.println("rightsInfo.remainingRights"+rightsInfo.remainingRights);

            if (rightsInfo.rightsStartDate!=null)

                logStrMessage("rightsInfo.rightsStartDate",rightsInfo.rightsStartDate.toString());

            if (rightsInfo.rightsEndDate!=null)

                logStrMessage("rightsInfo.rightsEndDate",rightsInfo.rightsEndDate.toString());

            if (rightsInfo.verbElements != null) {

                for(int k=0; k<rightsInfo.verbElements.length; k++) {

                    if (rightsInfo.verbElements[k]!= null){

                        logStrMessage("rightsInfo.verbElements["+k+"].verbName = ", rightsInfo.verbElements[k].verbName);

                        logStrMessage("rightsInfo.verbElements["+k+"].verbArgName = ", rightsInfo.verbElements[k].verbArgName);

                        logStrMessage("rightsInfo.verbElements["+k+"].verbArgValue = ", rightsInfo.verbElements[k].verbArgValue);

                    }

                }

            }

        } else

            System.out.println("rightsInfo is null !!");

    }

    

    private void forwardToJSP(

            HttpServletRequest request,

            HttpServletResponse response,

            String jspPath)

            throws ServletException, ShopException {

        

        if (jspPath == null) {

            throw new ShopException(

                    ShopException.NULL_ARGUMENT,

                    "JSP path is not specified.");

        }

        

        try {

            getServletConfig().getServletContext().getRequestDispatcher(

                    jspPath).forward(

                    request,

                    response);

            

        } catch (java.io.IOException ioException) {

            ioException.printStackTrace();

            throw new ShopException(

                    ShopException.INTERNAL_ERROR,

                    "Error in sending resource: " + ioException.getMessage());

        }

        

    }



    

    

    private void logStrMessage (String varName, String varVal) {

        if (varVal == null)

            System.out.println("Warning : "+varName+" is null");

        else

            System.out.println("Value of "+varName+" is "+varVal);

    }

    

}

⌨️ 快捷键说明

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