Blog do projektu Open Source JavaHotel

poniedziałek, 29 września 2014

Byliśmy na koncercie

Piękny Brzeg Sztuki to nowa inicjatywa władz dzielnicy składająca się z wydarzeń kulturalnych z różnych dziedzin sztuki. 17 września poszliśmy do kościoła p.w. św. Stanisław Kostki na koncert muzyki kameralnej. Podobało nam się bardzo, jednak wielka szkoda, że z repertuaru wypadła główna atrakcja, czyli "Fratres" Arvo Pärta. W ten sposób koncert, który w zamierzeniu mógłby być prezentacją XX wiecznych kompozytorów z rejony Europy Środkowo-Wschodniej (Bacewicz, Szostakowicz, Arvo Pärt) stał się po prostu wykonaniem dwóch utworów.
Piękny Brzeg Sztuki to bardzo dobra inicjatywa, miejmy nadzieję, że będzie kontynuowana i rozwijana w kolejnych latach, zaś koncerty muzyczne będą w niej zajmować poczesne miejsce.

wtorek, 23 września 2014

New version of JavaHotel, mailing

Introduction
I deployed new version of JavaHotel application. Google App Engine demo is available here (U/P user/user), source code can be downloaded here. New feature is mailing.
Booking
Sending a confirmation mail is a part of the booking process. After successful booking confirmation note can be sent immediately.

If answer is yes then a window with note content pops up.

The note content is generated automatically through XSLT transformation. XSL source file is available here. By extending XSL source file it is possible to modify the confirmation note content: add some graphics, information about cancelation policy, payment method etc. Note content can be also modified manually before sending.
Confirmation email can be sent also later or resent again in case of reservation changing.


Mailing PDF receipt
Automatic mailing is enabled for PDF receipt. Hotel guest can ask for a second copy of the receipt after leaving the hotel or wants to make some changes in the receipt content (for instance address data).
The receipt PDF is attached to the note. The content of receipt note is also generated using XSLT and can be modified as desired.

Email collecting
All notes sent from the application are stored internally in the database (independently from 'Send' folder in the mail box).
The user can review all notes related to the particular reservation.


Also all notes sent to the customer/guest can be reviewed.


Next step

Advance payment.

środa, 3 września 2014

XSLT 1.0, java function

Introduction
XSLT is a powerful tool and I'm planning to use it for creating some standard forms and emails in JavaHotel application. For instance: to send booking confirmation to the customer. To keep all stuff simple I'd like to send a text (not html) email. But even in the text email it were nice to have some simple formatting:
Night       Adults Daily Rate
2014/03/01       2       77  EUR
2014/03/02       2       77  EUR
2014/03/03       2       77  EUR
--------------------------------
                 Total:  231 EUR 

But unfortunately XSLT does not contain anything like 'padding-left' or 'padding-right' function.
Xalan XSLT processor available in JSE Sun Java is 1.0 (I'd like to avoid additional dependencies) so one cannot use XSLT 2.0 features like XPath 2.0 function library or xsl:function (a huge library is available here).
So the only solution is to create a custom padding functions.
XSLT java function enhancement
It is not easy being on short notice to grasp how to create custom Java function for XSLT. What's more - there are differences between Apache Xalan and Saxon. But after picking the essentials everything runs smoothly.
There are two simple ways to declare Java enhancement in XSLT document (very useful link).
The first requires full qualified (with package) Java class name.
<xsl:template name="currentTime" xmlns:java="http://xml.apache.org/xslt/java">
  <xsl:value-of select="java:java.util.Date.new()">
</xsl:value-of></xsl:template>
The second method: the prefix is bound to a specific class and function name can be qualified by namespace only.
<xsl:template name="currentTime" 
              xmlns:date="java://java.util.Date">
  <xsl:value-of select="date:new()"/>
</xsl:template>
Solution 
After passing this Rubicon I created a simple application to have output like that:
-----------------------------------------------------------------
         Description     Unit Price            Qty         Amount
-----------------------------------------------------------------
AMD Athlon                   580.00              6        3480.00
PDC-E5300                    645.00              4        2580.00
LG 18.5" WLCD                230.00             10        2300.00
HP LaserJet 5200            1100.00              1        1100.00
-----------------------------------------------------------------
                                             Total        9460.00
Full source code is available here (Java Main, xslt template, test input file and Java custom library).
Java function code is extremely simple and straightforward. 
public class MyFun {

    public static String upperCase(String s) {
        return s.toUpperCase();
    }

    public static String fillString(int length, String s) {
        StringBuffer b = new StringBuffer();
        for (int i = 0; i < length; i++)
            b.append(s.charAt(0));
        return b.toString();
    }

    public static String paddingLeft(int padd, String s) {
        if (s.length() >= padd)
            return s;
        return fillString(padd - s.length(), " ") + s;
    }

    public static String paddingRight(int padd, String s) {
        if (s.length() >= padd)
            return s;
        return s + fillString(padd - s.length(), " ");
    }

}