有人在这里用elfinder编辑过jsp文件吗?

时间:2019-11-15 15:50:47

标签: spring jsp editor mime elfinder

我已经在我的php项目中通过elfinder编辑了一个php文件。

但是,我无法通过elfinder在正在制作的java spring项目中编辑jsp文件。

这是我的elfinder配置选项。

$(document).ready(function() {
		$('#elfinder').elfinder(
			// 1st Arg - options
			{
				cssAutoLoad : false,               // Disable CSS auto loading
				baseUrl : '/assets/plugins/elFinder/',                    // Base URL to css/*, js/*
				url : '/mgmt/elfinder-servlet/connector/default', // connector URL (REQUIRED)
			uiOptions: {
					// toolbar configuration
					toolbar: [
						['home', 'back', 'forward', 'up', 'reload'],
						['mkdir', 'mkfile', 'upload'],
						['open', 'download', 'getfile'],
						['undo', 'redo'],
						['copy', 'cut', 'paste'],
						['duplicate', 'rename', 'edit', 'resize', 'chmod'],
						['selectall', 'selectnone', 'selectinvert'],
						['info'],
						['extract', 'archive'],
						['search'],
						['view', 'sort'],
						['fullscreen']
					]
				}
				,contextmenu : {
					// navbarfolder menu
					navbar : ['open', '|', 'copy', 'cut', 'paste', 'duplicate', '|', 'rm', '|', 'info'],
						// current directory menu
						cwd    : ['reload', 'back', '|', 'upload', 'mkdir', 'mkfile', 'paste', '|', 'sort', '|', 'info'],
						// current directory file menu
						files  : ['getfile', '|', 'custom', '|', 'download', '|', 'copy', 'cut', 'paste', 'duplicate', '|', 'rm', '|', 'edit', 'rename', '|', 'archive', 'extract', '|', 'info']
				}
				,width: '100%'
				,type: 'post'
				,commandsOptions : {
					quicklook : {
						// to enable CAD-Files and 3D-Models preview with sharecad.org
						sharecadMimes : ['image/vnd.dwg', 'image/vnd.dxf', 'model/vnd.dwf', 'application/vnd.hp-hpgl', 'application/plt', 'application/step', 'model/iges', 'application/vnd.ms-pki.stl', 'application/sat', 'image/cgm', 'application/x-msmetafile'],
							// to enable preview with Google Docs Viewer
							googleDocsMimes : ['application/pdf', 'image/tiff', 'application/vnd.ms-office', 'application/msword', 'application/vnd.ms-word', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/postscript', 'application/rtf'],
							// to enable preview with Microsoft Office Online Viewer
							// these MIME types override "googleDocsMimes"
							officeOnlineMimes : ['application/vnd.ms-office', 'application/msword', 'application/vnd.ms-word', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.spreadsheet', 'application/vnd.oasis.opendocument.presentation']
					},
					edit : {
						extraOptions : {
							// set API key to enable Creative Cloud image editor
							// see https://console.adobe.io/
							creativeCloudApiKey : '',
								// browsing manager URL for CKEditor, TinyMCE
								// uses self location with the empty value
								managerUrl : ''
						}
					}
				}
				// bootCalback calls at before elFinder boot up
				,bootCallback : function(fm, extraObj) {
					/* any bind functions etc. */
					fm.bind('init', function() {
						// any your code
					});
					// for example set document.title dynamically.
					var title = document.title;
					fm.bind('open', function() {
						var path = '',
							cwd  = fm.cwd();
						if (cwd) {
							path = fm.path(cwd.hash) || null;
						}
						document.title = path? path + ':' + title : title;
					}).bind('destroy', function() {
						document.title = title;
					});
				}
			},
			// 2nd Arg - before boot up function
			function(fm, extraObj) {
				// `init` event callback function
				fm.bind('init', function() {
					// Optional for Japanese decoder "encoding-japanese.js"
					if (fm.lang === 'ja') {
						fm.loadScript(
							[ '/assets/plugins/encoding.js/1.0.26/encoding.min.js' ],
							function() {
								if (window.Encoding && Encoding.convert) {
									fm.registRawStringDecoder(function(s) {
										return Encoding.convert(s, {to:'UNICODE',type:'string'});
									});
								}
							},
							{ loadType: 'tag' }
						);
					}
				});
			}
		);
	});

这是我的elfinder编辑器选项。

	(function(editors, elFinder) {
	if (typeof define === 'function' && define.amd) {
		define(['elfinder'], editors);
	} else if (elFinder) {
		var optEditors = elFinder.prototype._options.commandsOptions.edit.editors;
		elFinder.prototype._options.commandsOptions.edit.editors = optEditors.concat(editors(elFinder));
	}
}(function(elFinder) {
	"use strict";
	var apps = {},
		// get query of getfile
		getfile = window.location.search.match(/getfile=([a-z]+)/),
		useRequire = elFinder.prototype.hasRequire,
		hasFlash = (function() {
			var hasFlash;
			try {
				hasFlash = !!(new ActiveXObject('ShockwaveFlash.ShockwaveFlash'));
			} catch (e) {
				hasFlash = !!(typeof window.orientation === 'undefined' || (navigator && navigator.mimeTypes["application/x-shockwave-flash"]));
			}
			return hasFlash;
		})(),
		ext2mime = {
			bmp: 'image/x-ms-bmp',
			dng: 'image/x-adobe-dng',
			gif: 'image/gif',
			jsp: 'text/plain',
			jpeg: 'image/jpeg',
			jpg: 'image/jpeg',
			pdf: 'application/pdf',
			png: 'image/png',
			ppm: 'image/x-portable-pixmap',
			psd: 'image/vnd.adobe.photoshop',
			pxd: 'image/x-pixlr-data',
			svg: 'image/svg+xml',
			tiff: 'image/tiff',
			webp: 'image/webp',
			xcf: 'image/x-xcf',
			sketch: 'application/x-sketch'
		},
		mime2ext = {
			'text/plain'			  : 'jsp',
			'text/x-jsp'			  : 'jsp',
			'text/jsp'				  : 'jsp',
			'application/x-jsp'		  : 'jsp',
			'application/jsp'		  : 'jsp',
			'text/html'				  : 'html',
			'application/xhtml+xml'	  : 'html',
			'text/javascript'		  : 'javascript',
			'application/javascript'  : 'javascript',
			'text/css'				  : 'css',
			'text/x-c'				  : 'c_cpp',
			'text/x-csrc'			  : 'c_cpp',
			'text/x-chdr'			  : 'c_cpp',
			'text/x-c++'			  : 'c_cpp',
			'text/x-c++src'			  : 'c_cpp',
			'text/x-c++hdr'			  : 'c_cpp',
			'text/x-shellscript'	  : 'sh',
			'application/x-csh'		  : 'sh',
			'text/x-python'			  : 'python',
			'text/x-java'			  : 'java',
			'text/x-java-source'	  : 'java',
			'text/x-ruby'			  : 'ruby',
			'text/x-perl'			  : 'perl',
			'application/x-perl'	  : 'perl',
			'text/x-sql'			  : 'sql',
			'text/xml'				  : 'xml',
			'application/docbook+xml' : 'xml',
			'application/xml'		  : 'xml'
		},
		getExtention = function(mime, fm) {
			if (!mime2ext) {
				mime2ext = fm.arrayFlip(ext2mime);
			}
			var ext = mime2ext[mime] || fm.mimeTypes[mime];
			if (ext === 'jpeg') {
				ext = 'jpg';
			}
			return ext;
		},
		changeImageType = function(src, toMime) {
			var dfd = $.Deferred();
			try {
				var canvas = document.createElement('canvas'),
					ctx = canvas.getContext('2d'),
					img = new Image(),
					conv = function() {
						var url = canvas.toDataURL(toMime),
							mime, m;
						if (m = url.match(/^data:([a-z0-9]+\/[a-z0-9.+-]+)/i)) {
							mime = m[1];
						} else {
							mime = '';
						}
						if (mime.toLowerCase() === toMime.toLowerCase()) {
							dfd.resolve(canvas.toDataURL(toMime), canvas);
						} else {
							dfd.reject();
						}
					};

				img.src = src;
				$(img).on('load', function() {
					try {
						canvas.width = img.width;
						canvas.height = img.height;
						ctx.drawImage(img, 0, 0);
						conv();
					} catch(e) {
						dfd.reject();
					}
				}).on('error', function () {
					dfd.reject();
				});
				return dfd;
			} catch(e) {
				return dfd.reject();
			}
		},
		initImgTag = function(id, file, content, fm) {
			var node = $(this).children('img:first').data('ext', getExtention(file.mime, fm)),
				spnr = $('<div class="elfinder-edit-spinner elfinder-edit-image"/>')
					.html('<span class="elfinder-spinner-text">' + fm.i18n('ntfloadimg') + '</span><span class="elfinder-spinner"/>')
					.hide()
					.appendTo(this),
				url;

			if (!content.match(/^data:/)) {
				url = fm.openUrl(file.hash);
				node.attr('_src', content);
			}
			node.attr('id', id+'-img')
				.attr('src', url || content)
				.css({'height':'', 'max-width':'100%', 'max-height':'100%', 'cursor':'pointer'})
				.data('loading', function(done) {
					var btns = node.closest('.elfinder-dialog').find('button,.elfinder-titlebar-button');
					btns.prop('disabled', !done)[done? 'removeClass' : 'addClass']('ui-state-disabled');
					node.css('opacity', done? '' : '0.3');
					spnr[done? 'hide' : 'show']();
					return node;
				});
		},
		imgBase64 = function(node, mime) {
			var style = node.attr('style'),
				img, canvas, ctx, data;
			try {
				// reset css for getting image size
				node.attr('style', '');
				// img node
				img = node.get(0);
				// New Canvas
				canvas = document.createElement('canvas');
				canvas.width  = img.width;
				canvas.height = img.height;
				// restore css
				node.attr('style', style);
				// Draw Image
				canvas.getContext('2d').drawImage(img, 0, 0);
				// To Base64
				data = canvas.toDataURL(mime);
			} catch(e) {
				data = node.attr('src');
			}
			return data;
		};

	// check getfile callback function
	if (getfile) {
		getfile = getfile[1];
	}

	// return editors Array
	return [
		{
			// ACE Editor
			// called on initialization of elFinder cmd edit (this: this editor's config object)
			setup : function(opts, fm) {
				if (fm.UA.ltIE8 || !fm.options.cdns.ace) {
					this.disabled = true;
				}
			},
			// `mimes` is not set for support everything kind of text file
			info : {
				id : 'aceeditor',
				name : 'ACE Editor',
				iconImg : 'img/editor-icons.png 0 -96'
			},
			load : function(textarea) {
				var self = this,
					fm   = this.fm,
					dfrd = $.Deferred(),
					cdn  = fm.options.cdns.ace,
					start = function() {
						var editor, editorBase, mode,
							ta = $(textarea),
							taBase = ta.parent(),
							dialog = taBase.parent(),
							id = textarea.id + '_ace',
							ext = self.file.name.replace(/^.+\.([^.]+)|(.+)$/, '$1$2').toLowerCase(),
							// MIME/mode map
							mimeMode = {
								'text/plain'			  : 'txt',
								'text/x-jsp'			  : 'jsp',
								'text/jsp'				  : 'jsp',
								'application/x-jsp'		  : 'jsp',
								'application/jsp'		  : 'jsp',
								'text/x-php'			  : 'php',
								'application/x-php'		  : 'php',
								'text/html'				  : 'html',
								'application/xhtml+xml'	  : 'html',
								'text/javascript'		  : 'javascript',
								'application/javascript'  : 'javascript',
								'text/css'				  : 'css',
								'text/x-c'				  : 'c_cpp',
								'text/x-csrc'			  : 'c_cpp',
								'text/x-chdr'			  : 'c_cpp',
								'text/x-c++'			  : 'c_cpp',
								'text/x-c++src'			  : 'c_cpp',
								'text/x-c++hdr'			  : 'c_cpp',
								'text/x-shellscript'	  : 'sh',
								'application/x-csh'		  : 'sh',
								'text/x-python'			  : 'python',
								'text/x-java'			  : 'java',
								'text/x-java-source'	  : 'java',
								'text/x-ruby'			  : 'ruby',
								'text/x-perl'			  : 'perl',
								'application/x-perl'	  : 'perl',
								'text/x-sql'			  : 'sql',
								'text/xml'				  : 'xml',
								'application/docbook+xml' : 'xml',
								'application/xml'		  : 'xml'
							};

						// set base height
						taBase.height(taBase.height());

						// set basePath of ace
						ace.config.set('basePath', cdn);

						// Base node of Ace editor
						editorBase = $('<div id="'+id+'" style="width:100%; height:100%;"/>').text(ta.val()).insertBefore(ta.hide());

						// Editor flag
						ta.data('ace', true);

						// Aceeditor instance
						editor = ace.edit(id);

						// Ace editor configure
						editor.$blockScrolling = Infinity;
						editor.setOptions({
							theme: 'ace/theme/monokai',
							fontSize: '14px',
							wrap: true,
						});
						ace.config.loadModule('ace/ext/modelist', function() {
							// detect mode
							mode = ace.require('ace/ext/modelist').getModeForPath('/' + self.file.name).name;
							if (mode === 'text') {
								if (mimeMode[self.file.mime]) {
									mode = mimeMode[self.file.mime];
								}
							}
							// show MIME:mode in title bar
							taBase.prev().children('.elfinder-dialog-title').append(' (' + self.file.mime + ' : ' + mode.split(/[\/\\]/).pop() + ')');
							editor.setOptions({
								mode: 'ace/mode/' + mode
							});
							if (dfrd.state() === 'resolved') {
								dialog.trigger('resize');
							}
						});
						ace.config.loadModule('ace/ext/language_tools', function() {
							ace.require('ace/ext/language_tools');
							editor.setOptions({
								enableBasicAutocompletion: true,
								enableSnippets: true,
								enableLiveAutocompletion: false
							});
						});
						ace.config.loadModule('ace/ext/settings_menu', function() {
							ace.require('ace/ext/settings_menu').init(editor);
						});

						// Short cuts
						editor.commands.addCommand({
							name : "saveFile",
							bindKey: {
								win : 'Ctrl-s',
								mac : 'Command-s'
							},
							exec: function(editor) {
								self.doSave();
							}
						});
						editor.commands.addCommand({
							name : "closeEditor",
							bindKey: {
								win : 'Ctrl-w|Ctrl-q',
								mac : 'Command-w|Command-q'
							},
							exec: function(editor) {
								self.doCancel();
							}
						});

						editor.resize();

						// TextArea button and Setting button
						$('<div class="ui-dialog-buttonset"/>').css('float', 'left')
							.append(
								$('<button/>').html(self.fm.i18n('TextArea'))
									.button()
									.on('click', function(){
										if (ta.data('ace')) {
											ta.removeData('ace');
											editorBase.hide();
											ta.val(editor.session.getValue()).show().trigger('focus');
											$(this).text('AceEditor');
										} else {
											ta.data('ace', true);
											editorBase.show();
											editor.setValue(ta.hide().val(), -1);
											editor.focus();
											$(this).html(self.fm.i18n('TextArea'));
										}
									})
							)
							.append(
								$('<button>Ace editor setting</button>')
									.button({
										icons: {
											primary: 'ui-icon-gear',
											secondary: 'ui-icon-triangle-1-e'
										},
										text: false
									})
									.on('click', function(){
										editor.showSettingsMenu();
										$('#ace_settingsmenu')
											.css('font-size', '80%')
											.find('div[contains="setOptions"]').hide().end()
											.parent().appendTo($('#elfinder'));
									})
							)
							.prependTo(taBase.next());

						// trigger event 'editEditorPrepare'
						self.trigger('Prepare', {
							node: textarea,
							editorObj: ace,
							instance: editor,
							opts: {}
						});

						//dialog.trigger('resize');
						dfrd.resolve(editor);
					};

				// check ace & start
				if (!self.confObj.loader) {
					self.confObj.loader = $.Deferred();
					self.fm.loadScript([ cdn+'/ace.js' ], function() {
						self.confObj.loader.resolve();
					}, void 0, {obj: window, name: 'ace'});
				}
				self.confObj.loader.done(start);

				return dfrd;
			},
			close : function(textarea, instance) {
				instance && instance.destroy();
			},
			save : function(textarea, instance) {
				instance && $(textarea).data('ace') && (textarea.value = instance.session.getValue());
			},
			focus : function(textarea, instance) {
				instance && $(textarea).data('ace') && instance.focus();
			},
			resize : function(textarea, instance, e, data) {
				instance && instance.resize();
			}
		}
	];
}, window.elFinder));

我猜错是mime类型。 我不知道什么是jsp文件的mime类型。

有人在这里帮助我吗?

0 个答案:

没有答案