Doxia APT support coming closer

3

Written on August 16, 2009 by Allan Lykke Christensen

This and last weekend I’ve been working on improving the Doxia APT support in NetBeans. Namely I’ve been trying to integrate the Doxia APT parser with the NetBeans Lexer classes and secondly I’ve been implementing multi view support in the editor.

Doxia APT Parser integration

Last weekend a spend several hours trying to get my head around the Doxia Apt Parser and how it could be integrated with the NetBeans Lexer classes. Unfortunately I never found a way to do the integration. The NetBeans Lexer require that you implement the org.netbeans.spi.lexer.Lexer interface including a method, nextToken(), where each token is extracted as the file is being read. The Doxia AptParser on the other hand provide a simple parse method completing the parsing in one step. The two paradigms of parsing doesn’t seem to be compatible. If anyone got an idea on how to integrate the two I’d love to hear from you.

Multi View

The purpose of the multi view is to let Apt writers switch between the source code of an APT file and its rendered representation. So far I’ve managed to set up the NetBeans plumbing for displaying the two views and their components.

APT Multi View

APT Multi View

Unfortunately I’ve run into a Classloader problem when using the Doxia Converter classes for turning APT files into XHTML files.  Outside NetBeans the converter is working perfectly, but when I use it with the multi view inside NetBeans I get the following exception:


WARNING [org.netbeans.ProxyClassLoader]: Will not load class org.codehaus.plexus.container.initialization.InitializeResourcesPhase arbitrarily from one of ModuleCL@57a41eae[dk.i2m.netbeans.langsupport.apt] and ModuleCL@4ba805a3[org.netbeans.modules.maven.embedder] starting from SystemClassLoader[511 modules]; see http://wiki.netbeans.org/DevFaqModuleCCE

SEVERE [org.openide.util.Exceptions]

java.lang.ClassNotFoundException: org.codehaus.plexus.container.initialization.InitializeResourcesPhase

WARNING [org.netbeans.ProxyClassLoader]: Will not load class org.codehaus.plexus.container.initialization.InitializeResourcesPhase arbitrarily from one of ModuleCL@57a41eae[dk.i2m.netbeans.langsupport.apt] and ModuleCL@4ba805a3[org.netbeans.modules.maven.embedder] starting from SystemClassLoader[511 modules]; see http://wiki.netbeans.org/DevFaqModuleCCE

SEVERE [org.openide.util.Exceptions]
java.lang.ClassNotFoundException: org.codehaus.plexus.container.initialization.InitializeResourcesPhase
...

I am still to look into what can be done about the classloader problem. I’ve checked the suggested link (http://wiki.netbeans.org/DevFaqModuleCCE), but it seems to only explain the problem, without providing a solution or workaround.

That’s all for now!

Doxia APT language support

6

Written on August 5, 2009 by Allan Lykke Christensen

As I use Maven for most of my projects I end up writing a fair amount of documentation using the APT format [1]. Unfortunately NetBeans doesn’t have any built-in support (syntax highlighting, parsing) for the language yet. So yesterday I decided to looking into providing file type and language support for NetBeans. I first stumbled across a lot of tutorials regarding the Generic Language Support. However, after some researched I found that it is no longer supported. Instead I found another more recent article on the NetBeans wiki about providing language support [2]. The article was quite sketchy and confused me a lot. The confusion was mainly because of too much focus on adapting a JavaCC grammar file for Java syntax highlighting. I hope for the final version of the article will have a simpler example. Nevertheless, the article got me on my way and I’ve now managed to create very basic syntax highlighting for the APT language.

APT Language Support in NetBeans

APT Language Support in NetBeans

There is still a long way to go. I need to implement the parser and improve on the JavaCC grammar. Also, I’m planning to provide a “Preview” view in the editor so that the writer can get an idea of how the rendered document will look as he or she is writing.

If anyone knows of a good book or website about JavaCC, I’d very much like to hear from you.

That’s all for now!

[1] http://maven.apache.org/doxia/format.html
[2] http://wiki.netbeans.org/How_to_create_support_for_a_new_language

Third run. Week summary

0

Written on August 2, 2009 by Allan Lykke Christensen

I’ve just had my third and last run of the week. This morning my leg pains had almost gone completely. I believe that it went as a result of a stretching exercise recommended by one of my colleagues. I’ve been doing the stretching exercise before and after each run as well as every morning and evening. Nevertheless, my body was fatigued today and my run wasn’t very impressive. I went from 37 to 38.5 mins. It was a bit demotivating, but what keeps me going is the wonderful feeling that I get when I arrive home from a run. I can feel my body thanking me for the exercise and I feel warm and fuzzy inside.

This week in summary:

  • I’ve ran 15 KM (3×5 KM)
  • I’ve cycled 7 KM (1×7 KM)

My routine for next week:

  • Cycle 42 KM (6×7 KM)
  • Run 15 KM (3×5 KM, where one of the runs is an actual practice run)

I guess now is the time for me to also get into a healthier diet. Oh dear, what will become of me…

Second run

0

Written on July 31, 2009 by Allan Lykke Christensen

Since my first run I’ve been in agony! Nah, it’s not that bad, but goodness my thighs hurt when I sit down and stand up. So today, I went for my second run. This time I timed it correct and realised that I didn’t do the run in 30 mins, but in 37 mins!! Good thing I didn’t become a mathematician, eh? My goal has now been adjusted to getting it down to 30 mins. I realise that it will take me a long time to get in proper shape, but for now I am really enjoying it. There was a slight improvement in todays run. I think it came down to my iPod playlist. Anyway, enough gibberish for today. Next run is Sunday evening. Have a good weekend.

Oh no, what have I done!?

0

Written on July 30, 2009 by Allan Lykke Christensen

A few months ago I did something brave/ambitious/stupid. I signed up for a 15KM relay run. Each team has three members each running 5KM. Now, there is 21 days till the run and it has been ages since I last did any physical exercise. How on earth am I going to manage running for 5KM straight? Anyway, I’ve always loved a challenge, so today I went to a runners shop where they analysed my running technique and found me a good pair of running shoes with the support that I need to run properly. As soon as I got home I went for a 5KM run. It was a very poor performance on my side, but not as bad as I expected. I managed to run the 5KM in 30 mins. When I say run, I mean my technique of running for 2 mins and walking for 1 min.  I was completely amazed about how good it felt with the support from the shoes. I’ve always hated running because my shines start hurting after just a few minutes. With the new shoes my legs were completely fine. It was all down to my level of fitness.  I’m completely knackered now but I feel good. Tomorrow I’m resting from running, but cycling to and from work (about 12 KM total – half of which is uphill). If I can keep this up I hope that I won’t make a complete fool of myself and be able to run the 5KM in 20 mins.

Thanks Sun! NetCAT gear arrived!

2

Written on July 11, 2009 by Allan Lykke Christensen

From March till June this year I’ve been participating in the NetCAT programme. As usual it was it a great experience lead by Jiri Kovalsky of Sun Microsystems. Every year this experience keeps getting better. The community testers are actively and passionately involved in improving the quality of NetBeans. For me it has also been a pleasure to discuss NetBeans issues with the developers who created it. I don’t think many developers get the opportunity to get so close to the technologies that they use everyday.

If you’ve been reading my blog you’ll also know that I’ve begun developing modules for NetBeans. Without the NetCAT programme I don’t think I would ever have dared getting into it. Hopefully in the future I’ll be able to join the NetFix team so that I can assist with solving bugs.

Lastly, Sun sent the top 15 NetCATs (I was number 11) a small gift of appreciation. A really cool windbreaker with the NetCAT logo. I love it!

I welcome NetCATs to connect on LinkedIn

SMTP Dummy 1.1 Released (NetBeans Plugin)

1

Written on July 10, 2009 by Allan Lykke Christensen

This evening I added a few features to the SMTP Dummy NetBeans Plugin. It is now possible to specif a folder where mails caught are stored. It is also possible to open each mail “in the system” directly from NetBeans. You can download the latest version from the Kenai project page: http://kenai.com/projects/smtp-dummy

Screenshot of SMTP Dummy 1.1

Screenshot of SMTP Dummy 1.1

Note: If you are installing the plug-in for the first time, don’t forget to also download and install the Mailster library (also located in the download section)

Comments are very welcome!

NTLM authentication for HTTP connections

3

Written on June 28, 2009 by Allan Lykke Christensen

I was recently tasked with integrating one of our products with an off-the-shelf case and document management system used by many organisations in the Danish public sector. The case and document management system allows for integration via RESTful-like HTTP calls to the core of the system. The RESTful-like interface is easy to use, but it was challenging to get through to the system in the first place. You see, it was developed on a Windows platform (dot net) and it relies solely on NTLM authentication provided by the operating system. Automating the NTLM authentication would have been easy if the code was done using a dot net technology, but since our product is Java-based it was causing a bit of a headache. I researched possible API’s (JCIFS and JESPA) for doing the authentication, but they didn’t seem to be straight forward. As I had a partial solution using the JCIFS API, I requested help on the SAMBA-JCIFS mailing list where I was informed that Java 5 and 6 had built-in support for NTLM and there was no need for an API. So, here is the code I ended up with for automating the NTLM authentication:

public static String getResponse(final ConnectionSettings settings, 
        String request) throws IOException {
 
    String url = settings.getUrl() + "/" + request;
 
    Authenticator.setDefault(new Authenticator() {
        @Override
        public PasswordAuthentication getPasswordAuthentication() {
            System.out.println(getRequestingScheme() + " authentication")
             // Remember to include the NT domain in the username
            return new PasswordAuthentication(settings.getDomain() + "\\" + 
                settings.getUsername(), settings.getPassword().toCharArray());
        }
    });
 
    URL urlRequest = new URL(url);
    HttpURLConnection conn = (HttpURLConnection) urlRequest.openConnection();
    conn.setDoOutput(true);
    conn.setDoInput(true);
    conn.setRequestMethod("GET");
 
    StringBuilder response = new StringBuilder();
    InputStream stream = conn.getInputStream();
    BufferedReader in = new BufferedReader(new InputStreamReader(stream));
    String str = "";
    while ((str = in.readLine()) != null) {
        response.append(str);
    }
    in.close();
 
    return response.toString();
}

That’s all. Thanks to the guys who helped out on the SAMBA-CIFS mailing list and StackOverflow.

References:

SMTP Dummy 1.0 for NetBeans released

4

Written on June 13, 2009 by Allan Lykke Christensen

The first release of SMTP Dummy for NetBeans has been released.

SMTP Dummy 1.0

SMTP Dummy 1.0

Installation

  1. Download SMTP Dummy 1.0
  2. Download Mailster 1.0.0-M2
  3. Launch NetBeans
  4. Click Tools -> Plugins
  5. Select the “Downloaded” tab
  6. Click “Add Plugins…”
  7. Select the two downloaded files from above
  8. Click “Install” and accept the licenses

Usage

  1. In the Services tab (CTRL-5) you’ll see a node named “SMTP Dummy Servers”
  2. Right click the node and select “New”
  3. Enter “Dummy” as the name
  4. Enter “1025″ as the port
  5. Click “Finish”
  6. Right click the added node and select “Start”. It will take a few seconds before the server is started (the icon will turn green when its ready)
  7. You can now start testing sending mail on port 1025. To see the mails caught open the “Mails Received” window from Window -> Output -> Mails Received
  8. To view the contents of a caught mail, right click the mail and select View

FileObject streams

0

Written on June 12, 2009 by Allan Lykke Christensen

As I’m still learning the NetBeans platform I was getting concerned about closing and opening streams when creating new FileObjects. I therefore posted a question on StackOverflow hoping that some NetBeans Guru would see. After posting I dug into the NetBeans API and source code and discovered how it all works. Here is the except from my self-answered question on StackOverflow:

Q: When creating modules on the NetBeans platform, the FileObject object represents a file in the virtual file system of the IDE. Creating new FileObjects is simple, but does NetBeans completely control the reference to the actual File, or should I close FileObject myself? My code is like this:

FileObject appRoot = FileUtil.getConfigRoot().getFileObject("myapp");
 
try {
    FileObject fo = servers.createData(filename);
    fo.setAttribute("name", "a name");
    fo.setAttribute("desc", "a description");
} catch (IOException ex) {
   throws new FileCreationException("Could not create file " + filename, ex);            
}

With the above code, am I leaving open some references to the actual file or should I obtains the OutputStream of the FileObject and close it manually?

Thanks.

Self-answer: After digging around in the NetBeans API and source code I believe I’ve found the answer to my own question.

Attributes as set above are stored in a special attributes file. Each folder in the virtual file system has a hidden attributes file (.nbattrs) which contains the attributes stored for each FileObject, e.g.

<!DOCTYPE attributes PUBLIC "-//NetBeans//DTD DefaultAttributes 1.0//EN"     
                            "http://www.netbeans.org/dtds/attributes-1_0.dtd">
<attributes version="1.0">
    <fileobject name="dk-i2m-netbeans-smtpdummyservice-mailserver-1244831819713">
        <attr name="name" stringvalue="My test"/>
        <attr name="desc" intvalue="Server for testing outgoing e-mails"/>
    </fileobject>
</attributes>

This file is completely controlled by NetBeans and no opening or closing of input/output streams are necessary.

If however, you want to add content to the FileObject and not mere attributes, you will have to do it the normal Java-way of using the InputStream and OutputStream of the FileObject (both have a getter and setter) and remember to close the streams accordingly. e.g.

FileObject appRoot = FileUtil.getConfigRoot().getFileObject("myapp");
 
try {
    FileObject fo = servers.createData(filename);
    fo.setAttribute("name", "a name");
    fo.setAttribute("desc", "a description");
 
    // Lock the FileObject before writing
    FileLock lock;
    try {
        lock = fo.lock();
    } catch (FileAlreadyLockedException ex) {
        Exceptions.printStackTrace(ex);
        return;
    }
 
    try {
        OutputStream out = fo.getOutputStream(lock);
        try {
            // Write into the output stream
        } finally {
            // Remember to close the stream
            out.close();
        }
    } finally {
        lock.releaseLock();
    }
} catch (IOException ex) {
    throws new FileCreationException("Could not create file " + filename, ex);            
}