r958 - in xwiki/trunk/src: main/java/com/xpn/xwiki/api main/java/com/xpn/xwiki/doc main/java/com/xpn/xwiki/pdf/impl main/java/com/xpn/xwiki/web main/resources main/web/WEB-INF main/web/templates test/cactus/com/xpn/xwiki/test

Phung Hai Nam namphunghai at users.forge.objectweb.org
Thu Mar 2 11:57:54 CET 2006


Author: namphunghai
Date: 2006-03-02 11:57:53 +0100 (Thu, 02 Mar 2006)
New Revision: 958

Modified:
   xwiki/trunk/src/main/java/com/xpn/xwiki/api/Attachment.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiAttachment.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/pdf/impl/PdfURLFactory.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/AttachAction.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/CommentAddAction.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiDefaultURLFactory.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiPortlet.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiPortletURLFactory.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiServletURLFactory.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiURLFactory.java
   xwiki/trunk/src/main/resources/ApplicationResources.properties
   xwiki/trunk/src/main/web/WEB-INF/struts-config.xml
   xwiki/trunk/src/main/web/templates/attach.vm
   xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ViewEditTest.java
Log:
Fixed bug with storage of Attachment versions
Implemented Accessing revision of Attachments

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/api/Attachment.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/api/Attachment.java	2006-03-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/api/Attachment.java	2006-03-02 10:57:53 UTC (rev 958)
@@ -142,12 +142,8 @@
         return attachment.getArchive();
     }
 
-    /**
-     *
-     * @return a table with all versions object of the attachment
-     */
-
-    public Version[] getVersions() {
+    public Version[] getVersions() throws XWikiException {
+        attachment.loadArchive(context);
         return attachment.getVersions();
     }
 
@@ -157,6 +153,7 @@
      * @throws XWikiException
      */
     public List getVersionList() throws XWikiException {
+        attachment.loadArchive(context);
         return attachment.getVersionList();
     }
 
@@ -187,4 +184,8 @@
     public boolean isImage() {
         return attachment.isImage(context);
     }
+
+     public XWikiAttachment getAttachmentRevision(String rev) throws XWikiException{
+        return attachment.getAttachmentRevision(rev, context);
+    }
 }

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-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java	2006-03-02 10:57:53 UTC (rev 958)
@@ -204,10 +204,18 @@
         return doc.isNew();
     }
 
+    public String getAttachmentURL(String filename) {
+        return doc.getAttachmentURL(filename, "download", context);
+    }
+
     public String getAttachmentURL(String filename, String action) {
         return doc.getAttachmentURL(filename, action, context);
     }
 
+    public String getAttachmentRevisionURL(String filename, String version) {
+        return doc.getAttachmentRevisionURL(filename, version, context);
+    }
+
     public String getURL() {
         return doc.getURL("view", context);
     }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiAttachment.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiAttachment.java	2006-03-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiAttachment.java	2006-03-02 10:57:53 UTC (rev 958)
@@ -499,6 +499,7 @@
             String scontent = content.toString();
             XWikiAttachment revattach = new XWikiAttachment();
             revattach.fromXML(scontent);
+            revattach.setDoc(getDoc());
             return revattach;
         }    catch (Exception e) {
             Object[] args = { getFilename() };
@@ -506,45 +507,6 @@
                     "Exception while manipulating the archive for file {0}", e, args);
         }
     }
-
-    /*
-    public XWikiAttachment getAttachmentRevision(String rev, XWikiContext context) throws XWikiException {
-        XWikiAttachment revattach = null;
-
-        try {
-            Version[] versions = getDoc().getRevisions(context);
-            for (int i=0;i<versions.length;i++) {
-                Version version = versions[i];
-                XWikiDocument revdoc = context.getWiki().getDocument(getDoc(),version.toString(),context);
-                revattach = revdoc.getAttachment(getFilename());
-                if ((revattach!=null)&&revattach.getVersion().equals(rev))
-                    break;
-                revattach = null;
-            }
-            if (revattach==null)
-             return null;
-
-            context.getWiki().getStore().loadAttachmentArchive(this, context, true);
-            Archive archive = getArchive();
-            Version v = archive.getRevisionVersion(rev);
-            Object[] lines = archive.getRevision(v);
-            StringBuffer content = new StringBuffer();
-            for (int i=0;i<lines.length;i++) {
-                String line = lines[i].toString();
-                content.append(line);
-                if (i!=lines.length-1)
-                    content.append("\n");
-            }
-            String scontent = content.toString();
-            byte[] vcontent = Base64.decodeBase64(scontent.getBytes());
-            revattach.setContent(vcontent);
-            return revattach;
-        }    catch (Exception e) {
-            Object[] args = { getFilename() };
-            throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_ATTACHMENT_ARCHIVEFORMAT,
-                    "Exception while manipulating the archive for file {0}", e, args);
-        }
-    }
-   */
+    
 }
 

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-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	2006-03-02 10:57:53 UTC (rev 958)
@@ -475,6 +475,11 @@
         return context.getURLFactory().getURL(url, context);
     }
 
+    public String getAttachmentRevisionURL(String filename, String revision, XWikiContext context) {
+        URL url = context.getURLFactory().createAttachmentRevisionURL(filename, getWeb(), getName(), revision, 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) {

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/pdf/impl/PdfURLFactory.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/pdf/impl/PdfURLFactory.java	2006-03-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/pdf/impl/PdfURLFactory.java	2006-03-02 10:57:53 UTC (rev 958)
@@ -1,25 +1,25 @@
-/*
- * 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 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 wr0ngway
+ * @author sdumitriu
+ */
 
 package com.xpn.xwiki.pdf.impl;
 
@@ -58,6 +58,28 @@
         }
     }
 
+    public URL createAttachmentRevisionURL(String filename, String web, String name, String revision, String xwikidb, XWikiContext context) {
+        try {
+            File tempdir = (File) context.get("pdfexportdir");
+            File file = new File(tempdir, web + "." + name + "." + filename);
+            if (!file.exists()) {
+                XWikiDocument doc = null;
+                doc = context.getWiki().getDocument(web + "." + name, context);
+                XWikiAttachment attachment = doc.getAttachment(filename).getAttachmentRevision(revision, context);
+                byte[] data = new byte[0];
+                data = attachment.getContent(context);
+                FileOutputStream fos = new FileOutputStream(file);
+                fos.write(data);
+                fos.close();
+            }
+            return file.toURL();
+        } catch (Exception e) {
+            e.printStackTrace();
+            return super.createAttachmentRevisionURL(filename, web, name, revision, xwikidb, context);
+        }
+    }
+
+
     public String getURL(URL url, XWikiContext context) {
         if (url==null)
             return "";

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/AttachAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/AttachAction.java	2006-03-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/AttachAction.java	2006-03-02 10:57:53 UTC (rev 958)
@@ -1,24 +1,24 @@
-/*
- * 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 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 sdumitriu
+ */
 package com.xpn.xwiki.web;
 
 import com.xpn.xwiki.XWikiContext;
@@ -26,6 +26,7 @@
 
 public class AttachAction extends XWikiAction {
 	public String render(XWikiContext context) throws XWikiException {
+        
         return "attach";
 	}
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/CommentAddAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/CommentAddAction.java	2006-03-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/CommentAddAction.java	2006-03-02 10:57:53 UTC (rev 958)
@@ -60,6 +60,6 @@
 
     public String render(XWikiContext context) throws XWikiException {
         context.put("message", "nocommentwithnewdoc");
-        return "docnotexist";
+        return "exception";
     }
 }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiDefaultURLFactory.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiDefaultURLFactory.java	2006-03-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiDefaultURLFactory.java	2006-03-02 10:57:53 UTC (rev 958)
@@ -1,25 +1,25 @@
-/*
- * 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 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 wr0ngway
+ * @author sdumitriu
+ */
 
 package com.xpn.xwiki.web;
 
@@ -51,7 +51,11 @@
     public URL createAttachmentURL(String filename, String web, String name, String action, XWikiContext context) {
         return createAttachmentURL(filename, web, name, action, context.getDatabase(), context);
     }
-    
+
+    public URL createAttachmentRevisionURL(String filename, String web, String name, String revision, XWikiContext context) {
+        return createAttachmentRevisionURL(filename, web, name, revision, context.getDatabase(), context);
+    }
+
     public URL getRequestURL(XWikiContext context)
     {
         return context.getURL();

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiPortlet.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiPortlet.java	2006-03-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiPortlet.java	2006-03-02 10:57:53 UTC (rev 958)
@@ -294,6 +294,9 @@
             else if (action.equals("download")) {
                 renderResult = (new DownloadAction()).render(context);
             }
+            else if (action.equals("downloadrev")) {
+                renderResult = (new DownloadRevAction()).render(context);
+            }
             else if (action.equals("dot")) {
                 renderResult = (new DotAction()).render(context);
             }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiPortletURLFactory.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiPortletURLFactory.java	2006-03-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiPortletURLFactory.java	2006-03-02 10:57:53 UTC (rev 958)
@@ -59,7 +59,7 @@
             XWikiResponse response = context.getResponse();
             PortletURL purl;
 
-            if (action.equals("view")||action.equals("viewrev")||action.equals("download")||action.equals("skin")||action.equals("dot"))
+            if (action.equals("view")||action.equals("viewrev")||action.equals("download")||action.equals("downloadrev")||action.equals("skin")||action.equals("dot"))
                 purl = response.createRenderURL();
 
             if (action.equals("save")||action.equals("cancel")||action.equals("delete")||action.equals("propupdate")

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiServletURLFactory.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiServletURLFactory.java	2006-03-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiServletURLFactory.java	2006-03-02 10:57:53 UTC (rev 958)
@@ -1,28 +1,28 @@
-/*
- * 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 amelentev
- * @author sdumitriu
- * @author thomas
- */
+/*
+ * 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 amelentev
+ * @author sdumitriu
+ * @author thomas
+ */
 
 package com.xpn.xwiki.web;
 
@@ -242,7 +242,31 @@
         }
     }
 
+    public URL createAttachmentRevisionURL(String filename, String web, String name, String revision, String xwikidb, XWikiContext context) {
+        String action = "downloadrev";
+        StringBuffer newpath = new StringBuffer(servletPath);
+        newpath.append(actionPath);
+        addAction(newpath, action);
+        addSpace(newpath, web, action, context);
+        addName(newpath, name, action, context);
+        addFileName(newpath, filename, context);
 
+        String querystring = "rev=" + revision;
+        if ((querystring!=null)&&(!querystring.equals(""))) {
+            newpath.append("?");
+            newpath.append(querystring);
+            // newpath.append(querystring.replaceAll("&","&amp;"));
+        }
+
+        try {
+            return new URL(getServerURL(xwikidb, context), newpath.toString());
+        } catch (MalformedURLException e) {
+            // This should not happen
+            return null;
+        }
+    }
+
+
     public String getURL(URL url, XWikiContext context) {
         try {
             if (url==null)

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiURLFactory.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiURLFactory.java	2006-03-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiURLFactory.java	2006-03-02 10:57:53 UTC (rev 958)
@@ -1,25 +1,25 @@
-/*
- * 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 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 wr0ngway
+ * @author sdumitriu
+ */
 
 package com.xpn.xwiki.web;
 
@@ -45,6 +45,8 @@
     public URL createSkinURL(String filename, String web, String name, String xwikidb, XWikiContext context);
     public URL createAttachmentURL(String filename, String web, String name, String action, XWikiContext context);
     public URL createAttachmentURL(String filename, String web, String name, String action, String xwikidb, XWikiContext context);
+    public URL createAttachmentRevisionURL(String filename, String web, String name, String revision, XWikiContext context);
+    public URL createAttachmentRevisionURL(String filename, String web, String name, String revision, String xwikidb, XWikiContext context);
     public URL getRequestURL(XWikiContext context);
     public String getURL(URL url, XWikiContext context);
 }

Modified: xwiki/trunk/src/main/resources/ApplicationResources.properties
===================================================================
--- xwiki/trunk/src/main/resources/ApplicationResources.properties	2006-03-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/main/resources/ApplicationResources.properties	2006-03-02 10:57:53 UTC (rev 958)
@@ -191,14 +191,14 @@
 actiondoesnotexist=The action does not exist !
 thiswikidoesnotexist=This Wiki does not exist on this server.
 thisdocdoesnotexist=This document does not exist in this wiki.
-thispagealreadyexists=This document already exists in this wiki.
-thispagedoesnotexist=This document does not exist
-thistemplatedoesnotexist=This template does not exist
-youcanclicktoedit=You can click on <a href='$url'>edit</a> to create this page
+availableversionsattachment=The available versions of file '$attachment.filename' are:
+attachmentdoesnotexist=The attachment does not exists in this wiki 
 
 chartwizard=Chart Wizard
 chwhide=hide
 chwshow=show
+donotexist=dose not exit
+
 chwdatasourcelegend=Chart data source
 chwdatasourcetitle=Click to hide the chart data source option
 chwdatadefinelegend=Define new data source

Modified: xwiki/trunk/src/main/web/WEB-INF/struts-config.xml
===================================================================
--- xwiki/trunk/src/main/web/WEB-INF/struts-config.xml	2006-03-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/main/web/WEB-INF/struts-config.xml	2006-03-02 10:57:53 UTC (rev 958)
@@ -69,28 +69,34 @@
     <!-- ========== Action Mapping Definitions ============================== -->
     <action-mappings>
 
-        <!-- XWiki Struts Application with Velocity -->
-        <action path="/xmlrpc/"
-                type="com.xpn.xwiki.web.XMLRPCAction"
-                name="xmlrpc"
-                scope="request">
-        </action>
-        <action path="/view/"
-                type="com.xpn.xwiki.web.ViewAction"
-                name="view"
-                scope="request">
-            <forward name="view" path="/templates/view.vm"/>
-            <forward name="notexist" path="/templates/notexist.vm"/>
-            <forward name="plain" path="/templates/plain.vm"/>
-        </action>
-        <!---Add by me-->
-        <action path="/viewrev/"
-                type="com.xpn.xwiki.web.ViewrevAction"
-                name="viewrev"
-                scope="request">
-            <forward name="notexist" path="/templates/notexist.vm"></forward>
-            <forward name="view" path="/templates/view.vm"></forward>
-        </action>
+    <!-- XWiki Struts Application with Velocity -->
+    <action path="/xmlrpc/"
+            type="com.xpn.xwiki.web.XMLRPCAction"
+            name="xmlrpc"
+            scope="request">
+    </action>
+    <action path="/view/"
+            type="com.xpn.xwiki.web.ViewAction"
+            name="view"
+            scope="request">
+        <forward name="view" path="/templates/view.vm"/>
+        <forward name="notexist" path="/templates/notexist.vm"/>
+        <forward name="plain" path="/templates/plain.vm"/>
+    </action>
+    <action path="/viewattachrev/"
+            type="com.xpn.xwiki.web.ViewAttachRevAction"
+            name="viewattachrev"
+            scope="request">
+        <forward name="viewattachrev" path="/templates/viewattachrev.vm"/>
+    </action>
+    <!---Add by me-->
+    <action path="/viewrev/"
+            type ="com.xpn.xwiki.web.ViewrevAction"
+            name="viewrev"
+            scope="request">
+        <forward name="notexist" path="/templates/notexist.vm"></forward>
+        <forward name="view" path="/templates/view.vm"></forward>
+    </action>
 
         <action path="/pdf/"
                 type="com.xpn.xwiki.web.PDFAction"
@@ -212,18 +218,22 @@
             <forward name="upload" path="/templates/attach.vm"/>
         </action>
 
-        <action path="/download/"
-                type="com.xpn.xwiki.web.DownloadAction"
-                name="download"
-                scope="request">
-        </action>
+      <action path="/download/"
+          type="com.xpn.xwiki.web.DownloadAction"
+          name="download"
+          scope="request">
+      </action>
+      <action path="/downloadrev/"
+              type="com.xpn.xwiki.web.DownloadRevAction"
+              name="dowloadrev"
+              scope="request">
+      </action>
+      <action path="/dot/"
+          type="com.xpn.xwiki.web.DotAction"
+          name="dot"
+          scope="request">
+      </action>
 
-        <action path="/dot/"
-                type="com.xpn.xwiki.web.DotAction"
-                name="dot"
-                scope="request">
-        </action>
-
         <action path="/svg/"
                 type="com.xpn.xwiki.web.SVGAction"
                 name="svg"

Modified: xwiki/trunk/src/main/web/templates/attach.vm
===================================================================
--- xwiki/trunk/src/main/web/templates/attach.vm	2006-03-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/main/web/templates/attach.vm	2006-03-02 10:57:53 UTC (rev 958)
@@ -13,7 +13,9 @@
 <br />
 <table border="1" cellpadding="4" cellspacing="0" width="70%">
 <tr><th></th><th> <b>$msg.get("filename")</b> </th><th> <b>$msg.get("version")</b> </th>
-<th> <b>$msg.get("author")</b> </th><th> <b>$msg.get("size")</b> </th><th> <b>$msg.get("delete")</b></th> </tr>
+<th> <b>$msg.get("author")</b> </th><th> <b>$msg.get("size")</b> </th>
+ <th> <b>$msg.get("history")</b></th><th> <b>$msg.get("delete")</b></th>
+</tr>
 #foreach ($attach in $doc.attachmentList)
 <tr>
 <td>
@@ -21,8 +23,12 @@
 <img src="$doc.getAttachmentURL("${attach.filename}", "download")" alt="${attach.filename}" height="40" />
 #end
 </td><td><a href="$doc.getAttachmentURL("${attach.filename}", "download")">$attach.filename</a></td>
-<td>$attach.version</td><td>$attach.author</td><td>$attach.filesize</td>
-<td><a href="$doc.getAttachmentURL("${attach.filename}", "delattachment")" onclick="return confirm('$msg.get("confirmdelattachment")');">$msg.get("delete")</a></td>
+<td align="center">$attach.version</td><td align="center">$attach.author</td><td align=center>$attach.filesize</td>
+<td align="center">
+  <a href="$doc.getAttachmentURL("${attach.filename}", "viewattachrev")">$msg.get("history")</a>
+</td>
+<td align="center"><a href="$doc.getAttachmentURL("${attach.filename}", "delattachment")" onclick="return confirm('$msg.get("confirmdelattachment")');">$msg.get("delete")</a></td>
+</td>
 </tr>
 #set( $counter = $counter + 1)
 #end

Modified: xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ViewEditTest.java
===================================================================
--- xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ViewEditTest.java	2006-03-02 10:40:27 UTC (rev 957)
+++ xwiki/trunk/src/test/cactus/com/xpn/xwiki/test/ViewEditTest.java	2006-03-02 10:57:53 UTC (rev 958)
@@ -448,7 +448,7 @@
         BaseClass bclass = doc.getxWikiClass();
         BaseObject bobject = doc.getObject(bclass.getName(), 0);
         String content = Utils.content1;
-        Utils.content1 = "Template content";
+       // Utils.content1 = "Template content";
         Utils.createDoc(xwiki.getStore(), "Main", "SaveOkTestTemplate", bobject, bclass, context);
         Utils.content1 = content;
         setUrl(webRequest, "save", "SaveOkWithTestTemplate");
@@ -1488,8 +1488,8 @@
         try {
             String result = webResponse.getText();
             // Verify return
-            assertTrue("Attach Delete returned exception: " + result, result.indexOf("Exception") == -1);
-            assertTrue("Attach Delete should contain attachment text: " + result, result.indexOf("blablabla") != -1);
+            assertTrue("Attach Download  returned exception: " + result, result.indexOf("Exception")==-1);
+            assertTrue("Attach Download should contain attachment text: " + result, result.indexOf("blablabla")!=-1);
 
             // Flush cache to make sure we read from db
             xwiki.flushCache();
@@ -2051,62 +2051,129 @@
         launchTest();
     }
 
-    public void beginAddCommentOk(WebRequest webRequest) throws HibernateException, XWikiException {
+    public void testSaveWithTemplateNotOk() throws Throwable {
+      launchTest();
+    }
+
+    public void beginSaveWithTemplateNotOk(WebRequest webRequest) throws HibernateException, XWikiException {
         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
         StoreHibernateTest.cleanUp(hibstore, context);
         clientSetUp(hibstore);
+        XWikiDocument doc = new XWikiDocument();
+        Utils.prepareObject(doc, "Test.MyTestTemplate");
+        BaseClass bclass = doc.getxWikiClass();
+        BaseObject bobject = doc.getObject(bclass.getName(), 1);
+        Utils.createDoc(xwiki.getStore(), "Test", "MyTestTemplate", bobject, bclass, context);
+        setUrl(webRequest, "save", "Test", "MyTestPage", "");
+        webRequest.addParameter("template", "Test.MyTestTemplate");
+        webRequest.addParameter("parent", "XWiki.TestParentComesFromTemplate");
+        webRequest.addParameter("content", "XYZ");
+    }
+
+    public void endSaveWithTemplateNotOk(WebResponse webResponse) throws HibernateException, XWikiException {
+        try {
+            // Flush cache to make sure we read from db
+            xwiki.flushCache();
+
+            XWikiDocument doc2 = xwiki.getDocument("Test.MyTestPage", context);
+            String content2 = doc2.getContent();
+            assertEquals("Content is not identical", "XYZ",content2);
+
+        } finally {
+            clientTearDown();
+        }
+    }
+
+    public void testSaveWithTemplateToDocExistNotOk() throws Throwable {
+      launchTest();
+    }
+
+    public void beginSaveWithTemplateToDocExistNotOk(WebRequest webRequest) throws HibernateException, XWikiException {
+        XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
+        StoreHibernateTest.cleanUp(hibstore, context);
+        clientSetUp(hibstore);
+        XWikiDocument doc = new XWikiDocument();
+        Utils.prepareObject(doc, "Test.MyTestTemplate");
+        Utils.prepareObject(doc, "Test.MyTestPage");
+        BaseClass bclass = doc.getxWikiClass();
+        BaseObject bobject = doc.getObject(bclass.getName(), 2);
         String content = Utils.content1;
-        Utils.createDoc(xwiki.getStore(), "Main", "AddCommentOk", context);
+        Utils.content1 = "XYZ";
+        Utils.createDoc(xwiki.getStore(), "Test", "MyTestTemplate", bobject, bclass, context);
         Utils.content1 = content;
-        XWikiDocument doc2 = xwiki.getDocument("Main.AddCommentOk", context);
-        xwiki.saveDocument(doc2, context);
-        doc2.setContent("hello new test comment");
-        xwiki.saveDocument(doc2, context);
-        setUrl(webRequest, "commentadd", "AddCommentOk", "");
-        webRequest.addParameter("XWiki.XWikiComments_author", "XWiki.Admin");
-        webRequest.addParameter("XWiki.XWikiComments_date", "");
-        webRequest.addParameter("XWiki.XWikiComments_comment", "My comment");
-    }
 
-    public void endAddCommentOk(WebResponse webResponse) throws HibernateException, XWikiException {
-        String result = webResponse.getText();
+        Utils.createDoc(xwiki.getStore(), "Test", "MyTestPage", bobject, bclass, context);
 
-        // Make sure we clean the cache
-        xwiki.flushCache();
-        XWikiDocument doc = xwiki.getDocument("Main.AddCommentOk", context);
-        assertEquals("Could not find This comment", 1, doc.getComments().size());
+        setUrl(webRequest, "save", "Test", "MyTestPage", "");
+        webRequest.addParameter("template", "Test.MyTestTemplate");
+        webRequest.addParameter("parent", "XWiki.TestParentComesFromTemplate");
+        webRequest.addParameter("content", "New content");
     }
 
-    public void testAddCommentOk() throws Throwable {
+    public void endSaveWithTemplateToDocExistNotOk(WebResponse webResponse) throws HibernateException, XWikiException {
+        try {
+            String result = webResponse.getText();
+            XWikiDocument doc2 = xwiki.getDocument("Test.MyTestPage", context);
+            String content2 = doc2.getContent();
+            assertEquals("Content should still be XYZ", Utils.content1,content2);
+            // Verify return
+            assertTrue("Saving did not returned nice error message: " + result, (result.indexOf("You cannot create a document from a template when the document already exists.")!=-1));
+        } finally {
+            clientTearDown();
+        }
+    }
+
+    public void testAttachDownloadRev() throws Throwable {
         launchTest();
     }
 
 
-    public void beginAddCommentFail(WebRequest webRequest) throws HibernateException, XWikiException {
+    public void beginAttachDownloadRev(WebRequest webRequest) throws HibernateException, XWikiException, IOException {
         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
         StoreHibernateTest.cleanUp(hibstore, context);
         clientSetUp(hibstore);
-        setUrl(webRequest, "commentadd", "AddCommentFail", "");
-        webRequest.addParameter("XWiki.XWikiComments_author", "XWiki.Admin");
-        webRequest.addParameter("XWiki.XWikiComments_date", "");
-        webRequest.addParameter("XWiki.XWikiComments_comment", "My comment");
-    }
 
-    public void endAddCommentFail(WebResponse webResponse) throws HibernateException, XWikiException {
-        String result = webResponse.getText();
+        XWikiDocument doc1 = new XWikiDocument("Test", "AttachDownloadRevTest");
+        doc1.setContent(Utils.content1);
+        doc1.setAuthor(Utils.author);
+        doc1.setParent(Utils.parent);
+        xwiki.saveDocument(doc1, context);
+        XWikiAttachment attachment1 = new XWikiAttachment(doc1, Utils.filename);
+        String attachcontent1 = "blablabla";
+        attachment1.setContent(attachcontent1.getBytes());
 
-        // Make sure we clean the cache
-        xwiki.flushCache();
+        doc1.saveAttachmentContent(attachment1, context);
+        doc1.getAttachmentList().add(attachment1);
+        xwiki.saveDocument(doc1, context);
 
-        XWikiDocument doc = xwiki.getDocument("Main.AddCommentFail", context);
-        assertEquals("You can't comment when the document in article do not exist ", 0, doc.getComments().size());
-        assertTrue("Could not find This document does not exist in Content: " + result, result.indexOf("") != -1);
-    }
+        String attachcontent2 = "Another content";
+        attachment1.setContent(attachcontent2.getBytes());
 
-    public void testAddCommentFail() throws Throwable {
-        launchTest();
+        doc1.saveAttachmentContent(attachment1, context);
+        doc1.getAttachmentList().add(attachment1);
+        xwiki.saveDocument(doc1, context);
+        setUrl(webRequest, "downloadrev", "Test", "AttachDownloadRevTest/" + Utils.filename, "");
+        webRequest.addParameter("rev","1.1");
     }
 
+    public void endAttachDownloadRev(WebResponse webResponse) throws XWikiException, HibernateException {
+        try {
+            String result = webResponse.getText();
+            // Verify return
+            assertTrue("Attach Download  returned exception: " + result, result.indexOf("Exception")==-1);
+            assertEquals("Attach Download should contain attachment text of revision 1.1", "blablabla", result);
 
+            // Flush cache to make sure we read from db
+            xwiki.flushCache();
+
+            XWikiDocument doc2 = xwiki.getDocument("Test.AttachDownloadRevTest", context);
+            List list = doc2.getAttachmentList();
+            assertEquals("Document should have an attachement", 1, list.size());
+            XWikiAttachment attach1 = (XWikiAttachment)list.get(0);
+            assertEquals("Attachment should have version 1.2","1.2",attach1.getVersion());
+        } finally {
+            clientTearDown();
+        }
+    }
 }
 





More information about the Xwiki-notifications mailing list