IT Consultant – Java, J2EE, IBM WebSphere Portal, Lotus Notes/Domino
RSS icon Home icon
  • Sun JDK5/6 compilers broken when linking overloaded methods with variable arguments

    (5 votes) 1 Star2 Stars3 Stars4 Stars5 Stars
    Loading...
    Posted on 16 May 2008 Sebastian Thomschke*/?> 1 comment

    We are currently switching the build system of OVal from custom Ant scripts to Maven 2. During that process we accidentally compiled the project using the Java compiler of the Sun JDK 5 instead of the AspectJ compiler. Surprisingly javac did not complain about the missing aspect class files. Instead it already aborted while compiling an ordinary Java class which only referenced other non-AspectJ related classes. This is the original error message:

    [INFO] [compiler:compile]
    [INFO] Compiling 180 source files to C:\projects\oval\src\trunk\target\classes
    [INFO] ------------------------------------------------------------------------
    [ERROR] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Compilation failure
    C:\projects\oval\src\trunk\src\main\java\net\sf\oval\Validator.java:[373,58] 
    addMethodParameterChecks(java.lang.reflect.Method,int,java.lang.Object)
    has private access in net.sf.oval.internal.ClassChecks 

    There exist multiple methods named addMethodParameterChecks in the class ClassChecks with different signatures. The problem is that javac tries to link against the wrong method when compiling the class calling one of the methods.

    Read the rest of this entry »

  • Making the DD Sitemap Generator Plug-in work with multilingual blogs

    (2 votes) 1 Star2 Stars3 Stars4 Stars5 Stars
    Loading...
    Posted on 1 May 2008 Sebastian Thomschke*/?> 3 comments

    To create a bilingual blog with WordPress I am using the Language Switcher Plug-in. This plug-in allows you to put content in more than one language into the post title and content fields by surrounding the localized texts with special tags indicating their language (e.g. “[ lang_en]Hello World[ /lang_en][ lang_de]Hallo Welt[ /lang_de]”). When the posts are viewed in the browser the plug-in will determine the active language and strip off the texts specified in all other languages on the fly.

    I am using the great DD Sitemap Generator Plug-in for WordPress to automatically render a site map based on the posts, pages and categories created in my blog. The problem however is that the generated site map is not language aware and displays the page/post titles and category names including the tags and the texts of all languages at once.

    To solve this I started digging a bit into the code of WordPress and the Language Switcher Plug-in. The Language Switcher Plug-in achieves the on-the-fly processing of multilingual texts by hooking itself into the so called Filters API which is something like an event-based callback mechanism. Plug-ins can signal their interest in a certain text filter event by calling the add_filter(the_event_id, the_name_of_a_function_to_callback) function provided by the WordPress API to register one if it’s functions that will be invoked by WordPress when the filter event occurs. Besides registering for filter events, plug-ins can also fire such events by calling the apply_filters(the_event_id, the_text_to_be_filtered). WordPress will then apply all registered filters to the text passed over and the apply_filters will return a “filtered” version of the passed text. When rendering the title of a post or page WordPress fires the filter event “the_title” allowing plug-ins to process/modify the title before it is actually displayed. Therefore the Language Switcher Plug-in registers itself to this event and a lot of others to be able to strip off the language tags and the texts in languages other than the currently active one.

    Unfortunately the DD Sitemap Generator Plug-in is currently not applying the respective filters when rendering the site map. Therefore the Language Switcher Plug-in is not aware of it and as a result the site map shows all translations of a category name or page/post title at the same time no matter which language is currently active.

    To solve this problem I analyzed the source code of the DD Sitemap Generator Plug-in and added the missing apply_filters calls where appropriate. You can follow these steps in case you are having the same issue:

    1. Open the file <wordpress_root>/wp-content/plugins/sitemap-generator/sitemap-generator.php (or <wordpress_root>/wp-content/plugins/dd-sitemap-gen/dd-sitemap-gen.php) in an editor
    2. Locate the text
         $tmp_array[‘title’] = $pages[$k]->post_title;
      and replace it with
         $tmp_array[‘title’] = apply_filters(‘the_title’, $pages[$k]->post_title);
    3. Locate the text
         $tmp_array[‘title’] = $cat_data[$c][‘cat_name’];
      and replace it with
         $tmp_array[‘title’] = apply_filters(‘the_category’, $cat_data[$c][‘cat_name’]);
    4. Locate the text
         $tmp_array[‘title’] = $posts[$k]->post_title;
      and replace it with
         $tmp_array[‘title’] = apply_filters(‘the_title’, $posts[$k]->post_title);
    5. Save the file and you are done.

    If you are encountering similar problems with other plug-in you can use the same approach to make them play nicely with the Language Switcher Plug-in.