diff --git a/Examples/WebContent/index.html b/Examples/WebContent/index.html index 5c52342..cdd2e6d 100644 --- a/Examples/WebContent/index.html +++ b/Examples/WebContent/index.html @@ -79,6 +79,10 @@

Sample 1: Save to disk

fileUploadParams: { id: 'my_editor' }, + videoUploadURL: '/upload_video', + videoUploadParams: { + id: 'my_editor' + }, imageManagerLoadURL: '/load_images', imageManagerDeleteURL: "/delete_image", imageManagerDeleteMethod: "POST" @@ -121,6 +125,25 @@

Sample 1: Save to disk

console.log ('file delete problem: ' + JSON.stringify(err)); }) }) + // Catch video removal from the editor. + .on('froalaEditor.video.removed', function (e, editor, $vid) { + $.ajax({ + // Request method. + method: "POST", + // Request URL. + url: "/delete_video", + // Request params. + data: { + src: $vid.attr('src') + } + }) + .done (function (data) { + console.log ('video was deleted'); + }) + .fail (function (err) { + console.log ('video delete problem: ' + JSON.stringify(err)); + }) + }) }); @@ -264,7 +287,8 @@

Sample 4: Save to Amazon using signature version 4

.done(function( data ) { $('#edit-amazon').froalaEditor({ imageUploadToS3: data, - fileUploadToS3: data + fileUploadToS3: data, + videoUploadToS3: data }) }); }); diff --git a/Examples/build/classes/com/froala/examples/servlets/DeleteVideo.class b/Examples/build/classes/com/froala/examples/servlets/DeleteVideo.class new file mode 100644 index 0000000..4d44c12 Binary files /dev/null and b/Examples/build/classes/com/froala/examples/servlets/DeleteVideo.class differ diff --git a/Examples/build/classes/com/froala/examples/servlets/UploadVideo.class b/Examples/build/classes/com/froala/examples/servlets/UploadVideo.class new file mode 100644 index 0000000..fccb9ec Binary files /dev/null and b/Examples/build/classes/com/froala/examples/servlets/UploadVideo.class differ diff --git a/Examples/src/com/froala/examples/servlets/DeleteVideo.java b/Examples/src/com/froala/examples/servlets/DeleteVideo.java new file mode 100644 index 0000000..7bd5052 --- /dev/null +++ b/Examples/src/com/froala/examples/servlets/DeleteVideo.java @@ -0,0 +1,51 @@ +package com.froala.examples.servlets; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.froala.editor.Video; +import com.google.gson.Gson; + +/** + * Servlet implementation class DeleteVideo + */ +@WebServlet("/delete_video") +public class DeleteVideo extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public DeleteVideo() { + super(); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse + * response) + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + String src = request.getParameter("src"); + + try { + Video.delete(request, src); + } catch (Exception e) { + e.printStackTrace(); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + return; + } + String jsonResponseData = new Gson().toJson("Success"); + response.setContentType("application/json"); + response.setCharacterEncoding("UTF-8"); + response.getWriter().write(jsonResponseData); + } + +} diff --git a/Examples/src/com/froala/examples/servlets/UploadImage.java b/Examples/src/com/froala/examples/servlets/UploadImage.java index faac973..74a9176 100644 --- a/Examples/src/com/froala/examples/servlets/UploadImage.java +++ b/Examples/src/com/froala/examples/servlets/UploadImage.java @@ -49,10 +49,22 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) responseData = new HashMap(); responseData.put("error", e.toString()); } - String jsonResponseData = new Gson().toJson(responseData); - response.setContentType("application/json"); - response.setCharacterEncoding("UTF-8"); - response.getWriter().write(jsonResponseData); + // Wait for 5 secs for image upload + synchronized (responseData) { + try + { + responseData.wait(5000); + String jsonResponseData = new Gson().toJson(responseData); + response.setContentType("application/json"); + response.setCharacterEncoding("UTF-8"); + response.getWriter().write(jsonResponseData); + } + catch ( InterruptedException e ) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } } diff --git a/Examples/src/com/froala/examples/servlets/UploadVideo.java b/Examples/src/com/froala/examples/servlets/UploadVideo.java new file mode 100644 index 0000000..ad9e345 --- /dev/null +++ b/Examples/src/com/froala/examples/servlets/UploadVideo.java @@ -0,0 +1,70 @@ +package com.froala.examples.servlets; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.annotation.MultipartConfig; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.froala.editor.Video; +import com.google.gson.Gson; + +/** + * Servlet implementation class UploadVideo + */ +@WebServlet("/upload_video") +@MultipartConfig +public class UploadVideo extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public UploadVideo() { + super(); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse + * response) + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + String fileRoute = "/public/"; + + Map responseData; + try { + responseData = Video.upload(request, fileRoute); // Use default + // video + // validation. + } catch (Exception e) { + e.printStackTrace(); + responseData = new HashMap(); + responseData.put("error", e.toString()); + } + // Wait for 5 secs for video upload + synchronized (responseData) { + try + { + responseData.wait(5000); + String jsonResponseData = new Gson().toJson(responseData); + response.setContentType("application/json"); + response.setCharacterEncoding("UTF-8"); + response.getWriter().write(jsonResponseData); + } + catch ( InterruptedException e ) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + +} diff --git a/Lib/bin/com/froala/editor/Video.class b/Lib/bin/com/froala/editor/Video.class new file mode 100644 index 0000000..b5c4b22 Binary files /dev/null and b/Lib/bin/com/froala/editor/Video.class differ diff --git a/Lib/bin/com/froala/editor/video/VideoOptions.class b/Lib/bin/com/froala/editor/video/VideoOptions.class new file mode 100644 index 0000000..0a4a106 Binary files /dev/null and b/Lib/bin/com/froala/editor/video/VideoOptions.class differ diff --git a/Lib/bin/com/froala/editor/video/VideoValidation.class b/Lib/bin/com/froala/editor/video/VideoValidation.class new file mode 100644 index 0000000..01e3151 Binary files /dev/null and b/Lib/bin/com/froala/editor/video/VideoValidation.class differ diff --git a/Lib/src/com/froala/editor/Video.java b/Lib/src/com/froala/editor/Video.java new file mode 100644 index 0000000..fe969f0 --- /dev/null +++ b/Lib/src/com/froala/editor/Video.java @@ -0,0 +1,87 @@ +package com.froala.editor; + +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import com.froala.editor.video.VideoOptions; + +/** + * Video functionality. + * + * @author florin@froala.com + */ +public final class Video { + + /** + * Private constructor. + */ + private Video() { + + } + + /** + * File default options. + */ + public static final VideoOptions defaultOptions = new VideoOptions(); + + /** + * Uploads a video to disk. + * + * @param req + * Servlet HTTP request. + * @param fileRoute + * Route Server route where the file will be uploaded. This route + * must be public to be accesed by the editor. + * @return Object with link. + * @throws Exception + */ + public static Map upload(HttpServletRequest req, String fileRoute) throws Exception { + + return upload(req, fileRoute, defaultOptions); + } + + /** + * Uploads a video to disk. + * + * @param req + * Servlet HTTP request. + * @param fileRoute + * Server route where the file will be uploaded. This route must + * be public to be accesed by the editor. + * @param options + * Video options. Defaults to {@link #defaultOptions} which has + *
+ * Fieldname: "file"
+ * Validation: + *
    + *
  • Extensions: ".mp4", ".webm", ".ogg"
  • + *
  • Mime Types: "video/mp4", "video/webm", "video/ogg"
  • + *
+ * + * @return Object with link. + * @throws Exception + */ + public static Map upload(HttpServletRequest req, String fileRoute, VideoOptions options) + throws Exception { + + if (options == null) { + options = defaultOptions; + } + + return File.upload(req, fileRoute, options); + } + + /** + * Delete a video from disk. + * + * @param req + * Used to get the servlet context. + * @param src + * Server file path. + */ + public static void delete(HttpServletRequest req, String src) { + File.delete(req, src); + } + +} diff --git a/Lib/src/com/froala/editor/file/FileValidation.java b/Lib/src/com/froala/editor/file/FileValidation.java index 2836b73..61ea6e1 100644 --- a/Lib/src/com/froala/editor/file/FileValidation.java +++ b/Lib/src/com/froala/editor/file/FileValidation.java @@ -106,7 +106,7 @@ public boolean check(String filePath, String mimeType) { return customValidation.validate(filePath, mimeType); } - return ArrayUtils.contains(allowedExts, FilenameUtils.getExtension(filePath)) + return ArrayUtils.contains(allowedExts, FilenameUtils.getExtension(filePath).toLowerCase()) && ArrayUtils.contains(allowedMimeTypes, mimeType.toLowerCase()); } } diff --git a/Lib/src/com/froala/editor/video/VideoOptions.java b/Lib/src/com/froala/editor/video/VideoOptions.java new file mode 100644 index 0000000..2bac459 --- /dev/null +++ b/Lib/src/com/froala/editor/video/VideoOptions.java @@ -0,0 +1,28 @@ +package com.froala.editor.video; + +import com.froala.editor.file.FileOptions; + +/** + * Video Options used for uploading. + * + * @author florin@froala.com + */ +public class VideoOptions extends FileOptions { + + /** + * Init default video upload settings. + */ + @Override + protected void initDefault() { + setValidation(new VideoValidation()); + } + + /** + * Constructor. Uses default options: - fieldname "file" - validation + * default VideoValidation. To change them, use getters and setters. + */ + public VideoOptions() { + super(); + } + +} diff --git a/Lib/src/com/froala/editor/video/VideoValidation.java b/Lib/src/com/froala/editor/video/VideoValidation.java new file mode 100644 index 0000000..1899b80 --- /dev/null +++ b/Lib/src/com/froala/editor/video/VideoValidation.java @@ -0,0 +1,53 @@ +package com.froala.editor.video; + +import com.froala.editor.file.FileValidation; + +/** + * Video Validation. + * + * @author florin@froala.com + */ +public class VideoValidation extends FileValidation { + + /** + * Allowed video validation default extensions. + */ + public static final String[] allowedVideoExtsDefault = new String[] { "mp4", "webm", "ogg" }; + + /** + * Allowed video validation default mimetypes. + */ + public static final String[] allowedVideoMimeTypesDefault = new String[] { "video/mp4", "video/webm", "video/ogg" }; + + /** + * Init default video validation settings. + */ + @Override + protected void initDefault() { + + allowedExts = allowedVideoExtsDefault; + allowedMimeTypes = allowedVideoMimeTypesDefault; + } + + /** + * Constructor. Validates default videos with: - allowed file extensions: + * ".mp4", ".webm", ".ogg" - allowed mime types: + * "video/mp4", "video/webm", "video/ogg" + */ + public VideoValidation() { + super(); + } + + /** + * Constructor. + * + * @param allowedExts + * Allowed validation video extensions. + * @param allowedMimeTypes + * Allowed validation video mimetypes. + */ + public VideoValidation(String[] allowedExts, String[] allowedMimeTypes) { + super(allowedExts, allowedMimeTypes); + } + +}