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

📄 confluencerpchandler.java

📁 xwiki 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        checkToken(token, context);

        XWikiDocument doc = xwiki.getDocument(pageId, context);
        Page page = new Page(doc, context);
        return page.getHashtable();
    }

    public Vector getPageHistory(String token, String pageId) throws XWikiException {
        XWikiContext context = init();
        XWiki xwiki = context.getWiki();

        // Verify authentication token
        checkToken(token, context);

        Vector result = new Vector();
        XWikiDocument doc = xwiki.getDocument(pageId, context);
        Version[] versions = doc.getRevisions(context);
        for (int i=0;i<versions.length;i++) {
            String version = versions[i].toString();
            XWikiDocument revdoc = xwiki.getDocument(doc, version, context);
            result.add((new PageHistorySummary(revdoc)).getHashtable());
        }
        return result;
    }

    public Vector search(String token, String query, int maxResults) throws XWikiException {
        XWikiContext context = init();
        XWiki xwiki = context.getWiki();

        // Verify authentication token
        checkToken(token, context);

        Vector result = new Vector();
        List doclist = xwiki.getStore().searchDocumentsNames("where doc.content like '%" + Utils.SQLFilter(query) +
                "%' or doc.name like '%" + Utils.SQLFilter(query) + "%'", context);
        if (doclist == null)
            return result;

        for (int i=0;i<doclist.size();i++) {
            String docname = (String)doclist.get(i);
            XWikiDocument document = xwiki.getDocument(docname, context);
            SearchResult sresult = new SearchResult(document);
            result.add(sresult.getHashtable());
        }
        return result;
    }


    public String renderContent(String token, String spaceKey, String pageId, String content) {
        XWikiContext context = null;
        String result = "";
        try {
            context = init();
            XWiki xwiki = context.getWiki();
            context.setAction("view");

            // Verify authentication token
            checkToken(token, context);

            XWikiDocument document = xwiki.getDocument(pageId, context);
            context.setDoc(document);
            xwiki.prepareDocuments(context.getRequest(), context, (VelocityContext)context.get("vcontext"));
            result = xwiki.getRenderingEngine().renderText(content, document, context);
        } catch (Throwable e) {
            e.printStackTrace();
            result = handleException(e, context);
        }
        return result;
    }

    public Vector getAttachments(String token, String pageId) throws XWikiException {
        XWikiContext context = null;
        context = init();
        XWiki xwiki = context.getWiki();
        context.setAction("view");

        // Verify authentication token
        checkToken(token, context);

        XWikiDocument document = xwiki.getDocument(pageId, context);
        context.setDoc(document);
        xwiki.prepareDocuments(context.getRequest(), context, (VelocityContext)context.get("vcontext"));

        Vector result = new Vector();
        List attachlist = document.getAttachmentList();
        if (attachlist!=null) {
            for (int i=0;i<attachlist.size();i++) {
                Attachment attach = new Attachment(document, (XWikiAttachment)attachlist.get(i), context);
                result.add(attach.getHashtable());
            }
        }
        return result;
    }

    public Vector getComments(String token, String pageId) throws XWikiException {
        XWikiContext context = null;
        context = init();
        XWiki xwiki = context.getWiki();
        context.setAction("view");

        // Verify authentication token
        checkToken(token, context);

        XWikiDocument document = xwiki.getDocument(pageId, context);
        context.setDoc(document);
        xwiki.prepareDocuments(context.getRequest(), context, (VelocityContext)context.get("vcontext"));

        Vector result = new Vector();
        Vector commentlist = document.getObjects("XWiki.XWikiComments");
        if (commentlist!=null) {
            for (int i=0;i<commentlist.size();i++) {
                Comment comment = new Comment(document, (BaseObject)commentlist.get(i), context);
                result.add(comment);
            }
        }
        return result;
    }

    public Hashtable storePage(String token, Hashtable pageht) throws XWikiException {
        try {
        Page page = new Page(pageht);

        XWikiContext context = null;
        context = init();
        XWiki xwiki = context.getWiki();
        context.setAction("save");

        // Verify authentication token
        checkToken(token, context);

        XWikiDocument document = xwiki.getDocument(page.getId(), context);
        context.setDoc(document);
        xwiki.prepareDocuments(context.getRequest(), context, (VelocityContext)context.get("vcontext"));

        XWikiDocument newdoc = (XWikiDocument) document.clone();
        if (page.getParentId()!=null)
         newdoc.setParent(page.getParentId());

        newdoc.setAuthor(context.getUser());
        newdoc.setContent(page.getContent());
        context.getWiki().saveDocument(newdoc, document, context);
        return (new Page(newdoc, context)).getHashtable();
        } catch (XWikiException e) {
            e.printStackTrace();
            throw e;
        }
    }

    public void deletePage(String token, String pageId) throws XWikiException {
        XWikiContext context = null;
        context = init();
        XWiki xwiki = context.getWiki();
        context.setAction("delete");

        // Verify authentication token
        checkToken(token, context);

        XWikiDocument document = xwiki.getDocument(pageId, context);
        context.setDoc(document);
        xwiki.prepareDocuments(context.getRequest(), context, (VelocityContext)context.get("vcontext"));
        context.getWiki().deleteDocument(document, context);
    }

    public Hashtable getUser(String token, String username) {
        return null;
    }

    public void addUser(String token, Hashtable user, String password) {
    }

    public void addGroup(String token, String group) {
    }

    public Vector getUserGroups(String token, String username) {
        return null;
    }

    public void addUserToGroup(String token, String username, String groupname) {
    }

    protected String handleException(Throwable e, XWikiContext context) {

        if (!(e instanceof XWikiException)) {
            e = new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_UNKNOWN,
                    "Uncaught exception", e);
        }

        VelocityContext vcontext = ((VelocityContext)context.get("vcontext"));
        if (vcontext==null) {
            vcontext = new VelocityContext();
            context.put("vcontext", vcontext);
        }
        vcontext.put("exp", e);

        try {
            return parseTemplate("exception", context);
        } catch (Exception e2) {
            // I hope this never happens
            e.printStackTrace();
            e2.printStackTrace();
            return "Exception while serving request: " + e.getMessage();
        }
    }

    private String parseTemplate(String template, XWikiContext context) {
        context.setMode(XWikiContext.MODE_XMLRPC);
        String content = context.getWiki().parseTemplate(template + ".vm", context);
        return content;
    }

}

⌨️ 快捷键说明

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