r976 - in xwiki/trunk/src/main: java/com/xpn/xwiki java/com/xpn/xwiki/api java/com/xpn/xwiki/doc web/templates

Ludovic Dubost ludovic at users.forge.objectweb.org
Tue Mar 21 09:49:53 CET 2006


Author: ludovic
Date: 2006-03-21 09:49:52 +0100 (Tue, 21 Mar 2006)
New Revision: 976

Modified:
   xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiContext.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/api/Context.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/api/XWiki.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
   xwiki/trunk/src/main/web/templates/editrights.vm
Log:
Added parameter in CopyDocument and CopyWeb to copy a document or a space and clean it up before copying in XWiki object
Added getUserName and getLocalUserName API with no link parameter in XWiki object
Added isCreator and isCurrentUser api API to document
Added a getLockingDate API to get the Date of the Lock in Document object
Added getLocalUser API on context object
Removed a div from editrights.vm


Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java	2006-03-17 17:21:11 UTC (rev 975)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java	2006-03-21 08:49:52 UTC (rev 976)
@@ -2195,6 +2195,9 @@
     }
 
     public boolean copyDocument(String docname, String targetdocname, String sourceWiki, String targetWiki, String wikilanguage, boolean reset, XWikiContext context) throws XWikiException {
+        return copyDocument(docname, docname, sourceWiki, targetWiki, wikilanguage, true, false, context);
+    }
+    public boolean copyDocument(String docname, String targetdocname, String sourceWiki, String targetWiki, String wikilanguage, boolean reset, boolean force, XWikiContext context) throws XWikiException {
         String db = context.getDatabase();
         try {
             if (sourceWiki != null)
@@ -2208,8 +2211,14 @@
                     context.setDatabase(targetWiki);
                 XWikiDocument tdoc = getDocument(targetdocname, context);
                 // There is already an existing document
-                if (!tdoc.isNew())
-                    return false;
+                if (!tdoc.isNew()) {
+                    if (force) {
+                        // We need to delete the previous document
+                        deleteDocument(tdoc, context);
+                    } else {
+                     return false;
+                    }
+                }
 
                 if (wikilanguage == null) {
                     // Make sure attachments are loaded
@@ -2306,13 +2315,34 @@
     }
 
     public int copyWikiWeb(String web, String sourceWiki, String targetWiki, String wikilanguage, XWikiContext context) throws XWikiException {
+        return copyWikiWeb(web, sourceWiki, targetWiki, wikilanguage, false, context);
+    }
+
+    public int copyWikiWeb(String web, String sourceWiki, String targetWiki, String wikilanguage, boolean clean, XWikiContext context) throws XWikiException {
         String db = context.getDatabase();
         int nb = 0;
+        String sql = "";
+        if (web != null)
+            sql = "where doc.web = '" + Utils.SQLFilter(web) + "'";
+
+        if (clean) {
+            try {
+                context.setDatabase(targetWiki);
+                List list = getStore().searchDocumentsNames(sql, context);
+                if (log.isInfoEnabled())
+                    log.info("Deleting " + list.size() + " documents from wiki " + targetWiki);
+
+                for (Iterator it = list.iterator(); it.hasNext();) {
+                    String docname = (String) it.next();
+                    XWikiDocument doc = getDocument(docname, context);
+                    deleteDocument(doc, context);
+                }
+            } finally {
+                context.setDatabase(db);
+            }
+        }
+
         try {
-            String sql = "";
-            if (web != null)
-                sql = "where doc.web = '" + Utils.SQLFilter(web) + "'";
-
             context.setDatabase(sourceWiki);
             List list = getStore().searchDocumentsNames(sql, context);
             if (log.isInfoEnabled())
@@ -2329,6 +2359,7 @@
         }
     }
 
+
     public int copyWiki(String sourceWiki, String targetWiki, String language, XWikiContext context) throws XWikiException {
         return copyWikiWeb(null, sourceWiki, targetWiki, language, context);
     }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiContext.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiContext.java	2006-03-17 17:21:11 UTC (rev 975)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiContext.java	2006-03-21 08:49:52 UTC (rev 976)
@@ -1,26 +1,26 @@
-/*
- * Copyright 2006, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- *
- * @author ludovic
- * @author wr0ngway
- * @author sdumitriu
- */
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * @author ludovic
+ * @author wr0ngway
+ * @author sdumitriu
+ */
 
 package com.xpn.xwiki;
 
@@ -167,6 +167,11 @@
          return "XWiki.XWikiGuest";
     }
 
+    public String getLocalUser() {
+        String username = getUser();
+        return username.substring(username.indexOf(":") + 1);
+    }
+    
     public XWikiUser getXWikiUser() {
         return user;
     }
@@ -250,4 +255,5 @@
     public void setCacheDuration(int cacheDuration) {
         this.cacheDuration = cacheDuration;
     }
+
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/api/Context.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/api/Context.java	2006-03-17 17:21:11 UTC (rev 975)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/api/Context.java	2006-03-21 08:49:52 UTC (rev 976)
@@ -144,6 +144,14 @@
     }
 
     /**
+     *
+     * @return the local username of the current user which made the request
+     */
+    public String getLocalUser() {
+        return context.getLocalUser();
+    }
+
+    /**
      * set the document if you have the programming right
      * @param doc
      */

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java	2006-03-17 17:21:11 UTC (rev 975)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java	2006-03-21 08:49:52 UTC (rev 976)
@@ -727,6 +727,18 @@
         }
     }
 
+    public Date getLockingDate() {
+        try {
+            XWikiLock lock = doc.getLock(context);
+            if (lock != null && !context.getUser().equals(lock.getUserName()))
+                return lock.getDate();
+            else
+                return null;
+        } catch (XWikiException e) {
+            return null;
+        }
+    }
+
     public java.lang.Object get(String classOrFieldName) {
         if (currentObj!=null)
             return doc.display(classOrFieldName, currentObj.getBaseObject(), context);
@@ -797,4 +809,21 @@
     public String getEditURL(String action, String mode, String language) {
         return doc.getEditURL(action, mode, language, context);
     }
+
+    public boolean isCurrentUserCreator() {
+        return doc.isCurrentUserCreator(context);
+    }
+
+    public boolean isCurrentUserPage() {
+        return doc.isCurrentUserPage(context);
+    }
+
+    public boolean isCurrentLocalUserPage() {
+        return doc.isCurrentLocalUserPage(context);
+    }
+
+    public boolean isCreator(String username) {
+        return doc.isCreator(username);
+    }
+
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/api/XWiki.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/api/XWiki.java	2006-03-17 17:21:11 UTC (rev 975)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/api/XWiki.java	2006-03-21 08:49:52 UTC (rev 976)
@@ -500,6 +500,20 @@
             return false;
     }
 
+    public boolean copyDocument(String docname, String targetdocname, String sourceWiki, String targetWiki, String wikilanguage, boolean reset, boolean force) throws XWikiException {
+        if (checkProgrammingRights())
+            return xwiki.copyDocument(docname, targetdocname, sourceWiki, targetWiki, wikilanguage, reset, force, context);
+        else
+            return false;
+    }
+
+    public int copyWikiWeb(String web, String sourceWiki, String targetWiki, String wikiLanguage, boolean clean) throws XWikiException {
+        if (checkProgrammingRights())
+            return xwiki.copyWikiWeb(web, sourceWiki, targetWiki, wikiLanguage, clean, context);
+        else
+            return -1;
+    }
+
     public String includeTopic(String topic) throws XWikiException {
         return includeTopic(topic, true);
     }
@@ -703,6 +717,30 @@
         }
     }
 
+    public String getUserName(String user, boolean link) {
+        return xwiki.getUserName(user, null, link, context);
+    }
+
+    public String getUserName(String user, String format, boolean link) {
+        return xwiki.getUserName(user, format, link, context);
+    }
+
+    public String getLocalUserName(String user, boolean link) {
+        try {
+            return xwiki.getUserName(user.substring(user.indexOf(":") + 1), null, link, context);
+        } catch (Exception e) {
+            return xwiki.getUserName(user, null, link, context);
+        }
+    }
+
+    public String getLocalUserName(String user, String format, boolean link) {
+        try {
+            return xwiki.getUserName(user.substring(user.indexOf(":") + 1), format, link, context);
+        } catch (Exception e) {
+            return xwiki.getUserName(user, format, link, context);
+        }
+    }
+
     public String formatDate(Date date) {
         return xwiki.formatDate(date, null, context);
     }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	2006-03-17 17:21:11 UTC (rev 975)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	2006-03-21 08:49:52 UTC (rev 976)
@@ -2401,4 +2401,28 @@
         }
     }
 
+    public boolean isCurrentUserCreator(XWikiContext context) {
+        return isCreator(context.getUser());
+    }
+
+    public boolean isCreator(String username) {
+        if (username.equals("XWiki.XWikiGuest"))
+         return false;
+       return username.equals(getCreator());
+    }
+
+    public boolean isCurrentUserPage(XWikiContext context) {
+        String username = context.getUser();
+        if (username.equals("XWiki.XWikiGuest"))
+         return false;
+        return context.getUser().equals(getFullName());
+    }
+
+    public boolean isCurrentLocalUserPage(XWikiContext context) {
+        String username = context.getLocalUser();
+        if (username.equals("XWiki.XWikiGuest"))
+         return false;
+        return context.getUser().equals(getFullName());
+    }
+
 }

Modified: xwiki/trunk/src/main/web/templates/editrights.vm
===================================================================
--- xwiki/trunk/src/main/web/templates/editrights.vm	2006-03-17 17:21:11 UTC (rev 975)
+++ xwiki/trunk/src/main/web/templates/editrights.vm	2006-03-21 08:49:52 UTC (rev 976)
@@ -94,7 +94,6 @@
 </form>
 </div>
 </div>
-</div>
 #includeHelp("EditRightsHelp")
          </div>
             </div>





More information about the Xwiki-notifications mailing list