Closed GoogleCodeExporter closed 8 years ago
I understand the requirement but I'm not yet sure what the best solution would
be.
1. The import statement should work (Issue 62) to be able to run any Alfresco
script but this is probably not the most convenient solution for your usecase.
2. There should be a location where you can place script files that will be
included automatically. I'm think of /Company Home/Data Dictionary/Javascript
Console Imports/*.js. All files placed here will be run before the actual
script (ordered by name).
- Would that work for you, or would you prefer a filesystem folder?
- Is the Javascript Console the right place for the extension or should your
custom code be available in Javascript Actions and Webscripts as well?
- Just as a reminder: Java logic can already be made available via
configuration (BaseProcessorExtension) in the Javascript API.
Original comment by Florian....@gmail.com
on 31 Jan 2012 at 10:20
According to Alfresco wiki
(http://wiki.alfresco.com/wiki/4.0_JavaScript_API#Importing_Scripts) import
statement will not work until js console wraps code to be executed with a
function statement. Correct me if I'm wrong, but it looks possible to
«import» script with eval function, so the idea is to define an API import
function that takes a path to the script inside repository as an argument and
imports it using eval. Using this function you may implement auto import of the
scripts from repository path, I think it should work in almost all cases.
I'm going to implement shell-like commands (ls, cd, pwd, cat etc), so I think
js console is the right place for my extension. I thought about additional
root-scope object implementation, but there are two reasons why I don't want to
solve a problem this way:
— I would like to use print function and space variable available during
script execution via js console, so new root scope object will not have access
to the scope these function and variable defined in;
— these functions are interactive, so there is no need of them in another
place.
Original comment by fuf...@gmail.com
on 1 Feb 2012 at 6:01
Eval will not work since that import syntax is not valid Javascript. It is an
invention by Alfresco. They parsed the script in the RhinoScriptProcessor class
before compiling and caching the script.
The Rhino engine actually knows a load("myscript.js") command that would be
helpful but its not implemented in Alfresco AFAIK.
For the cd command you will need to alter the space variable in the browser.
Currently you can not transfer any state between script executions. At one time
I had an object called ctx that would be sent to the webscript, could be
changed, transferred back to the browser and then saved to localstorage in the
browser - but I think I removed that.
Original comment by Florian....@gmail.com
on 1 Feb 2012 at 3:57
When writing about eval i mean a construction like this:
eval('(fucntion(){'+companyhome.childByNamePath("…").content+'})()').
Yes, you're right about space variable. It'd be nice if you add a ctx object
— i think it'll help making js console even more powerful! :)
Original comment by fuf...@gmail.com
on 1 Feb 2012 at 4:38
If you build the JS Console from source you can now change the space variable
and have a folder for includes: /Data Dictionary/Scripts/Javascript Console
Includes/*
It works but it needs some polishing before I'll release a new version.
Original comment by Florian....@gmail.com
on 1 Feb 2012 at 8:41
[deleted comment]
I guess the approach outlined in #4 is fine to get to a quick solution for the
repository/js console scenario.
A long-term solution should imho be independent of the environment (repo or
surf) and implemented as a library call - i.e. "load('something.js')" or
require('something.js')" as provided by node.js or rhino.
Original comment by deas0...@googlemail.com
on 2 Feb 2012 at 9:44
#5: Florian, thank you, I'll let you know if find any problems.
#7: Totally agree. I'm not sure what the best next step is. I'm not ready to
patch Alfresco sources to provide such a functionality, but I may raise an
issue at Jira.
Original comment by fuf...@gmail.com
on 2 Feb 2012 at 11:30
Upload new version 0.4.3 which supports /Data Dictionary/Javascript Console
Includes/* and regular <import> statements.
Closing this issue.
Original comment by Florian....@gmail.com
on 7 Feb 2012 at 4:30
With version 0.4.3 I have the following error when trying to execute any code
from js console:
500 Internal Error
An error inside the HTTP server which prevented it from fulfilling the request.
01110006 Wrapped Exception (with status template): Error executing one if the
included scripts from the data dictionary.
JavaException:
org.alfresco.service.cmr.repository.DuplicateChildNodeNameException: Duplicate
child name not allowed: Javascript Console Includes
(jar:file:/home/lx/alfresco-4.0.d/tomcat/shared/lib/javascript-console-0.4.3.jar
!/alfresco/templates/webscripts/de/fme/jsconsole/execute.post.js#252)
Here is the output from js debugger:
% search.xpathSearch("/app:company_home/app:dictionary/app:jsincludes").length
0
%
search.xpathSearch("/app:company_home/app:dictionary")[0].childByNamePath("Javas
cript Console Includes")
Node Type: {http://www.alfresco.org/model/content/1.0}folder, Node Aspects:
[{http://www.alfresco.org/model/content/1.0}auditable,
{http://www.alfresco.org/model/system/1.0}referenceable,
{http://www.alfresco.org/model/system/1.0}localized]
I've attached a patch to provide a quick fix for the problem. I'm not sure what
this error is caused by.
Original comment by fuf...@gmail.com
on 11 Feb 2012 at 10:55
Attachments:
[deleted comment]
I to got a 500 error when trying to use 0.4.3 of the console, and on
investigation it turned out that however you tried to execute
search.xpathSearch I got an error from Alfresco. I'm using 4.0a and there is a
JIRA about xpath not working as a search type on the node browser, but it
suggests that this search type just shouldn't be in the DDL and nothing else.
To make 0.4.3 work under Alfresco 4.0a I had to alter the search.xpathSearch to
a search.query.
I do not know if this is a bug in Alfresco 4.0a in the search.xpathSearch java
code or if it is resolved in later versions, but from my experience xpathSearch
doesn't work in 4.0a.
A patch file and a version of execute.post.js that does work with 4.0a is
attached.
Original comment by coolhand...@googlemail.com
on 29 Feb 2012 at 5:50
Attachments:
With the changes proposed in https://issues.alfresco.com/jira/browse/ALF-13631
it should now be possible to include arbitrary scripts in any JavaScript
executed by the Repository, including input via the JavaScript console.
Unfortunately, I have not found a way to make it fully independent of the
environment, e.g. there is a slight API difference between the Repository and
Share tier due to existing extensibility features (script search path) in Surf
that I didn't want to touch.
Original comment by axel.fa...@prodyna.de
on 9 Apr 2012 at 7:29
Hi Axel, I support your proposal (let's see if we can get some votes on that
ticket ;-) .. but I believe it will not be easy to get this in the core. Since
there is no way to do the dynamic execution without modifying the
ScriptProcessor I probably won't get it into the Javascript Console without
that core change.
Original comment by Florian....@gmail.com
on 9 Apr 2012 at 9:07
Original issue reported on code.google.com by
fuf...@gmail.com
on 31 Jan 2012 at 6:23