r1141 - in xwiki/trunk/src/main: java/com/xpn/xwiki java/com/xpn/xwiki/api java/com/xpn/xwiki/doc java/com/xpn/xwiki/web web/skins/xwiki10
Ludovic Dubost
ludovic at users.forge.objectweb.org
Fri Aug 11 18:39:24 CEST 2006
Author: ludovic
Date: 2006-08-11 18:39:23 +0200 (Fri, 11 Aug 2006)
New Revision: 1141
Modified:
xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.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/java/com/xpn/xwiki/web/ObjectAddForm.java
xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiServletURLFactory.java
xwiki/trunk/src/main/web/skins/xwiki10/macros.vm
Log:
Added new apis to handle custom forms on xwiki objects
Fix url creation for getSkinFile when there is a "/"
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java 2006-08-11 14:27:59 UTC (rev 1140)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java 2006-08-11 16:39:23 UTC (rev 1141)
@@ -3823,5 +3823,13 @@
return macrosmapping;
}
+
+ // This functions adds an object from an new object creation form
+ public BaseObject getObjectFromRequest(String className, XWikiContext context) throws XWikiException {
+ Map map = Util.getObject(context.getRequest(), className);
+ BaseClass bclass = context.getWiki().getClass(className, context);
+ BaseObject newobject = (BaseObject) bclass.fromMap(map, context);
+ return newobject;
+ }
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java 2006-08-11 14:27:59 UTC (rev 1140)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/api/Document.java 2006-08-11 16:39:23 UTC (rev 1141)
@@ -784,13 +784,6 @@
return TOCGenerator.generateTOC(getContent(), init, max, numbered, context);
}
- public com.xpn.xwiki.api.Object addObjectFromRequest() throws XWikiException {
- if (hasAccessLevel("edit"))
- return new com.xpn.xwiki.api.Object(getDoc().addObjectFromRequest(context), context);
- else
- return null;
- }
-
public void insertText(String text, String marker) throws XWikiException {
if (hasAccessLevel("edit"))
getDoc().insertText(text, marker, context);
@@ -886,4 +879,16 @@
}
}
+ 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);
+ }
+
+ public com.xpn.xwiki.api.Object addObjectFromRequest(String className) throws XWikiException {
+ 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);
+ }
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/api/XWiki.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/api/XWiki.java 2006-08-11 14:27:59 UTC (rev 1140)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/api/XWiki.java 2006-08-11 16:39:23 UTC (rev 1141)
@@ -32,9 +32,12 @@
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.util.Util;
import com.xpn.xwiki.render.groovy.XWikiGroovyRenderer;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.objects.meta.MetaClass;
+import com.xpn.xwiki.objects.BaseObject;
+import com.xpn.xwiki.objects.classes.BaseClass;
import com.xpn.xwiki.stats.api.XWikiStatsService;
import com.xpn.xwiki.stats.impl.DocumentStats;
import com.xpn.xwiki.web.Utils;
@@ -1026,5 +1029,13 @@
public String getMacroList() {
return xwiki.getMacroList(context);
}
+
+ public com.xpn.xwiki.api.Object getObjectFromRequest(String className) throws XWikiException {
+ return new com.xpn.xwiki.api.Object(xwiki.getObjectFromRequest(className, context), context);
+ }
+
+ public Document createDocument() {
+ return new Document(new XWikiDocument(), 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-08-11 14:27:59 UTC (rev 1140)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java 2006-08-11 16:39:23 UTC (rev 1141)
@@ -2368,26 +2368,6 @@
}
}
- // This functions adds an object from an new object creation form
- public BaseObject addObjectFromRequest(XWikiContext context) throws XWikiException {
- // Read info in object
- ObjectAddForm form = new ObjectAddForm();
- form.setRequest((HttpServletRequest) context.getRequest());
- form.readRequest();
-
- XWikiDocument newdoc = (XWikiDocument) clone();
- String className = form.getClassName();
- int nb = newdoc.createNewObject(className, context);
- BaseObject oldobject = newdoc.getObject(className, nb);
- BaseClass baseclass = oldobject.getxWikiClass(context);
- BaseObject newobject = (BaseObject) baseclass.fromMap(form.getObject(className), oldobject);
- newobject.setNumber(oldobject.getNumber());
- newobject.setName(newdoc.getFullName());
- newdoc.setObject(className, nb, newobject);
- context.getWiki().saveDocument(newdoc, context);
- return newobject;
- }
-
public void insertText(String text, String marker, XWikiContext context) throws XWikiException {
setContent(StringUtils.replaceOnce(getContent(), marker, text + marker));
context.getWiki().saveDocument(this, context);
@@ -2520,4 +2500,51 @@
getVersioningStore(context).resetRCSArchive(this, true, context);
}
+ // This functions adds an object from an new object creation form
+ public BaseObject addObjectFromRequest(XWikiContext context) throws XWikiException {
+ // Read info in object
+ ObjectAddForm form = new ObjectAddForm();
+ form.setRequest((HttpServletRequest) context.getRequest());
+ form.readRequest();
+
+ String className = form.getClassName();
+ int nb = createNewObject(className, context);
+ BaseObject oldobject = getObject(className, nb);
+ BaseClass baseclass = oldobject.getxWikiClass(context);
+ BaseObject newobject = (BaseObject) baseclass.fromMap(form.getObject(className), oldobject);
+ newobject.setNumber(oldobject.getNumber());
+ newobject.setName(getFullName());
+ setObject(className, nb, newobject);
+ return newobject;
+ }
+
+ // This functions adds an object from an new object creation form
+ public BaseObject addObjectFromRequest(String className, XWikiContext context) throws XWikiException {
+ int nb = createNewObject(className, context);
+ BaseObject oldobject = getObject(className, nb);
+ BaseClass baseclass = oldobject.getxWikiClass(context);
+ BaseObject newobject = (BaseObject) baseclass.fromMap(Util.getObject(context.getRequest(), className + "_0"), oldobject);
+ newobject.setNumber(oldobject.getNumber());
+ newobject.setName(getFullName());
+ setObject(className, nb, newobject);
+ return newobject;
+ }
+
+ // This functions adds an object from an new object creation form
+ public BaseObject updateObjectFromRequest(String className, XWikiContext context) throws XWikiException {
+ int nb;
+ BaseObject oldobject = getObject(className);
+ if (oldobject==null) {
+ nb = createNewObject(className, context);
+ oldobject = getObject(className, nb);
+ } else
+ nb = oldobject.getNumber();
+ BaseClass baseclass = oldobject.getxWikiClass(context);
+ BaseObject newobject = (BaseObject) baseclass.fromMap(Util.getObject(context.getRequest(), className + "_" + nb), oldobject);
+ newobject.setNumber(oldobject.getNumber());
+ newobject.setName(getFullName());
+ setObject(className, nb, newobject);
+ return newobject;
+ }
+
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/ObjectAddForm.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/ObjectAddForm.java 2006-08-11 14:27:59 UTC (rev 1140)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/ObjectAddForm.java 2006-08-11 16:39:23 UTC (rev 1141)
@@ -1,27 +1,29 @@
-/*
- * 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.util.Util;
+
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -44,16 +46,6 @@
}
public Map getObject(String prefix) {
- Map map = getRequest().getParameterMap();
- HashMap map2 = new HashMap();
- Iterator it = map.keySet().iterator();
- while (it.hasNext()) {
- String name = (String) it.next();
- if (name.startsWith(prefix + "_")) {
- String newname = name.substring(prefix.length()+1);
- map2.put(newname, map.get(name));
- }
- }
- return map2;
+ return Util.getObject(getRequest(), prefix);
}
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiServletURLFactory.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiServletURLFactory.java 2006-08-11 14:27:59 UTC (rev 1140)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiServletURLFactory.java 2006-08-11 16:39:23 UTC (rev 1141)
@@ -186,10 +186,17 @@
}
private void addFileName(StringBuffer newpath, String filename, XWikiContext context) {
- newpath.append("/");
- newpath.append(encode(filename, context));
+ addFileName(newpath, filename, true, context);
}
+ private void addFileName(StringBuffer newpath, String filename, boolean encode, XWikiContext context) {
+ newpath.append("/");
+ if (encode)
+ newpath.append(encode(filename, context));
+ else
+ newpath.append(filename);
+ }
+
private String encode(String name, XWikiContext context) {
return Utils.encode(name, context);
}
@@ -202,7 +209,7 @@
StringBuffer newpath = new StringBuffer(servletPath);
newpath.append("skins/");
newpath.append(skin);
- addFileName(newpath, filename, context);
+ addFileName(newpath, filename, false, context);
try {
return new URL(getServerURL(context), newpath.toString());
} catch (MalformedURLException e) {
@@ -217,7 +224,7 @@
addAction(newpath, "skin", context);
addSpace(newpath, web, "skin", context);
addName(newpath, name, "skin", context);
- addFileName(newpath, filename, context);
+ addFileName(newpath, filename, false, context);
try {
return new URL(getServerURL(xwikidb, context), newpath.toString());
} catch (MalformedURLException e) {
@@ -230,7 +237,7 @@
public URL createTemplateURL(String filename, XWikiContext context) {
StringBuffer newpath = new StringBuffer(servletPath);
newpath.append("templates");
- addFileName(newpath, filename, context);
+ addFileName(newpath, filename, false, context);
try {
return new URL(getServerURL(context), newpath.toString());
} catch (MalformedURLException e) {
Modified: xwiki/trunk/src/main/web/skins/xwiki10/macros.vm
===================================================================
--- xwiki/trunk/src/main/web/skins/xwiki10/macros.vm 2006-08-11 14:27:59 UTC (rev 1140)
+++ xwiki/trunk/src/main/web/skins/xwiki10/macros.vm 2006-08-11 16:39:23 UTC (rev 1141)
@@ -219,10 +219,11 @@
#macro(xwikimessageboxfield $fielddoc $fieldname $fieldtext $html)
<label class="field">$fieldtext</label>
<span class="field">
+#if($fieldname!="")
+$fielddoc.display($fieldname, "edit")
+#end
#if($html!="")
$html
-#else
-$fielddoc.display($fieldname, "edit")
#end
</span>
#end
More information about the Xwiki-notifications
mailing list