FLOW3: Create a select box mapping to a list of objects in a Fluid view

FLOW3 rocks. However, the current documentation is… well… a bit short :-) The quickstart guide and the blog example show you the basics of working with FLOW3 and Fluid, its templating engine. But for explanations or examples of even the slightest more complex functionality you have to search the web for quite some time (or at least I had to ;-)).

Like today: I wanted to map an object of type Invoice to an object of type Client in a Fluid view. How do you do that, so that FLOW3 instantiates a real Client object and hands it over to the Invoice object upon its instantiation? It turns out, all you have to provide the framework to magically do that, is something like a select tag with the Client objects‘ GUIDs like this:

  1. <select name="client">
  2.   <option value="80f870ee-931c-4706-8716-fb3e52bbe450">Client 1</option>
  3.   <option value="fb2cd21e-64e8-439b-bff2-be51948b8ff5">Client 2</option>

But how do you do that using Fluid? I found the solution (mainly by chance) here: FLOW3 – your first relation between to models.

  1. <f:form.select property="client" name="client" options="{clients}" optionLabelField="name" />

If you omit the attribute optionValueField on the view helper f:form (see Fluid ViewHelper Reference), the objects‘ GUIDs are magically used for the values of the options in the HTML form and FLOW3 figures out that it has to instantiate Client objects.

Iterate over a possibly empty array in VBA (Excel)

When you try to iterate over an empty array in VBA like this, you will get a runtime error (index out of bounds):

  1. Sub ArrayTest()
  2.  
  3. Dim testarray() As Integer
  4. Dim i As Integer
  5.  
  6. For i = LBound(testarray) To UBound(testarray) ‚ <– error
  7.    Debug.Print testarray(i)
  8. Next i
  9.  
  10. End Sub

Even if you check the return value of LBounds like this, it results in the same error:

  1. Sub ArrayTest()
  2.  
  3. Dim testarray() As Integer
  4. Dim i As Integer
  5.  
  6. If LBound(testarray) > 1 Then  ‚ <– error
  7.    For i = LBound(testarray) To UBound(testarray)
  8.         Debug.Print testarray(i)
  9.     Next i
  10. End If
  11.  
  12. End Sub

However, to get rid of the error and to iterate over a possibly empty array, the following code works:

  1. Sub ArrayTest()
  2.  
  3. Dim testarray() As Integer
  4. Dim i As Integer
  5.  
  6. On Error Resume Next
  7. If LBound(testarray) > 1 Then
  8.     If Err.Number = 0 Then
  9.         For i = LBound(testarray) To UBound(testarray)
  10.             Debug.Print testarray(i)
  11.         Next i
  12.     End If
  13. End If
  14.  
  15. End Sub

Visual Basic magic 😉

SVG-Dateien in LaTeX einbinden

Wenn man mit LaTeX arbeitet, ist es sinnvoll, die verwendeten Grafiken in einem skalierbaren Dateiformat einzubinden, damit sie beim Druck genauso scharf aussehen wie der Text. Viele Vektorgrafiken (gerade auch in der Wikipedia) liegen heutzutage im SVG-Format vor.

Diese Dateien direkt in LaTeX einzubinden ist nach meinen Recherchen aktuell anscheinend noch nicht möglich. Es wird immer der Weg der Konvertierung der SVG-Datei in EPS oder PDF empfohlen. Beides ist mit der freien Software InkScape sehr einfach möglich: SVG-Datei öffnen, Speichern unter, Dateiformat auswählen, fertig.

Die PDF-Datei kann dann mittels \includegraphics{Datei.pdf} in LaTeX eingebunden werden.

Interview mit mir zum Einsatz von Wikis in Unternehmen bei NDR Info

Heute Morgen war ich in einem kurzen Interview zum Einsatz von Wikis in Unternehmen bei NDR Info im Radio zu hören. Schon Anfang Dezember war Christoph Heinzle vom NDR bei uns im Unternehmen und hat eine Kollegin und mich zu dem Thema interviewt.

Unser Wiki gibt es nun bereits seit einigen Jahren und es hat sich eine stattliche Anzahl an Artikeln angesammelt. Im Durchschnitt hat jeder EDV-Mitarbeiter über 100 Artikel verfasst, ob Dokumentationen, Arbeitsanweisungen oder Tutorials.

Hier gibt es den Online-Artikel zum Radiobeitrag: Firmen konservieren Wissen mit Wiki.

Getting PL/SQL Developer on Windows 7 64bit to connect to an Oracle database

After I installed the latest version of PL/SQL Developer on my Windows 7 64bit machine today, I got the following error message when trying to connect to an Oracle database:

Initialization error
Could not initialize "D:\oracle\product\11.2.0\client_1\bin\oci.dll"
Make sure you have the 32 bits Oracle Client installed.
PL/SQL Developer Windows 7 64bit Oci Error

As I’ve found out, the solution is to install (actually, simply extracting the archive is enough) the latest 32bit version of the Oracle Instant Client and configure PL/SQL Developer to use it instead of the 64bit Oracle client under Tools – Preferences.

PL/SQL Developer Windows 7 64bit Settings

I found this solution here: Fix Initialization Error: LoadLibrary oci.dll returned 0 while trying to connect to Oracle using PL/SQL Developer.

However, PL/SQL Developer didn’t recognize my tnsnames.ora anymore after I switched to the 32bit Instant Client. The solution is pretty simple: just create the directory network\admin in the 32bit Instant Client’s directory and copy your tnsnames.ora from the real Oracle client’s directory there.

Installation of Microsoft Baseline Security Analyzer (MBSA) fails with error code 2738

When installing Microsoft Baseline Security Analyzer (MBSA) the installation on my Windows 7 64bit machine failed with error code 2738. However, I found the solution for this problem in the Chip forum:

  • Remove the registry key HKEY_CURRENT_USER\SOFTWARE\Classes\Wow6432Node\CLSID\.
    MBSAError2738RegeditDeleteKey
  • Register vbscript.dll running regsvr32 C:\Windows\SysWOW64\vbscript.dll as Administrator.MBSAError2738RegisterDLL2
    MBSAError2738RegisterDLL

How to add a local calendar to the Android 2.2 Froyo emulator

After I had successfully added the calendar application to my Android emulator running Android 2.2 (Froyo), I soon realized that I wasn’t able to create events in it because I had no calendars. Android gave me this nice message: You have no calendars.

Android 2.2 Froyo: You have no calendars

Searching the web for this problem lead me to the need of creating a Google account that then could be synced with the emulator’s calendar. However, the sync did not work. After setting up the account under Settings - Accounts and sync - Add account - Google it didn’t show up in the sync settings and there was still no calendar created for it.

The Android documentation said that it would be possible to create a calendar in an application, so I tried that. Quite a few hours of trying and debugging later, I finally found this post on StackOverflow, that contains a list of all the needed fields and correct values for them: After adding an event to a user-created calendar in android,the event title doesn’t show up.

So here’s the final piece of code that adds a local calendar to the Android emulator:

  1. ContentValues vals = new ContentValues();
  2. vals.put("_id", 1);
  3. vals.put("_sync_account", account.name);
  4. vals.put("_sync_account_type", account.type);
  5. vals.put("name", account.name);
  6. vals.put("displayName", account.name);
  7. vals.put("color", 14417920);
  8. vals.put("access_level", 700);
  9. vals.put("selected", 1);
  10. vals.put("ownerAccount", account.name);
  11. vals.put("sync_events", 1);
  12. vals.put("timezone", "GMT");
  13. vals.put("hidden", 0);
  14. getContentResolver().insert(calUri, vals);

Where calUri is something like

content://com.android.calendar/calendars?caller_is_syncadapter=true&account_name=local&account_type=LOCAL

and account is an android.accounts.Account.

I’ve put the code into a small application that reads the available accounts and creates a local calendar via a simple click on a button.

Download

Attention: Your emulator has to run Google APIs (Google Inc.) – API Level 8 and not Android 2.2 – API Level 8.

Android Emulator running Google API 8

How to add the calendar application to the Android emulator running Android 2.2 Froyo

I was pretty confused when I found out that the Android emulator does not provide a basic calendar application. Starting with version 4.0 „Ice Cream Sandwich“ there seems to be a calendar API, but when developing an application for an older version like 2.2 „Froyo“ you not only have no common API for accessing the calendar but also haven’t even got access to a simple calendar application in the emulator. After searching the web for quite some time on how to get a calendar application running on my emulator, I know compiled one myself for Android 2.2. Here’s how to do it:

  1. First, I set up a complete build environment on a virtual machine running Ubuntu 10.4 64bit (download Ubuntu here) following this guide: Initializing a Build Environment.
  2. Be sure to download the correct sources:
    repo init -u https://android.googlesource.com/platform/manifest -b froyo
  3. When the download is ready, build the system, but only the needed components:
    . build/envsetup.sh
    lunch full-eng
    make Calendar
    make CalendarProvider
  4. You’ll find Calendar.apk and CalendarProvider.apk in /out/target/product/generic/system/app. Copy them to the machine running the Android emulator.
  5. Run the emulator and install the APKs:
    adb install Calendar.apk
    adb install CalendarProvider.apk
  6. Start the application in the emulator.
Calendar application in Android 2.2 Froyo emulator

Download the compiled APKs

Validating an XML file against a schema with Natural and Java

Although Natural provides (very basic) functionality to parse and load an XML file, I could not find a way to validate XML against a schema. So I wrote a small Java program that does the validation and can be called from Natural (on Linux) via a User Exit.

Here is the Natural code for subprogram XMLVALID. It validates an XML file against a given schema using User Exit USR1052N (call a shell command) redirecting the output to a temp file. If an error occurred it reads the temp file and returns the error message. It uses quite a few hard coded paths you may need to change on your system.

DEFINE DATA
*
PARAMETER USING XMLVALP
*
LOCAL USING XMLVALC
*
LOCAL
01 USR1052L
  02 OS-COMMAND (A253)
  02 RESPONSE   (I04)
*
01 #TEMPFILE (A) DYNAMIC
*
01 #WORK (A1000)
*
01 #DEFAULT-SCHEMA-PATH (A) DYNAMIC CONST <'/home/XML/'>
01 #INDEX (N4)
*
END-DEFINE
*
RESET XMLVALP-DEFAULT
*
EXAMINE FULL XML-SCHEMA FOR '/' GIVING POSITION IN #INDEX
IF #INDEX LE 0
  COMPRESS #DEFAULT-SCHEMA-PATH XML-SCHEMA INTO XML-SCHEMA LEAVING NO
END-IF
*
COMPRESS '/tmp/XML-Validation-' *DATN '-' *TIMN '.txt' INTO #TEMPFILE LEAVING NO
COMPRESS '/usr/bin/java -cp' #DEFAULT-SCHEMA-PATH 'XMLValidator' XML-FILE XML-SCHEMA '>' #TEMPFILE INTO OS-COMMAND
*
CALLNAT 'USR1052N' USR1052L
XMLVALP.XML-RESULT := RESPONSE
*
IF XMLVALP.XML-RESULT NE VALID-XML
  DEFINE WORK FILE 1 #TEMPFILE TYPE 'ASCII'
  READ WORK 1 #WORK
    COMPRESS XML-ERROR #WORK INTO XMLVALP.XML-ERROR
  END-WORK
  CLOSE WORK 1
END-IF
*
COMPRESS 'rm' #TEMPFILE INTO OS-COMMAND
CALLNAT 'USR1052N' USR1052L
*
END

The Java validator is pretty straightforward:

  1. package xml;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import javax.xml.XMLConstants;
  7. import javax.xml.parsers.DocumentBuilder;
  8. import javax.xml.parsers.DocumentBuilderFactory;
  9. import javax.xml.transform.dom.DOMSource;
  10. import javax.xml.validation.Schema;
  11. import javax.xml.validation.SchemaFactory;
  12. import javax.xml.validation.Validator;
  13.  
  14. import org.w3c.dom.Document;
  15. import org.xml.sax.SAXParseException;
  16.  
  17. public class XMLValidator
  18. {
  19.     private final static int INVALID_PARAMETERS = 1;
  20.     private final static int INVALID_XML = 2;
  21.     private final static int INVALID_FILE = 3;
  22.     private final static int ANY_ERROR = 4;
  23.  
  24.     public static void main(String[] args)
  25.     {
  26.         if (args.length != 2)
  27.         {
  28.             System.out.println("Usage: XMLValidator PathToXMLFile PathToSchemaFile");
  29.             System.exit(INVALID_PARAMETERS);
  30.         }
  31.  
  32.         String xmlFile = args[0];
  33.         String xsdFile = args[1];
  34.  
  35.         try
  36.         {
  37.             validateXml(xmlFile, xsdFile);
  38.         }
  39.         catch (Exception e)
  40.         {
  41.             System.out.println("Error: " + e.getMessage());
  42.             System.exit(ANY_ERROR);
  43.         }
  44.     }
  45.  
  46.     private static void validateXml(String xmlFile, String xsdFile) throws Exception
  47.     {
  48.         // create a factory that understands namespaces and validates the XML input
  49.         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  50.         factory.setNamespaceAware(true);
  51.  
  52.         try
  53.         {
  54.             // read the XML file
  55.             DocumentBuilder builder = factory.newDocumentBuilder();
  56.             Document mDoc = builder.parse(new File(xmlFile));
  57.  
  58.             // create a SchemaFactory capable of understanding schemas
  59.             SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  60.  
  61.             // load the schema
  62.             Schema schema = schemaFactory.newSchema(new File(xsdFile));
  63.  
  64.             // validate the XML file
  65.             Validator validator = schema.newValidator();
  66.             validator.validate(new DOMSource(mDoc));
  67.         }
  68.         catch (SAXParseException spe)
  69.         {
  70.             // error generated by the parser
  71.             System.out.println("Parser error: URI " + spe.getSystemId() + ", Line " + spe.getLineNumber() + ", Message: " + spe.getMessage());
  72.             System.exit(INVALID_XML);
  73.         }
  74.         catch (IOException ioe)
  75.         {
  76.             System.out.println("Error reading file ‚" + xmlFile + "‘.");
  77.             System.exit(INVALID_FILE);
  78.         }
  79.     }
  80. }

Download