Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
burtbeckwith committed Aug 15, 2013
1 parent 3465563 commit c9e242e
Show file tree
Hide file tree
Showing 27 changed files with 160 additions and 273 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/scripts
/lib
/.settings
/plugin.xml
/grails-elfinder-connector-*.zip
55 changes: 13 additions & 42 deletions ElfinderConnectorGrailsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ import grails.plugin.elfinder.command.ElfinderParentsCommand
import grails.plugin.elfinder.command.ElfinderTreeCommand
import grails.plugin.elfinder.filemanager.ElfinderLocalFileSystemFileManager


/**
* @author Sudhir Nimavat
*
*/
class ElfinderConnectorGrailsPlugin {
// the plugin version
def version = "0.1"
def grailsVersion = "1.3 > *"
def grailsVersion = "2.0 > *"
def title = "Elfinder Connector Plugin"
def author = "Sudhir Nimavat"
def authorEmail = "sudhir@nimavat.me"
Expand All @@ -28,7 +25,6 @@ class ElfinderConnectorGrailsPlugin {
def issueManagement = [ system: "GITHUB", url: "https://github.com/snimavat/grails-elfinder-connector/issues" ]
def license = "APACHE"


def doWithSpring = {
//configure file manger
def pluginConfig = application.config.grails.plugin.elfinder
Expand All @@ -41,55 +37,30 @@ class ElfinderConnectorGrailsPlugin {
elfinderFileManager(ElfinderLocalFileSystemFileManager) { root = pluginConfig.rootDir }

//configure commands
elfinderOpenCommand(ElfinderOpenCommand) { bean ->
bean.scope = "prototype"
elFinderFileManager = ref("elfinderFileManager")
}

elfinderParentsCommand(ElfinderParentsCommand) { bean ->
def configurationClosure = { bean ->
bean.scope = "prototype"
elFinderFileManager = ref("elfinderFileManager")
}

elfinderTreeCommand(ElfinderTreeCommand) { bean ->
bean.scope = "prototype"
elFinderFileManager = ref("elfinderFileManager")
}
elfinderOpenCommand(ElfinderOpenCommand, configurationClosure)

elfinderMkdirCommand(ElFinderMkdirCommand) { bean ->
bean.scope = "prototype"
elFinderFileManager = ref("elfinderFileManager")
}
elfinderParentsCommand(ElfinderParentsCommand, configurationClosure)

elfinderMkfileCommand(ElFinderMkfileCommand) { bean ->
bean.scope = "prototype"
elFinderFileManager = ref("elfinderFileManager")
}
elfinderTreeCommand(ElfinderTreeCommand, configurationClosure)

elfinderRenameCommand(ElFinderRenameCommand) { bean ->
bean.scope = "prototype"
elFinderFileManager = ref("elfinderFileManager")
}
elfinderMkdirCommand(ElFinderMkdirCommand, configurationClosure)

elfinderRmCommand(ElFinderRmCommand) { bean ->
bean.scope = "prototype"
elFinderFileManager = ref("elfinderFileManager")
}
elfinderMkfileCommand(ElFinderMkfileCommand, configurationClosure)

elfinderLsCommand(ElfinderLsCommand) { bean ->
bean.scope = "prototype"
elFinderFileManager = ref("elfinderFileManager")
}
elfinderRenameCommand(ElFinderRenameCommand, configurationClosure)

elfinderFileCommand(ElFinderFileCommand) { bean ->
bean.scope = "prototype"
elFinderFileManager = ref("elfinderFileManager")
}
elfinderRmCommand(ElFinderRmCommand, configurationClosure)

elfinderUploadCommand(ElFinderUploadCommand) { bean ->
bean.scope = "prototype"
elFinderFileManager = ref("elfinderFileManager")
}
elfinderLsCommand(ElfinderLsCommand, configurationClosure)

elfinderFileCommand(ElFinderFileCommand, configurationClosure)

elfinderUploadCommand(ElFinderUploadCommand, configurationClosure)
}
}
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
grails-elfinder-connector
=========================

Elfinder file browser connector for grails
Elfinder file browser connector for Grails

elfinder demo : http://elfinder.org/

Expand All @@ -14,14 +14,11 @@ Now point your elfinder client to index action of *ElfinderConnectorController*

Example:
```
<script>
$().ready(function() {
var elf = $('#elfinder').elfinder({
url : '${g.createLink(controller:'elfinderConnector')}'
}).elfinder('instance');
});
</script>
<script>
$().ready(function() {
var elf = $('#elfinder').elfinder({
url : '${g.createLink(controller:'elfinderConnector')}'
}).elfinder('instance');
});
</script>
```


3 changes: 0 additions & 3 deletions application.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#Grails Metadata file
#Tue Aug 06 16:47:22 IST 2013
app.grails.version=2.2.4
app.name=elfinder-connector
17 changes: 8 additions & 9 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.work.dir = 'target'

grails.project.dependency.resolution = {
inherits("global") {
}
log "warn"
legacyResolve false

inherits 'global'
log 'warn'

repositories {
grailsCentral()
mavenCentral()
mavenLocal()
mavenCentral()
}

dependencies {
test("org.spockframework:spock-grails-support:0.7-groovy-2.0") { export = false }
compile "commons-io:commons-io:2.4"
}

plugins {
build(":tomcat:$grailsVersion", ":release:2.2.1", ":rest-client-builder:1.0.3") { export = false }
build(":release:2.2.1", ":rest-client-builder:1.0.3") { export = false }
test(":spock:latest.integration") { export = false }
}
}
27 changes: 9 additions & 18 deletions grails-app/conf/Config.groovy
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
log4j = {
appenders {
console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
}
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'

warn 'org.mortbay.log'
debug 'grails.plugin.elfinder'
appenders {
console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
}
error 'org.codehaus.groovy.grails',
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
debug 'grails.plugin.elfinder'
}

grails.plugin.elfinder.rootDir = "test/integration/resources"
grails.plugin.elfinder.rootDir = "test/integration/resources"
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@ package grails.plugin.elfinder

import grails.converters.JSON
import grails.plugin.elfinder.command.ElfinderBaseCommand
import grails.plugin.elfinder.filemanager.ElfinderLocalFileSystemFileManager

import org.apache.commons.lang.StringUtils

/**
*
* @author Sudhir Nimavat
*
*/
class ElfinderConnectorController {

def grailsApplication

def index() {
String cmd = params.cmd ?: "Unknown"
String commandName = "elfinder"+StringUtils.capitalize(cmd)+"Command"
def index(String cmd) {
cmd = cmd ?: "Unknown"
String commandName = "elfinder${StringUtils.capitalize(cmd)}Command"

log.debug("Executing command $commandName")

Expand All @@ -26,21 +21,22 @@ class ElfinderConnectorController {
if(command == null) {
log.error("Unknown command received : $commandName")
render(status:400, text:"unknown command")
} else {
command.params = params
command.request = request
command.response = response
try {
command.execute()
if(!command.responseOutputDone) {
def resp = command.responseMap as JSON
render resp
}
}catch(Exception e) {
log.error("Error encountered while executing command $commandName", e)
def resp = [error:e.message]
render resp as JSON
return
}

command.params = params
command.request = request
command.response = response
try {
command.execute()
if(!command.responseOutputDone) {
def resp = command.responseMap as JSON
render resp
}
}catch(Exception e) {
log.error("Error encountered while executing command $commandName", e)
def resp = [error:e.message]
render resp as JSON
}
}
}
5 changes: 2 additions & 3 deletions src/groovy/grails/plugin/elfinder/MimeTypeMappings.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package grails.plugin.elfinder

class MimeTypeMappings {

private static Map mappings = [
private static final Map mappings = [
// applications
'ai' : 'application/postscript',
'eps' : 'application/postscript',
Expand Down Expand Up @@ -120,8 +120,7 @@ class MimeTypeMappings {
'ogm' : 'video/ogg'
]


public static String forExtension(String extension) {
static String forExtension(String extension) {
return mappings[extension] ?: "unknown"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package grails.plugin.elfinder.command

/**
* @author Sudhir Nimavat
*
*/
class ElFinderFileCommand extends ElfinderBaseCommand {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package grails.plugin.elfinder.command

/**
*
* @author Sudhir Nimavat
*
*/
class ElFinderMkdirCommand extends ElfinderBaseCommand {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package grails.plugin.elfinder.command

/**
* @author Sudhir Nimavat
*
*/
class ElFinderMkfileCommand extends ElfinderBaseCommand {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package grails.plugin.elfinder.command

/**
* @author Sudhir Nimavat
*
*/
class ElFinderRenameCommand extends ElfinderBaseCommand {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package grails.plugin.elfinder.command

/**
*
* @author Sudhir Nimavat
*
*/
class ElFinderRmCommand extends ElfinderBaseCommand {

@Override
void execute() {
List targets = params.list('targets[]')
List targets = params.list('targets[]')

List removed = []
targets.each {
removed.addAll(elFinderFileManager.delete(unhash(it)))
}
putResponse("removed",removed )
}
putResponse("removed", removed)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ import org.springframework.web.multipart.commons.CommonsMultipartFile

/**
* @author Sudhir Nimavat
*
*/
class ElFinderUploadCommand extends ElfinderBaseCommand {

@Override
void execute() {
String target = params['target']
String target = params['target']

List<MultipartFile> files = request.getFiles('upload[]')
List added = []

files.each {CommonsMultipartFile tempFile ->
println "uploading: "+tempFile.originalFilename
log.debug "uploading: $tempFile.originalFilename"
def info = elFinderFileManager.uploadFile(tempFile, unhash(target))
if(info) {
added.add(info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import grails.plugin.elfinder.filemanager.ElFinderFileManager

import org.apache.commons.lang.Validate


abstract class ElfinderBaseCommand {

ElFinderFileManager elFinderFileManager
Expand All @@ -17,14 +16,14 @@ abstract class ElfinderBaseCommand {

boolean responseOutputDone = false

public abstract void execute()
abstract void execute()

protected void putResponse(def key, def val) {
protected void putResponse(key, val) {
Validate.notNull(key, "Key can not be null")
responseMap[key] = val
}

protected void addError(def err) {
protected void addError(err) {
responseMap.clear()
responseMap["error"] = err
}
Expand Down Expand Up @@ -54,7 +53,6 @@ abstract class ElfinderBaseCommand {
putResponse("files", files)
}


void tree(String target) {
String path = unhash(target)
List tree = []
Expand Down
Loading

0 comments on commit c9e242e

Please sign in to comment.