r969 - in xwiki/trunk/src/main: java/com/xpn/xwiki java/com/xpn/xwiki/web web/templates
Nguyen Viet Chung
chungnv at users.forge.objectweb.org
Fri Mar 10 03:16:26 CET 2006
Author: chungnv
Date: 2006-03-10 03:16:25 +0100 (Fri, 10 Mar 2006)
New Revision: 969
Modified:
xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java
xwiki/trunk/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java
xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java
xwiki/trunk/src/main/java/com/xpn/xwiki/web/ViewAttachRevAction.java
xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.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/web/templates/attachments.vm
Log:
Fixed Upload Attachment in XwikiPortlet with exo-platform 2.0
Fixed Delete Attachment in XwikiPortlet with exo-platform 2.0
Fixed History Attachment in XwikiPortlet with exo-platform 2.0
Fixed ViewRev Attachment in XwikiPortlet with exo-platform 2.0
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java 2006-03-09 12:14:02 UTC (rev 968)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/XWiki.java 2006-03-10 02:16:25 UTC (rev 969)
@@ -1583,7 +1583,7 @@
}
needsUpdate |= bclass.addBooleanField("allow", "Allow/Deny", "allow");
BooleanClass afield = (BooleanClass) bclass.get("allow");
- if (afield.getDefaultValue()!=1) {
+ if (afield.getDefaultValue() != 1) {
afield.setDefaultValue(1);
needsUpdate = true;
}
@@ -2543,8 +2543,13 @@
doc = getDocument("Main.WebHome", context);
} else if (context.getMode() == XWikiContext.MODE_XMLRPC) {
doc = context.getDoc();
- } else
- doc = getDocumentFromPath(request.getPathInfo(), context);
+ } else {
+ String action = context.getAction();
+ if ((request.getParameter("topic") != null) && (action.equals("edit") || action.equals("inline")))
+ doc = getDocument(request.getParameter("topic"), context);
+ else
+ doc = getDocumentFromPath(request.getPathInfo(), context);
+ }
context.put("doc", doc);
vcontext.put("doc", new Document(doc, context));
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java 2006-03-09 12:14:02 UTC (rev 968)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java 2006-03-10 02:16:25 UTC (rev 969)
@@ -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;
@@ -27,20 +27,22 @@
import com.xpn.xwiki.doc.XWikiDocument;
public class DeleteAttachmentAction extends XWikiAction {
- public boolean action(XWikiContext context) throws XWikiException {
+ public boolean action(XWikiContext context) throws XWikiException {
XWikiRequest request = context.getRequest();
XWikiResponse response = context.getResponse();
XWikiDocument doc = context.getDoc();
-
+ XWikiAttachment attachment = null;
+ String filename;
String path = request.getPathInfo();
- String filename = Utils.decode(path.substring(path.lastIndexOf("/")+1),context);
- XWikiAttachment attachment = null;
+ if (context.getMode() == XWikiContext.MODE_PORTLET)
+ filename = request.getParameter("filename");
+ else
+ filename = Utils.decode(path.substring(path.lastIndexOf("/") + 1), context);
- if (request.getParameter("id")!=null) {
+ if (request.getParameter("id") != null) {
int id = Integer.parseInt(request.getParameter("id"));
attachment = (XWikiAttachment) doc.getAttachmentList().get(id);
- }
- else {
+ } else {
attachment = doc.getAttachment(filename);
}
@@ -49,5 +51,5 @@
String redirect = Utils.getRedirect("attach", context);
sendRedirect(response, redirect);
return false;
- }
+ }
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java 2006-03-09 12:14:02 UTC (rev 968)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java 2006-03-10 02:16:25 UTC (rev 969)
@@ -28,22 +28,23 @@
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.plugin.fileupload.FileUploadPlugin;
import com.xpn.xwiki.xmlrpc.XWikiXMLRPCRequest;
import org.apache.commons.fileupload.DefaultFileItem;
+import org.apache.commons.fileupload.FileItem;
import org.apache.ecs.Filter;
import org.apache.ecs.filter.CharacterFilter;
import org.apache.log4j.MDC;
+import org.apache.struts.upload.MultipartRequestWrapper;
+import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class Utils {
@@ -198,7 +199,6 @@
// Test works with xwiki-test.cfg instead of xwiki.cfg
XWikiContext context = new XWikiContext();
String dbname = "xwiki";
-
URL url = XWiki.getRequestURL(request);
context.setURL(url);
// Push the URL into the Log4j NDC context
@@ -409,4 +409,29 @@
}
}
+ public static FileUploadPlugin handleMultipart(HttpServletRequest request, XWikiContext context) {
+ FileUploadPlugin fileupload = null;
+ try {
+ if (request instanceof MultipartRequestWrapper) {
+ fileupload = new FileUploadPlugin("fileupload", "fileupload", context);
+ fileupload.loadFileList(context);
+ context.put("fileuploadplugin", fileupload);
+ MultipartRequestWrapper mpreq = (MultipartRequestWrapper) request;
+ List fileItems = fileupload.getFileItems(context);
+ for (Iterator iter = fileItems.iterator(); iter.hasNext();) {
+ FileItem item = (FileItem) iter.next();
+ if (item.isFormField()) {
+ String sName = item.getFieldName();
+ String sValue = item.getString();
+ mpreq.setParameter(sName, sValue);
+ }
+ }
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ return fileupload;
+ }
+
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/ViewAttachRevAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/ViewAttachRevAction.java 2006-03-09 12:14:02 UTC (rev 968)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/ViewAttachRevAction.java 2006-03-10 02:16:25 UTC (rev 969)
@@ -27,12 +27,8 @@
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.api.Attachment;
import com.xpn.xwiki.api.Document;
+import com.xpn.xwiki.doc.XWikiAttachment;
import com.xpn.xwiki.doc.XWikiDocument;
-import com.xpn.xwiki.doc.XWikiAttachment;
-
-import java.io.IOException;
-import java.util.List;
-
import org.apache.velocity.VelocityContext;
public class ViewAttachRevAction extends XWikiAction {
@@ -41,21 +37,25 @@
XWikiRequest request = context.getRequest();
XWikiDocument doc = context.getDoc();
String path = request.getRequestURI();
- String filename = Utils.decode(path.substring(path.lastIndexOf("/")+1),context);
+ String filename;
+ if (context.getMode() == XWikiContext.MODE_PORTLET)
+ filename = request.getParameter("filename");
+ else
+ filename = Utils.decode(path.substring(path.lastIndexOf("/") + 1), context);
+
XWikiAttachment attachment = null;
- if (request.getParameter("id")!=null) {
+ if (request.getParameter("id") != null) {
int id = Integer.parseInt(request.getParameter("id"));
attachment = (XWikiAttachment) doc.getAttachmentList().get(id);
- }
- else {
+ } else {
attachment = doc.getAttachment(filename);
- if (attachment == null ) {
+ if (attachment == null) {
context.put("message", "attachmentdoesnotexist");
return "exception";
}
}
VelocityContext vcontext = (VelocityContext) context.get("vcontext");
- vcontext.put("attachment",new Attachment((Document)vcontext.get("doc"), attachment, context));
+ vcontext.put("attachment", new Attachment((Document) vcontext.get("doc"), attachment, context));
return "viewattachrev";
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.java 2006-03-09 12:14:02 UTC (rev 968)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiAction.java 2006-03-10 02:16:25 UTC (rev 969)
@@ -32,7 +32,6 @@
import com.xpn.xwiki.monitor.api.MonitorPlugin;
import com.xpn.xwiki.plugin.fileupload.FileUploadPlugin;
import com.xpn.xwiki.render.XWikiVelocityRenderer;
-import org.apache.commons.fileupload.FileItem;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.MDC;
@@ -40,15 +39,12 @@
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
-import org.apache.struts.upload.MultipartRequestWrapper;
import org.apache.velocity.VelocityContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
/**
* <p>A simple action that handles the display and editing of an
@@ -106,13 +102,12 @@
String redirect = context.getWiki().Param("xwiki.virtual.redirect");
response.sendRedirect(redirect);
return null;
- }
- else
- throw e;
+ } else
+ throw e;
}
// Parses multipart so that parms in multipart are available for all actions
- fileupload = handleMultipart(req, context);
+ fileupload = Utils.handleMultipart(req, context);
XWikiURLFactory urlf = xwiki.getURLFactoryService().createURLFactory(context.getMode(), context);
context.setURLFactory(urlf);
@@ -229,31 +224,6 @@
}
}
- private FileUploadPlugin handleMultipart(HttpServletRequest request, XWikiContext context) {
- FileUploadPlugin fileupload = null;
- try {
- if (request instanceof MultipartRequestWrapper) {
- fileupload = new FileUploadPlugin("fileupload", "fileupload", context);
- fileupload.loadFileList(context);
- context.put("fileuploadplugin", fileupload);
- MultipartRequestWrapper mpreq = (MultipartRequestWrapper) request;
- List fileItems = fileupload.getFileItems(context);
- for (Iterator iter = fileItems.iterator(); iter.hasNext();) {
- FileItem item = (FileItem) iter.next();
- if (item.isFormField()) {
- String sName = item.getFieldName();
- String sValue = item.getString();
- mpreq.setParameter(sName, sValue);
- }
- }
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- return fileupload;
- }
-
public String getRealPath(String path) {
return servlet.getServletContext().getRealPath(path);
}
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-09 12:14:02 UTC (rev 968)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiPortlet.java 2006-03-10 02:16:25 UTC (rev 969)
@@ -25,36 +25,29 @@
package com.xpn.xwiki.web;
-import java.io.IOException;
-
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
-import javax.portlet.GenericPortlet;
-import javax.portlet.PortletException;
-import javax.portlet.PortletMode;
-import javax.portlet.PortletPreferences;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
-import javax.portlet.WindowState;
-
+import com.xpn.xwiki.XWiki;
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.plugin.fileupload.FileUploadPlugin;
+import com.xpn.xwiki.render.XWikiVelocityRenderer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.MDC;
+import org.apache.struts.upload.MultipartRequestWrapper;
import org.apache.velocity.VelocityContext;
-import com.xpn.xwiki.XWiki;
-import com.xpn.xwiki.XWikiContext;
-import com.xpn.xwiki.XWikiException;
-import com.xpn.xwiki.render.XWikiVelocityRenderer;
+import javax.portlet.*;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
public class XWikiPortlet extends GenericPortlet {
- protected final Log logger = LogFactory.getLog( getClass() );
+ protected final Log logger = LogFactory.getLog(getClass());
private String name = "XWiki Portlet";
- public static final PortletMode CONFIG_PORTLET_MODE = new PortletMode("config");
- public static final String ROOT_SPACE_PARAM_NAME = "rootSpace";
+ public static final PortletMode CONFIG_PORTLET_MODE = new PortletMode("config");
+ public static final String ROOT_SPACE_PARAM_NAME = "rootSpace";
- protected String getTitle(RenderRequest renderRequest) {
+ protected String getTitle(RenderRequest renderRequest) {
return name;
}
@@ -62,9 +55,27 @@
return Utils.prepareContext(action, request, response, engine_context);
}
+ protected HttpServletRequest processMultipart(HttpServletRequest request) {
+ if (!"POST".equalsIgnoreCase(request.getMethod())) {
+ return (request);
+ }
+
+ String contentType = request.getContentType();
+
+ if ((contentType != null)
+ && contentType.startsWith("multipart/form-data")) {
+ return (new MultipartRequestWrapper(request));
+ } else {
+ return (request);
+ }
+ }
+
protected boolean prepareAction(String action, XWikiRequest request, XWikiResponse response,
XWikiEngineContext engine_context, XWikiContext context) throws XWikiException, IOException {
XWiki xwiki = XWiki.getXWiki(context);
+
+ FileUploadPlugin fileupload = Utils.handleMultipart(processMultipart(request.getHttpServletRequest()), context);
+
XWikiURLFactory urlf = xwiki.getURLFactoryService().createURLFactory(context.getMode(), context);
context.setURLFactory(urlf);
VelocityContext vcontext = XWikiVelocityRenderer.prepareContext(context);
@@ -73,11 +84,15 @@
protected void cleanUp(XWikiContext context) {
try {
- XWiki xwiki = (context!=null) ? context.getWiki() : null;
+ FileUploadPlugin fileupload = (FileUploadPlugin) context.get("fileuploadplugin");
+ if (fileupload != null)
+ fileupload.cleanFileList(context);
+
+ XWiki xwiki = (context != null) ? context.getWiki() : null;
// Make sure we cleanup database connections
// There could be cases where we have some
- if ((context!=null)&&(xwiki!=null)) {
- if (xwiki.getStore()!=null)
+ if ((context != null) && (xwiki != null)) {
+ if (xwiki.getStore() != null)
xwiki.getStore().cleanUp(context);
}
} finally {
@@ -92,8 +107,8 @@
"Uncaught exception", e);
}
- VelocityContext vcontext = ((VelocityContext)context.get("vcontext"));
- if (vcontext==null) {
+ VelocityContext vcontext = ((VelocityContext) context.get("vcontext"));
+ if (vcontext == null) {
vcontext = new VelocityContext();
context.put("vcontext", vcontext);
}
@@ -101,11 +116,11 @@
try {
XWikiException xex = (XWikiException) e;
- if (xex.getCode()==XWikiException.ERROR_XWIKI_ACCESS_DENIED) {
+ if (xex.getCode() == XWikiException.ERROR_XWIKI_ACCESS_DENIED) {
String page = Utils.getPage(request, "accessdenied");
Utils.parseTemplate(page, context);
return;
- } else if (xex.getCode()==XWikiException.ERROR_XWIKI_USER_INACTIVE) {
+ } else if (xex.getCode() == XWikiException.ERROR_XWIKI_USER_INACTIVE) {
String page = Utils.getPage(request, "userinactive");
Utils.parseTemplate(page, context);
return;
@@ -118,128 +133,115 @@
}
}
- protected void doDispatch(RenderRequest aRenderRequest, RenderResponse aRenderResponse) throws PortletException, IOException {
- WindowState windowState = aRenderRequest.getWindowState();
- if(!windowState.equals(WindowState.MINIMIZED) && aRenderRequest.getPortletMode().equals( CONFIG_PORTLET_MODE ) ) {
- doView( aRenderRequest, aRenderResponse );
- } else {
- super.doDispatch(aRenderRequest, aRenderResponse);
- }
- }
+ protected void doDispatch(RenderRequest aRenderRequest, RenderResponse aRenderResponse) throws PortletException, IOException {
+ WindowState windowState = aRenderRequest.getWindowState();
+ if (!windowState.equals(WindowState.MINIMIZED) && aRenderRequest.getPortletMode().equals(CONFIG_PORTLET_MODE)) {
+ doView(aRenderRequest, aRenderResponse);
+ } else {
+ super.doDispatch(aRenderRequest, aRenderResponse);
+ }
+ }
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException {
- WindowState windowState = actionRequest.getWindowState();
- if(!windowState.equals(WindowState.MINIMIZED) && actionRequest.getPortletMode().equals( CONFIG_PORTLET_MODE ) ) {
- handleConfigForm( actionRequest, actionResponse );
- } else {
- XWikiContext context = null;
- XWikiRequest request = new XWikiPortletRequest(actionRequest);
- XWikiResponse response = new XWikiPortletResponse(actionResponse);
- XWikiEngineContext engine_context = new XWikiPortletContext(actionRequest.getPortletSession().getPortletContext());
+ WindowState windowState = actionRequest.getWindowState();
+ if (!windowState.equals(WindowState.MINIMIZED) && actionRequest.getPortletMode().equals(CONFIG_PORTLET_MODE)) {
+ handleConfigForm(actionRequest, actionResponse);
+ } else {
+ XWikiContext context = null;
+ XWikiRequest request = new XWikiPortletRequest(actionRequest);
+ XWikiResponse response = new XWikiPortletResponse(actionResponse);
+ XWikiEngineContext engine_context = new XWikiPortletContext(actionRequest.getPortletSession().getPortletContext());
- try {
- String action = request.getParameter("action");
- if ((action==null)||(action.equals("")))
- action = "view";
+ try {
+ String action = request.getParameter("action");
+ if ((action == null) || (action.equals("")))
+ action = "view";
- context = prepareContext(action, request, response, engine_context);
- if (prepareAction(action, request, response, engine_context, context)==false)
- return;
+ context = prepareContext(action, request, response, engine_context);
+ if (prepareAction(action, request, response, engine_context, context) == false)
+ return;
// XWikiService xwikiservice = new XWikiService();
-
-
-
- XWikiForm form = null;
- if (action.equals("save"))
- form = new EditForm();
+
+ XWikiForm form = null;
+
+ if (action.equals("save"))
+ form = new EditForm();
else if (action.equals("lock"))
form = new EditForm();
else if (action.equals("cancel"))
form = new EditForm();
else if (action.equals("rollback"))
form = new RollbackForm();
- else if (action.equals("objectadd"))
- form = new ObjectAddForm();
- else if (action.equals("commentadd"))
- form = new ObjectAddForm();
- else if (action.equals("objectremove"))
- form = new ObjectRemoveForm();
- else if (action.equals("propadd"))
- form = new PropAddForm();
+ else if (action.equals("objectadd"))
+ form = new ObjectAddForm();
+ else if (action.equals("commentadd"))
+ form = new ObjectAddForm();
+ else if (action.equals("objectremove"))
+ form = new ObjectRemoveForm();
+ else if (action.equals("propadd"))
+ form = new PropAddForm();
- if (form!=null) {
- form.reset(null, request);
- context.setForm(form);
- }
-
- if (action.equals("save")) {
- (new SaveAction()).action(context);
- }
- else if (action.equals("rollback")) {
- (new RollbackAction()).action(context);
+ if (form != null) {
+ form.reset(null, request);
+ context.setForm(form);
}
- else if (action.equals("cancel")) {
+
+ if (action.equals("save")) {
+ (new SaveAction()).action(context);
+ } else if (action.equals("rollback")) {
+ (new RollbackAction()).action(context);
+ } else if (action.equals("cancel")) {
(new CancelAction()).action(context);
- }
- else if (action.equals("lock")) {
+ } else if (action.equals("lock")) {
(new LockAction()).action(context);
- }
- else if (action.equals("delete")) {
+ } else if (action.equals("delete")) {
(new DeleteAction()).action(context);
- }
- else if (action.equals("propupdate")) {
+ } else if (action.equals("propupdate")) {
(new PropUpdateAction()).action(context);
- }
- else if (action.equals("propadd")) {
+ } else if (action.equals("propadd")) {
(new PropAddAction()).action(context);
- }
- else if (action.equals("objectadd")) {
+ } else if (action.equals("objectadd")) {
(new ObjectAddAction()).action(context);
- }
- else if (action.equals("commentadd")) {
+ } else if (action.equals("commentadd")) {
(new CommentAddAction()).action(context);
- }
- else if (action.equals("objectremove")) {
+ } else if (action.equals("objectremove")) {
(new ObjectRemoveAction()).action(context);
- }
- else if (action.equals("upload")) {
+ } else if (action.equals("upload")) {
(new UploadAction()).action(context);
- }
- else if (action.equals("delattachment")) {
+ } else if (action.equals("delattachment")) {
(new DeleteAttachmentAction()).action(context);
- }
- else if (action.equals("skin")) {
+ } else if (action.equals("skin")) {
(new SkinAction()).action(context);
- }
- else if (action.equals("logout")) {
+ } else if (action.equals("logout")) {
(new LogoutAction()).action(context);
- }
- else if (action.equals("register")) {
+ } else if (action.equals("register")) {
(new RegisterAction()).action(context);
- }
- } catch (Throwable e) {
- handleException(request, response, e, context);
- } finally {
- cleanUp(context);
- }
- }
+ } else if (action.equals("inline")) {
+ (new InlineAction()).action(context);
+ }
+ } catch (Throwable e) {
+ handleException(request, response, e, context);
+ } finally {
+ cleanUp(context);
+ }
+ }
}
- private void handleConfigForm(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException {
- PortletPreferences preferences = actionRequest.getPreferences();
- String rootSpace = actionRequest.getParameter( ROOT_SPACE_PARAM_NAME );
- preferences.setValue( XWikiPortletRequest.ROOT_SPACE_PREF_NAME, rootSpace );
- actionResponse.setPortletMode( PortletMode.VIEW );
- preferences.store();
- if (logger.isDebugEnabled()) {
- logger.debug("New root space is [" + rootSpace + "]");
- }
+ private void handleConfigForm(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException {
+ PortletPreferences preferences = actionRequest.getPreferences();
+ String rootSpace = actionRequest.getParameter(ROOT_SPACE_PARAM_NAME);
+ preferences.setValue(XWikiPortletRequest.ROOT_SPACE_PREF_NAME, rootSpace);
+ actionResponse.setPortletMode(PortletMode.VIEW);
+ preferences.store();
+ if (logger.isDebugEnabled()) {
+ logger.debug("New root space is [" + rootSpace + "]");
+ }
- }
+ }
- protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException {
+ protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException {
XWikiContext context = null;
XWikiRequest request = new XWikiPortletRequest(renderRequest);
XWikiResponse response = new XWikiPortletResponse(renderResponse);
@@ -248,25 +250,24 @@
try {
action = request.getParameter("action");
- if ((action==null)||(action.equals(""))) {
- action = renderRequest.getPortletMode().equals( CONFIG_PORTLET_MODE )
- ? "portletConfig"
- : "view";
- }
-
+ if ((action == null) || (action.equals(""))) {
+ action = renderRequest.getPortletMode().equals(CONFIG_PORTLET_MODE)
+ ? "portletConfig"
+ : "view";
+ }
context = prepareContext(action, request, response, engine_context);
- if (prepareAction(action, request, response, engine_context, context)==false)
+ if (prepareAction(action, request, response, engine_context, context) == false)
return;
XWikiForm form = null;
if (action.equals("edit")
- ||action.equals("inline"))
+ || action.equals("inline"))
form = new PrepareEditForm();
else if (action.equals("preview"))
form = new EditForm();
- if (form!=null) {
+ if (form != null) {
form.reset(null, request);
context.setForm(form);
}
@@ -275,63 +276,51 @@
// Determine what to do
if (action.equals("view")) {
renderResult = (new ViewAction()).render(context);
- }
- else if ( action.equals("viewrev")) {
+ } else if (action.equals("viewrev")) {
renderResult = (new ViewrevAction()).render(context);
- }
- else if ( action.equals("inline")) {
+ } else if (action.equals("inline")) {
renderResult = (new InlineAction()).render(context);
- }
- else if ( action.equals("edit") ) {
+ } else if (action.equals("edit")) {
renderResult = (new EditAction()).render(context);
- }
- else if ( action.equals("preview")) {
+ } else if (action.equals("preview")) {
renderResult = (new PreviewAction()).render(context);
- }
- else if (action.equals("delete")) {
+ } else if (action.equals("delete")) {
renderResult = (new DeleteAction()).render(context);
- }
- else if (action.equals("download")) {
+ } else if (action.equals("download")) {
renderResult = (new DownloadAction()).render(context);
- }
- else if (action.equals("downloadrev")) {
+ } else if (action.equals("downloadrev")) {
renderResult = (new DownloadRevAction()).render(context);
- }
- else if (action.equals("dot")) {
+ } else if (action.equals("viewattachrev")) {
+ renderResult = (new ViewAttachRevAction()).render(context);
+ } else if (action.equals("dot")) {
renderResult = (new DotAction()).render(context);
- }
- else if (action.equals("svg")) {
+ } else if (action.equals("svg")) {
renderResult = (new SVGAction()).render(context);
- }
- else if (action.equals("attach")) {
+ } else if (action.equals("attach")) {
renderResult = (new AttachAction()).render(context);
- }
- else if (action.equals("login")) {
+ } else if (action.equals("login")) {
renderResult = (new LoginAction()).render(context);
- }
- else if (action.equals("loginerror")) {
+ } else if (action.equals("loginerror")) {
renderResult = (new LoginErrorAction()).render(context);
- }
- else if (action.equals("register")) {
+ } else if (action.equals("register")) {
renderResult = (new RegisterAction()).render(context);
+ } else if (action.equals("portletConfig")) {
+ renderResult = "portletConfig";
}
- else if ( action.equals("portletConfig") ) {
- renderResult = "portletConfig";
- }
- if (renderResult!=null) {
+ if (renderResult != null) {
String page = Utils.getPage(request, renderResult);
Utils.parseTemplate(page, context);
}
} catch (Throwable e) {
- if (logger.isWarnEnabled()) {
- logger.warn("oops",e);
- }
+ if (logger.isWarnEnabled()) {
+ logger.warn("oops", e);
+ }
handleException(request, response, e, context);
} finally {
// Let's make sure we have flushed content and closed
try {
- response.getWriter().flush();
+ response.getWriter().flush();
} catch (Throwable e) {
}
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-09 12:14:02 UTC (rev 968)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/XWikiPortletURLFactory.java 2006-03-10 02:16:25 UTC (rev 969)
@@ -1,38 +1,36 @@
-/*
- * 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 namphunghai
- * @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 namphunghai
+ * @author wr0ngway
+ * @author sdumitriu
+ */
package com.xpn.xwiki.web;
-import java.net.URL;
-import java.util.Map;
-
-import javax.portlet.PortletURL;
-
+import com.xpn.xwiki.XWikiContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import com.xpn.xwiki.XWikiContext;
+import javax.portlet.PortletURL;
+import java.net.URL;
+import java.util.Map;
public class XWikiPortletURLFactory extends XWikiServletURLFactory {
@@ -50,6 +48,35 @@
actionPath = "bin/";
}
+ public URL createAttachmentURL(String filename, String web, String name, String action, String xwikidb, XWikiContext context) {
+ try {
+ XWikiResponse response = context.getResponse();
+ PortletURL purl;
+ if (action.equals("download"))
+ return super.createAttachmentURL(filename, web, name, action, xwikidb, context); //To change body of overridden methods use File | Settings | File Templates.
+ else if (action.equals("viewattachrev")) {
+ purl = response.createRenderURL();
+ purl.setParameter("filename", filename);
+ purl.setParameter("action", action);
+ purl.setParameter("topic", web + "." + name);
+ } else {
+ purl = response.createActionURL();
+ purl.setParameter("topic", web + "." + name);
+ purl.setParameter("filename", filename);
+ purl.setParameter("action", action);
+ }
+
+ if (log.isDebugEnabled())
+ log.debug("Generated URL is: " + purl.toString());
+
+ return new URL(serverURL, purl.toString());
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
public URL createURL(String web, String name, String action, String querystring, String anchor, String xwikidb, XWikiContext context) {
try {
if (log.isDebugEnabled())
@@ -59,15 +86,15 @@
XWikiResponse response = context.getResponse();
PortletURL purl;
- if (action.equals("view")||action.equals("viewrev")||action.equals("download")||action.equals("downloadrev")||action.equals("skin")||action.equals("dot"))
+ if (action.equals("view") || action.equals("viewrev") || action.equals("attach") || action.equals("download") || action.equals("downloadrev") || action.equals("viewattachrev") || action.equals("skin") || action.equals("dot"))
purl = response.createRenderURL();
-
- if (action.equals("save")||action.equals("cancel")||action.equals("delete")||action.equals("propupdate")
- ||action.equals("propadd")||action.equals("propdelete")
- ||action.equals("objectadd")||action.equals("objectremove")
- ||action.equals("commentadd")||action.equals("editprefs")
- ||action.equals("upload")||action.equals("delattachment")
- ||action.equals("login")||action.equals("logout"))
+ else
+ if (action.equals("save") || action.equals("cancel") || action.equals("delete") || action.equals("propupdate")
+ || action.equals("propadd") || action.equals("propdelete")
+ || action.equals("objectadd") || action.equals("objectremove")
+ || action.equals("commentadd") || action.equals("editprefs")
+ || action.equals("upload") || action.equals("delattachment")
+ || action.equals("login") || action.equals("logout"))
purl = response.createActionURL();
else
purl = response.createRenderURL();
@@ -95,7 +122,7 @@
}
public URL createURL(String web, String name, String action, boolean redirect, XWikiContext context) {
- if (redirect==false)
+ if (redirect == false)
return createURL(web, name, action, context);
try {
Modified: xwiki/trunk/src/main/web/templates/attachments.vm
===================================================================
--- xwiki/trunk/src/main/web/templates/attachments.vm 2006-03-09 12:14:02 UTC (rev 968)
+++ xwiki/trunk/src/main/web/templates/attachments.vm 2006-03-10 02:16:25 UTC (rev 969)
@@ -5,73 +5,86 @@
#set($attachments = $doc.attachmentList)
#if($attachments.size()>0)
<div id="xwikiattachments" class="xwikidata">
-<div class="xwikidatatitle2">
-<div class="xwikidatatitle1"> </div>
-<div class="xwikidatatitle">
-<a href="" onclick="showhide('xwikiattachmentscontent'); return false">$msg.get("Attachments")</a>:
-$!attachments.size() $msg.get("attachments") #if($attachments.size()>0) $msg.get("by")
-$xwiki.getLocalUserName($attachments.get(0).author) ...
-#end
-</div>
-</div>
-<div id="xwikiattachmentscontent" class="xwikidatacontent" #if($showattachments!="open") style="display:none" #end>
-<table>
-<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>
-#foreach ($attach in $attachments)
-<tr>
-<td>
-#if ($attach.isImage())
-<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>$xwiki.getLocalUserName($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>
-</tr>
-#set( $counter = $counter + 1)
-#end
-</table>
-<br />
-<form action="$doc.getURL("upload")" enctype="multipart/form-data" method="post">
-<p>
-<script type="text/javascript">
-function updateAttachName(form) {
- var fname = form.filepath.value;
+ <div class="xwikidatatitle2">
+ <div class="xwikidatatitle1"> </div>
- if (fname=="") {
- return false;
- }
+ <div class="xwikidatatitle">
+ <a href="" onclick="showhide('xwikiattachmentscontent'); return false">$msg.get("Attachments")</a>:
+ $!attachments.size() $msg.get("attachments") #if($attachments.size()>0) $msg.get("by")
+ $xwiki.getLocalUserName($attachments.get(0).author) ...
+ #end
+ </div>
+ </div>
- var i = fname.lastIndexOf('\\');
- if (i==-1)
- i = fname.lastIndexOf('/');
+ <div id="xwikiattachmentscontent" class="xwikidatacontent"#if($showattachments!="open") style="display:none" #end>
+ < table>
+ <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("history")</b></th><th><b>$msg.get("delete")</b>
+ </th></tr>
+ #foreach ($attach in $attachments)
+ <tr>
+ <td>
+ #if ($attach.isImage())
+ <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>$xwiki.getLocalUserName($attach.author)</td><td>$attach.filesize</td>
+ <td align="center">
+ <a href="$doc.getAttachmentURL("${attach.filename}", "viewattachrev")">$msg.get("history")</ a>
+ </td>
+ <td>
+ <a href="$doc.getAttachmentURL("${attach.filename}", "delattachment")" onclick="return confirm('$msg.get("confirmdelattachment")');">$msg.get("delete")</
+ a></td>
+ </tr>
+ #set( $counter = $counter + 1)
+ #end
+ </table>
+ <br/>
- fname = fname.substring(i+1);
- if (form.filename.value==fname)
- return true;
+ <form action="$doc.getURL(" upload")" enctype="multipart/form-data" method="post">
+ < p>
+ <script type="text/javascript">
+ function updateAttachName(form) {
+ var fname = form.filepath.value;
- if (form.filename.value=="")
- form.filename.value = fname;
- else {
- if (confirm("$msg.get("doyouwanttoreplace") '" + fname + "' ?"))
- form.filename.value = fname;
- }
- return true;
-}
-</script>
-$msg.get("choosetargetfilename"):
-<input type="text" name="filename" value="" size="20" />
-<br /><br />
-$msg.get("choosefiletoupload"):
-<input type="file" name="filepath" value="" size="40" />
-<br /><br />
-<input type="submit" value="$msg.get("attachthisfile")" onclick="return updateAttachName(this.form)" />
-</p>
-</form>
+ if (fname == "") {
+ return false;
+ }
+
+ var i = fname.lastIndexOf('\\');
+ if (i == -1)
+ i = fname.lastIndexOf('/');
+
+ fname = fname.substring(i + 1);
+ if (form.filename.value == fname)
+ return true;
+
+ if (form.filename.value == "")
+ form.filename.value = fname;
+ else {
+ if (confirm("$msg.get("doyouwanttoreplace
+ ") '" + fname + "' ?"
+ ))
+ form.filename.value = fname;
+ }
+ return true;
+ }
+ </script>
+ $msg.get("choosetargetfilename"):
+ <input type="text" name="filename" value="" size="20"/>
+ <br/><br/>
+ $msg.get("choosefiletoupload"):
+ <input type="file" name="filepath" value="" size="40"/>
+ <br/><br/>
+ <input type="submit" value="$msg.get(" attachthisfile")" onclick="return updateAttachName(this.form)" />
+ </ p>
+ </form>
</div>
<div class="xwikidatafooter2">
-<div class="xwikidatafooter1"> </div>
-<div class="xwikidatafooter"> </div>
+ <div class="xwikidatafooter1"> </div>
+
+ <div class="xwikidatafooter"> </div>
</div>
</div>
#end
More information about the Xwiki-notifications
mailing list