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

📄 companywebhandler.java

📁 解觖java技术中后台无法上传数给的情况
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

        // now the image has been save, go ahead and update database
        StringBuffer bufferVirtualFile = new StringBuffer(128);
        bufferVirtualFile.append(MVNForumGlobal.UPLOADED_COMPANY_DIR);
        bufferVirtualFile.append("/").append(companyID).append("/").append("style.css");
        String virtualFile =  bufferVirtualFile.toString();

        try {
            DAOFactory.getCompanyDAO().updateCompanyCss(companyID, virtualFile);
        } catch (DatabaseException ex) {// we dont need to catch ObjectNotFoundException since the companyID is already exits
            log.fatal("Assertion in CompanyWebHandler.processChangeCss");// we dont want it to be here
            // need to delete the file if the above database task failed
            FileUtil.deleteFile(cssFile);
            throw ex;
        }
        CompanyBean companyBean = null;
        try {
            companyBean = DAOFactory.getCompanyDAO().getCompany(companyID);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object[] {new Integer(companyID)});
            throw new ObjectNotFoundException(localizedMessage);
        }
        request.setAttribute("CompanyBean", companyBean);
    }

    public void prepare(GenericRequest request)
        throws ObjectNotFoundException, BadInputException, DatabaseException, AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

        int companyID = GenericParamUtil.getParameterInt(request, "companyid");

        CompanyBean companyBean = null;
        try {
            companyBean = DAOFactory.getCompanyDAO().getCompany(companyID);
        } catch (ObjectNotFoundException e) {
            Locale locale = I18nUtil.getLocaleInRequest(request);
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object[] {new Integer(companyID)});
            throw new ObjectNotFoundException(localizedMessage);
        }
        request.setAttribute("CompanyBean", companyBean);
    }

    public void processDelete(ServletContext context, GenericRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

        // primary key column(s)
        int companyID = GenericParamUtil.getParameterInt(request, "companyid");

        // now check the password
        MyUtil.ensureCorrectCurrentPassword(request);

        try {
            DAOFactory.getCompanyDAO().delete(companyID);
        } catch (ObjectNotFoundException e ) {
            Locale locale = I18nUtil.getLocaleInRequest(request);
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object[] {new Integer(companyID)});
            throw new ObjectNotFoundException(localizedMessage);
        }
        DAOFactory.getMemberCompanyDAO().delete_inCompany(companyID);

        // now delete the folder for this company
        StringBuffer bufferCompanyFolder = new StringBuffer(128);
        bufferCompanyFolder.append(context.getRealPath(MVNForumGlobal.UPLOADED_COMPANY_DIR));
        bufferCompanyFolder.append(File.separatorChar).append(companyID);
        String companyFolder = bufferCompanyFolder.toString();
        try {
            FileUtil.deleteDir(new File(companyFolder));
        } catch (IOException ioe) {
        }

        // now update the search index
        CompanyIndexer.scheduleDeleteCompanyTask(companyID);
    }

    /**
     * This method supports sorting base on many criteria
     */
    public void prepareShowCompanyManagement(GenericRequest request)
        throws DatabaseException, AssertionException, BadInputException, AuthenticationException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

        // for sort and order stuff
        String sort  = GenericParamUtil.getParameter(request, "sort");
        String order = GenericParamUtil.getParameter(request, "order");
        if (sort.length() == 0) sort = "CompanyCreationDate";
        if (order.length()== 0) order = "DESC";

        // we continue
        int postsPerPage = onlineUser.getPostsPerPage();
        int offset = 0;
        try {
            offset = GenericParamUtil.getParameterInt(request, "offset");
        } catch (BadInputException e) {
            // do nothing
        }

        Locale locale = I18nUtil.getLocaleInRequest(request);

        int totalCompanies = DAOFactory.getCompanyDAO().getNumberOfCompanies();
        if (offset > totalCompanies) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("The offset is not allowed to be greater than total companies.");
        }

        Collection companyBeans = DAOFactory.getCompanyDAO().getCompanies_withSortSupport_limit(offset, postsPerPage, sort, order);

        request.setAttribute("CompanyBeans", companyBeans);
        request.setAttribute("TotalCompanies", new Integer(totalCompanies));
        request.setAttribute("offset", new Integer(offset));
    }

    public void processSearch(GenericRequest request)
        throws BadInputException, IOException, DatabaseException, ObjectNotFoundException,
        AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

        String companyNameKey  = GenericParamUtil.getParameter(request, "companyname", false);
        String companyAddressKey  = GenericParamUtil.getParameter(request, "companyaddress", false);
        String companyDateKey  = GenericParamUtil.getParameter(request, "companycreationdate", false);

        Locale locale = I18nUtil.getLocaleInRequest(request);

        int defaultRows = onlineUser.getPostsPerPage();

        int offset = GenericParamUtil.getParameterUnsignedInt(request, "offset", 0);
        int rows   = GenericParamUtil.getParameterUnsignedInt(request, "rows", defaultRows);
        if (rows == 0) {
            rows = defaultRows;// fix NullPointerException when rows = 0
        }

        // offset should be even when divide with rowsToReturn
        offset = (offset / rows) * rows;

        CompanySearchQuery query = new CompanySearchQuery();

        if (companyNameKey.length() > 0) {
            query.setCompanyNameKey(companyNameKey);
        } else if (companyAddressKey.length() > 0){
            query.setCompanyAddressKey(companyAddressKey);
        } else {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_search.key_is_null");
            throw new BadInputException(localizedMessage);
        }
        // dd/MM/yyyy :: default date string
        /*if ( companyDateKey.equals("dd/MM/yyyy")) {
            // do nothing
        } else if (companyDateKey.length() > 0){
            query.setCompanyDateKey(new Timestamp(GenericParamUtil.getParameterDate(request,"companycreationdate").getTime()));
        }*/

        int searchDate        = GenericParamUtil.getParameterUnsignedInt(request, "date", CompanySearchQuery.SEARCH_ANY_DATE);
        int searchBeforeAfter = GenericParamUtil.getParameterInt(request, "beforeafter", CompanySearchQuery.SEARCH_NEWER);

        if ((searchDate != CompanySearchQuery.SEARCH_ANY_DATE) && (searchDate < 365 * 10)) { // 10 years
            long deltaTime = DateUtil.DAY * searchDate;

            Timestamp now = DateUtil.getCurrentGMTTimestamp();
            Timestamp from = null;
            Timestamp to = null;

            long currentTime = now.getTime();

            if (searchBeforeAfter == CompanySearchQuery.SEARCH_NEWER) {
                from = new Timestamp(currentTime - deltaTime);
            } else {// older
                to = new Timestamp(currentTime - deltaTime);
            }

            query.setFromCompanyDateKey(from);
            query.setToCompanyDateKey(to);
        }


        query.searchDocuments(offset, rows);
        int hitCount = query.getHitCount();
        Collection result = query.getCompanyResult();

        if (offset > hitCount) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows");
            throw new BadInputException(localizedMessage);
        }

        request.setAttribute("offset", new Integer(offset));
        request.setAttribute("rows", new Integer(rows));
        request.setAttribute("TotalCompanies", new Integer(hitCount));
        request.setAttribute("CompanyBeans", result);
        request.setAttribute("CompanyName", companyNameKey);
        request.setAttribute("CompanyAddress", companyAddressKey); //strCompanyAddress);
        request.setAttribute("CompanyCreationDate",companyDateKey); //strCompanyCreationDate);
        request.setAttribute("CompanyModifiedDate", ""); //strCompanyModifiedDate);
        request.setAttribute("FromCompanyCreationDate", ""); // strFromCompanyCreationDate);
        request.setAttribute("ToCompanyCreationDate", ""); // strToCompanyCreationDate);
    }
}

⌨️ 快捷键说明

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