<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Logs and memo</title>
	<atom:link href="http://tgoirand.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://tgoirand.wordpress.com</link>
	<description>Kindle, Java, Maven, Emacs and other stuff</description>
	<lastBuildDate>Thu, 05 Jan 2012 22:21:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='tgoirand.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Logs and memo</title>
		<link>http://tgoirand.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://tgoirand.wordpress.com/osd.xml" title="Logs and memo" />
	<atom:link rel='hub' href='http://tgoirand.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Using cookies, HttpURLConnection and InputStream in Java</title>
		<link>http://tgoirand.wordpress.com/2011/05/04/using-cookies-httpurlconnection-and-inputstream-in-java/</link>
		<comments>http://tgoirand.wordpress.com/2011/05/04/using-cookies-httpurlconnection-and-inputstream-in-java/#comments</comments>
		<pubDate>Wed, 04 May 2011 19:48:25 +0000</pubDate>
		<dc:creator>Thomas Goirand</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://tgoirand.wordpress.com/?p=254</guid>
		<description><![CDATA[java.net.HttpCookie has been introduced in Java 6. It&#8217;s quite rare to find any sample about it when it actually provides an easy way to collect cookies from an HTTP connection. As far as I know, there isn&#8217;t a convenient way to provide a CookieStore to an HttpURLConnection and the programmer has to set values and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=254&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://download.oracle.com/javase/6/docs/api/java/net/HttpCookie.html">java.net.HttpCookie</a> has been introduced in Java 6. It&#8217;s quite rare to find any sample about it when it actually provides an easy way to collect cookies from an HTTP connection.</p>
<p><pre class="brush: java;">
CookieManager cm = new CookieManager();
CookieHandler.setDefault(cm);
</pre></p>
<p>As far as I know, there isn&#8217;t a convenient way to provide a CookieStore to an HttpURLConnection and the programmer has to set values and properties of the HTTP header by himself.<br />
A way to avoid that, is to create an InputStream class which would behave just like FileOutputStream but for HTTP connections.</p>
<p>i.e.<br />
<pre class="brush: java;">
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpCookie;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;

import sun.misc.BASE64Encoder;

public class HttpInputStream extends InputStream {

	private InputStream is;
	private HttpURLConnection conn;
	public final static String USERAGENT_FIREFOX_5_MAC = &quot;Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; fr; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 GTB7.1&quot;;
	private int TIMEOUT = 10000;

	public HttpInputStream(URL url, String username, String password, HttpParameters params, List&lt;HttpCookie&gt; cookies) throws IOException {
		openConnection(url, USERAGENT_FIREFOX_5_MAC);
		setCookies(cookies);
		authenticate(username, password);
		setParameters(params);
		connect();
	}

	public HttpInputStream(URL url, String username, String password, HttpParameters params) throws IOException {
		openConnection(url, USERAGENT_FIREFOX_5_MAC);
		authenticate(username, password);
		setParameters(params);
		connect();
	}

	public HttpInputStream(URL url, HttpParameters params, List&lt;HttpCookie&gt; cookies) throws IOException {
		openConnection(url, USERAGENT_FIREFOX_5_MAC);
		setCookies(cookies);
		setParameters(params);
		connect();
	}

	public HttpInputStream(URL url, HttpParameters params) throws IOException {
		openConnection(url, USERAGENT_FIREFOX_5_MAC);
		setParameters(params);
		connect();
	}

	public HttpInputStream(URL url, List&lt;HttpCookie&gt; cookies) throws IOException {
		openConnection(url, USERAGENT_FIREFOX_5_MAC);
		setCookies(cookies);
		connect();
	}

	private void authenticate(String username, String password) {
		if (username != null) {
			BASE64Encoder enc = new BASE64Encoder();
			String userpassword = username + &quot;:&quot; + password;
			String encodedAuthorization = enc.encode(userpassword.getBytes());
			conn.setRequestProperty(&quot;Authorization&quot;, &quot;Basic &quot; + encodedAuthorization);
		}
	}

	private void openConnection(URL url, String useragent) throws IOException {
		conn = (HttpURLConnection) url.openConnection();
		if (useragent != null) {
			conn.setRequestProperty(&quot;User-agent&quot;, useragent);
		}
		conn.setDoOutput(true);
		conn.setReadTimeout(TIMEOUT);
	}
	
	protected void setCookies(List&lt;HttpCookie&gt; cookies) throws IOException {
		if (cookies != null) {
			for (HttpCookie cookie : cookies) {
				if (log.isDebugEnabled())
					log.debug(&quot;set cookie&quot;);
				conn.setRequestProperty(&quot;Cookie&quot;, cookie.getName() + &quot;=&quot; + cookie.getValue());
			}
		}
	}

	private void setParameters(HttpParameters params) throws IOException {
		if (params != null) {
			conn.setRequestMethod(params.getMethod().toString());
			conn.setDoInput(true);

			if (params.getMethod() == HttpParameters.HttpMethod.POST) {
				conn.setDoOutput(true);
				DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
				wr.writeBytes(params.getEncodedParamaters());
				wr.flush();
				wr.close();
			}
		} else {
			conn.setRequestMethod(&quot;GET&quot;);
		}
	}

	private void connect() throws IOException {
		conn.connect();
		is = conn.getInputStream();
	}

	@Override
	public int read() throws IOException {
		return is.read();
	}

	@Override
	public void close() throws IOException {
		is.close();
		conn.disconnect();
	}

	@Override
	public int read(byte[] b, int off, int len) throws IOException {
		return is.read(b, off, len);
	}

	@Override
	public int read(byte[] b) throws IOException {
		return is.read(b);
	}
}

</pre></p>
<p>The class HttpParameters:</p>
<p><pre class="brush: java;">
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.LinkedHashMap;
import java.util.Map;

public class HttpParameters {
	protected Map&lt;String, String&gt; params;
	protected HttpMethod method;
	protected String CHARSET = &quot;UTF-8&quot;;

	public HttpParameters(HttpMethod method) {
		this.method = method;
		params = new LinkedHashMap&lt;String, String&gt;();
	}

	public HttpParameters(Map&lt;String, String&gt; params, HttpMethod method) {
		this.params = params;
		this.method = method;
	}

	public void addParameter(String key, String value) {
		params.put(key, value);
	}

	public String getEncodedParamaters() throws UnsupportedEncodingException {
		StringBuilder sb = new StringBuilder();
		boolean first = true;
		for (String key : params.keySet()) {
			if (!first) {
				sb.append(&quot;&amp;&quot;);
			}
			first = false;

			sb.append(URLEncoder.encode(key, CHARSET));
			sb.append(&quot;=&quot;);
			sb.append(URLEncoder.encode(params.get(key), CHARSET));
		}

		return sb.toString();
	}
	
	public HttpMethod getMethod() {
		return method;
	}

	public void setMethod(HttpMethod method) {
		this.method = method;
	}

	public enum HttpMethod {
		GET, POST, PUT, DELETE
	}
}
</pre></p>
<p>Then it is easy to deal with HTTP content, URL and Cookies<br />
i.e</p>
<p><pre class="brush: java;">
CookieManager cm = new CookieManager();
CookieHandler.setDefault(cm);

// authenticate and get the session cookie
new HttpInputStream(new URL(&quot;http://www.foo.com/&quot;, &quot;login&quot;, &quot;password&quot;)).close();

// set parameters
HttpParameters param = new HttpParameters(HttpParameters.HttpMethod.POST);
param.addParameter(&quot;param1&quot;, &quot;value1&quot;);
param.addParameter(&quot;param2&quot;, &quot;value2&quot;);

// download a file using the cookie
InputStream is = new HttpInputStream(new URL(&quot;http://www.foo.com/space/doc.pdf&quot;, cm.getCookieStore().getCookies()), param);

OutputStream os = new FileOutputStream(new File(&quot;doc.pdf&quot;));

int read;
while ((read = os.read()) != -1)
	is.write(read);

is.close();
os.close();
</pre></p>
<p>et voilà.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tgoirand.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tgoirand.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tgoirand.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tgoirand.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tgoirand.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tgoirand.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tgoirand.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tgoirand.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tgoirand.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tgoirand.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tgoirand.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tgoirand.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tgoirand.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tgoirand.wordpress.com/254/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=254&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tgoirand.wordpress.com/2011/05/04/using-cookies-httpurlconnection-and-inputstream-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e717c8fdbabaaa4c45779202ca0ce05?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tgoirand</media:title>
		</media:content>
	</item>
		<item>
		<title>Mobipocket extracter and transformer for Alfresco</title>
		<link>http://tgoirand.wordpress.com/2011/04/27/mobipocket-extracter-and-transformer-for-alfresco/</link>
		<comments>http://tgoirand.wordpress.com/2011/04/27/mobipocket-extracter-and-transformer-for-alfresco/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 17:08:25 +0000</pubDate>
		<dc:creator>Thomas Goirand</dc:creator>
				<category><![CDATA[Alfresco]]></category>
		<category><![CDATA[Kindle]]></category>

		<guid isPermaLink="false">http://tgoirand.wordpress.com/?p=229</guid>
		<description><![CDATA[I&#8217;ve just published on AlfrescoForge an AMP file including an extracter and transformer for mobipocket format. It means it allows to extract metadata from unencrypted kindle documents and makes its content searchable. Anybody interested in the compression API can contact me.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=229&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just published on <a href="http://forge.alfresco.com/frs/?group_id=290">AlfrescoForge</a> an AMP file including an extracter and transformer for mobipocket format.</p>
<p>It means it allows to extract metadata from unencrypted kindle documents and makes its content searchable.<br />
<a href="http://tgoirand.files.wordpress.com/2011/04/screen-shot-2011-04-27-at-17-39-39.png"><img src="http://tgoirand.files.wordpress.com/2011/04/screen-shot-2011-04-27-at-17-39-39.png?w=530&#038;h=164" alt="" title="Screen shot 2011-04-27 at 17.39.39" width="530" height="164" class="aligncenter size-full wp-image-230" /></a></p>
<p>Anybody interested in the compression API can contact me.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tgoirand.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tgoirand.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tgoirand.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tgoirand.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tgoirand.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tgoirand.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tgoirand.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tgoirand.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tgoirand.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tgoirand.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tgoirand.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tgoirand.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tgoirand.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tgoirand.wordpress.com/229/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=229&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tgoirand.wordpress.com/2011/04/27/mobipocket-extracter-and-transformer-for-alfresco/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e717c8fdbabaaa4c45779202ca0ce05?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tgoirand</media:title>
		</media:content>

		<media:content url="http://tgoirand.files.wordpress.com/2011/04/screen-shot-2011-04-27-at-17-39-39.png" medium="image">
			<media:title type="html">Screen shot 2011-04-27 at 17.39.39</media:title>
		</media:content>
	</item>
		<item>
		<title>Mobipocket Algorithm for Java</title>
		<link>http://tgoirand.wordpress.com/2011/04/27/mobipocket-algorithm-for-java/</link>
		<comments>http://tgoirand.wordpress.com/2011/04/27/mobipocket-algorithm-for-java/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 11:01:45 +0000</pubDate>
		<dc:creator>Thomas Goirand</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Kindle]]></category>

		<guid isPermaLink="false">http://tgoirand.wordpress.com/?p=216</guid>
		<description><![CDATA[I&#8217;ve implemented mobipocket format and compression algorithm for Java since it didn&#8217;t seem to exist. The aim is to implement mobipocket compression used by Kindle devices for opensource Java content management systems such as Alfresco. The project hasn&#8217;t been fully tested and before I make it public on java.net (if I can figure out on how to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=216&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve implemented mobipocket format and compression algorithm for Java since it didn&#8217;t seem to exist.</p>
<p>The aim is to implement mobipocket compression used by Kindle devices for opensource Java content management systems such as Alfresco.</p>
<p>The project hasn&#8217;t been fully tested and before I make it public on <a href="http://java.net/projects/mobipocket/">java.net</a> (if I can figure out on how to make a project public), here is the tested algorithm for decompression.</p>
<p><pre class="brush: java;">
    /**
     * Unpack a mobipocket binary document section.
     * @param data data to extract
     * @param indice last position to extract
     * @return array of unpacked bytes.
     * @throws IOException
     * @author &lt;a href=&quot;tgoirand@gmail.com&quot;&gt;Thomas Goirand&lt;/a&gt;
     */
    byte[] unpack(int[] data, int indice) throws IOException {
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
        DataOutputStream o = new DataOutputStream(bo);

        int index = 0;

        while (index &lt; indice) {
            int val = data[index];
            index++;
            if (val &gt;= 1 &amp;&amp; val &lt;= 8 ) {
                for (int i = index; i &lt; index + val &amp;&amp; i &lt; data.length; i++) {
                    o.write((byte) data[i]);
                }
                index += val;
            } else if (val &lt; 128) {
                o.write((byte) val);
            } else if (val &gt;= 192) {
                o.write((byte) ' ');
                o.write((byte) (val ^ 128));
            } else {
                if (index &lt; indice) {
                    val = (val &lt;&lt; 8 ) | data[index];
                    index++;
                    int m = (val &gt;&gt; 3) &amp; 0x07ff;
                    int n = (val &amp; 7) + 3;

                    if (m &gt; n) {
                        byte[] buf = bo.toByteArray();
                        byte[] b = new byte[n];

                        for (int i = 0; i &lt; b.length; i++) {
                            b[i] = buf[(buf.length - m) + i];
                        }
                        o.write(b);
                    } else {
                        for (int i = 0; i &lt; n &amp;&amp; m &gt; 0; i++) {
                            byte[] buf = bo.toByteArray();
                            byte t = buf[buf.length - m];
                            o.write(t);
                        }
                    }
                }
            }

        }
        return bo.toByteArray();
    }
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tgoirand.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tgoirand.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tgoirand.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tgoirand.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tgoirand.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tgoirand.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tgoirand.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tgoirand.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tgoirand.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tgoirand.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tgoirand.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tgoirand.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tgoirand.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tgoirand.wordpress.com/216/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=216&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tgoirand.wordpress.com/2011/04/27/mobipocket-algorithm-for-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e717c8fdbabaaa4c45779202ca0ce05?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tgoirand</media:title>
		</media:content>
	</item>
		<item>
		<title>Opening AMP files with Emacs as Zip files</title>
		<link>http://tgoirand.wordpress.com/2011/04/26/opening-amp-files-with-emacs-as-zip-files/</link>
		<comments>http://tgoirand.wordpress.com/2011/04/26/opening-amp-files-with-emacs-as-zip-files/#comments</comments>
		<pubDate>Tue, 26 Apr 2011 07:35:36 +0000</pubDate>
		<dc:creator>Thomas Goirand</dc:creator>
				<category><![CDATA[Alfresco]]></category>

		<guid isPermaLink="false">http://tgoirand.wordpress.com/?p=205</guid>
		<description><![CDATA[A very useful Emacs feature is opening a zip file, browsing it as a folder and even editing its content. Alfresco Module Package (AMP)  is a zip file with a special structure. To get the same behavior with an AMP file than a zip file within Emacs, the following code can be added in the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=205&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A very useful Emacs feature is opening a zip file, browsing it as a folder and even editing its content.<br />
<a href="http://wiki.alfresco.com/wiki/AMP_Files">Alfresco Module Package</a> (AMP)  is a zip file with a special structure.<br />
To get the same behavior with an AMP file than a zip file within Emacs, the following code can be added in the .emacs config file:</p>
<p><pre class="brush: bash;">
(eval-after-load &quot;dired-aux&quot; '(add-to-list 'dired-compress-file-suffixes '(&quot;\\.amp\\'&quot; &quot;.amp&quot; &quot;unzip&quot;)))
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tgoirand.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tgoirand.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tgoirand.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tgoirand.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tgoirand.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tgoirand.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tgoirand.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tgoirand.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tgoirand.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tgoirand.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tgoirand.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tgoirand.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tgoirand.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tgoirand.wordpress.com/205/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=205&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tgoirand.wordpress.com/2011/04/26/opening-amp-files-with-emacs-as-zip-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e717c8fdbabaaa4c45779202ca0ce05?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tgoirand</media:title>
		</media:content>
	</item>
		<item>
		<title>Sending your subscription of &#8216;Le Monde&#8217; to your Kindle</title>
		<link>http://tgoirand.wordpress.com/2011/01/13/sending-your-subscription-of-le-monde-to-your-kindle/</link>
		<comments>http://tgoirand.wordpress.com/2011/01/13/sending-your-subscription-of-le-monde-to-your-kindle/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 21:46:27 +0000</pubDate>
		<dc:creator>Thomas Goirand</dc:creator>
				<category><![CDATA[Kindle]]></category>

		<guid isPermaLink="false">http://tgoirand.wordpress.com/?p=188</guid>
		<description><![CDATA[If you&#8217;re living far from home or like reading novels, technical books or newspapers in different languages, the new Amazon Kindle is a bless. It&#8217;s a pity different players as editors or publishers haven&#8217;t agreed yet to use the same rules. If you subscribe to Le Monde then, it&#8217;s not possible to send it periodically [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=188&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re living far from home or like reading novels, technical books or newspapers in different languages, the new Amazon Kindle is a bless.</p>
<p>It&#8217;s a pity different players as editors or publishers haven&#8217;t agreed yet to use the same rules.</p>
<p>If you subscribe to Le Monde then, it&#8217;s not possible to send it periodically to your Kindle account. It&#8217;s even not possible to buy &#8220;Le Monde&#8221; from the Kindle store when you live in the UK whilst it is available in the States (!?) (but not in France).</p>
<p>However, it&#8217;s possible if you own the device and a subscription, to build yourself a bridge to send one to the other.</p>
<p>I&#8217;ve just done a rather <strong>dirty script</strong> in Python (actually my first script in Python) which is doing the job.</p>
<p><pre class="brush: python;">'''

@author: Thomas Goirand
'''

import sgmllib

class LeMondeArticleParser(sgmllib.SGMLParser):

 def reset(self):
 sgmllib.SGMLParser.reset(self)
 self.headline = []
 self.body = []
 self.verbheadline = 0
 self.verbbody = 0

 def parse(self, s):
 self.feed(s)
 self.close()

 def rebuild_tag(self, tag, attrs):
 s = ''
 if not attrs:
 s += '&lt;' + tag + '&gt;'
 else:
 s += '&lt;' + tag
 for name, value in attrs:
 s += ' ' + name + '=' + '&quot;' + value + '&quot;'
 s += '&gt;'
 return s

 def unknown_starttag(self, tag, attrs):
 if tag == 'span':
 att = [v for k, v in attrs if k=='class']
 if (self.verbbody &gt; 0):
 self.verbbody += 1
 if (att[0] == 'dossiertitre'):
 self.verbheadline = 1
 if (att[0] == 'dossiertxt'):
 self.verbbody = 1
 if (self.verbbody &gt; 0):
 self.body.append(self.rebuild_tag(tag, attrs))

 def unknown_endtag(self, tag):
 if tag == 'span':
 self.verbheadline = 0
 self.verbbody -= 1

 if (self.verbbody &gt; 0):
 self.body.append('&lt;/' + tag + '&gt;')

 def handle_data(self, text):
 if (self.verbheadline &gt; 0):
 self.headline.append(text)
 if (self.verbbody &gt; 0):
 self.body.append(text)

 def get_headline(self):
 return ''.join(self.headline)

 def get_body(self):
 return ''.join(self.body)

# Parser to retrieve URL from the index
class LeMondeIndex(sgmllib.SGMLParser):

 def reset(self):
 sgmllib.SGMLParser.reset(self)
 self.urls = {}
 self.url = ''
 self.index_ori = 0 # keep the original order, but...
 self.index_tuples = {} # I'm sure there's better TODO

 def parse(self, s):
 self.feed(s)
 self.close()

 def unknown_starttag(self, tag, attrs):
 option = [v for k, v in attrs if tag == 'option' and k=='value']
 if option:
 self.url = option[0]


 def unknown_endtag(self, tag):
 if (self.url != '' and tag == 'option'):
 self.url = ''


 def handle_data(self, text):
 if (self.url != ''):
 if not self.url in self.urls:
 self.urls[self.url] = ''
 self.index_ori = self.index_ori + 1
 self.index_tuples[self.index_ori] = self.url
 self.urls[self.url] += text;

 def get_urls(self):
 return self.urls

 def get_order(self):
 return self.index_tuples

class LeMondeCategories(sgmllib.SGMLParser):

 def reset(self):
 sgmllib.SGMLParser.reset(self)
 self.urls = {}
 self.url = ''
 self.index_ori = 0 # keep the original order, but...
 self.index_tuples = {} # I'm sure there's better TODO

 def parse(self, s):
 self.feed(s)
 self.close()

 def start_a(self, attrs):
 import fnmatch

 href = [v for k, v in attrs if k=='href']
 if href and fnmatch.fnmatch(href[0], &quot;article_*&quot;):
 self.url = href[0]


 def end_a(self):
 if (self.url != ''):
 self.url = ''


 def handle_data(self, text):
 if (self.url != ''):
 if not self.url in self.urls:
 self.urls[self.url] = ''
 self.index_ori = self.index_ori + 1
 self.index_tuples[self.index_ori] = self.url
 self.urls[self.url] += text;

 def get_urls(self):
 return self.urls

 def get_order(self):
 return self.index_tuples


class FindArticlesParser(sgmllib.SGMLParser):

 def reset(self):
 sgmllib.SGMLParser.reset(self)
 self.url = ''

 def unknown_starttag(self, tag, attrs):
 if tag == 'iframe':
 src = [v for k, v in attrs if k=='src']
 if src:
 self.url = src[0]

 def parse(self, s):
 self.feed(s)
 self.close()

 def get_url(self):
 return self.url

class FindZipParser(sgmllib.SGMLParser):

 def reset(self):
 sgmllib.SGMLParser.reset(self)
 self.url = ''

 def start_a(self, attrs):
 href = [v for k, v in attrs if k=='href']
 s_class = [v for k, v in attrs if k=='class']
 if s_class and s_class[0] == 'html_lienTelech' and href:
 self.url = href[0]

 def parse(self, s):
 self.feed(s)
 self.close()

 def get_url(self):
 return self.url

class ZipManager():
 import zipfile, fnmatch

 def parse(self, path_file):
 print &quot;Open zip file &quot; + path_file
 self.zip_f = self.zipfile.ZipFile(path_file, &quot;r&quot;)

 def open_file(self, name_file):
 for name in self.zip_f.namelist():
 if self.fnmatch.fnmatch(name, '*/' + name_file):
 data = self.zip_f.read(name)
 return data

 def close(self):
 self.zip_f.close()

def clean_file_and_add(content, dest):
 p = LeMondeArticleParser()
 p.parse(content)
 dest.write('&lt;h3&gt;' + p.get_headline() + '&lt;/h3&gt;')
 dest.write(p.get_body())
 p.close()


def download_document(s_login, s_password, dir_target):
 import urllib2, urllib

 &quot;&quot;&quot;
 Authentication
 &quot;&quot;&quot;
 query_args = { 'url_zop':'http://abonnes.lemonde.fr/', 'url':'http://www.lemonde.fr/', 'login':s_login, 'password':s_password, 'connexion':'Connexion' }
 req = urllib2.Request(&quot;http://www.lemonde.fr/teaser/&quot;, urllib.urlencode(query_args))
 req.add_header('User-agent', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; fr; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 GTB7.1')
 req.add_header('Referer', 'http://www.lemonde.fr/')

 response = urllib2.urlopen(req)
 cookies = response.headers.get('Set-Cookie')

 &quot;&quot;&quot;
 Searching the zip file
 &quot;&quot;&quot;

 req_art = urllib2.Request(&quot;http://abonnes.lemonde.fr/les-articles-du-monde/&quot;)
 req_art.add_header('cookie', cookies)

 req.add_header('User-agent', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; fr; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 GTB7.1')
 req.add_header('Referer', 'http://www.lemonde.fr/')

 res_art = urllib2.urlopen(req_art)
 art_page = res_art.read()
 res_art.close()

 p = FindArticlesParser()
 p.parse(art_page) # TODO does it exist?

 # Last page
 s_download_page = &quot;http://abonnes.lemonde.fr&quot; + p.get_url()
 print &quot;Found expected document in &quot; + s_download_page

 req_art2 = urllib2.Request(&quot;http://abonnes.lemonde.fr&quot; + p.get_url())
 req_art2.add_header('cookie', cookies)
 req_art2.add_header('User-agent', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; fr; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 GTB7.1')
 req_art2.add_header('Referer', 'http://abonnes.lemonde.fr/')

 res_art2 = urllib2.urlopen(req_art2)
 art_page2 = res_art2.read()
 res_art2.close()

 p_zip = FindZipParser()
 p_zip.parse(art_page2)

 &quot;&quot;&quot;
 Downloading zip
 &quot;&quot;&quot;

 zip_file_www = urllib2.Request(p_zip.get_url())
 zip_file_www.add_header('cookie', cookies)
 zip_file_www.add_header('User-agent', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; fr; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 GTB7.1')
 zip_file_www.add_header('Referer', s_download_page)
 res_www_zip = urllib2.urlopen(zip_file_www)

 a_filename = p_zip.get_url().split('/')
 file_name = a_filename[len(a_filename) - 1]

 print &quot;Download to &quot; + dir_target + file_name
 output = open(dir_target + file_name,'wb')
 output.write(res_www_zip.read())

 return dir_target + file_name



def process_dir(zip_file, target):
 file_rel_cat = 'data/frame_gauche_1.html'

 m_zip = ZipManager()
 m_zip.parse(zip_file)
 ctt_struct = m_zip.open_file(file_rel_cat)

 p = LeMondeIndex()
 p.parse(ctt_struct)

 urls_index = p.get_urls()

 print &quot;Create file &quot; + target
 file_target = open(target, 'w')
 file_target.write('&lt;html&gt;')
 file_target.write('&lt;head&gt;')
 file_target.write('&lt;title&gt;Le Monde&lt;/title&gt;')
 file_target.write('&lt;/head&gt;')
 file_target.write('&lt;body&gt;')


 # Generate topics table
 file_target.write('&lt;a name=&quot;toc&quot; /&gt;')
 file_target.write('&lt;ul&gt;')
 for k, v in sorted(p.get_order().iteritems()):
 file_target.write('&lt;li&gt;&lt;a href=&quot;#' + v + '&quot;&gt;' + urls_index[v] +'&lt;/a&gt;&lt;/li&gt;')
 s_cats = m_zip.open_file('data/' + v)
 p_cats = LeMondeCategories()
 p_cats.parse(s_cats)
 cats_lemonde = p_cats.get_urls()

 file_target.write('&lt;ul&gt;')
 for k_c, v_c in sorted(p_cats.get_order().iteritems()):
 file_target.write('&lt;li&gt;&lt;a href=&quot;#' + v_c + '&quot;&gt;*&lt;/a&gt; ' + cats_lemonde[v_c] +'&lt;/li&gt;')
 file_target.write('&lt;/ul&gt;\n')


 file_target.write('&lt;/ul&gt;\n')
 file_target.write('&lt;a name=&quot;start&quot; /&gt;')
 for k, v in sorted(p.get_order().iteritems()):
 file_target.write('&lt;a name=&quot;' + v + '&quot;&gt;&lt;/a&gt;&lt;h2&gt;' + urls_index[v] +'&lt;/h2&gt;&lt;br&gt;')
 s_cats = m_zip.open_file('data/' + v)
 p_cats = LeMondeCategories()
 p_cats.parse(s_cats)
 cats_lemonde = p_cats.get_urls()

 for k_c, v_c in sorted(p_cats.get_order().iteritems()):
 file_target.write('&lt;a name=&quot;' + v_c + '&quot;&gt;&lt;/a&gt;\n')
 file_target.write('&lt;mbp:section&gt;\n')
 clean_file_and_add(m_zip.open_file('data/' + v_c), file_target)
 file_target.write('&lt;/mbp:section&gt;\n')
 file_target.write('&lt;mbp:pagebreak /&gt;')

 file_target.write('&lt;/body&gt;&lt;/html&gt;')
 m_zip.close()
 file_target.close()

def send_mail(mail_from, mail_to, f_attachement_content):
 import smtplib, os
 from email.mime.multipart import MIMEMultipart
 from email.MIMEBase import MIMEBase
 from email import Encoders

 print &quot;Sending mail from &quot; + mail_from + &quot; to &quot; + mail_to

 msg = MIMEMultipart()
 msg['Subject'] = 'Le Monde'
 msg['From'] = mail_from
 msg['To'] = mail_to

 part = MIMEBase('application', &quot;octet-stream&quot;)
 part.set_payload( open(f_attachement_content, &quot;rb&quot;).read() )
 Encoders.encode_base64(part)
 part.add_header('Content-Disposition', 'attachment; filename=&quot;%s&quot;' % os.path.basename(f_attachement_content))
 msg.attach(part)

 s = smtplib.SMTP('localhost')
 s.sendmail(mail_from, mail_to, msg.as_string())
 s.quit()

def process_lemonde(s_login, s_password, f_target, mail_from, mail_to):
 z_zip = download_document(s_login, s_password, f_target)

 s_name_zip = z_zip.split('/')
 s_doc_name = &quot;Le Monde (&quot; + s_name_zip[len(s_name_zip) - 1] + &quot;).html&quot;

 process_dir(z_zip, f_target + s_doc_name)
 send_mail(mail_from, mail_to, f_target + s_doc_name)

if __name__ == '__main__':
 process_lemonde(&quot;youremailforlemonde@domain.com&quot;, &quot;yourpasswordforlemonde&quot;, &quot;/directorytmp/&quot;, &quot;youremail4amazon@domain.com&quot;, &quot;login4amazon@free.kindle.com&quot;)

</pre></p>
<p>Exceptions are not handled properly, there is a lot to improve to get a better formatting. Suggestions are welcome.</p>
<p>You will need it to set the cron like as following if you&#8217;re running linux:</p>
<p><pre class="brush: bash;">
0 15 * * 1-6 python /home/user/kindle/script.py
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tgoirand.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tgoirand.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tgoirand.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tgoirand.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tgoirand.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tgoirand.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tgoirand.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tgoirand.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tgoirand.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tgoirand.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tgoirand.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tgoirand.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tgoirand.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tgoirand.wordpress.com/188/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=188&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tgoirand.wordpress.com/2011/01/13/sending-your-subscription-of-le-monde-to-your-kindle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e717c8fdbabaaa4c45779202ca0ce05?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tgoirand</media:title>
		</media:content>
	</item>
		<item>
		<title>VDR + XBMC + Ubuntu</title>
		<link>http://tgoirand.wordpress.com/2010/12/04/vdr-xbmc-ubuntu/</link>
		<comments>http://tgoirand.wordpress.com/2010/12/04/vdr-xbmc-ubuntu/#comments</comments>
		<pubDate>Sat, 04 Dec 2010 12:53:02 +0000</pubDate>
		<dc:creator>Thomas Goirand</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://tgoirand.wordpress.com/?p=176</guid>
		<description><![CDATA[&#8220;PVR&#8221;, &#8220;media player&#8221;, &#8220;Digital video recorder&#8221;, whatever the name, I&#8217;ve used the software VDR to play TV and record it for now more than five years. It&#8217;s quite handy and for people like me who are not fond of TV, it allows to set up easily what they want to record and convert video to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=176&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8220;PVR&#8221;, &#8220;media player&#8221;, &#8220;Digital video recorder&#8221;, whatever the name, I&#8217;ve used the software <a title="VDR" href="http://www.tvdr.de/">VDR</a> to play TV and record it for now more than five years. It&#8217;s quite handy and for people like me who are not fond of TV, it allows to set up easily what they want to record and convert video to watch it on the train using a device such an IPhone.</p>
<p>I&#8217;ve always found VDR rather ugly though and being able to plug it to the fabulous software <a title="XBMC" href="http://xbmc.org/">XBMC</a> was not only the oppotunity to keep the engine and hide the UI interface but also adding essential features as Video On Demand (VOD) (youtube or some international programs like the great &#8220;<a href="http://www.arretsurimages.net/">Arret sur Images</a>&#8221; for French speaking people).</p>
<p>Here an HD video streamed from the Vimeo website:<br />
<a href="http://tgoirand.files.wordpress.com/2010/12/2011-04-29_1280x7202.png"><img src="http://tgoirand.files.wordpress.com/2010/12/2011-04-29_1280x7202.png?w=530&#038;h=298" alt="" title="2011-04-29_1280x720" width="530" height="298" class="aligncenter size-full wp-image-243" /></a></p>
<p>A screenshot of the Video menu:<br />
<a href="http://tgoirand.files.wordpress.com/2010/12/settings.png"><img src="http://tgoirand.files.wordpress.com/2010/12/settings.png?w=530&#038;h=298" alt="" title="XBMC video menu" width="530" height="298" class="aligncenter size-full wp-image-234" /></a></p>
<p>Now including Live TV:</p>
<p><a href="http://tgoirand.files.wordpress.com/2010/12/tv1.png"><img src="http://tgoirand.files.wordpress.com/2010/12/tv1.png?w=530&#038;h=298" alt="" title="Live TV menu" width="530" height="298" class="aligncenter size-full wp-image-236" /></a></p>
<p>With amazing live programs<br />
<a href="http://tgoirand.files.wordpress.com/2010/12/2011-04-29_1280x7204.png"><img src="http://tgoirand.files.wordpress.com/2010/12/2011-04-29_1280x7204.png?w=530&#038;h=298" alt="" title="TV" width="530" height="298" class="aligncenter size-full wp-image-248" /></a></p>
<p>Record your favorite program using the EPG facilities:<br />
<a href="http://tgoirand.files.wordpress.com/2010/12/2011-04-29_1280x7203.png"><img src="http://tgoirand.files.wordpress.com/2010/12/2011-04-29_1280x7203.png?w=530&#038;h=298" alt="" title="EPG" width="530" height="298" class="aligncenter size-full wp-image-246" /></a></p>
<p><strong>My Configuration</strong></p>
<p>Location:<br />
North London</p>
<p>PCI cards:<br />
- TerraTec Cinergy 1400 DVB-T<br />
- M-AUDIO &#8211; Audiophile 2496</p>
<p><strong>First installing softwares </strong></p>
<p>- Install Ubuntu 10.04 (lucid)<br />
- Add the repo for XBMC with PVR branch</p>
<p><pre class="brush: bash;">
sudo add-apt-repository ppa:lars-opdenkamp/xbmc-pvr
sudo add-apt-repository ppa:alexandr-surkov/test2
</pre></p>
<p>- Execute the commands</p>
<p><pre class="brush: bash;">
apt-get update
apt-get install xbmc vdr vdr-plugin-streamdev-server vdr-plugin-vnsiserver vdradmin-am
</pre></p>
<p><strong>Configuring VDR</strong></p>
<p>- Configure /etc/vdr/plugins/streamdevhosts.conf to stream TV on your local network (using VLC as client)</p>
<p>Edit /etc/vdr/channels.conf</p>
<p>Find channels from your area using dvbscan or if you live in North London you can add the following settings</p>
<p><pre class="brush: bash;">
:BBC
BBC ONE;BBC:505833330:B8C34D34G32M16T2Y0:T:0:600=2:601=eng@3,602=eng@3:0:0:4164:9018:4100:0
BBC TWO;BBC:505833330:B8C34D34G32M16T2Y0:T:0:610=2:611=eng@3,612=eng@3:0:0:4228:9018:4100:0
BBC THREE;BBC:505833330:B8C34D34G32M16T2Y0:T:0:0:0:0:0:4351:9018:4100:0
BBC FOUR;BBC:529833330:B8C34D34G32M16T2Y0:T:0:0:0:0:0:16832:9018:16384:0
:Channel 4
Film4;Channel 4 TV:537833330:B8C34D34G32M16T2Y0:T:0:701=2:702=eng@4,704=eng@4:0:0:27136:9018:24576:0
Channel 4;Channel 4 TV:481833330:B8C23D12G32M64T2Y0:T:0:560=2:561=eng@4,562=eng@4:0:0:8384:9018:8197:0
E4;Channel 4 TV:481833330:B8C23D12G32M64T2Y0:T:0:570=2:571=eng@4,572=eng@4:0:0:8448:9018:8197:0
E4+1;Channel 4 TV:578166670:B8C34D34G32M16T2Y0:T:0:501=2:502=eng@4,504=eng@4:0:0:22336:9018:20480:0
:ITV
ITV1;ITV:481833330:B8C23D12G32M64T2Y0:T:0:520=2:521=eng@3,522=eng@3:0:0:8261:9018:8197:0
ITV2;ITV:481833330:B8C23D12G32M64T2Y0:T:0:530=2:531=eng@3,532=eng@3:0:0:8325:9018:8197:0
ITV3;ITV:561833330:B8C23D12G32M64T2Y0:T:0:6881=2:6882=eng@4,6883=eng@4:0:0:16048:9018:12290:0
ITV4;ITV:537833330:B8C34D34G32M16T2Y0:T:0:601=2:602=eng@4,604=eng@4:0:0:28032:9018:24576:0
CITV;ITV:561833330:B8C23D12G32M64T2Y0:T:0:6833=2:6834=eng@4,6835=eng@4:0:0:16032:9018:12290:0
BBC NEWS 24;BBC:505833:I0C34D0M16B8T2G32Y0:T:27500:640=2:641=eng@3:0:0:4415:0:0:0
ITV News;ITV:481833:I0C23D0M64B8T2G32Y0:T:27500:2850=2:2851=@4:0:0:8581:0:0:0
:Sky
SKY THREE;Sky:578166670:B8C34D34G32M16T2Y0:T:0:301=2:302=eng@4,304=eng@4:0:0:22208:9018:20480:0
Sky Spts News;Sky:578166670:B8C34D34G32M16T2Y0:T:0:0:0:0:0:22144:9018:20480:0
Sky News;Sky:578166670:B8C34D34G32M16T2Y0:T:0:101=2:102=eng@4,104=eng@4:0:0:22080:9018:20480:0
Dave;UKTV:578166670:B8C34D34G32M16T2Y0:T:0:401=2:402=eng@4,404=eng@4:0:0:22272:9018:20480:0
4Music:537833330:B8C34D34G32M16T2Y0:T:0:101=2:102=eng@4:0:0:25664:9018:24576:0
VIVA;MTV Europe:537833330:B8C34D34G32M16T2Y0:T:0:201=2:202=eng@4:0:0:25728:9018:24576:0
Yesterday;UKTV:537833330:B8C34D34G32M16T2Y0:T:0:301=2:302=eng@4,304=eng@4:0:0:25792:9018:24576:0
Ideal World:537833330:B8C34D34G32M16T2Y0:T:0:501=2:502=eng@4:0:0:25920:9018:24576:0
Dave ja vu;UKTV:537833330:B8C34D34G32M16T2Y0:T:0:0:0:0:0:27392:9018:24576:0
Create &amp; Craft;Ideal Shopping Direct Plc:537833330:B8C34D34G32M16T2Y0:T:0:2301=2:2302=eng@4,2304=eng@4:0:0:27776:9018:24576:0
Q:537833330:B8C34D34G32M16T2Y0:T:0:0:1901=eng@4:0:0:26688:9018:24576:0
FIVER;five:561833330:B8C23D12G32M64T2Y0:T:0:6673=2:6674=eng@4,6675=eng@4:0:0:12928:9018:12290:0
FIVE USA;five:561833330:B8C23D12G32M64T2Y0:T:0:6689=2:6690=eng@4,6691=eng@4:0:0:12992:9018:12290:0
QVC;QVC:561833330:B8C23D12G32M64T2Y0:T:0:6049=2:6050=eng@4:0:0:13120:9018:12290:0
Channel One;Virgin Media Television Limited:561833330:B8C23D12G32M64T2Y0:T:0:6785=2:6786=eng@4,6787=eng@4:0:0:14304:9018:12290:0
QUEST;Discovery:561833330:B8C23D12G32M64T2Y0:T:0:6929=2:6930=eng@4:0:0:14498:9018:12290:0
Ttext Holidays;Teletext Limited:561833330:B8C23D12G32M64T2Y0:T:0:0:6354=eng@4:0:0:14784:9018:12290:0
ESPN;ESPN:561833330:B8C23D12G32M64T2Y0:T:0:6801=2:6802=eng@4:0:100,180A:16096:9018:12290:0
TOPUP Anytime3;TopUp TV Ltd:561833330:B8C23D12G32M64T2Y0:T:0:0:0:0:100:16288:9018:12290:0
301;BBC:529833330:B8C34D34G32M16T2Y0:T:0:203=2:407=eng@3,408=und@3:0:0:19456:9018:16384:0
:Radio
BBC Radio 1;BBC:529833330:B8C34D34G32M16T2Y0:T:0:0:436=eng@3:0:0:18496:9018:16384:0
BBC Radio 2;BBC:529833330:B8C34D34G32M16T2Y0:T:0:0:437=eng@3:0:0:18560:9018:16384:0
BBC Radio 3;BBC:529833330:B8C34D34G32M16T2Y0:T:0:0:438=eng@3:0:0:18624:9018:16384:0
BBC Radio 4;BBC:529833330:B8C34D34G32M16T2Y0:T:0:0:439=eng@3:0:0:18688:9018:16384:0
BBC World Sv.;BBC:529833330:B8C34D34G32M16T2Y0:T:0:0:440=eng@3:0:0:18304:9018:16384:0
BBC Asian Net.;BBC:529833330:B8C34D34G32M16T2Y0:T:0:0:435=eng@3:0:0:18240:9018:16384:0
BBC R1X;BBC:529833330:B8C34D34G32M16T2Y0:T:0:0:434=eng@3:0:0:18176:9018:16384:0
BBC Radio 7;BBC:529833330:B8C34D34G32M16T2Y0:T:0:0:433=eng@3:0:0:18112:9018:16384:0
BBC 6 Music;BBC:529833330:B8C34D34G32M16T2Y0:T:0:0:432=eng@3:0:0:18048:9018:16384:0
BBC R5SX;BBC:529833330:B8C34D34G32M16T2Y0:T:0:0:431=eng@3:0:0:17984:9018:16384:0
BBC R5L;BBC:529833330:B8C34D34G32M16T2Y0:T:0:0:430=eng@3:0:0:17920:9018:16384:0
BBC Parliament;BBC:529833330:B8C34D34G32M16T2Y0:T:0:205=2:421=eng@3:0:0:17024:9018:16384:0
CBeebies;BBC:529833330:B8C34D34G32M16T2Y0:T:0:201=2:401=eng@3,402=eng@3:0:0:16960:9018:16384:0
302;BBC:529833330:B8C34D34G32M16T2Y0:T:0:204=2:411=eng@4,412=und@4:0:0:19520:9018:16384:0
CBBC Channel;BBC:505833330:B8C34D34G32M16T2Y0:T:0:620=2:621=eng@3,622=eng@3:0:0:4671:9018:4100:0
BBC NEWS;BBC:505833330:B8C34D34G32M16T2Y0:T:0:640=2:641=eng@4:0:0:4415:9018:4100:0
Magic:537833330:B8C34D34G32M16T2Y0:T:0:0:1801=eng@4:0:0:26624:9018:24576:0
The Hits Radio:537833330:B8C34D34G32M16T2Y0:T:0:0:1701=eng@4:0:0:26560:9018:24576:0
Kerrang!:537833330:B8C34D34G32M16T2Y0:T:0:0:1301=eng@4:0:0:26304:9018:24576:0
heat:537833330:B8C34D34G32M16T2Y0:T:0:0:1201=eng@4:0:0:26240:9018:24576:0
Kiss:537833330:B8C34D34G32M16T2Y0:T:0:0:1101=eng@4:0:0:26176:9018:24576:0
SMOOTH RADIO;GMG:537833330:B8C34D34G32M16T2Y0:T:0:0:1401=eng@4:0:0:26368:9018:24576:0
ADULT smileTV3;Game Network:578166670:B8C34D34G32M16T2Y0:T:0:0:0:0:0:22400:9018:20480:0
Virgin1+1;Virgin Media Television Limited:537833330:B8C34D34G32M16T2Y0:T:0:0:0:0:0:25856:9018:24576:0
Lottery Xtra;Camelot Group plc:537833330:B8C34D34G32M16T2Y0:T:0:0:0:0:0:27264:9018:24576:0
TOPUP Anytime4;Top Up TV Europe Limited:537833330:B8C34D34G32M16T2Y0:T:0:0:0:0:0:27328:9018:24576:0
Russia Today;Information TV:537833330:B8C34D34G32M16T2Y0:T:0:2101=2:2102=eng@4,2104=eng@4:0:0:27456:9018:24576:0
ADULT smileTV2:537833330:B8C34D34G32M16T2Y0:T:0:0:0:0:0:27520:9018:24576:0
Big Deal:537833330:B8C34D34G32M16T2Y0:T:0:0:0:0:0:27648:9018:24576:0
ADULT Babestn;Game Network:537833330:B8C34D34G32M16T2Y0:T:0:0:0:0:0:27904:9018:24576:0
Al Jazeera Eng;Al Jazeera International Ltd:537833330:B8C34D34G32M16T2Y0:T:0:0:0:0:0:27712:9018:24576:0
Rocks &amp; Co 1;NETPLAYTV:537833330:B8C34D34G32M16T2Y0:T:0:0:0:0:0:27840:9018:24576:0
BBC Red Button;BBC:505833330:B8C34D34G32M16T2Y0:T:0:0:0:0:0:4479:9018:4100:0
Home;five:561833330:B8C23D12G32M64T2Y0:T:0:0:0:0:0:14976:9018:12290:0
Television X;five:561833330:B8C23D12G32M64T2Y0:T:0:0:0:0:0:15232:9018:12290:0
G.O.L.D.;five:561833330:B8C23D12G32M64T2Y0:T:0:0:0:0:0:15552:9018:12290:0
Teachers TV;five:561833330:B8C23D12G32M64T2Y0:T:0:0:0:0:0:15808:9018:12290:0
TOPUP Anytime1;TopUp TV Ltd:561833330:B8C23D12G32M64T2Y0:T:0:0:0:0:0:16224:9018:12290:0
TOPUP Anytime2;Top Up TV Europe Limited:561833330:B8C23D12G32M64T2Y0:T:0:0:0:0:0:16256:9018:12290:0
SuperCasino;NETPLAYTV BROADCASTING LTD:561833330:B8C23D12G32M64T2Y0:T:0:0:0:0:0:14560:9018:12290:0
CNN;CNN:561833330:B8C23D12G32M64T2Y0:T:0:6945=2:6946=eng@4:0:0:15648:9018:12290:0
ADULT PARTY;Square1 Management Ltd:561833330:B8C23D12G32M64T2Y0:T:0:0:0:0:0:14368:9018:12290:0
ADULT TMTV;Bang Media (London) Ltd:561833330:B8C23D12G32M64T2Y0:T:0:0:0:0:0:15264:9018:12290:0
303;BBC:529833330:B8C34D34G32M16T2Y0:T:0:0:0:0:0:19584:9018:16384:0
Community;BBC:529833330:B8C34D34G32M16T2Y0:T:0:0:0:0:0:19968:9018:16384:0
Smash Hits!;Bauer:561833330:B8C23D12G32M64T2Y0:T:0:0:6306=@4:0:0:14592:9018:12290:0
Absolute Radio;Absolute Radio:578166670:B8C34D34G32M16T2Y0:T:0:0:1901=@4:0:0:23104:9018:20480:0
Premier Radio;London Christian Radio Ltd:578166670:B8C34D34G32M16T2Y0:T:0:0:1701=eng@4:0:0:22976:9018:20480:0
talkSPORT;talkSPORT:578166670:B8C34D34G32M16T2Y0:T:0:0:1101=eng@4:0:0:22592:9018:20480:0
price-drop tv;sit-up limited:578166670:B8C34D34G32M16T2Y0:T:0:611=2:612=eng@4:0:0:22464:9018:20480:0
bid tv;Sit-Up Ltd:561833330:B8C23D12G32M64T2Y0:T:0:6273=2:6274=eng@4:0:0:14272:9018:12290:0
More 4;Channel 4 TV:481833330:B8C23D12G32M64T2Y0:T:0:590=2:591=eng@4,592=eng@4:0:0:8442:9018:8197:0
Heart;Global Radio:481833330:B8C23D12G32M64T2Y0:T:0:0:631=eng@3:0:0:8772:9018:8197:0
Channel 4+1;Channel 4 TV:481833330:B8C23D12G32M64T2Y0:T:0:580=2:581=eng@4,582=eng@4:0:0:8452:9018:8197:0
ITV2 +1;ITV:481833330:B8C23D12G32M64T2Y0:T:0:600=2:601=eng@3,602=eng@3:0:0:8361:9018:8197:0
FIVE;five:481833330:B8C23D12G32M64T2Y0:T:0:540=2:541=eng@3,542=eng@3:0:0:8500:9018:8197:0
Babestation2;Game Network BV:537833330:B8C34D34G32M16T2Y0:T:0:0:0:0:0:27584:9018:24576:0
Ideal Extra;Ideal Shopping Direct PLC:578166670:B8C34D34G32M16T2Y0:T:0:2101=2:2102=eng@4:0:0:23808:9018:20480:0
TV News;Cellcast:578166670:B8C34D34G32M16T2Y0:T:0:0:0:0:0:23872:9018:20480:0
COMMUNITY;Mediatrust:578166670:B8C34D34G32M16T2Y0:T:0:0:0:0:0:24064:9018:20480:0
Dave ja vu;UKTV:578166670:B8C34D34G32M16T2Y0:T:0:2111=2:2112=eng@4,2114=eng@4:0:0:23936:9018:20480:0
Big Deal:578166670:B8C34D34G32M16T2Y0:T:0:0:0:0:0:24000:9018:20480:0
Sky Sports 1;BT plc:529833330:B8C34D34G32M16T2Y0:T:0:202=2:403=eng@3,404=eng@3:0:100,180A:20160:9018:16384:0
Sky Sports 2;BT plc:529833330:B8C34D34G32M16T2Y0:T:0:204=2:411=eng@3,412=eng@3:0:100,180A:20224:9018:16384:0
Gems TV;Coloured Rocks Ltd:561833330:B8C23D12G32M64T2Y0:T:0:0:0:0:0:15328:9018:12290:0
Sky3+1;BSkyB:578166670:B8C34D34G32M16T2Y0:T:0:201=2:202=eng@4,203=eng@4:0:0:22244:9018:20480:0
ADULT Bluekiss;Games Network BV:578166670:B8C34D34G32M16T2Y0:T:0:0:0:0:0:24128:9018:20480:0
ADULT redhotTV;RHF Productions Limited:561833330:B8C23D12G32M64T2Y0:T:0:0:0:0:0:15680:9018:12290:0
ADULT Filth;RHF Productions Limited:561833330:B8C23D12G32M64T2Y0:T:0:0:0:0:0:15728:9018:12290:0
Smash Hits!;Bauer:537833330:B8C34D34G32M16T2Y0:T:0:0:1501=eng@4:0:0:27040:9018:24576:0
ADULT PARTY;Square1 Management Ltd:578166670:B8C34D34G32M16T2Y0:T:0:0:0:0:0:24256:9018:20480:0
ITV Preview 1;ITV Broadcasting:561833330:B8C23D12G32M64T2Y0:T:0:0:0:0:0:15984:9018:12290:0
CNN;Turner:578166670:B8C34D34G32M16T2Y0:T:0:0:0:0:0:24192:9018:20480:0
Absolute Radio;TIML Radio Ltd:561833330:B8C23D12G32M64T2Y0:T:0:0:6082=eng@4:0:0:14688:9018:12290:0
Heart;Global Radio:561833330:B8C23D12G32M64T2Y0:T:0:0:6098=eng@4:0:0:14720:9018:12290:0
Capital;Global Radio:561833330:B8C23D12G32M64T2Y0:T:0:0:6114=eng@4:0:0:14752:9018:12290:0
</pre></p>
<p><strong>Configuring Lirc for Terratec remote control use</strong></p>
<p>Edit /etc/lirc/hardware.conf</p>
<p>and fill with following content</p>
<p><pre class="brush: bash;">
REMOTE=&quot;Custom&quot;
REMOTE_MODULES=&quot;&quot;
REMOTE_DRIVER=&quot;devinput&quot;
# Next 2 lines will work as long as you have just 1 remote
#Both the event and the by-path value can change so this way works fine
#TEMPIREVENT=`ls /dev/input/by-path/ |grep event-ir`
REMOTE_DEVICE=&quot;/dev/input/event4&quot;
#REMOTE_DEVICE=&quot;/dev/input/by-id&quot;
REMOTE_LIRCD_CONF=&quot;/etc/lircd.conf&quot;
REMOTE_LIRCD_ARGS=&quot;&quot;
TRANSMITTER=&quot;Command IR : Direct TV Receiver&quot;
TRANSMITTER_MODULES=&quot;lirc_dev lirc_cmdir&quot;
TRANSMITTER_DRIVER=&quot;&quot;
TRANSMITTER_DEVICE=&quot;/dev/lirc0&quot;
TRANSMITTER_LIRCD_CONF=&quot;directtv/general.conf&quot;
TRANSMITTER_LIRCD_ARGS=&quot;&quot;
START_LIRCD=&quot;true&quot;
START_LIRCMD=&quot;&quot;
LOAD_MODULES=&quot;&quot;
LIRCMD_CONF=&quot;&quot;
FORCE_NONINTERACTIVE_RECONFIGURATION=&quot;false&quot;
REMOTE_SOCKET=&quot;&quot;
TRANSMITTER_SOCKET=&quot;&quot;
</pre></p>
<p>Edit /etc/lirc/lircd.conf</p>
<p>and fill with content</p>
<p><pre class="brush: bash;">
# Please make this file available to others
# by sending it to 
#
# this config file was automatically generated
# using lirc-0.8.4a(devinput) on Sun Nov  1 19:20:22 2009
#
# contributed by
#
# brand:                       Terratec
# model no. of remote control:
# devices being controlled by this remote:
#

begin remote

 name  TerraTec_Cinergy_1400
 bits           16
 eps            30
 aeps          100

 one             0     0
 zero            0     0
 pre_data_bits   16
 pre_data       0x8001
 gap          135994
 toggle_bit_mask 0x80010160

 begin codes
 Power                    0x0074
 0                        0x000B
 1                        0x0002
 2                        0x0003
 3                        0x0004
 4                        0x0005
 5                        0x0006
 6                        0x0007
 7                        0x0008
 8                        0x0009
 9                        0x000A
 Up                       0x0067
 Left                     0x0069
 Right                    0x006A
 Down                     0x006C
 Mute                     0x0071
 VolumeDown               0x0072
 VolumeUp                 0x0073
 Pause                    0x0077
 Stop                     0x0080
 Record                   0x00A7
 Refresh                  0x00AD
 Play                     0x00CF
 Ok                       0x0160
 OSD                      0x0161
 Info                     0x0166
 EPG                      0x016D
 Text                     0x0184
 Video                    0x0189
 RED                      0x018E
 GREEN                    0x018F
 YELLOW                   0x0190
 BLUE                     0x0191
 ChannelUp                0x0192
 ChannelDown              0x0193
 Next                     0x0197
 Previous                 0x019C
 end codes

end remote
</pre></p>
<p>Edit ~/.xbmc/userdata/Lircmap.xml</p>
<p>and fill with content</p>
<p><pre class="brush: xml;">
&lt;lircmap&gt;
       &lt;remote device=&quot;TerraTec_Cinergy_1400&quot;&gt;
               &lt;left&gt;ArrowLeft&lt;/left&gt;
               &lt;right&gt;ArrowRight&lt;/right&gt;
               &lt;up&gt;ArrowUp&lt;/up&gt;
               &lt;down&gt;ArrowDown&lt;/down&gt;
               &lt;select&gt;OK&lt;/select&gt;
               &lt;back&gt;Refresh&lt;/back&gt;
               &lt;menu&gt;OSD&lt;/menu&gt;
               &lt;info&gt;Info&lt;/info&gt;
               &lt;display&gt;Text&lt;/display&gt;
               &lt;title&gt;EPG&lt;/title&gt;
               &lt;play&gt;Play&lt;/play&gt;
               &lt;pause&gt;Pause&lt;/pause&gt;
               &lt;reverse&gt;Previous&lt;/reverse&gt;
               &lt;forward&gt;Next&lt;/forward&gt;
               &lt;stop&gt;Stop&lt;/stop&gt;
			   &lt;zero&gt;0&lt;/zero&gt;
               &lt;one&gt;1&lt;/one&gt;
               &lt;two&gt;2&lt;/two&gt;
               &lt;three&gt;3&lt;/three&gt;
               &lt;four&gt;4&lt;/four&gt;
               &lt;five&gt;5&lt;/five&gt;
               &lt;six&gt;6&lt;/six&gt;
               &lt;seven&gt;7&lt;/seven&gt;
               &lt;eight&gt;8&lt;/eight&gt;
               &lt;nine&gt;9&lt;/nine&gt;
               &lt;power&gt;Power&lt;/power&gt;
               &lt;record&gt;Record&lt;/record&gt;
               &lt;volumeplus&gt;VolumeUp&lt;/volumeplus&gt;
               &lt;volumeminus&gt;VolumeDown&lt;/volumeminus&gt;
               &lt;skipplus&gt;ChannelUp&lt;/skipplus&gt;
               &lt;skipminus&gt;ChannelDown&lt;/skipminus&gt;
               &lt;mute&gt;Mute&lt;/mute&gt;
               &lt;myTV&gt;Red&lt;/myTV&gt;
               &lt;mymusic&gt;Green&lt;/mymusic&gt;
               &lt;mypictures&gt;Yellow&lt;/mypictures&gt;
               &lt;myvideo&gt;Blue&lt;/myvideo&gt;
       &lt;/remote&gt;
  &lt;/lircmap&gt;
</pre></p>
<p>Restart lirc, xbmc, gdm (or restart the computer).</p>
<p><strong>Configuring XBMC</strong></p>
<p>Use the remote (if REMOTE_DEVICE=&#8221;/dev/input/event4&#8243; is correct) to go in the settings and enble addons &gt; PVR &gt; VDR</p>
<p>In Settings &gt; Add-Ons &gt; Installed Add-ons<br />
Select VDR VNSI Client and enable it:<br />
<a href="http://tgoirand.files.wordpress.com/2010/12/2011-04-29_1280x720.png"><img src="http://tgoirand.files.wordpress.com/2010/12/2011-04-29_1280x720.png?w=530&#038;h=298" alt="" title="VNSI Client plugin" width="530" height="298" class="aligncenter size-full wp-image-238" /></a></p>
<p>Now select Settings &gt; Live TV (if you haven&#8217;t got this menu, something went wrong) and check &#8220;enabled&#8221;<br />
<a href="http://tgoirand.files.wordpress.com/2010/12/2011-04-29_1280x7201.png"><img src="http://tgoirand.files.wordpress.com/2010/12/2011-04-29_1280x7201.png?w=530&#038;h=298" alt="" title="Live TV Settings" width="530" height="298" class="aligncenter size-full wp-image-239" /></a></p>
<p>You should get a new menu in the home window.</p>
<p>Eventually configure everything you want using the <a href="http://wiki.xbmc.org/?title=XBMC_Online_Manual" title="XBMC online manual">XBMC online guide</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tgoirand.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tgoirand.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tgoirand.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tgoirand.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tgoirand.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tgoirand.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tgoirand.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tgoirand.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tgoirand.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tgoirand.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tgoirand.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tgoirand.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tgoirand.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tgoirand.wordpress.com/176/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=176&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tgoirand.wordpress.com/2010/12/04/vdr-xbmc-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e717c8fdbabaaa4c45779202ca0ce05?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tgoirand</media:title>
		</media:content>

		<media:content url="http://tgoirand.files.wordpress.com/2010/12/2011-04-29_1280x7202.png" medium="image">
			<media:title type="html">2011-04-29_1280x720</media:title>
		</media:content>

		<media:content url="http://tgoirand.files.wordpress.com/2010/12/settings.png" medium="image">
			<media:title type="html">XBMC video menu</media:title>
		</media:content>

		<media:content url="http://tgoirand.files.wordpress.com/2010/12/tv1.png" medium="image">
			<media:title type="html">Live TV menu</media:title>
		</media:content>

		<media:content url="http://tgoirand.files.wordpress.com/2010/12/2011-04-29_1280x7204.png" medium="image">
			<media:title type="html">TV</media:title>
		</media:content>

		<media:content url="http://tgoirand.files.wordpress.com/2010/12/2011-04-29_1280x7203.png" medium="image">
			<media:title type="html">EPG</media:title>
		</media:content>

		<media:content url="http://tgoirand.files.wordpress.com/2010/12/2011-04-29_1280x720.png" medium="image">
			<media:title type="html">VNSI Client plugin</media:title>
		</media:content>

		<media:content url="http://tgoirand.files.wordpress.com/2010/12/2011-04-29_1280x7201.png" medium="image">
			<media:title type="html">Live TV Settings</media:title>
		</media:content>
	</item>
		<item>
		<title>An Java exercise: different trains&#8230;</title>
		<link>http://tgoirand.wordpress.com/2010/12/02/another-music-different-trains/</link>
		<comments>http://tgoirand.wordpress.com/2010/12/02/another-music-different-trains/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 20:05:02 +0000</pubDate>
		<dc:creator>Thomas Goirand</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://tgoirand.wordpress.com/?p=171</guid>
		<description><![CDATA[The other day a chap sent me a problem to solve. First, It sounded rather straight forward but as the exercice has gone by, I noticed some contradictions. Take a look at the following, it might help. Problem: The local commuter railroad services a number of towns in Kiwiland. Because of monetary concerns, all of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=171&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The other day a chap sent me a problem to solve.<br />
First, It sounded rather straight forward but as the exercice has gone by, I noticed some contradictions.<br />
Take a look at the following, it might help.</p>
<p><strong>Problem</strong>:<br />
The local commuter railroad services a number of towns in Kiwiland. Because of monetary concerns, all of the tracks are ‘one-way.’ That is, a route from Kaitaia to Invercargill does not imply the existence of a route from Invercargill to Kaitaia. In fact, even if both of these routes do happen to exist, they are distinct and are not necessarily the same distance!</p>
<p>The purpose of this problem is to help the railroad provide its customers with information about the routes. In particular, you will compute the distance along a certain route, the number of different routes between two towns, and the shortest route between two towns.Input: A directed graph where a node represents a town and an edge represents a route between two towns. The weighting of the edge represents the distance between the two towns. <span style="color:#ff0000;">A given route will never appear more than once, and for a given route, the starting and ending town will not be the same town.</span></p>
<p><strong>Input: </strong><br />
A directed graph where a node represents a town and an edge represents a route between two towns. The weighting of the edge represents the distance between the two towns. A given route will never appear more than once, and for a given route, the starting and ending town will not be the same town.</p>
<p>I started then a program in Java to calculate the routes of the first outputs:</p>
<p><strong>Output</strong>:</p>
<p>For test input 1 through 5, if no such route exists, output ‘NO SUCH ROUTE’. Otherwise, follow the route as given; do not make any extra stops!<br />
For example, the first problem means to start at city A, then travel directly to city B (a distance of 5), then directly to city C (a distance of 4).</p>
<p>1. The distance of the route A-B-C.<br />
2. The distance of the route A-D.<br />
3. The distance of the route A-D-C.<br />
4. The distance of the route A-E-B-C-D.<br />
5. The distance of the route A-E-D.<br />
6. The number of trips starting at C and ending at C with a maximum of 3 stops. In the sample data below, there are two such trips: C-D-C (2 stops). and C-E-B-C (3 stops).<br />
7. The number of trips starting at A and ending at C with exactly 4 stops. In the sample data below, there are three such trips: A to C (via B,C,D); A to C (via D,C,D); and A to C (via D,E,B).<br />
8. The length of the shortest route (in terms of distance to travel) from A to C.<br />
<span style="color:#ff0000;"><span style="color:#000000;">9. The length of</span> the shortest route (in terms of distance to travel) from B to B.</span><br />
10. The number of <span style="color:#ff0000;">different routes from C to C</span> with a distance of less than 30. In the sample data, the trips are: CDC, CEBC, CEBCDC, CDCEBC, CDEBC, CEBCEBC, CEBCEBCEBC.</p>
<p>I realized then, I had to program some algorithm in contradiction with the problem details (in red). Very well thought work!</p>
<p>For those who are interested by the source code, it is working fine for all the outputs and can be downloaded on Github:<br />
<a title="Thoughtworks" href="https://github.com/tgoirand/TRAINS" target="_blank">https://github.com/tgoirand/TRAINS<br />
</a>Unfortunately I don&#8217;t think the design is smart and it would might be cleverer to implement an Iterator to generate different routes</p>
<p>Hope it will help!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tgoirand.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tgoirand.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tgoirand.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tgoirand.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tgoirand.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tgoirand.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tgoirand.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tgoirand.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tgoirand.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tgoirand.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tgoirand.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tgoirand.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tgoirand.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tgoirand.wordpress.com/171/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=171&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tgoirand.wordpress.com/2010/12/02/another-music-different-trains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e717c8fdbabaaa4c45779202ca0ce05?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tgoirand</media:title>
		</media:content>
	</item>
		<item>
		<title>[Alfresco] Swing beanshell console</title>
		<link>http://tgoirand.wordpress.com/2010/10/21/alfresco-swing-beanshell-console/</link>
		<comments>http://tgoirand.wordpress.com/2010/10/21/alfresco-swing-beanshell-console/#comments</comments>
		<pubDate>Thu, 21 Oct 2010 07:51:13 +0000</pubDate>
		<dc:creator>Thomas Goirand</dc:creator>
				<category><![CDATA[Alfresco]]></category>
		<category><![CDATA[Beanshell]]></category>

		<guid isPermaLink="false">http://tgoirand.wordpress.com/?p=154</guid>
		<description><![CDATA[The Swing beanshell console can be useful to execute commands against a running instance of the repository. I&#8217;ve created an AMP extension to enable it within Alfresco: - Download the AMP file from Forge http://forge.alfresco.com/frs/download.php/1043/bsh-console.amp - Drop de the module in your amps folder and execute ./apply_amps.sh - Start Alfresco You&#8217;ll find a shell which [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=154&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The Swing beanshell console can be useful to execute commands against a running instance of the repository.</p>
<p>I&#8217;ve created an AMP extension to enable it within Alfresco:</p>
<p>- Download the AMP file from Forge</p>
<p><a title="Swing Console" href="http://forge.alfresco.com/frs/download.php/1043/bsh-console.amp">http://forge.alfresco.com/frs/download.php/1043/bsh-console.amp</a></p>
<p>- Drop de the module in your amps folder and execute ./apply_amps.sh</p>
<p>- Start Alfresco<a href="http://tgoirand.files.wordpress.com/2010/10/capture-d_ecran-2010-08-08-a-22-32-51.png"><br />
</a>You&#8217;ll find a shell which accepts the beanshell commands:</p>
<p><a href="http://www.beanshell.org/manual/syntax.html#Basic_Syntax">http://www.beanshell.org/manual/syntax.html#Basic_Syntax</a></p>
<p>Alfresco Foundation API can be access through the special variable</p>
<p>bsh.system.serviceRegistry  e.g.</p>
<p><pre class="brush: java;">
org.alfresco.service.ServiceRegistry serviceRegistry = bsh.system.serviceRegistry;

import java.util.*;
import org.alfresco.service.cmr.security.*;
import org.alfresco.service.namespace.*;
import org.alfresco.service.cmr.repository.*;
import org.alfresco.model.*;
import org.alfresco.service.cmr.security.*;
import org.alfresco.util.*;

serviceRegistry.getAuthenticationService().authenticate(&quot;admin&quot;, &quot;admin&quot;.toCharArray()); // need to authenticate

PersonService personService = serviceRegistry.getPersonService();
org.alfresco.util.PropertyMap personProps = new org.alfresco.util.PropertyMap();
personProps.put(ContentModel.PROP_USERNAME, &quot;tom&quot;);
personProps.put(ContentModel.PROP_FIRSTNAME, &quot;Thomas&quot;);
personProps.put(ContentModel.PROP_LASTNAME, &quot;Goirand&quot;);
personProps.put(ContentModel.PROP_EMAIL, &quot;tgoirand+blog@gmail.com&quot;);

personService.createPerson(personProps);
</pre></p>
<p><a href="http://tgoirand.files.wordpress.com/2010/10/capture-d_ecran-2010-10-21-a-08-42-03.png"><img class="aligncenter size-full wp-image-156" title="Create User" src="http://tgoirand.files.wordpress.com/2010/10/capture-d_ecran-2010-10-21-a-08-42-03.png?w=530" alt=""   /></a> The user should be created and its properties can be listed using standard Foundation API code</p>
<p><pre class="brush: java;">
NodeRef person = personService.getPerson(&quot;tom&quot;);
NodeService nodeService = serviceRegistry.getNodeService();

Map props = nodeService.getProperties(person);
for (Iterator it2 = props.keySet().iterator(); it2.hasNext(); ) {
 QName key = (QName)it2.next();
 print(key + &quot;=&gt;\t&quot; + props.get(key));
}
</pre></p>
<p><a href="http://tgoirand.files.wordpress.com/2010/10/capture-d_ecran-2010-10-21-a-08-44-56.png"><img class="aligncenter size-full wp-image-157" title="List user properties" src="http://tgoirand.files.wordpress.com/2010/10/capture-d_ecran-2010-10-21-a-08-44-56.png?w=530" alt=""   /></a></p>
<p>Known bug: Too many lines pasted into the console can make it freeze <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>To disable the console, comment out the bean defined in</p>
<p>tomcat/webapps/alfresco/WEB-INF/classes/alfresco/module/bshConsole/context/service-context.xml</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tgoirand.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tgoirand.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tgoirand.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tgoirand.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tgoirand.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tgoirand.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tgoirand.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tgoirand.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tgoirand.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tgoirand.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tgoirand.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tgoirand.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tgoirand.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tgoirand.wordpress.com/154/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=154&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tgoirand.wordpress.com/2010/10/21/alfresco-swing-beanshell-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e717c8fdbabaaa4c45779202ca0ce05?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tgoirand</media:title>
		</media:content>

		<media:content url="http://tgoirand.files.wordpress.com/2010/10/capture-d_ecran-2010-10-21-a-08-42-03.png" medium="image">
			<media:title type="html">Create User</media:title>
		</media:content>

		<media:content url="http://tgoirand.files.wordpress.com/2010/10/capture-d_ecran-2010-10-21-a-08-44-56.png" medium="image">
			<media:title type="html">List user properties</media:title>
		</media:content>
	</item>
		<item>
		<title>[Alfresco] Remove duplicated users</title>
		<link>http://tgoirand.wordpress.com/2010/10/20/alfresco-remove-duplicate-users/</link>
		<comments>http://tgoirand.wordpress.com/2010/10/20/alfresco-remove-duplicate-users/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 09:12:05 +0000</pubDate>
		<dc:creator>Thomas Goirand</dc:creator>
				<category><![CDATA[Alfresco]]></category>

		<guid isPermaLink="false">http://tgoirand.wordpress.com/?p=150</guid>
		<description><![CDATA[If you have duplicated users in your repository, you&#8217;ll find here a script to remove them easily. It has been tested against Alfresco 2.2 SP5. It may work with further version though. To install the script (linux/mac only), copy the following content in a file in the same folder than alfresco.sh. You can also download [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=150&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you have duplicated users in your repository, you&#8217;ll find here a script to remove them easily. It has been tested against Alfresco 2.2 SP5. It may work with further version though.</p>
<p>To install the script (linux/mac only), copy the following content in a file in the same folder than alfresco.sh. You can also download the file on forge: <a href="http://forge.alfresco.com/frs/?group_id=226">http://forge.alfresco.com/frs/?group_id=226</a></p>
<p>Don&#8217;t forget to change admin user and password.</p>
<p>set executing permissions and execute it.</p>
<p>A problem You might find a better option to remove duplicate users that remain in the repository than this script (in fixing LDAP issues). This one has been tested against 2.2.5 only but maybe work against 3.* as well.</p>
<p><pre class="brush: bash;">
#!/bin/bash
## Copyright (C) 2009 Thomas Goirand
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
## INSTALL
## Copy this file in the Alfresco root repository and execute it.
## TOMCAT MUST BE NOT RUNNING.
##
## Author: tgoirand@gmail.com

# set Alfresco admin credentials
# admin username
ALF_USERNAME=admin
# admin password
ALF_PASSWORD=admin

# set the alfresco webapp path
ALFRESCO_WEBAPP=tomcat/webapps/alfresco
# set the extention shared path
EXTENSION_PATH=tomcat/shared/classes
# Directory containing db drivers and servlet-api.jar for 3.3.1
EXTRA_LIB=tomcat/lib

if [ ! -d $ALFRESCO_WEBAPP ] ; then
 echo &quot;Webapp: ${ALFRESCO_WEBAPP} not found. Exit.&quot;
 exit
fi

if [ ! -d $EXTRA_LIB ] ; then
 echo &quot;$EXTRA_LIB not found...&quot;
 EXTRA_LIB=tomcat/shared/lib
 echo &quot;...trying $EXTRA_LIB&quot;
fi

# Following only needed for Sun JVMs before to 1.5 update 8
export JAVA_OPTS='-Xms512m -Xmx1024m -Xss1024k -XX:MaxPermSize=256m -XX:NewSize=256m'
echo &quot;Starting beanshell...&quot;

WEBINFLIB=${ALFRESCO_WEBAPP}/WEB-INF/lib
#MODULEPATH=${ALFRESCO_WEBAPP}/WEB-INF/classes/alfresco/module
CLASSESDIRPATH=${ALFRESCO_WEBAPP}/WEB-INF/classes

CLASSPATH=${WEBINFLIB}:${MODULEPATH}:${CLASSESDIRPATH}:${EXTENSION_PATH}

if [ -d $EXTRA_LIB ] ; then
 for EXTRA_JARNAME in $( ls ${EXTRA_LIB} )
 do
 CLASSPATH=${CLASSPATH}:${EXTRA_LIB}/${EXTRA_JARNAME}
 done
else
 echo &quot;$EXTRA_LIB not found.&quot;
fi

for JARNAME in $( ls ${WEBINFLIB} )
do
 CLASSPATH=${CLASSPATH}:${WEBINFLIB}/${JARNAME}
done

java ${JAVA_OPTS} -classpath ${CLASSPATH} bsh.Interpreter &lt;&lt;EOF
print (&quot;Loading context... can take a little while...&quot;);
import java.io.*;
import java.util.*;
import javax.transaction.*;
import org.alfresco.error.*;
import org.alfresco.model.*;
import org.alfresco.repo.security.permissions.*;
import org.alfresco.service.*;
import org.alfresco.service.cmr.repository.*;
import org.alfresco.service.cmr.search.*;
import org.alfresco.service.cmr.security.*;
import org.alfresco.service.namespace.*;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.util.ApplicationContextHelper;
import org.safehaus.uuid.UUID;
import org.springframework.context.ApplicationContext;
import org.alfresco.service.cmr.security.AuthorityService;
import org.hibernate.*;

org.springframework.context.ApplicationContext ctx = org.alfresco.util.ApplicationContextHelper.getApplicationContext();
org.alfresco.service.ServiceRegistry serviceRegistry = (org.alfresco.service.ServiceRegistry) ctx.getBean(org.alfresco.service.ServiceRegistry.SERVICE_REGISTRY);
serviceRegistry.getAuthenticationService().authenticate(&quot;${ALF_USERNAME}&quot;, &quot;${ALF_PASSWORD}&quot;.toCharArray());

SearchService searchService = serviceRegistry.getSearchService();
NodeService nodeService = serviceRegistry.getNodeService();
AuthorityService pubAuthorityService = (AuthorityService) ctx.getBean(&quot;AuthorityService&quot;);
PermissionServiceSPI permissionService = (PermissionServiceSPI) ctx.getBean(&quot;permissionServiceImpl&quot;);
PersonService personService = serviceRegistry.getPersonService();
AuthorityService authorithyService = serviceRegistry.getAuthorityService();

SessionFactory sessionFactory = ctx.getBean(&quot;sessionFactory&quot;);
Session session = org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(sessionFactory, true);

void delete(NodeRef nr) {
 print(&quot;delete:&quot; + nr);
 tx = session.beginTransaction();
 nodeService.deleteNode(nr);
/*    Set containerAuthorities = authorithyService.getContainingAuthorities(null, nr, true);
 for (Iterator it = containerAuthorities.iterator(); it.hasNext(); )    {
 authorithyService.removeAuthority(containerAuthority, uidNodeRef.uid);
 }
 // remove any user permissions
 permissionService.deletePermissions(nr);*/
 tx.commit();
}

Set nodeRefs = personService.getAllPeople();
Map dbIdref = new TreeMap();
Map nodeRefref = new TreeMap();

for (Iterator itPeople = nodeRefs.iterator(); itPeople.hasNext(); ) {
 NodeRef person = (NodeRef)itPeople.next();
 Map props = nodeService.getProperties(person);

 Long dbId = (Long)props.get(QName.createQName(&quot;{http://www.alfresco.org/model/system/1.0}node-dbid&quot;));
 String userName = props.get(QName.createQName(&quot;{http://www.alfresco.org/model/content/1.0}userName&quot;));

 if (dbIdref.containsKey(userName)) {
 print(&quot;duplicate found:&quot; + userName + &quot;:&quot; + dbIdref.get(userName) + &quot;:&quot; + dbId);
 if (dbIdref.get(userName) &gt; dbId) { // keeping the older
 delete((NodeRef)nodeRefref.get(userName));
 dbIdref.remove(userName);
 nodeRefref.remove(userName);

 dbIdref.put(userName, dbId); // can't use a Set with a bean, buggy the beanshell.
 nodeRefref.put(userName, person);
 } else {
 delete(person);
 }

 } else {
 dbIdref.put(userName, dbId); // can't use a Set with a bean, buggy the beanshell.
 nodeRefref.put(userName, person);
 }
}

EOF

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tgoirand.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tgoirand.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tgoirand.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tgoirand.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tgoirand.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tgoirand.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tgoirand.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tgoirand.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tgoirand.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tgoirand.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tgoirand.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tgoirand.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tgoirand.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tgoirand.wordpress.com/150/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=150&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tgoirand.wordpress.com/2010/10/20/alfresco-remove-duplicate-users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e717c8fdbabaaa4c45779202ca0ce05?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tgoirand</media:title>
		</media:content>
	</item>
		<item>
		<title>[Alfresco] Reindexing a single node</title>
		<link>http://tgoirand.wordpress.com/2010/10/04/alfresco-reindexing-a-single-node/</link>
		<comments>http://tgoirand.wordpress.com/2010/10/04/alfresco-reindexing-a-single-node/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 15:31:17 +0000</pubDate>
		<dc:creator>Thomas Goirand</dc:creator>
				<category><![CDATA[Alfresco]]></category>
		<category><![CDATA[Beanshell]]></category>

		<guid isPermaLink="false">http://tgoirand.wordpress.com/?p=138</guid>
		<description><![CDATA[An easy way to get a node re-indexed in Alfresco is to modify or rename it. But if you can&#8217;t, you might want to use with caution the following tip. Tested against Alfresco 2.2SP5 only.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=138&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>An easy way to get a node re-indexed in Alfresco is to modify or rename it. But if you can&#8217;t, you might want to use with caution the following tip.</p>
<p>Tested against Alfresco 2.2SP5 only.</p>
<p><pre class="brush: java;">

import org.alfresco.service.transaction.TransactionService;
import org.hibernate.*;

String nodeToReindex = &quot;workspace://SpacesStore/f5518f16-01cc-48ad-b54f-33ccc3123237&quot;;

org.springframework.context.ApplicationContext ctx = org.alfresco.util.ApplicationContextHelper.getApplicationContext();
org.alfresco.service.ServiceRegistry serviceRegistry = (org.alfresco.service.ServiceRegistry) ctx.getBean(org.alfresco.service.ServiceRegistry.SERVICE_REGISTRY);
org.alfresco.repo.search.IndexerAndSearcher indexerAndSearcher = (org.alfresco.repo.search.IndexerAndSearcher)ctx.getBean(&quot;indexerAndSearcherFactory&quot;);
TransactionService transactionService = serviceRegistry.getTransactionService();
javax.transaction.UserTransaction ut = transactionService.getUserTransaction();

org.alfresco.service.cmr.repository.NodeRef noderef = new org.alfresco.service.cmr.repository.NodeRef(nodeToReindex);

ut.begin();
org.alfresco.repo.search.Indexer indexer = indexerAndSearcher.getIndexer(org.alfresco.service.cmr.repository.StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
indexer.updateNode(noderef);
ut.commit();

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tgoirand.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tgoirand.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tgoirand.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tgoirand.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tgoirand.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tgoirand.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tgoirand.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tgoirand.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tgoirand.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tgoirand.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tgoirand.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tgoirand.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tgoirand.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tgoirand.wordpress.com/138/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tgoirand.wordpress.com&amp;blog=11862326&amp;post=138&amp;subd=tgoirand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tgoirand.wordpress.com/2010/10/04/alfresco-reindexing-a-single-node/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e717c8fdbabaaa4c45779202ca0ce05?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tgoirand</media:title>
		</media:content>
	</item>
	</channel>
</rss>
