r1334 - in xwiki/trunk/src: main/java/com/xpn/xwiki/api main/java/com/xpn/xwiki/doc main/java/com/xpn/xwiki/plugin/fileupload main/java/com/xpn/xwiki/store main/java/com/xpn/xwiki/store/jcr test/java/com/xpn/xwiki/plugin/charts/mocks
Jeremi Joslin
jeremi at users.forge.objectweb.org
Wed Sep 20 12:22:45 CEST 2006
Author: jeremi
Date: 2006-09-20 12:22:45 +0200 (Wed, 20 Sep 2006)
New Revision: 1334
Modified:
xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java
xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocumentArchive.java
xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java
xwiki/trunk/src/main/java/com/xpn/xwiki/store/XWikiAttachmentStoreInterface.java
xwiki/trunk/src/main/java/com/xpn/xwiki/store/XWikiHibernateAttachmentStore.java
xwiki/trunk/src/main/java/com/xpn/xwiki/store/jcr/XWikiJcrAttachmentStore.java
xwiki/trunk/src/test/java/com/xpn/xwiki/plugin/charts/mocks/MockStore.java
Log:
[GELC] http://www.gelc.org
* Save multiple Attachment to a document in one shot (instead of one by one)
* Add an API to Document to add multiple attachment from the request
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java 2006-09-20 09:51:00 UTC (rev 1333)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java 2006-09-20 10:22:45 UTC (rev 1334)
@@ -28,8 +28,10 @@
package com.xpn.xwiki.api;
-import com.xpn.xwiki.XWikiContext;
-import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.*;
+import com.xpn.xwiki.XWiki;
+import com.xpn.xwiki.plugin.fileupload.FileUploadPluginApi;
+import com.xpn.xwiki.plugin.fileupload.FileUploadPlugin;
import com.xpn.xwiki.doc.XWikiAttachment;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.doc.XWikiDocumentArchive;
@@ -42,6 +44,7 @@
import com.xpn.xwiki.util.Util;
import org.suigeneris.jrcs.diff.DifferentiationFailedException;
import org.suigeneris.jrcs.rcs.Version;
+import org.apache.commons.fileupload.DefaultFileItem;
import java.util.*;
@@ -65,8 +68,8 @@
}
protected XWikiDocument getDoc() {
- if (doc==olddoc)
- doc = (XWikiDocument) doc.clone();
+ if (doc == olddoc)
+ doc = (XWikiDocument) doc.clone();
return doc;
}
@@ -153,7 +156,7 @@
public String getDefaultLanguage() {
return doc.getDefaultLanguage();
}
-
+
public String getDefaultTemplate() {
return doc.getDefaultTemplate();
}
@@ -252,7 +255,7 @@
public Class getxWikiClass() {
BaseClass bclass = getDoc().getxWikiClass();
- if (bclass==null)
+ if (bclass == null)
return null;
else
return new Class(bclass, context);
@@ -261,21 +264,21 @@
public Class[] getxWikiClasses() {
List list = getDoc().getxWikiClasses(context);
- if (list==null)
+ if (list == null)
return null;
Class[] result = new Class[list.size()];
- for (int i=0;i<list.size();i++)
+ for (int i = 0; i < list.size(); i++)
result[i] = new Class((BaseClass) list.get(i), context);
return result;
}
public int createNewObject(String classname) throws XWikiException {
- return getDoc().createNewObject(classname, context);
+ return getDoc().createNewObject(classname, context);
}
public Object newObject(String classname) throws XWikiException {
- int nb = createNewObject(classname);
- return getObject(classname, nb);
+ int nb = createNewObject(classname);
+ return getObject(classname, nb);
}
public boolean isFromCache() {
@@ -290,10 +293,10 @@
public Map getxWikiObjects() {
Map map = getDoc().getxWikiObjects();
Map resultmap = new HashMap();
- for (Iterator it = map.keySet().iterator();it.hasNext();) {
+ for (Iterator it = map.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
- Vector objects = (Vector)map.get(name);
- if (objects!=null)
+ Vector objects = (Vector) map.get(name);
+ if (objects != null)
resultmap.put(name, getObjects(objects));
}
return resultmap;
@@ -301,11 +304,11 @@
protected Vector getObjects(Vector objects) {
Vector result = new Vector();
- if (objects==null)
+ if (objects == null)
return result;
- for (int i=0;i<objects.size();i++) {
+ for (int i = 0; i < objects.size(); i++) {
BaseObject bobj = (BaseObject) objects.get(i);
- if (bobj!=null) {
+ if (bobj != null) {
result.add(newObjectApi(bobj, context));
}
}
@@ -320,7 +323,7 @@
public Object getFirstObject(String fieldname) {
try {
BaseObject obj = getDoc().getFirstObject(fieldname, context);
- if (obj==null)
+ if (obj == null)
return null;
else
return newObjectApi(obj, context);
@@ -332,7 +335,7 @@
public Object getObject(String classname, String key, String value, boolean failover) {
try {
BaseObject obj = getDoc().getObject(classname, key, value, failover);
- if (obj==null)
+ if (obj == null)
return null;
else
return newObjectApi(obj, context);
@@ -344,7 +347,7 @@
public Object getObject(String classname, String key, String value) {
try {
BaseObject obj = getDoc().getObject(classname, key, value);
- if (obj==null)
+ if (obj == null)
return null;
else
return newObjectApi(obj, context);
@@ -361,11 +364,11 @@
try {
BaseObject obj = getDoc().getObject(classname);
- if ((obj==null)&&create) {
- return newObject(classname);
+ if ((obj == null) && create) {
+ return newObject(classname);
}
- if (obj==null)
+ if (obj == null)
return null;
else
return newObjectApi(obj, context);
@@ -377,7 +380,7 @@
public Object getObject(String classname, int nb) {
try {
BaseObject obj = getDoc().getObject(classname, nb);
- if (obj==null)
+ if (obj == null)
return null;
else
return newObjectApi(obj, context);
@@ -394,7 +397,7 @@
String xml = doc.getXMLContent(context);
return context.getUtil().substitute("s/<password>.*?<\\/password>/<password>********<\\/password>/goi", xml);
}
-
+
public String toXML() throws XWikiException {
if (checkProgrammingRights())
return doc.toXML(context);
@@ -423,8 +426,8 @@
public List getAttachmentList() {
List list = getDoc().getAttachmentList();
List list2 = new ArrayList();
- for (int i=0;i<list.size();i++) {
- list2.add(new Attachment(this, (XWikiAttachment)list.get(i), context));
+ for (int i = 0; i < list.size(); i++) {
+ list2.add(new Attachment(this, (XWikiAttachment) list.get(i), context));
}
return list2;
}
@@ -438,10 +441,10 @@
return getObjects("XWiki.XWikiComments");
else {
Vector list = getObjects("XWiki.XWikiComments");
- if (list==null)
+ if (list == null)
return list;
Vector newlist = new Vector();
- for (int i=list.size()-1;i>=0;i--) {
+ for (int i = list.size() - 1; i >= 0; i--) {
newlist.add(list.get(i));
}
return newlist;
@@ -461,36 +464,36 @@
}
public String display(String fieldname) {
- if (currentObj==null)
- return doc.display(fieldname, context);
+ if (currentObj == null)
+ return doc.display(fieldname, context);
else
- return doc.display(fieldname, currentObj.getBaseObject(), context);
+ return doc.display(fieldname, currentObj.getBaseObject(), context);
}
public String display(String fieldname, String mode) {
- if (currentObj==null)
- return doc.display(fieldname, mode, context);
+ if (currentObj == null)
+ return doc.display(fieldname, mode, context);
else
- return doc.display(fieldname, mode, currentObj.getBaseObject(), context);
+ return doc.display(fieldname, mode, currentObj.getBaseObject(), context);
}
public String display(String fieldname, Object obj) {
- if (obj==null)
+ if (obj == null)
return "";
return doc.display(fieldname, obj.getBaseObject(), context);
}
public String display(String fieldname, String mode, Object obj) {
- if (obj==null)
+ if (obj == null)
return "";
return doc.display(fieldname, mode, obj.getBaseObject(), context);
}
-
- public String displayForm(String className,String header, String format) {
+
+ public String displayForm(String className, String header, String format) {
return doc.displayForm(className, header, format, context);
}
- public String displayForm(String className,String header, String format, boolean linebreak) {
+ public String displayForm(String className, String header, String format, boolean linebreak) {
return doc.displayForm(className, header, format, linebreak, context);
}
@@ -499,25 +502,25 @@
}
public String displayRendered(com.xpn.xwiki.api.PropertyClass pclass, String prefix, Collection object) throws XWikiException {
- if ((pclass==null)||(object==null))
+ if ((pclass == null) || (object == null))
return "";
return doc.displayRendered(pclass.getBasePropertyClass(), prefix, object.getCollection(), context);
}
public String displayView(com.xpn.xwiki.api.PropertyClass pclass, String prefix, Collection object) {
- if ((pclass==null)||(object==null))
+ if ((pclass == null) || (object == null))
return "";
return doc.displayView(pclass.getBasePropertyClass(), prefix, object.getCollection(), context);
}
public String displayEdit(com.xpn.xwiki.api.PropertyClass pclass, String prefix, Collection object) {
- if ((pclass==null)||(object==null))
+ if ((pclass == null) || (object == null))
return "";
return doc.displayEdit(pclass.getBasePropertyClass(), prefix, object.getCollection(), context);
}
public String displayHidden(com.xpn.xwiki.api.PropertyClass pclass, String prefix, Collection object) {
- if ((pclass==null)||(object==null))
+ if ((pclass == null) || (object == null))
return "";
return doc.displayHidden(pclass.getBasePropertyClass(), prefix, object.getCollection(), context);
}
@@ -536,7 +539,7 @@
public Attachment getAttachment(String filename) {
XWikiAttachment attach = getDoc().getAttachment(filename);
- if (attach==null)
+ if (attach == null)
return null;
else
return new Attachment(this, attach, context);
@@ -544,16 +547,16 @@
public List getContentDiff(Document origdoc, Document newdoc) throws XWikiException, DifferentiationFailedException {
try {
- if ((origdoc==null)&&(newdoc==null))
+ if ((origdoc == null) && (newdoc == null))
return new ArrayList();
- if (origdoc==null)
+ if (origdoc == null)
return doc.getContentDiff(new XWikiDocument(newdoc.getWeb(), newdoc.getName()), newdoc.getDoc(), context);
- if (newdoc==null)
+ if (newdoc == null)
return doc.getContentDiff(origdoc.getDoc(), new XWikiDocument(origdoc.getWeb(), origdoc.getName()), context);
return doc.getContentDiff(origdoc.getDoc(), newdoc.getDoc(), context);
} catch (Exception e) {
- java.lang.Object[] args = { origdoc.getFullName(), origdoc.getVersion(), newdoc.getVersion() };
+ java.lang.Object[] args = {origdoc.getFullName(), origdoc.getVersion(), newdoc.getVersion()};
List list = new ArrayList();
XWikiException xe = new XWikiException(XWikiException.MODULE_XWIKI_DIFF, XWikiException.ERROR_XWIKI_DIFF_CONTENT_ERROR,
"Error while making content diff of {0} between version {1} and version {2}", e, args);
@@ -565,16 +568,16 @@
public List getXMLDiff(Document origdoc, Document newdoc) throws XWikiException, DifferentiationFailedException {
try {
- if ((origdoc==null)&&(newdoc==null))
+ if ((origdoc == null) && (newdoc == null))
return new ArrayList();
- if (origdoc==null)
+ if (origdoc == null)
return doc.getXMLDiff(new XWikiDocument(newdoc.getWeb(), newdoc.getName()), newdoc.getDoc(), context);
- if (newdoc==null)
+ if (newdoc == null)
return doc.getXMLDiff(origdoc.getDoc(), new XWikiDocument(origdoc.getWeb(), origdoc.getName()), context);
return doc.getXMLDiff(origdoc.getDoc(), newdoc.getDoc(), context);
} catch (Exception e) {
- java.lang.Object[] args = { origdoc.getFullName(), origdoc.getVersion(), newdoc.getVersion() };
+ java.lang.Object[] args = {origdoc.getFullName(), origdoc.getVersion(), newdoc.getVersion()};
List list = new ArrayList();
XWikiException xe = new XWikiException(XWikiException.MODULE_XWIKI_DIFF, XWikiException.ERROR_XWIKI_DIFF_XML_ERROR,
"Error while making xml diff of {0} between version {1} and version {2}", e, args);
@@ -586,16 +589,16 @@
public List getRenderedContentDiff(Document origdoc, Document newdoc) throws XWikiException, DifferentiationFailedException {
try {
- if ((origdoc==null)&&(newdoc==null))
+ if ((origdoc == null) && (newdoc == null))
return new ArrayList();
- if (origdoc==null)
+ if (origdoc == null)
return doc.getRenderedContentDiff(new XWikiDocument(newdoc.getWeb(), newdoc.getName()), newdoc.getDoc(), context);
- if (newdoc==null)
+ if (newdoc == null)
return doc.getRenderedContentDiff(origdoc.getDoc(), new XWikiDocument(origdoc.getWeb(), origdoc.getName()), context);
return doc.getRenderedContentDiff(origdoc.getDoc(), newdoc.getDoc(), context);
} catch (Exception e) {
- java.lang.Object[] args = { origdoc.getFullName(), origdoc.getVersion(), newdoc.getVersion() };
+ java.lang.Object[] args = {origdoc.getFullName(), origdoc.getVersion(), newdoc.getVersion()};
List list = new ArrayList();
XWikiException xe = new XWikiException(XWikiException.MODULE_XWIKI_DIFF, XWikiException.ERROR_XWIKI_DIFF_RENDERED_ERROR,
"Error while making rendered diff of {0} between version {1} and version {2}", e, args);
@@ -607,16 +610,16 @@
public List getMetaDataDiff(Document origdoc, Document newdoc) throws XWikiException {
try {
- if ((origdoc==null)&&(newdoc==null))
+ if ((origdoc == null) && (newdoc == null))
return new ArrayList();
- if (origdoc==null)
+ if (origdoc == null)
return doc.getMetaDataDiff(new XWikiDocument(newdoc.getWeb(), newdoc.getName()), newdoc.getDoc(), context);
- if (newdoc==null)
+ if (newdoc == null)
return doc.getMetaDataDiff(origdoc.getDoc(), new XWikiDocument(origdoc.getWeb(), origdoc.getName()), context);
return doc.getMetaDataDiff(origdoc.getDoc(), newdoc.getDoc(), context);
} catch (Exception e) {
- java.lang.Object[] args = { origdoc.getFullName(), origdoc.getVersion(), newdoc.getVersion() };
+ java.lang.Object[] args = {origdoc.getFullName(), origdoc.getVersion(), newdoc.getVersion()};
List list = new ArrayList();
XWikiException xe = new XWikiException(XWikiException.MODULE_XWIKI_DIFF, XWikiException.ERROR_XWIKI_DIFF_METADATA_ERROR,
"Error while making meta data diff of {0} between version {1} and version {2}", e, args);
@@ -628,16 +631,16 @@
public List getObjectDiff(Document origdoc, Document newdoc) throws XWikiException {
try {
- if ((origdoc==null)&&(newdoc==null))
+ if ((origdoc == null) && (newdoc == null))
return new ArrayList();
- if (origdoc==null)
+ if (origdoc == null)
return getDoc().getObjectDiff(new XWikiDocument(newdoc.getWeb(), newdoc.getName()), newdoc.getDoc(), context);
- if (newdoc==null)
+ if (newdoc == null)
return getDoc().getObjectDiff(origdoc.getDoc(), new XWikiDocument(origdoc.getWeb(), origdoc.getName()), context);
return getDoc().getObjectDiff(origdoc.getDoc(), newdoc.getDoc(), context);
} catch (Exception e) {
- java.lang.Object[] args = { origdoc.getFullName(), origdoc.getVersion(), newdoc.getVersion() };
+ java.lang.Object[] args = {origdoc.getFullName(), origdoc.getVersion(), newdoc.getVersion()};
List list = new ArrayList();
XWikiException xe = new XWikiException(XWikiException.MODULE_XWIKI_DIFF, XWikiException.ERROR_XWIKI_DIFF_OBJECT_ERROR,
"Error while making meta object diff of {0} between version {1} and version {2}", e, args);
@@ -649,16 +652,16 @@
public List getClassDiff(Document origdoc, Document newdoc) throws XWikiException {
try {
- if ((origdoc==null)&&(newdoc==null))
+ if ((origdoc == null) && (newdoc == null))
return new ArrayList();
- if (origdoc==null)
+ if (origdoc == null)
return doc.getClassDiff(new XWikiDocument(newdoc.getWeb(), newdoc.getName()), newdoc.getDoc(), context);
- if (newdoc==null)
+ if (newdoc == null)
return doc.getClassDiff(origdoc.getDoc(), new XWikiDocument(origdoc.getWeb(), origdoc.getName()), context);
return doc.getClassDiff(origdoc.getDoc(), newdoc.getDoc(), context);
} catch (Exception e) {
- java.lang.Object[] args = { origdoc.getFullName(), origdoc.getVersion(), newdoc.getVersion() };
+ java.lang.Object[] args = {origdoc.getFullName(), origdoc.getVersion(), newdoc.getVersion()};
List list = new ArrayList();
XWikiException xe = new XWikiException(XWikiException.MODULE_XWIKI_DIFF, XWikiException.ERROR_XWIKI_DIFF_CLASS_ERROR,
"Error while making class diff of {0} between version {1} and version {2}", e, args);
@@ -709,13 +712,13 @@
}
public boolean getLocked() {
- try{
+ try {
XWikiLock lock = doc.getLock(context);
if (lock != null && !context.getUser().equals(lock.getUserName()))
return true;
else
return false;
- } catch(Exception e) {
+ } catch (Exception e) {
return false;
}
}
@@ -745,10 +748,10 @@
}
public java.lang.Object get(String classOrFieldName) {
- if (currentObj!=null)
+ if (currentObj != null)
return getDoc().display(classOrFieldName, currentObj.getBaseObject(), context);
BaseObject object = getDoc().getFirstObject(classOrFieldName, context);
- if (object!=null) {
+ if (object != null) {
return getDoc().display(classOrFieldName, object, context);
}
return getDoc().getObject(classOrFieldName);
@@ -760,10 +763,10 @@
object = new Object(getDoc().getFirstObject(fieldName, context), context);
else
object = currentObj;
- if (object!=null){
+ if (object != null) {
//com.xpn.xwiki.objects.classes.PropertyClass pclass = (PropertyClass) object.getBaseObject().getxWikiClass(context).get(fieldName);
//return getDoc().displayView(pclass, fieldName, object.getBaseObject(), context);
- return ((BaseProperty)object.getBaseObject().safeget(fieldName)).getValue();
+ return ((BaseProperty) object.getBaseObject().safeget(fieldName)).getValue();
}
return null;
}
@@ -776,11 +779,12 @@
/**
* Returns data needed for a generation of Table of Content for this document.
- * @param init an intial level where the TOC generation should start at
- * @param max maximum level TOC is generated for
+ *
+ * @param init an intial level where the TOC generation should start at
+ * @param max maximum level TOC is generated for
* @param numbered if should generate numbering for headings
- * @return a map where an heading (title) ID is the key and
- * value is another map with two keys: text, level and numbering
+ * @return a map where an heading (title) ID is the key and
+ * value is another map with two keys: text, level and numbering
*/
public Map getTOC(int init, int max, boolean numbered) {
return TOCGenerator.generateTOC(getContent(), init, max, numbered, context);
@@ -792,16 +796,16 @@
}
public boolean equals(java.lang.Object arg0) {
- if (!(arg0 instanceof Document)) return false;
- Document d = (Document) arg0;
- return d.context.equals(context) && doc.equals(d.doc);
+ if (!(arg0 instanceof Document)) return false;
+ Document d = (Document) arg0;
+ return d.context.equals(context) && doc.equals(d.doc);
}
- public List getBacklinks () throws XWikiException {
+ public List getBacklinks() throws XWikiException {
return doc.getBacklinks(context);
}
- public List getLinks () throws XWikiException {
+ public List getLinks() throws XWikiException {
return doc.getLinks(context);
}
@@ -835,12 +839,12 @@
public void set(String fieldname, java.lang.Object value) {
Object obj;
- if (currentObj!=null)
- obj = currentObj;
+ if (currentObj != null)
+ obj = currentObj;
else
- obj = getFirstObject(fieldname);
- if (obj==null)
- return;
+ obj = getFirstObject(fieldname);
+ if (obj == null)
+ return;
obj.set(fieldname, value);
}
@@ -863,35 +867,35 @@
public void save() throws XWikiException {
if (hasAccessLevel("edit"))
- context.getWiki().saveDocument(getDoc(), olddoc, context);
+ context.getWiki().saveDocument(getDoc(), olddoc, context);
else {
- java.lang.Object[] args = { getDoc().getFullName() };
- throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED,
- "Access denied in edit mode on document {0}", null, args);
+ java.lang.Object[] args = {getDoc().getFullName()};
+ throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED,
+ "Access denied in edit mode on document {0}", null, args);
}
}
public void saveWithProgrammingRights() throws XWikiException {
if (checkProgrammingRights())
- context.getWiki().saveDocument(getDoc(), olddoc, context);
+ context.getWiki().saveDocument(getDoc(), olddoc, context);
else {
- java.lang.Object[] args = { getDoc().getFullName() };
- throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED,
- "Access denied with no programming rights document {0}", null, args);
+ java.lang.Object[] args = {getDoc().getFullName()};
+ throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED,
+ "Access denied with no programming rights document {0}", null, args);
}
}
public com.xpn.xwiki.api.Object addObjectFromRequest() throws XWikiException {
- // Call to getDoc() ensures that we are working on a clone()
- return new com.xpn.xwiki.api.Object(getDoc().addObjectFromRequest(context), context);
+ // Call to getDoc() ensures that we are working on a clone()
+ return new com.xpn.xwiki.api.Object(getDoc().addObjectFromRequest(context), context);
}
public com.xpn.xwiki.api.Object addObjectFromRequest(String className) throws XWikiException {
- return new com.xpn.xwiki.api.Object(getDoc().addObjectFromRequest(className, context), context);
+ return new com.xpn.xwiki.api.Object(getDoc().addObjectFromRequest(className, context), context);
}
public com.xpn.xwiki.api.Object updateObjectFromRequest(String className) throws XWikiException {
- return new com.xpn.xwiki.api.Object(getDoc().updateObjectFromRequest(className, context), context);
+ return new com.xpn.xwiki.api.Object(getDoc().updateObjectFromRequest(className, context), context);
}
public boolean isAdvancedContent() {
@@ -906,7 +910,7 @@
return getDoc().removeObject(obj.getBaseObject());
}
- public boolean removeObjects(String className){
+ public boolean removeObjects(String className) {
return getDoc().removeObjects(className);
}
@@ -914,7 +918,7 @@
if (hasAccessLevel("delete"))
context.getWiki().deleteDocument(getDocument(), context);
else {
- java.lang.Object[] args = { doc.getFullName() };
+ java.lang.Object[] args = {doc.getFullName()};
throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED,
"Access denied in edit mode on document {0}", null, args);
}
@@ -924,13 +928,62 @@
if (checkProgrammingRights())
context.getWiki().deleteDocument(getDocument(), context);
else {
- java.lang.Object[] args = { doc.getFullName() };
+ java.lang.Object[] args = {doc.getFullName()};
throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED,
"Access denied with no programming rights document {0}", null, args);
}
}
-
- public String getVersionHashCode(){
- return doc.getVersionHashCode(context);
+
+ public String getVersionHashCode() {
+ return doc.getVersionHashCode(context);
}
+
+ public int addAttachments() throws XWikiException {
+ return addAttachments(null);
+ }
+
+ public int addAttachments(String fieldName) throws XWikiException {
+ if (!hasAccessLevel("edit")){
+ java.lang.Object[] args = {getDoc().getFullName()};
+ throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED,
+ "Access denied in edit mode on document {0}", null, args);
+ }
+
+ XWiki xwiki = context.getWiki();
+ FileUploadPlugin fileupload = (FileUploadPlugin) xwiki.getPlugin("fileupload", context);
+ List fileuploadlist = fileupload.getFileItems(context);
+ List attachments = new ArrayList();
+ int nb = 0;
+
+ Iterator it = fileuploadlist.iterator();
+ while(it.hasNext()) {
+ DefaultFileItem item = (DefaultFileItem) it.next();
+ String name = item.getFieldName();
+ if (fieldName != null && !fieldName.equals(name))
+ continue;
+ if (item.isFormField())
+ continue;
+ byte[] data = fileupload.getFileItemData(name, context);
+ if ((data != null) && (data.length > 0)){
+ String fname = fileupload.getFileName(name, context);
+ int i = fname.indexOf("\\");
+ if (i == -1)
+ i = fname.indexOf("/");
+ String filename = fname.substring(i + 1);
+ filename = filename.replaceAll("\\+", " ");
+ XWikiAttachment attachment = new XWikiAttachment();
+ doc.getAttachmentList().add(attachment);
+ attachment.setContent(data);
+ attachment.setFilename(filename);
+ attachment.setAuthor(context.getUser());
+ // Add the attachment to the document
+ attachment.setDoc(doc);
+ attachments.add(attachment);
+ nb++;
+ }
+ }
+ doc.saveAttachmentsContent(attachments, context);
+ return nb;
+ }
+
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java 2006-09-20 09:51:00 UTC (rev 1333)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java 2006-09-20 10:22:45 UTC (rev 1334)
@@ -1697,7 +1697,34 @@
}
}
+ public void saveAttachmentsContent(List attachments, XWikiContext context) throws XWikiException {
+ String database = context.getDatabase();
+ try {
+ // We might need to switch database to
+ // get the translated content
+ if (getDatabase() != null)
+ context.setDatabase(getDatabase());
+
+ context.getWiki().getAttachmentStore().saveAttachmentsContent(attachments, this, true, context, true);
+ }catch(java.lang.OutOfMemoryError e){
+ throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
+ XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE,
+ "Out Of Memory Exception");
+ }
+ finally {
+ if (database != null)
+ context.setDatabase(database);
+ }
+
+ }
+
+
public void saveAttachmentContent(XWikiAttachment attachment, XWikiContext context) throws XWikiException {
+ saveAttachmentContent(attachment, true, true, context);
+ }
+
+
+ protected void saveAttachmentContent(XWikiAttachment attachment, boolean bParentUpdate, boolean bTransaction, XWikiContext context) throws XWikiException {
String database = context.getDatabase();
try {
// We might need to switch database to
@@ -1705,7 +1732,7 @@
if (getDatabase() != null)
context.setDatabase(getDatabase());
- context.getWiki().getAttachmentStore().saveAttachmentContent(attachment, context,true);
+ context.getWiki().getAttachmentStore().saveAttachmentContent(attachment, bParentUpdate, context, bTransaction);
}catch(java.lang.OutOfMemoryError e){
throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE,
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocumentArchive.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocumentArchive.java 2006-09-20 09:51:00 UTC (rev 1333)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocumentArchive.java 2006-09-20 10:22:45 UTC (rev 1334)
@@ -51,7 +51,14 @@
if ((text!=null)&&(!text.trim().equals(""))) {
StringInputStream is = new StringInputStream(text);
archive = new Archive("", is);
- } else {
+ } else
+ if (text == null){
+ Object[] lines = new Object[1];
+ lines[0] = "";
+ archive = new Archive(lines, "", "1.0");
+ }
+ else
+ {
Object[] lines = ToString.stringToArray(text);
archive = new Archive(lines, "", "1.0");
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java 2006-09-20 09:51:00 UTC (rev 1333)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java 2006-09-20 10:22:45 UTC (rev 1334)
@@ -203,6 +203,7 @@
return data;
}
+
/**
* Allows to retrieve the data of FileItem named name
* loadFileList needs to be called beforehand
@@ -216,6 +217,27 @@
* @return
* @throws XWikiException
*/
+ public String getFileItemAsString(String name, XWikiContext context) throws XWikiException {
+ byte[] data = getFileItemData(name, context);
+ if (data==null)
+ return null;
+ else
+ return new String(data);
+ }
+
+ /**
+ * Allows to retrieve the data of FileItem named name
+ * loadFileList needs to be called beforehand
+ * @deprecated not well named, use {@link #getFileItemAsString(String, com.xpn.xwiki.XWikiContext)}
+ * @param name Name of the item
+ * @param context Context of the request
+ * @return String of the data
+ * @throws XWikiException Exception is thrown if the data could not be read
+ * @param name
+ * @param context
+ * @return
+ * @throws XWikiException
+ */
public String getFileItem(String name, XWikiContext context) throws XWikiException {
byte[] data = getFileItemData(name, context);
if (data==null)
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/store/XWikiAttachmentStoreInterface.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/store/XWikiAttachmentStoreInterface.java 2006-09-20 09:51:00 UTC (rev 1333)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/store/XWikiAttachmentStoreInterface.java 2006-09-20 10:22:45 UTC (rev 1334)
@@ -3,7 +3,10 @@
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.doc.XWikiAttachment;
+import com.xpn.xwiki.doc.XWikiDocument;
+import java.util.List;
+
/**
* Created by IntelliJ IDEA.
* User: ludovic
@@ -14,6 +17,7 @@
public interface XWikiAttachmentStoreInterface {
public void saveAttachmentContent(XWikiAttachment attachment, XWikiContext context, boolean bTransaction) throws XWikiException;
public void saveAttachmentContent(XWikiAttachment attachment, boolean bParentUpdate, XWikiContext context, boolean bTransaction) throws XWikiException;
+ public void saveAttachmentsContent(List attachments, XWikiDocument doc, boolean bParentUpdate, XWikiContext context, boolean bTransaction) throws XWikiException;
public void loadAttachmentContent(XWikiAttachment attachment, XWikiContext context, boolean bTransaction) throws XWikiException;
public void loadAttachmentArchive(XWikiAttachment attachment, XWikiContext context, boolean bTransaction) throws XWikiException;
public void deleteXWikiAttachment(XWikiAttachment attachment, XWikiContext context, boolean bTransaction) throws XWikiException;
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/store/XWikiHibernateAttachmentStore.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/store/XWikiHibernateAttachmentStore.java 2006-09-20 09:51:00 UTC (rev 1333)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/store/XWikiHibernateAttachmentStore.java 2006-09-20 10:22:45 UTC (rev 1334)
@@ -6,12 +6,14 @@
import com.xpn.xwiki.doc.XWikiAttachment;
import com.xpn.xwiki.doc.XWikiAttachmentArchive;
import com.xpn.xwiki.doc.XWikiAttachmentContent;
+import com.xpn.xwiki.doc.XWikiDocument;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Session;
import java.util.List;
+import java.util.Iterator;
/**
* Created by IntelliJ IDEA.
@@ -105,6 +107,35 @@
}
+ public void saveAttachmentsContent(List attachments, XWikiDocument doc, boolean bParentUpdate, XWikiContext context, boolean bTransaction) throws XWikiException {
+ try{
+ if (bTransaction) {
+ checkHibernate(context);
+ bTransaction = beginTransaction(context);
+ }
+ if (attachments == null)
+ return;
+ Iterator it = attachments.iterator();
+ while(it.hasNext()){
+ XWikiAttachment att = (XWikiAttachment) it.next();
+ saveAttachmentContent(att, false, context, false);
+ }
+ if (bParentUpdate){
+ context.getWiki().getStore().saveXWikiDoc(doc, context, true);
+ }
+ }
+ catch (Exception e) {
+ throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT,
+ "Exception while saving attachments", e);
+ } finally {
+ try {
+ if (bTransaction)
+ endTransaction(context, false);
+ } catch (Exception e) {}
+ }
+
+ }
+
public void loadAttachmentContent(XWikiAttachment attachment, XWikiContext context, boolean bTransaction) throws XWikiException {
try {
if (bTransaction) {
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/store/jcr/XWikiJcrAttachmentStore.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/store/jcr/XWikiJcrAttachmentStore.java 2006-09-20 09:51:00 UTC (rev 1333)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/store/jcr/XWikiJcrAttachmentStore.java 2006-09-20 10:22:45 UTC (rev 1334)
@@ -6,9 +6,11 @@
import com.xpn.xwiki.doc.XWikiAttachment;
import com.xpn.xwiki.doc.XWikiAttachmentArchive;
import com.xpn.xwiki.doc.XWikiAttachmentContent;
+import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.store.XWikiAttachmentStoreInterface;
import javax.jcr.*;
+import javax.transaction.NotSupportedException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
@@ -55,7 +57,12 @@
"Exception while saving attachment {0} of document {1}", e, args);
}
}
- String getAttachmentPath(XWikiAttachment att) {
+
+ public void saveAttachmentsContent(List attachments, XWikiDocument doc, boolean bParentUpdate, XWikiContext context, boolean bTransaction) {
+ new NotSupportedException().printStackTrace();
+ }
+
+ String getAttachmentPath(XWikiAttachment att) {
return getBaseDocPath( att.getDoc() ) + "/attach/"+att.getFilename();
}
String getAttachmentContentPath(XWikiAttachmentContent ac) {
Modified: xwiki/trunk/src/test/java/com/xpn/xwiki/plugin/charts/mocks/MockStore.java
===================================================================
--- xwiki/trunk/src/test/java/com/xpn/xwiki/plugin/charts/mocks/MockStore.java 2006-09-20 09:51:00 UTC (rev 1333)
+++ xwiki/trunk/src/test/java/com/xpn/xwiki/plugin/charts/mocks/MockStore.java 2006-09-20 10:22:45 UTC (rev 1334)
@@ -172,6 +172,10 @@
}
+ public void saveAttachmentsContent(List attachments, XWikiDocument doc, boolean bParentUpdate, XWikiContext context, boolean bTransaction) throws XWikiException {
+
+ }
+
public void loadAttachmentContent(XWikiAttachment attachment,
XWikiContext context, boolean bTransaction) throws XWikiException {
More information about the Xwiki-notifications
mailing list