Archive for the ‘Development’ Category

Render cObj RECORDS fully or slimmed

Monday, May 24th, 2010

Short share of TypoScript know-how..

TYPO3 comes with a handfull different cObjects, such as TEXT, IMAGE etc.. (see the tsref) and then there are the more general cObjects for content rendering; CONTENT and RECORDS. The CONTENTS object focuses on a more widely rendering process, where you find your data with a select property, and a renderObj output.. ..then there is the little bit simpler variant RECORDS that allows you to find and output records from one or more tables in a bit more raw way thant CONTENT allows you to.. anyway.. what I wanted to share today was this difference when outputing a RECORDS object..

Take this TypoScript:

  1. lib.addressline = RECORDS
  2. lib.addressline.source = 47
  3. lib.addressline.tables = tt_content

It outputs a tt_content record with uid 47 like this:

  1. <div id="c47"><p>My content with uid 47</p></div>

Quite often you might want it a bit more trimmed.. (especially when you map it with typoscript object path in templavoila into a predifend position in a template). Then you can do like this

  1. lib.addressline = RECORDS
  2. lib.addressline.source = 47
  3. lib.addressline.tables = tt_content
  4. lib.addressline.conf.tt_content = TEXT
  5. lib.addressline.conf.tt_content.field = bodytext

Which renders this instead:

  1. My content with uid 47

The basic thing is – define what you want in your output, and ignore the rest. The same could be done with a logotype image or similar (mapping an image content outputs a lot of extra wrappings by default..)

Another small notice; If you map a ts object from templavoila and get HTML output as text, then edit DS/TO and uncheck “as content through htmlSpecialChars (HSC)” for that field….

Generate page as PDF from TYPO3 with the webkitpdf extension

Wednesday, February 24th, 2010

I’ve been digging quite a lot into this thing about generating a TYPO3 page as a PDF file. There are a few extensions in TER that does this in various ways. The two best shots I came up with after some fiddeling was

  • PDF Generator 2 (pdf_generator2)
  • WebkitPDF (webkitpdf)

There are some others but, afaik they lack CSS support.

I started out with the first one, which was really  easy to set up and use, but when I launched it on my production server it throw memory errors, so I started to play with WebkitPDF instead. This extension is a simple but powerfull wrapping around the Wkhtmltopdf project (http://code.google.com/p/wkhtmltopdf/) which basically takes the Webkit HTML engine and generates a print out from that.

The documentation instructs you put the FE plugin on a new page, and then add a short TS into you TS Setup. I thought I’d post my TS setup here for example on how to use it slightly different (mostly since I wanted to have the current page title as filename). Note that I’m forwarding the PDF link to a ts object – lib.pdfLink. I’ve mapped that in an FCE with links in my case. Instead of adding the FE plugin on a separate page I include it on all pages (last row in TS) – since I need the ouput possibility on most pages anyway.

  1. plugin.tx_webkitpdf_pi1.scriptParams {
  2.   print-media-type =
  3.   margin-top = 0mm
  4. }
  5. //set current page title as output filename
  6. plugin.tx_webkitpdf_pi1.staticFileName = TEXT
  7. plugin.tx_webkitpdf_pi1.staticFileName.data = page : title
  8. //generate link
  9. includeLibs.webkit = EXT:webkitpdf/res/user_webkitpdf.php
  10. lib.pdf = USER
  11. lib.pdf.userFunc = user_webkitpdf->user_getPDFLink
  12. lib.pdf {
  13.   //pid =
  14.   linkText = produktblad i pdf-format
  15. }
  16. lib.pdfLink < lib.pdf
  17.  
  18. //include the renderer. we do this on the same page, since we want to fetch the correct page title as filename
  19. page.100 < plugin.tx_webkitpdf_pi1

Additional notes:

I just realized that the CSS attribute page-break-after/before is a bit kinky with the pdf converter (actually it’s the webkit engine, and Firefox has the same problem. I didn’t bother to check if IE suffers from the same, but I guess it does…).
If you want to break a page somewhere, then make sure the page break doesn’t reside in floated elements. This is a bit tricky since a modern HTML template normally consists of floated divs and by that there is no natural position for such page break. This was fairly easy to solve for me in my current case since I really didn’t need the other columns in my output. Therefore I could first set the divs like:

  1. [..general CSS layout setup..]
  2.  
  3. @media screen {
  4. .leftColumn { float: left; }
  5. .rightColumn { float: right; } /*or whatever*/
  6. .pagebreak { visibility: hidden; } /*pagebreak elements should not show up in browser*/
  7. }
  8.  
  9. @media print {
  10. .rightColum { visibility: hidden; }/*dont want it in print mode*/
  11. .pagebreak { visibility: show; page-break-after: always; }
  12. }

I made a small FCE in TYPO3 containing a div with class .pagebreak, which I could insert anywhere on a page. It’s hidden in media screen, but breaks the page when printing. Pritty nifty if you ask me :P

Finally a decent MessageBox!

Tuesday, December 8th, 2009

by Josef from Eden Foundation.

There is one frustration every Swing programmer shares: The message box system. The class JOptionPane, that comes with the Java Runtime Environment, is indeed versatile – but at the same time agonizing because of a very basic problem. Long messages don’t wrap… (click on the image to see what I mean)

a far too wide message dialog

This is the default behavior. There are various workarounds, the best that I’ve read about being to override the getMaxCharactersPerLineCount() method through a subclass. It’s a decent solution.

But once you start thinking about a bad class, you start getting wishful. And my wishlist came to include:

  • HTML-formatting for my messages (so some things can be written in bold or italic).
  • Possibility for the user to select and copy parts of the message, or it’s entirety, for sending in chats or emails when communicating with support.
  • Support for really, really long messages, the ones that are as long as License agreement! for the cases where this actually is desirable. If so, the message box should not disappear partly outside the screen. Instead, the message should be scrollable.

As I couldn’t find my dreambox anywhere on the net, I finally took the time to fix my own. I found it especially challenging because of the LayoutManagers that just didn’t seem to want to do what I want, but in the end, a tip from Stanislav Lapitsky helped me sort it out. He had a quick-and-dirty on how to figure out the height of a JEditorPane if you are locking it’s width:

http://java-sl.com/tip_text_height_measuring.html

So I’ve made a wrapper class that I call instead of JOptionPane, that wraps my message strings into a JEditorPane before displaying them. The key part of the code was to embed the text messages in a nice component.

  1.   public static void error(Component owner, String message, String title) {
  2.     JOptionPane.showMessageDialog(owner, wrap(message, "Error Encountered:"),
  3.         title == null ? "Error" : title, JOptionPane.ERROR_MESSAGE);
  4.   }
  5.  
  6.   private static JComponent wrap(String message, String shortTitle) {
  7.  
  8.     int maxWidth = 400;
  9.     int maxHeight = Toolkit.getDefaultToolkit().getScreenSize().height * 2 / 3;
  10.  
  11.     String htmlizedMessage = null;
  12.     if (message.contains("<p>") || message.contains("<P>")
  13.         || message.contains("<br>") || message.contains("<BR>")
  14.         || message.contains("<Br>"))
  15.       htmlizedMessage = message;
  16.     else
  17.       htmlizedMessage = message.replace("\n", "<BR>");
  18.  
  19.     int h = getContentHeight(htmlizedMessage, maxWidth);
  20.  
  21.     JPanel pnl = new JPanel();
  22.     pnl.setLayout(new BorderLayout());
  23.     JEditorPane text = new JEditorPane("text/html", htmlizedMessage);
  24.     text.setBorder(null);
  25.     text.setBackground(null);
  26.     text.setEditable(false);
  27.  
  28.     int titleHeight = 0;
  29.     if (shortTitle != null) {
  30.       JLabel lblTitle = new JLabel(shortTitle);
  31.       lblTitle.setFont(lblTitle.getFont().deriveFont(
  32.           lblTitle.getFont().getSize() * 1.5f));
  33.       lblTitle.setBorder(new EmptyBorder(0, 0, 10, 0));
  34.       lblTitle.setMaximumSize(lblTitle.getPreferredSize());
  35.       titleHeight = lblTitle.getPreferredSize().height;
  36.       pnl.add(lblTitle, BorderLayout.PAGE_START);
  37.     }
  38.     JScrollPane scroll = new JScrollPane(text);
  39.     scroll.setBorder(null);
  40.     scroll.setMaximumSize(new Dimension(maxWidth, maxHeight));
  41.     scroll.setPreferredSize(new Dimension(Math.min(maxWidth, text
  42.         .getPreferredSize().width), Math.min(maxHeight, getContentHeight(
  43.         htmlizedMessage, maxWidth))));
  44.  
  45.     pnl.add(scroll, BorderLayout.CENTER);
  46.     return pnl;
  47.   }

The result looks like this:

…like this…

…or this…

…or if the message is really, really long and almost qualifies to be an End User License Agreement (as if any end users ever have the time and legal knowledge to understand those), like this:

You can find the full source here:

http://www.edenfoundation.org/products/code/MsgDlg.java

svn over ssh with another port than 22

Wednesday, December 2nd, 2009

A client of mine has their own SVN repository and they where running ssh over another port than the normal 22. Doing this can be a bit tricky since svn doesn’t really like the common host:port style when using svn+ssh protocoll (or whatever you call that combo).

I’m using NetBeans (6.7.1) in Ubuntu, so was eager to get svn working directly from there. Since svn itself doesn’t like special ports, neither did NB. But after a simple search on “netbeans svn ssh port number” I surfed into (not stumbled – you know – I surf the web..) a subject in the subversion mailing list which reviled a simple solution. With ssh you can add some kind of alias for hosts for which you also can define a port etc, then it’s as simple as one two three to use custom ports with svn+ssh. I’m taking the liberty to sum the mail archive post here:

create (if not already there) a file in you home folder ~/.ssh/config

Adopt the following to your needs and add them to that file


host mysvnhost
Hostname svn.onthehost.tld
Port 80
ForwardAgent no
ForwardX11 no

Then just use svn+ssh://mysvnhost/path/to/repo with svn.

nominate FLOW3 and TYPO3 for SF community awards

Tuesday, May 19th, 2009

Show your support for TYPO3 and the upcoming framework FLOW3 and nominate them for a soure forge community award.

Hit this image to nominate FLOW3 for “Best New Project” and “Most Likely to Change the Way You Do Everything”

..or, hit this button to nominate TYPO3 for “Best Project” and “Best Project for the Enterprise”

There aint much more to say about that ;)

Stels-MDB, a pure-java ms-access engine

Friday, March 6th, 2009

by Josef from Eden Foundation.

Having an old MS Access database full of important data can be a real nuisance for cross-platform strategies. Lately, I’ve been evaluating what approach to use for making a Java desktop app run on Linux. The tricky thing is that the database it interfaces with is in the Microsoft Access format, developed at the time when that product was new and cutting edge (yes, that was in version 1.1). Now Access’ engine library ADO won’t run natively on Linux, so this far, my program has been limited to Windows by making use of the jdbc:odbc-bridge. Today, with Linux desktops quickly gaining importance, this needs to change. Migrating the database to another system like MySQL is a bit of a job, so I searched for less draconian alternatives. I found a promising library, Stels-MDB, that claims to handle Access’ MDB files through native Java code. I downloaded the trial version and gave it a run. Here is a summary of my experiences:

Switching the database driver from jdbc:odbc to Stels-MDB was very easy. It was just to adjust the two connection strings for the driver name and parameters, and voilà. I could run my app. But Stels does not behave identically to Microsoft’s ODBC driver, so there were some issues to look at.

Case sensitivity

Stels-MDB was case sensitive. This meant that a search criteria of “DALLI” used in a query would not detect records containing the value “Dalli”… A major issue in my eyes. Fortunately, support at J-Stels Software seems to be very good. Within a day or two, they had recompiled a new version of the driver with an option that removes case-sensitivity. I think SQL searches should be case-insensitive by default, but anyway, their solution was satisfactory as it only required me to make a trivial modification to the JDBC connection string. Great guys!

Different SQL syntax

Stels-MDB does not use the same SQL syntax as MS Access. Access, in fact, deviates from the Ansi SQL92 standard, and that’s a pity, because Access’ unique traits (such as using brackets for quoting fields) adds nothing of value compared to the standard syntax. So Stels could choose two smart ways here, either run the ugly MS syntax for compatibility with legacy Access-based apps, or they could follow the ANSI standard so that the Stels engine can be seamlessly plugged in and out of vendor-independent database apps that don’t care which underlying database you are using, only that you have a valid JDBC driver. Unfortunately, Stels have opted for a syntax that has some quirks of its own, probably to simplify coding and to keep the style with their other query engines (for CSV files and more). The most basic things work well; quoting fields can be done both through double quotes and backticks. But other ordinary stuff has to be done through special functions. A date value for instance, has to be wrapped into the function “to_date()” to be recognised. So as a developer, you easily risk embedding “Stels-only” sql into your program code. Or, you’ll have to create your statements through an sql-generating library[link], where you add a subclass to cover Stel’s peculiarities, which is what I did.

Syntax of AnsiSQLFormatter:
SELECT "Order ID", "Product ID", "Order Date" FROM "Orders" WHERE "Order Date"='25-Nov-2008 21:24:15'
Syntax of MsaccessSQLFormatter:
SELECT [Order ID], [Product ID], [Order Date] FROM [Orders] WHERE [Order Date]=#25-Nov-2008 21:24:15#
Syntax of StelsSQLFormatter:
SELECT `Order ID`, `Product ID`, `Order Date` FROM `Orders` WHERE `Order Date`=to_date('2008-11-25 21:24:15','yyyy-MM-dd HH:mm:ss')

Limited SQL features

Another problem I ran into with my queries, was that they were too complex for the subset of features currently supported by Stels. Subqueries, in particular, were not popular, they provided me with messages like this:

java.sql.SQLException: [StelsMDB JDBC driver] Can't parse SQL query: [SQL Engine API] Incorrect syntax near the word 'FROM' (position: 39). See realized SQL specification in the driver documentation. SQL query was: 'SELECT MAX(`Time`) AS `MaxTime` FROM (`Microplots` INNER JOIN `MicroplotInfo` ON `Microplots`.`Plot`=`MicroplotInfo`.`Plot` AND `Microplots`.`Bar`=`MicroplotInfo`.`Bar`) WHERE `Microplots`.`Year`=2008'

I also missed some common functions like Day(), Month() and Year(). But I could probably easily have added these to Stels myself, because it provides an extension mechanism for custom-made functions.

Jackcess under the hood

Although Stels-MDB is closed-source, it is based on the open-source library Jackcess. From what I understand, it basically wraps Jackcess’ non sql-based api into a query engine so you can use it in more normal ways, and, well, run queries on your data. Unfortunately, just as Stels’ query engine is not fully mature, Jackcess’ table handling doesn’t seem to be yet either. My tables were certainly of the more demanding type – developed over the years through basically every past version of Access, with lots of indexes and foreign keys (referential integrity in MS Access terms). They’re actually a headache in relationships. :-) Knowing that the mdb format is cryptic and undocumented (I haven’t seen MS make any effort to help the developer community access this format, despite the product’s name…), I was not surprised that Jackcess had some hiccups. I couldn’t figure out what the root causes were, or didn’t spend enough time searching. Some problems were solved by compacting my database and removing obsolete indexes, whilst others wouldn’t go away. Here’s one error that stuck:

[StelsMDB JDBC driver] Error executing sql: [StelsMDB JDBC driver] Can't write 'Seeds' on the disk. Error was: Can't insert a record in the table 'Seeds' [Jackcess] FIXME cannot write indexes of this type yet.

I couldn’t reproduce this problem in a simpler, test database that I built from scratch, but then again, I did not invest the necessary time to make a full inquiry into the matter. But it’s clear from the FIXME that some features have not been implemented in Jackcess yet.

Performance

A little use of a stopwatch when running my code through Stels gave me a rough comparison of its speed to that of the ADO engine running through the jdbc:odbc layer. Stels is slow. The operations I timed took 6 – 10 times longer with Stels than with Access’ engine. This would have been ok if I was plundering mdb files for data in a series of one-time jobs. But it was too slow for running an ambitious desktop app with high demands on its database back-end.

Conclusion

All in all, Stels-MDB is a brave effort that really had my hopes up. But it isn’t mature enough for more high-end needs. I am very glad to see that there are people trying to provide solutions to us Java programmers sitting around with important mdb-files and wanting to take full advantage of the potentials of platform independence. I hope that both J-Stel Software and the Jackcess project make steady progress until that dream comes true. Figuring out the mdb format without official documentation from its software house is a formidable challenge… I also hope that Stels-MDB moves towards standard ANSI sql syntax, and still wonder why MS Access did not do so more than a decade ago. For now, we’ll have to look for something else here at Eden Foundation. Perhaps outright migration to MySQL? We’ll see…

Having a midnight laughter – rebranded TYPO3 newsthread

Tuesday, February 24th, 2009

Stuck in work process I launched Thunderbird to skim through the TYPO3 newslists. Apparently I haven’t checked that one for some time since Thunderbird suggested me to get the latest 500 posts :) Anyway. There was a really funny, or should I say sad, posting about a Russian rebrand/fork of TYPO3. First he uses a pseudonym posting news about a fork, then he denies ‘borrowing’ TYPO3 code and icons, finaly changing into admiting having to change a few lines of code and some icons.. doh.. – check out the site and judge for yourself.

It’s really sad that people just can’t see the fundamental philosophy of TYPO3 and the intentions of it’s original inventor Kasper Skårhöj, releasing his work as GPL:d open source software – Inspire people to share!

I few days earlier I stumbled upon a swedish fork/overlay work of TYPO3 called TYPO3 magenta. I got the similar feelings over this one as with that Russian guys fork. Though this is a bit more balancing on the edge. The TYPO3 name is still there but with a suffix. It’s open stated to be built on TYPO3. From the website (freely translated from Swedish using google..):

“TYPO3 Magenta is a web-based system to manage, organize and publish content on websites. TYPO3 Magenta is a further development of the publishing tool TYPO3. TYPO3 is based on open source which means significantly lower costs compared with commercial counterparts. TYPO3 Magenta has developed with the user in focus. The primary user group is Swedish small-and medium-sized enterprises.”

It’s sold in a license form with system, hosting and support.

But as I said, I find this solution better – while not good. I’m guessing it’s mostly about a nifty back end skinn. Refactoring TYPO3 this way is like saying “TYPO3 is good but old school. We make it modern and better with our own version”. And the main issue is still – what would a company loose going 100% TYPO3 and sharing improvements rather then trying to be so special?

I will be honest. We started our business with two CMS solutions. CMS made simple and TYPO3. One simple CMS for the simple sites and one advanced for the larger ones. We promoted them as simple and advanced cms. However during time I realized that both we and the solutions themselves would benefit much more exposing TYPO3 as it is, with it’s huge community and existing brand name rather then trying to make it seem more like our own, and so far it’s just been true. I think that the more credibility and reward the community gets for it’s efforts the better TYPO3 will be.

After all, the community is a vital part of TYPO3 together with it’s open source base. Alongside with that TYPO3 is also a very strong brand and should be promoted and empowered so.

Inspire people to share! – it will get us so much further

Typoscript code completion in TYPO3 version 4.3a1

Tuesday, February 10th, 2009

Finally I took a quick test of TYPO3 version 4.3 alpha 1. Read the link for a detailed release info. However I’d like to highlight one update a bit extra for you. The TypoScript editing extension that made life prittier highlightning and helping out with the indentation for the TS code when editing has now got itself a usefull and very nicely implemented code completion function. Look at the image below.

It’s perfect for people like me that just cant get all those object and attribute names to stick in memory.

Code completion in TYPO3 v 4.3

Now, I’m having a hard time waiting for next alpha or maybe beta so I can test the new front end editing fuzz which at least seems awsome!. Check it out at Jeff Segars blogg.

TYPO3 commerce extension finally shows prices for me

Tuesday, December 30th, 2008

I’ve actually had trouble with this for quite some time. I’m using the commerce extension for TYPO3 for a site. The plan is to turn the site into an e-com site eventually, but starting of with plain product listings so I thought I’d give the commerce extension a shot. It’s quite comprehensive. Amongst a lot of things it has a good internal structure to allow all kinds of variants of an article – especially suitable for things like textiles where you have a combination of color and sizes making an article.

One big downside I feel currently is the template setup. It’s heavily templated, but still not really as flexible as I’d like. Could be a competence/knowledge issue – but nah! I’m smart! really..

However I’ve had some real troubles showing the prices. Really. Seems so basic, but I just couldn’t get into it. Today I logged into the #typo3 channel @ freenode irc. Thanks to friendly help from PiMB there I got it working. It all had to do with setting the currency. I ended up with this in my TS:

  1. plugin.tx_commerce_pi1.currency = SEK
  2. plugin.tx_commerce_pi2.currency = SEK
  3. plugin.tx_commerce_pi3.currency = SEK
  4. plugin.tx_commerce_pi5.currency = SEK

The default for ..pi1.currency was – “currency” – and not a real currency – like SEK or EUR. That’s all. the other FE commerce plugings actually has EUR as default.

Anyway. by this post I’d like to state that the open source community is (at least around TYPO3) very friendly and helpsome. – and – thanks PiMP for the hint ;)

The site – still in a bit of progress (have some wierd positioning in the templates) – can be found here (swedish) http://www.byylva.se/. High quality carpets and other textiles :)

cheers. And a happy new Year!

Adobe CS4 is down for counting

Wednesday, December 10th, 2008

As soon as Adobe CS4 was released we got our hands on it. Since I’ve been doing quite a lot Flash things lately I was hoping the new version would reveal some greate new features. However after trying it for couple of weeks now, I can only summarize the experience as; grumpy. To begin with Flash crashes for me when opening most of my old cs3 files, doesn’t recognize an old flash project file (.flp), crashes totaly if I’m to fast clicking around (hey.. it’s fun to click around with the mouse). The last behaviour is the same for the other nifty tools such as Illustrator and Fireworks.

They die right in front of me leaving me with a broken (long-time-since-last-save) file. Some say it’s about fonts, some say it’s about somethingelse. I saw someone who solved it by buying a new computer..

I contacted Adobe in for the subject, posted an error report and gave them full dumps of my machines current state.. getting the reply to go through a bunch of help yourself links with twenty steps each! Things like that make me grumby.

Anyway.. I’ve tried reinstalling the entire CS4 premium package (uninstall and install taking for ages) without success.. and yeah. one last thing.. Acrobat reader now crashes if I try to open a pdf link within the (a/any) browser. Thanks..

regards,
A grumpy web developer