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

📄 xwiki.java

📁 xwiki 源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/** * =================================================================== * * Copyright (c) 2003-2005 Ludovic Dubost, All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details, published at * http://www.gnu.org/copyleft/gpl.html or in gpl.txt in the * root folder of this distribution. */package com.xpn.xwiki;import com.xpn.xwiki.doc.XWikiAttachment;import com.xpn.xwiki.doc.XWikiDocument;import com.xpn.xwiki.notify.PropertyChangedRule;import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;import com.xpn.xwiki.notify.XWikiNotificationManager;import com.xpn.xwiki.notify.XWikiNotificationRule;import com.xpn.xwiki.objects.BaseObject;import com.xpn.xwiki.objects.PropertyInterface;import com.xpn.xwiki.objects.classes.*;import com.xpn.xwiki.objects.meta.MetaClass;import com.xpn.xwiki.plugin.XWikiPluginManager;import com.xpn.xwiki.plugin.XWikiPluginInterface;import com.xpn.xwiki.render.XWikiRenderingEngine;import com.xpn.xwiki.render.XWikiVelocityRenderer;import com.xpn.xwiki.store.XWikiCacheStore;import com.xpn.xwiki.store.XWikiCacheStoreInterface;import com.xpn.xwiki.store.XWikiHibernateStore;import com.xpn.xwiki.store.XWikiStoreInterface;import com.xpn.xwiki.user.api.XWikiAuthService;import com.xpn.xwiki.user.api.XWikiGroupService;import com.xpn.xwiki.user.api.XWikiRightService;import com.xpn.xwiki.user.api.XWikiUser;import com.xpn.xwiki.user.impl.exo.ExoAuthServiceImpl;import com.xpn.xwiki.user.impl.exo.ExoGroupServiceImpl;import com.xpn.xwiki.user.impl.xwiki.XWikiAuthServiceImpl;import com.xpn.xwiki.user.impl.xwiki.XWikiGroupServiceImpl;import com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl;import com.xpn.xwiki.user.impl.LDAP.LDAPAuthServiceImpl;import com.xpn.xwiki.util.Util;import com.xpn.xwiki.web.*;import com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString;import com.xpn.xwiki.stats.api.XWikiStatsService;import com.xpn.xwiki.stats.impl.XWikiStatsServiceImpl;import com.xpn.xwiki.stats.impl.SearchEngineRule;import com.xpn.xwiki.api.Document;import com.xpn.xwiki.api.User;import com.xpn.xwiki.api.Api;import com.xpn.xwiki.cache.api.XWikiCacheService;import com.xpn.xwiki.cache.impl.OSCacheService;import org.hibernate.HibernateException;import org.apache.commons.lang.RandomStringUtils;import org.apache.commons.lang.StringUtils;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.commons.net.smtp.SMTPClient;import org.apache.commons.net.smtp.SMTPReply;import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.UsernamePasswordCredentials;import org.apache.commons.httpclient.methods.GetMethod;import org.apache.ecs.Filter;import org.apache.ecs.filter.CharacterFilter;import org.apache.ecs.xhtml.textarea;import org.apache.velocity.VelocityContext;import org.apache.velocity.app.tools.VelocityFormatter;import org.securityfilter.filter.URLPatternMatcher;import org.exoplatform.container.RootContainer;import org.exoplatform.container.PortalContainer;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.*;import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.lang.Class;import java.net.MalformedURLException;import java.net.URL;import java.net.URLEncoder;import java.util.*;import java.util.zip.ZipOutputStream;import java.text.SimpleDateFormat;import java.text.DateFormatSymbols;public class XWiki implements XWikiDocChangeNotificationInterface, XWikiInterface {    private static final Log log = LogFactory.getLog(XWiki.class);    private XWikiConfig config;    private XWikiStoreInterface store;    private XWikiRenderingEngine renderingEngine;    private XWikiPluginManager pluginManager;    private XWikiNotificationManager notificationManager;    private XWikiAuthService authService;    private XWikiRightService rightService;    private XWikiGroupService groupService;    private XWikiStatsService statsService;    private XWikiCacheService cacheService;    private MetaClass metaclass = MetaClass.getMetaClass();    private boolean test = false;    private String version = null;    private XWikiEngineContext engine_context;    private String database;    private String fullNameSQL;    private URLPatternMatcher urlPatternMatcher = new URLPatternMatcher();    // These are caches in order to improve finding virtual wikis    private List virtualWikiList = new ArrayList();    private static Map virtualWikiMap = new HashMap();    private static Map threadMap = new HashMap();    private boolean isReadOnly = false;    public static XWiki getMainXWiki(XWikiContext context) throws XWikiException {        String xwikicfg = "/WEB-INF/xwiki.cfg";        String xwikiname = "xwiki";        XWiki xwiki = null;        XWikiEngineContext econtext = context.getEngineContext();        try {            xwiki = (XWiki) econtext.getAttribute(xwikiname);            if (xwiki == null) {                InputStream xwikicfgis = econtext.getResourceAsStream(xwikicfg);                xwiki = new XWiki(xwikicfgis, context, context.getEngineContext());                econtext.setAttribute(xwikiname, xwiki);            }            context.setWiki(xwiki);            xwiki.setDatabase(context.getDatabase());            return xwiki;        } catch (Exception e) {            e.printStackTrace();            throw new XWikiException(XWikiException.MODULE_XWIKI,                    XWikiException.ERROR_XWIKI_INIT_FAILED,                    "Could not initialize main XWiki context", e);        }    }    public XWikiHibernateStore getHibernateStore() {        XWikiStoreInterface store = getStore();        if (store instanceof XWikiHibernateStore)            return (XWikiHibernateStore) store;        else if (store instanceof XWikiCacheStoreInterface) {            store = ((XWikiCacheStoreInterface) store).getStore();            if (store instanceof XWikiHibernateStore)                return (XWikiHibernateStore) store;            else                return null;        } else            return null;    }    public synchronized void updateDatabase(String appname, XWikiContext context) throws HibernateException, XWikiException {        updateDatabase(appname, false, context);    }    public synchronized void updateDatabase(String appname, boolean force, XWikiContext context) throws HibernateException, XWikiException {        String database = context.getDatabase()                ;        try {            List wikilist = getVirtualWikiList();            context.setDatabase(appname);            if (!wikilist.contains(appname)) {                wikilist.add(appname);                XWikiHibernateStore store = getHibernateStore();                if (store != null)                    store.updateSchema(context, force);            }            // Make sure these classes exists            getPrefsClass(context);            getUserClass(context);            getGroupClass(context);            getRightsClass(context);            getCommentsClass(context);            getSkinClass(context);            getGlobalRightsClass(context);            getPluginManager().virtualInit(context);            // Add initdone which will allow to            // bypass some initializations            context.put("initdone", "1");        } finally {            context.setDatabase(database);        }    }    public List getVirtualWikiList() {        return virtualWikiList;    }    public static XWiki getXWiki(XWikiContext context) throws XWikiException {        XWiki xwiki = getMainXWiki(context);        if (xwiki.isVirtual()) {            XWikiRequest request = context.getRequest();            String host = "";            try {                URL requestURL = context.getURL();                host = requestURL.getHost();            } catch (Exception e) {            }            ;            if (host.equals(""))                return xwiki;            String appname = findWikiServer(host, context);            if (appname == null) {                String uri = request.getRequestURI();                int i1 = host.indexOf(".");                String servername = (i1 != -1) ? host.substring(0, i1) : host;                appname = uri.substring(1, uri.indexOf("/", 2));                if ("0".equals(xwiki.Param("xwiki.virtual.autowww"))) {                    appname = servername;                } else {                    if ((servername.equals("www"))                            || (context.getUtil().match("m|[0-9]+\\.|[0-9]+\\.[0-9]+\\.[0-9]|", host))) {                        if (appname.equals("xwiki"))                            return xwiki;                    } else {                        appname = servername;                    }                }            }            // Check if this appname exists in the Database            String serverwikipage = getServerWikiPage(appname);            XWikiDocument doc = xwiki.getDocument(serverwikipage, context);            if (doc.isNew()) {                throw new XWikiException(XWikiException.MODULE_XWIKI,                        XWikiException.ERROR_XWIKI_DOES_NOT_EXIST,                        "The wiki " + appname + " does not exist");            }            // Set the wiki owner            String wikiOwner = doc.getStringValue("XWiki.XWikiServerClass", "owner");            if (wikiOwner.indexOf(":") == -1)                wikiOwner = xwiki.getDatabase() + ":" + wikiOwner;            context.setWikiOwner(wikiOwner);            context.setWikiServer(doc);            context.setVirtual(true);            context.setDatabase(appname);            context.setOriginalDatabase(appname);            try {                // Let's make sure the virtaul wikis are upgraded to the latest database version                xwiki.updateDatabase(appname, false, context);            } catch (HibernateException e) {                // Just to report it                e.printStackTrace();            }        }        return xwiki;    }    public static URL getRequestURL(XWikiRequest request) throws XWikiException {        try {            StringBuffer requestURL = request.getRequestURL();            String qs = request.getQueryString();            if ((qs != null) && (!qs.equals("")))                return new URL(requestURL.toString() + "?" + qs);            else                return new URL(requestURL.toString());        } catch (Exception e) {            throw new XWikiException(XWikiException.MODULE_XWIKI_APP,                    XWikiException.ERROR_XWIKI_APP_URL_EXCEPTION,                    "Exception while getting URL from request", e);        }    }    private static String findWikiServer(String host, XWikiContext context) {        String wikiserver = (String) virtualWikiMap.get(host);        if (wikiserver != null)            return wikiserver;        String hql = ", BaseObject as obj, StringProperty as prop where obj.name=" + context.getWiki().getFullNameSQL()                + " and obj.className='XWiki.XWikiServerClass' and prop.id.id = obj.id "                + "and prop.id.name = 'server' and prop.value='" + host + "'";        try {            List list = context.getWiki().getStore().searchDocumentsNames(hql, context);            if ((list == null) || (list.size() == 0))                return null;            String docname = (String) list.get(0);            if (!docname.startsWith("XWiki.XWikiServer"))                return null;            wikiserver = docname.substring("XWiki.XWikiServer".length()).toLowerCase();            virtualWikiMap.put(host, wikiserver);            return wikiserver;        } catch (XWikiException e) {            return null;        }    }    public static String getServerWikiPage(String servername) {        return "XWiki.XWikiServer"                + servername.substring(0, 1).toUpperCase()                + servername.substring(1);    }    public XWiki(XWikiConfig config, XWikiContext context) throws XWikiException {        this(config, context, null, false);    }    public XWiki(XWikiConfig config, XWikiContext context, XWikiEngineContext engine_context, boolean noupdate) throws XWikiException {        initXWiki(config, context, engine_context, noupdate);    }    /**     * @deprecated use {@link #XWiki(XWikiConfig, XWikiContext)} instead     */    public XWiki(String xwikicfgpath, XWikiContext context) throws XWikiException {        this(xwikicfgpath, context, null, false);    }    /**     * @deprecated use {@link #XWiki(XWikiConfig, XWikiContext, XWikiEngineContext, boolean)} instead     */    public XWiki(String xwikicfgpath, XWikiContext context, XWikiEngineContext engine_context, boolean noupdate) throws XWikiException {        try {            initXWiki(new XWikiConfig(new FileInputStream(xwikicfgpath)), context, engine_context, noupdate);        } catch (FileNotFoundException e) {            Object[] args = {xwikicfgpath};            throw new XWikiException(XWikiException.MODULE_XWIKI_CONFIG,                    XWikiException.ERROR_XWIKI_CONFIG_FILENOTFOUND,                    "Configuration file {0} not found", e, args);        }    }    /**     * @deprecated use {@link #XWiki(XWikiConfig, XWikiContext, XWikiEngineContext, boolean)} instead     */    public XWiki(InputStream is, XWikiContext context, XWikiEngineContext engine_context) throws XWikiException {        initXWiki(new XWikiConfig(is), context, engine_context, true);    }    public void initXWiki(XWikiConfig config, XWikiContext context, XWikiEngineContext engine_context, boolean noupdate) throws XWikiException {        setEngineContext(engine_context);        context.setWiki(this);        // Create the notification manager

⌨️ 快捷键说明

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