Render cObj RECORDS fully or slimmed

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….

A new era – I’m converting to the Mac’s

May 10th, 2010

I recently decided to be dary – I ordered a MacBook Pro – the 15″ i7, 2.66ghz, with the highres (1680) screen. I got it last week, and so far all I can say is actually – WOW :) It does feel like ‘*Nix made right’. Of cource, there are some bridges to cross, but I didn’t expect anything else anyway.

I thought it’d be cool to post my experiences so far, and the stuff I’ve so far has bloated the computer with, so here we go ;)

  • The little characters commonly used by developers – the (in swedish at least) so called seagul wings – { and }. They can be found with the combination shift+alt+8or9. I would prefer one less key in the combo – but I’m getting used to it..
  • The brackets [ and ] are under 8 and 9 as well, but solely with alt+number.. Still teaching my fingers that..
  • The dollar sign.. On my swedish keyboard there is a € char above number 4. Found out that the $ char is there as well, but with alt+4.
  • Change primary screen when using an external screen? first it seemed a bit problematic when I found solutions like, “close the computer, and press space bar on the keyboard which activates the computer a gain”. It’s far esier. Open dislpay settings and drag the toolbar to the screen that should be primary. Done..
  • Clearing the DNS settings is done with (terminal) dscacheutil -flushcache

Some settings I’ve quicly changed…

  • I quickly changed so that the F[1..12] keyboard buttons are F[1..12] buttons and not function keys. Now the function button is used to reach the function buttons behaviour instead. Better…
  • Changed so that double clicking on window list minimizes the window.
  • Changed size on dock (The menu list on a mac) and set it to auto hide (which also means that maximizing a window really uses the entire space and not just down to the top of the dock).
  • The setup on the Dock – a lot of rearly used apps there, removed them (they are still in the Applications folder), and added the terminal (I use it a lot!) and some other more commonly used apps (like all browsers etc)

AAANND the apps :P

  • Adium for chatting – It’s a superb IM client for most protocols
  • Growl – a really cool notification app that integrates with most apps
  • FileZilla client (FTP) – I’ve used under both Linux and Windows. By far the best FTP client. Easy to transfer from the PC by exporting/import the settings as XML.
  • Skype
  • NetBeans – my current IDE of choice
  • Subversion – command line version so far.. Still missing a good client (would prefer an OSE one, otherwise the Versions app seems good)
  • Microsofts RDP client
  • MySQL server (also remember to copy/create a config file under /etc for admin apps to work..)
  • MySQL Workbench
  • Firefox with some of the common add ons for a web developer ;)
  • Chrome
  • TextMate (heard it should be the developers best friend on a mac) – trying it out still.
  • Smultron (a dev editor as well. testing that too)
  • Tomboy. One of my favourite apps from the Linux world. A note taking app based on the wiki concept. really smooth.
  • The Adobe CS5 Web package.. (I actually hoped that I could convert my CS4 license to a Mac one, but apperantly that’s not possibly now since they released the version 5.. buhu.. :(
  • I’m about to install the VirtualBox, but I’ve not come that far yet..

I think that’s it for now.. btw:

  • four fingers sliding down – show all open windows..
  • three fingers sliding left/right. Browser back/fwd (and such)
  • two fingers sliding down/up. scroll
  • two fingers clicking – right click

- I like it.

The only downside so far is my configuration mess up with my external keyboard. less than/greater then (<>) becomes §° instead (the key is actually lost in the mapping for some reason). Havn’t found a solution to that yet.

Cheers.

:)

Generate page as PDF from TYPO3 with the webkitpdf extension

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!

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

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.

Those where the days

October 8th, 2009

Long time since last post, and by then it’s this really on topic link: http://sarien.net/ :)

Just had to post it. Brings those old memories back to life. Those where the days, right?

Thanks Martin Kool for bringing it all back :P

nominate FLOW3 and TYPO3 for SF community awards

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

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

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

Extending my network to XING

February 23rd, 2009

I’ve been looking at the XING networking platform from time to time, but never put myself into adding an account. However, now I’m there -> https://www.xing.com/profile/David_Smeringe <- and the first impression is quite positive. It feels very business focused as well as having great tools to maintain your network. Sadly there’s not that many swedes afaik. Maybe I just wasn’t looking under the right stone.. :)

So, if your’e a XING user and think you apply to my network pattern (web development, business partners, TYPO3 people, and some more..), please include me in yours!

See my LinkedIn profile as well..