Alfresco scoped webscript configuration, can it be loaded into an E4X object? - javascript

I'm looking to use a scoped configuration file in an Alfresco javascript webscript. I started with this wiki page, and it got me mostly there.
This jira page told me I needed to create a file spring-webscripts-config-custom.xml and place it in a META-INF folder i.e. in /shared/classes/META-INF/spring-webscripts-config-custom.xml. Fine. Got that working. I can load the file, and browse the configuration using the methods listed in the Jira page.
But those methods are a pain to use (childrenMap and getChild), and I'd rather use E4X to parse and query the XML configuration file. To do so, I'd need to get the configuration file as a string and pass it to
var conf = new XML( configStr );
Any ideas on how I can do this?
And a good E4X tutorial page

There's IMHO no way to achieve what you describe with a JS backed webscript. You would need to implement a Java controller to get access to the configuration file and send it back to the client.
That said, exposing their content to the outside world it's not really what the Alfresco configuration files are designed for. If you could disclose more details of you are trying to achieve it would be easier to suggest some proper ways to expose configuration data to the client.
EDIT
After the scope has been clarified, my suggestion is to provide your web script with a dedicated XML configuration file containing all the mapping between error codes and messages. As explained in the docs, let's suppose your web script is defined in myscript.get.desc.xml. Then you can create a file named myscript.get.config.xml that contains e.g.:
<messages>
<message>
<id>1</id>
<desc>A long description here</desc>
</message>
</messages>
You can then parse such configuration in the JS controller myscript.get.js:
var myconfig = new XML(config.script);

Related

ocpsoft rewrite ConfigurationProvider Registration fails

I want to use ocpsoft rewrite in order to overcome proxy issues with Richfaces. Since the JavaScript files could not be found through a proxy configuration (similar to the problem described in JSF. URL rewriting solution needed). Somehow I do not manage to register the ConfigurationProvider correctly. Here is the warning message I receive:
WARNING: No ConfigurationProviders were registered: Rewrite will not
be enabled on this application. Did you forget to create a
'/META-INF/services/org.ocpsoft.rewrite.config.ConfigurationProvider
file containing the fully qualified name of your provider
implementation?
The Project layout is as follows:
src
main
java
resources
webapp
META-INF
services
org.ocpsoft.rewrite.config.ConfigurationProvider (containing the full qualified name to the ConfigurationProvider implementation)
WEB-INF
resources
target
My project is Maven based using JSF2 with Richfaces 4.3.0.Final and opcsoft rewrite 1.1.0.Final. Any ideas?
The location of your SPI file is incorrect. It should be:
src/main/resources/META-INF/services/org.ocpsoft.rewrite.config.ConfigurationProvider

How to load file contents from another domain using just JS?

I'm thinking of doing some online file manipulation for mobile users, the idea being that the user provides a URL to the file, then the file contents are modified by the JS, and can then be downloaded. But I haven't been able to figure out how to get the file when it's on a separate domain using just JS.
Is this possible? If so any hints or examples would be appreciated.
Just wanted to add that part of what I wanted to do was make it available without my hosting it. I'm thinking of something like a a file they can host somewhere,and then all of the bandwidth is their own...and that of wherever they are getting the file from of course.
The only way to load contents of a file on another domain is from within a <script> tag. This is how JSONP works. Look into getting your target file into this format.
The other way would be to use a local proxy. Create a web service method that loads and returns the contents of the file, then call that locally using your favorite JavaScript framework.
Depending on how you think of public webservices, and within some limitations I'm still mapping, you can do this using an ajax call to YQL, like so.
(will expand the answer later).
http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20data.uri%20where%20url=%22http://t3.gstatic.com/images?q=tbn:ANd9GcSyART8OudfFJQ5oBplmhZ6HIIlougzPgwQ9qcgknK8_tivdW0EOg%22
One of the limitations of this method is file size, it currently tops out at 25k.

How to Return static HTML and/or Javascript in OpenRasta

I am using OpenRasta 2.0, and am hosting within a console application.
I would like to be able to return some static HTML pages and JavaScript files from this setup, for example:
/index.html
/jquery.js
The files are entirely static, i.e. no Handler or Resource is required.
I have added the appropriate files to the project, and initially tried the following syntax:
ResourceSpace.Has
.ResourcesOfType<object>()
.AtUri("/")
.HandledBy<HtmlHandler>()
.RenderedByAspx("~/Views/IndexView.aspx");
The .aspx file is added to the project under a folder 'Views', and is set the build action to 'Embedded Resource'. This results in a NullReferenceException at runtime when attempting to resolve the virtual path. If I set the build action of the file to 'Compile', then it will not compile, I'm guessing because the console project does not understand ASPX.
I have also tried the following shorthand syntax for this available if referencing the WebForms codec:
ResourceSpace.Has
.TheUri("/jquery.js")
.ForThePage("~/Views/jquery.js");
But this suffers from the same issues as my initial approach, although does remove the need for a dummy Handler. So as far as I can tell, the WebForms codec cannot be used within a console application because the ASPX files cannot be compiled.
I was able to return HTML using the Razor codec as this expects the view templates to be embedded. However - I was not able to return a JavaScript file with the appropriate media type using the same technique, and I had to turn my otherwise static files into .cshtml files with a #resource defined.
I can't find any examples online of returning static HTML and/or JavaScript using OpenRasta. I would expect to find a dedicated configuration API for this like the "TheUri" syntax but independent of the WebForms codec.
I could create my own 'EmbeddedFileHandler' to return the content of a static embedded file, but I feel like I'm missing something since this is such a simple use case...
Anything that depends on the asp.net pipeline being initialized (such as aspx webforms pages) cannot compile because the BuildProvider is not there to do it, mostly because webforms is too tightly coupled to the asp.net pipeline.
OR 2 was not really designed to be used as a full web stack outside of asp.net for serving static content, as usually the host environment is better suited at doing it, but that's definitly something we're going to address in 3.0.
What I'd suggest is something along the lines of registering FileInfo as a resource, create a handler that can scan the file system for the files you want, and provide your own codec that either stream the data itself or call the API for the host http listener. It should be about 20 lines of code tops and would make a great blog post. :)

Django URL Config for javascript files

Hey guys - I am having trouble setting up my Django urls file correctly for the following thing!
<script type="text/javascript" src="/javascript/HashMap.js"></script>
What happens is the file is attempted to get found : http://localhost/javascript/HashMap.js but this URL does not match any within the URL Config and therefore the GET request fails.
Can anyone lend a hand to help me find the correct line to add to allow this kind of thing to work!
Cheers
Andy
You need to serve your JavaScript as a static file.
How you do this in production depends on what Web server you're running with. Django doesn't normally serve up static files.
For example, for Apache, you'd put this in your Apache config:
Alias /javascript/ /usr/local/wsgi/static/javascript/
Then you can put your .js files in the directory referenced.
The Django docs have a entire page on just this topic (serving static files): http://docs.djangoproject.com/en/dev/howto/static-files/
Javascript is usually considered a static resource file. If that's true in your case, I would refer you to the Django documentation. If you really need to use urlconfs to point to a view that generates Javascript, then you will need to make an entry in your URLconf for it and point it to a view.
If you're trying to get only the file as static content, the problem will be surely at your MEDIA_ROOT and MEDIA_URL settings variables. Just check they're pointing to where the javascript file is and your MEDIA_URL should have a postfix to ensure that you're accessing an "special" directory where the media files are stored.
In the case you're trying to do some processing over the file, generating it at runtime, etc.
try with this regular expression:
r'^javascript/(?P<jsfile>.+\.js)$'
In your view declaration, instead of only get the request as parameter, you will have the request and a new param called jsfile, that is the filename you'requesting. So in the view, do the processing and return an HttpResponse object with the processed file contents.

How to access proprietary .js file in Spring MVC?

I am newby in Spring, but have a task, and I am learning on the fly.
I used Roo to generates for me part of the code, but now I have to make some dynamic list binding, which is done with form, popping-up in new window, and when the submit button is pushed I have to insert the new values in the parent window.
For the purpose I wrote a .js file, which hooks the values to the parent DOM tree, but the point is that I can't configure Spring to deliver the required .js file to the browser.
The browser, doesn't recognize my function. Even when I try to access the .js file via the browser, I receive error that the file couldn't not be found.
I've tried to configure the web.xml, but it didn't work...
Any ideas, how I can configure the access to a .js file in a Spring MVC application?
Thanks a lot!
P.S. Respectively, I'll need to grant access for a static .htm(l) file... I suppose the principle for configuration of the access of static html files is the same..., right?
You just need to get the path to the file right. Assuming you have a Maven-like set-up (I assume you do because you're using Roo), then your script belongs under src/main/webapp - probably in something like a scripts folder.
Let's assume that your file is at src/main/webapp/scripts/myscript.js
You can create a URL reference for your script by adding the following Spring tag:
<spring:url value="/scripts/myscript.js" var="script_url"/>
This should give you the right path to your script, regardless of the context in which you later decide to publish your webapp.
After that, it's just a matter of using that reference:
<script type="text/javascript" src="${script_url}"></script>

Categories