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

📄 configurationwebhandler.java

📁 解觖java技术中后台无法上传数给的情况
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                        node.setText(mailinterceptor_implementation);
                    } else if (node.getName().equals("contentinterceptor_implementation")) {
                        node.setText(contentinterceptor_implementation);
                    } else if (node.getName().equals("loginidinterceptor_implementation")) {
                        node.setText(loginidinterceptor_implementation);
                    }
                }
            }
        }
        saveDocument(document, strPathName + "mvncore.xml");
        request.setAttribute("action", "updatemvncore");
    }

    public void updateUrlPattern(GenericRequest request)
        throws BadInputException, DocumentException, IOException,
        AssertionException, AuthenticationException, DatabaseException {

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

        String admin_url = GenericParamUtil.getParameterSafe(request, "admin_url", true);
        String user_url = GenericParamUtil.getParameterSafe(request, "user_url", true);

        String strPathName = FileUtil.getServletClassesPath();
        SAXReader reader = new SAXReader();
        String xmlFilePath = strPathName + "mvnforum.xml";
        Document document = reader.read(new File(xmlFilePath));

        Element root = document.getRootElement();
        for (int i = 0; i < root.nodeCount(); i++) {
            Node node = root.node(i);
            //log.debug("Node " + i + " = " + node.getName());
            if (node.getNodeTypeName().equals("Element")) {
                if (node.getName().equals("adminmoduleconfig")) {
                    Node subElement = ((Element) node).element("url_pattern");
                    //log.debug("sub element " + subElement);
                    subElement.setText(admin_url);
                } else if (node.getName().equals("usermoduleconfig")) {
                    Node subElement = ((Element) node).element("url_pattern");
                    //log.debug("sub element " + subElement);
                    subElement.setText(user_url);
                }
            }
        }

        saveDocument(document, xmlFilePath);
        request.setAttribute("action", "updateurls");
    }

    public void configBackupProcess(GenericRequest request)
        throws IOException, AssertionException, DatabaseException, AuthenticationException {

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

        String servletClassPath = FileUtil.getServletClassesPath();

        String mvncoreFileName = servletClassPath + File.separator + "mvncore.xml";
        String mvnforumFileName = servletClassPath + File.separator + "mvnforum.xml";

        String pattern = "yyyy-MM-dd_HH-mm-ss";
        String nowDesc = DateUtil.format(new Date(), pattern);
        String newMVNCoreFileName = servletClassPath + File.separator + "mvncore_" + nowDesc + ".xml";
        String newMVNForumFileName = servletClassPath + File.separator + "mvnforum_" + nowDesc + ".xml";

        // We don't have to check files here, we check it in FileUtil.copyFile
        FileUtil.copyFile(mvncoreFileName, newMVNCoreFileName, false);
        FileUtil.copyFile(mvnforumFileName, newMVNForumFileName, false);

        File newMVNCoreFile = new File(newMVNCoreFileName);
        File newMVNForumFile = new File(newMVNForumFileName);

        request.setAttribute("MVNCoreFileName", newMVNCoreFile.getAbsolutePath());
        request.setAttribute("MVNForumFileName", newMVNForumFile.getAbsolutePath());
        request.setAttribute("step", "Backup");
    }

    private void saveDocument(Document doc, String fileName) throws IOException {
        XMLWriter writer = new XMLWriter(new FileWriter(fileName));
        writer.write(doc);
        writer.close();
    }

    public void prepareEditTemplate(GenericRequest request)
        throws AuthenticationException, DatabaseException, AssertionException,
        IOException, FileNotFoundException, BadInputException {

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

        String templateName = GenericParamUtil.getParameterSafe(request, "template", false);
        StringUtil.checkGoodName(templateName);
        String subject = "";
        String body = "";
        final String SUBJECT_SUFFIX = "-subject.ftl";
        final String BODY_SUFFIX = "-body.ftl";

        if (templateName.equals("")) {
            templateName = MVNForumGlobal.TEMPLATE_SENDACTIVATECODE_PREFIX;
        }
        // checking valid input here
        if ((templateName.equals(MVNForumGlobal.TEMPLATE_FORGOTPASSWORD_PREFIX) == false) &&
            (templateName.equals(MVNForumGlobal.TEMPLATE_SENDACTIVATECODE_PREFIX) == false) &&
            (templateName.equals(MVNForumGlobal.TEMPLATE_WATCHMAIL_PREFIX) == false) ) {
            throw new AssertionException("Does not accept invalid input: " + templateName);
        }

        String templateDir = MVNForumConfig.getTemplateDir();
        String subjectFileName = templateDir + File.separator + templateName + SUBJECT_SUFFIX;
        String bodyFileName    = templateDir + File.separator + templateName + BODY_SUFFIX;

//        subject = new String(FileUtil.getBytes(new FileInputStream(subjectFileName)), "UTF-8");
//        body    = new String(FileUtil.getBytes(new FileInputStream(bodyFileName)) , "UTF-8");
        subject = FileUtil.readFile(subjectFileName, "UTF-8");
        body    = FileUtil.readFile(bodyFileName, "UTF-8");

        request.setAttribute("TemplateSubject", subject);
        request.setAttribute("TemplateBody", body);
    }

    public void processEditTemplate(GenericRequest request)
        throws DatabaseException, AuthenticationException, IOException,
        FileNotFoundException, AssertionException, BadInputException, TemplateException {

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

        final String SUBJECT_SUFFIX = "-subject.ftl";
        final String BODY_SUFFIX = "-body.ftl";

        String templateName = GenericParamUtil.getParameterSafe(request, "template", true);
        StringUtil.checkGoodName(templateName);
        // checking valid input here
        if ((templateName.equals(MVNForumGlobal.TEMPLATE_FORGOTPASSWORD_PREFIX) == false) &&
            (templateName.equals(MVNForumGlobal.TEMPLATE_SENDACTIVATECODE_PREFIX) == false) &&
            (templateName.equals(MVNForumGlobal.TEMPLATE_WATCHMAIL_PREFIX) == false) ) {
            throw new AssertionException("Does not accept invalid input: " + templateName);
        }

        String subject = GenericParamUtil.getParameter(request, "subject", true);
        String body    = GenericParamUtil.getParameter(request, "body", true);

        String templateDir = MVNForumConfig.getTemplateDir();

        String subjectFileName = templateDir + File.separator + templateName + SUBJECT_SUFFIX;
        String bodyFileName    = templateDir + File.separator + templateName + BODY_SUFFIX;

        // just for test freemakers
        SimpleHash root = new SimpleHash();
        try {
            Configuration cfg = MVNForumConfig.getFreeMarkerConfiguration();
            if (templateName.equals(MVNForumGlobal.TEMPLATE_SENDACTIVATECODE_PREFIX)) {
                root.put("serverName", "");
                root.put("MVNForumInfo", "");
                root.put("activationUrl", "");
                root.put("memberName", "");
                root.put("activateCode", "");
            } else if (templateName.equals(MVNForumGlobal.TEMPLATE_FORGOTPASSWORD_PREFIX)) {
                root.put("serverName", "");
                root.put("MVNForumInfo", "");
                root.put("passwordResetUrl", "");
                root.put("memberName", "");
                root.put("currentTempPassword", "");
            } else if (templateName.equals(MVNForumGlobal.TEMPLATE_WATCHMAIL_PREFIX)) {
                root.put("lastSent", "");
                root.put("now", "");
                root.put("forumBase", "");

                ArrayList list = new ArrayList();
                SimpleHash subroot = new SimpleHash();
                subroot.put("leader", true);
                subroot.put("categoryName", "");
                subroot.put("forumName", "");
                subroot.put("threadTopic", "");
                subroot.put("memberName", "");
                subroot.put("lastPostMemberName", "");
                subroot.put("threadLastPostDate", "");
                subroot.put("threadUrl", "");
                list.add(subroot);

                root.put("threadWatchList", list);
            } else {
                throw new AssertionException("Does not accept invalid input: " + templateName);
            }
            StringReader subjectReader = new StringReader(subject);
            StringReader bodyReader = new StringReader(body);

            Template subjectTemplate = new Template("", subjectReader, cfg, "");
            StringWriter subjectWriter = new StringWriter(256);
            subjectTemplate.process(root, subjectWriter);

            Template bodyTemplate = new Template("", bodyReader, cfg, "");
            StringWriter bodyWriter = new StringWriter(1024);
            bodyTemplate.process(root, bodyWriter);
        } catch(TemplateException ex) {
            throw ex;
        }
        FileUtil.writeFile(subject, subjectFileName, "UTF-8");
        FileUtil.writeFile(body, bodyFileName, "UTF-8");

        request.setAttribute("Successful", "true");
        request.setAttribute("TemplateSubject", subject);
        request.setAttribute("TemplateBody", body);
    }

    public void commitConfig(GenericRequest request)
        throws DatabaseException, AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();
        MVNForumConfig.reload();
        MVNCoreConfig.reload();
        request.setAttribute("action", "commit");
    }
}

⌨️ 快捷键说明

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