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

📄 xwiki.java

📁 xwiki 源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        needsUpdate |= bclass.addBooleanField("use_email_verification", "Use eMail Verification", "yesno");        needsUpdate |= bclass.addTextField("smtp_server", "SMTP Server", 30);        needsUpdate |= bclass.addTextField("admin_email", "Admin eMail", 30);        needsUpdate |= bclass.addTextAreaField("validation_email_content", "Validation eMail Content", 72, 10);        needsUpdate |= bclass.addTextAreaField("confirmation_email_content", "Confirmation eMail Content", 72, 10);        needsUpdate |= bclass.addTextField("ad_clientid", "Advertisement Client ID", 60);        String content = doc.getContent();        if ((content == null) || (content.equals(""))) {            needsUpdate = true;            doc.setContent("1 XWiki Users");        }        if (needsUpdate)            saveDocument(doc, context);        return bclass;    }    public BaseClass getGroupClass(XWikiContext context) throws XWikiException {        XWikiDocument doc;        boolean needsUpdate = false;        try {            doc = getDocument("XWiki.XWikiGroups", context);        } catch (Exception e) {            doc = new XWikiDocument();            doc.setWeb("XWiki");            doc.setName("XWikiGroups");        }        BaseClass bclass = doc.getxWikiClass();        if (context.get("initdone") != null)            return bclass;        bclass.setName("XWiki.XWikiGroups");        needsUpdate |= bclass.addTextField("member", "Member", 30);        String content = doc.getContent();        if ((content == null) || (content.equals("")))            doc.setContent("1 XWiki Groups");        if (needsUpdate)            saveDocument(doc, context);        return bclass;    }    public BaseClass getRightsClass(String pagename, XWikiContext context) throws XWikiException {        XWikiDocument doc;        boolean needsUpdate = false;        try {            doc = getDocument("XWiki." + pagename, context);        } catch (Exception e) {            doc = new XWikiDocument();            doc.setWeb("XWiki");            doc.setName(pagename);        }        BaseClass bclass = doc.getxWikiClass();        if (context.get("initdone") != null)            return bclass;        bclass.setName("XWiki." + pagename);        needsUpdate |= bclass.addTextField("users", "Users", 80);        needsUpdate |= bclass.addTextField("groups", "Groups", 80);        needsUpdate |= bclass.addTextField("levels", "Levels", 80);        PropertyInterface allowProp = bclass.get("allow");        if ((allowProp != null) && (allowProp instanceof NumberClass)) {            bclass.removeField("allow");            needsUpdate = true;        }        needsUpdate |= bclass.addBooleanField("allow", "Allow/Deny", "allow");        String content = doc.getContent();        if ((content == null) || (content.equals("")))            doc.setContent("1 XWiki " + pagename + " Class");        if (needsUpdate)            saveDocument(doc, context);        return bclass;    }    public BaseClass getRightsClass(XWikiContext context) throws XWikiException {        return getRightsClass("XWikiRights", context);    }    public BaseClass getGlobalRightsClass(XWikiContext context) throws XWikiException {        return getRightsClass("XWikiGlobalRights", context);    }    public BaseClass getCommentsClass(XWikiContext context) throws XWikiException {        XWikiDocument doc;        boolean needsUpdate = false;        try {            doc = getDocument("XWiki.XWikiComments", context);        } catch (Exception e) {            doc = new XWikiDocument();            doc.setWeb("XWiki");            doc.setName("XWikiComments");            needsUpdate = true;        }        BaseClass bclass = doc.getxWikiClass();        if (context.get("initdone") != null)            return bclass;        bclass.setName("XWiki.XWikiComments");        needsUpdate |= bclass.addTextField("author", "Author", 30);        needsUpdate |= bclass.addTextAreaField("highlight", "Highlighted Text", 40, 2);        needsUpdate |= bclass.addNumberField("replyto", "Reply To", 5, "integer");        needsUpdate |= bclass.addDateField("date", "Date");        needsUpdate |= bclass.addTextAreaField("comment", "Comment", 40, 5);        String content = doc.getContent();        if ((content == null) || (content.equals(""))) {            needsUpdate = true;            doc.setContent("1 XWiki Comment Class");        }        if (needsUpdate)            saveDocument(doc, context);        return bclass;    }    public BaseClass getSkinClass(XWikiContext context) throws XWikiException {        XWikiDocument doc;        boolean needsUpdate = false;        try {            doc = getDocument("XWiki.XWikiSkins", context);        } catch (Exception e) {            doc = new XWikiDocument();            doc.setWeb("XWiki");            doc.setName("XWikiSkins");            needsUpdate = true;        }        BaseClass bclass = doc.getxWikiClass();        if (context.get("initdone") != null)            return bclass;        bclass.setName("XWiki.XWikiSkins");        needsUpdate |= bclass.addTextField("name", "Name", 30);        needsUpdate |= bclass.addTextField("baseskin", "Base Skin", 30);        needsUpdate |= bclass.addTemplateField("style.css", "Style");        needsUpdate |= bclass.addTemplateField("header.vm", "Header");        needsUpdate |= bclass.addTemplateField("footer.vm", "Footer");        needsUpdate |= bclass.addTemplateField("viewheader.vm", "View Header");        needsUpdate |= bclass.addTemplateField("view.vm", "View");        needsUpdate |= bclass.addTemplateField("edit.vm", "Edit");        String content = doc.getContent();        if ((content == null) || (content.equals(""))) {            needsUpdate = true;            doc.setContent("1 XWiki Skin Class");        }        if (needsUpdate)            saveDocument(doc, context);        return bclass;    }    public int createUser(XWikiContext context) throws XWikiException {        return createUser(false, "edit", context);    }    public int validateUser(boolean withConfirmEmail, XWikiContext context) throws XWikiException {        try {            XWikiRequest request = context.getRequest();            String xwikiname = request.getParameter("xwikiname");            String validkey = request.getParameter("validkey");            if (xwikiname.indexOf(".") == -1)                xwikiname = "XWiki." + xwikiname;            XWikiDocument docuser = getDocument(xwikiname, context);            BaseObject userobj = docuser.getObject("XWiki.XWikiUsers", 0);            String validkey2 = userobj.getStringValue("validkey");            String email = userobj.getStringValue("email");            String password = userobj.getStringValue("password");            if ((!validkey2.equals("") && (validkey2.equals(validkey)))) {                userobj.setIntValue("active", 1);                saveDocument(docuser, context);                if (withConfirmEmail)                    sendValidationEmail(xwikiname, password, email, validkey, "confirmation_email_content", context);                return 0;            } else                return -1;        } catch (Exception e) {            e.printStackTrace();            throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_VALIDATE_USER,                    "Exception while validating user", e, null);        }    }    public int createUser(boolean withValidation, String userRights, XWikiContext context) throws XWikiException {        try {            XWikiRequest request = context.getRequest();            Map map = Util.getObject(request, "register");            String content = "#includeForm(\"XWiki.XWikiUserTemplate\")";            String xwikiname = request.getParameter("xwikiname");            String password2 = request.getParameter("register2_password");            String password = ((String[]) map.get("password"))[0];            String email = ((String[]) map.get("email"))[0];            String template = request.getParameter("template");            String parent = request.getParameter("parent");            String validkey = null;            if (!password.equals(password2)) {                // TODO: throw wrong password exception                return -2;            }            if ((template != null) && (!template.equals(""))) {                XWikiDocument tdoc = getDocument(template, context);                if ((!tdoc.isNew()))                    content = tdoc.getContent();            }            if ((parent == null) || (parent.equals(""))) {                parent = "XWiki.XWikiUsers";            }            if (withValidation) {                map.put("active", "0");                validkey = generateValidationKey(16);                map.put("validkey", validkey);            } else {                // Mark user active                map.put("active", "1");            }            int result = createUser(xwikiname, map, parent, content, userRights, context);            if ((result > 0) && (withValidation)) {                // Send the validation email                sendValidationEmail(xwikiname, password, email, validkey, "validation_email_content", context);            }            return result;        } catch (XWikiException e) {            e.printStackTrace();            throw e;        } catch (Exception e) {            e.printStackTrace();            throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_CREATE_USER,                    "Exception while creating user", e, null);        }    }    public void sendValidationEmail(String xwikiname, String password, String email, String validkey, String contentfield, XWikiContext context) throws XWikiException {        String sender;        String content;        try {            sender = getXWikiPreference("admin_email", context);            content = getXWikiPreference(contentfield, context);        } catch (Exception e) {            throw new XWikiException(XWikiException.MODULE_XWIKI_EMAIL, XWikiException.ERROR_XWIKI_EMAIL_CANNOT_GET_VALIDATION_CONFIG,                    "Exception while reading the validation email config", e, null);        }        try {            VelocityContext vcontext = (VelocityContext) context.get("vcontext");            vcontext.put("validkey", validkey);            vcontext.put("email", email);            vcontext.put("password", password);            vcontext.put("sender", sender);            vcontext.put("xwikiname", xwikiname);            content = parseContent(content, context);        } catch (Exception e) {            throw new XWikiException(XWikiException.MODULE_XWIKI_EMAIL, XWikiException.ERROR_XWIKI_EMAIL_CANNOT_PREPARE_VALIDATION_EMAIL,                    "Exception while preparing the validation email", e, null);        }        // Let's now send the message        sendMessage(sender, email, content, context);    }    public void sendMessage(String sender, String[] recipient, String message, XWikiContext context) throws XWikiException {        SMTPClient smtpc = null;        try {            String server = getXWikiPreference("smtp_server", context);            String port = getXWikiPreference("smtp_port", context);            String login = getXWikiPreference("smtp_login", context);            if ((server == null) || server.equals(""))                server = "127.0.0.1";            if ((port == null) || (port.equals("")))                port = "25";            if ((login == null) || login.equals(""))                login = "XWiki version " + getVersion();            smtpc = new SMTPClient();            smtpc.connect(server, Integer.parseInt(port));            int reply = smtpc.getReplyCode();            if (!SMTPReply.isPositiveCompletion(reply)) {                Object[] args = {server, port, new Integer(reply), smtpc.getReplyString()};                throw new XWikiException(XWikiException.MODULE_XWIKI_EMAIL, XWikiException.ERROR_XWIKI_EMAIL_CONNECT_FAILED,                        "Could not connect to server {0} port {1} error code {2} ({3})", null, args);            }            if (smtpc.login(login) == false) {                reply = smtpc.getReplyCode();                Object[] args = {server, port, new Integer(reply), smtpc.getReplyString()};                throw new XWikiException(XWikiException.MODULE_XWIKI_EMAIL, XWikiException.ERROR_XWIKI_EMAIL_LOGIN_FAILED,                        "Could not login to mail server {0} port {1} error code {2} ({3})", null, args);            }            if (smtpc.sendSimpleMessage(sender, recipient, message) == false) {                reply = smtpc.getReplyCode();                Object[] args = {server, port, new Integer(reply), smtpc.getReplyString()};                throw new XWikiException(XWikiException.MODULE_XWIKI_EMAIL, XWikiException.ERROR_XWIKI_EMAIL_SEND_FAILED,                        "Could not send mail to server {0} port {1} error code {2} ({3})", null, args);            }        } catch (IOException e) {            Object[] args = {sender, recipient};            throw new XWikiException(XWikiException.MODULE_XWIKI_EMAIL, XWikiException.ERROR_XWIKI_EMAIL_ERROR_SENDING_EMAIL,                    "Exception while sending email from {0} to {1}", e, args);        } finally {            if ((smtpc != null) && (smtpc.isConnected())) {                try {                    smtpc.disconnect();                } catch (IOException e) {                    e.printStackTrace();                }            }        }    }    public void sendMessage(String sender, String recipient, String message, XWikiContext context) throws XWikiException {        String[] recip = {recipient};        sendMessage(sender, recip, message, context);

⌨️ 快捷键说明

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