<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4788606468171792208</id><updated>2012-03-05T21:51:42.975+01:00</updated><category term='apache'/><category term='linux'/><category term='xml'/><category term='ant'/><category term='postgresql'/><category term='libreoffice'/><category term='javascript'/><category term='java'/><category term='mysql'/><category term='openatrium'/><category term='php'/><category term='tcltk'/><category term='C'/><category term='beanshell'/><category term='notícies'/><category term='.Net'/><category term='sqlite'/><category term='ooobasic'/><category term='bash'/><category term='firebird'/><category term='flex'/><category term='tecnologies'/><category term='oracle'/><category term='eines'/><category term='seguretat'/><category term='c#'/><category term='llibreries'/><category term='lazarus'/><category term='esdeveniments'/><category term='glade'/><category term='excel'/><category term='python'/><category term='groovy'/><category term='programari lliure'/><category term='gambas2'/><category term='html'/><category term='gimp'/><category term='mono'/><category term='hardware'/><category term='openoffice.org'/><category term='trucs'/><title type='text'>Apunts de Tecnologia</title><subtitle type='html'>El Bloc de Serveis TIC i Programari Lliure - STICiPL</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://apuntstecnologia.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://apuntstecnologia.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Serveis Tecnològics i Programari Lliure</name><uri>http://www.blogger.com/profile/12434522547196735270</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>93</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4788606468171792208.post-1567314631542213086</id><published>2012-03-05T21:16:00.000+01:00</published><updated>2012-03-05T21:51:42.995+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tecnologies'/><category scheme='http://www.blogger.com/atom/ns#' term='programari lliure'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='esdeveniments'/><title type='text'>Els vídeotutorials de la deSymfony 2011</title><content type='html'>PHP és un dels llenguatges més populars per a desenvolupar aplicacions i llocs web. La creació de llocs web acostuma a enfocar-se com la tria d'un gestor de continguts que ens proporcioni un sistema amistós &amp;nbsp;per a fer pàgines i organitzar-les, i sense haver de preocupar-nos de detalls de baix nivell. En molts casos, ens permeten desenvolupar el lloc sense ni haver de conèixer PHP. Parlo, per exemple de Drupal i derivats, com OpenAtrium, &amp;nbsp;o Joomla!... &lt;a href="http://en.wikipedia.org/wiki/List_of_content_management_systems#PHP"&gt;N'hi han molts.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Els Gestors de Contingut són extraordinàriament útils justament per al que estan fets: crear, mantenir, organitzar continguts, documents, imatges; organitzar-ne l'accés dels usuaris; llistes de correu; fòrums... tot allò per al que existeixi un mòdul disponible o que es pugui connectar al CMS i que no calgui modificar més enllà de les possibilitats de parametrització que ofereixi. &lt;br /&gt;&lt;br /&gt;El problema ve quan els requeriments de l'aplicació web ja no són els relacionats amb la gestió de continguts. En aquest moment, el CMS ja no és útil, o només ho és marginalment. Aleshores cal atacar el desenvolupament de l'aplicació web d'una altre forma. Per descomptat que es pot encarar la construcció d'un lloc web creant des de zero, "from scratch", &amp;nbsp;totes les pàgines del lloc.&lt;br /&gt;&lt;br /&gt;Però en aquest cas segur que ens trobaríem que hem de reinventar la roda contínuament. Un &amp;nbsp;enfoc més pràctic &amp;nbsp;seria utilitzar un framework que ens proporcionés unes llibreries, una arquitectura, una estructura i unes capes i patrons ben definits per a desenvolupar el lloc. Encara serem nosaltres els responsables d'escriure les pàgines amb PHP i desenvolupar-ne els requeriments funcionals. Però ja no caldrà que reinventem la roda.&lt;br /&gt;&lt;br /&gt;Estic parlant de frameworks com poden ser &lt;a href="http://www.springsource.org/"&gt;Spring&lt;/a&gt;, &lt;a href="http://rubyonrails.org/"&gt;Ruby on Rails&lt;/a&gt;, &amp;nbsp;&lt;a href="http://www.asp.net/mvc"&gt;ASP MVC&lt;/a&gt;... Tots ells es basen en el &lt;a href="http://en.wikipedia.org/wiki/Architectural_pattern"&gt;patró d'arquitectura&lt;/a&gt; &lt;a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller"&gt;MVC (Model View Controller)&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://en.wikipedia.org/wiki/Symfony"&gt;Symfony&lt;/a&gt; és un dels framework MVC més populars per al llenguatge PHP.&lt;br /&gt;&lt;br /&gt;Per a conèixer-lo millor podem revisar aquesta col·lecció de vídeos i tutorials que es van realitzar durant les jornades &lt;a href="http://desymfony.com/2011/"&gt;deSymfony 2011&lt;/a&gt; a la Universitat Jaume I de Castelló, els passats 1,2 i 3 de juliol de 2011. Es tracta d'una recopilació excepcional que ens pot ajudar &amp;nbsp;molt en la tasca d'iniciar-nos en l'ús de Symfony.&lt;br /&gt;&lt;br /&gt;La DeSymphony és la major conferència sobre Symfony en castellà i la segona del món, en valor absolut, després de la Symfony Live que és la conferència oficial de Symfony.&lt;br /&gt;&lt;br /&gt;Per a enguany també està prevista la celebració de jornades: la&amp;nbsp;&lt;a href="http://desymfony.com/"&gt;deSymfony 2012&amp;nbsp;&lt;/a&gt;&amp;nbsp;els dies 15 i 16 de juny, a Castelló.&lt;br /&gt;&lt;br /&gt;Tots els enllaços estan presos de la pàgina&amp;nbsp;&lt;a href="http://www.symfony.es/2011/07/06/desymfony-2011-todos-los-videos-y-presentaciones/"&gt;http://www.symfony.es/2011/07/06/desymfony-2011-todos-los-videos-y-presentaciones/&lt;/a&gt;. Els reprodueixo a continuació:&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;Els enllaços porten a les pàgines respectives de symfony.es, a les que està encastat el vídeo corresponent. Els vídeos estan allotjats a vimeo.&lt;br /&gt;&lt;br /&gt;Vet aquí els enllaços:&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Primer dia&lt;/strong&gt; (1 de juliol de 2011):&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony-2011-instalacion-y-primeros-pasos/"&gt;Introducción a Symfony2 + Tutorial #1: Instalación y primeros pasos&lt;/a&gt;, Javier Eguiluz&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony-2011-el-modelo-y-doctrine2/"&gt;Tutorial #2: El modelo. Doctrine2&lt;/a&gt;, Nacho Martín&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony2011-la-vista-twig/"&gt;Tutorial #3: La vista. Twig&lt;/a&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony2011-la-vista-twig/"&gt;,&lt;/a&gt; Marcos Labad&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony2011-formularios-y-seguridad/"&gt;Tutorial #4: Formularios y Seguridad&lt;/a&gt;, Javier López&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony2011-backend/"&gt;Tutorial #5: Backend&lt;/a&gt;, Javier Eguiluz&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony-2011-assetic-y-testing/"&gt;Tutorial #6: Optimización, Assetic y Pruebas unitarias&lt;/a&gt;, Albert Jessurum&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony-2011-mandango-un-odm-ultra-rapido-para-symfony2/"&gt;Mandango, un ODM ultra-rápido para PHP, MongoDB y Symfony2&lt;/a&gt;, Pablo Díez&lt;/li&gt;&lt;/ul&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Segon dia&lt;/strong&gt; (2 de juliol de 2011):&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony-2011-twig-cuando-django-encontro-a-symfony/"&gt;Twig, cuando Django encontró a Symfony&lt;/a&gt;, Javier Eguiluz&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony-2011-symfony-1-mi-viejo-amigo/"&gt;Symfony 1, mi viejo amigo&lt;/a&gt;, José Antonio Pío&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony-2011-microframework-silex/"&gt;Microframework Silex&lt;/a&gt;, Nacho Martín&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony-2011-rendimiento-en-aplicaciones-web-con-symfony2/"&gt;Rendimiento en aplicaciones web con Symfony2&lt;/a&gt;, Asier Marqués&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony-2011-creacion-de-aplicaciones-moviles-con-symfony2/"&gt;Creación de aplicaciones móviles con Symfony2&lt;/a&gt;, Pablo Godel&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony-2011-reduciendo-el-acoplamiento-entre-aplicaciones-con-rabbitmq/"&gt;Reduciendo el acoplamiento entre aplicaciones con RabbitMQ&lt;/a&gt;, Álvaro Videla&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony-2011-symfony-y-3-millones-de-usuarios-nuestro-dia-a-dia/"&gt;Symfony y los 3 millones de usuarios, nuestro día a día&lt;/a&gt;, Jordi Llonch&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony-2011-deja-los-plugins-en-casa-%C2%A1habemus-bundles/"&gt;Deja los plugins en casa, ¡Habemus Bundles!&lt;/a&gt;, Albert Jessurum&lt;/li&gt;&lt;/ul&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Tercer dia&lt;/strong&gt; (3 de juliol de 2011):&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.symfony.es/2011/07/06/desymfony-2011-entorno-de-desarrollo-productivo/"&gt;Entorno de desarrollo productivo&lt;/a&gt;, Pablo Godel&lt;/li&gt;&lt;li&gt;&lt;a href="http://es.scribd.com/fullscreen/59462216?access_key=key-mgrooshtthcrrphh4dv"&gt;Introducción al desarrollo ágil&lt;/a&gt;, Ricardo Borillo&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4788606468171792208-1567314631542213086?l=apuntstecnologia.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apuntstecnologia.blogspot.com/feeds/1567314631542213086/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://apuntstecnologia.blogspot.com/2012/03/els-videotutorials-de-la-desymfony-2011.html#comment-form' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/1567314631542213086'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/1567314631542213086'/><link rel='alternate' type='text/html' href='http://apuntstecnologia.blogspot.com/2012/03/els-videotutorials-de-la-desymfony-2011.html' title='Els vídeotutorials de la deSymfony 2011'/><author><name>Serveis Tecnològics i Programari Lliure</name><uri>http://www.blogger.com/profile/12434522547196735270</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4788606468171792208.post-1174515460726958255</id><published>2012-02-29T23:26:00.003+01:00</published><updated>2012-02-29T23:37:46.128+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tecnologies'/><category scheme='http://www.blogger.com/atom/ns#' term='seguretat'/><category scheme='http://www.blogger.com/atom/ns#' term='programari lliure'/><title type='text'>Criptografia de clau pública amb GnuPG</title><content type='html'>&lt;b&gt;&lt;u&gt;Introducció&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;És molt possible que en alguna ocasió ens hagi sorgit la necessitat d'incrementar la seguretat en les nostres comunicacions per correu electrònic, o garantir l'autoria d'algun document, o la seva integritat.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Aquests són problemes antics i fa temps que se'ls ha donat respostes raonablement satisfactòries. Mai es pot garantir amb certesa absoluta la seguretat de les comunicacions, o l'autoria d'un document o la seva integritat, sobretot per la presència de factors humans. Però per la part del software, almenys es poden posar les coses prou difícils com per a que amb una tecnologia determinada &amp;nbsp;no sigui possible vulnerar la seguretat en un temps finit i raonablement "curt".&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Les comunicacions segures amb organismes oficials o amb entitats financeres passen per l'utilització de certificats digitals. En aquest cas, unes institucions internacionals, les autoritats de certificació, &amp;nbsp;ens proporcionaran, per un preu, uns certificats digitals temporals de caràcter "universal" que vindran avalats per la confiança que hom té arreu del món en aquestes autoritats de certificació.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Aquesta solució que és inevitable seguir quan hom tracta amb organismes oficials, o en solucions de comerç electrònic, pot resultar excessiva, o no gens convenient, quan es tracta de garantir la privacitat personal.&lt;br /&gt;&lt;br /&gt;¿I si volem restringir estrictament la privacitat de les comunicacions entre nosaltres i els nostres interlocutors sense la intervenció de terceres parts i sense que calgui posar-se&amp;nbsp;contínuament&amp;nbsp;d'acord amb passwords o claus secretes?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;GnuPG&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;Una de les eines més populars per a poder fer comunicacions privades segures, signar documents garantint-ne la seva autoria o la seva integritat (que ningú l'ha modificat sense el nostre permís) és el &lt;a href="http://en.wikipedia.org/wiki/Pretty_Good_Privacy"&gt;PGP (Pretty Good Privacy)&lt;/a&gt;. PGP té un equivalent en el programari lliure: el &lt;a href="http://ca.wikipedia.org/wiki/GNU_Privacy_Guard"&gt;GPG o GnuPG &amp;nbsp;(GNU Privacy Guard&lt;/a&gt;).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;A Linux Ubuntu és possible que el tingueu instal·lat per defecte. En tot cas, des del Centre de Programari, o del Synaptic, es pot instal·lar (només cal cercar gpg) sense cap dificultat. Per a màquines Windows es pot instal·lar el &lt;a href="http://www.gpg4win.org/"&gt;Gpg4win&lt;/a&gt; que proporciona el gpg, eines per a gestionar claus, i integració amb l'explorador de windows, o amb Outlook.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Enigmail&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;En el món del programari lliure destacar entre d'altres que GnuPG s'integra amb el gestor de correu &lt;a href="http://www.mozilla.org/ca/thunderbird/"&gt;Mozilla Thunderbird&lt;/a&gt; mitjançant l'addon &lt;a href="http://enigmail.mozdev.org/home/index.php.html"&gt;Enigmail&lt;/a&gt;. &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Documentació&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Si algú vol conèixer detalls en profunditat sobre GnuPG, la referència és &amp;nbsp;&lt;a href="http://www.gnupg.org/documentation/manuals/gnupg/"&gt;Using the GNU Privacy Guard&lt;/a&gt;, també podem consultar &lt;a href="http://www.gnupg.org/gph/en/manual.html"&gt;The GNU Privacy Handbook&lt;/a&gt; (&lt;a href="http://www.gnupg.org/gph/en/manual.pdf"&gt;pdf&lt;/a&gt;), i en general, la &lt;a href="http://www.gnupg.org/documentation/"&gt;pàgina de documentació de GnuPG&lt;/a&gt;.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Criptografia de clau pública&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Prenguem contacte amb GnuPG.&amp;nbsp;Primer de tot, crearé el parell de claus privada i pública sobre el que es construeix la seguretat de la &lt;a href="http://ca.wikipedia.org/wiki/Criptografia_de_clau_p%C3%BAblica"&gt;criptografia de clau pública&lt;/a&gt; de GnuPG. &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;Vet aquí el plantejament de GnuPG:&amp;nbsp;Nosaltres, i ningú més que nosaltres, som els guardians de la nostra clau privada que només coneixem nosaltres. No cal intercanviar cap password amb ningú.&lt;br /&gt;La nostra clau pública, en canvi, la pot conèixer tothom.&lt;br /&gt;&lt;br /&gt;Per a poder enviar un missatge xifrat a algú, ens cal la seva clau pública.&lt;br /&gt;Per a poder dexifrar un missatge adreçat a nosaltres, ens cal la nostra clau privada.&lt;br /&gt;Per a certificar que un missatge l'enviem nosaltres i que no ha estat alterat, el signem amb la nostra clau privada.&lt;br /&gt;Per a verificar que un missatge l'ha enviat qui diu que l'ha enviat el verifiquem amb la clau pública de l'emissor.&lt;br /&gt;Es pot signar (amb la nostra clau privada) i xifrar (amb la clau pública del destinatari) a l'hora un missatge que enviem.&lt;br /&gt;Es pot verificar (amb la clau pública de l'emissor) i dexifrar (amb la nostra clau privada) a l'hora un missatge que rebem.&lt;br /&gt;&lt;br /&gt;Tota l'estona estic parlant de "missatge" i hom podria pensar que em refereixo a missatges de correu electrònic. Però no és el cas. El "missatge" pot ser qualsevol fitxer que rebem per qualsevol via.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Criptografia de clau simètrica&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Tanmateix, GnuPG també permet xifrar missatges mitjançant el sistema d'intercanvi de claus. Aquest sistema és el que es coneix com a &lt;a href="http://ca.wikipedia.org/wiki/Criptografia_sim%C3%A8trica"&gt;criptografia de clau simètrica&lt;/a&gt;. És el que fem servir quan enviem o rebem un zip protegit amb password. Ens han de donar, o hem de donar, la clau per a poder-lo llegir. &lt;br /&gt;&lt;br /&gt;Aleshores, WinZip o GnuPG?&amp;nbsp;No hi ha una avantatge d'un sobre l'altre en quant a l'us de claus simètriques.&amp;nbsp;&amp;nbsp;L'algorisme de xifrat de clau simètrica que fa servir GnuPG per defecte és el &lt;a href="http://en.wikipedia.org/wiki/CAST-128"&gt;CAST5&lt;/a&gt;. Que és superior a l'algorisme de xifrat que emprava originalment WinZip (&lt;a href="http://kb.winzip.com/help/help_encryption.htm"&gt;zip 2.0&lt;/a&gt;). Tanmateix, les versions actuals de WinZIP fan servir l'algorisme de xifrat&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard"&gt;AES&lt;/a&gt;. Una altre eina a tenir en compte és OpenSSL. Es tracta de programari lliure per a, entre moltes d'altres opcions, xifrar i desxifrar missatges fent servir criptografia de clau simètrica.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Criptografia híbrida&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;En realitat, GnuPG combina el xifrat simètric amb el xifrat de clau pública. Els missatges enviats es xifren amb una clau simètrica de sessió (només per a aquell missatge), que a la seva vegada es xifrada amb la clau pública. Tot plegat, missatge i clau, s'empaqueta i s'envia junt. Aleshores el destinatari fa servir la clau privada per desxifrar la clau de sessió i, a continuació, fent servir la clau de sessió, desxifrar el missatge. GnuPG és doncs, de forma més precisa, un esquema de&amp;nbsp;&lt;a href="http://ca.wikipedia.org/wiki/Criptografia_h%C3%ADbrida"&gt;criptografia híbrida&lt;/a&gt;. El motiu de fer-ho així és que és &amp;nbsp;menys costós computacionalment xifrar amb clau simètrica que amb asimètrica.&lt;br /&gt;&lt;br /&gt;El criteri per a usar GnuPG, doncs, és per a emprar l'esquema de criptografia de clau pública en el que no cal intercanviar la clau simètrica. En criptografia de clau simètrica, el moment de l'intercanvi de la clau és el moment en que la comunicació és més vulnerable a un atac. En canvi, en la criptografia de clau pública, la vulnerabilitat depèn de la capacitat que tinguem de mantenir les claus privades en secret.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;El programa gpg&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Anem a tocar l'eina. Acabo d'instal·lar GnuPG amb synaptic.&amp;nbsp;Faig un cop d'ull a les opcions de gpg:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@apolo:~$ gpg --help&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg (GnuPG) 1.4.11&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Copyright (C) 2010 Free Software Foundation, Inc.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;License GPLv3+: GNU GPL version 3 or later &amp;lt;http://gnu.org/licenses/gpl.html&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;This is free software: you are free to change and redistribute it.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;There is NO WARRANTY, to the extent permitted by law.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Home: ~/.gnupg&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Algoritmes suportats:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Clau pública: RSA, RSA-E, RSA-S, ELG-E, DSA&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Xifratge: 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH, CAMELLIA128,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CAMELLIA192, CAMELLIA256&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Dispersió: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Compressió: No comprimit, ZIP, ZLIB, BZIP2&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Sintaxi: gpg [opcions] [fitxers]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;signa, comprova, xifra o desxifra&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;l'operació predeterminada depén de les dades introduïdes&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Ordres:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;-s, --sign [fitxer] &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; crea una signatura&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--clearsign [fitxer] &amp;nbsp; &amp;nbsp; &amp;nbsp;crea una signatura en text clar&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;-b, --detach-sign &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; crea una signatura separada&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;-e, --encrypt &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xifra dades&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;-c, --symmetric &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xifra només amb xifratge simètric&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;-d, --decrypt &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; desxifra dades (predeterminat)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--verify &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;verifica una signatura&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--list-keys &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; llista claus&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--list-sigs &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; llista claus i signatures&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--check-sigs &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;list and check key signatures&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--fingerprint &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; llista claus i empremtes digitals&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;-K, --list-secret-keys &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;llista claus secretes&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--gen-key &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; genera un nou parell de claus&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--delete-keys &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; elimina claus de l'anell públic&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--delete-secret-keys &amp;nbsp; &amp;nbsp; &amp;nbsp;elimina claus de l'anell secret&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--sign-key &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;signa una clau&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--lsign-key &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; signa una clau localment&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--edit-key &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;signa o edita una clau&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--gen-revoke &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;genera un certificat de revocació&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--export &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;exporta claus&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--send-keys &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; exporta claus a un servidor de claus&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--recv-keys &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; importa claus d'un servidor de claus&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--search-keys &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cerca claus en un servidor de claus&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--refresh-keys &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;actualitza totes les claus des d'un servidor de claus&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--import &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;importa/fon claus&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--card-status &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print the card status&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--card-edit &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; change data on a card&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--change-pin &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;change a card's PIN&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--update-trustdb &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;actualitza la base de dades de confiança&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--print-md algo [fitxers] &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;imprimeix resums de missatges&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Opcions:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;-a, --armor &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; crea eixida amb armadura ascii&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;-r, --recipient NOM &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xifra per a NOM&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;-u, --local-user &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;usa aquest id per a signar o desxifrar&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;-z N &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;nivell de compressió N (0 no comprimeix)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--textmode &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;usa el mode de text canònic&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;-o, --output &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;fitxer d'eixida&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;-v, --verbose &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; detall&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;-n, --dry-run &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; no fa cap canvi&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;-i, --interactive &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pregunta abans de sobreescriure&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--openpgp &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; use strict OpenPGP behavior&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;--pgp2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;generate PGP 2.x compatible messages&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;(En la pàgina del man hi ha una llista completa d'ordres i d'opcions)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Exemples:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;-se -r Bob [fitxer] &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;signa i xifra per a l'usuari Bob&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;--clearsign [fitxer] &amp;nbsp; &amp;nbsp; &amp;nbsp; crea una signatura en text clar&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;--detach-sign [fitxer] &amp;nbsp; &amp;nbsp; crea una signatura separada&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;--list-keys [noms] &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mostra claus&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;--fingerprint [noms] &amp;nbsp; &amp;nbsp; &amp;nbsp; mostra empremtes digitals&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Si us plau, informeu sobre els errors a &amp;lt;gnupg-bugs@gnu.org&amp;gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Tanmateix, amb --help no s'obtenen totes les opcions. &amp;nbsp;Per a obtenir un llistat de totes les opcions de gpg, cal consultar el manual: a un terminal fem &lt;a href="http://www.gnupg.org/documentation/manpage.en.html"&gt;man pgp&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Generar claus&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;El primer de tot:&amp;nbsp;&amp;nbsp;Genero les claus amb gpg --gen-key. Fixem-nos com ens permet seleccionar el tipus de clau, el temps de validesa (he triat 1 any), un ID que es construeix amb el nom i cognoms, adreça electrònica i un comentari, i ens demana també un password per xifrar la clau privada. Aquesta password ens la demanarà sempre que ens calgui la clau privada. El password NO és la clau privada. Però ens caldrà el password per a poder-la utilitzar. Trobem novament una clau simètrica per protegir, en aquest cas, la clau privada; però aquí no hem d'intercanviar la password amb ningú. Al contrari. El que cal és que ningú més que nosaltres conegui aquest password.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~$ &lt;b&gt;gpg --gen-key&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg (GnuPG) 1.4.11; Copyright (C) 2010 Free Software Foundation, Inc.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;This is free software: you are free to change and redistribute it.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;There is NO WARRANTY, to the extent permitted by law.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: directory `/home/albert/.gnupg' created&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: s'ha creat el nou fitxer d'opcions «/home/albert/.gnupg/gpg.conf»&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: AVÍS: les opcions en «/home/albert/.gnupg/gpg.conf» encara no estan actives durant aquesta execució&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: s'ha creat l'anell «/home/albert/.gnupg/secring.gpg»&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: s'ha creat l'anell «/home/albert/.gnupg/pubring.gpg»&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;Seleccioneu quin tipus de clau voleu:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp;(1) RSA and RSA (default)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp;(2) DSA and Elgamal&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp;(3) DSA (només signar)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp;(4) RSA (només signar)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;La vostra selecció? 1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;RSA keys may be between 1024 and 4096 bits long.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;What keysize do you want? (2048) 4096&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;La grandària sol·licitada és 4096 bits&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;Especifiqueu el temps de validesa de la clau&lt;/b&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 = la clau no caduca&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;n&amp;gt; &amp;nbsp;= la clau caduca als n dies&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;n&amp;gt;w = la clau caduca a les n setmanes&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;n&amp;gt;m = la clau caduca als n mesos&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;n&amp;gt;y = la clau caduca als n anys&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Indiqueu la validesa de la clau (0) 1y&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Key expires at dj 21 feb 2013 21:30:51 CET&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Is this correct? (y/N) y&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;You need a user ID to identify your key&lt;/b&gt;; the software constructs the user ID&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;from the Real Name, Comment and Email Address in this form:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; "Heinrich Heine (Der Dichter) &amp;lt;heinrichh@duesseldorf.de&amp;gt;"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Nom i cognoms: Albert Baranguer Codina&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Adreça electrònica: abaranguer@gmail.com&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Comentari: clau personal&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Heu triat l'identificador d'usuari:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; "Albert Baranguer Codina (clau personal) &amp;lt;abaranguer@gmail.com&amp;gt;"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Canvia (N)om, (C)omentari, (E)mail o (O) d'acord / (X) ix o&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;Cal una contrasenya per a protegir la clau secreta&lt;/b&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Cal generar molts bits aleatòriament. És bona idea fer alguna altra cosa&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;(teclejar, moure el ratolí, usar els discos) durant la generació de&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;nombres primers; açò dóna oportunitat al generador de nombres aleatoris&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;d'aconseguir prou entropia.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;..+++++&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;......+++++&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Cal generar molts bits aleatòriament. És bona idea fer alguna altra cosa&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;(teclejar, moure el ratolí, usar els discos) durant la generació de&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;nombres primers; açò dóna oportunitat al generador de nombres aleatoris&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;d'aconseguir prou entropia.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;...................................+++++&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;..............+++++&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: /home/albert/.gnupg/trustdb.gpg: s'ha creat la base de dades de confiança&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: key 7FCC9B65 marked as ultimately trusted&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;s'han creat i signat les claus pública i secreta.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: s'està comprovant la base de dades de confiança&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: depth: 0 &amp;nbsp;valid: &amp;nbsp; 1 &amp;nbsp;signed: &amp;nbsp; 0 &amp;nbsp;trust: 0-, 0q, 0n, 0m, 0f, 1u&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: la pròxima comprovació de la base de dades de confiança serà el 2013-02-21&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp; 4096R/7FCC9B65 2012-02-22 [expires: 2013-02-21]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Key fingerprint = *********** demana'm el fingerprint! ***************&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;uid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Albert Baranguer Codina (clau personal) &amp;lt;abaranguer@gmail.com&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sub &amp;nbsp; 4096R/B092F31D 2012-02-22 [expires: 2013-02-21]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~$&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;La meva clau pública!&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Obtinc la clau pública, és el bloc en negreta:&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~$ gpg --armor --output public-key.asc --export abaranguer&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~$ cat public-key.asc&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;-----BEGIN PGP PUBLIC KEY BLOCK-----&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;Version: GnuPG v1.4.11 (GNU/Linux)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;mQINBE9FUSIBEADov6JmvW2uebJsVqk4HkcV7ri3Yh4wKd0u/Oz6igItIZxIVI8D&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;VQaeSMbEV7SIlRS91A4t2k474gr4iAI/fIKYNYs3ZSfKKERachY9wiZ2I4beMsaU&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;3DsHZiOk8sbmf3sITXV1r5vvW1lTciNVun1n3ucLq2/UnNudF6b/cLFoMJhmM0j5&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;8mMI4VBD6LNFJvrQlH21bRCgaNp71I8Bhb5ZM10Ffe3242S6Mkm/q4j11rm9SYs3&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;1Cuhl7eXqaZdqo6v3VGyuUDh7NL1WEpfZ+4AvduiOUhRaynHe89xOCcGiTjp1pxS&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;QnFMSLR51Emi32PYVGwPCG2MvovE+0fV32GYRr7zBe/IwpDFZvfJqnybtxH5UJrI&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;QVy47LL04+fYK7Y6MEcoW+P3n3eDiUCiApzaHWiXzfICZKNhRi5HmUKUZi1b2X+E&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;hG4EPUNUjsPrBCXPApIYoRgnze1tZUvfKgLzx6mBi8xIT3T3DSeQ1gLTGJfTDm5K&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;GB+PgK/xekcM9/SJftRIjcWEs/JlQvAJChTLXY359LeQQi77j1GuMWOntv0KS3UP&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;SY35cLxjjzr6wQq7CRMqrwszi21Fp+0EJ/eUVF4e0evrRQR3R7YEe93SJ4K/1Xd4&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;ncreHug19Ff2G6UKWwW/Dpd55VQ17/cq/fWBNktiCCfOt8SyEU7zYQ3muwARAQAB&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;tD5BbGJlcnQgQmFyYW5ndWVyIENvZGluYSAoY2xhdSBwZXJzb25hbCkgPGFiYXJh&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;bmd1ZXJAZ21haWwuY29tPokCPgQTAQIAKAUCT0VRIgIbAwUJAeEzgAYLCQgHAwIG&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;FQgCCQoLBBYCAwECHgECF4AACgkQu4sy9X/Mm2XPmQ//UKe/onoZb9MPJGF7+1DA&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;27EMKszZsGi9NdZwnV/u7lQyZBP46lmy7LEN9etyHDGW0pkaY78K4ERZqdGKgvg4&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;sEsAl4299MwJkZgJpS9Sv+0vlm6pQoPirkDLo9rD8l80RhV5fFmirJdjtg+8s7wE&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;8RLiOvReThwCP6tNZWzqDNAaBXPNHHJGckIiq9WRINSFHcQrg0QtdUPalSprmgBc&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;k0lwFnhlDein4b+OSYYUoL4hGowQltBrwEyNOmACQENcWd+Avc5cHttPU5DEdB3U&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;L/sa+lN6T8x0KlAS9fWMCQO90wQdWMsP+VPSBaZlpUhGYwFXpeI07jLbcwJ9tFY0&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;J+wJG/+8LwfK7Q4KuaNoW6kdzIzRl9WsRqi4L3dvdGbNf5b6iPDHxRU3YGJ/aB8W&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;5O/EK+aYwlBK6d7hg3EnTUs9IYhNa8Tiy6vpEQHFX5v8enuPpgcO1Hxg5++TwPsh&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;rrmA+nFAEvhGDioxFqMi4uZ206iPH6lCQhhGBRe4SDTk9ZNy1bIoekJf6oMW5uuZ&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;n9h2h8DSmnG0nV86DV1ynRX+1DRdaNhWqQWaMoJIB/N9vfdrrWdSD7yS3jJV/Srm&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;DLd8S1LRcsYMgap/PXGHaYzq88qQpAm6cb+fbrPmXdqotp7gLZN6+Qo8WCiXhI3B&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;yjteIIN2iaDCg06CS1uR5/K5Ag0ET0VRIgEQAKct4btXdhW+4QDyIuRhhhnd/W3v&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;QIHXfrcMySATU8S/+k/TsISDwuOfiZOqKh3wueZwIii5vYm0XkaCIpiZL6ttsPke&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;T4mF9N8RwdKzpx6x+cXot+MuH3oUZO+fES0wHJCT+81zRMnpBrKke7wQUpxg/DUv&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;xXft6muhmOfbEnGS6DUL+Cb9KZhKHmBtwcxvSIyX6JQipkUsy1gDvTbhckS7UOme&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;j9MTnGG/0GXOVCgJCraTFxtiZzRz3Wwk/VwDTFfs1NyozX9jEzDbIccdohG8KU6e&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;t1KlxevV3amnMPb8Q76kzCIs8nLyaIG0ZI3KAP/oS0fCcwacdFEzYtPtwbXsCbSt&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;EJi+c1mOpNvl0rAr98zRULDJSMQqB50GiMqvaCtu2qpoKPVEr7N7dOYQ4H8Jyd6f&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;f5sGRFji0m8ZlgGCKxHtuvxglXTFA9qHbFoIDggglK+uyyd2OgLkE7U10s5qxJkF&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;YS4UttzuIWPnH8mTm7NZq5RGVn37LOMaucvJifHYdLR6154Ld9WCWuNyRN05AeqZ&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;LWt1tB72m4KTDWx62qVLEq4LfATs7Vp7/jh7LmmistFw8vScTukvpy8ZbU56q9lI&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;RbhUUycZ1gOQexwW9s/hqjmFlM72lV+ZvIhWNWb0e0so6FriOtpLx0IlA8x8Glm1&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;afB1D7G12t4XKikdABEBAAGJAiUEGAECAA8FAk9FUSICGwwFCQHhM4AACgkQu4sy&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;9X/Mm2XKeQ/+P2BEwIN+lgUgn6MWvd88X1juOXsNjXKJxYDdyhE0yTx9p2FWtlbr&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;rbio5P05FrSwtokxL92givi2Rp1HrGjI7Ba5c8uEUKhrKBgXPmwSscZv1HidBiFY&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;VcxSMU+yh5DxXrySslQ/GeiqNTQMkQEkOWbKUoG74zqGke4oWLsewuDNCfhT0Kyy&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;+JzoguMzDJ2sSpu77yXcjrl0vWss/OPyMx87iHKeAwj1/oknkAffw2OnVym5mCBl&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;fhVf8aDLCR3fycLpNI6/RF9bOKRa5mTatSwkhu0Y1yrOMO5lLVLp4jxcU1Kr97+Y&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;LjYXTykCtd9lT79YhXwSLw7oDLHeebNojBmIlp1SvRHGvTIKxkxGa4YuuwBSJYwE&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;nUnb9+PfPjdLKqOX+oY9w4i5PCxXPJLe/5qvcPQKsjQC1o+WtNvsY7z01CtqJdKy&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;ronchTZbyA43hxdzV+EnzUVQqvhxqN8XsqOIqEWQ7YZJYx49r22Ni6y583HbW8JK&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;SdvYLw9sVVSGcW53M/Y1zj/uBAQHNfbAhWBX2CAWJ6PYl5UVMt6PupYD+3XBo1p5&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;lM+i9EIEfyA4mhY5e6RvUJsarEAWMQdZuv7f+R4rUms/EpilGOpMTDsATYZEoNNA&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;Wk8MWmGIc7mdczShLqp2OiWsNWE5aLVWhWNtMOcncLpN0JD0U9kbMKA=&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;=+LAQ&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;b&gt;-----END PGP PUBLIC KEY BLOCK-----&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Si algú em vol enviar missatges xifrats amb GnuPG, ja pot fer-ho! ;-)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Fingerprint&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Tothom que em vulgui enviar missatges xifrats haurà de tenir la meva clau pública. &amp;nbsp;Ara bé, si l'agafa de la web com pot estar-ne segur que és de veritat la meva clau pública? Haurà de verificar-ne el "fingerprint". L'empremta dactilar. Quan he generat la clau una de les línies m'ha informat del fingerprint de la clau:&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp; 4096R/7FCC9B65 2012-02-22 [expires: 2013-02-21]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Key fingerprint = *********** demana'm el fingerprint! ***************&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Que he decidit no publicar a la web...&lt;br /&gt;&lt;br /&gt;Aleshores, algú que rebi la meva clau pública hauria de posar-se en contacte amb mi d'alguna &amp;nbsp;forma segura per verificar que el fingerprint de la clau que té correspon amb el fingerprint que jo posseeixo. Si coincideixen l'usuari podrà la confiar que &amp;nbsp;ha rebut la meva clau pública.&lt;br /&gt;&lt;br /&gt;Suposant que copia la clau pública a un fitxer de text anomenat abaranguer@gmail.com.pub.asc&amp;nbsp;l'usuari haurà d'importar la meva clau pública al seu clauer.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Llistar les claus&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;... i podria començar per verificar les claus que són al clauer.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@apolo:~/Documents$ &lt;b&gt;gpg --list-key&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;/home/albert/.gnupg/pubring.gpg&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;-------------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp; 4096R/6E28AAB8 2012-02-26 [expires: 2017-02-24]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;uid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Albert Baranguer Codina (Clau Personal 2) &amp;lt;albert.baranguer@josoc.cat&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sub &amp;nbsp; 4096R/3B954851 2012-02-26 [expires: 2017-02-24]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@apolo:~/Documents$&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Només hi té la seva clau. El que ha de fer és...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Importar una clau&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Tinc&amp;nbsp;abaranguer@gmail.com.pub.asc a la carpeta Documents i faig:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@apolo:~/Documents$ &lt;b&gt;gpg --import abaranguer@gmail.com.pub.asc&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: key 7FCC9B65: public key "Albert Baranguer Codina (clau personal) &amp;lt;abaranguer@gmail.com&amp;gt;" imported&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: Nombre total processat: 1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; importades: 1 &amp;nbsp;(RSA: 1)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@apolo:~/Documents$&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Verifico que he importat la clau&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@apolo:~/Documents$ &lt;b&gt;gpg --list-key&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;/home/albert/.gnupg/pubring.gpg&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;-------------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp; 4096R/6E28AAB8 2012-02-26 [expires: 2017-02-24]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;uid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Albert Baranguer Codina (Clau Personal 2) &amp;lt;albert.baranguer@josoc.cat&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sub &amp;nbsp; 4096R/3B954851 2012-02-26 [expires: 2017-02-24]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp; 4096R/7FCC9B65 2012-02-22 [expires: 2013-02-21]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;uid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Albert Baranguer Codina (clau personal) &amp;lt;abaranguer@gmail.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sub &amp;nbsp; 4096R/B092F31D 2012-02-22 [expires: 2013-02-21]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@apolo:~/Documents$&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Obtenir el fingerprint&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Quin és el fingerprint de la clau que acabo d'importar?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@apolo:~/Documents$ &lt;b&gt;gpg --fingerprint&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;/home/albert/.gnupg/pubring.gpg&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;-------------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp; 4096R/6E28AAB8 2012-02-26 [expires: 2017-02-24]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Key fingerprint = ************* fingerprint 1 *************&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;uid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Albert Baranguer Codina (Clau Personal 2) &amp;lt;albert.baranguer@josoc.cat&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sub &amp;nbsp; 4096R/3B954851 2012-02-26 [expires: 2017-02-24]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp; 4096R/7FCC9B65 2012-02-22 [expires: 2013-02-21]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Key fingerprint = &lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;******* fingerprint clau importada ******&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;uid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Albert Baranguer Codina (clau personal) &amp;lt;abaranguer@gmail.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sub &amp;nbsp; 4096R/B092F31D 2012-02-22 [expires: 2013-02-21]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;O bé una de sola&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@apolo:~/Documents$ &lt;b&gt;gpg --fingerprint abaranguer@gmail.com&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp; 4096R/7FCC9B65 2012-02-22 [expires: 2013-02-21]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Key fingerprint =&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;******* fingerprint clau importada ******&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;uid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Albert Baranguer Codina (clau personal) &amp;lt;abaranguer@gmail.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sub &amp;nbsp; 4096R/B092F31D 2012-02-22 [expires: 2013-02-21]&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Servidors de claus&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;Recapitulem: fins ara he creat un parell de claus, una de privada que només conec jo i una de pública que he publicat a la web. Tothom que vulgui enviar-me missatges pot fer servir la clau pública per xifrar-los. Si vol estar-ne segur que la clau pública "és bona", hauria de posar-se en contacte amb mi per a verificar-ne el fingerprint.&lt;br /&gt;&lt;br /&gt;Hi ha una altre opció per a fer això: puc publicar la clau a un &lt;a href="http://en.wikipedia.org/wiki/Key_server_(cryptographic)"&gt;servidor de claus&lt;/a&gt;. Els servidors de claus emmagatzemen i permeten examinar claus públiques. A més els servidors de claus repliquen la informació entre ells, de forma que quan hom publica la seva clau a un servidor, en pocs dies aquesta clau és disponible a la resta de servidors.&lt;br /&gt;&lt;br /&gt;El camí contrari, "despublicar" del keyserver, demana pujar al servidor el certificat de revocació de la clau. El certificat de revocació el podem generar amb el mateix GnuPG. &amp;nbsp;Es recomana generar el certificat just al mateix moment en que hom crea el parell de claus.&lt;br /&gt;&lt;br /&gt;Si hagués publicat la clau a un keyserver ara, en comptes de publicar la clau a la web, en tindria prou amb publicar-ne l'ID. L'ID de la clau és aquest número que he obtingut al generar.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp; 4096R/&lt;b&gt;7FCC9B65&lt;/b&gt; 2012-02-22 [expires: 2013-02-21]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Aleshores qualsevol usuari podria utilitzar l'ID per cercar la clau i descarregar-se-la dels keyservers.&lt;br /&gt;&lt;br /&gt;I un usuari amb qui no ens coneixem de res, perquè se n'hauria de refiar d'aquesta clau descarregada d'un keyserver?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Xarxa de confiança&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Per a poder respondre a aquesta pregunta cal explicar primer que quan un usuari rep una clau pública, &amp;nbsp;en verifica el fingerprint &amp;nbsp;i te confiança en el propietari, aleshores pot signar la clau pública rebuda amb la seva pròpia clau privada. Aquesta clau pública té un plus afegit de confiança: un usuari en certifica la seva validesa. Aquesta clau pública signada es podria passar a un altre usuari que, en cas de verificar el fingerprint &amp;nbsp;o, senzillament, perquè confia en l'usuari que ha signat la clau podria, a la seva vegada, signar ell també la clau. &lt;br /&gt;&lt;br /&gt;Cada cop que algú signa la nostra clau pública està certificant que la clau és de confiança. Com més signatures té la clau, vol dir que més gent certifica que "és bona". A més, cadascun d'aquest usuaris pot tenir la seva pròpia clau pública amb signatures d'altres usuaris. &amp;nbsp;Aquesta xarxa de signatures de la que participa la nostra clau és la seva&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Web_of_trust"&gt;"xarxa de confiança" (web of trust)&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Tanmateix, hom podria desconfiar d'algunes de les claus de la xarxa de confiança. En aquest cas GnuPG permet afegir un &lt;a href="http://www.gnupg.org/gph/en/manual/x334.html"&gt;indicador de "confiança"&lt;/a&gt;&amp;nbsp; (mireu també &lt;a href="http://www.gnupg.org/gph/en/manual/c481.html#AEN526"&gt;aquí&lt;/a&gt;) sobre les diferents persones que han signat. Des del "desconegut", passant pel "cap confiança", "hi confio" fins al "confio com si fos jo mateix". En tot cas, aquest indicador és d'us personal i no es posa a la clau.&lt;br /&gt;&lt;br /&gt;La resposta, doncs, a la pregunta de perquè un usuari se n'hauria de refiar de la clau descarregada del key server és que no té perquè fer-ho, però pot pensar que una clau pública que estigui signada per uns quants usuaris, o que pertany o toca a la seva xarxa de confiança pot ser, raonablement, de confiança.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Festa de firmes!&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Els grups d'usuaris de PGP / GnuPG convoquen de tant en tant les &lt;a href="https://wiki.ubuntu.com/CatalanTeam/FestaDeFirmes"&gt;"Festes de Firmes"&lt;/a&gt; (&lt;a href="http://en.wikipedia.org/wiki/Key_signing_party"&gt;key signing party&lt;/a&gt;). Que es un esdeveniment en que els participants s'intercanvien les seves fingerprint després d'haver verificat mutuament &amp;nbsp;les identitats, per exemple amb el DNI, de forma que, en acabar l'acte, amb els fingerprint de les claus públiques d'altres participants, les descarreguen del keyserver, en verifiquen els fingerprint, les signen i les redifonen. Es tracta d'una forma lúdica d'ampliar la xarxa de confiança (podríem veure-ho com una xarxa social més, en definitiva).&lt;br /&gt;&lt;br /&gt;En to cas, podem fer servir GnuPG sense que calgui la xarxa de confiança.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Signar&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Un cop explicats aquests conceptes, passem a qüestions més pràctiqes&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Com signo un document? Vaig a generar un document de prova (loremipsum.txt) en que hi posaré un paràgraf del Lorem ipsum (el genero amb aquesta web:&amp;nbsp;&lt;a href="http://ca.lipsum.com/"&gt;http://ca.lipsum.com/&lt;/a&gt;)&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Per a signar-lo amb la clau privada faig&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg --sign loremipsum.txt&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Observem que gpg ens demana la password de la clau privada. El resultat eś el fitxer xifrat amb extensió&amp;nbsp;loremipsum.txt.gpg.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Si volgués que el fitxer fos ilegible i amb un altre nom faria:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg --armor --output signat.txt --sign loremipsum.txt&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;També podria voler que el text original es pogués llegir "en clar", i que la signatura estigués separada en el mateix fitxer. Aleshores faria&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg &amp;nbsp;--output signat.2.txt --clearsign loremipsum.txt&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Però si el document original amb el missatge no admetés la inclusió de cap signatura, el que es podria fer és posar la signatura en un fitxer signatura.txt apart. A més el vull fer legible. Ho faig així:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg --armor --output signatura.txt --detach-sign loremipsum.txt&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Depenent del cas, enviaré el document signat, o la signatura i el document en fitxers separats, al seu destinatari. Aquest, un cop rebi el document signat, el verificarà amb la meva clau pública.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Verificar la signatura&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;El receptor del missatge podria verificar amb&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg --verify loremipsum.txt.gpg&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;( o amb signat.txt, o signat.2.txt )&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;En aquest cas obtindrem un missatge&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@apolo:~/Documents$ gpg --verify signatura.txt loremipsum.txt&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: Signature made dt 28 feb 2012 22:55:35 CET using RSA key ID 7FCC9B65&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: Good signature from "Albert Baranguer Codina (Clau Personal) &amp;lt;abaranguer@gmail.com&amp;gt;"&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;o bé, si venen per separat:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg --verify signatura.txt loremipsum.txt&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Primer ha d'anar la signatura, i després el document que s'ha signat. En cas de posar-los en l'ordre invers, obtindrem un missatge d'error:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@apolo:~/Documents$ gpg --verify loremipsum.txt signatura.txt&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: no s'han trobat dades OpenPGP vàlides.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: no s'ha pogut verificar la signatura.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Recordeu que el fitxer de signatura (.sig o .asc)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;ha de ser el primer que figure en la línia d'ordres.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Xifrar un missatge&lt;br /&gt;&lt;br /&gt;Per a fer la prova, enviaré&amp;nbsp;&amp;nbsp;el loremipsum.txt xifrat a l'usuari unaltrecompte@servidor.com, del qual tinc la clau pública.&lt;br /&gt;&lt;br /&gt;Tinc algunes claus públiques més al clauer. Per tant he de triar la del destinatari. Ho faig amb l'opció --recipient i l'ID de la clau.&lt;br /&gt;&lt;br /&gt;Vet aquí:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~/Documents$ gpg --armor --output xifrat.txt --recipient 6E28AAB8 --encrypt loremipsum.txt&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: 3B954851: There is no assurance this key belongs to the named user&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp;4096R/3B954851 2012-02-26 Albert Baranguer Codina (Clau Personal 2) &amp;lt;unaltrecompte@servidor.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;Empremta digital de la clau primària: xxxx&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Empremta digital de la subclau:&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;It is NOT certain that the key belongs to the person named&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;in the user ID. &amp;nbsp;If you *really* know what you are doing,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;you may answer the next question with yes.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Use this key anyway? (y/N) y&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Les claus públiques del meu clauer no les he signat ni tenen cap signatura de ningú de "confiança absoluta", per tant rebo un missatge d'advertència. Podria signar la clau i marcar el destinatari com "de confiança absoluta, com si fos jo mateix", (de fet, ho soc! ;-) de forma que m'estalviaria aquest missatge.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Signar una clau pública&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Primer miro les claus del clauer&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~$ &lt;b&gt;gpg --list-keys&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;/home/albert/.gnupg/pubring.gpg&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;-------------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp; 4096R/7FCC9B65 2012-02-22 [expires: 2013-02-21]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;uid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Albert Baranguer Codina (clau personal) &amp;lt;abaranguer@gmail.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sub &amp;nbsp; 4096R/B092F31D 2012-02-22 [expires: 2013-02-21]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp; 2048R/D826822A 2012-02-23 [expires: 2017-02-21]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;uid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Serveis TIC i Programari Lliure &amp;lt;stsoftlliure@gmail.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sub &amp;nbsp; 2048R/9D8D4AA0 2012-02-23 [expires: 2017-02-21]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp; 4096R/&lt;b&gt;6E28AAB8&lt;/b&gt; 2012-02-26 [expires: 2017-02-24]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;uid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Albert Baranguer Codina (Clau Personal 2) &amp;lt;unaltrecompte@servidor.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sub &amp;nbsp; 4096R/3B954851 2012-02-26 [expires: 2017-02-24]&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I em fixo en els seus ID. Abans de signar-les hauria de comprovar-ne els fingerprint per estar-ne segur de la seva autenticitat. En aquest cas ho considero fet. Totes són &amp;nbsp;claus de prova.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Per tant, puc passar a signar la clau corresponent&amp;nbsp;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~$ &lt;b&gt;gpg --sign-key 6E28AAB8&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp;4096R/6E28AAB8 &amp;nbsp;created: 2012-02-26 &amp;nbsp;expires: 2017-02-24 &amp;nbsp;usage: SC &amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;trust: desconeguda &amp;nbsp; validity: desconeguda&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sub &amp;nbsp;4096R/3B954851 &amp;nbsp;created: 2012-02-26 &amp;nbsp;expires: 2017-02-24 &amp;nbsp;usage: E &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;[ unknown] (1). Albert Baranguer Codina (Clau Personal 2) &amp;lt;unaltrecompte@servidor.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp;4096R/6E28AAB8 &amp;nbsp;created: 2012-02-26 &amp;nbsp;expires: 2017-02-24 &amp;nbsp;usage: SC &amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;trust: desconeguda &amp;nbsp; validity: desconeguda&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;Empremta digital de la clau primària: C6EC 5EAF 31BE C8D9 6644 &amp;nbsp;200F 1849 3E7D 6E28 AAB8&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Albert Baranguer Codina (Clau Personal 2) &amp;lt;unaltrecompte@servidor.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Aquesta clau caducarà el 2017-02-24.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Are you sure that you want to sign this key with your&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;key "Albert Baranguer Codina (clau personal) &amp;lt;abaranguer@gmail.com&amp;gt;" (7FCC9B65)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Really sign? (y/N) y&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Cal una contrasenya per desblocar la clau secreta de&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;l'usuari: «Albert Baranguer Codina (clau personal) &amp;lt;abaranguer@gmail.com&amp;gt;» "&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;4096-bit RSA key, ID 7FCC9B65, created 2012-02-22&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: gpg-agent no està disponible en aquesta sessió&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~$&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Veifico que realment ha signat&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~$ &lt;b&gt;gpg --list-sigs&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: s'està comprovant la base de dades de confiança&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: depth: 0 &amp;nbsp;valid: &amp;nbsp; 1 &amp;nbsp;signed: &amp;nbsp; 2 &amp;nbsp;trust: 0-, 0q, 0n, 0m, 0f, 1u&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: depth: 1 &amp;nbsp;valid: &amp;nbsp; 2 &amp;nbsp;signed: &amp;nbsp; 0 &amp;nbsp;trust: 2-, 0q, 0n, 0m, 0f, 0u&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: la pròxima comprovació de la base de dades de confiança serà el 2013-02-21&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;/home/albert/.gnupg/pubring.gpg&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;-------------------------------&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp; 4096R/7FCC9B65 2012-02-22 [expires: 2013-02-21]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;uid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Albert Baranguer Codina (clau personal) &amp;lt;abaranguer@gmail.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sig 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7FCC9B65 2012-02-22 &amp;nbsp;Albert Baranguer Codina (clau personal) &amp;lt;abaranguer@gmail.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sub &amp;nbsp; 4096R/B092F31D 2012-02-22 [expires: 2013-02-21]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sig &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7FCC9B65 2012-02-22 &amp;nbsp;Albert Baranguer Codina (clau personal) &amp;lt;abaranguer@gmail.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp; 2048R/D826822A 2012-02-23 [expires: 2017-02-21]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;uid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Serveis TIC i Programari Lliure &amp;lt;stsoftlliure@gmail.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sig 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;D826822A 2012-02-23 &amp;nbsp;Serveis TIC i Programari Lliure &amp;lt;stsoftlliure@gmail.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sub &amp;nbsp; 2048R/9D8D4AA0 2012-02-23 [expires: 2017-02-21]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sig &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;D826822A 2012-02-23 &amp;nbsp;Serveis TIC i Programari Lliure &amp;lt;stsoftlliure@gmail.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp; 4096R/6E28AAB8 2012-02-26 [expires: 2017-02-24]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;uid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Albert Baranguer Codina (Clau Personal 2) &amp;lt;unaltrecompte@servidor.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sig 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6E28AAB8 2012-02-26 &amp;nbsp;Albert Baranguer Codina (Clau Personal 2) &amp;lt;unaltrecompte@servidor.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sig &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7FCC9B65 2012-02-29 &amp;nbsp;Albert Baranguer Codina (clau personal) &amp;lt;abaranguer@gmail.com&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sub &amp;nbsp; 4096R/3B954851 2012-02-26 [expires: 2017-02-24]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sig &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6E28AAB8 2012-02-26 &amp;nbsp;Albert Baranguer Codina (Clau Personal 2) &amp;lt;unaltrecompte@servidor.comt&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~$&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Aquí podem comprovar que tota signatura públic té, almenys, una signatura, que,es la de la seva parella clau privada. El compte&amp;nbsp;unaltrecompte@servidor.com té, doncs dues signatures, la de la seva parella privada i la que li acabo de posar.&lt;br /&gt;&lt;br /&gt;Ara que tinc la clau pública de unaltrecompte@servicor.com signada, repeteixo el xifrat del loreipsum.txt&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:/media/ADATA UFD/docs$ &lt;b&gt;gpg --armor --output xifrat.2.txt --recipient 6E28AAB8 --encrypt loremipsum.txt&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:/media/ADATA UFD/docs$&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;El resultat és que obtinc el fitxer xifrat.2.txt netament, sense cap missatge d'advertència.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Xifrar i signar un missatge&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Però, i si el destinatari volgués tenir la certesa que el fitxer l'he enviat jo? Ben mirat, algú em podria haver suplantat i enviar el missatge enlloc meu. El que cal fer, per a eliminar aquest dubte, és signar i xifrar a l'hora el document.&lt;br /&gt;&lt;br /&gt;A l'exemple, faig:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:/media/ADATA UFD/docs$ &lt;b&gt;gpg --armor --output xifrat.4.txt --recipient 6E28AAB8 --sign --encrypt loremipsum.txt&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Cal una contrasenya per desblocar la clau secreta de&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;l'usuari: «Albert Baranguer Codina (clau personal) &amp;lt;abaranguer@gmail.com&amp;gt;» "&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;4096-bit RSA key, ID 7FCC9B65, created 2012-02-22&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: gpg-agent no està disponible en aquesta sessió&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:/media/ADATA UFD/docs$&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;i obtinc el fitxer &amp;nbsp;xifrat i signat xifrat4.txt. &amp;nbsp;Com sempre que cal fer alguna acció amb la clau privada, gpg m'ha demanat la password per a poder &amp;nbsp;fer-la servir.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I què hauria passat si la clau no hagués estat signada?&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~/Documents$ &lt;b&gt;gpg --armor --output xifrat.2.txt --recipient 6E28AAB8 --sign --encrypt loremipsum.txt&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Cal una contrasenya per desblocar la clau secreta de&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;l'usuari: «Albert Baranguer Codina (clau personal) &amp;lt;abaranguer@gmail.com&amp;gt;» "&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;4096-bit RSA key, ID 7FCC9B65, created 2012-02-22&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: gpg-agent no està disponible en aquesta sessió&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: 3B954851: There is no assurance this key belongs to the named user&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;pub &amp;nbsp;4096R/3B954851 2012-02-26 Albert Baranguer Codina (Clau Personal 2) &amp;lt;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;unaltrecompte@servidor.com&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;Empremta digital de la clau primària:&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Empremta digital de la subclau:&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;xxxx&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;It is NOT certain that the key belongs to the person named&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;in the user ID. &amp;nbsp;If you *really* know what you are doing,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;you may answer the next question with yes.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Use this key anyway? (y/N) y&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~/Documents$&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Primer em demana la password de la clau privada. A continuació m'adverteix que la clau pública del destinatari no està signada. El resultat, en tot cas, és el fitxer xifrat.2.txt&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Desxifrar&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;Ara tinc uns quants fitxers xifrats que només podrà dexifrar &amp;nbsp;unaltrecompter@servidor.com.&lt;br /&gt;&lt;br /&gt;És el més senzill de tot: dexifrar és l'opció per defecte de gpg, per tant, n'hi ha prou amb fer...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@apolo:/media/ADATA UFD/docs$ &lt;b&gt;gpg xifrat.txt&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Cal una contrasenya per desblocar la clau secreta de&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;l'usuari: «Albert Baranguer Codina (Clau Personal 2) &amp;lt;&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;unaltrecompte@servidor.com&lt;/span&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;gt;» "&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;4096-bit RSA key, ID 3B954851, created 2012-02-26 (main key ID 6E28AAB8)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: gpg-agent no està disponible en aquesta sessió&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: encrypted with 4096-bit RSA key, ID 3B954851, created 2012-02-26&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; "Albert Baranguer Codina (Clau Personal 2) &amp;lt;unaltrecompte@servidor.com&amp;gt;"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;gpg: xifrat.txt: el sufix és desconegut&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Introduïu el nou nom del fitxer [loremipsum.txt]: loremipsum.decrypt.txt&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@apolo:/media/ADATA UFD/docs$&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Com que per a dexifrar cal la clau privada, el gpg demana el password corresponent.&lt;br /&gt;&lt;br /&gt;En examinar loremipsum.decrypt.txt obtinc, com era d'esperar el paràgraf de Lorem Ipsum original.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;i&gt;&lt;span style="color: #20124d;"&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque dignissim lobortis auctor. Nunc sem sapien, egestas eu dignissim non, molestie sit amet mi. In diam lacus, fermentum et mollis quis, pellentesque id enim. Nullam pretium, dolor non malesuada viverra, eros odio convallis arcu, eu tincidunt libero purus sit amet purus. Praesent eu aliquet nunc. Sed vitae augue lacus. Duis fermentum purus sed ligula malesuada nec ornare orci posuere. Etiam ac facilisis turpis&lt;/span&gt;.&lt;/i&gt;&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Per acabar&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;En el post dedicat a gpg he fet un repàs dels principals conceptes que cal conèixer per a utilitzar GnuPG. He esmentat altres eines relacionades, com Enigmail. He &amp;nbsp;distingit entre criptografia de clau simètrica, de clau pública, i híbrida. &amp;nbsp;També he parlat de les xarxes de confiança que es poden implementar &amp;nbsp;els intercanvis de claus públiques de GnuPG. He presentat les accions principals que es poden realitzar amb GnuPG, que són signar, xifrar, verificar i dexifrar. &lt;br /&gt;&lt;br /&gt;En cap cas he pretès realitzar una anàlisi exhaustiva de l'eina. Hi han molts i bons manuals fets que acompleixen aquesta missió i n'he citat alguns.&lt;br /&gt;&lt;br /&gt;Finalment, el resultat d'aquest post és que penjaré la meva clau pública a la web. Per si algú prefereix entrar en contacte amb Serveis TIC i Programari Lliure de forma privada.&amp;nbsp;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4788606468171792208-1174515460726958255?l=apuntstecnologia.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apuntstecnologia.blogspot.com/feeds/1174515460726958255/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://apuntstecnologia.blogspot.com/2012/02/criptografia-de-clau-publica-amb-gnupg.html#comment-form' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/1174515460726958255'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/1174515460726958255'/><link rel='alternate' type='text/html' href='http://apuntstecnologia.blogspot.com/2012/02/criptografia-de-clau-publica-amb-gnupg.html' title='Criptografia de clau pública amb GnuPG'/><author><name>Serveis Tecnològics i Programari Lliure</name><uri>http://www.blogger.com/profile/12434522547196735270</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4788606468171792208.post-4022367962743234325</id><published>2011-12-27T19:09:00.004+01:00</published><updated>2012-02-19T21:57:24.550+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tecnologies'/><category scheme='http://www.blogger.com/atom/ns#' term='java'/><title type='text'>Una aproximació a Google App Engine. Com desenvolupar al núvol de Google.</title><content type='html'>&lt;a href="https://appengine.google.com/"&gt;Google App Engine&lt;/a&gt; és la plataforma &amp;nbsp;que ofereix Google i en la que es poden executar aplicacions web pròpies desenvolupades en Java, i d'altres llenguatges, de forma gratuita fins a un cert nivell de tràfic o recursos.&amp;nbsp;L'interès de Google App Engine és que a l'estar-ne integrat, permet aprofitar els serveis de la "plataforma Google"i, a més, es disposa d'una API que permet accedir a aquests serveis.&lt;br /&gt;&lt;br /&gt;Només cal tenir un compte a Google i registrar-se amb Google App Engine per a poder accedir a aquest servei de plataforma (&lt;a href="http://en.wikipedia.org/wiki/Platform_as_a_service"&gt;Platform as a Service&lt;/a&gt;, o PaaS) i poder desenvolupar aplicacions en el núvol personal a Google.&lt;br /&gt;&lt;br /&gt;Google App Engine és, doncs, una plataforma de cloud computing en la que podrem desplegar aplicacions web (per exemple, un CMS com &lt;a href="http://www.vosao.org/"&gt;Vosao&lt;/a&gt;) i disposarem d'APIS que permetran l'autenticacio , amb la resta de serveis que &amp;nbsp;tinguem a Google, com Docs,o enviar correus amb GMail, o&lt;br /&gt;&lt;br /&gt;No confondre Google App Engine amb Google&amp;nbsp;&lt;a href="http://support.google.com/a/bin/answer.py?hl=en&amp;amp;answer=91077"&gt;Apps&lt;/a&gt; (amb s). Aquest últim ve &amp;nbsp;a ser la versió "personalitzada" i depenent del grau de personalització, de pagament, dels serveis de Google . &amp;nbsp;Per cert, Apps també pot ser considerat una plataforma de desenvolupament. &lt;a href="http://code.google.com/intl/ca-ES/googleapps/appsscript/"&gt;Google Apps Script&lt;/a&gt; permet crear macros per automatitzar tasques amb Javascript. Poso en cartera un post per parlar d'Apps i de les seves macros.&lt;br /&gt;&lt;br /&gt;Però tornem a l'App Engine. Hi han &amp;nbsp;restriccions que cal tenir en compte. Entre d'altres: Només es pot fer servir un subconjunt de les classes del JRE estàndard, la "llista blanca de classes de JRE"; les aplicacions no poden crear fils (Thread); Els processos de servidor en resposta a peticions no poden trigar més de 30s; només es pot executar codi en resposta a peticions rebudes per HTTP; les aplicacions estan limitades pels frameworks que imposa Google i, per exemple, es pot consultar, afegir, modificar i esborrar dades de la base de dades NO-Relacional &amp;nbsp;BigTable que proporciona Google App Engine, però no es poden fer servir bases de dades relacionals com MySQL.&lt;br /&gt;&lt;br /&gt;A la wikipedia podem trobar una bona descripció del &lt;a href="http://en.wikipedia.org/wiki/Google_App_Engine"&gt;Google App Engine&lt;/a&gt;.&amp;nbsp;En tot cas, les especificacions i restriccions depenen de &lt;a href="http://code.google.com/intl/ca-ES/appengine/docs/whatisgoogleappengine.html"&gt;Google&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;El que m'interessa a mi és com funciona des del punt de vista del desenvolupador. Res millor que seguir els demos de l'SDK de Google App Engine (GAE).&lt;br /&gt;&lt;br /&gt;Cal el J&lt;a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html"&gt;DK 1.6 com a mínim&lt;/a&gt;.&lt;br /&gt;L'SDK de Google App Engine per Java i la documentació (&lt;a href="http://code.google.com/intl/ca-ES/appengine/downloads.html"&gt;http://code.google.com/intl/ca-ES/appengine/downloads.html&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;Un cop descarregat i instal·lat tot aquest material, em dirigeixo a la java &lt;a href="http://code.google.com/intl/ca-ES/appengine/docs/java/gettingstarted/"&gt;Getting Started Guide&lt;/a&gt;, per a compilar les proves faré servir &lt;a href="http://code.google.com/intl/ca-ES/appengine/docs/java/tools/ant.html"&gt;Apache Ant&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;En aquest moment tinc a &lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;/home/albert&lt;/span&gt; la carpeta&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;appengine-java-sdk&lt;/span&gt;&lt;br /&gt;Que he renombrat eliminant-ne el sufix amb el número de versió seguint les indicacions de la guia; i la carpeta&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;google-appengine-docs&lt;/span&gt;&lt;br /&gt;que conté la documentació i que també he renombrat eliminat-ne el sufix amb la data de versió.&lt;br /&gt;&lt;br /&gt;Ara puc provar l'aplicació Guestbook que va amb les demos de l'appengine, fent&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;./appengine-java-sdk/bin/dev_appserver.sh appengine-java-sdk/demos/guestbook/war&amp;nbsp;&lt;/span&gt;&lt;br /&gt;des de la carpeta /home/albert&lt;br /&gt;&lt;br /&gt;L'aplicació engega:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;albert@athena:~$ ./appengine-java-sdk/bin/dev_appserver.sh appengine-java-sdk/demos/guestbook/war&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;31/12/2011 19:32:49 com.google.apphosting.utils.jetty.JettyLogger info&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;INFO: Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;31/12/2011 19:32:50 com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;INFO: Successfully processed /home/albert/appengine-java-sdk/demos/guestbook/war/WEB-INF/appengine-web.xml&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;31/12/2011 19:32:51 com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;INFO: Successfully processed /home/albert/appengine-java-sdk/demos/guestbook/war/WEB-INF/web.xml&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;31/12/2011 20:33:08 com.google.appengine.tools.development.DevAppServerImpl start&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;INFO: The server is running at http://localhost:8080/&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;31/12/2011 20:33:09 com.google.appengine.tools.development.DevAppServerImpl start&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;INFO: The admin console is running at http://localhost:8080/_ah/admin&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;31/12/2011 20:34:04 com.google.appengine.tools.development.LocalResourceFileServlet doGet&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;WARNING: No file found for: /favicon.ico&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I fent http://localhost:8080&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-PTIg6AKJ6E8/Tv9ngCm5zJI/AAAAAAAAALY/dHy1DqLooow/s1600/2011-12-31-204924_800x480_scrot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://3.bp.blogspot.com/-PTIg6AKJ6E8/Tv9ngCm5zJI/AAAAAAAAALY/dHy1DqLooow/s400/2011-12-31-204924_800x480_scrot.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Puc deixar alguns missatges de prova:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-jWzXnY8p4zM/Tv9pJ4mFJQI/AAAAAAAAALk/C6qLwyrQlBM/s1600/2011-12-31-205657_800x480_scrot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://3.bp.blogspot.com/-jWzXnY8p4zM/Tv9pJ4mFJQI/AAAAAAAAALk/C6qLwyrQlBM/s400/2011-12-31-205657_800x480_scrot.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;També podem fer un cop d'ull a la consola d'administració, a&amp;nbsp;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;http://localhost:8080/_ah/admin&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-RX5LhOuFlNc/TxxnM01K22I/AAAAAAAAALs/4DvFd_RlW7w/s1600/2012-01-22-204420_1024x768_scrot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://4.bp.blogspot.com/-RX5LhOuFlNc/TxxnM01K22I/AAAAAAAAALs/4DvFd_RlW7w/s400/2012-01-22-204420_1024x768_scrot.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Podem examinar el visor de dades El datastore viewer, o es pot examinar la finestra XMPP per als missatges de xats, el correu electrònic associat... En particular, al Datastore Viewer podrem examinar els missatges que ja hem afegit.&lt;br /&gt;&lt;br /&gt;Com ho fa? a la carpeta&amp;nbsp;appengine-java-sdk/demos/guestbook/war trobem el codi font de l'aplicació.&lt;br /&gt;&lt;br /&gt;En un primer cop d'ull ens adonem que es tracta d'una aplicació web java gairebé estàndar: hi trobem jsp i css i una carpeta WEB-INF amb els habituals sub-carpetes classes i lib. A més també hi trobo el web.xml de les aplicacions web i, como a variació sobre el estàndar, un document appengine-web.xml.&lt;br /&gt;&lt;br /&gt;En aquest cas, &amp;nbsp;appengine-web.xml només informa de la versió de l'aplicació i del fitxer de propietats del sistema de logs. Sobre aquest últim, dir que el sistema de logs del GAE és similar al que hom implementa amb log4j.&lt;br /&gt;&lt;br /&gt;Vet aquí l'appengine-web.xml&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="line" style="font-family: monospace;"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #073763; font-size: xx-small;"&gt;&amp;lt;appengine-web-app&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;xmlns&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;http://appengine.google.com/ns/1.0&lt;/span&gt;"&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="collapsible-content" style="font-family: monospace; margin-left: 1em;"&gt;&lt;span style="color: #073763; font-size: xx-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #073763; font-size: xx-small;"&gt;&amp;lt;application/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #073763; font-size: xx-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="line"&gt;&lt;span style="color: #073763; font-size: xx-small;"&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;&lt;span class="text"&gt;1&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #073763; font-size: xx-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="collapsible" id="collapsible1"&gt;&lt;div class="expanded"&gt;&lt;div class="line"&gt;&lt;span style="color: #073763; font-size: xx-small;"&gt;&lt;span class="button collapse-button" style="-webkit-user-select: none; background-image: -webkit-canvas(arrowDown); background-position: 0% 0%; background-repeat: no-repeat no-repeat; cursor: pointer; display: inline-block; height: 10px; margin-left: -10px; vertical-align: bottom; width: 10px;"&gt;&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;system-properties&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="collapsible-content" style="margin-left: 1em;"&gt;&lt;span style="color: #073763; font-size: xx-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #073763; font-size: xx-small;"&gt;&amp;lt;property&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;name&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;java.util.logging.config.file&lt;/span&gt;"&lt;/span&gt;&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;value&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;WEB-INF/logging.properties&lt;/span&gt;"&lt;/span&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #073763; font-size: xx-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #073763; font-size: xx-small;"&gt;&amp;lt;/system-properties&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;span style="color: #073763; font-size: xx-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="line" style="font-family: monospace;"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #073763; font-size: xx-small;"&gt;&amp;lt;/appengine-web-app&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;A continuació, examino la resta del codi.&lt;br /&gt;&lt;br /&gt;Primer de tot, la pàgina guestbook.jsp&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="java.util.List" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.users.User" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.users.UserService" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.users.UserServiceFactory" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.datastore.DatastoreService" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.datastore.Query" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.datastore.Entity" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.datastore.FetchOptions" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.datastore.Key" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.datastore.KeyFactory" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;lt;head&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;link type="text/css" rel="stylesheet" href="/stylesheets/main.css" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;lt;/head&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;lt;body&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; String guestbookName = request.getParameter("guestbookName");&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; if (guestbookName == null) {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; guestbookName = "default";&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; UserService userService = UserServiceFactory.getUserService();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; User user = userService.getCurrentUser();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; if (user != null) {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;p&amp;gt;Hello, &amp;lt;%= user.getNickname() %&amp;gt;! (You can&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;a href="&amp;lt;%= userService.createLogoutURL(request.getRequestURI()) %&amp;gt;"&amp;gt;sign out&amp;lt;/a&amp;gt;.)&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; } else {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;p&amp;gt;Hello!&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;a href="&amp;lt;%= userService.createLoginURL(request.getRequestURI()) %&amp;gt;"&amp;gt;Sign in&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;to include your name with greetings you post.&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; // Run an ancestor query to ensure we see the most up-to-date&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; // view of the Greetings belonging to the selected Guestbook.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; Query query = new Query("Greeting", guestbookKey).addSort("date", Query.SortDirection.DESCENDING);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; List&amp;lt;Entity&amp;gt; greetings = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(5));&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; if (greetings.isEmpty()) {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;p&amp;gt;Guestbook '&amp;lt;%= guestbookName %&amp;gt;' has no messages.&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;%&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; } else {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;p&amp;gt;Messages in Guestbook '&amp;lt;%= guestbookName %&amp;gt;'.&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;%&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (Entity greeting : greetings) {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (greeting.getProperty("user") == null) {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;p&amp;gt;An anonymous person wrote:&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;%&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } else {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;&amp;lt;%= ((User) greeting.getProperty("user")).getNickname() %&amp;gt;&amp;lt;/b&amp;gt; wrote:&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;%&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;blockquote&amp;gt;&amp;lt;%= greeting.getProperty("content") %&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;%&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;form action="/sign" method="post"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;div&amp;gt;&amp;lt;textarea name="content" rows="3" cols="60"&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;div&amp;gt;&amp;lt;input type="submit" value="Post Greeting" /&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;input type="hidden" name="guestbookName" value="&amp;lt;%= guestbookName %&amp;gt;"/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;form action="/guestbook.jsp" method="get"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;div&amp;gt;&amp;lt;input type="text" name="guestbookName" value="&amp;lt;%= guestbookName %&amp;gt;"/&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;div&amp;gt;&amp;lt;input type="submit" value="Switch Guestbook" /&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;La pàgina comença fent la importació de les classes del Google App Engine que farà servir després.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.users.User" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.users.UserService" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.users.UserServiceFactory" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.datastore.DatastoreService" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.datastore.Query" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.datastore.Entity" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.datastore.FetchOptions" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.datastore.Key" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;%@ page import="com.google.appengine.api.datastore.KeyFactory" %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A continuació, determina si l'usuari està logat amb&amp;nbsp;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;userService.getCurrentUser();&amp;nbsp;&lt;/span&gt;per a poder presentar l'opció de logar-se (&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;userService.createLoginURL(request.getRequestURI())&lt;/span&gt;) o deslogar-se (&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;userService.createLogoutURL(request.getRequestURI())&lt;/span&gt;) .&lt;br /&gt;&lt;br /&gt;Segueix amb la preparació de la "base de dades": el DataStore. Per defecte el llibre de visites és el "default". Es podran crear altres llibres de visites amb el paràmetre&amp;nbsp;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;guestbookName&lt;/span&gt;. Aquest paràmetre es podrà modificar amb el formulari que presenta la pàgina.&lt;br /&gt;&lt;br /&gt;Amb&amp;nbsp;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName);&amp;nbsp;&lt;/span&gt;es crea el llibre de visites (o s'obre per accedir-hi si ja existia) i se n'obté la clau de referència (compte que els DataStore NO són bases de dades relacionals!).&lt;br /&gt;&lt;br /&gt;A continuació obté la llista dels cinc darrers missatges del llibre de visites ordenats per data, des del més recent:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Query query = new Query("Greeting", guestbookKey).addSort("date", Query.SortDirection.DESCENDING);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;List&amp;lt;Entity&amp;gt; greetings = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(5))&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Si no hi han missatges, n'informa:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;if (greetings.isEmpty()) {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;p&amp;gt;Guestbook '&amp;lt;%= guestbookName %&amp;gt;' has no messages.&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;%&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I si n'hi han, itera per la llista presentant-ne l'autor i el text del missatge:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;} else {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;p&amp;gt;Messages in Guestbook '&amp;lt;%= guestbookName %&amp;gt;'.&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;%&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (Entity greeting : greetings) {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (greeting.getProperty("user") == null) {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;p&amp;gt;An anonymous person wrote:&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;%&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } else {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;&amp;lt;%= ((User) greeting.getProperty("user")).getNickname() %&amp;gt;&amp;lt;/b&amp;gt; wrote:&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;%&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;blockquote&amp;gt;&amp;lt;%= greeting.getProperty("content") %&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;%&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Finalment, la pàgina presenta els camps en el que es pot introduir el missatge i seleccionar el llibre de visites en el que es vol desar.&lt;br /&gt;Internament, els dos camps s'organitzen en dos formularis HTML, el primer invoca al servlet /sign i li passa el text del missatge i el llibre de visites en el que ha d'inserir-lo. El segon formulari auto-invoca la mateixa pàgina guestbook.jsp i permet modificar el paràmetre guestbookName (per defecte, &amp;nbsp;default), es dir, permet crear un llibre de vistes nou, o seleccionar-ne un d'existent.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;form action="/sign" method="post"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;div&amp;gt;&amp;lt;textarea name="content" rows="3" cols="60"&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;div&amp;gt;&amp;lt;input type="submit" value="Post Greeting" /&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;input type="hidden" name="guestbookName" value="&amp;lt;%= guestbookName %&amp;gt;"/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;form action="/guestbook.jsp" method="get"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;div&amp;gt;&amp;lt;input type="text" name="guestbookName" value="&amp;lt;%= guestbookName %&amp;gt;"/&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;div&amp;gt;&amp;lt;input type="submit" value="Switch Guestbook" /&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;La pàgina guestbook.jsp fa molta de l'operativa del llibre de visites tota sola, però cal alguna cosa més. a&amp;nbsp;&amp;nbsp;a la carpeta&amp;nbsp;appengine-java-sdk/demos/guestbook/src&amp;nbsp;també trobo el codi font del parell de servlets que completen l'aplicació (més un parell de classes auxiliars):&lt;br /&gt;&lt;br /&gt;Els servlets són invocats pels formularis anteriors. A web.xml (a la carpeta&amp;nbsp;appengine-java-sdk/demos/guestbook/war/WEB-INF/web.xml) veig que&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="line" style="font-family: monospace;"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&amp;lt;web-app&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;xmlns&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;http://java.sun.com/xml/ns/javaee&lt;/span&gt;"&lt;/span&gt;&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;version&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;2.5&lt;/span&gt;"&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="collapsible-content" style="font-family: monospace; margin-left: 1em;"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="collapsible" id="collapsible1"&gt;&lt;div class="expanded"&gt;&lt;div class="line"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="button collapse-button" style="-webkit-user-select: none; background-image: -webkit-canvas(arrowDown); background-position: 0% 0%; background-repeat: no-repeat no-repeat; cursor: pointer; display: inline-block; height: 10px; margin-left: -10px; vertical-align: bottom; width: 10px;"&gt;&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;servlet&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="collapsible-content" style="margin-left: 1em;"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;servlet-name&amp;gt;&lt;/span&gt;&lt;span class="text"&gt;&lt;b&gt;guestbook&lt;/b&gt;&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;/servlet-name&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;servlet-class&amp;gt;&lt;/span&gt;&lt;span class="text"&gt;&lt;b&gt;guestbook.GuestbookServlet&lt;/b&gt;&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;/servlet-class&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&amp;lt;/servlet&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="collapsible" id="collapsible2"&gt;&lt;div class="expanded"&gt;&lt;div class="line"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="button collapse-button" style="-webkit-user-select: none; background-image: -webkit-canvas(arrowDown); background-position: 0% 0%; background-repeat: no-repeat no-repeat; cursor: pointer; display: inline-block; height: 10px; margin-left: -10px; vertical-align: bottom; width: 10px;"&gt;&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;servlet-mapping&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="collapsible-content" style="margin-left: 1em;"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;servlet-name&amp;gt;&lt;/span&gt;&lt;span class="text"&gt;guestbook&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;/servlet-name&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;url-pattern&amp;gt;&lt;/span&gt;&lt;span class="text"&gt;/guestbook&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;/url-pattern&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&amp;lt;/servlet-mapping&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="collapsible" id="collapsible3"&gt;&lt;div class="expanded"&gt;&lt;div class="line"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="button collapse-button" style="-webkit-user-select: none; background-image: -webkit-canvas(arrowDown); background-position: 0% 0%; background-repeat: no-repeat no-repeat; cursor: pointer; display: inline-block; height: 10px; margin-left: -10px; vertical-align: bottom; width: 10px;"&gt;&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;servlet&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="collapsible-content" style="margin-left: 1em;"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;servlet-name&amp;gt;&lt;/span&gt;&lt;span class="text"&gt;&lt;b&gt;sign&lt;/b&gt;&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;/servlet-name&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;servlet-class&amp;gt;&lt;/span&gt;&lt;span class="text"&gt;&lt;b&gt;guestbook.SignGuestbookServlet&lt;/b&gt;&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;/servlet-class&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&amp;lt;/servlet&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="collapsible" id="collapsible4"&gt;&lt;div class="expanded"&gt;&lt;div class="line"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="button collapse-button" style="-webkit-user-select: none; background-image: -webkit-canvas(arrowDown); background-position: 0% 0%; background-repeat: no-repeat no-repeat; cursor: pointer; display: inline-block; height: 10px; margin-left: -10px; vertical-align: bottom; width: 10px;"&gt;&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;servlet-mapping&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="collapsible-content" style="margin-left: 1em;"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;servlet-name&amp;gt;&lt;/span&gt;&lt;span class="text"&gt;sign&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;/servlet-name&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;url-pattern&amp;gt;&lt;/span&gt;&lt;span class="text"&gt;/sign&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;/url-pattern&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&amp;lt;/servlet-mapping&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="collapsible" id="collapsible5"&gt;&lt;div class="expanded"&gt;&lt;div class="line"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="button collapse-button" style="-webkit-user-select: none; background-image: -webkit-canvas(arrowDown); background-position: 0% 0%; background-repeat: no-repeat no-repeat; cursor: pointer; display: inline-block; height: 10px; margin-left: -10px; vertical-align: bottom; width: 10px;"&gt;&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;welcome-file-list&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="collapsible-content" style="margin-left: 1em;"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;welcome-file&amp;gt;&lt;/span&gt;&lt;span class="text"&gt;guestbook.jsp&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;/welcome-file&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&amp;lt;/welcome-file-list&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="line" style="font-family: monospace;"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&amp;lt;/web-app&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Per tant &amp;nbsp;/sign es refereix a SignGuestbookServlet.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;package guestbook;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import java.io.IOException;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import java.util.Date;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import java.util.logging.Logger;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import javax.jdo.PersistenceManager;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import javax.servlet.http.*;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.appengine.api.users.User;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.appengine.api.users.UserService;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.appengine.api.users.UserServiceFactory;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import guestbook.Greeting;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import guestbook.PMF;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;public class SignGuestbookServlet extends HttpServlet {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; private static final Logger log = Logger.getLogger(SignGuestbookServlet.class.getName());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public void doPost(HttpServletRequest req, HttpServletResponse resp)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throws IOException {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; UserService userService = UserServiceFactory.getUserService();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; User user = userService.getCurrentUser();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String content = req.getParameter("content");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Date date = new Date();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Greeting greeting = new Greeting(user, content, date);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PersistenceManager pm = PMF.get().getPersistenceManager();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pm.makePersistent(greeting);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } finally {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pm.close();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; resp.sendRedirect("/guestbook.jsp");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;}&lt;/span&gt;&amp;nbsp; &lt;br /&gt;&lt;br /&gt;Hi veig la importació de les classes de l'AppEngine que permeten fer l'autenticació (User, UserService i UserServiceFactory). També fa la importació de les classes auxiliars Greeting i PMF.&lt;br /&gt;&lt;br /&gt;La persistència de dades s'aconsegueix amb&amp;nbsp;&lt;a href="http://code.google.com/intl/ca-ES/appengine/docs/java/datastore/jdo/overview.html"&gt;JDO&lt;/a&gt;. Greeting correspon al model. i PMF és el PersistenceManagerFactory.&lt;br /&gt;&lt;br /&gt;Greeting:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;package guestbook;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import java.util.Date;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import javax.jdo.annotations.IdGeneratorStrategy;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import javax.jdo.annotations.IdentityType;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import javax.jdo.annotations.PersistenceCapable;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import javax.jdo.annotations.Persistent;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import javax.jdo.annotations.PrimaryKey;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.appengine.api.users.User;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;@PersistenceCapable(identityType = IdentityType.APPLICATION)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;b&gt;public class Greeting&lt;/b&gt; {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; @PrimaryKey&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; private Long id;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; @Persistent&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; private User author;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; @Persistent&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; private String content;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; @Persistent&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; private Date date;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public Greeting(User author, String content, Date date) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.author = author;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.content = content;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.date = date;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public Long getId() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return id;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public User getAuthor() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return author;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public String getContent() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return content;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public Date getDate() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return date;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public void setAuthor(User author) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.author = author;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public void setContent(String content) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.content = content;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public void setDate(Date date) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.date = date;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;i PMF:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;package guestbook;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import javax.jdo.JDOHelper;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import javax.jdo.PersistenceManagerFactory;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;public final class PMF {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; private static final PersistenceManagerFactory pmfInstance =&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; JDOHelper.getPersistenceManagerFactory("transactions-optional");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; private PMF() {}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public static PersistenceManagerFactory get() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return pmfInstance;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A&amp;nbsp;appengine-java-sdk/demos/guestbook/war/WEB-INF/classes/META-INF trobarem el fitxer de configuració de JDO: el jdoconfig.xml ,on es diu que es farà servir el appengine per a la persistència.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;jdoconfig&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;xmlns&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;http://java.sun.com/xml/ns/jdo/jdoconfig&lt;/span&gt;"&lt;/span&gt;&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;xmlns:xsi&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;http://www.w3.org/2001/XMLSchema-instance&lt;/span&gt;"&lt;/span&gt;&lt;span class="webkit-html-attribute"&gt;&lt;span class="webkit-html-attribute-name"&gt;xsi:noNamespaceSchemaLocation&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;http://java.sun.com/xml/ns/jdo/jdoconfig&lt;/span&gt;"&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="collapsible-content" style="margin-left: 1em;"&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="collapsible" id="collapsible1"&gt;&lt;div class="expanded"&gt;&lt;div class="line"&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="button collapse-button" style="-webkit-user-select: none; background-image: -webkit-canvas(arrowDown); background-position: 0% 0%; background-repeat: no-repeat no-repeat; cursor: pointer; display: inline-block; height: 10px; margin-left: -10px; vertical-align: bottom; width: 10px;"&gt;&lt;/span&gt;&lt;span class="webkit-html-tag"&gt;&amp;lt;persistence-manager-factory&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;name&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;transactions-optional&lt;/span&gt;"&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="collapsible-content" style="margin-left: 1em;"&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;b&gt;&amp;lt;property&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;name&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;javax.jdo.PersistenceManagerFactoryClass&lt;/span&gt;"&lt;/span&gt;&lt;span class="webkit-html-attribute"&gt;&lt;span class="webkit-html-attribute-name"&gt;value&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory&lt;/span&gt;"&lt;/span&gt;/&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;b&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;b&gt;&amp;lt;property&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;name&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;javax.jdo.option.ConnectionURL&lt;/span&gt;"&lt;/span&gt;&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;value&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;appengine&lt;/span&gt;"&lt;/span&gt;/&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;property&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;name&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;javax.jdo.option.NontransactionalRead&lt;/span&gt;"&lt;/span&gt;&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;value&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;true&lt;/span&gt;"&lt;/span&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;property&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;name&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;javax.jdo.option.NontransactionalWrite&lt;/span&gt;"&lt;/span&gt;&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;value&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;true&lt;/span&gt;"&lt;/span&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;property&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;name&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;javax.jdo.option.RetainValues&lt;/span&gt;"&lt;/span&gt;&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;value&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;true&lt;/span&gt;"&lt;/span&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;property&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;name&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;datanucleus.appengine.autoCreateDatastoreTxns&lt;/span&gt;"&lt;/span&gt;&lt;span class="webkit-html-attribute"&gt;&amp;nbsp;&lt;span class="webkit-html-attribute-name"&gt;value&lt;/span&gt;="&lt;span class="webkit-html-attribute-value"&gt;true&lt;/span&gt;"&lt;/span&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;/persistence-manager-factory&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="text"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="line"&gt;&lt;span class="webkit-html-tag"&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;lt;/jdoconfig&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Amb JDO, gravar la informació és tan senzill com instanciar el model (&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Greeting greeting = new Greeting(user, content, date);&lt;/span&gt;) i fer-lo persistent (&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;pm.makePersistent(greeting);&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;L'altre servlet és GuestbookServlet&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;package guestbook;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import java.io.IOException;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import javax.servlet.http.*;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.appengine.api.users.User;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.appengine.api.users.UserService;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.appengine.api.users.UserServiceFactory;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;public class GuestbookServlet extends HttpServlet {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public void doGet(HttpServletRequest req, HttpServletResponse resp)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throws IOException {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; UserService userService = UserServiceFactory.getUserService();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; User user = userService.getCurrentUser();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (user != null) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; resp.setContentType("text/plain");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; resp.getWriter().println("Hello, " + user.getNickname());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } else {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Aquest segon servlet no s'invoca directament en el codi.&amp;nbsp;Es tracta d'un servlet que ens mostra com utilitzar la Users API per a, depenent de si l'usuari està logat o no, fer una acció o altre.&amp;nbsp;Per a invocar-lo directament faig&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;http://localhost:8080/guestbook.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Suposant que no m'he logat abans (fent click a sign in), El resultat és que es mostra el següent:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-GhXxkSg5krw/Tzw5zRAOZCI/AAAAAAAAAL0/Y27gd3MA6Ek/s1600/2012-02-16-000306_592x430_scrot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="290" src="http://4.bp.blogspot.com/-GhXxkSg5krw/Tzw5zRAOZCI/AAAAAAAAAL0/Y27gd3MA6Ek/s400/2012-02-16-000306_592x430_scrot.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;En l'entorn amb el que faig les proves, la invocació a &amp;nbsp;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;createLoginURL&amp;nbsp;&lt;/span&gt;porta a una pantalla com l'anterior. El que fa el servlet és que si l'usuari no estàlogat, redirecciona a aquesta pantalla de login. Si estiguéssim a l'entorn "de &amp;nbsp;producció" de Google, aleshores ens dirigiríem a la pàgina de login de Google. &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Tornant a l'entorn de prova, si en canvi hagués estat logat &amp;nbsp;obtindria:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-PQHUhgX0o5o/Tzw6-3TB4sI/AAAAAAAAAL8/CHUrEMuExFE/s1600/2012-02-16-000817_592x430_scrot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="290" src="http://3.bp.blogspot.com/-PQHUhgX0o5o/Tzw6-3TB4sI/AAAAAAAAAL8/CHUrEMuExFE/s400/2012-02-16-000817_592x430_scrot.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Una aplicació ben senzilla. Tampoc hi ha gaire cosa a explicar del codi.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Un cop ja tinc l'aplicació en funcionament, ve el moment de desplegar-la en producció. He de fer "el deploy".&lt;br /&gt;&lt;br /&gt;El desplegament és també molt senzill. Primer de tot cal identificar-se al Google App Engine. Accedeixo a la web&amp;nbsp;&lt;a href="http://code.google.com/intl/ca-ES/appengine/"&gt;http://code.google.com/intl/ca-ES/appengine/&lt;/a&gt;&amp;nbsp;i faig click a Sign Up.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-eJnF5GXnH0I/T0DjF9U_PrI/AAAAAAAAAME/9BNEbX1Q1SY/s1600/signup.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="393" src="http://1.bp.blogspot.com/-eJnF5GXnH0I/T0DjF9U_PrI/AAAAAAAAAME/9BNEbX1Q1SY/s400/signup.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;I creo una aplicació. Click a Create Application.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-j54XkM6T5mo/T0Dj6ftXr7I/AAAAAAAAAMM/12fODKX1Kjc/s1600/create.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="237" src="http://4.bp.blogspot.com/-j54XkM6T5mo/T0Dj6ftXr7I/AAAAAAAAAMM/12fODKX1Kjc/s400/create.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Em demana un número de telèfon per verificar la creació &amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-yEewPrn3itM/T0DkmD1f3iI/AAAAAAAAAMU/3rHk4fD-cPM/s1600/verify.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://4.bp.blogspot.com/-yEewPrn3itM/T0DkmD1f3iI/AAAAAAAAAMU/3rHk4fD-cPM/s400/verify.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;Des de Barcelona, el codi de regió és +34. Rebo el codi i l'he de posar a la següent pantalla.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-cTBqdPzqTBY/T0FX9EIMELI/AAAAAAAAANE/SyKA9GaOLb0/s1600/sms.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://1.bp.blogspot.com/-cTBqdPzqTBY/T0FX9EIMELI/AAAAAAAAANE/SyKA9GaOLb0/s400/sms.png" width="321" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Ara he d'emplenar un formulari de registre de l'aplicació. Poso el títol &amp;nbsp;de l'aplicació, i l'identificador. Fixem-nos que aquí es defineix la URL d'accés de l'aplicació. En aquest cas serà&lt;br /&gt;&lt;br /&gt;http://stsoftlliure-proves.appspot.com&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-evzrI3wD_HY/T0FXvRJm1GI/AAAAAAAAAMs/T-zPYjHOUE4/s1600/createapp.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"&gt;&lt;img border="0" height="480" src="http://2.bp.blogspot.com/-evzrI3wD_HY/T0FXvRJm1GI/AAAAAAAAAMs/T-zPYjHOUE4/s640/createapp.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Accepto les condicions del servei i, finalment, l'aplicació queda registrada.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&amp;nbsp;&lt;a href="http://3.bp.blogspot.com/-b3ZKuqu6mJI/T0FXxhI6PlI/AAAAAAAAAM8/YGtuY06FSJw/s1600/registered.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"&gt;&lt;img border="0" height="300" src="http://3.bp.blogspot.com/-b3ZKuqu6mJI/T0FXxhI6PlI/AAAAAAAAAM8/YGtuY06FSJw/s400/registered.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;Ara que ja tinc preparat l'espai on ubicar l'aplicació, faig el deploy des de la línia de comandes, dent servir l'aplicació appcfg.h que es proporciona amb l'SDK de l'App Engine. L'aplicació ens demanarà el correu gmail del compte i el password. Es connectarà a Internet i desplegarà l'aplicació. Fixem-nos que no cal crear un fitxer .war.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;albert@apolo:~/appengine-java-sdk/bin$ &lt;b&gt;appcfg.sh -A stsoftlliure-proves update /home/albert/appengine-java-sdk/demos/guestbook/war&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Reading application configuration data...&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;19/02/2012 13:16:45 com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;INFO: Successfully processed /home/albert/appengine-java-sdk/demos/guestbook/war/WEB-INF/appengine-web.xml&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;2012-02-19 13:16:45.947:INFO::Logging to STDERR via org.mortbay.log.StdErrLog&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;19/02/2012 13:16:46 com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;INFO: Successfully processed /home/albert/appengine-java-sdk/demos/guestbook/war/WEB-INF/web.xml&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;19/02/2012 13:16:46 com.google.apphosting.utils.config.IndexesXmlReader readConfigXml&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;INFO: Successfully processed /home/albert/appengine-java-sdk/demos/guestbook/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Beginning server interaction for stsoftlliure-proves...&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;0% Created staging directory at: '/tmp/appcfg2668004339756750410.tmp'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;5% Scanning for jsp files.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;8% Compiling jsp files.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;19/02/2012 13:16:55 com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;INFO: Successfully processed /tmp/appcfg2668004339756750410.tmp/WEB-INF/web.xml&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;20% Scanning files on local disk.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;25% Initiating update.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;28% Cloning 1 static files.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;31% Cloning 27 application files.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;40% Uploading 1 files.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;52% Uploaded 1 files.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;61% Initializing precompilation...&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;68% Sending batch containing 1 file(s) totaling 1KB.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;90% Deploying new version.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;95% Will check again in 1 seconds.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;98% Will check again in 2 seconds.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;99% Will check again in 4 seconds.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;99% Closing update: new version is ready to start serving.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;99% Uploading index definitions.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Update completed successfully.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Success.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Cleaning up temporary files...&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;albert@apolo:~/appengine-java-sdk/bin$&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;Verifico que la nova aplicació ja és visible al Dashboard...&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&amp;nbsp;&lt;a href="http://2.bp.blogspot.com/-BrJIvY3GCNw/T0FXwThpOoI/AAAAAAAAAM0/wFErWaDKJxA/s1600/dashboard.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"&gt;&lt;img border="0" height="300" src="http://2.bp.blogspot.com/-BrJIvY3GCNw/T0FXwThpOoI/AAAAAAAAAM0/wFErWaDKJxA/s400/dashboard.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;...I ja puc fer servir la meva nova aplicació instal·lada al Google App Engine.&lt;br /&gt;&lt;br /&gt;Accedeixo a l'adreça &lt;a href="http://stsoftlliure-proves.appspot.com/"&gt;http://stsoftlliure-proves.appspot.com&lt;/a&gt;&amp;nbsp;i puc provar l'aplicació:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Tbh4XeFIYF8/T0FXtQ4P5AI/AAAAAAAAAMc/qUxzJPuEwIg/s1600/aplicacio.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://4.bp.blogspot.com/-Tbh4XeFIYF8/T0FXtQ4P5AI/AAAAAAAAAMc/qUxzJPuEwIg/s400/aplicacio.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4788606468171792208-4022367962743234325?l=apuntstecnologia.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apuntstecnologia.blogspot.com/feeds/4022367962743234325/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/12/una-aproximacio-google-app-engine-com.html#comment-form' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/4022367962743234325'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/4022367962743234325'/><link rel='alternate' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/12/una-aproximacio-google-app-engine-com.html' title='Una aproximació a Google App Engine. Com desenvolupar al núvol de Google.'/><author><name>Serveis Tecnològics i Programari Lliure</name><uri>http://www.blogger.com/profile/12434522547196735270</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-PTIg6AKJ6E8/Tv9ngCm5zJI/AAAAAAAAALY/dHy1DqLooow/s72-c/2011-12-31-204924_800x480_scrot.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4788606468171792208.post-4426573041941637987</id><published>2011-12-11T22:18:00.001+01:00</published><updated>2011-12-11T23:25:36.236+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='programari lliure'/><title type='text'>Lubuntu a un Hercules eCafe 800</title><content type='html'>En un &lt;a href="http://apuntstecnologia.blogspot.com/2011/04/hercules-ecafe-ec800-20g-amb-ubentu.html"&gt;post anterior&lt;/a&gt; vam instal·lar &lt;a href="http://www.ubuntu.cat/"&gt;Ubuntu&lt;/a&gt; de la darrera versió Netbook Remix en un petit Hercules eCafe 800.La maquineta ha funcionat prou bé però ha estat evident, des del primer dia, que Gnome li anava gran.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;La solució ha estat posar una distribució més lleugera. En aquest cas la &lt;a href="http://lubuntu.net/"&gt;Lubuntu&lt;/a&gt;. Lubuntu és una distribució que fa servir &lt;a href="http://lxde.org/"&gt;LXDE&lt;/a&gt; com a entorn d'escriptori i &lt;a href="http://wiki.debian.org/Openbox"&gt;OpenBox&lt;/a&gt; com a gestor de finestres, amb la intenció de minimitzar el consum de recursos que calen. Vegeu també&amp;nbsp;&lt;a href="http://ca.wikipedia.org/wiki/Lubuntu"&gt;http://ca.wikipedia.org/wiki/Lubuntu&lt;/a&gt;. Per cert, està disponible en català.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;La instal·lació no ha tingut complicacions: he descarregat la iso de&amp;nbsp;&lt;a href="http://cdimages.ubuntu.com/lubuntu/releases/11.10/release/"&gt;http://cdimages.ubuntu.com/lubuntu/releases/11.10/release/&lt;/a&gt;&amp;nbsp;i he creat un pendrive d'instal·lació.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Per a fer la instal·lació m'ha estat útil connectar un monitor extern, degut a que la petita pantalla de l'eCafe no era suficient per als continguts que s'estaven mostrant. Aquest problema ja el vaig trobar en l'anterior instal·lació de Ubuntu (Gnome), i es resol igual: un cop feta la instal·lació cal afegir el fitxer &lt;a href="http://launchpadlibrarian.net/39792250/xorg.conf"&gt;xorg.conf&lt;/a&gt;&amp;nbsp;a /etc/X11.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Un cop feta la instal·lació i fet l'ajust de pantalla, ja es pot treballar amb el netbook. Ens adonarem d'alguns canvis, per exemple en el programari instal·lat. Per mi el més cridaner ha estat trobar Chromium, el navegador open-source que ha servit de base per a Chrome, en comptes de Firefox. I també trobar Synaptic, en comptes del "Centre de Programari de l'Ubuntu".&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;La millora en la reproducció de vídeos i música és evident. També en la reproducció de vídeos online.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Pegues, de moment, poques. Li he instal·lat Thunderbird, LibreOffice, Skype... i el netbook els mou de forma que són útils. No està gens malament per a aquesta petita maquina.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Potser encara posaré Lubuntu a l'ordinador de sobretaula.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4788606468171792208-4426573041941637987?l=apuntstecnologia.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apuntstecnologia.blogspot.com/feeds/4426573041941637987/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/12/lubuntu-un-hercules-ecafe-800.html#comment-form' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/4426573041941637987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/4426573041941637987'/><link rel='alternate' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/12/lubuntu-un-hercules-ecafe-800.html' title='Lubuntu a un Hercules eCafe 800'/><author><name>Serveis Tecnològics i Programari Lliure</name><uri>http://www.blogger.com/profile/12434522547196735270</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4788606468171792208.post-426224436240006863</id><published>2011-12-06T23:05:00.001+01:00</published><updated>2011-12-18T20:42:05.494+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='programari lliure'/><category scheme='http://www.blogger.com/atom/ns#' term='llibreries'/><title type='text'>Codis QR amb Java i ZXing</title><content type='html'>Cada cop és més comú trobar arreu codis QR. Els codis QR apareixen en promocions i en publicitat de tots tipus. Sens dubte que les aplicacions per a telèfons mòbils que permeten descodificar aquests &amp;nbsp;codis de barres han&amp;nbsp;contribuït&amp;nbsp;a popularitzar los i, a la vegada, són un estímul més per a fer-se amb un smartphone que permeti gaudir-ne d'aquesta capacitat. Es tracta de dues tecnologies que es reforcen l'una a l'altre.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Vet aquí el que en diu la &lt;a href="http://ca.wikipedia.org/wiki/Codi_QR"&gt;Viquipèdia dels codis QR&lt;/a&gt;:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;"El codi QR (en anglès QR Code) és un codi de barres en 2 dimensions (codi matriu) que pot emmagatzemar fins a 7089 caràcters numèrics, 4296 caràcters alfanumèrics (contràriament al codi de barres "tradicional" que només pot emmagatzemar de 10 a 13 caràcters) o 2953 octets .&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;Per accedir a la informació continguda o encriptada en un qr-code, és necessari un dispositiu digital de captura d'imatges ( Ex: càmera de fotos d'un mòbil, webcam...) i un software específic lector de qr-codes.&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;Té l'avantatge de poder emmagatzemar moltes informacions tot i ser petit i ràpid d'escanejar. Així, les sigles «QR» deriven de «Quick Response» ja que el contingut pot ser desxifrat ràpidament.&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;La informació oculta en el codi pot estar en forma de:&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;TEXT&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;URL (ens permetrà visitar una pàgina web concreta amb un sol clic)&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;SMS ( podrem enviar un sms predeterminat a un número de predeterminat amb un sol clic)&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;VCARD (targes de presentació)&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;Les possibilitats i aplicacions d'aquests codis en gestió i màrqueting (especialment en opt-in màrqueting i promocions) són novedoses i interessants ja que mitjançant els codis qr es poden unir dos suports històricament aïllats: paper i internet o tinta i bits.&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;El codi QR ha estat creat per l'empresa japonesa Denso-Wave el 1994. El codi QR és molt emprat al Japó, on actualment és el codi de dues dimensions més popular.&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;L'estàndard japonès per als codis QR, JIS X 0510, ha estat publicat el 1999, i la norma ISO corresponent, ISO/IEC 18004, ha estat aprovada el juny de 2000.&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;b&gt;Un detall important sobre el codi QR, seria que &lt;u&gt;es tracta de codi obert&lt;/u&gt; i els seus drets de patent (propietat de Denso Wave) no són exercits.&lt;/b&gt;"&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;&lt;div&gt;Que els codis QR siguin d'alguna manera codi open source tampoc deu ser aliè al seu èxit.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Però, i com es poden crear codis QQ? i com descodificar-los? Més concretament, com crear o llegir codis QR amb Java ( o amb JVM)? Una cerca ràpida amb Google ens mostra diverses llibreries. Em crida l'atenció la llibreria &lt;a href="http://code.google.com/p/zxing/"&gt;ZXing&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ZXing és una llibreria per al processat d'imatges de codis de barres de 1D/2D per a clients Android i Java.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Dit i fet, descarrego la llibreria (versió 1.7) d'aquí:&amp;nbsp;&lt;a href="http://code.google.com/p/zxing/downloads/detail?name=ZXing-1.7.zip"&gt;http://code.google.com/p/zxing/downloads/detail?name=ZXing-1.7.zip&lt;/a&gt;, i la descomprimeixo.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;El paquet té la següent estructura:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;albert@athena:~/zxing$ ls&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;actionscript &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; androidtest &amp;nbsp;build.properties &amp;nbsp;COPYING &amp;nbsp;csharp &amp;nbsp;javase &amp;nbsp;README &amp;nbsp; zxing.appspot.com&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;android &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AUTHORS &amp;nbsp; &amp;nbsp; &amp;nbsp;build.xml &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; core &amp;nbsp; &amp;nbsp; iphone &amp;nbsp;jruby &amp;nbsp; rim &amp;nbsp; &amp;nbsp; &amp;nbsp;zxingorg&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;android-integration &amp;nbsp;bug &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CHANGES &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cpp &amp;nbsp; &amp;nbsp; &amp;nbsp;javame &amp;nbsp;objc &amp;nbsp; &amp;nbsp;symbian&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;albert@athena:~/zxing$&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Observem que no hi han jars. Cal compilar-los. És tan senzill com, en un terminal, moure's primrer a la carpeta core i executar ant, i després a la carpeta javase i tornar a excutar ant. Cal, evidentment, tenir ant instal·lat.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;De moment, seguiré les instruccions que posen al lloc web de ZXing.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;albert@athena:~/zxing$ cd core&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;albert@athena:~/zxing/core$ ls&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;build &amp;nbsp;build.xml &amp;nbsp;lib &amp;nbsp;pom.xml &amp;nbsp;src &amp;nbsp;test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;albert@athena:~/zxing/core$ ant&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Buildfile: /home/albert/zxing/core/build.xml&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;clean:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp;[delete] Deleting directory /home/albert/zxing/core/build&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;build:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;init:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;compile:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; [mkdir] Created dir: /home/albert/zxing/core/build&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; [javac] Compiling 177 source files to /home/albert/zxing/core/build&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; [javac] 1 warning&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [jar] Building jar: /home/albert/zxing/core/core.jar&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;BUILD SUCCESSFUL&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Total time: 34 seconds&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;albert@athena:~/zxing/core$ cd ../javase&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;albert@athena:~/zxing/javase$ ls&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;build &amp;nbsp;build.xml &amp;nbsp;pom.xml &amp;nbsp;src&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;albert@athena:~/zxing/javase$ ant&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Buildfile: /home/albert/zxing/javase/build.xml&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;init:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;build:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [jar] Building jar: /home/albert/zxing/javase/javase.jar&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;BUILD SUCCESSFUL&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Total time: 6 seconds&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-style-span" style="color: #073763;"&gt;albert@athena:~/zxing/javase$&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;Si examinem de nou les carpetes core i javase trobarem core.jar i javase.jar a les carpetes de mateix nom:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;albert@athena:~/zxing/javase$ ls&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;build &amp;nbsp;build.xml &amp;nbsp;javase.jar &amp;nbsp;pom.xml &amp;nbsp;src&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;albert@athena:~/zxing/javase$ cd ../core&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;albert@athena:~/zxing/core$ ls&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;build &amp;nbsp;build.xml &amp;nbsp;core.jar &amp;nbsp;lib &amp;nbsp;pom.xml &amp;nbsp;src &amp;nbsp;test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-style-span" style="color: #073763;"&gt;albert@athena:~/zxing/core$&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;En aquest moment es pot fer una prova. Faré servir la següent &amp;nbsp;imatge:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-bZczcoINfeY/TuuT0Xy57vI/AAAAAAAAAK0/TlUCBHUyyTc/s1600/sticipl.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-bZczcoINfeY/TuuT0Xy57vI/AAAAAAAAAK0/TlUCBHUyyTc/s1600/sticipl.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I ara, fem la prova executant la classe CommandLineRunner que permet descodificar una imatge:&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;albert@athena:~/zxing$ java -cp javase/javase.jar:core/core.jar com.google.zxing.client.j2se.CommandLineRunner ./sticipl.png&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;file:/home/albert/zxing/./sticipl.png (format: QR_CODE, type: TEXT):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Raw result:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Serveis TIC i Programari Lliure&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Parsed result:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Serveis TIC i Programari Lliure&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Found 4 result points.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; Point 0: (14.0,102.0)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; Point 1: (14.0,14.0)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; Point 2: (102.0,14.0)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; Point 3: (90.0,90.0)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-style-span" style="color: #073763;"&gt;albert@athena:~/zxing$&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Pel que fa a la documentació, el javadoc de ZXing el podem trobar a&amp;nbsp;&lt;a href="http://zxing.org/w/docs/javadoc/index.html"&gt;http://zxing.org/w/docs/javadoc/index.html&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;També ens pot ajudar la pàgina de les DeveloperNotes (&lt;a href="http://code.google.com/p/zxing/wiki/DeveloperNotes"&gt;http://code.google.com/p/zxing/wiki/DeveloperNotes&lt;/a&gt;)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;El que faré serà un parell de programes d'exemple, un per a crear codis de barra &amp;nbsp;QR i un altre per a descodificar-los. Un coder i un decoder d'exemple.&lt;br /&gt;&lt;br /&gt;Primer de tot, el decoder. L'aplicaré al següent QR:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-zOESFDCa1CE/Tu0RvXLEeCI/AAAAAAAAAK8/VPViRmLz_rI/s1600/albert.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-zOESFDCa1CE/Tu0RvXLEeCI/AAAAAAAAAK8/VPViRmLz_rI/s1600/albert.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Vet aquí el codi:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;package com.sticipl.prova.zxing;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.zxing.Reader;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.zxing.qrcode.QRCodeReader;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.zxing.client.j2se.BufferedImageLuminanceSource;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.zxing.LuminanceSource;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.zxing.common.HybridBinarizer;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.zxing.BinaryBitmap;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.zxing.BarcodeFormat;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.zxing.ResultPoint;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import com.google.zxing.Result;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import java.awt.image.BufferedImage;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import java.io.File;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import javax.imageio.ImageIO;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;public class ProvaZxing {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public ProvaZxing() {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;try {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Reader reader = new QRCodeReader(); &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BufferedImage myImage = ImageIO.read(&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new File("/home/albert/Workspace/wk-java/prova-zxing/img/albert.png")&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; );&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LuminanceSource source = new BufferedImageLuminanceSource(myImage);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Result result = reader.decode(bitmap);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String text = result.getText();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println("Text llegit: " + text);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; byte[] rawBytes = result.getRawBytes();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (byte byteElem : rawBytes) {&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println("Byte: " + byteElem);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BarcodeFormat format = result.getBarcodeFormat();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println("Format del codi: " + format);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ResultPoint[] punts = result.getResultPoints(); &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (ResultPoint punt : punts) {&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println("Punt.x: " + punt.getX() + "; Punt.y: " + punt.getY());&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; } catch(Exception e) {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println("Error: " + e.toString()); &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; } &amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;&amp;nbsp;   &lt;/span&gt;public static void main(String args[]) {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new ProvaZxing();&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;El programa és directe: instancia un reader del tipus QRCodeReader, crea una BufferedImage a partir de la imatge del &amp;nbsp;QR. El reader s'aplica al QRReder i, senzillament, el descodifica. El resultat s'obté en diferents formats.&lt;br /&gt;&lt;br /&gt;L'aplicació del programa sobre la darrera imatge proporciona la sortida:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Text llegit: Albert Baranguer Codina&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 65&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 116&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 22&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: -58&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 38&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 87&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 39&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 66&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 4&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 38&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 23&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 38&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 22&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: -26&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 119&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 86&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 87&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 34&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 4&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 54&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: -10&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 70&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: -106&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: -26&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 16&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: -20&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: 17&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Byte: -20&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Format del codi: QR_CODE&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Punt.x: 14.0; Punt.y: 86.0&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Punt.x: 14.0; Punt.y: 14.0&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Punt.x: 86.0; Punt.y: 14.0&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Punt.x: 74.0; Punt.y: 74.0&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;La creació de codis QR no té dificultat i segueix un procediment similar al de la descodificació: primer de tot, cal instanciar un QRCodeWriter i amb aquesta instància, directament es codifica la informació. El resultat és una matriu de bits que es fa servir per a crear una BufferedImage. Vet aquí el mètode codifica(String sText), que rep com a argument el text a codificar&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: #073763;"&gt;// genera un codi QR per al text passat&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public void codifica(String sCadena) {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; try { &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Writer writer = new QRCodeWriter();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BitMatrix bitmat = writer.encode(sCadena, BarcodeFormat.QR_CODE, 200, 200);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // genera la imatge.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Obté ample i alt&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int width = bitmat.getWidth();&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int height = bitmat.getHeight();&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // crea BufferedImage&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BufferedImage imatge = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // estableix els bits de la imatge (true, negre; false, blanc)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (int y = 0; y &amp;lt; height; y++) {&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (int x = 0; x &amp;lt; width; x++) {&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;boolean boolPunt = bitmat.get(x,y);&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;imatge.setRGB(x, y, (boolPunt ? 0 : 0xFFFFFF));&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // genera el fitxer d'imatge a partir de la BufferedImage&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; File file = new File("/home/albert/Workspace/wk-java/prova-zxing/img/generat.png");&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FileOutputStream fos = new FileOutputStream(file);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ImageIO.write(imatge, "png", fos);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fos.flush();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fos.close();&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; } catch(Exception e) {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;System.out.println("Error: " + e.toString()); &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; } &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Aplicant el mètode amb els argument mostrats:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public static void main(String args[]) {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ProvaZxing prova = new ProvaZxing();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // prova.decode();&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; prova.codifica("Generat amb Zxing - Serveis TIC i Programari Lliure - Albert Baranguer Codina - accents: àèò éíóú ç ñ ...");&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-style-span" style="color: #073763;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;obtinc la imatge:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-IAaB0D985wU/Tu4-os5MwFI/AAAAAAAAALE/I9-6qeddbwM/s1600/albert.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-IAaB0D985wU/Tu4-os5MwFI/AAAAAAAAALE/I9-6qeddbwM/s1600/albert.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Per acabar, una altre imatge generada amb el mètode codifica(). Endevineu quin és el text que amaga?&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-xE1HL0_4yRo/Tu5A0c91p9I/AAAAAAAAALM/aQlPDvLsoIg/s1600/url-sticipl.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-xE1HL0_4yRo/Tu5A0c91p9I/AAAAAAAAALM/aQlPDvLsoIg/s1600/url-sticipl.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4788606468171792208-426224436240006863?l=apuntstecnologia.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apuntstecnologia.blogspot.com/feeds/426224436240006863/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/12/codis-qr-amb-java-i-zxing.html#comment-form' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/426224436240006863'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/426224436240006863'/><link rel='alternate' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/12/codis-qr-amb-java-i-zxing.html' title='Codis QR amb Java i ZXing'/><author><name>Serveis Tecnològics i Programari Lliure</name><uri>http://www.blogger.com/profile/12434522547196735270</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-bZczcoINfeY/TuuT0Xy57vI/AAAAAAAAAK0/TlUCBHUyyTc/s72-c/sticipl.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4788606468171792208.post-1579056620546530247</id><published>2011-11-20T22:21:00.001+01:00</published><updated>2011-11-25T01:15:11.582+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='programari lliure'/><category scheme='http://www.blogger.com/atom/ns#' term='groovy'/><title type='text'>Groovy i HSQLDB</title><content type='html'>Groovy aporta classes per al treball amb bases de dades que permeten un increment de la productivitat en el desenvolupament de codi d'aplicacions que en facin us.&lt;br /&gt;&lt;br /&gt;Dit d'una altre forma: Groovy permet simplificar el codi de les aplicacions de bases de dades. &amp;nbsp;Res millor que un exemple.&lt;br /&gt;&lt;br /&gt;En l'exercici que es proposa faré us de la base de dades HSQLDB, que és el motor de base de dades que es fa servir, per exemple, &amp;nbsp;a les suites ofimàtiques OpenOffice.org i LibreOffice.&lt;br /&gt;&lt;br /&gt;Per a poder utilitzar HSQLDB des de Groovy cal afegir el hsqldb.jar a les llibreries que es carreguen a l'inici. En el cas que m'ocupa, un Groovy sobre Linux Ubuntu, cal revisar el fitxer $GROOVY_HOME/conf/groovy-starter.conf en el que es pot trobar el següent:&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; # load user specific libraries&lt;br /&gt;&amp;nbsp; &amp;nbsp; load !{user.home}/.groovy/lib/*.jar&lt;br /&gt;&lt;br /&gt;Tinc l'HSQLDB instal·lat a una carpeta apart. Per tant, per evitar duplicitats, en comptes de posar l'hsqldb.jar a $HOME/.groovy/lib, el que faig és posar en aquesta carpeta un enllaç simbòlic al jar que hi ha a la carpeta on està desplegat el motor de la base de dades.&lt;br /&gt;&lt;br /&gt;A continuació, creo una base de dades del tipus fitxer i standalone. Cal dir que HSQLDB pot funcionar en "mode servidor" o &amp;nbsp;bé en "mode standalone". A més, també pot funcionar o bé mantenint les dades en un fitxer, o bé "mantenint" les dades en memòria (evidentment, només es "mantenen" mentre el procés és viu).&lt;br /&gt;&lt;br /&gt;Per a crear la taula es pot fer servir, per exemple, l'OpenOffice.org/LibreOffice Base. En aquest cas caldria afegir hsqldb.jar al classpath de l'OOo/LO (eines - opcions - java)&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-Vt0_zdJcJN8/Ts6ssFnVvGI/AAAAAAAAAKQ/iOLVbjBBOEA/s1600/Captura-Opcions+-+LibreOffice+-+Java.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="197" src="http://3.bp.blogspot.com/-Vt0_zdJcJN8/Ts6ssFnVvGI/AAAAAAAAAKQ/iOLVbjBBOEA/s400/Captura-Opcions+-+LibreOffice+-+Java.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;i camí a les classes:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-SgVlEJlFeHk/Ts6srg_jk2I/AAAAAAAAAKM/mOEEkFMPots/s1600/Captura-Cam%25C3%25AD+a+les+classes.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="185" src="http://1.bp.blogspot.com/-SgVlEJlFeHk/Ts6srg_jk2I/AAAAAAAAAKM/mOEEkFMPots/s400/Captura-Cam%25C3%25AD+a+les+classes.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;i, a continuació, crearia una base de dades del tipus Jdbc.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-kzaHUllslO0/Ts6ssipmpkI/AAAAAAAAAKY/al7lxV8GXd0/s1600/Captura-Propietats+de+la+base+de+dades.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="272" src="http://1.bp.blogspot.com/-kzaHUllslO0/Ts6ssipmpkI/AAAAAAAAAKY/al7lxV8GXd0/s400/Captura-Propietats+de+la+base+de+dades.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;En el meu cas, la base de dades la fico a Documentes/databases/hsqldb/prova.db, per tant la URL JDBC que he de fer servir és:&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;jdbc:hsqldb:/home/albert/Documents/databases/hsqldb/prova.db&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;i el driver:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;org.hsqldb.jdbc.JDBCDriver&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(canviar aquesta imatge)&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-sZln1fLvUwA/TsqnrEmCUhI/AAAAAAAAAJ0/wbB3_zwS4mI/s1600/Captura-Propietats+de+la+base+de+dades.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="218" src="http://1.bp.blogspot.com/-sZln1fLvUwA/TsqnrEmCUhI/AAAAAAAAAJ0/wbB3_zwS4mI/s320/Captura-Propietats+de+la+base+de+dades.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Això em permetrà fer servir l'assistent de l'OOo/LO per a definir la taula i els tipus de dades. Creo una taula diccionari amb tres columnes: id (enter), nom (varchar de 100) i valor (varchar de 100).&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-VeVtSS3_nUk/TsqowITu1EI/AAAAAAAAAKE/5SAsJzz5Lgc/s1600/table-Design.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="246" src="http://2.bp.blogspot.com/-VeVtSS3_nUk/TsqowITu1EI/AAAAAAAAAKE/5SAsJzz5Lgc/s320/table-Design.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;I &amp;nbsp;un cop creada la taula, la informo amb algunes dades de prova:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/--whz5RfJ5s4/TsqovqW_ckI/AAAAAAAAAJ8/9cVP83HkxcA/s1600/Data-View.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/--whz5RfJ5s4/TsqovqW_ckI/AAAAAAAAAJ8/9cVP83HkxcA/s1600/Data-View.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Probablement la classe més útil de Groovy per al treball amb bases de dades sigui groovy.sql.Sql. &amp;nbsp;Aquesta classe és una mena de navalla suïssa que proporciona una varietat de mètodes per a fer gairebé totes les tasques comuns amb taules.&lt;br /&gt;&lt;br /&gt;La pàgina de la documentació de &lt;a href="http://groovy.codehaus.org/api/groovy/sql/Sql.html"&gt;groovy.sql.Sql&lt;/a&gt; ens explica les possibilitats d'aquesta navalla&amp;nbsp;suïssa.&lt;br /&gt;&lt;br /&gt;Per a utilitzar-la &amp;nbsp;cal importar-la&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;import groovy.sql.Sql&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A continuació puc configurar la connexió a la base de dades que he creat fa un moment:&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;def ds = [url:'jdbc:hsqldb:/home/albert/Documents/databases/hsqldb/prova.db',&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; user:'sa',&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; password:'',&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; driver:'org.hsqldb.jdbc.JDBCDriver']&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;def sql = Sql.newInstance(ds.url, ds.user, ds.password, ds.driver)&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Consulto la taula que he creat amb el OOo/LO amb el potent mètode eachRow, adonem-nos com la fila en curs és accessible amb 'it':&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sql.eachRow("select * from public.\"diccionari\" where \"id\" &amp;gt;= 3") {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; println "id = ${it.id}; nom = ${it.nom}; valor = ${it.valor}"&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;i el resultat és&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~/Workspace/wk-groovy/prova-jdbc$ groovy provabd.groovy&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 3; nom = nom3; valor = valor3&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 4; nom = nom4; valor = valor3&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 5; nom = nom5; valor = valor5&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Creo una nova taula i la informo amb dades. Cal tenir en compte algunes particularitats de l'SQL de &amp;nbsp;l'HSQLDB: els noms de les taules han d'anar precedides de l'esquema; els noms de taules, columnes i&amp;nbsp;&amp;nbsp;d'altres objectes van entre cometes dobles; els literals van entre comentes simples.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sql.execute '''&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;create table public.\"traductor\" (&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp;\"id\" integer not null,&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp;\"catala\" varchar(100),&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp;\"castella\" varchar(100),&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;'''&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Faig insert de dades amb diferents mètodes:&lt;br /&gt;&lt;br /&gt;- fent servir la sintaxi amb '''&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sql.execute '''&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;insert into public.\"traductor\"(\"id\",\"catala\",\"castella\") values (1, 'catala 1','castella 1')&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;'''&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;println "inserta fila 1"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;- &amp;nbsp;fent servir la sintaxi de preparedStatement de JDBC&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;def params = [2, 'catala 2', 'castella 2']&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sql.execute("insert into public.\"traductor\" (\"id\", \"catala\", \"castella\") values (?, ?, ?)", params)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;println "inserta fila 2"&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;params = [3, 'catala 3', 'castella 3']&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sql.execute("insert into public.\"traductor\" (\"id\", \"catala\", \"castella\") values (?, ?, ?)", params)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;println "inserta fila 3"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;- fent servir la sintaxi GString&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;def map = [id:4, catala:'català 4', castella:'castellà 4']&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sql.execute("insert into public.\"traductor\" (\"id\", \"catala\", \"castella\") values ($map.id, $map.catala, $map.castella)")&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;println "inserta fila 4"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Visualitzo els resultats amb eachRow, ara fent servir el paràmetre fila a la closure, en comptes d'it.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sql.eachRow("select * from public.\"traductor\"") {fila -&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; println "id = $fila.id; català = $fila.catala; castellà = $fila.castella"&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Després d'aquestes accions, tinc les dues taules amb dades, com puc veure amb l'OOo/LO&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-dqFKNti1L2U/Ts7IBE1ZnZI/AAAAAAAAAKk/S0JU2nhaQVo/s1600/diccionari.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="292" src="http://4.bp.blogspot.com/-dqFKNti1L2U/Ts7IBE1ZnZI/AAAAAAAAAKk/S0JU2nhaQVo/s320/diccionari.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-R-tdVQfA0GQ/Ts7IBtiqq4I/AAAAAAAAAKo/oq0GUp3_aKI/s1600/traductor.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="269" src="http://1.bp.blogspot.com/-R-tdVQfA0GQ/Ts7IBtiqq4I/AAAAAAAAAKo/oq0GUp3_aKI/s320/traductor.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;He fet inserts, evidentment també es poden fer update, delete... fent servir execute, o millor &amp;nbsp;executeUpdate, que em retorna una llista de les files afectades.&lt;br /&gt;&lt;br /&gt;eachRow admet paginació. He afegit algunes dades més a la taula traductor i la visualitzo, primer tota i després mostrant només quatre files a partir de la fila tres:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;println "mostra la taula \"traductor\""&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sql.eachRow("select * from public.\"traductor\"") {fila -&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; println "id = $fila.id; català = $fila.catala; castellà = $fila.castella"&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;println "mostra 4 files de la taula \"traductor\" a partir de la fila 3"&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sql.eachRow("select * from public.\"traductor\"", 3, 4 ) {fila -&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; println "id = $fila.id; català = $fila.catala; castellà = $fila.castella"&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;El resultat és:&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;mostra la taula "traductor"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 1; català = catala 1; castellà = castella 1&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 2; català = catala 2; castellà = castella 2&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 3; català = catala 3; castellà = castella 3&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 4; català = català 4; castellà = castellà 4&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 5; català = catala 5; castellà = castella 5&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 6; català = catala 6; castellà = castella 6&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 7; català = catala 7; castellà = castella 7&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 8; català = català 8; castellà = castellà 8&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;mostra 4 files de la taula "traductor" a partir de la fila 3&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 3; català = catala 3; castellà = castella 3&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 4; català = català 4; castellà = castellà 4&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 5; català = catala 5; castellà = castella 5&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 6; català = catala 6; castellà = castella 6&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;La classe groovy.sql.Sql té altres mètodes que també permeten augmentar la productivitat del desenvolupament, que s'afegeixen al fet que els scripts en Groovy no requereixen compilació.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;groovy.sql.Sql també té mètodes que retornen ResultSet de jdbc, permetent el tractament típic de Java.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;El package groovy.sql també inclou la classe &amp;nbsp;DataSet que deriva de groovy.sql.Sql i que permet fer queries a la base de dades fent servir operadors i noms de camps de Groovy en comptes de crides a API JDBC i noms de taules i columnes. Un petit exemple:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Primer de tot, cal importar DataSet&lt;/div&gt;&lt;div&gt;import groovy.sql.DataSet&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;i ja el puc fer servir:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;primer mostro el contingut de la taula amb eachRow d'Sql i després fa la query amb DataSet&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;println "mostra la taula \"traductor\""&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sql.eachRow("select * from public.\"traductor\"") {fila -&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; println "id = $fila.id; català = $fila.catala; castellà = $fila.castella"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;println "mostra valors amb id entre 3 i 7 fent servir la classe DataSet"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;def traduccions = sql.dataSet("public.\"traductor\"")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;def filtrat = traduccions.findAll {it."\"id\"" &amp;gt;= 3 &amp;amp;&amp;amp; it."\"id\"" &amp;lt;= 7 }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;filtrat.each { fila -&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; println "id = $fila.id; català = $fila.catala; castellà = $fila.castella"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;El resultat és el següent&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;mostra la taula "traductor"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 1; català = catala 1; castellà = castella 1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 2; català = catala 2; castellà = castella 2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 3; català = catala 3; castellà = castella 3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 4; català = català 4; castellà = castellà 4&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 5; català = catala 5; castellà = castella 5&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 6; català = catala 6; castellà = castella 6&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 7; català = catala 7; castellà = castella 7&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 8; català = català 8; castellà = castellà 8&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;mostra valors amb id entre 3 i 7 fent servir la classe DataSet&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 3; català = catala 3; castellà = castella 3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 4; català = català 4; castellà = castellà 4&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 5; català = catala 5; castellà = castella 5&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 6; català = catala 6; castellà = castella 6&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id = 7; català = catala 7; castellà = castella 7&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;En aquest exemple les particularitats de HSQLDB pel que fa als noms de taules i columnes entre cometes &amp;nbsp;no permeten aprofitar la simplificació de fer servir els noms de les columnes com si fossin noms de camps Groovy de l'objecte it. Però, si més no, es permet veure l'ús de l'operador &amp;amp;&amp;amp; per a construir el "where" del Dataset&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I finalment, per acabar...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;// tanca la connexió&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sql.close()&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4788606468171792208-1579056620546530247?l=apuntstecnologia.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apuntstecnologia.blogspot.com/feeds/1579056620546530247/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/11/groovy-i-hsqldb.html#comment-form' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/1579056620546530247'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/1579056620546530247'/><link rel='alternate' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/11/groovy-i-hsqldb.html' title='Groovy i HSQLDB'/><author><name>Serveis Tecnològics i Programari Lliure</name><uri>http://www.blogger.com/profile/12434522547196735270</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-Vt0_zdJcJN8/Ts6ssFnVvGI/AAAAAAAAAKQ/iOLVbjBBOEA/s72-c/Captura-Opcions+-+LibreOffice+-+Java.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4788606468171792208.post-2649383999713432981</id><published>2011-11-01T23:04:00.004+01:00</published><updated>2011-11-01T23:04:52.057+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='programari lliure'/><category scheme='http://www.blogger.com/atom/ns#' term='llibreries'/><title type='text'>Un "Piulador" amb Twitter4J amb gestió de l'autenticació</title><content type='html'>En el post anterior vaig fer un "piulador" personal que em permet enviar tweets (o piulades) al compte associat a l'Access Token.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Per obtenir l'Access Token i l'Access Token Secret va caldre demanar-los a la web de Twitter. Els valors que em va proporcionar Twitter &amp;nbsp;els vaig fer servir posant-los a l'objecte de la classe ConfigurationBuilder que passava com argument al constructor de l'objecte de la classe Twitter que és el que permet l'operació.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Un cop obtinguts l'Access Token i l'Access Token Secretm aquests dos valors els podrà fer servir el Piulador indefinidament. L'usuari pot, però, forçar que se'n generin de nous des de la web de Twitter.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Per a que el "Piulador" el pugui fer servir tothom que tingui un compte a Twitter cal que sigui el mateix piulador qui el demani i en gestioni l'obtenció. Això és el que faré avui.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;El codi del partida és el Piulador del post anterior:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;package com.sticipl.proves;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.Status;&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.Twitter;&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.TwitterException;&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.TwitterFactory;&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.conf.ConfigurationBuilder;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="font-size: xx-small;"&gt;&lt;br style="background-color: white;" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: x-small;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;public final class ProvaTwitter {&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; /**&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* Usage: java twitter4j.examples.tweets.UpdateStatus [text]&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* @param args message&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public static void main(String[] args) {&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;ConfigurationBuilder cb = new ConfigurationBuilder();&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;cb.setDebugEnabled(true)&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;.setOAuthConsumerKey("[El consumer Key obtingut]")&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;.setOAuthConsumerSecret("[el consumer secret obtingut]")&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;.setOAuthAccessToken("[l'access token obtingut]")&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;.setOAuthAccessTokenSecret("[l'access token secret obtingut]");&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;TwitterFactory tf = new TwitterFactory(cb.build());&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Twitter twitter = tf.getInstance();&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Status status = twitter.updateStatus("Aquest és el missatge enviat des de l'aplicació #Java de prova fent us de #Twitter4J");&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println("Actualitzat status a [" + status.getText() + "].");&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.exit(0);&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (TwitterException te) {&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; te.printStackTrace();&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println("Excepció de Twitter: " + te.getMessage());&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.exit(-1);&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18px;" /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;El que cal fer és canviar el bloc de codi del ConfigurationBuilder per un bloc de codi que en gestioni l'obtenció del parell Access Token / Access Token Secret.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Al post anterior vaig dir que el Consumer ha de demanar l'autorització de l'usuari amb un Request Token i que aquest Request Token es bescanvia per l'Access Token. &amp;nbsp;Com es fa això? A la secció dels &lt;a href="http://twitter4j.org/en/code-examples.html"&gt;exemples de codi de la web Twitter4J&lt;/a&gt; expliquen com:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;ol class="main" style="background-color: white; color: #331144; font-family: Verdana, Arial, sans-serif; font-size: 14px; text-align: left;"&gt;With OAuth authorization scheme, an application can access the user account without userid/password combination given. You need to register your application at&lt;a href="http://twitter.com/oauth_clients/new" style="color: #004499; text-decoration: none;"&gt;http://twitter.com/oauth_clients/new&lt;/a&gt;&amp;nbsp;to acquire consumer key, and consumer secret in advance. key / secret pair can be set via&amp;nbsp;&lt;a href="http://twitter4j.org/en/javadoc/twitter4j/Twitter.html#setOAuthConsumer(java.lang.String,%20java.lang.String)" style="color: #004499; text-decoration: none;"&gt;Twitter#setOAuthConsumer()&lt;/a&gt;, or following system properties:&lt;br /&gt;&lt;br /&gt;&lt;pre class="codeSample" style="background-color: #ffffdd; border-bottom-color: rgb(170, 170, 153); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(170, 170, 153); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 153); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 153); border-top-style: solid; border-top-width: 1px; overflow-x: auto; overflow-y: hidden; padding-bottom: 3px; padding-left: 3px; padding-right: 3px; padding-top: 3px; width: 543px;"&gt;-Dtwitter4j.oauth.consumerKey=[consumer key]&lt;br /&gt;-Dtwitter4j.oauth.consumerSecret=[consumer secret]&lt;/pre&gt;&lt;ol class="main" style="background-color: white; color: #331144; font-family: Verdana, Arial, sans-serif; font-size: 14px; text-align: left;"&gt;&lt;br /&gt;&lt;/ol&gt;Initially, you don't have a permission to access the user's account and need to acquire access token by redirecting the user to an authorization URL as follows:&lt;/ol&gt;&lt;ol class="main" style="background-color: white; color: #331144; font-family: Verdana, Arial, sans-serif; font-size: 14px; text-align: left;"&gt;&lt;br /&gt;&lt;pre class="codeSample" style="background-color: #ffffdd; border-bottom-color: rgb(170, 170, 153); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(170, 170, 153); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 153); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 153); border-top-style: solid; border-top-width: 1px; overflow-x: auto; overflow-y: hidden; padding-bottom: 3px; padding-left: 3px; padding-right: 3px; padding-top: 3px; width: 543px;"&gt;  public static void main(String args[]) thrwos Exception{&lt;br /&gt;    // The factory instance is re-useable and thread safe.&lt;br /&gt;    Twitter twitter = new TwitterFactory().getInstance();&lt;br /&gt;    twitter.setOAuthConsumer("[consumer key]", "[consumer secret]");&lt;br /&gt;    RequestToken requestToken = twitter.getOAuthRequestToken();&lt;br /&gt;    AccessToken accessToken = null;&lt;br /&gt;    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;    while (null == accessToken) {&lt;br /&gt;      System.out.println("Open the following URL and grant access to your account:");&lt;br /&gt;      System.out.println(requestToken.getAuthorizationURL());&lt;br /&gt;      System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:");&lt;br /&gt;      String pin = br.readLine();&lt;br /&gt;      try{&lt;br /&gt;         if(pin.length() &amp;gt; 0){&lt;br /&gt;           accessToken = twitter.getOAuthAccessToken(requestToken, pin);&lt;br /&gt;         }else{&lt;br /&gt;           accessToken = twitter.getOAuthAccessToken();&lt;br /&gt;         }&lt;br /&gt;      } catch (TwitterException te) {&lt;br /&gt;        if(401 == te.getStatusCode()){&lt;br /&gt;          System.out.println("Unable to get the access token.");&lt;br /&gt;        }else{&lt;br /&gt;          te.printStackTrace();&lt;br /&gt;        }&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;    //persist to the accessToken for future reference.&lt;br /&gt;    storeAccessToken(twitter.verifyCredentials().getId() , accessToken);&lt;br /&gt;    Status status = twitter.updateStatus(args[0]);&lt;br /&gt;    System.out.println("Successfully updated the status to [" + status.getText() + "].");&lt;br /&gt;    System.exit(0);&lt;br /&gt;  }&lt;br /&gt;  private static void storeAccessToken(int useId, AccessToken accessToken){&lt;br /&gt;    //store accessToken.getToken()&lt;br /&gt;    //store accessToken.getTokenSecret()&lt;br /&gt;  }&lt;/pre&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;El que faig és adaptar aquest codi al meu piulador:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;package com.sticipl.proves;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import java.io.BufferedReader;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import java.io.FileWriter;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import java.io.InputStreamReader;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import java.io.PrintWriter;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.Status;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.Twitter;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.TwitterException;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.TwitterFactory;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.auth.AccessToken;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.auth.RequestToken;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;public final class ProvaTwitter {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private Twitter twitter;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private BufferedReader br;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; /**&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* Usage: java twitter4j.examples.tweets.UpdateStatus [text]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* @param args message&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public static void main(String[] args) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new ProvaTwitter();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;public ProvaTwitter() {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;try {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; twitter = new TwitterFactory().getInstance();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AutenticaConsumer();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Status status = twitter.updateStatus("Aquest és el missatge enviat des de l'aplicació #Java de prova fent us de #Twitter4J. Versió 2");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println("Actualitzat status a [" + status.getText() + "].");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.exit(0);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (TwitterException te) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; te.printStackTrace();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println("Excepció de Twitter: " + te.getMessage());&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.exit(-1);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (Exception e) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; e.printStackTrace();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println("Excepció general: " + e.getMessage());&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.exit(-2); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;private void AutenticaConsumer() throws Exception{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;twitter.setOAuthConsumer("[consumer key]", "[consumer key secret]");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;RequestToken requestToken = twitter.getOAuthRequestToken();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;AccessToken accessToken = null;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;br = new BufferedReader(new InputStreamReader(System.in));&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;while (null == accessToken) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;System.out.print("Entra el nom d'aquest perfil d'accés a Twitter:");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;String sNomPerfil = br.readLine();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;System.out.println("Obre la següent URL a un navegador, identifica't amb el teu compte de twitter i autoritza al piulador:");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;System.out.println(requestToken.getAuthorizationURL());&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;System.out.print("Entra el PIN(si està disponible) i prem enter:");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;String pin = br.readLine();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;try {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;if(pin.length() &amp;gt; 0) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;     &lt;/span&gt;accessToken = twitter.getOAuthAccessToken(requestToken, pin);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;} else {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;     &lt;/span&gt;accessToken = twitter.getOAuthAccessToken();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;//persist to the accessToken for future reference.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;storeAccessToken(sNomPerfil, twitter.verifyCredentials().getId() , accessToken);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;} catch (TwitterException te) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;if (401 == te.getStatusCode()) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;     &lt;/span&gt;System.out.println("No ha pogut obtenir l'Access Token.");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;} else {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;     &lt;/span&gt;te.printStackTrace();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; private &amp;nbsp;void storeAccessToken(String sNomPerfil, long l, AccessToken accessToken){&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;// guarda un fitxer amb:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;// nom del perfil a guardar&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;// twitter.verifyCredentials().getId()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;// guarda accessToken.getToken()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;// guarda accessToken.getTokenSecret()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;FileWriter fitxer = null;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;PrintWriter pw = null;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;try {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;fitxer = new FileWriter("./twitter-access-token.txt");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;pw = new PrintWriter(fitxer);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;pw.println("Nom perfil: " + sNomPerfil );&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;pw.println("twitter.verifyCredentials().getId(): " + l );&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;pw.println("Access Token: " + accessToken.getToken() );&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;pw.println("Access Token Secret: " + accessToken.getTokenSecret() );&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;} catch (Exception e) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;e.printStackTrace();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;} finally {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;try {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;if (null != fitxer)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;    &lt;/span&gt;fitxer.close();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; } catch (Exception e2) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;e2.printStackTrace();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;} &amp;nbsp; &amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; } &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I l'executo:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Des del main s'invoca al constructor , el qual, primer de tot, va al mètode AutenticaConsumer, que és el que fa la negociació OAuth.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;A AutenticaConsumer, &amp;nbsp;s'estableixen el Consumer Key i el Cosumer Key Secret i, a continuació s'obté un Request Token.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Entra el nom d'aquest perfil d'accés a Twitter:sticipl&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;A continuació demana un nom de perfil d'accés al twitter per a identificar-lo en futures connexions. La idea és que guarda a un fitxer el nom del perfil i l'Access Token i l'Access Token Secret, de forma que per a futures connexions amb aquest perfil, &amp;nbsp;podria fer servir directament aquests valors emmagatzemats localment, en comptes d'haver de tornar a demanar accés. &amp;nbsp;En aquesta versió&amp;nbsp;genera el fitxer, però&amp;nbsp;no està implementada la &amp;nbsp;recuperació per perfil de l'Acces Token. No costaria gaire fer-ho, però potser millor amb una bd HSQLDB que amb un fitxer pla.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Amb el Request Token obté la URL d'autorització. L'usuari ha d'anar a aquesta URL, identificar-se amb el compte de Twitter amb el que vol fer servir el piulador, i autoritzar al Piulador a poder enviar missatges.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Obre la següent URL a un navegador, identifica't amb el teu compte de twitter i autoritza al piulador:&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;http://api.twitter.com/oauth/authorize?oauth_token=&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Dit i fet, copio la URL i l'enganxo a un navegador. Vaig a la web d'Autorització de Twitter. Com que ja estava logat a Twitter amb el compte de sticipl, aquesta és el compte per al que s'autoritzarà el Piulador. Però podria haver sortit i haver-me logat de nou amb un compte diferent :&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-i5ziopzxTUU/TrBoWSthAwI/AAAAAAAAAJU/dYkrVkxVWlg/s1600/Captura.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;br /&gt;&lt;/a&gt;&lt;a href="http://4.bp.blogspot.com/-i5ziopzxTUU/TrBoWSthAwI/AAAAAAAAAJU/dYkrVkxVWlg/s1600/Captura.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;br /&gt;&lt;/a&gt;&lt;a href="http://4.bp.blogspot.com/-i5ziopzxTUU/TrBoWSthAwI/AAAAAAAAAJU/dYkrVkxVWlg/s1600/Captura.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/-i5ziopzxTUU/TrBoWSthAwI/AAAAAAAAAJU/dYkrVkxVWlg/s1600/Captura.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://4.bp.blogspot.com/-i5ziopzxTUU/TrBoWSthAwI/AAAAAAAAAJU/dYkrVkxVWlg/s400/Captura.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;Faig click a Authorize App i...&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-sLYkP7fjFWk/TrBoXNg3bOI/AAAAAAAAAJY/zojRLTIBc4g/s1600/Captura-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://1.bp.blogspot.com/-sLYkP7fjFWk/TrBoXNg3bOI/AAAAAAAAAJY/zojRLTIBc4g/s400/Captura-1.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;La pàgina de Twitter em proporciona un PIN. El piulador estava esperant a que li indiqués aquest PIN:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Entra el PIN(si està disponible) i prem enter:6865240&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;Un cop autoritzat, el mètode AutenticaConsumer invoca al mètode storeAccessToken que genera el fitxer amb l'Access Token i l'Access Token Key per a usos futurs. El fitxer generat és una cosa com aquesta:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Nom perfil: sticipl&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;twitter.verifyCredentials().getId(): 177894606&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Access Token:&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Access Token Secret:&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;AutenticaConsumer acaba i torna al constructor,&amp;nbsp;i el constructor fa la següent piulada:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Actualitzat&amp;nbsp;status a [Aquest és el missatge enviat des de l'aplicació #Java de prova fent us de #Twitter4J. Versió 2].&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Vet aquí el resultat:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-gl5B7R_hDDA/TrBqeN2s15I/AAAAAAAAAJk/7VVnI_pV1JA/s1600/Captura-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://2.bp.blogspot.com/-gl5B7R_hDDA/TrBqeN2s15I/AAAAAAAAAJk/7VVnI_pV1JA/s400/Captura-2.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Vet aquí, doncs, una versió del piulador amb autenticació OAuth gestionada des de la mateixa aplicació.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;La web de Twitter4J ens ens proporciona codi d'exemple per a desenvolupar altres funcions del Twitter que aniré explorant en propers posts.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4788606468171792208-2649383999713432981?l=apuntstecnologia.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apuntstecnologia.blogspot.com/feeds/2649383999713432981/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/11/un-piulador-amb-twitter4j-amb-gestio-de.html#comment-form' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/2649383999713432981'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/2649383999713432981'/><link rel='alternate' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/11/un-piulador-amb-twitter4j-amb-gestio-de.html' title='Un &quot;Piulador&quot; amb Twitter4J amb gestió de l&apos;autenticació'/><author><name>Serveis Tecnològics i Programari Lliure</name><uri>http://www.blogger.com/profile/12434522547196735270</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-i5ziopzxTUU/TrBoWSthAwI/AAAAAAAAAJU/dYkrVkxVWlg/s72-c/Captura.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4788606468171792208.post-2977332383421518854</id><published>2011-10-30T23:22:00.000+01:00</published><updated>2011-10-30T23:26:40.469+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='programari lliure'/><title type='text'>Un "Piulador" personal amb Twitter4J</title><content type='html'>En el post d'avui crearé un petit "Piulador": una petita aplicació que em permetrà piular al Twitter.&lt;br /&gt;&lt;br /&gt;El primer pas es descarregar l'API per al llenguatge de desenvolupament triat del lloc dels desenvolupadors de Twitter:&amp;nbsp;&lt;a href="https://dev.twitter.com/docs/twitter-libraries"&gt;https://dev.twitter.com/docs/twitter-libraries&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Tenim APIs per a diferents llenguatges i amb diferents orígens. En particular per a Java, PHP, Python i C++ a la mateixa web dels desenvolupadors en destaquen aquestes:&lt;br /&gt;&lt;br /&gt;C++: &amp;nbsp;Twitcurl, &amp;nbsp;&lt;a href="http://code.google.com/p/twitcurl/"&gt;http://code.google.com/p/twitcurl/&lt;/a&gt;.&lt;br /&gt;Java: &amp;nbsp;Twitter4J, &lt;a href="http://twitter4j.org/"&gt;http://twitter4j.org/&lt;/a&gt;.&lt;br /&gt;PHP: TmhOAuth,&amp;nbsp;&lt;a href="http://github.com/themattharris/tmhOAuth"&gt;http://github.com/themattharris/tmhOAuth&lt;/a&gt;.&lt;br /&gt;Python: Tweepy,&amp;nbsp;&lt;a href="https://github.com/tweepy/tweepy"&gt;https://github.com/tweepy/tweepy&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;En el meu cas, desenvoluparé l'aplicació amb Java, així que el primer que faig és descarregar Twitter4j&lt;br /&gt;&lt;br /&gt;A la web de Twitter4J en podem llegir algunes de les característiques d'aquesta API&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;"Twitter4J és una biblioteca java (jar) no oficial per a l'&lt;a href="http://apiwiki.twitter.com/Twitter-API-Documentation"&gt;API de Twitter&lt;/a&gt;.&lt;/i&gt;&lt;br /&gt;&lt;i&gt;Amb Twitter4J, es pot integrar fàcilment una aplicació Java amb el servei de Twitter.&lt;/i&gt;&lt;br /&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;i&gt;Twitter4J ofereix:&amp;nbsp;&lt;/i&gt;&lt;br /&gt;&lt;i&gt;✔ és Java pur 100%. Funciona a partir de la versió de plataforma Java 1.4.2&lt;/i&gt;&lt;br /&gt;&lt;i&gt;✔ Preparat per a la plataforma &lt;a href="http://code.google.com/android/"&gt;Android&lt;/a&gt; i per a &lt;a href="http://code.google.com/appengine/"&gt;Google App Engine&lt;/a&gt;.&lt;/i&gt;&lt;br /&gt;&lt;i&gt;✔ Sense dependències. No li cal cap jar addicional.&lt;/i&gt;&lt;br /&gt;&lt;i&gt;✔ suport OAuth inclòs&lt;/i&gt;&lt;br /&gt;&lt;i&gt;✔ suport de GZip inclòs&lt;/i&gt;&lt;br /&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;i&gt;Requeriments de sistema&lt;/i&gt;&lt;br /&gt;&lt;i&gt;Windows o Unix amb suport de Java.&lt;/i&gt;&lt;br /&gt;&lt;i&gt;JVM: Java 1.4.2 o superior&lt;/i&gt;&lt;br /&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;i&gt;Com utilitzar Twitter4J?&lt;/i&gt;&lt;br /&gt;&lt;i&gt;Només cal afegir twitter4j-core-2.2.5.jar al classpath de l'aplicació.&lt;/i&gt;&lt;br /&gt;&lt;i&gt;El millor lloc per on començar és llegir el &lt;a href="http://twitter4j.org/en/javadoc/index.html"&gt;JavaDoc&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;i&gt;El millor lloc per on començar a llegir el JavaDoc és la interface &lt;a href="http://twitter4j.org/en/javadoc/twitter4j/Twitter.html"&gt;twitter4j.Twitter&lt;/a&gt;."&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Però potser el primer que cal per a poder treballar amb Twitter és conèixer el protocol per a autenticar-se amb el servei: &amp;nbsp;El &lt;a href="http://tools.ietf.org/html/rfc5849"&gt;protocol OAuth&lt;/a&gt;&amp;nbsp; (rfc5849). Podem consultar també a&amp;nbsp;&lt;a href="http://oauth.net/core/1.0/"&gt;http://oauth.net/core/1.0/&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;El document de la rfc5849 &amp;nbsp;ocupa 39 pàgines. però en un primer moment no cal llegir-lo per a poder fer servir la Twitter4J, perquè els detalls del funcionament estan encapsulats a la llibreria.&lt;br /&gt;&lt;br /&gt;El que sí que caldrà és registrar l'aplicació que estem construint al servei Twitter, per a que aquest la reconegui i sigui capaç d'identificar-ne l'origen dels tweets. Això es fa a l'adreça&amp;nbsp;&lt;a href="https://dev.twitter.com/apps/new"&gt;https://dev.twitter.com/apps/new&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-S7pDDsTjK1c/Tq2-8pgD71I/AAAAAAAAAI0/F0ER_KFfOGw/s1600/Captura-01.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://1.bp.blogspot.com/-S7pDDsTjK1c/Tq2-8pgD71I/AAAAAAAAAI0/F0ER_KFfOGw/s400/Captura-01.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;Al formulari de registre haurem de posar el nom de l'aplicació, la descripció, l'adreça de descàrrega de l'aplicació (si la té)...&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-rMr-JgKFx7w/Tq2-_6ykVhI/AAAAAAAAAI8/s6uePfGYpzI/s1600/Captura02.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://3.bp.blogspot.com/-rMr-JgKFx7w/Tq2-_6ykVhI/AAAAAAAAAI8/s6uePfGYpzI/s400/Captura02.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;També hi podrem posar una icona, el tipus d'accés...el registre no resulta complicat.&lt;br /&gt;&lt;br /&gt;Un cop registrada l'aplicació obtindrem les claus per autoritzar l'aplicació al Twitter.&lt;br /&gt;&lt;br /&gt;En el llenguatge de OAuth &amp;nbsp;un Consumer és una aplicació, o una web, que accedeix a un proveïdor de servei en representació d'un usuari. Al registrar l'aplicació obtindrem el parell de valors que ens caldran per a autenticar l'aplicació, o consumer:&lt;br /&gt;&lt;br /&gt;Consumer Key: Un valor utilitzat per l'aplicació per a identificar-se ella mateixa enfront del servei Twitter (el "login" de l'aplicació).&lt;br /&gt;Consumer Secret: Un valor secret utilitzat per l'aplicació per a certificar la propietat de la Consumer Key &amp;nbsp;(el password).&lt;br /&gt;&lt;br /&gt;A més, se'ns proporcionarà un conjunt d'URLs a les que caldrà accedir per a que l'usuari que faci servir l'aplicació també pugui autenticar-se&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Request token URL:&amp;nbsp;https://api.twitter.com/oauth/request_token&lt;br /&gt;Authorize URL:&amp;nbsp;https://api.twitter.com/oauth/authorize&lt;br /&gt;Access token URL:&amp;nbsp;https://api.twitter.com/oauth/access_token&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Aquestes adreces permetran el diàleg entre el consumer i el servei per a autenticar a l'usuari final.&lt;br /&gt;&lt;br /&gt;Request Token: és un valor utilitzat pel Consumer per a obtenir autorització de l'usuari i que es tradueix en un Access Token.&lt;br /&gt;Access Token: és un valor utilitzat pel Consumer per a obtenir accés als Protected Resources (en el cas del Twitter, als tweets emesos o adreçats a l'usuari) en representació de l'usuari, en comptes de fer servir les pròpies credencials de l'usuari al Servei. És dir, l'aplicació no fa servir directament el login i el password de twitter de l'usuari. Podriem dir que l'Access Token és un login temporal.&lt;br /&gt;Access Token Secret: un valor secret utilitzat pel Consumer per a certificar la propietat de l'Access Token (seria el password temporal corresponent al login temporal).&lt;br /&gt;&lt;br /&gt;En la pàgina que es registra l'aplicació també podem obtenir un Acces Token i un Access Token Secret que es poden fer servir directament a l'aplicació per a piular des del propi compte de Twitter.&lt;br /&gt;&lt;br /&gt;Guardem molt bé els diferents tokens rebuts. I mantinguem en secret els "passwords"&lt;br /&gt;&amp;nbsp;Finalment, un cop registrada l'aplicació, podrem veure la nova aplicació registrada (i totes aquelles altres que puguem tenir) a &lt;a href="https://dev.twitter.com/apps"&gt;https://dev.twitter.com/apps&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-rDty7GYjKvg/Tq2_CXPtwpI/AAAAAAAAAJE/ycVsLRn3S-k/s1600/Captura-My+applications+%257C+Twitter+Developers+-+Google+Chrome.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="280" src="http://3.bp.blogspot.com/-rDty7GYjKvg/Tq2_CXPtwpI/AAAAAAAAAJE/ycVsLRn3S-k/s400/Captura-My+applications+%257C+Twitter+Developers+-+Google+Chrome.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;A la pàgina de Twitter4J ens diuen com fer servir aquests parells.&lt;br /&gt;&lt;br /&gt;Amb un &amp;nbsp;fitxer de propietats estàndard: &amp;nbsp;twitter4j.properties.&amp;nbsp;Cal que el fitxer "twitter4j.properties" es trobi a les rutes del classpath.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;debug=true&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;oauth.consumerKey=*********************&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;oauth.consumerSecret=******************************************&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;oauth.accessToken=**************************************************&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;oauth.accessTokenSecret=******************************************&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Amb un objecte ConfigurationBuilder&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;ConfigurationBuilder cb = new ConfigurationBuilder();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;cb.setDebugEnabled(true)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; .setOAuthConsumerKey("*********************")&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; .setOAuthConsumerSecret("******************************************")&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; .setOAuthAccessToken("**************************************************")&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; .setOAuthAccessTokenSecret("******************************************");&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;TwitterFactory tf = new TwitterFactory(cb.build());&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;Twitter twitter = tf.getInstance();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;O amb variables de sistema passades a la JVM.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;$ java -Dtwitter4j.debug=true&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; -Dtwitter4j.oauth.consumerKey=*********************&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; -Dtwitter4j.oauth.consumerSecret=******************************************&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; -Dtwitter4j.oauth.accessToken=**************************************************&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; -Dtwitter4j.oauth.accessTokenSecret=******************************************&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; -cp twitter4j-core-2.2.5.jar:yourApp.jar yourpackage.Main&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Arribats a aquest punt, un cop obtinguts els parells Consumer Key, Consumer Secret i Access Token i Access Token Secret ja estic en condicions de fer una petita aplicació amb java que "Piuli" al twitter en nom del meu compte. &lt;br /&gt;&lt;br /&gt;Una cosa tan senzilla com això:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;package com.sticipl.proves;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.Status;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.Twitter;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.TwitterException;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.TwitterFactory;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;import twitter4j.conf.ConfigurationBuilder;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;public final class ProvaTwitter {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; /**&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* Usage: java twitter4j.examples.tweets.UpdateStatus [text]&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* @param args message&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; public static void main(String[] args) {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;ConfigurationBuilder cb = new ConfigurationBuilder();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;cb.setDebugEnabled(true)&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;.setOAuthConsumerKey("[El consumer Key obtingut]")&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;.setOAuthConsumerSecret("[el consumer secret obtingut]")&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;.setOAuthAccessToken("[l'access token obtingut]")&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;.setOAuthAccessTokenSecret("[l'access token secret obtingut]");&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;TwitterFactory tf = new TwitterFactory(cb.build());&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Twitter twitter = tf.getInstance();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Status status = twitter.updateStatus("Aquest és el missatge enviat des de l'aplicació #Java de prova fent us de #Twitter4J");&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println("Actualitzat status a [" + status.getText() + "].");&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.exit(0);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } catch (TwitterException te) {&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; te.printStackTrace();&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println("Excepció de Twitter: " + te.getMessage());&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.exit(-1);&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: xx-small;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;En executar aquesta mini-aplicació, obtinc:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Actualitzat status a [Aquest és el missatge enviat des de l'aplicació #Java de prova fent us de #Twitter4J].&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;I en anar a Twitter puc comprovar que, efectivament, així és:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-o3C-VGvPWPw/Tq3NCmFcFsI/AAAAAAAAAJM/EDBGEjWzF2k/s1600/Captura-STiPL+%2528sticipl%2529+on+Twitter.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="280" src="http://4.bp.blogspot.com/-o3C-VGvPWPw/Tq3NCmFcFsI/AAAAAAAAAJM/EDBGEjWzF2k/s400/Captura-STiPL+%2528sticipl%2529+on+Twitter.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;En aquesta primera aproximació a Twitter4J he fet un petit "piulador" personal. En un proper post presentaré un "Piulador" general.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4788606468171792208-2977332383421518854?l=apuntstecnologia.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apuntstecnologia.blogspot.com/feeds/2977332383421518854/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/10/en-el-post-davui-creare-un-petit.html#comment-form' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/2977332383421518854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/2977332383421518854'/><link rel='alternate' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/10/en-el-post-davui-creare-un-petit.html' title='Un &quot;Piulador&quot; personal amb Twitter4J'/><author><name>Serveis Tecnològics i Programari Lliure</name><uri>http://www.blogger.com/profile/12434522547196735270</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-S7pDDsTjK1c/Tq2-8pgD71I/AAAAAAAAAI0/F0ER_KFfOGw/s72-c/Captura-01.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4788606468171792208.post-5570725589791097940</id><published>2011-10-28T23:49:00.002+02:00</published><updated>2011-12-08T23:45:05.369+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='eines'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='apache'/><title type='text'>Com instal·lar XAMPP a Ubuntu.</title><content type='html'>A l'hora de fer presentacions i demos d'aplicacions web, pot ser molt útil disposar d'una versió de la demo en un servidor web en localhost, potser en una clau usb.&lt;br /&gt;&lt;br /&gt;També pot ser molt útil un servidor web d'aquest tipus a l'hora de preparar sessions de formació.&lt;br /&gt;&lt;br /&gt;És possible trobar per Internet diverses distribucions que d'aquest tipus que combinen &lt;b&gt;A&lt;/b&gt;pache amb &amp;nbsp;&lt;b&gt;M&lt;/b&gt;ySQL i &lt;b&gt;P&lt;/b&gt;HP, tant sobre &lt;b&gt;L&lt;/b&gt;inux (LAMP), com sobre &lt;b&gt;W&lt;/b&gt;indows (WAMP), per exemple &lt;a href="http://www.apachefriends.org/en/xampp.html"&gt;XAMPP&lt;/a&gt; o &lt;a href="http://www.chsoftware.net/en/mowes/mowesportable/mowes.htm"&gt;MoWeS Portable&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;MoWeS Portable empaqueta, a més de&amp;nbsp;la plataforma AMP, altres aplicacions que utilitzen aquesta infraestructura, com Joomla! o Drupal. Ara bé, MoWeS Portable només està disponible per a Windows.&lt;br /&gt;&lt;br /&gt;XAMPP, en canvi, s'ofereix per a Linux i Windows.&lt;br /&gt;&lt;br /&gt;En el post d'avuí el que faig és instal·lar el XAMPP a un netbook Linux.&lt;br /&gt;&lt;br /&gt;No cal dir que la plataforma AMP es pot instal·lar des del Centre de Programari de l'Ubuntu. Però la instal·lació de XAMPP és encara més senzilla.&lt;br /&gt;&lt;br /&gt;Dit i fet. El primer pas és descarregar-se el paquet d'instal·lació. El &amp;nbsp;puc trobar en aquesta adreça: &amp;nbsp;&lt;a href="http://sourceforge.net/projects/xampp/files/BETAS/xampp-linux-1.7.7.tar.gz/download"&gt;http://sourceforge.net/projects/xampp/files/BETAS/xampp-linux-1.7.7.tar.gz/download&lt;/a&gt;. Són uns 77MB.&lt;br /&gt;&lt;br /&gt;Aquesta versió incorpora: &amp;nbsp;&amp;nbsp;Apache, MySQL, PHP amb PEAR, Perl, ProFTPD, phpMyAdmin, OpenSSL, GD, Freetype2, libjpeg, libpng, gdbm, zlib, expat, Sablotron, libxml, Ming, Webalizer, pdf class, ncurses, mod_perl, FreeTDS, gettext, mcrypt, mhash, eAccelerator, SQLite i IMAP C-Client.&lt;br /&gt;&lt;br /&gt;En particular Apache 2.2.21, MySQL 5.5.16, PHP 5.3.8, i phpMyAdmin 3.4.5.&lt;br /&gt;&lt;br /&gt;Per instal·lar &amp;nbsp;n'hi ha prou amb desempaquetar el tar.gz. Cal tenir en compte que als fitxers d'instal·lació s'assumeix que la home del XAMPP serà /opt/lampp. Això NO vol dir que només es pugui instal·lar en aquesta carpeta. Això l'únic que vol dir és que caldrà que /opt/lampp sigui la "home" del XAMPP i això es podrà aconseguir amb un enllaç simbòlic des de /opt/lampp al directori d'instal·lació que triï.&lt;br /&gt;&lt;br /&gt;Si la carpeta de destinació del XAMPP es troba en una clau usb caldrà que aquesta clau estigui formatada amb un sistema de fitxers que permeti els enllaços simbòlics, per exemple &amp;nbsp;ext2,ext3 o ext4.&lt;br /&gt;&lt;br /&gt;A l'hora de fer l'enllaç simbòlic caldrà tenir en compte el punt de muntatge del dispositiu. Per exemple, al meu netbook amb Ubuntu 11.04, el punt de muntatge és /media.&lt;br /&gt;&lt;br /&gt;Per a poder instal·lar correctament el XAMPP caldran, a més, permisos de root. I també per a posar en marxa i aturar els diversos components de la distribució.&lt;br /&gt;&lt;br /&gt;Tenint en compte tot l'anterior, instal·lo el XAMPP a la meva carpeta home, on he deixat el tar.gz:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;sudo tar xvfz xampp-linux-1.7.7.tar.gz -C .&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Amb la ordre anterior es crea una carpeta lampp amb els dversos components del XAMPP.&lt;br /&gt;&lt;br /&gt;Ara creo l'enllaç simbòlic:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sudo ln -s /home/albert/lampp&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;/opt/lampp&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I engego per primer cop el servidor. Aquesta primera arrencada acaba d'instal·lar i configurar els components.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~$ sudo /opt/lampp/lampp start&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Starting XAMPP for Linux 1.7.7...&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;XAMPP: Starting Apache with SSL (and PHP5)...&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;XAMPP: Starting MySQL...&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;XAMPP: Starting ProFTPD...&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;XAMPP for Linux started.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~$&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I per revisar la nova instal·lació en tinc prou amb obrir un navegador i apuntar-lo al localhost:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-HaP87Li1WGA/TqseO1ccOOI/AAAAAAAAAIk/KZCtSa4D45c/s1600/Captura-XAMPP+-+Google+Chrome.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="215" src="http://3.bp.blogspot.com/-HaP87Li1WGA/TqseO1ccOOI/AAAAAAAAAIk/KZCtSa4D45c/s400/Captura-XAMPP+-+Google+Chrome.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-Rh7n4A1fMY4/TqseSAz_S1I/AAAAAAAAAIs/zS5XqwH2qHQ/s1600/Captura-XAMPP+for+Linux+1.7.7+-+Google+Chrome.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="215" src="http://3.bp.blogspot.com/-Rh7n4A1fMY4/TqseSAz_S1I/AAAAAAAAAIs/zS5XqwH2qHQ/s400/Captura-XAMPP+for+Linux+1.7.7+-+Google+Chrome.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;El directori arrel del servidor web es troba a /opt/lampp/htdocs (en el meu cas, mercès a l'enllaç simbòlic, és&amp;nbsp;/home/albert/lampp/htdocs).&lt;br /&gt;&lt;br /&gt;Per aturar el XAMPP puc fer:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~$ sudo /opt/lampp/lampp stop&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;Stopping XAMPP for Linux 1.7.7...&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;XAMPP: Stopping Apache with SSL...&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;XAMPP: Stopping MySQL...&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;XAMPP: Stopping ProFTPD...&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;XAMPP stopped.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@athena:~$&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I per a eliminar la instal·lació sense deixar rastres, amb el XAMPP aturat, n'hi ha prou amb fer:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sudo rm -r lampp&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;És possible engegar i aturar individualment els diversos components del XAMPP. Examinant el fitxer $HOME/lampp/lampp es poden &amp;nbsp;trobar les diverses opcions disponibles. La forma d'invocar-les, en general, és:&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #351c75; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;sudo /opt/lampp/lampp &lt;i&gt;opció&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4788606468171792208-5570725589791097940?l=apuntstecnologia.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apuntstecnologia.blogspot.com/feeds/5570725589791097940/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/10/com-installar-xampp-ubuntu.html#comment-form' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/5570725589791097940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/5570725589791097940'/><link rel='alternate' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/10/com-installar-xampp-ubuntu.html' title='Com instal·lar XAMPP a Ubuntu.'/><author><name>Serveis Tecnològics i Programari Lliure</name><uri>http://www.blogger.com/profile/12434522547196735270</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-HaP87Li1WGA/TqseO1ccOOI/AAAAAAAAAIk/KZCtSa4D45c/s72-c/Captura-XAMPP+-+Google+Chrome.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4788606468171792208.post-7874810656166259113</id><published>2011-10-09T14:55:00.002+02:00</published><updated>2011-10-09T14:55:25.009+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sqlite'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><title type='text'>Com accedir a bases de dades SQLite amb Python</title><content type='html'>En l'exercici d'avui, presento el mòdul pysqlite2 que proporciona una senzilla interfície per a utilitzar SQLite amb Python.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;A l'Ubuntu, per a afegir aquest mòdul &amp;nbsp;n'hi ha prou amb anar al Centre de Programari de l'Ubuntu i instal·lar els paquets python-pysqlite2 i python-pysqlite2-doc.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-3kmHrYYRUkE/TpGVycG7bmI/AAAAAAAAAIg/-VtEt4aQd1U/s1600/Captura-Centre+de+programari+de+l%2527Ubuntu.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="204" src="http://4.bp.blogspot.com/-3kmHrYYRUkE/TpGVycG7bmI/AAAAAAAAAIg/-VtEt4aQd1U/s320/Captura-Centre+de+programari+de+l%2527Ubuntu.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Cal anar amb compte perquè els números de versió poden crear confusió: trobarem també els mòduls python-pysqlite, però aquests són per a taules de l'anterior SQLite2. Els python-pysqlite2, corresponen a SQLite3, que és la versió actual.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Primer de tot crearé una base de dades SQLite3 de proves amb una taula diccionari. amb tres columnes: id, PK, numèric amb autoincrement; nom, text; valor, text.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;La taula es pot crear de forma senzilla amb l'aplicació gràfica SQLiteman, que permet operar amb taules d'SQLite3. En tot cas, també es pot crear la taula de proves amb la interfície en mode text que proporciona el mateix SQLite3. En cas de no disposar de SQLiteman, aquest es pot instal·lar, com tota la resta, des del Centre de Programari de l'Ubuntu.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-KL2ogSv8QSs/TpGVoVe6fQI/AAAAAAAAAIc/JLKScSjbwTs/s1600/Captura-prova-sqlite.db+-+Sqliteman.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/-KL2ogSv8QSs/TpGVoVe6fQI/AAAAAAAAAIc/JLKScSjbwTs/s320/Captura-prova-sqlite.db+-+Sqliteman.png" width="318" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;L'esquema &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;CREATE TABLE "diccionari" (&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; "nom" TEXT NOT NULL,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; "valor" TEXT NOT NULL&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;CREATE TABLE sqlite_sequence(name,seq);&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Un cop creada la taula, la informo amb dades de prova.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I, a continuació, el codi per a afegir, cercar, esborrar...amb Python i pysqlite2.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;#!/usr/bin/python&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# coding: latin-1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# python i sqlite&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;from pysqlite2 import dbapi2 as sqlite&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# es connecta a una base de dades&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;con = sqlite.connect("./prova-sqlite.db")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# itera a través de la taula diccionari amb un cursor&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;cursor = con.cursor()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# executa el cursor&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;cursor.execute("select id, nom, valor from diccionari")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# itera a través de les files&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# obtenir-ne només resultat un:&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;print "\n-------------------------------"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;print "estat inicial"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;for fila in cursor:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;# recupera els valors&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;iddic, nom, valor = fila[0], fila[1], fila[2]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;# els mostra&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;print "id: " + str(iddic) + "; nom: " + nom + "; valor: " + valor&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# inserta noves files, amb una seqüència&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;print "\n-------------------------------"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;print "insereix 3 files"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;cursor.execute("insert into diccionari(nom, valor) values (?, ?)", ("nom6","valor6") )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;cursor.execute("insert into diccionari(nom, valor) values (?, ?)", ("nom7","valor7") )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;cursor.execute("insert into diccionari(nom, valor) values (?, ?)", ("nom8","valor8") )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# commit&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;con.commit();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# a veure què ha fet...&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;cursor.execute("select id, nom, valor from diccionari")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# itera a través de les files&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;for fila in cursor:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;# recupera els valors&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;iddic, nom, valor = fila[0], fila[1], fila[2]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;# els mostra (un mètode alternatiu)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;print "id: %d; nom: %s; valor: %s" % (iddic, nom, valor)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# amb un mapeig&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;print "\n-------------------------------"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;print "insereix 3 files més"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;item = {"nom": "nom9", "valor": "valor9"}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;cursor.execute("insert into diccionari(nom, valor) values (:nom, :valor)", item)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;item = {"nom": "nom10", "valor": "valor10"}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;cursor.execute("insert into diccionari(nom, valor) values (:nom, :valor)", item)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;item = {"nom": "nom11", "valor": "valor11"}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;cursor.execute("insert into diccionari(nom, valor) values (:nom, :valor)", item)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# commit&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;con.commit();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# tornem a veure què ha fet...&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;cursor.execute("select id, nom, valor from diccionari")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# itera a través de les files&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;for fila in cursor:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;# recupera els valors&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;iddic, nom, valor = fila[0], fila[1], fila[2]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;# els mostra&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;print "id: %d; nom: %s; valor: %s" % (iddic, nom, valor)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;#finalment, ho deixo tot com estava al començament&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;cursor.execute("delete from diccionari where id &amp;gt; 5")&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;con.commit()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# ho verifica...&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;cursor.execute("select id, nom, valor from diccionari")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# itera a través de les files, un mètode alternatiu amb fetchone&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;print "\n-------------------------------"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;print "ho deixa com estava a l'inici"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;fila = cursor.fetchone()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;while (not (fila is None)):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;# recupera els valors&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;iddic, nom, valor = fila[0], fila[1], fila[2]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;# els mostra&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;print "id: %d; nom: %s; valor: %s" % (iddic, nom, valor)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;fila = cursor.fetchone()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# tanca el cursor&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;cursor.close()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;# tanca la connexió&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;con.close()&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Els comentaris del codi en proporcionen les explicacions. Només en destacaria les alternatives idiomàtiques que ofereix Python per a realitzar diverses accions:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Per exemple: un print de diferents variables, i l'alternativa a l'estil del printf de C:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;print "id: " + str(iddic) + "; nom: " + nom + "; valor: " + valor&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;print "id: %d; nom: %s; valor: %s" % (iddic, nom, valor)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;O aquesta altre: la iteració a través d'un cursor amb for, i uns alternativa amb while&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;amb for&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;for fila in cursor:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;# recupera els valors&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;iddic, nom, valor = fila[0], fila[1], fila[2]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;# els mostra&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;print "id: %d; nom: %s; valor: %s" % (iddic, nom, valor)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;amb while:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;fila = cursor.fetchone()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;while (not (fila is None)):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;# recupera els valors&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;iddic, nom, valor = fila[0], fila[1], fila[2]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;# els mostra&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;print "id: %d; nom: %s; valor: %s" % (iddic, nom, valor)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;	&lt;/span&gt;fila = cursor.fetchone()&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Instruccions "preparades" i l'ús de '?', o de variables vinculades a l'insert&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;amb '?'&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;cursor.execute("insert into diccionari(nom, valor) values (?, ?)", ("nom6","valor6") )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;amb variables vinculades&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;item = {"nom": "nom11", "valor": "valor11"}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #073763; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;cursor.execute("insert into diccionari(nom, valor) values (:nom, :valor)", item)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I, a continuació, una execució del programa &amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@atenea:~/wk-python/prova-sqlite$ python prova-sqlite.py&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;-------------------------------&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;estat inicial&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 1; nom: nom1; valor: valor1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 2; nom: nom2; valor: valor2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 3; nom: nom3; valor: valor3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 4; nom: nom4; valor: valor4&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 5; nom: nom5; valor: valor5&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;-------------------------------&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;insereix 3 files&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 1; nom: nom1; valor: valor1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 2; nom: nom2; valor: valor2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 3; nom: nom3; valor: valor3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 4; nom: nom4; valor: valor4&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 5; nom: nom5; valor: valor5&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 45; nom: nom6; valor: valor6&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 46; nom: nom7; valor: valor7&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 47; nom: nom8; valor: valor8&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;-------------------------------&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;insereix 3 files més&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 1; nom: nom1; valor: valor1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 2; nom: nom2; valor: valor2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 3; nom: nom3; valor: valor3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 4; nom: nom4; valor: valor4&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 5; nom: nom5; valor: valor5&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 45; nom: nom6; valor: valor6&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 46; nom: nom7; valor: valor7&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 47; nom: nom8; valor: valor8&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 48; nom: nom9; valor: valor9&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 49; nom: nom10; valor: valor10&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 50; nom: nom11; valor: valor11&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;-------------------------------&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;ho deixa com estava a l'inici&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 1; nom: nom1; valor: valor1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 2; nom: nom2; valor: valor2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 3; nom: nom3; valor: valor3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 4; nom: nom4; valor: valor4&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;id: 5; nom: nom5; valor: valor5&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0c343d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;albert@atenea:~/wk-python/prova-sqlite$&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Per saber-ne més, una cerca a Google ens proporcionarà un munt d'enllaços. Tanmateix, cal explicitar la referència fonamental: el lloc de la documentació de Python (&lt;a href="http://docs.python.org/"&gt;http://docs.python.org&lt;/a&gt;).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;En particular, l'apartat de SQLite 3:&amp;nbsp;&lt;a href="http://docs.python.org/library/sqlite3.html"&gt;http://docs.python.org/library/sqlite3.html&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4788606468171792208-7874810656166259113?l=apuntstecnologia.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apuntstecnologia.blogspot.com/feeds/7874810656166259113/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/10/com-accedir-bases-de-dades-sqlite-amb.html#comment-form' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/7874810656166259113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/7874810656166259113'/><link rel='alternate' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/10/com-accedir-bases-de-dades-sqlite-amb.html' title='Com accedir a bases de dades SQLite amb Python'/><author><name>Serveis Tecnològics i Programari Lliure</name><uri>http://www.blogger.com/profile/12434522547196735270</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-3kmHrYYRUkE/TpGVycG7bmI/AAAAAAAAAIg/-VtEt4aQd1U/s72-c/Captura-Centre+de+programari+de+l%2527Ubuntu.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4788606468171792208.post-6839683382955958444</id><published>2011-09-30T00:47:00.001+02:00</published><updated>2011-09-30T00:57:30.854+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='esdeveniments'/><title type='text'>10a Diada de les Telecomunicacions a Catalunya.</title><content type='html'>Avui -29 de setembre, Sant Gabriel, patró de les Telecomunicacions- s'ha celebrat la &lt;a href="http://www.coettc.com/diadacom/2011/index.php?apartat=quees"&gt;10a Diada de les Telecomunicacions a Catalunya&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Organitzat pel &lt;a href="http://www.coettc.com/"&gt;COETTC&lt;/a&gt;, es tracta d'un esdeveniment important dins el món TIC al nostre país.&lt;br /&gt;&lt;br /&gt;Com podem llegir &amp;nbsp;a la mateixa web del esdeveniment:&lt;br /&gt;&lt;br /&gt;"La Diada està orientada als professionals del sector TIC: empresaris, directius, universitaris, comercials i polítics relacionats amb les TIC. També s’adreça als estudiants d'enginyeria i FP, i a tots aquells que tinguin inquietud per estar al dia en el sector TIC.&lt;br /&gt;&lt;br /&gt;A la Diada es pren el pols al Sector; s'analitza el que ha estat l'últim any, i es fa una prospecció del que serà el futur immediat. Les diferents ponències no són panells d'alt contingut científic, sinó exposicions i plantejaments de tendències futures: tot això amb un llenguatge fàcil i assequible."&lt;br /&gt;&lt;br /&gt;Dins els marc de la Diada, al CosmoCaixa de Barcelona s'han dut a terme diverses activitats,&lt;br /&gt;&lt;ul&gt;&lt;li style="list-style-image: initial; list-style-position: initial; list-style-type: square; margin-bottom: 5px;"&gt;Conferencia inaugural.&lt;/li&gt;&lt;li style="list-style-image: initial; list-style-position: initial; list-style-type: square; margin-bottom: 5px;"&gt;Taules rodones.&lt;/li&gt;&lt;li style="list-style-image: initial; list-style-position: initial; list-style-type: square; margin-bottom: 5px;"&gt;&lt;i&gt;Networking&lt;/i&gt;, facilitant als assistents diversos moments per a relacionar-se, comunicar-se i fer negocis entre ells.&lt;/li&gt;&lt;li style="list-style-image: initial; list-style-position: initial; list-style-type: square; margin-bottom: 5px;"&gt;El lliurament dels Premis Excel·lència a les Telecomunicacions, després de l'acte de cloenda&lt;/li&gt;&lt;/ul&gt;Les diverses activitats de la Diada han pogut preparar-se i seguir-se online per les xarxes socials Twitter, FaceBook i LinkedIn&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.facebook.com/pages/Coettc/107275569351696"&gt;www.facebook.com/pages/Coettc/107275569351696&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.twitter.com/coettc"&gt;www.twitter.com/coettc&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.linkedin.com/groups/Enginyers-T%C3%A8cnics-de-Telecomunicaci%C3%B3-de-1862282?trk=myg_ugrp_ovr"&gt;www.linkedin.com/groups/Enginyers-Tècnics-de-Telecomunicació-de-1862282?trk=myg_ugrp_ovr&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4788606468171792208-6839683382955958444?l=apuntstecnologia.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://apuntstecnologia.blogspot.com/feeds/6839683382955958444/comments/default' title='Comentaris del missatge'/><link rel='replies' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/09/10a-diada-de-les-telecomunicacions.html#comment-form' title='0 comentaris'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/6839683382955958444'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4788606468171792208/posts/default/6839683382955958444'/><link rel='alternate' type='text/html' href='http://apuntstecnologia.blogspot.com/2011/09/10a-diada-de-les-telecomunicacions.html' title='10a Diada de les Telecomunicacions a Catalunya.'/><author><name>Serveis Tecnològics i Programari Lliure</name><uri>http://www.blogger.com/profile/12434522547196735270</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4788606468171792208.post-2950955579723324915</id><published>2011-09-18T16:45:00.000+02:00</published><updated>2011-09-18T16:48:47.746+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C'/><category scheme='http://www.blogger.com/atom/ns#' term='eines'/><category scheme='http://www.blogger.com/atom/ns#' term='programari lliure'/><title type='text'>Taules hash amb C a Linux</title><content type='html'>Les taules hash , hash maps són una estructura de dades que, mitjançant una funció hash (o &lt;a href="http://ca.wikipedia.org/wiki/Funci%C3%B3_resum"&gt;funció resum&lt;/a&gt;) identifica uns valors, anomenats claus, amb uns valors associats.&lt;br /&gt;&lt;br /&gt;L'avantatge de les taules hash sobre altres estructures de dades és la gran rapidesa d'accés a la informació i el cost constant d'aquest accés. Per això,&amp;nbsp; les taules hash tenen un munt d'aplicacions.&lt;br /&gt;&lt;br /&gt;En tot cas, les taules hash són una solució molt senzilla i eficient per a l'emmagatzematge i l'accés a la informació que es pugui modelar directament amb taules de&amp;nbsp; parelles clau valor.&lt;br /&gt;&lt;br /&gt;Amb C sobre Linux (en el meu cas Ubuntu 11.04) apareixen almenys tres opcions ràpides per a implementar taules hash: &lt;br /&gt;Amb funcions de la llibreria estàndar &lt;a href="http://en.wikipedia.org/wiki/GNU_C_Library"&gt;GlibC&lt;/a&gt;&lt;br /&gt;Amb funcions de la llibreria GTK, &lt;a href="http://en.wikipedia.org/wiki/GLib"&gt;Glib&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Amb "bases de dades" del tipus DBM, a Linux &lt;a href="http://www.gnu.org.ua/software/gdbm/"&gt;Gdbm&lt;/a&gt;; o amb l'evolució amb capacitat concurrent de Gdbm desenvolupada per a &lt;a href="http://www.samba.org/"&gt;SAMBA&lt;/a&gt;: &lt;a href="http://tdb.samba.org/"&gt;TDB&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Anem a repassar les opcions:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Amb Glibc (La llibreria estàndard de C)&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Un exemple de taules hash amb les funcions de la llibreria estàndard Glibc (hcreate, hsearch i hdestroy)&lt;br /&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;/* aquest exemple està adaptat de la documentació del man */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;#include &amp;lt;search.h&amp;gt;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;#include &amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;struct info {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* aquesta estructura és la dels valors emmagatzemats a la taula */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int age, room;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;};&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;#define NUM_EMPL&amp;nbsp;&amp;nbsp;&amp;nbsp; 5000&amp;nbsp;&amp;nbsp;&amp;nbsp; /* # número d'elements. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;int main(void)&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;{&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char string_space[NUM_EMPL*20];&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* espai d'emmagatzematge de la taula de valors de les claus. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct info info_space[NUM_EMPL];&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* espai per emmagatzemar la informació de claus. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char *str_ptr = string_space;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* següent posició a l'espai de valors. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct info *info_ptr = info_space;&amp;nbsp;&amp;nbsp; /* següent posició a l'espai de claus. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ENTRY item;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ENTRY *found_item;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* nom a buscar. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char name_to_find[30];&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i = 0;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Create table; no error checking is performed. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("Crea la taula\n");&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (void) hcreate(NUM_EMPL);&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("Introdueix clau age room a la taula. Per acabar d'entrar valors prem CTRL-D\n");&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (scanf("%s %d %d", str_ptr, &amp;amp;info_ptr-&amp;gt;age,&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;info_ptr-&amp;gt;room) != EOF &amp;amp;&amp;amp; i++ &amp;lt; NUM_EMPL) {&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Put information in structure, and structure in item. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("Afegeix %s %d %d a la taula\n", str_ptr, info_ptr-&amp;gt;age, info_ptr-&amp;gt;room);&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; item.key = str_ptr;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; item.data = info_ptr;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; str_ptr += strlen(str_ptr) + 1;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; info_ptr++;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Put item into table. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("Afegeix - hsearch(item, ENTER)\n");&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (void) hsearch(item, ENTER);&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Access table. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("Busca valors a la taula. Per acabar CTRL-C\n");&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; item.key = name_to_find;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (scanf("%s", item.key) != EOF) {&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("Buscant %s amb hsearch(item, FIND)\n", item.key);&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ((found_item = hsearch(item, FIND)) != NULL) {&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* If item is in the table. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (void)printf("trobat %s, age = %d, room = %d\n",&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; found_item-&amp;gt;key,&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((struct info *)found_item-&amp;gt;data)-&amp;gt;age,&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((struct info *)found_item-&amp;gt;data)-&amp;gt;room);&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (void)printf("no trobat %s\n", name_to_find);&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Una excució podria ser, per exemple: &lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;albert@atenea:~/wk-c/prova-hash-glibc$ ./prova_hash_glibc&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Crea la taula&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Introdueix clau age room a la taula. Per acabar d'entrar valors prem CTRL-D&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;clau1 1 2&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Afegeix clau1 1 2 a la taula&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Afegeix - hsearch(item, ENTER)&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;clau2 3 4&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Afegeix clau2 3 4 a la taula&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Afegeix - hsearch(item, ENTER)&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;clau3 5 6&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Afegeix clau3 5 6 a la taula&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Afegeix - hsearch(item, ENTER)&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Busca valors a la taula. Per acabar CTRL-C&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;prova&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Buscant prova amb hsearch(item, FIND)&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;no trobat prova&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;clau1&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Buscant clau1 amb hsearch(item, FIND)&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;trobat clau1, age = 1, room = 2&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;clau3&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Buscant clau3 amb hsearch(item, FIND)&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;trobat clau3, age = 5, room = 6&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;^C&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;albert@atenea:~/wk-c/prova-hash-glibc$ &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Amb GLib (la llibreria de GTK)&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;La referència per a taules hash amb Glib es troba a &lt;a href="http://developer.gnome.org/glib/2.28/glib-Hash-Tables.html"&gt;http://developer.gnome.org/glib/2.28/glib-Hash-Tables.html &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;En resum:&lt;br /&gt;&lt;br /&gt;Per a crear una taula hash de Glib (una GHashTable), fem servir: g_hash_table_new().&lt;br /&gt;&lt;br /&gt;Per afegir una clau i el seu valor associat a la GHashTable, fem servir: g_hash_table_insert().&lt;br /&gt;&lt;br /&gt;Per a cercar el valor associat a una clar fem servir&amp;nbsp; g_hash_table_lookup()&amp;nbsp; i g_hash_table_lookup_extended().&lt;br /&gt;&lt;br /&gt;Per a eliminar una aprella clau-valor, g_hash_table_remove().&lt;br /&gt;&lt;br /&gt;Per a&amp;nbsp; invocar una funció per a cada parella clau-valor,&amp;nbsp; g_hash_table_foreach().&lt;br /&gt;&lt;br /&gt;Per a esborrar del tot una GHashTable,&amp;nbsp; g_hash_table_destroy(). &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Vet aquí l'exemple amb GLibC implementat amb les funcions de GLib. L'exemple ha estat desenvolupat fent servir Anjuta. He partit d'un projecte genèric mínim amb C. M'ha calgut afegir la llibreria glib2.0-0 i l'include a glib.h al fitxer Makefile.am (automake)&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;## Process this file with automake to produce Makefile.in&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;## Created by Anjuta&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;AM_CPPFLAGS = \&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;-DPACKAGE_DATA_DIR=\""$(datadir)"\" &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;AM_CFLAGS =\&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; -Wall\&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; -g&lt;b&gt;\&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; -I/usr/include/glib-2.0\&lt;/span&gt;&lt;/b&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -I/usr/lib/glib-2.0/include&lt;/b&gt; &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;bin_PROGRAMS = hashtables&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;hashtables_SOURCES = \&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;main.c&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;hashtables_LDFLAGS = &lt;b&gt;-lglib-2.0&lt;/b&gt; &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;hashtables_LDADD = &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;El codi és el següent. Pràcticament només he tingut que canviar les funcions:&lt;br /&gt;&lt;div style="color: #20124d; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #20124d; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;span style="font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;#include &amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;#include &amp;lt;glib.h&amp;gt;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;struct value {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* aquesta estructura és la dels valors emmagatzemats a la taula */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gint age, room;&amp;nbsp; /* gint és el tipus glib que encapsula a int*/&amp;nbsp; &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;};&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;#define NUM_KEYS&amp;nbsp;&amp;nbsp;&amp;nbsp; 5000&amp;nbsp;&amp;nbsp;&amp;nbsp; /* número d'elements. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;#define KEY_SIZE&amp;nbsp;&amp;nbsp;&amp;nbsp; 20&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* tamanys de la clau*/&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;int main(void)&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;{&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GHashTable *hashTable;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gchar keys[NUM_KEYS * KEY_SIZE];&amp;nbsp;&amp;nbsp;&amp;nbsp; /* espai d'emmagatzematge de la taula de valors de les claus. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct value values[NUM_KEYS]; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* espai per emmagatzemar la informació de claus. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gchar *keyPtr = keys;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; /* següent posició a l'espai de valors. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct value *valuePtr = values;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* següent posició a l'espai de claus. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gchar keyToFind[KEY_SIZE];&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; /* clau a buscar, màxim de KEY_SIZE caràcters */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i=0;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Crea taula hash.&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; g_str_hash és una funció hash que es proporciona amb Glib &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; per a claus del tipus (gchar *) &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; g_str_equal és una funció que es proporciona amb Glib per verificar &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l'igualtat de dues claus del tipus (gchar *) &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; */ &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("Crea la taula\n");&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; hashTable = g_hash_table_new(g_str_hash, g_str_equal);&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("Introdueix clau age room a la taula. Per acabar d'entrar valors prem CTRL-D\n");&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (scanf("%s %d %d", &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;keyPtr, &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;amp;valuePtr-&amp;gt;age, &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;amp;valuePtr-&amp;gt;room) != EOF &amp;amp;&amp;amp; i++ &amp;lt; NUM_KEYS) {&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* traça */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("Afegeix %s %d %d a la taula\n", keyPtr, valuePtr-&amp;gt;age, valuePtr-&amp;gt;room);&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* els posa a la taula */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("Afegeix - g_hash_table_insert\n");&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; /* afegeix clau-valor a taula hash.&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; g_hash_table_insert rep tres paràmetres&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; punter a la taula hash&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; punter a la clau&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; punter al valor&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; */&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; g_hash_table_insert(hashTable, keyPtr, valuePtr);&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; /* prepara els punters per a nova clau valor*/&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keyPtr += strlen(keyPtr) + 1;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; valuePtr++;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Ara busca per la taula. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("Busca valors a la taula. Per acabar CTRL-C\n");&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; keyPtr = keyToFind;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (scanf("%s", keyPtr) != EOF) {&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("Buscant %s amb g_hash_table_lookup\n", keyPtr);&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ((valuePtr = g_hash_table_lookup(hashTable, keyPtr)) != NULL) {&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* si ha trobat diferent de nul, el mostra. */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* nota: això pot ser un problema, perquè no es pot distingir&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; el "no trobat" del "trobat el valor nul".&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; En aquests casos, cal fer servir g_hash_table_lookup_extended&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("found %s, age = %d, room = %d\n",&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keyPtr,&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; valuePtr-&amp;gt;age,&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; valuePtr-&amp;gt;room);&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("not found %s\n", keyPtr);&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;L'execució del programa anterior segueix les mateixes indicacions que al primer exemple:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;albert@atenea:~/wk-c/prova-hash-glib$&amp;nbsp; hashtables &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Crea la taula&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Introdueix clau age room a la taula. Per acabar d'entrar valors prem CTRL-D&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;albert 42 192&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Afegeix albert 42 192 a la taula&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Afegeix - g_hash_table_insert&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;montse 40 201&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Afegeix montse 40 201 a la taula&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Afegeix - g_hash_table_insert&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;^D&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Busca valors a la taula. Per acabar CTRL-C&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;kok&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Buscant kok amb g_hash_table_lookup&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;not found kok&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;albert&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Buscant albert amb g_hash_table_lookup&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;found albert, age = 42, room = 192&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;montse&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;Buscant montse amb g_hash_table_lookup&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;found montse, age = 40, room = 201&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;^C&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;GDBM i TDB&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;En el desenvolupament de SAMBA es va veure que calia un sistema de base de dades senzill del tipus hash: una taula de claus i valors.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://en.wikipedia.org/wiki/Dbm"&gt;DBM&lt;/a&gt; (la BD de BSD) oferia la interfase adequada, però no permetia l'accés concurrent. Aleshores, es va reescriure DBM permetent aquest accés concurrent i el resultat va ser &lt;a href="http://tdb.samba.org/"&gt;TDB&lt;/a&gt;. TDB es pot utilitzar com un alternativa concurrent de DBM. &lt;br /&gt;&lt;br /&gt;A Ubuntu es poden instal·lar des del Centre de Programari tant la versió GNU de DBM, la GDBM, com la TDB.&lt;br /&gt;&lt;br /&gt;TDB i GDBM ocupen molt poc espai i poden ser una bona sol·lució per a implementar taules hash amb C allà on calguin, en comptes de fer servir les funcions que ofereixen la llibreria estàndard de C, GLibc, o les de la llibreria de GTK, GLib.&lt;br /&gt;&lt;br /&gt;Una preacució a tenir en compte és que existeixen diferents formats de fitxer dbm. &lt;br /&gt;&lt;br /&gt;La instal·ació de TDB inclou, a més&amp;nbsp; dels llibreries i dels include,&amp;nbsp; els executables següents:&lt;br /&gt;&lt;br /&gt;tdbbackup: és una eina que es pot fer servir per fer el backup des fitxers .tdb de Samba i verificar-ne la integritat. Si troba un fitxer .tdb de Samba fet malbé i un fitxer de backup previ, aleshores restaura el fitxer anterior.&lt;br /&gt;tdbdump: és una eina que fa el volcat, o dump, d'un fitxer .tdb en un format legible. A més també pot fer el volcat d'una clau específica.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;tdbtool: permet manipular fitxers .tdb. Les opcions que ofereix aquest programa són:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-size: x-small;"&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;albert@atenea:~$ tdbtool&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;tdb&amp;gt; help&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;database not open&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;tdbtool: &lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; create&amp;nbsp;&amp;nbsp;&amp;nbsp; dbname&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : create a database&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; open&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dbname&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : open an existing database&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; transaction_start&amp;nbsp;&amp;nbsp;&amp;nbsp; : start a transaction&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; transaction_commit&amp;nbsp;&amp;nbsp; : commit a transaction&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; transaction_cancel&amp;nbsp;&amp;nbsp; : cancel a transaction&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; erase&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : erase the database&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; dump&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : dump the database as strings&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; keys&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : dump the database keys as strings&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; hexkeys&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : dump the database keys as hex values&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; info&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : print summary info about the database&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; insert&amp;nbsp;&amp;nbsp;&amp;nbsp; key&amp;nbsp; data&amp;nbsp; : insert a record&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; move&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; key&amp;nbsp; file&amp;nbsp; : move a record to a destination tdb&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; store&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; key&amp;nbsp; data&amp;nbsp; : store a record (replace)&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; show&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; key&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : show a record by key&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; delete&amp;nbsp;&amp;nbsp;&amp;nbsp; key&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : delete a record by key&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; list&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : print the database hash table and freelist&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; free&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : print the database freelist&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; check&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : check the integrity of an opened database&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; speed&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : perform speed tests on the database&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; ! command&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : execute system command&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; 1 | first&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : print the first record&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; n | next&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : print the next record&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; q | quit&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : terminate&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; \n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : repeat 'next' command&lt;/span&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;br style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;" /&gt;&lt;span style="fo
