<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>This site works best in a real browser - Code Snippets</title>
    <link>http://grahamcox.co.uk/serendipity/</link>
    <description>My little place on the web...</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.5.3 - http://www.s9y.org/</generator>
    <pubDate>Tue, 17 Aug 2010 10:10:26 GMT</pubDate>

    <image>
        <url>http://grahamcox.co.uk/serendipity/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: This site works best in a real browser - Code Snippets - My little place on the web...</title>
        <link>http://grahamcox.co.uk/serendipity/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Calling Maven2 from Ant</title>
    <link>http://grahamcox.co.uk/serendipity/index.php?/archives/39-Calling-Maven2-from-Ant.html</link>
            <category>Code Snippets</category>
    
    <comments>http://grahamcox.co.uk/serendipity/index.php?/archives/39-Calling-Maven2-from-Ant.html#comments</comments>
    <wfw:comment>http://grahamcox.co.uk/serendipity/wfwcomment.php?cid=39</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://grahamcox.co.uk/serendipity/rss.php?version=2.0&amp;type=comments&amp;cid=39</wfw:commentRss>
    

    <author>nospam@example.com (Graham Cox)</author>
    <content:encoded>
    There is a lot of information available on how to call Ant from Maven2 scripts, but very little on the reverse operation. As it happens, this is actually quite simple to manage - Maven2 is a Java app, so it can be executed by simply using the Java task from inside your Ant script with the correct classpath, Main class name and arguments. The following snippit will do this for the simple case:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#60;target&amp;#160;name=&quot;execute_maven&quot;&amp;#62;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#60;java&amp;#160;classname=&quot;org.codehaus.classworlds.Launcher&quot;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;fork=&quot;yes&quot;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;failonerror=&quot;true&quot;&amp;#62;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#60;arg&amp;#160;value=&quot;${maven.target}&quot;&amp;#160;/&amp;#62;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#60;sysproperty&amp;#160;key=&quot;classworlds.conf&quot;&amp;#160;value=&quot;${maven.home}/bin/m2.conf&quot;&amp;#160;/&amp;#62;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#60;sysproperty&amp;#160;key=&quot;maven.home&quot;&amp;#160;value=&quot;${maven.home}&quot;&amp;#160;/&amp;#62;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#60;classpath&amp;#62;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#60;pathelement&amp;#160;location=&quot;${maven.home}/boot/classworlds-1.1.jar&quot;&amp;#160;/&amp;#62;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#60;/classpath&amp;#62;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#60;/java&amp;#62;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#60;/target&amp;#62;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Note that this depends on the property &quot;maven.home&quot; being set correctly, and when called it will require the &quot;maven.target&quot; parameter to be supplied. &quot;maven.home&quot; will likely be set in build.properties or similar, and calling it is as simple as&lt;br /&gt;
&lt;div class=&quot;bb-code-title&quot;&gt;CODE:&lt;/div&gt;&lt;div class=&quot;bb-code&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#60;antcall&amp;#160;target=&quot;execute_maven&quot;&amp;#62;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#60;param&amp;#160;name=&quot;maven.target&quot;&amp;#160;value=&quot;install&quot;&amp;#160;/&amp;#62;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#60;/antcall&amp;#62;&lt;/div&gt; 
    </content:encoded>

    <pubDate>Tue, 17 Aug 2010 11:10:26 +0100</pubDate>
    <guid isPermaLink="false">http://grahamcox.co.uk/serendipity/index.php?/archives/39-guid.html</guid>
    
</item>
<item>
    <title>CMake code to support asciidoc</title>
    <link>http://grahamcox.co.uk/serendipity/index.php?/archives/36-CMake-code-to-support-asciidoc.html</link>
            <category>CMake</category>
    
    <comments>http://grahamcox.co.uk/serendipity/index.php?/archives/36-CMake-code-to-support-asciidoc.html#comments</comments>
    <wfw:comment>http://grahamcox.co.uk/serendipity/wfwcomment.php?cid=36</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://grahamcox.co.uk/serendipity/rss.php?version=2.0&amp;type=comments&amp;cid=36</wfw:commentRss>
    

    <author>nospam@example.com (Graham Cox)</author>
    <content:encoded>
    Asciidoc is a really useful and sensible way of allowing people to write documentation, in that the plain text source code is nearly as readable as the generated output. The following is a CMake file to allow for conversion of text input files into asciidoc generated output files&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
PROJECT(Document)&lt;br /&gt;
FIND_PACKAGE(Asciidoc)&lt;br /&gt;
IF(ASCIIDOC_FOUND)&lt;br /&gt;
  FILE(GLOB _docfiles *.txt)&lt;br /&gt;
&lt;br /&gt;
  FOREACH(_file ${_docfiles})&lt;br /&gt;
    GET_FILENAME_COMPONENT(_file_we ${_file} NAME_WE)&lt;br /&gt;
    SET(_in &quot;${_file_we}&quot;)&lt;br /&gt;
    SET(_out &quot;${_file_we}.html&quot;)&lt;br /&gt;
    IF (NOT &quot;${_in}&quot; STREQUAL &quot;CMakeLists&quot;)&lt;br /&gt;
        ADD_CUSTOM_COMMAND(&lt;br /&gt;
            OUTPUT    &quot;${_out}&quot;&lt;br /&gt;
            COMMAND   ${ASCIIDOC_EXECUTABLE} -a toc -o ${_out} ${_file}&lt;br /&gt;
            DEPENDS   ${_file}&lt;br /&gt;
            COMMENT   &quot;Asciidoc ${_in}&quot;&lt;br /&gt;
        )&lt;br /&gt;
        ADD_CUSTOM_TARGET(${_in} ALL echo&lt;br /&gt;
          DEPENDS   &quot;${_out}&quot;&lt;br /&gt;
        )&lt;br /&gt;
    ENDIF (NOT &quot;${_in}&quot; STREQUAL &quot;CMakeLists&quot;)&lt;br /&gt;
&lt;br /&gt;
  ENDFOREACH(_file)&lt;br /&gt;
ENDIF(ASCIIDOC_FOUND)&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
And it needs the following FindAsciidoc.cmake file available&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
# - Find Asciidoc&lt;br /&gt;
# this module looks for asciidoc&lt;br /&gt;
#&lt;br /&gt;
#  ASCIIDOC_EXECUTABLE - the full path to asciidoc&lt;br /&gt;
#  ASCIIDOC_FOUND      - If false, don&#039;t attempt to use asciidoc.&lt;br /&gt;
&lt;br /&gt;
FIND_PROGRAM(ASCIIDOC_EXECUTABLE&lt;br /&gt;
  asciidoc&lt;br /&gt;
  )&lt;br /&gt;
&lt;br /&gt;
MARK_AS_ADVANCED(&lt;br /&gt;
  ASCIIDOC_EXECUTABLE&lt;br /&gt;
  )&lt;br /&gt;
&lt;br /&gt;
IF (NOT ASCIIDOC_EXECUTABLE)&lt;br /&gt;
  SET(ASCIIDOC_FOUND &quot;NO&quot;)&lt;br /&gt;
ELSE (NOT ASCIIDOC_EXECUTABLE)&lt;br /&gt;
  SET(ASCIIDOC_FOUND &quot;YES&quot;)&lt;br /&gt;
ENDIF (NOT ASCIIDOC_EXECUTABLE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
IF (NOT ASCIIDOC_FOUND AND Asciidoc_FIND_REQUIRED)&lt;br /&gt;
   MESSAGE(FATAL_ERROR &quot;Could not find asciidoc&quot;)&lt;br /&gt;
ENDIF (NOT ASCIIDOC_FOUND AND Asciidoc_FIND_REQUIRED)&lt;br /&gt;
&lt;/code&gt; 
    </content:encoded>

    <pubDate>Fri, 07 Nov 2008 13:14:38 +0000</pubDate>
    <guid isPermaLink="false">http://grahamcox.co.uk/serendipity/index.php?/archives/36-guid.html</guid>
    
</item>
<item>
    <title>Caret Position in a text control</title>
    <link>http://grahamcox.co.uk/serendipity/index.php?/archives/13-Caret-Position-in-a-text-control.html</link>
            <category>Code Snippets</category>
            <category>Cross-Browser</category>
    
    <comments>http://grahamcox.co.uk/serendipity/index.php?/archives/13-Caret-Position-in-a-text-control.html#comments</comments>
    <wfw:comment>http://grahamcox.co.uk/serendipity/wfwcomment.php?cid=13</wfw:comment>

    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://grahamcox.co.uk/serendipity/rss.php?version=2.0&amp;type=comments&amp;cid=13</wfw:commentRss>
    

    <author>nospam@example.com (Graham Cox)</author>
    <content:encoded>
    Once again, IE proves that it can&#039;t do anything in a standard way. &lt;br /&gt;
&lt;br /&gt;
Retrieving the caret position from a text control in Firefox and Opera is a very simple job - you simply use the selectionStart and selectionEnd parameters of the control itself.&lt;br /&gt;
&lt;br /&gt;
Retrieving the caret position from a text control in IE is not quite so simple. There are no parameters that give you this information, so you have to work it out for yourself. As it happens, there are a number of ways of doing this available on the internet. Unfortunatly, none of them work properly.&lt;br /&gt;
&lt;br /&gt;
The &quot;official&quot; method of doing it according to the Microsoft Web Team in the article &lt;a href=&quot;http://grahamcox.co.uk/serendipity/exit.php?url=aHR0cDovL21zZG4ubWljcm9zb2Z0LmNvbS9saWJyYXJ5L2RlZmF1bHQuYXNwP3VybD0vbGlicmFyeS9lbi11cy9kaHRtbHRlY2hjb2wvY29scy9kbndlYnRlYW0vd2VidGVhbTEyMDMyMDAxLmFzcA==&amp;amp;entry_id=13&quot; title=&quot;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dhtmltechcol/cols/dnwebteam/webteam12032001.asp&quot;  onmouseover=&quot;window.status=&#039;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dhtmltechcol/cols/dnwebteam/webteam12032001.asp&#039;;return true;&quot; onmouseout=&quot;window.status=&#039;&#039;;return true;&quot;&gt;Yule Not Want to Miss this One&lt;/a&gt; (See &quot;O Cursor, Where Art Thou—finding yourself in a text box&quot;) is just horrible:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Save the input field value in a temporary variable. &lt;/li&gt;&lt;li&gt;Create a TextRange object on the document.selection (assuming the input field is focused). &lt;/li&gt;&lt;li&gt;Insert a “~” character into that TextRange object (range.text = &quot;~&quot;). Thus, the tilde would be inserted at the caret position (which we actually want to determine). &lt;/li&gt;&lt;li&gt;Search for the “~” character in the input field value and remember the index where it was found. &lt;br /&gt;
Restore the original input field value, saved at (1). &lt;/li&gt;&lt;li&gt;Return the index determined at (4) and claim it is the caret position.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;
&lt;br /&gt;
The better method of doing it uses undocumented features of the Range object, and is &lt;a href=&quot;http://grahamcox.co.uk/serendipity/exit.php?url=aHR0cDovL3d3dy5iYXpvbi5uZXQvbWlzaG9vL2FydGljbGVzLmVwbD9hcnRfaWQ9MTI5Mg==&amp;amp;entry_id=13&quot; title=&quot;http://www.bazon.net/mishoo/articles.epl?art_id=1292&quot;  onmouseover=&quot;window.status=&#039;http://www.bazon.net/mishoo/articles.epl?art_id=1292&#039;;return true;&quot; onmouseout=&quot;window.status=&#039;&#039;;return true;&quot;&gt;described here by Mishoo&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
This uses the Range.getBookmark() function which returns a value that can be used to get to the caret position. It worked fine. And in IE7 it stopped working. Microsoft changed the way this function worked (It&#039;s undocumented and so they can do that) and broke things that rely on it.&lt;br /&gt;
&lt;br /&gt;
The third method of working out the caret position, which I have not seen mentioned anywhere on the internet and so might very well not work properly, is to use the Range.offsetLeft value. This gives you a value which represents the distance from the start of the text field that the caret is located at. In standard mode, this value is (position * 7) + 1. &lt;br /&gt;
&lt;br /&gt;
This has been tested in IE5, IE5.5, IE6 and IE7 and returns the same values across all of them. It also returns the same value regardless of the zoom of the page and the location of the textbox on the screen.&lt;br /&gt;
&lt;br /&gt;
As such, below is my cross-browser function to get the caret position from a given text field. It is known to work in Firefox, Opera, Netscape and (now) all versions of IE from 5.5 and up. &lt;br /&gt;&lt;a href=&quot;http://grahamcox.co.uk/serendipity/index.php?/archives/13-Caret-Position-in-a-text-control.html#extended&quot;&gt;Continue reading &quot;Caret Position in a text control&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Fri, 21 Jul 2006 10:23:52 +0100</pubDate>
    <guid isPermaLink="false">http://grahamcox.co.uk/serendipity/index.php?/archives/13-guid.html</guid>
    
</item>
<item>
    <title>Cross-Browser event object</title>
    <link>http://grahamcox.co.uk/serendipity/index.php?/archives/9-Cross-Browser-event-object.html</link>
            <category>Code Snippets</category>
            <category>Cross-Browser</category>
    
    <comments>http://grahamcox.co.uk/serendipity/index.php?/archives/9-Cross-Browser-event-object.html#comments</comments>
    <wfw:comment>http://grahamcox.co.uk/serendipity/wfwcomment.php?cid=9</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://grahamcox.co.uk/serendipity/rss.php?version=2.0&amp;type=comments&amp;cid=9</wfw:commentRss>
    

    <author>nospam@example.com (Graham Cox)</author>
    <content:encoded>
    Different browsers handle events in different ways. Unfortunatly, this means that the same function will receive it&#039;s data in different ways on different browsers. From the major three:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Firefox. Event object is passed as parameter to the callback function&lt;/li&gt;&lt;li&gt;Opera. Event object is passed as a parameter to the callback function. Some members of event object have different names&lt;/li&gt;&lt;li&gt;Internet Explorer. No parameters passed to callback function. Event object exists as a global variable(!) instead. Some members of event object have different names.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
Whilst Internet Explorer does use a global variable to store the event object, this is actually less of a problem since the javascript engine is single-threaded. It shouldn&#039;t be possible to have two event handlers for two different events using the same event object. This could change in IE7 or later however, at which time things will likely all stop working in a horrible manner.&lt;br /&gt;
&lt;br /&gt;
This snippit can be called, being passed the event parameter from the event handler, and will return an event object in a standardised way. Note that this is nowhere near finished, and still has a lot of work needed to cover everything. In specific, keyboard handling is very rudimentary (see below) and mouse handling is non-existant.  &lt;br /&gt;&lt;a href=&quot;http://grahamcox.co.uk/serendipity/index.php?/archives/9-Cross-Browser-event-object.html#extended&quot;&gt;Continue reading &quot;Cross-Browser event object&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Mon, 17 Jul 2006 17:34:54 +0100</pubDate>
    <guid isPermaLink="false">http://grahamcox.co.uk/serendipity/index.php?/archives/9-guid.html</guid>
    
</item>
<item>
    <title>Cross-Browser getElement()</title>
    <link>http://grahamcox.co.uk/serendipity/index.php?/archives/7-Cross-Browser-getElement.html</link>
            <category>Code Snippets</category>
            <category>Cross-Browser</category>
    
    <comments>http://grahamcox.co.uk/serendipity/index.php?/archives/7-Cross-Browser-getElement.html#comments</comments>
    <wfw:comment>http://grahamcox.co.uk/serendipity/wfwcomment.php?cid=7</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://grahamcox.co.uk/serendipity/rss.php?version=2.0&amp;type=comments&amp;cid=7</wfw:commentRss>
    

    <author>nospam@example.com (Graham Cox)</author>
    <content:encoded>
    This code is a simple Javascript function that works in most modern browsers to return a document element given the name of the element.

It requires that both the name and id attribute of the control be set to the same value, and this value is what is used to look up the element. 
 &lt;br /&gt;&lt;a href=&quot;http://grahamcox.co.uk/serendipity/index.php?/archives/7-Cross-Browser-getElement.html#extended&quot;&gt;Continue reading &quot;Cross-Browser getElement()&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Mon, 17 Jul 2006 13:42:55 +0100</pubDate>
    <guid isPermaLink="false">http://grahamcox.co.uk/serendipity/index.php?/archives/7-guid.html</guid>
    
</item>

</channel>
</rss>