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

📄 xwikidocument.java

📁 xwiki 源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/**
 * ===================================================================
 *
 * Copyright (c) 2003 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.
 *
 * Created by
 * User: Ludovic Dubost
 * Date: 24 nov. 2003
 * Time: 00:00:31
 */
package com.xpn.xwiki.doc;

import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.notify.XWikiNotificationRule;
import com.xpn.xwiki.objects.BaseCollection;
import com.xpn.xwiki.objects.BaseObject;
import com.xpn.xwiki.objects.BaseProperty;
import com.xpn.xwiki.objects.classes.BaseClass;
import com.xpn.xwiki.objects.classes.PropertyClass;
import com.xpn.xwiki.render.XWikiVelocityRenderer;
import com.xpn.xwiki.store.XWikiStoreInterface;
import com.xpn.xwiki.store.XWikiHibernateStore;
import com.xpn.xwiki.util.Util;
import com.xpn.xwiki.web.EditForm;
import com.xpn.xwiki.web.PrepareEditForm;
import com.xpn.xwiki.web.Utils;
import com.xpn.xwiki.web.ObjectAddForm;
import org.apache.commons.jrcs.diff.Diff;
import org.apache.commons.jrcs.diff.DifferentiationFailedException;
import org.apache.commons.jrcs.diff.Revision;
import org.apache.commons.jrcs.rcs.Archive;
import org.apache.commons.jrcs.rcs.Lines;
import org.apache.commons.jrcs.rcs.Version;
import org.apache.commons.jrcs.util.ToString;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.lang.StringUtils;
import org.apache.ecs.filter.CharacterFilter;
import org.apache.tools.ant.filters.StringInputStream;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.tools.VelocityFormatter;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.dom.DOMDocument;
import org.dom4j.dom.DOMElement;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.StringWriter;
import java.io.StringReader;
import java.net.URL;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;


public class XWikiDocument {
    private static final Log log = LogFactory.getLog(XWikiHibernateStore.class);

    private String parent;
    private String web;
    private String name;
    private String content;
    private String meta;
    private String format;
    private String creator;
    private String author;
    private Archive archive;
    private Date updateDate;
    private Date creationDate;
    private Version version;
    private long id = 0;
    private boolean mostRecent = false;
    private boolean isNew = true;
    private String template;
    private String language;
    private String defaultLanguage;
    private int translation;
    private String database;

    // Used to make sure the MetaData String is regenerated
    private boolean isContentDirty = false;
    // Used to make sure the MetaData String is regenerated
    private boolean isMetaDataDirty = false;

    // Meta Data
    private BaseClass xWikiClass;
    private Map xWikiObjects = new HashMap();

    private List attachmentList;

    // Caching
    private boolean fromCache = false;
    private ArrayList objectsToRemove = new ArrayList();

    private XWikiStoreInterface store;

    public XWikiStoreInterface getStore() {
        return store;
    }

    public void setStore(XWikiStoreInterface store) {
        this.store = store;
    }


    public long getId() {
        if ((language==null)||language.trim().equals(""))
            id = getFullName().hashCode();
        else
            id = (getFullName() + ":" + language).hashCode();

        //if (log.isDebugEnabled())
        //    log.debug("ID: " + getFullName() + " " + language + ": " + id);
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getWeb() {
        return web;
    }

    public void setWeb(String web) {
        this.web = web;
    }

    public String getVersion() {
        return getRCSVersion().toString();
    }

    public void setVersion(String version) {
        this.version = new Version(version);
    }

    public Version getRCSVersion() {
        if (version == null) {
            version = new Version("1.1");
        }
        return version;
    }

    public void setRCSVersion(Version version) {
        this.version = version;
    }

    public XWikiDocument() {
        this("Main", "WebHome");
    }

    public XWikiDocument(String web, String name) {
        this.web = web;

        int i1 =name.indexOf(".");
        if (i1==-1) {
            this.name = name;
        } else {
            this.web = name.substring(0,i1);
            this.name = name.substring(i1+1);
        }
        this.updateDate = new Date();
        this.creationDate = new Date();
        this.parent = "";
        this.content = "\n";
        this.format = "";
        this.author = "";
        this.language = "";
        this.defaultLanguage = "";
        this.archive = null;
        this.attachmentList = new ArrayList();
    }

    public XWikiDocument getParentDoc() {
        return new XWikiDocument(web, getParent());
    }

    public String getParent() {
        return parent.trim();
    }

    public void setParent(String parent) {
        if (!parent.equals(this.parent)) {
            setMetaDataDirty(true);
        }
        this.parent = parent;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        if (!content.equals(this.content)) {
            setContentDirty(true);
        }
        this.content = content;
    }

    public String getRenderedContent(XWikiContext context) throws XWikiException {
        return context.getWiki().getRenderingEngine().renderDocument(this, context);
    }

    public String getRenderedContent(String text, XWikiContext context) {
        return context.getWiki().getRenderingEngine().renderText(text, this, context);
    }

    public String getEscapedContent(XWikiContext context) throws XWikiException {
        CharacterFilter filter = new CharacterFilter();
        return filter.process(getTranslatedContent(context));
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getFullName() {
        StringBuffer buf = new StringBuffer();
        buf.append(getWeb());
        buf.append(".");
        buf.append(getName());
        return buf.toString();
    }

    public void setFullName(String name) {
        // Should not be used
    }

    public String getFormat() {
        if (format==null)
            return "";
        else
            return format;
    }

    public void setFormat(String format) {
        this.format = format;
        if (!format.equals(this.format)) {
            setMetaDataDirty(true);
        }
    }

    public String getAuthor() {
        if (author==null)
            return "";
        else
            return author.trim();
    }

    public void setAuthor(String author) {
        if (!getAuthor().equals(this.author)) {
            setMetaDataDirty(true);
        }
        this.author = author;
    }

    public String getCreator() {
        if (creator==null)
            return "";
        else
            return creator.trim();
    }

    public void setCreator(String creator) {
        if (!getCreator().equals(this.creator)) {
            setMetaDataDirty(true);
        }
        this.creator = creator;
    }

    public Date getDate() {
        if (updateDate==null)
            return new Date();
        else
            return updateDate;
    }

    public void setDate(Date date) {
        if (!date.equals(this.updateDate)) {
            setMetaDataDirty(true);
        }
        this.updateDate = date;
    }

    public Date getCreationDate() {
        if (creationDate == null)
            return new Date();
        else
            return creationDate;
    }

    public void setCreationDate(Date date) {
        if (!creationDate.equals(this.creationDate)) {
            setMetaDataDirty(true);
        }
        this.creationDate = date;
    }

    public String getMeta() {
        return meta;
    }

    public void setMeta(String meta) {
        if (meta==null) {
            if (this.meta!=null)
                setMetaDataDirty(true);
        } else if (!meta.equals(this.meta)) {
            setMetaDataDirty(true);
        }
        this.meta = meta;
    }

    public void appendMeta(String meta) {
        StringBuffer buf = new StringBuffer(this.meta);
        buf.append(meta);
        buf.append("\n");
        this.meta = buf.toString();
        setMetaDataDirty(true);
    }

    public boolean isContentDirty() {
        return isContentDirty;
    }

    public void incrementVersion() {
        if (version==null)
            version = new Version("1.1");
        else {
            version = version.next();
        }
    }

    public void setContentDirty(boolean contentDirty) {
        isContentDirty = contentDirty;
    }

    public boolean isMetaDataDirty() {
        return isMetaDataDirty;
    }

    public void setMetaDataDirty(boolean metaDataDirty) {
        isMetaDataDirty = metaDataDirty;
    }

    public String getAttachmentURL(String filename, XWikiContext context) {
        return getAttachmentURL(filename, "download", context);
    }

    public String getAttachmentURL(String filename, String action, XWikiContext context) {
        URL url = context.getURLFactory().createAttachmentURL(filename, getWeb(), getName(), action, context);
        return context.getURLFactory().getURL(url, context);
    }

    public String getURL(String action, boolean redirect, XWikiContext context) {
        URL url = context.getURLFactory().createURL(getWeb(), getName(), action, redirect, context);
        if (redirect) {
            if (url==null)

⌨️ 快捷键说明

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