Skip to content

Commit

Permalink
Feature #5710 : implementing an HTML5 drag & drop plugin for file & f…
Browse files Browse the repository at this point in the history
…older uploads.

- wiring Gallery application
- wiring Kmelia application by keeping all the functional behavior that was already existing
- enabling drag and drop of attachments to subjects and messages of Forums application
- wiring SilverCrawler application (cleaning some code)

In kmelia application:
- specifying that validateImportedFilesClassification.jsp provides content for popup.
- wiring an existing document import of zip archive with the centralized import services...

Adding a new behavior about massive creation of publications by Drag & Drop in Kmelia application.
  • Loading branch information
SilverYoCha committed Sep 21, 2015
1 parent 657a80c commit ff27539
Show file tree
Hide file tree
Showing 34 changed files with 835 additions and 909 deletions.
Expand Up @@ -419,7 +419,6 @@
<c:param name="ComponentId"><%=instanceId%></c:param>
<c:param name="Context" value="${'attachment'}" />
<c:param name="addFileMenu" value="${'true'}" />
<c:param name="dnd" value="${'false'}" />
<c:param name="notI18n" value="${'true'}" />
<c:param name="CallbackUrl" value="${callBackUrl}" />
</c:import>
Expand Down
@@ -1,19 +1,19 @@
$if(albumPart)$
Dieses Album enthält noch keine sub-Alben.<br/>
Um einen hinzuzufügen, verwenden Sie eine der folgenden Lösungen:
This album contains no albums yet.<br/>
To add some, use:
<ul>
$if(dragAndDropEnable)$<li>einen Ordner in der Drag and Drop Zone verschieben</li>$endif$
<li>der Vorgang <a href="$albumUrl$">$albumOperation$</a></li>
$if(dragAndDropEnable)$<li class="dragAndDropUploadCheck"><b>this zone</b> to perform a <b>drag&drop</b> of folders</li>$endif$
<li>the operation <a href="$albumUrl$">$albumOperation$</a></li>
</ul><br/><br/>
$endif$
Dieses Album enthält noch keine Medien.
This album contains no media yet.
$if(mediaPart)$<br/>
Um eine hinzuzufügen, verwenden Sie eine der folgenden Lösungen:
To add one, use:
<ul>
$if(dragAndDropEnable)$<li>Die Drag and Drop Zone</li>$endif$
<li>der Vorgang <a href="$photoUrl$">$photoOperation$</a></li>
<li>der Vorgang <a href="$videoUrl$">$videoOperation$</a></li>
<li>der Vorgang <a href="$soundUrl$">$soundOperation$</a></li>
<li>der Vorgang <a href="$streamingUrl$">$streamingOperation$</a></li>
$if(dragAndDropEnable)$<li class="dragAndDropUploadCheck"><b>this zone</b> to perform a <b>drag&drop</b> of media</li>$endif$
<li>the operation <a href="$photoUrl$">$photoOperation$</a></li>
<li>the operation <a href="$videoUrl$">$videoOperation$</a></li>
<li>the operation <a href="$soundUrl$">$soundOperation$</a></li>
<li>the operation <a href="$streamingUrl$">$streamingOperation$</a></li>
</ul>
$endif$
@@ -1,16 +1,16 @@
$if(albumPart)$
This album contains no albums yet.<br/>
To add one, use one of the following:
To add some, use:
<ul>
$if(dragAndDropEnable)$<li>drag a folder in the drag and drop zone</li>$endif$
$if(dragAndDropEnable)$<li class="dragAndDropUploadCheck"><b>this zone</b> to perform a <b>drag&drop</b> of folders</li>$endif$
<li>the operation <a href="$albumUrl$">$albumOperation$</a></li>
</ul><br/><br/>
$endif$
This album contains no media yet.
$if(mediaPart)$<br/>
To add one, use one of the following:
To add one, use:
<ul>
$if(dragAndDropEnable)$<li>the drag and drop zone</li>$endif$
$if(dragAndDropEnable)$<li class="dragAndDropUploadCheck"><b>this zone</b> to perform a <b>drag&drop</b> of media</li>$endif$
<li>the operation <a href="$photoUrl$">$photoOperation$</a></li>
<li>the operation <a href="$videoUrl$">$videoOperation$</a></li>
<li>the operation <a href="$soundUrl$">$soundOperation$</a></li>
Expand Down
@@ -1,16 +1,16 @@
$if(albumPart)$
Cet album ne contient pas encore de sous albums.<br/>
Pour en ajouter un, utilisez une des solutions suivantes :
Pour en ajouter, utiliser :
<ul>
$if(dragAndDropEnable)$<li>glisser un dossier dans la zone de glisser-déposer</li>$endif$
$if(dragAndDropEnable)$<li class="dragAndDropUploadCheck"><b>cette zone</b> pour effectuer un <b>glisser-déposer</b> de dossiers (selon les capacités de votre navigateur WEB) dans cette zone</li>$endif$
<li>l'opération <a href="$albumUrl$">$albumOperation$</a></li>
</ul><br/><br/>
$endif$
Cet album ne contient pas encore de média.
$if(mediaPart)$<br/>
Pour en ajouter un, utilisez une des solutions suivantes :
Pour en ajouter, utiliser :
<ul>
$if(dragAndDropEnable)$<li>la zone de glisser-déposez</li>$endif$
$if(dragAndDropEnable)$<li class="dragAndDropUploadCheck"><b>cette zone pour effectuer un glisser-déposer de médias</b></li>$endif$
<li>l'opération <a href="$photoUrl$">$photoOperation$</a></li>
<li>l'opération <a href="$videoUrl$">$videoOperation$</a></li>
<li>l'opération <a href="$soundUrl$">$soundOperation$</a></li>
Expand Down
Expand Up @@ -26,42 +26,32 @@
import com.silverpeas.util.FileUtil;
import com.silverpeas.util.StringUtil;
import com.silverpeas.util.ZipManager;
import com.stratelia.silverpeas.peasCore.servlets.SilverpeasAuthenticatedHttpServlet;
import com.stratelia.silverpeas.silvertrace.SilverTrace;
import com.stratelia.webactiv.beans.admin.OrganizationController;
import com.stratelia.webactiv.beans.admin.UserDetail;
import com.stratelia.webactiv.util.EJBUtilitaire;
import com.stratelia.webactiv.util.FileRepositoryManager;
import com.stratelia.webactiv.util.JNDINames;
import com.stratelia.webactiv.util.exception.SilverpeasRuntimeException;
import com.stratelia.webactiv.util.fileFolder.FileFolderManager;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.io.FileUtils;
import org.silverpeas.cache.service.CacheServiceFactory;
import org.silverpeas.core.admin.OrganisationController;
import org.silverpeas.servlet.FileUploadUtil;
import org.silverpeas.servlet.HttpRequest;
import org.silverpeas.web.util.SilverpeasTransverseWebErrorUtil;
import org.silverpeas.upload.UploadSession;
import org.silverpeas.util.error.SilverpeasTransverseErrorUtil;

import javax.ejb.EJBException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

import static com.silverpeas.util.StringUtil.isDefined;

/**
* Class declaration
*
*
* @author
*/
public class GalleryDragAndDrop extends HttpServlet {
public class GalleryDragAndDrop extends SilverpeasAuthenticatedHttpServlet {

private static final long serialVersionUID = -3063286463794353943L;

Expand All @@ -71,7 +61,7 @@ public void init(ServletConfig config) {
super.init(config);
} catch (ServletException se) {
SilverTrace.fatal("importExportPeas", "ImportDragAndDrop.init",
"peasUtil.CANNOT_ACCESS_SUPERCLASS");
"peasUtil.CANNOT_ACCESS_SUPERCLASS");
}
}

Expand All @@ -85,67 +75,43 @@ public void doGet(HttpServletRequest req, HttpServletResponse res)
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
SilverTrace.info("gallery", "GalleryDragAndDrop.doPost", "root.MSG_GEN_ENTER_METHOD");
String userId = null;
UserDetail userDetail = UserDetail.getCurrentRequester();
HttpRequest request = HttpRequest.decorate(req);
UploadSession uploadSession = UploadSession.from(request);
try {
request.setCharacterEncoding("UTF-8");
String componentId = request.getParameter("ComponentId");
String albumId = request.getParameter("AlbumId");
userId = request.getParameter("UserId");

if (!uploadSession.isUserAuthorized(componentId)) {
throwHttpForbiddenError();
}

SilverTrace.info("gallery", "GalleryDragAndDrop.doPost", "root.MSG_GEN_PARAM_VALUE",
"componentId = " + componentId + " albumId = " + albumId + " userId = " + userId);

File savePath =
new File(FileRepositoryManager.getTemporaryPath(), UUID.randomUUID().toString());

List<FileItem> items = request.getFileItems();

for (FileItem item : items) {
if (!item.isFormField()) {
String fileUploadId = item.getFieldName().substring(4);
String fileNameParam = FileUploadUtil.getFileName(item);
String parentPathParam =
FileUploadUtil.getParameter(items, "relpathinfo" + fileUploadId, null);
if (fileNameParam != null) {

File filePath = new File(
new File(savePath, (StringUtil.isDefined(parentPathParam) ? parentPathParam : "")),
fileNameParam);

SilverTrace
.info("gallery", "GalleryDragAndDrop.doPost.doPost", "root.MSG_GEN_PARAM_VALUE",
"item = " + item.getFieldName() + " - full path = " + filePath);

File parentFolder = filePath.getParentFile();
if (!parentFolder.exists()) {
parentFolder.mkdirs();
}

item.write(filePath);

// Cas du zip
if (FileUtil.isArchive(filePath.getName())) {
ZipManager.extract(filePath, parentFolder);
}
}
}
"componentId = " + componentId + " albumId = " + albumId + " userId = " +
userDetail.getId());

for (File filePath : uploadSession.getRootFolderFiles()) {

SilverTrace.info("gallery", "GalleryDragAndDrop.doPost.doPost", "root.MSG_GEN_PARAM_VALUE",
"full path = " + filePath);

// Cas du zip
if (FileUtil.isArchive(filePath.getName())) {
ZipManager.extract(filePath, filePath.getParentFile());
}
}
importRepository(savePath, userId, componentId, albumId);
FileUtils.deleteQuietly(savePath);

importRepository(uploadSession.getRootFolder(), userDetail.getId(), componentId, albumId);

} catch (Exception e) {
SilverTrace.debug("gallery", "GalleryDragAndDrop.doPost.doPost", "root.MSG_GEN_PARAM_VALUE",
e);
final StringBuilder sb = new StringBuilder("ERROR");
final String errorMessage = SilverpeasTransverseWebErrorUtil
.performAppletAlertExceptionMessage(e,
UserDetail.getById(userId).getUserPreferences().getLanguage());
if (isDefined(errorMessage)) {
sb.append(": ");
sb.append(errorMessage);
}
res.getOutputStream().println(sb.toString());
SilverTrace
.debug("gallery", "GalleryDragAndDrop.doPost.doPost", "root.MSG_GEN_PARAM_VALUE", e);
SilverpeasTransverseErrorUtil
.throwTransverseErrorIfAny(e, userDetail.getUserPreferences().getLanguage());
} finally {
uploadSession.clear();
}
res.getOutputStream().println("SUCCESS");
}

private void importRepository(final File repository, final String userId, final String componentId,
Expand Down Expand Up @@ -184,15 +150,6 @@ private void importRepository(final File repository, final String userId, final
}
}

private String getParameterValue(List<FileItem> items, String parameterName) {
for (FileItem item : items) {
if (item.isFormField() && parameterName.equals(item.getFieldName())) {
return item.getString();
}
}
return null;
}

/**
* Gets the GalleryBm EJB proxy
* @return
Expand Down
Expand Up @@ -159,6 +159,9 @@ public String getDestination(String function, GallerySessionController gallerySC
request.setAttribute("IsOrder", gallerySC.isOrder());
destination = rootDest + "welcome.jsp";
} else if ("ViewAlbum".equals(function)) {
if (StringUtil.isDefined(request.getParameter("deselectAll"))) {
deselectAll(gallerySC);
}
// récupération de l'Id de l'album en cours
String albumId = request.getParameter("Id");
gallerySC.goToAlbum(albumId);
Expand Down

0 comments on commit ff27539

Please sign in to comment.