I quickly launched my VMWare Fusion into Vista, gulp, and proceeded to run Microsoft's Visual Studio 2008. This posting won't be a tutorial on how to write C#, but i'll just go over some of the basics of setting up a simple C#-based COM object that can be used from within Jaxer.
The first thing to note is that to register COM objects in Vista, you need to be Administrator, so just launch Visual Studio as Administrator using the right-click menu 'Run as Administrator'. Once you have Visual Studio running, start by creating a new 'Class Library' project.
Once you've created the project, right-click on the project and go to the Properties menu, we'll want to make this object a COM-visible one.
In the 'Build' section of the properties, scroll to the bottom and check the 'Register for COM Interop' checkbox. This will make your object visible to other languages as a COM object.
The next thing you'll need to do is open your 'AssemblyInfo.cs' file, which is usually in your Properties folder of your project. Be sure to change the 'false' value to 'true' for the 'ComVisible' setting:
Now that you've done that, you can just create a COM object the 'usual' way. The complete project is attached, so you can take a look there. The image processing code was borrowed from the following online tutorial: http://blog.paranoidferret.com/index.php/2007/06/13/csharp-tutorial-image-editing-rotate/
Once you've got your object compiled, using it from within Jaxer is super-easy! You can just use the COMObject function to create a wrapped instance of the native object and then just use functions and properties on it just as if it were native JavaScript.
So here is the very short HTML file and JavaScript code running server-side via Jaxer that creates the COM object, loads our image, rotates it via the input field in the HTML form, and then saves it back as a new image. The communications from JS to .NET happens very quickly and as you can see, was super-simple to set up.
Here's a screenshot of the image being rotated:
What's really cool is that you can write anything you like in C#/VB.NET and easily access it via JavaScript in Jaxer. Note how in my sample, the onclick event for the button calls the server-side JavaScript function directly, which in turn calls the .NET COM object. That is, you can bind browser-side buttons directly to back-end .NET COM objects, all in JavaScript through Jaxer!
| Attachment | Size |
|---|---|
| MyCOMObject.zip | 15.16 KB |
There are some interesting threads going on in the Aptana Forums about using Aptana Studio with Adobe Flex and Flex Builder. The idea of using Ajax and Flex or Flash together is not new. Google Finance did a great job a few years ago blending the two to provide a very nice user experience with Flash-based interactive charts within an otherwise Ajax UI.
It seems that the Aptana community is uncovering increasing efficiencies in using Aptana Studio and Adobe's Flex Builder together. We've also known that many Adobe AIR users are building their Ajax apps for AIR using Aptana Studio, and have heard from others that using Aptana Jaxer to create JSON data services (written natively in JavaScript) consumable by Flash and Flex apps makes a lot of sense as well. Flash and Flex each have an "Ajax bridge" to expose JavaScript APIs for the embedded objects.
Anyways... It seems Adobe is now actively taking a deeper look at this trend in the hybridization of Ajax and Flash and Flex. I saw that they are offering $75 bucks for an hour phone call to discuss your experience with and thoughts on using these together.
Here's the link if you're interested: http://www.adobe.com/go/RIAintegration_study/. $75 bucks... That's almost the cost of a tank of gas in San Francisco.
We're continuing that philosophy now with our Aptana Cloud offering (currently in beta) as well as our support for Ruby on Rails, PHP and LAMP development, and of course app development with Ajax libraries on the client side and for those that want server-side Ajax, Aptana Jaxer, a first-of its kind open source Ajax server built around the Mozilla browser engine.
"We can see that Jaxer lets developers leverage the hard work which has already been spent building client-side libraries on the server-side. These simple examples show off some of the true potential of utilizing the Ext JS framework on the server-side" says Rich.
The easy to follow example shows off a very simple wrapper around an Ext.data.Store and the corresponding Jaxer server code that returns JSON to a Ext JS datagrid.
A comprehensive guide to using RadRails to develop your Ruby on Rails projects in a professional and productive manner
Aptana RadRails is an Integrated Development Environment for Ruby on Rails projects. Built on top of the well-known Eclipse platform, RadRails provides all the tools you need to create a whole Rails application from a single interface, allowing you to focus on the creative part of the development as your IDE takes care of the mechanics.
This book will show you how to use the tools RadRails provides to improve your productivity:
This book is for Ruby on Rails developers who want to make the most of the framework by using an Integrated Development Environment.
Even though the book explains everything you need to follow the contents, the focus is on how to use the tool and not on the Rails framework itself, so previous working knowledge of Rails is highly advisable. Previous knowledge of Eclipse is not necessary.
--------------------------------------------------------------------------------
Javier Ramírez has been developing Web Applications since before the term Web Application was coined. Born in Zaragoza, Spain, in 1974, he started programming as a hobby around the age of 11 assisted by his older sister. A few years later, he got his first modem and became a regular of BBSes and Newsgroups. His interest in developing server applications that can be accessed remotely comes from those times.
He has learned —and forgotten— many programming languages, including Basic, dBase III, Cobol, Pascal, SQL, C, C++, ASP, TCL, JavaScript, PHP, and Java, the language on which he has focused for most of his career so far. He has held the positions of programmer, analyst, consultant, team leader, post-sales engineer, project manager, and software architect, totaling over 12 years in the IT business.
Having developed projects mainly for banks and other big corporations in Spain, Italy and the US, he co-founded some years ago a small software development shop, which provided him with valuable experience about the difficulties and the joys of entrepreneurship. After two years, he left the company in pursuit of new professional challenges.
For the last two years, he has been proudly working for ASPgems, where he discovered Ruby on Rails, which soon became his framework of choice for developing Web Applications. He is one of the organizers of the Spanish Rails Conference, also participating as a Speaker in the two events held so far.
He has also been an instructor on Robotics, Java, FatWire Content Server, and Ruby on Rails, and a University Lecturer in the subjects of 'Software Engineering' and 'The Java Programming Language', which he currently teaches at Universidad Francisco de Vitoria, in Madrid.
Javier Ramírez holds a B.Sc. in Business Information Systems with First Class Honors and a degree in Ingeniería en Sistemas de Computación.
------------------------------------------------------------------------------------------------
In June, Aptana and ColdFusion enthusiast, Mark Drew will be at CFUnited presenting:
Fresh AIR: Getting to grips with Aptana and AIR appsMark, who has been central to the CFEclipse project, is sure to deliver a great session, so be sure to check it out.
This session will give a nice and fresh introduction to developing AIR applications using Aptana. By using a ColdFusion developer's existing knowledge of HTML and JavaScript (and some quick introductions to JavaScript libraries such as EXT and JQuery), the whole process of developing rich desktop apps will be demystified.
Aptana will build off of its IDE and AJAX success with its new technology. Read the full story.
Learn more about Aptana Cloud, an "Elastic Application Cloud" that's ideal for Web developers who use scripting languages.
Join the early access program.
Following are the convenience functions that help make the magic happen. The first function is addElementToPage(). It very simply just creates an H2 tag and sets the title and a DIV tag which contains the contents of the fetched element:
This next function, getDocumentFromURL(), is the one that does most of the work. (I found some good info on the subject of HTML to DOM here: http://jszen.blogspot.com/2007/02/how-to-parse-html-strings-into-dom.html) It first goes and retrieves the remote page. Then it creates a 'document fragment' from the contents of the fetched site. That fragment is then added to a dynamically created IFRAME. Finally, the Document object from the IFRAME is fetched and returned. In short, we can pass in a URL, get the string value, place it into an IFRAME, then pull out the resulting Document object so that we can work on it.
This final function was found at http://www.dustindiaz.com/getelementsbyclass/ and walks a node looking for an element with a specific class name. It was used in the case where elements don't have ID's, so a class name is used instead.
What's exciting about this sample is that it is relatively simple, uses the full power of server-side JavaScript and more importantly, Jaxer's cool server-side DOM capability to enable real 'DOM scraping'. Once window object creation is finished in Jaxer (real soon now), then you'll be able to fetch remote pages, execute their integrated code, then proceed to fetch out items from the resulting DOM.
In this example, (the first in a series) we're going to build a simple voting tool, using a single page of DHTML. The implementation is quite basic but covers a good few examples of how to use Aptana Jaxer in real world situations, such as :
This example was written as a single page webapp. You could remove the Javascript to another file and make it all unobtrusive if that is what gets you excited, but I'm just using an inline script tag, as the code is only about 30 or so lines long. Also in Jaxer we could have easily implemented this using Jaxer's seamless ajax callback mechanism but for the purpose of this example we'll stick with a traditional form post.
Let's get started. Most folks reading this should be familiar with the standard blog/portal poll, where you are presented with a set of choices.
and once you have voted you get to see the current results of the voting.
In our example we allow multiple votes per user but you can easily change that by just commenting out a single line of code.
One of the interesting features of this application is that, by using server-side DOM manipulation in Jaxer, you can remove any unwanted content before it is sent to the client browser. We use this to hide the vote results until the user has voted
This is a useful technique for permission based forms where, for example, you may want remove the credit card details unless the user has established the correct permissions and been validated by the server.
So let's jump in and have a look at the code used to make this work. The code in this article has been updated to use the API of Jaxer 0.9.8 or later, for The full source listing below contains comments to indicate where the code was changed to work with the later API.
Above is the contents of the HEAD element. Just the usual suspects, setting the title and some simple CSS stuff. The only interesting part is at line #3, where we load the jQuery library on the server, because we intend to do some serverside DOM manipulation before the page is sent to the client.
The runat='server' attribute tells Jaxer to load this javascript library on the server.
The autoload attribute is a recent addition to Jaxer, and it instructs Jaxer to load that page and keep it cached as preparsed bytecode (for faster library loadtime) for any future calls to this page, including callbacks.
In the body of the document we have a simple form which we will dynamically populate on the server. The form will post the vote to itself on the server.
We are marking up the DOM content with the classnames 'voter' and 'nonvoter' to identify content that is specific to a user's status, and make it easily accessible using jQuery on the server.
The first dozen or so lines are simply creating a DB and preparing a schema for use.
So we've connected to the database (which was automatically created if needed, how convenient!) and set up the schema and initial content we expect. We also setup an Array (questions) containing the questions for the voting poll
Next we need to check the session value we are storing (status) to determine whether this user has already voted, and then check to see if the form data for the vote is being posted. Then, if we are actually voting, we write the vote to the database and set the user status to 'voter'.
When we write the vote to the database, we grab the sessionID and the remote IP address and write those out with the vote data, this will let us enforce single voting later if we need it.
Finally query the database to get the current vote counts, remembering to subtract 1 from the total to account for the dummy rows we inserted to seed database and prevent any nulls from appearing in the results totals.
Now we build the DOM, to do this we issue a query to the DB to get the current vote tally.
Using E4X - ECMAScript For XML as a simple templating tool we create the DOM with the nodes populated according to our dataset.
One of the nice features of server-side javascript with Jaxer is that you have access to all neat things built into Mozilla without the worry of client side browser support, which enables reliable use of the advanced features of the Javascript language.
If you look closely at the code below you'll notice we use a simple syntax for variable substitution using curly braces containing javascript code inside the E4X assigments. This allows us to use this for templating as long as we are creating valid XML nodes.
So the document now has a DOM that has been populated with the content for BOTH voters and non-voters. We use a little jQuery magic to remove the elements we don't want presented to the user.
In this way the user will EITHER see the form with the question and the submit button
OR the current voting results data.
Now we set the session variable status to be the current status of the user as they have either voted or not.
Finally as the page that is served has no further dependency on Jaxer once it leaves the server, we tell Jaxer to not bother injecting the client framework. Normally the client framework would be automatically inserted as a script tag in the outgoing HTML, but our simple example doesn't need to communicate back to the Jaxer server, as it contains no server callbacks.
So there you have it, a simple poll on a single page, using many of Jaxer's cool features.
The full code and supporting files for this article are available here
| Attachment | Size |
|---|---|
| choices.png | 7.09 KB |
| voted.png | 7.61 KB |
| votepoll.zip | 36.12 KB |
Aptana Jaxer has been updated to 0.9.5 providing increased performance for server-side JavaScript and a host of other enhancements to make End-to-End Ajax development easier.
Aptana Studio users can get the latest via Help > Software Updates. Otherwise, download the latest now.
One of the common web tasks that always seems to involve a lot of arcane knowledge of backend systems, is how to upload files. Like most systems, Aptana Jaxer uses the post/receive model, where a web form is posted to the server, and the target of that form will receive and process the content. Where Jaxer makes this really easy is that it is all done with regular JavaScript and HTML. No special enviroment vars, excessive string processing, or finding handles to oddly named temp files is required.
All you need is a form to present to the user, which contains an input element of type upload, and an HTML page to receive the submitted form containing a "runat=server" script block that retrieves the data from the request. You could have the form and the recipient be the same page, however in this example I'll use two files for clarity. As an aside in Jaxer you can actually send the form directly to a JavaScript function living on the server but we'll look at that configuration in a future blog entry.
This example upload form simply allows you to select up to 2 files for upload from the local filesystem. Pressing 'upload' posts the contents of that form to an HTML page containing the JavaScript shown later.
The form will look like the following when viewed in a browser. Pressing the browse button will present you with a file selection dialog, or you can type the path into the input box directly. I've used 2 file slots in this example to demostrate that the files passed in are available as part of an files array contained in the request object (a JavaScript representation of the HTTP request) and are accessed like any other JavaScript array.
'upload' sends the selected file(s) to the server.
To receive the data from the form when submitted we put some Jaxer code into the page the form will be submitted to. The code below should be in script block with a runat = 'server' attribute, which makes the code run serverside and doesn't present it to the client so you don't expose any serverside filenames or folder structures.
The data posted by the form is available within the Jaxer.request object.
For the purposes of this example we are specifically interested in the Jaxer.request.files array which contains an array of Jaxer.Request.FileInfo objects, one for each file posted with the form.
The Jaxer.Request.FileInfo object contains some useful properties describing the file, such as fileName, contentType, etc.Uploading two files from my filesystem from the form in this example would return a page of output like below. We have uploaded the file to same location as the submission.html file used as the form action in the originating HTML.
Saved to : C:\aptana\JaxerDev\public\work\bar.txt original filename : bar.txt temp filename : C:\aptana\JaxerDev\tmp\tmp contentType : text/plain size : 15754 Saved to : C:\aptana\JaxerDev\public\work\foo.txt original filename : foo.txt temp filename : C:\aptana\JaxerDev\tmp\tmp-1 contentType : text/plain size : 816
Well that's really all there is to it. It's simple and easy and you never have to think about anything other than HTML and Javascript.
API docs for the FileInfo object and the Jaxer.Request object are available online.
AjaxWorld, March 18-20, New York, NY
Kevin Hakman presents Aptana Studio: Your Unfair Advantage for AJAX, iPhone, Adobe AIR, PHP and Rails
Development and
Rapid Development of
Enterprise Ajax Apps both on Wednesday, March 19.
iPhone Developer Summit, March 18-20, New York, NY
Also on Wednesday March 19, Kevin Hakman presents Developing AJAX Applications for iPhone and iPod Touch.
EclipseCon, March 17-19, Santa Clara, CA
Eclipse Monkey committer and Aptana engineer Ingo Muschenetz shares
Building Eclipse-based Products: A View From the Trenches
on March 18, and Aptana engineer Kevin Sawicki delivers
Pimp My Editor with insights for extending and customizing features in Eclipse.
I'm happy to announce that RadRails 1.0 has been released today. This release has been a long time coming and includes a lot of new features and polish. We're especially proud of the progress we've made here at Aptana since we took over the project. RadRails 0.7.2 users will definitely want to check out this new release - it offers a more stable environment, full Rails 2.0 support, support for JRuby, and a boatload of new features. For those who want the comprehensive list of changes since the 0.9.3 release, you can find the changelist in ASAP.
The highlights include:
These new features join an already impressive set of functionality:
Please note that unless you've been using 1.0.0 nightlies Aptana/Eclipse will not automatically update you to 1.0. You'll need to force an install of RadRails 1.0 via the Start Page, Plugins Manager, or Software update mechanism that you used to initially install RadRails. For those who prefer to use the Software Update route, the update site URL for RadRails is: http://update.aptana.com/update/rails/3.2/
This week, the Aptana development team continued working on the 1.1.5 release for Aptana Studio and the 0.95 release for the Jaxer server.
New Release
We're planning to release "nightly" versions of Aptana Studio 1.1.5 and Jaxer 0.95 next week. These releases will contain numerous bug fixes. The Aptana Studio release should contain updates for many of the bundled Ajax Library frameworks, including support for EXT 2.0.2., Yahoo UI 2.5, Adobe Spry 1.6, and more.
Tips and Tricks
Do you have a question about an Aptana Studio Pro license? Or do you need some basic troubleshooting help? Visit our recently re-organized Aptana Studio FAQ and see if your question has already been answered there.
If you still need help, you can always file a support request in our ASAP system, of course.
Community Buzz
We'd like to thank our community for their help with submitting bugs and feature requests in ASAP. If you've submitted a bug or a feature request and are curious if we've implemented the fix or feature yet, visit your ASAP ticket and look for the Fix Version field. This field lists the current target release date for the fix or feature.
Yesterday Adobe announced the availability of Adobe AIR 1.0. At the same time, Aptana released the Adobe AIR plugin for Aptana Studio which simplifies development of Ajax applications that run "on AIR". (Adobe AIR Plugin for Aptana Studio)
If you are not familiar with Adobe AIR, it enables you to use the skills and Web technologies you already know, HTML, CSS, and JavaScript, to write applications that can be deployed to the Windows and Mac desktop, and shortly on Linux desktops too.
And what is Aptana Jaxer, you ask? Jaxer is an Ajax server that enables you to leverage those same Web skills and technologies, HTML, CSS, and JavaScript, to write server-side code and do a whole new range of things with JavaScript like interact with databases, file systems, and remote data sources, do server-side DOM manipulations, cross-domain data calls, make socket connections, and call server-side JavaScript functions from the client-side, plus lots more. Yes, you write both client and server code using HTML and Ajax. You can even write entire web applications in a single HTML file if you wish.
With that said, it becomes much clearer as to what ‘Jaxer on AIR’ is all about -- two systems that enable you to leverage your Ajax skills for building desktop and server apps, unified into a single, very interesting model. With Jaxer you can implement your server-side to know if an app is running in AIR and thus take advantage of offline synchronization and local access to the client system as permitted, or if you’re running on the Web with a subset of the total potential features of your Ajax apps and Web pages.
I did a 10-minute screencast showing a simple example of this. I take one of Jack Slocum’s great Ext / Adobe AIR demos (EXT Tasks Demo) and Jaxer-enabled it. I added a single JavaScript function that can query my backend database, and I use the results to fill the user interface.
This demo just scratches the surface of what is possible, but I hope it opens the doors to your thinking about how to utilize these great technologies – it’s my version of their chocolate and our peanut-butter happily together, enjoy!
We are excited to announce that Kevin Hakman has joined Aptana to head up marketing and developer community programs. Kevin is a recognized leader in the Ajax community. Long before the term "Ajax" was coined, Kevin was pioneering single page web application concepts via the company he co-founded, General Interface Corp., one of the first enterprise Ajax libraries and visual development tools companies. General Interface Corp. went on to be acquired by TIBCO Software in 2004 as a compliment the company's service-oriented architecture (SOA) products. Today TIBCO General Interface is used by many Fortune-scale companies for rapid Web application development and deployment atop their XML and SOAP data sources.
In addition to his historic role on the steering committee of the OpenAjax Alliance, Kevin currently chairs the organization's integrated development environment working group. The OpenAjax Alliance IDE Working Group which includes Adobe, Aptana, the Eclipse Foundation, IBM, Microsoft, Sun, TIBCO and others is now close to delivering a draft specification for a uniform way to describe Ajax libraries and controls and thus streamline the ability to use Ajax libraries within your development tools of choice. Kevin is a frequent speaker at Ajax industry events and is an author to many published articles on Ajax in the enterprise.
This past week we released another point release of Jaxer, version 0.9.3, updating the standalone server as well as the one packaged within Aptana Studio. Of course there were bug fixes, performance improvements, and API enhancements. Perhaps most important, this was our first release to officially support Linux. Supporting Linux isn't trivial because of the multitude of variants, but it is very strategic as the deployment platform of choice for many people. Look for more distros being supported and more forms of distribution, from buildable source drops to tarballs and installable packages and even to complete EC2 and VMWare images. And thanks to the community for already helping us with supporting Linux distros.
So where are these releases leading — what are some things on the immediate roadmap for Jaxer?
Oh, and the time frame? We're not exactly the patient type, so for many of these think weeks rather than months. Want something specific to come out even faster? Join the discussions on the forums, join the effort (some folks are supporting Linux distros, others are building persistence frameworks, some are putting together samples), or join our team.
This past week, the Aptana development team released a patch release that provides support for the Jaxer server on Linux. Read on to learn more details about this release.
New Release
Earlier this week, Aptana released new "nightly" builds of both Aptana Studio (v.1.1.3) and the Jaxer server (0.93). Aptana Studio 1.1.3 contains several bug fixes. Jaxer 0.93 contains several major new additions including support for Linux and integration with Amazon's EC2 technology. You can read more about these developments on our blog:
Community Buzz
Frequent visitors to the Aptana web site may have noticed some changes recently. We've been in the process of re-organizing some of our documentation in order to make things easier for the community to find. One recent major addition that we've made is the Book of Jaxer, which is now the main landing page for all of our Jaxer documentation. Additionally, we've compiled a new FAQ page for Aptana Studio, which should answer most of your questions about Aptana Studio licenses and otherwise help you get started with Studio.
If you're having trouble finding a certain piece of information or notice that we're missing a Help topic on something, please file a new request in ASAP, and we'll try to get the information added to the site as quickly as we can.
Tips and Tricks
Are you new to Jaxer development, but aren't quite sure how to get started? Our new Jaxer Quick Start Guide is a fast and easy way to walk through the entire process. This guide covers all of the basic information that you'll need to get started with Jaxer, including installation, creating your first Jaxer project, and resources for learning more.
Are you looking for a quick and easy way to deploy your Jaxer applications? You can now take advantage of the cloud technology provided by Amazon's Elastic Compute Cloud (also known as EC2). EC2 provides you with a fast way to get going with Jaxer and to deploy it on a hosted infrastructure. With your own EC2 instance, you can make your Jaxer applications available for both private and public consumption.
The Jaxer Team has set up a CentOS image with Jaxer pre-configured and ready to go. Find out how to get your own instance running (and more) on the Running an EC2 Instance of the Jaxer Server page.
We'd love to hear about what you're building with Jaxer, so if you're working on a Jaxer app or just have a few questions about Jaxer, we'd like to invite you to participate in our Jaxer community forums.
The Jaxer Team is proud to announce that we now support Jaxer for several Linux platforms:
To learn how to get up and running on Linux, see the Jaxer Standalone Installation guide for Linux.
We've been working with volunteer beta testers within the Jaxer community to bring you these distros, and we plan to support additional distros in the future. However, this is our initial release for Linux support and because the various Linux platforms have so many nuances, some Linux platforms could likely still have some issues. Our Linux support is very community driven, so we invite you to participate in the platform vote on the forums to voice your opinion about your preferred platform:
http://forums.aptana.com/viewtopic.php?t=4844
If you have Jaxer up and running on a platform that we have not listed, let us know so we can add it to the list of supported platforms. Additionally, if you need help troubleshooting issues with Jaxer on your Linux platform, post your questions on the Jaxer forums.
This tutorial is a sample of some functionality you can quickly achieve in Jaxer. In this case we'll be building a very basic file-based "blog".
The idea is simple: Create an HTML page that will show all the "posts". A post is created by creating or FTPing a txt file to the server and naming it so it will appear in the order desired. We'll also add the ability to use Markdown syntax in the txt file so you can easily do some basic HTML without the HTML syntax.
You can easily extend this to add a page where posts can be written and previewed, re-ordered/renamed, move to using a DB instead of txt files, etc.
We'll want a folder named "articles" as a sub-folder of our project. Next we'll create a simple index HTML page as a peer of that folder, with a div inside the body containing the id "posts".
<html>
<head>
<title>My Blog</title>
</head>
<body>
<h1>My Blog</h1>
<div id="posts"></div>
</body>
</html>
To get started writing server side Javascript we 'll add a script tag in the head with a runat attribute set to server:
<script runat="server">
</script>
Jaxer has a nice API that allows you to work with the filesystem directly on the server. We're going to take advantage of that to have it grab files inside the "articles" folder that is a peer of our html file on the server:
function init() {
var path = Jaxer.Dir.resolve("articles");
var dir = new Jaxer.Dir(path);
var files = dir.readDir().map(function(file) {
return file.leaf;
});
}
Now we have a function which grabs the "articles" directory and then gets a listing of all the filenames inside that directory. Next we want to loop over the files, read in their contents and append it to a string that we'll be pushing back into the div with id "posts".
var html = "";
for (var i = 0; i < files.length; i++) {
var read = Jaxer.File.read("articles/" + files[i]);
html+= read;
}
document.getElementById('posts').innerHTML = html;
Pretty simple. We read all the files, concat their contents together into a string and then push that into the posts div. We can try it out by having this function run when the server has loaded the page/DOM. We just modify the body tag like so:
<body onserverload="init();">
This tells Jaxer to run our init function when it has completed creation of the page's load process.
Obviously, concatenating all the files contents together doesn't look too nice. Lets wrap each file's contents in a div with class "post" so we can style it later.
var read = Jaxer.File.read("articles/" + files[i]);
html+= makePost(read);
function makePost(contents) {
return "<div class=\"post\">" + contents + "</div>\n";
}
That's much better. Now we don't have all the files in one giant string.
But this hasn't bought us much - we still have to write the HTML tags inside the txt files if we want to do any styling or marking up of the content. Let's provide a markup syntax to allow users to use simple text conventions to generate HTML. One such library is Markdown. We're going to use a nice Markdown in JS library provided from: http://softwaremaniacs.org/playground/showdown-highlight/
It's pretty simple to use. First we include the library on the server side:
<script src="showdown.js" runat="server"/>
Next, we use it to mark up the file's contents before we wrap it in the div:
...
var read = Jaxer.File.read("articles/" + files[i]);
html+= makePost(markdown(read));
...
function markdown(content) {
var converter = new Showdown.converter();
return converter.makeHtml(contents);
}
And there you have it. We now have a blog index page which will grab all of our article text files, run them through markdown and insert them into post divs for us.
To wrap up here's the full code:
<html>
<head>
<title>Articles</title>
</head>
<script src="/showdown.js" runat="server">
</script>
<script runat="server">
var converter = new Showdown.converter();
function createPost(contents){
// Run markdown filter on contents
var text = converter.makeHtml(contents);
return "<div class=\"post\">" + text + "</div>";
}
function init() {
try {
// read all the articles in text files in "articles" sub-dir of this dir (#.txt)
var articlesPath = Jaxer.Dir.resolve("articles");
var files = new Jaxer.Dir(articlesPath).readDir();
var string = "";
var i = 0;
for (i = 0; i < files.length; i++) {
var filename = Jaxer.Dir.combine(articlesPath, files[i].leaf);
if (new Jaxer.FileUtils().ext(filename) == "txt") {
var raw = Jaxer.File.read(filename);
string += createPost(raw);
}
}
document.getElementById('output').innerHTML = string;
}
catch (err) {
document.getElementById('output').innerHTML = err.description;
}
}
</script>
<body onserverload="init()">
<div id="output"></div>
</body>
</html>
A how to guide on integrating Jaxer with Apache Tomcat has been released.
This guide walks you through how to enable Jaxer to post-process your HTML and JSP pages for your Tomcat web applications. The tutorial includes two WAR files, one that adds support for Jaxer callbacks on your Tomcat pages and the other includes samples on possible ways to integrate Jaxer with your JSP/HTML pages.
Jaxer also has a connector available for the Jetty HTTP server which is used inside Aptana Studio.
Please use this forum thread to discuss the Jaxer-Tomcat connect
Jaxer lets you use your full stack of Ajax technologies — HTML, JavaScript, DOM manipulation, XHR, etc. — on the server, to make web application development a lot smoother and more natural.
But Jaxer is also based on the Mozilla engine, in fact on the same core that will power Firefox 3, just without the rendering. And this simple fact unlocks a lot of power that's been built up over many years by Mozilla developers. Unless your apps and sites have targeted Firefox exclusively — unlikely, given its market share — they could not rely on JavaScript features beyond version 1.4. And how about the numerous extensions that have been developed for Firefox, some of which actually ship with the browser? Most developers don't even know about them, and they couldn't rely on them being available to most of their target audience.
But now all that Firefox 3 goodness is under the hood of your Jaxer, on the server side, under your full control. So if JavaScript 1.7 and 1.8 generators, iterators, and array comprehensions float your boat, then happy sailing. Soon native JSON parsing and encoding will be available, along with other features on the march towards JavaScript 2. Perhaps more significantly, you have a rich SOA stack: SOAP, WSDL, and other four-letter friends from the enterprise architect's bestiary. Microformats, anyone? Simply use the script loader to import the built-in Microformats.js and you have access to hCard, hCalendar, and other functionalities. XSLT transformations are at your fingertips by just "new"ing up an XSLTProcessor object. There are all sorts of hidden gems to discover: did you know there's a very nice RDF subsystem in there? How about base64 encoding and decoding? Try typing for (var p in Components.classes) { print(p); } in the Jaxer Shell to see that we've just scratched the surface of what's available.
Of course, if you don't see something you need, you can always just build it: think server-side GreaseMonkey scripts on steroids. I can't wait to see what people will come up with, now that all these capabilities are free from their browser dependence. There's already been a number of cool examples on various blogs, and we'll start to roll out more on a regular basis. More importantly, we'll make it easy to share your own samples and snippets with the community. Stay tuned...
New Release
The upcoming Aptana Studio 1.1 release will be a patch release that fixes several bugs in 1.1, including the following issues:
Tips and Tricks
We're aware that some users have been having difficulty installing the recent updates to Aptana Studio. The team is working on isolating the causes of this issue and hope to improve the situation soon. In the meantime, if you have been unable to download/install the updates, try performing a manual installation as directed on the update site:
http://update.aptana.com/update/3.2/
Community Buzz
We see a lot of bug reporting and feature requests on the forums; however, the best way to get support or to request a new feature is to fill out a ticket in ASAP
http://support.aptana.com/issues/
By filing a ticket in ASAP, you enable us to track the status of a ticket more easily, and you can also easily search for related bugs and feature requests.
Next Week
Next week, we'll get started with work on the 1.2 release. Current plans for the 1.2 release include a number of updates to the Ajax libraries bundled with Aptana Studio (EXT, Yahoo UI, etc.) and a migration to the Eclipse 3.3 platform as the base platform for Aptana.We are pleased to announce that our Adobe AIR plugin for Aptana Studio now supports beta 3 of the Adobe AIR SDK.
This release requires Aptana Studio 1.1 or later which can be downloaded here.
What's new in this release:
Wow, it’s been a long road getting to this release date, but I am very excited and proud of our team, and I'm happy to say that today we released our beta 1 of Jaxer -- what we believe to be the first true Ajax Server product.
So what is an “Ajax Server”? Simply put, we unify the development model for Ajax developers. That is, write “Ajax” code client AND server. The same APIs, the same JavaScript, the same HTML and best of all, manipulate the DOM on the server.
What does all that mean? It means that you can do a getElementById() and set its innerHTML on the server side just as easily as you can on the browser. You can write a single JavaScript function and share it between browser and server. You can write server functions which can be transparently called from the browser -- synchronous or asynchronously.
If you’re a beginning Ajax developer and any of that sounds complicated, it’s not. It simply means you can now build an entire Web 2.0 application, client and server, using only the Ajax technologies you love.
I asked several of the leaders in the Ajax space to join with us and with you, the Ajax community, in defining where we go from here. I’m very honored to say that we’ve got an all-star group assembled as our Aptana Advisory Board, just take a look at this who’s who list.
We’ve placed a few screencasts online so you can take a quick look at what Jaxer is all about and how you can start playing with it right away.
Send us your feedback, your suggestions, and tell us what you are building. After all, building a free, open-source product ultimately means we’re building this for you!
Regards,
Paul Colton
Earlier this week, the Aptana team rolled out a beta version of the upcoming Aptana Studio 1.1 release to our Pro users. This release contains many new features and implements some of the most popular feature requests we’ve gotten in recent months. Read on to learn more about the upcoming 1.1 release.
New Release
The release of Aptana Studio 1.1 is now available all users. This release contains many new features, including some of the most-often requested features by our users. Some of the highlights of 1.1 include the following enhancements:
Tips and Tricks
Do you have a suggestion for a new feature for Aptana Studio? Submit your feature request to the ASAP database. This will allow other users to “vote” on your feature request and help us plan future releases.
Community Buzz
We are aware that some users are encountering problems as they try to update Aptana Studio. We are working on this issue and hope to have it fixed soon. In the meantime, the more information that we can gather from our user community, the easier it will be to pinpoint the issue. If you do encounter an error while trying to update Aptana Studio, please file a bug report in the ASAP database, or add your comments to an existing issue.