r1047 - in xwiki/trunk/src/main: java/com/xpn/xwiki/doc java/com/xpn/xwiki/store java/com/xpn/xwiki/user/impl/xwiki web/templates

Ludovic Dubost ludovic at users.forge.objectweb.org
Fri Apr 14 15:51:29 CEST 2006


Author: ludovic
Date: 2006-04-14 15:51:29 +0200 (Fri, 14 Apr 2006)
New Revision: 1047

Modified:
   xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/store/XWikiHibernateAttachmentStore.java
   xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/MyPersistentLoginManager.java
   xwiki/trunk/src/main/web/templates/attachments.vm
Log:
Fix tag in attachment template
Allow float in cookielife to have less than 1 day cookie life
Make better error catching in delete attachment
Fix XML output and input in XWikiDocument

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	2006-04-13 17:23:12 UTC (rev 1046)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	2006-04-14 13:51:29 UTC (rev 1047)
@@ -1182,6 +1182,7 @@
         doc.setContentAuthor(getContentAuthor());
         doc.setContent(getContent());
         doc.setContentDirty(isContentDirty());
+        doc.setCreationDate(getCreationDate());
         doc.setDate(getDate());
         doc.setContentUpdateDate(getContentUpdateDate());
         doc.setTitle(getTitle());
@@ -1411,6 +1412,10 @@
         el.addText(getParent());
         docel.add(el);
 
+        el = new DOMElement("creator");
+        el.addText(getCreator());
+        docel.add(el);
+
         el = new DOMElement("author");
         el.addText(getAuthor());
         docel.add(el);

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/store/XWikiHibernateAttachmentStore.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/store/XWikiHibernateAttachmentStore.java	2006-04-13 17:23:12 UTC (rev 1046)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/store/XWikiHibernateAttachmentStore.java	2006-04-14 13:51:29 UTC (rev 1047)
@@ -9,6 +9,8 @@
 import org.hibernate.Session;
 import org.hibernate.Query;
 import org.hibernate.SessionFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import java.util.List;
 
@@ -20,6 +22,7 @@
  * To change this template use File | Settings | File Templates.
  */
 public class XWikiHibernateAttachmentStore extends XWikiHibernateBaseStore implements XWikiAttachmentStoreInterface {
+    private static final Log log = LogFactory.getLog(XWikiHibernateAttachmentStore.class);
 
     /**
      * THis allows to initialize our storage engine.
@@ -166,43 +169,56 @@
             Session session = getSession(context);
 
             // Delete the three attachement entries
-            try{
+            try {
                 loadAttachmentContent(attachment, context, false);
-            }catch(XWikiException e){
-                context.put("exception",e);
+            } catch (Exception e) {
+                if (log.isWarnEnabled())
+                    log.warn("Error loading attachment content when deleting attachment " + attachment.getFilename() + " of doc " + attachment.getDoc().getFullName());
             }
-            if(context.get("exception") != null){
-                XWikiException e1 = (XWikiException) context.get("exception");
-                if(e1.getCode() != XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_ATTACHMENT ){
-                    session.delete(attachment.getAttachment_content());
-                }
-            }else session.delete(attachment.getAttachment_content());
+            try {
+                session.delete(attachment.getAttachment_content());
+            } catch (Exception e) {
+                if (log.isWarnEnabled())
+                    log.warn("Error deleting attachment content " + attachment.getFilename() + " of doc " + attachment.getDoc().getFullName());
+            }
+            try {
+                loadAttachmentContent(attachment, context, false);
+            } catch(XWikiException e){
+                if (log.isWarnEnabled())
+                    log.warn("Error loading attachment archive when deleting attachment " + attachment.getFilename() + " of doc " + attachment.getDoc().getFullName());
+            }
 
-            try{
-                loadAttachmentArchive(attachment, context, false);
-            }catch(XWikiException e){
-                context.put("exception",e);
+            try {
+                session.delete(attachment.getAttachment_archive());
+            } catch (Exception e) {
+                if (log.isWarnEnabled())
+                    log.warn("Error deleting attachment archive " + attachment.getFilename() + " of doc " + attachment.getDoc().getFullName());
             }
-            if(context.get("exception") != null){
-                XWikiException e1 = (XWikiException) context.get("exception");
-                if(e1.getCode() != XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_ATTACHMENT ){
-                    session.delete(attachment.getAttachment_archive());
-                }
-            }else session.delete(attachment.getAttachment_archive());
 
-            session.delete(attachment);
+            try {
+                session.delete(attachment);
+            } catch (Exception e) {
+                if (log.isWarnEnabled())
+                    log.warn("Error deleting attachment meta data " + attachment.getFilename() + " of doc " + attachment.getDoc().getFullName());
+            }
 
-            if (parentUpdate) {
-                List list = attachment.getDoc().getAttachmentList();
-                for (int i=0;i<list.size();i++) {
-                    XWikiAttachment attach = (XWikiAttachment) list.get(i);
-                    if (attachment.getFilename().equals(attach.getFilename())) {
-                        list.remove(i);
-                        break;
+            try {
+                if (parentUpdate) {
+                    List list = attachment.getDoc().getAttachmentList();
+                    for (int i=0;i<list.size();i++) {
+                        XWikiAttachment attach = (XWikiAttachment) list.get(i);
+                        if (attachment.getFilename().equals(attach.getFilename())) {
+                            list.remove(i);
+                            break;
+                        }
                     }
+                    context.getWiki().getStore().saveXWikiDoc(attachment.getDoc(), context, false);
                 }
-                context.getWiki().getStore().saveXWikiDoc(attachment.getDoc(), context, false);
+            } catch (Exception e) {
+                if (log.isWarnEnabled())
+                    log.warn("Error updating document when deleting attachment " + attachment.getFilename() + " of doc " + attachment.getDoc().getFullName());
             }
+
             if (bTransaction) {
                 endTransaction(context, true);
             }

Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/MyPersistentLoginManager.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/MyPersistentLoginManager.java	2006-04-13 17:23:12 UTC (rev 1046)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/MyPersistentLoginManager.java	2006-04-14 13:51:29 UTC (rev 1047)
@@ -90,7 +90,7 @@
         // create client cookie to store username and password
         Cookie usernameCookie = new Cookie(COOKIE_USERNAME, username);
         if (!sessionCookie)
-         usernameCookie.setMaxAge(60 * 60 * 24 * Integer.parseInt(cookieLife));
+         setMaxAge(usernameCookie);
         usernameCookie.setPath(cookiePath);
         if (cookieDomain!=null)
             usernameCookie.setDomain(cookieDomain);
@@ -98,7 +98,7 @@
         addCookie(response, usernameCookie);
         Cookie passwdCookie = new Cookie(COOKIE_PASSWORD, password);
         if (!sessionCookie)
-         passwdCookie.setMaxAge(60 * 60 * 24 * Integer.parseInt(cookieLife));
+            setMaxAge(passwdCookie);
         passwdCookie.setPath(cookiePath);
         if (cookieDomain!=null)
             passwdCookie.setDomain(cookieDomain);
@@ -106,7 +106,7 @@
         addCookie(response, passwdCookie);
         Cookie rememberCookie = new Cookie(COOKIE_REMEMBERME, "true");
         if (!sessionCookie)
-         rememberCookie.setMaxAge(60 * 60 * 24 * Integer.parseInt(cookieLife));
+            setMaxAge(rememberCookie);
         rememberCookie.setPath(cookiePath);
         if (cookieDomain!=null)
             rememberCookie.setDomain(cookieDomain);
@@ -116,7 +116,7 @@
             if (validationHash != null) {
                 Cookie validationCookie = new Cookie(COOKIE_VALIDATION, validationHash);
                 if (!sessionCookie)
-                 validationCookie.setMaxAge(60 * 60 * 24 * Integer.parseInt(cookieLife));
+                    setMaxAge(validationCookie);
                 validationCookie.setPath(cookiePath);
                 if (cookieDomain!=null)
                     validationCookie.setDomain(cookieDomain);
@@ -133,6 +133,15 @@
         return;
     }
 
+    private void setMaxAge(Cookie cookie) {
+        try {
+           cookie.setMaxAge(Math.round(60 * 60 * 24 * Float.parseFloat(cookieLife)));
+        } catch (Exception e) {
+            if (log.isErrorEnabled())
+                log.error("Failed setting cookie Max age with duration " + cookieLife);
+        }
+    }
+
     private void addCookie(HttpServletResponse response, Cookie cookie) {
         if (log.isDebugEnabled())
             log.debug("Adding cookie: " + cookie.getDomain() + " " + cookie.getPath() + " " + cookie.getName() + " " + cookie.getValue());

Modified: xwiki/trunk/src/main/web/templates/attachments.vm
===================================================================
--- xwiki/trunk/src/main/web/templates/attachments.vm	2006-04-13 17:23:12 UTC (rev 1046)
+++ xwiki/trunk/src/main/web/templates/attachments.vm	2006-04-14 13:51:29 UTC (rev 1047)
@@ -42,7 +42,7 @@
     <br/>
 
     <form action="$doc.getURL(" upload")" enctype="multipart/form-data" method="post">
-            < p>
+            <p>
         <script type="text/javascript">
             function updateAttachName(form) {
                 var fname = form.filepath.value;
@@ -76,7 +76,7 @@
         <input type="file" name="filepath" value="" size="40"/>
         <br/><br/>
         <input type="submit" value="$msg.get(" attachthisfile")" onclick="return updateAttachName(this.form)" />
-                </ p>
+                </p>
     </form>
 </div>
 <div class="xwikidatafooter2">
@@ -86,4 +86,4 @@
 </div>
 </div>
 #end
-#end
\ No newline at end of file
+#end





More information about the Xwiki-notifications mailing list