<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
<channel>
	<title>Daniele Serio - Official Web Site - @2011</title>
	
	<link>http://www.danieleserio.it</link>
	<description>...programmare è uno stile di vita...</description>
	<lastBuildDate>Tue, 21 Feb 2012 12:48:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/danieleserio/LnTo" /><feedburner:info uri="danieleserio/lnto" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Windows 8: addio al pulsante START, Microsoft lo rimuove</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/Ma7kiLF-rRU/</link>
		<comments>http://www.danieleserio.it/windows-8-addio-al-pulsante-start-microsoft-lo-rimuove/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 21:40:55 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[Guide e Tutorial]]></category>
		<category><![CDATA[Informatica & Tecnologia]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[windows 8]]></category>
		<category><![CDATA[windows developer preview]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2374</guid>
		<description><![CDATA[Microsoft muove un importante passo in avanti, almeno simbolico, rimuovendo il pulsante start di Windows che tutti conoscono. Già, perché secondo numerose indiscrezioni (e come dimostrato con l&#8217;installazione di windows 8), il colosso di Redmond avrebbe rimosso il tanto noto pulsante dalla Consumer Preview di Windows 8 che ha cominciato a circolare. Introdotto oltre 15 anni fa con lo sviluppo [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft muove un importante passo in avanti, almeno simbolico, <strong>rimuovendo il pulsante start </strong>di Windows che tutti conoscono. Già, perché secondo numerose indiscrezioni (e come dimostrato con <a title="Windows 8 Build 8102 – Developer Preview" href="http://www.danieleserio.it/windows-8-build-8102-developer-preview/">l&#8217;installazione di windows 8</a>), il colosso di Redmond avrebbe rimosso il tanto noto pulsante dalla Consumer Preview di Windows 8 che ha cominciato a circolare.<span id="more-2374"></span></p>
<p>Introdotto oltre 15 anni fa con lo sviluppo di <strong>Windows 95</strong>, Microsoft avrebbe così, anche se ancora non è confermato ufficialmente, deciso di rimuovere quello che è stato uno dei marchi distintivi del sistema operativo. A mostrarlo sarebbero gli screenshot della versione Consumer Preview (build 8220) emersi negli ultimi giorni e che mostrano chiaramente una barra delle applicazioni priva del caratteristico pulsante start. Questo pulsante era già stato appiattito e annerito, per diventare quanto più simile alla nuova interfaccia metro, nelle build di test di Windows 8 distribuite nei mesi passati.<a href="http://www.danieleserio.it/wp-content/uploads/2012/02/microsoft-windows-8-consumer-preview-sans-start-button.jpg"><img class="aligncenter size-full wp-image-2376" title="microsoft-windows-8-consumer-preview-sans-start-button" src="http://www.danieleserio.it/wp-content/uploads/2012/02/microsoft-windows-8-consumer-preview-sans-start-button.jpg" alt="" width="560" height="423" /></a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/lzdBSJJfAjGRezngiAj2_L8nCPM/0/da"><img src="http://feedads.g.doubleclick.net/~a/lzdBSJJfAjGRezngiAj2_L8nCPM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/lzdBSJJfAjGRezngiAj2_L8nCPM/1/da"><img src="http://feedads.g.doubleclick.net/~a/lzdBSJJfAjGRezngiAj2_L8nCPM/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/Ma7kiLF-rRU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/windows-8-addio-al-pulsante-start-microsoft-lo-rimuove/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/windows-8-addio-al-pulsante-start-microsoft-lo-rimuove/</feedburner:origLink></item>
		<item>
		<title>Come risolvere ORA-01034: Oracle not available ORA-27101: shared memory realm does not exist</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/8B-Jly_R_3w/</link>
		<comments>http://www.danieleserio.it/come-risolvere-ora-01034-oracle-not-available-ora-27101-shared-memory-realm-does-not-exist/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 09:47:43 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[Guide e Tutorial]]></category>
		<category><![CDATA[Programmazione]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2369</guid>
		<description><![CDATA[Oggi vi mostro come risolvere l&#8217;errore:  ORA-01034: Oracle not availableORA-27101: shared memory realm does not existSVR4 Error: 2: No such file or directory Questo errore può verificarsi se il database, o meglio alcuni servizi non sono stati avviati correttamente, nonostante tra i servizi windows ci sia scritto &#8220;Avviato&#8221;. La risoluzione è molto semplice, occorre aprire [...]]]></description>
			<content:encoded><![CDATA[<p>Oggi vi mostro come risolvere l&#8217;errore: </p>
<p><strong>ORA-01034: Oracle not available</strong><br /><strong>ORA-27101: shared memory realm does not exist</strong><br /><strong>SVR4 Error: 2: No such file or directory<span id="more-2369"></span></strong></p>
<p>Questo errore può verificarsi se il database, o meglio alcuni servizi non sono stati avviati correttamente, nonostante tra i servizi windows ci sia scritto &#8220;Avviato&#8221;.</p>
<p>La risoluzione è molto semplice, occorre aprire una sessione DOS o SHELL e digitare i seguenti comandi:</p>
<ol>
<li><strong>sqlplus /nolog</strong></li>
<li><strong>connect / as sysdba</strong></li>
<li><strong>startup</strong></li>
</ol>
<p>Il risultato dovrà essere il seguente:</p>
<p><strong>Istanza ORACLE avviata.</strong></p>
<p><strong>Total System Global Area 210837208 bytes</strong><br /><strong>Fixed Size 454360 bytes</strong><br /><strong>Variable Size 159383552 bytes</strong><br /><strong>Database Buffers 50331648 bytes</strong><br /><strong>Redo Buffers 667648 bytes</strong><br /><strong>Database montato.</strong><br /><strong>Database aperto.</strong></p>

<p><a href="http://feedads.g.doubleclick.net/~a/sjyVhMiQKbMUXk77x8k_05N3Ma4/0/da"><img src="http://feedads.g.doubleclick.net/~a/sjyVhMiQKbMUXk77x8k_05N3Ma4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/sjyVhMiQKbMUXk77x8k_05N3Ma4/1/da"><img src="http://feedads.g.doubleclick.net/~a/sjyVhMiQKbMUXk77x8k_05N3Ma4/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/8B-Jly_R_3w" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/come-risolvere-ora-01034-oracle-not-available-ora-27101-shared-memory-realm-does-not-exist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/come-risolvere-ora-01034-oracle-not-available-ora-27101-shared-memory-realm-does-not-exist/</feedburner:origLink></item>
		<item>
		<title>Neve abbondante a Roma anche Venerdi 10/02 e Sabato 11/02: ecco i dati degli esperti</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/Jymth7oxjVc/</link>
		<comments>http://www.danieleserio.it/neve-abbondante-a-roma-anche-venerdi-1002-e-sabato-1102-ecco-il-dati-degli-esperti/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 12:42:44 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2347</guid>
		<description><![CDATA[ALLARME: da VENERDI NEVE al centrosud, a Roma, +Emilia Romagna &#62; VIDEO Sulla previsione di Roma leggi la nostra intervista di 5 giorni fa all&#8217;ANSA. PREVISIONI a cura di ANTONIO SANO&#8217;:&#8221;GIOVEDI NOTTE nuovo afflusso siberiano. &#8221;Blizzard&#8221; al nordest, Valpadana, Emilia, e poi Adriatiche!VENERDI nuovo vortice con tanta neve al centro ed Emilia Romagna, Campania e poi nordest da Sabato&#8221;. OGGI al allarme neve su [...]]]></description>
			<content:encoded><![CDATA[<p><strong>ALLARME: da VENERDI NEVE al centrosud, a Roma, +Emilia Romagna &gt; VIDEO</strong></p>
<div>Sulla previsione di Roma leggi la nostra intervista di 5 giorni fa all&#8217;ANSA. PREVISIONI a cura di ANTONIO SANO&#8217;:&#8221;GIOVEDI NOTTE nuovo afflusso siberiano. &#8221;Blizzard&#8221; al nordest, Valpadana, Emilia, e poi Adriatiche!VENERDI nuovo vortice con tanta neve al centro ed Emilia Romagna, Campania e poi nordest da Sabato&#8221;. OGGI al allarme neve su Irpinia e Basilicata altri 50cm. ATTENZIONE: GIOVEDI sera  ennesimo impulso siberiano da nord-nordest. Dalla sera temporali di neve - blizzard (bufere!) su nordest, Emilia Romagna, poi resto del nord e Adriatiche. Fenomeno affascinante e raro, da seguire!  <span id="more-2347"></span></div>
<div>ATTENZIONE: VENERDI &#8211; SABATO vortice sull&#8217;Italia, neve al centrosud fino in pianura, su coste adriatiche, a Roma e Lazio, tanta neve  a 100m su Campania con forte maltempo, forte su Irpinia, Lucania, Puglia, ancora sull&#8217;Emilia Romagna e Marche molto forte con vera emergenza e tendenza a risalita dei fenomeni sul Veneto! </div>
<div> </div>
<div><span style="font-size: medium;"><strong>DATI DI VENERDI 10/02</strong></span></div>
<div><a href="http://www.danieleserio.it/wp-content/uploads/2012/02/tabella_venerdi.png"><img class="aligncenter size-full wp-image-2361" title="tabella_venerdi" src="http://www.danieleserio.it/wp-content/uploads/2012/02/tabella_venerdi.png" alt="" width="667" height="456" /></a></div>
<div> </div>
<div> </div>
<div><strong>DATI DI SABATO 11/02</strong></div>
<div><a href="http://www.danieleserio.it/wp-content/uploads/2012/02/tabella_sabato.png"><img class="aligncenter size-full wp-image-2360" title="tabella_sabato" src="http://www.danieleserio.it/wp-content/uploads/2012/02/tabella_sabato.png" alt="" width="672" height="459" /></a></div>
<p><a href="http://www.danieleserio.it/wp-content/uploads/2012/02/0004cs.gif"><img class="size-full wp-image-2348 aligncenter" title="0004cs" src="http://www.danieleserio.it/wp-content/uploads/2012/02/0004cs.gif" alt="" width="280" height="319" /></a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/HCztyJGs_2qu-xybL9_lj-w00Ts/0/da"><img src="http://feedads.g.doubleclick.net/~a/HCztyJGs_2qu-xybL9_lj-w00Ts/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/HCztyJGs_2qu-xybL9_lj-w00Ts/1/da"><img src="http://feedads.g.doubleclick.net/~a/HCztyJGs_2qu-xybL9_lj-w00Ts/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/Jymth7oxjVc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/neve-abbondante-a-roma-anche-venerdi-1002-e-sabato-1102-ecco-il-dati-degli-esperti/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/neve-abbondante-a-roma-anche-venerdi-1002-e-sabato-1102-ecco-il-dati-degli-esperti/</feedburner:origLink></item>
		<item>
		<title>Disponibile per il download: GWT Developer Plugin per Firefox 9.0</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/Gxiz1ZqOXpQ/</link>
		<comments>http://www.danieleserio.it/disponibile-per-il-download-gwt-developer-plugin-per-firefox-9-0/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 15:48:25 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[GWT - Google Web Toolkit]]></category>
		<category><![CDATA[Programmazione]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2336</guid>
		<description><![CDATA[E&#8217; uscito Firefox 9, e molti sviluppatori GWT &#8211; SMARTGWT &#8211; EXTJS &#8211; GXT sui sono trovati di fronte ad un problema: il plugin gwt-developer-mode non è compatibile. Io per primo ho avuto la necessità di sviluppare su Firefox 9, e quindi dopo qualche ora di lavoro, ecco qui pronto &#8220;GWT Developer Plugin per Firefox 9&#8243;. [...]]]></description>
			<content:encoded><![CDATA[<p>E&#8217; uscito <strong>Firefox 9</strong>, e molti sviluppatori GWT &#8211; SMARTGWT &#8211; EXTJS &#8211; GXT sui sono trovati di fronte ad un problema: il plugin gwt-developer-mode non è compatibile.</p>
<p>Io per primo ho avuto la necessità di sviluppare su Firefox 9, e quindi dopo qualche ora di lavoro, ecco qui pronto &#8220;<strong>GWT Developer Plugin per Firefox 9&#8243;</strong>.<span id="more-2336"></span></p>
<p>Il plugin è testato e funzionante su tutte le piattaforme e sistemi operativi sia a 32bit che a 64bit. </p>
<p><img title="Continua..." src="http://www.danieleserio.it/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" alt="" /></p>
<p>Ecco il link per il download: [get_link_pwd]</p>
<p>Hello, I just finished creating GWT Developer Plugin for Firefox 9.</p>
<p>The plugin is tested and running on all platforms.</p>
<p>Here is the link for download:  [get_link_pwd]</p>

<p><a href="http://feedads.g.doubleclick.net/~a/f5AKBEViDh8YE-OcUfABKGpXPmw/0/da"><img src="http://feedads.g.doubleclick.net/~a/f5AKBEViDh8YE-OcUfABKGpXPmw/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/f5AKBEViDh8YE-OcUfABKGpXPmw/1/da"><img src="http://feedads.g.doubleclick.net/~a/f5AKBEViDh8YE-OcUfABKGpXPmw/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/Gxiz1ZqOXpQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/disponibile-per-il-download-gwt-developer-plugin-per-firefox-9-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/disponibile-per-il-download-gwt-developer-plugin-per-firefox-9-0/</feedburner:origLink></item>
		<item>
		<title>GeoTools: un toolkit Open Source Java per il GIS</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/QI-_4fmojwk/</link>
		<comments>http://www.danieleserio.it/geotools-un-toolkit-open-source-java-per-il-gis/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 09:03:56 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[GeoTools]]></category>
		<category><![CDATA[Guide e Tutorial]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programmazione]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2330</guid>
		<description><![CDATA[In questo articolo vedremo come utilizzare il toolkit GeoTools, composto da una serie di librerie Open Source scritte in Java, che permette di effettuare le tipiche operazioni di un sistema GIS su  informazioni derivanti da dati geografici. Un GIS (Geographic(al) Information System, in italiano Sistema Informativo Geografico) è un sistema informativo computerizzato che permette di [...]]]></description>
			<content:encoded><![CDATA[<p>In questo articolo vedremo come utilizzare il toolkit GeoTools, composto da una serie di librerie Open Source scritte in Java, che permette di effettuare le tipiche operazioni di un sistema GIS su  informazioni derivanti da dati geografici. Un GIS (Geographic(al) Information System, in italiano Sistema Informativo Geografico) è un sistema informativo computerizzato che permette di acquisire, gestire, manipolare e visualizzare dati georeferenziati e si distingue da quello che viene chiamato  sistema SIT (Sistema Informativo Territoriale) il quale include al suo interno anche le organizzazioni (composte da uomini, strumenti e procedure) che si occupano del sistema GIS.</p>
<p><span id="more-2330"></span></p>
<p>L’informazione territoriale può essere codificata in un sistema informativo geografico attraverso due tipologie principali di dato: il dato vettoriale e il dato raster.</p>
<p>I dati vettoriali sono costituiti da elementi semplici quali punti, linee e poligoni, codificati e memorizzati sulla base delle loro coordinate. Un punto viene individuato in un sistema informativo geografico attraverso le sue coordinate reali (x1, y1); una linea o un poligono attraverso la posizione dei suoi nodi (x1, y1; x2, y2; …). A ciascun elemento è associato un record del database informativo che contiene tutti gli attributi dell’oggetto rappresentato.</p>
<p>Il dato raster permette di rappresentare il mondo reale attraverso una matrice di celle, generalmente di forma quadrata o rettangolare, dette pixel. A ciascun pixel sono associate le informazione relative a ciò che esso rappresenta sul territorio. La dimensione del pixel (detta anche pixel size), generalmente espressa nell’unità di misura della carta (metri, chilometri etc.), è strettamente relazionata alla precisione del dato.</p>
<p>I dati vettoriali e i dati raster si adattano ad usi diversi. La cartografia vettoriale è particolarmente adatta alla rappresentazione di dati che variano in modo discreto (ad esempio l’ubicazione dei cassonetti dei rifiuti di una città o la rappresentazione delle strade o una carta dell’uso del suolo), la cartografia raster è più adatta alla rappresentazione di dati con variabilità continua (ad esempio un modello digitale di elevazione o una carta di acclività del versante).</p>
<p>Uno dei formati più utilizzati per la memorizzazione di dati vettoriali è lo <em>shapefile ESRI</em>. Il formato è stato sviluppato e regolato da <a href="http://www.esri.com/" target="_blank">ESRI</a> ed emesso come open standard, allo scopo di accrescere l’interoperabilità fra i sistemi ESRI e altri GIS. Di fatto è diventato uno standard per il dato vettoriale spaziale, e viene usato da una grande varietà di sistemi GIS.</p>
<p>Con “shapefile” si indica di norma un insieme di file con estensione .shp, .dbf, .shx, altre che hanno in comune il prefisso dei nomi (per es. “laghi.*”). Spesso con shapefile si indica però solo i file “.shp”. Tuttavia questo file da solo è incompleto poiché interpretazione ed utilizzo dipendono dagli altri file.</p>
<p>Gli shapefile descrivono spazialmente punti, poligoni, polilinee utilizzabili, ad es., per rappresentare stagni, laghi e fiumi, rispettivamente. A ciascun elemento possono essere associati ulteriori attributi che descrivono le voci (ad es. nome o temperatura).</p>
<p>Uno shapefile è considerato come un unico insieme, ma in realtà è l’insieme di più file. Tre file sono obbligatori, senza di essi uno shapefile non è tale; ad essi si possono aggiungere altri 9 file che conservano indici e dati accessori. Tutti i file di uno Shapefile sono allocati nella stessa cartella:</p>
<p>File obbligatori:</p>
<ul>
<li>.shp – il file che conserva le geometrie;</li>
<li>.shx – il file che conserva l’indice delle geometrie;</li>
<li>.dbf – il database degli attributi.</li>
</ul>
<p>File opzionali:</p>
<ul>
<li>.sbn e .sbx – indici spaziali;</li>
<li>.fbn e .fbx – indici spaziali delle feature in sola lettura;</li>
<li>.ain e .aih – indici attributari dei campi della tabella;</li>
<li>.prj – il file che conserva l’informazione sul sistema di coordinate, espresso in Well-Known Text;</li>
<li>.shp.xml – metadato dello shapefile;</li>
<li>.atx – indice attributario della tabella (file .dbf) nella forma &lt;nome_shapefile&gt;.&lt;nome_colonna&gt;.atx (ArcGIS 8 e superiori).</li>
</ul>
<p>Una descrizione dettagliata del formato viene fornita nel seguente file pdf tratto dal sito della ESRI:</p>
<p><a href="http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf">http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf</a></p>
<p>Possiamo reperire degli shapefile di esempio dalle seguenti URL:</p>
<p><a href="http://www.mappinghacks.com/data/" target="_blank">http://www.mappinghacks.com/data/</a></p>
<p><a href="http://udig.refractions.net/docs/data.zip" target="_blank">http://udig.refractions.net/docs/data.zip</a></p>
<p>Dal sito dell’Istat è possibile inoltre scaricare gli shapefile delle Regioni, Province e Comuni di Italia raggruppati per anno (2001, 2008 e 2010):</p>
<p><a href="http://www.istat.it/ambiente/cartografia/">http://www.istat.it/ambiente/cartografia/</a></p>
<p>Vediamo ora come poter realizzare uno strumento che ci permetti di visualizzare dei dati georeferenziati in formato shapefile. A questo scopo utilizziamo il toolkit GeoTools che possiamo scaricare dal sito Sourceforge:</p>
<p><a href="http://sourceforge.net/projects/geotools/files/">http://sourceforge.net/projects/geotools/files/</a></p>
<p>scegliamo l’ultima release e la versione già compilata (geotools-version-milestone-bin.zip), la quale include una serie di librerie .jar. In alternativa è possibile scaricarne i sorgenti e compilarli utilizzando Maven.</p>
<p>Creiamo a questo punto un Progetto Java all’interno del nostro Editor Eclipse, cliccando su File -&gt; New -&gt; Java Project. Il pacchetto che abbiamo scaricato contiene una pletora di librerie, per il nostro esempio possiamo includere solo quelle qui di seguito elencate:</p>
<ul>
<li>commons-pool-1.5.4.jar;</li>
<li>geoapi-2.3-M1.jar;</li>
<li>geoapi-pending-2.1-M1.jar;</li>
<li>gt-api-version-milestone.jar;</li>
<li>gt-coverage-version-milestone.jar;</li>
<li>gt-data-version-milestone.jar;</li>
<li>gt-epsg-extension-version-milestone.jar;</li>
<li>gt-grid-version-milestone.jar;</li>
<li>gt-main-version-milestone.jar;</li>
<li>gt-metadata-version-milestone.jar;</li>
<li>gt-referencing-version-milestone.jar;</li>
<li>gt-render-version-milestone.jar;</li>
<li>gt-shapefile-version-milestone.jar: questa è la libreria che ci consente di leggere i file che compongono lo shapefile;</li>
<li>gt-shapefile-renderer–version-milestone.jar;</li>
<li>gt-swing-version-milestone.jar;</li>
<li>jdom-1.0.jar;</li>
<li>jsr-275-1.0-beta-2.jar;</li>
<li>jts-1.11.jar;</li>
<li>miglayout-3.7-swing.jar.</li>
<li>vecmath-1.3.2.jar.</li>
</ul>
<p>Una volta copiati questi jar in una cartella del nostro progetto (ad esempio lib), dobbiamo aggiungerli al Build Path.</p>
<p>Possiamo ora provare il toolkit utilizzando questo semplice codice:</p>
<div id="highlighter_75062">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>package</code> <code>it.appuntisoftware;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>import</code> <code>java.io.File;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>import</code> <code>org.geotools.data.CachingFeatureSource;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>import</code> <code>org.geotools.data.FeatureSource;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>import</code> <code>org.geotools.data.FileDataStore;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>import</code> <code>org.geotools.data.FileDataStoreFinder;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>import</code> <code>org.geotools.map.DefaultMapContext;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>import</code> <code>org.geotools.map.MapContext;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>import</code> <code>org.geotools.swing.JMapFrame;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>import</code> <code>org.geotools.swing.data.JFileDataStoreChooser;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>public</code> <code>class</code> <code>GISDemo{</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>public</code> <code>static</code> <code>void</code> <code>main(String[] args) </code><code>throws</code> <code>Exception {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>//Visualizza una finestra per la scelta del file di tipo shapefiles</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>File file = JFileDataStoreChooser.showOpenFile(</code><code>"shp"</code><code>, </code><code>null</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>15</code></td>
<td><code>if</code> <code>(file == </code><code>null</code><code>) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>16</code></td>
<td><code>return</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>17</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>18</code></td>
<td><code>FileDataStore store = FileDataStoreFinder.getDataStore(file);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>19</code></td>
<td><code>FeatureSource featureSource = store.getFeatureSource();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>20</code></td>
<td><code>// Crea una mappa e vi aggiunge lo shapefile</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>21</code></td>
<td><code>MapContext map = </code><code>new</code> <code>DefaultMapContext();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>22</code></td>
<td><code>map.setTitle(</code><code>"La mappa dei Comuni d'Italia"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>23</code></td>
<td><code>map.addLayer(featureSource, </code><code>null</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>24</code></td>
<td><code>// Visualizza la Mappa</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>25</code></td>
<td><code>JMapFrame.showMap(map);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>26</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>27</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Lanciamo il nostro progetto e ci verrà presentato a video un pannello attraverso cui scegliere dal nostro FileSystem il file .shp:</p>
<div id="attachment_1458"><a href="http://www.appuntisoftware.it/wp-content/uploads/2010/12/geotools.jpg"><img title="geotools" src="http://www.appuntisoftware.it/wp-content/uploads/2010/12/geotools-300x210.jpg" alt="geotools 300x210 GeoTools: un toolkit Open Source Java per il GIS" width="300" height="210" /></a></p>
<p>Carichiamo il nostro file .shp</p>
</div>
<p>in questo esempio sto caricando lo shapefile dei comuni italiani del 2010.</p>
<p>Terminata la fase di caricamento e rendering ci verrà mostrato un pannello che visualizza le informazioni geografiche dei comuni italiani con degli strumenti di zoom e di selezione:</p>
<div id="attachment_1459"><a href="http://www.appuntisoftware.it/wp-content/uploads/2010/12/geotools2.jpg"><img title="geotools2" src="http://www.appuntisoftware.it/wp-content/uploads/2010/12/geotools2-300x223.jpg" alt="geotools2 300x223 GeoTools: un toolkit Open Source Java per il GIS" width="300" height="223" /></a></p>
<p>La mappa dei comuni italiani con i relativi confini</p>
</div>
<p>Utilizzando la quarta icona (procedendo da sinistra)  sulla barra degli strumenti in alto, possiamo ottenere il dettaglio di un particolare punto sulla mappa:</p>
<div id="attachment_1460"><a href="http://www.appuntisoftware.it/wp-content/uploads/2010/12/geotools3.jpg"><img title="geotools3" src="http://www.appuntisoftware.it/wp-content/uploads/2010/12/geotools3-300x223.jpg" alt="geotools3 300x223 GeoTools: un toolkit Open Source Java per il GIS" width="300" height="223" /></a></p>
<p>Cliccando sul comune di roma vengono visualizzate alcune informazioni del comune</p>
</div>
<p>in particolare vengono visualizzare le coordinate (x,y) del punto in cui si è cliccato.</p>
<p>L’applicazione ha un problema di performance in quanto ad ogni refresh dell’immagine, ad esempio quando viene zoomata, viene riletto lo shapefile dal disco, per evitare ciò possiamo caricarlo in memoria utilizzando un meccanismo di caching implementto dalla classe CachingFeatureSource. Possiamo dunque reimplementare il nostro metodo in questo modo:</p>
<div id="highlighter_278561">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>public</code> <code>void</code> <code>usingFeatureCaching() </code><code>throws</code> <code>Exception {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>File file = JFileDataStoreChooser.showOpenFile(</code><code>"shp"</code><code>, </code><code>null</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>if</code> <code>(file == </code><code>null</code><code>) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>return</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>FileDataStore store = FileDataStoreFinder.getDataStore(file);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>FeatureSource featureSource = store.getFeatureSource();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>CachingFeatureSource cache = </code><code>new</code><code>CachingFeatureSource(featureSource); </code><code>//abbiamo aggiunto questa riga</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>MapContext map = </code><code>new</code> <code>DefaultMapContext();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>map.setTitle(</code><code>"La mappa dei Comuni d'Italia - utilizzando il caching"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>map.addLayer(cache, </code><code>null</code><code>); </code><code>//gli passiamo l'oggetto cache</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>JMapFrame.showMap(map);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Il nostro esempio è funzionante, ma sulla consolle viene visualizzata la seguente avvertenza:</p>
<p>17-dic-2010 16.33.55 org.geotools.factory.FactoryRegistry scanForPlugins</p>
<p>AVVERTENZA: Can&#8217;t load a service for category &#8220;MathTransformProvider&#8221;. Cause is &#8220;NoClassDefFoundError: javax/media/jai/WarpAffine&#8221;.</p>
<p>Per eliminare tale avvertenza dobbiamo scaricare la libreria Java Advanced Imaging (JAI) dal seguente indirizzo:</p>
<p><a href="https://jai.dev.java.net/binary-builds.html" target="_blank">https://jai.dev.java.net/binary-builds.html</a></p>
<p>per i nostri scopi possiamo scegliere quella senza accelerazione nativa (<a href="http://download.java.net/media/jai/builds/release/1_1_3/jai-1_1_3-lib.zip">jai-1_1_3-lib.zip</a>), e la aggiungiamo al nostro Build-Path.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/afOCPbAWJ2VR_0xl2xeagMk0T8w/0/da"><img src="http://feedads.g.doubleclick.net/~a/afOCPbAWJ2VR_0xl2xeagMk0T8w/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/afOCPbAWJ2VR_0xl2xeagMk0T8w/1/da"><img src="http://feedads.g.doubleclick.net/~a/afOCPbAWJ2VR_0xl2xeagMk0T8w/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/QI-_4fmojwk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/geotools-un-toolkit-open-source-java-per-il-gis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/geotools-un-toolkit-open-source-java-per-il-gis/</feedburner:origLink></item>
		<item>
		<title>Json-lib: una libreria Java per elaborare dati in formato JSON</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/VlPCCfT-eoU/</link>
		<comments>http://www.danieleserio.it/json-lib-una-libreria-java-per-elaborare-dati-in-formato-json/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 09:02:11 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[Guide e Tutorial]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programmazione]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2325</guid>
		<description><![CDATA[In questo articolo vedremo come trasformare dei tipi di dati Java (primitivi, array, classi, etc…) in formato JSON (JavaScript Object Notation) e viceversa, utilizzando una libreria in linguaggio Java denominata Json-lib. A cosa serve questa trasformazione? Ebbene lo sviluppo di applicazioni RIA (Rich Internet Application), attualissimo nel panorama odierno dello sviluppo web oriented, è ormai incentrato [...]]]></description>
			<content:encoded><![CDATA[<p>In questo articolo vedremo come trasformare dei tipi di dati Java (primitivi, array, classi, etc…) in formato JSON (JavaScript Object Notation) e viceversa, utilizzando una libreria in linguaggio Java denominata Json-lib.</p>
<p>A cosa serve questa trasformazione? Ebbene lo sviluppo di applicazioni RIA (Rich Internet Application), attualissimo nel panorama odierno dello sviluppo web oriented, è ormai incentrato sull’utilizzo massivo di JavaScript per la costruzione di interfacce grafiche (GUI) sempre più piacevoli e flessibili e sul paradigma Ajax che permette lo scambio “leggero” (cioè senza ricorrere al refresh del browser) tra Client e Server.<span id="more-2325"></span></p>
<p>Ed è proprio in questa interazione che entra in gioco JSON, il quale è ormai considerato lo standard de facto (a scapito del prolisso XML) per lo scambio di dati tra Client (JavaScript? e Server (che può utilizzare le tecnologie più disparate (Java, PHP, .NET, etc…).</p>
<p>&nbsp;</p>
<p>JSON[<a href="http://www.appuntisoftware.it/json-lib-una-libreria-java-per-elaborare-dati-in-formato-json/#1">1</a>] è un formato di testo completamente indipendente dal linguaggio di programmazione, ma utilizza convenzioni conosciute dai programmatori di linguaggi della famiglia del C, come C, C++, C#, Java, JavaScript, Perl, Python, e molti altri. Questa caratteristica fa di JSON un linguaggio ideale per lo scambio di dati.</p>
<p>JSON è basato su due strutture:</p>
<ul>
<li>Un insieme di coppie nome/valore. In diversi linguaggi, questo è realizzato come un oggetto, un record, uno struct, un dizionario, una tabella hash, un elenco di chiavi o un array associativo.</li>
<li>Un elenco ordinato di valori. Nella maggior parte dei linguaggi questo si realizza con un array, un vettore, un elenco o una sequenza.</li>
</ul>
<p>In JSON le due strutture assumono queste forme:</p>
<p>Un <em>oggetto</em> è una serie non ordinata di nomi/valori. Un oggetto inizia con <code>{</code> (parentesi graffa sinistra) e finisce con <code>}</code> (parentesi graffa destra). Ogni nome è seguito da <code>:</code> (due punti) e la coppia di nome/valore sono separati dalla <code>,</code> (virgola).</p>
<p><img title="Json lib: una libreria Java per elaborare dati in formato JSON" src="http://json.org/object.gif" alt="object Json lib: una libreria Java per elaborare dati in formato JSON" width="419" height="79" /></p>
<p>Un <em>array</em> è una raccolta ordinata di valori. Un array comincia con <code>[</code> (parentesi quadra sinistra) e finisce con <code>]</code> (parentesi quadra destra). I valori sono separati dalla <code>,</code> (virgola).</p>
<p><img title="Json lib: una libreria Java per elaborare dati in formato JSON" src="http://json.org/array.gif" alt="array Json lib: una libreria Java per elaborare dati in formato JSON" width="419" height="79" /></p>
<p>Un <em>valore</em> può essere una stringa tra virgolette, o un numero, o vero o falso o nullo, o un oggetto o un array. Queste strutture possono essere annidate.</p>
<p><img title="Json lib: una libreria Java per elaborare dati in formato JSON" src="http://json.org/value.gif" alt="value Json lib: una libreria Java per elaborare dati in formato JSON" width="419" height="195" /></p>
<p>Una <em>stringa</em> è una raccolta di zero o più caratteri Unicode, tra virgolette; per le sequenze di escape utilizza la barra rovesciata. Un singolo carattere è rappresentato come una stringa di caratteri di lunghezza uno. Una stringa è molto simile ad una stringa C o Java.</p>
<p><img title="Json lib: una libreria Java per elaborare dati in formato JSON" src="http://json.org/string.gif" alt="string Json lib: una libreria Java per elaborare dati in formato JSON" width="419" height="289" /></p>
<p>Un numero è molto simile ad un numero C o Java, a parte il fatto che i formati ottali e esadecimali non sono utilizzati.</p>
<p><img title="Json lib: una libreria Java per elaborare dati in formato JSON" src="http://json.org/number.gif" alt="number Json lib: una libreria Java per elaborare dati in formato JSON" width="419" height="186" /></p>
<p>I caratteri di spaziatura possono essere inseriti in mezzo a qualsiasi coppia di token.</p>
<p>Dopo questa panoramica sul linguaggio JSON, vediamo come poter “tradurre” dei dati in formato Java (Stringhe, array, oggetti, etc…) in formato JSON, e viceversa, utilizzando la libreria Json-lib, che permette di ottenere questa trasformazione automaticamente ed in maniera molto semplice.</p>
<p>Scarichiamo la libreria dal sito: <a href="http://sourceforge.net/projects/json-lib/files/json-lib/">http://sourceforge.net/projects/json-lib/files/json-lib/</a></p>
<p>Inoltre dobbiamo scaricare le relative librerie da cui dipende, che sono:</p>
<ul>
<li>jakarta commons-lang</li>
<li>jakarta commons-beanutils</li>
<li>jakarta commons-collections</li>
<li>jakarta commons-logging</li>
<li>ezmorph</li>
<li>xom (opzionale)</li>
</ul>
<p>Ora possiamo creare un progetto nel nostro IDE Eclipse ed importare queste librerie, creiamo un progetto Web Dinamico così potremo vedere anche quale sarà l’output in una ipotetica JSP che gira su di un Application Server (nel nostro caso Tomcat).</p>
<p>Dalla barra dei menu di Eclipse clicchiamo su File -&gt; New -&gt; Project…, nel wizard per il New Project, selezioniamo Web -&gt; Dynamic Web Project:</p>
<div>
<dl id="attachment_1480">
<dt></dt>
<dt><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/02/nuvo-progetto.jpg"><img title="Nuovo progetto" src="http://www.appuntisoftware.it/wp-content/uploads/2011/02/nuvo-progetto-300x300.jpg" alt="nuvo progetto 300x300 Json lib: una libreria Java per elaborare dati in formato JSON" width="300" height="300" /></a></dt>
</dl>
</div>
<p>Clicchiamo su Next si aprirà questo pannello:</p>
<div>
<div>
<dl id="attachment_1570">
<dt></dt>
<dd>
<div id="attachment_1589"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/05/json.png"><img title="json" src="http://www.appuntisoftware.it/wp-content/uploads/2011/05/json-222x300.png" alt="json 222x300 Json lib: una libreria Java per elaborare dati in formato JSON" width="222" height="300" /></a></p>
<p>Inseriamo in nome del nostro progetto e lasciamo il resto da Default</p>
</div>
</dd>
</dl>
</div>
</div>
<p>Diamo un nome al nostro progetto, scegliamo in Configuration lasciamo Default e clicchiamo su Next fino ad arrivare al tasto Finish (non dobbiamo includere alcuna libreria jar o Runtime particolare).</p>
<p>Includiamo ora nel Build Path le librerie che abbiamo scaricato precedentemente. Per farlo possiamo copiare la libreria direttamente nel folder /WebContent/WEB-INF/lib tramite drag and drop dalla cartella in cui l’abbiamo scaricata, così facendo ritroveremo la libreria sotto <em>Web App Libraries:</em></p>
<p>&nbsp;</p>
<div id="attachment_1591"><em><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/05/json2.png"><img title="json2" src="http://www.appuntisoftware.it/wp-content/uploads/2011/05/json2-300x202.png" alt="json2 300x202 Json lib: una libreria Java per elaborare dati in formato JSON" width="300" height="202" /></a></em></p>
<p>Le librerie compariranno sotto il folder Web App Libraries</p>
</div>
<p>A questo punto creiamo una classe di Test (TestJson.java) e proviamo il comportamento della libreria:</p>
<div id="highlighter_355286">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>package</code> <code>it.appuntisoftware;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>import</code> <code>java.util.ArrayList;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>import</code> <code>java.util.List;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>import</code> <code>net.sf.json.JSONArray;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>public</code> <code>class</code> <code>TestJson {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>public</code> <code>static</code> <code>void</code> <code>main (String args[]){</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>boolean</code><code>[] boolArray = </code><code>new</code> <code>boolean</code><code>[]{</code><code>true</code><code>,</code><code>false</code><code>,</code><code>true</code><code>};</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>JSONArray jsonArray = JSONArray.fromObject( boolArray );</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>System.out.println( jsonArray );</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>List&lt;String&gt; list = </code><code>new</code> <code>ArrayList&lt;String&gt;();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>list.add( </code><code>"primo"</code> <code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>list.add( </code><code>"secondo"</code> <code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>15</code></td>
<td><code>jsonArray = JSONArray.fromObject( list );</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>16</code></td>
<td><code>System.out.println( jsonArray );</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>17</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>18</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Otterremo questo output a video:</p>
<pre>[true,false,true]
["primo","secondo"]</pre>
<p>Coerentemente a quanto previsto dallo standard JSON per array di boolean e di tipo stringa.</p>
<p>Proviamo ora a convertire un oggetto di una nostra classe preesistente in formato JSON. Definiamo un oggetto di tipo OggettoGenerico (o qualsiasi nome di fantasia) con delle proprietà che possono essere variabili di tipo booleano, Stringhe o Array:</p>
<div id="highlighter_506900">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>package</code> <code>it.appuntisoftware;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>import</code> <code>net.sf.json.JSONFunction;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>public</code> <code>class</code> <code>OggettoGenerico {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>private</code> <code>String nome = </code><code>"aappuntisoftware"</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>private</code> <code>int</code> <code>id = </code><code>1</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>private</code> <code>char</code><code>[] caratteri = </code><code>new</code> <code>char</code><code>[]{</code><code>'a'</code><code>,</code><code>'f'</code><code>};</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>private</code> <code>String func = </code><code>"function(i){ return this.options[i]; }"</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>private</code> <code>JSONFunction funzione = </code><code>new</code> <code>JSONFunction(</code><code>new</code> <code>String[]{</code><code>"i"</code><code>},</code><code>"return this.options[i];"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>//Metodi Getter e Setter</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Nell’esempio abbiamo istanziato un tipo particolare di nome JSONFunction, il quale rappresenta una funzione JavaScript (ovviamente non rappresentabile direttamente in Java ma presente nel linguaggio JSON, in altre parole possiamo trasferire dal Server al Client delle funzioni JavaScript). Oltre ai tipi standard presenti nel linguaggio Java la libreria ci fornisce dunque altri tipi che sono presenti nel linguaggio JSON e sono:</p>
<ul>
<li>JSONFunction</li>
<li>JSONArray</li>
<li>JSONObject</li>
</ul>
<p>Per convertire l’oggetto Java in JSON utilizziamo la funzione fromObject() della classe JSONObject in questo modo:</p>
<div id="highlighter_430410">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>package</code> <code>it.appuntisoftware;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>import</code> <code>net.sf.json.JSONObject;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>public</code> <code>class</code> <code>TestJson {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>public</code> <code>static</code> <code>void</code> <code>main (String args[]){</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>JSONObject jsonObject = JSONObject.fromObject(</code><code>new</code> <code>OggettoGenerico() );</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>System.out.println( jsonObject );</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>che produrrà questo output :</p>
<p>{“caratteri”:["a","f"],”func”:function(i){ return this.options[i]; },”funzione”:function(i){ return this.options[i]; },”id”:1,”nome”:”aappuntisoftware”}</p>
<p>dove le coppie sono ordinate alfabeticamente in base al nome della coppia nome/valore (ordine che non ha alcuna ripercussione sulle applicazioni JavaScript che utilizzano l’oggetto, in quanto l’ordine dei dati non conta!).</p>
<p>Vediamo ora come poter utilizzare la libreria all’interno di una JSP:</p>
<div id="highlighter_48393">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;%@ page language=</code><code>"java"</code> <code>contentType=</code><code>"text/html; charset=ISO-8859-1"</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>pageEncoding=</code><code>"ISO-8859-1"</code><code>%&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>&lt;!DOCTYPE html PUBLIC </code><code>"-//W3C//DTD HTML 4.01 Transitional//EN"</code><code>"<a href="http://www.w3.org/TR/html4/loose.dtd">http://www.w3.org/TR/html4/loose.dtd</a>"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>&lt;html&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>&lt;head&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>&lt;meta http-equiv=</code><code>"Content-Type"</code> <code>content=</code><code>"text/html; charset=ISO-8859-1"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>&lt;title&gt;Insert title here&lt;/title&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>&lt;/head&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>&lt;body&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>&lt;%</code><code>@page</code> <code>import</code><code>=</code><code>"net.sf.json.JSONObject"</code><code>%&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>&lt;%</code><code>@page</code> <code>import</code><code>=</code><code>"it.appuntisoftware.OggettoGenerico"</code> <code>%&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>&lt;%</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>JSONObject jsonObject = JSONObject.fromObject(</code><code>new</code> <code>OggettoGenerico() );</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>%&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>15</code></td>
<td><code>&lt;%=jsonObject%&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>16</code></td>
<td><code>&lt;/body&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>17</code></td>
<td><code>&lt;/html&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Otterremo lo stesso output dell’esempio precedente ma in esecuzione su un Application Server (vedremo in un prossimo articolo come utilizzare questi dati).</p>
<p>Riferimenti</p>
<p>[<a name="1"></a>1] Tratto dal sito web di riferimento dello standard: <a href="http://json.org/">http://json.org</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/YuaK4FyD2UXjLlcXo35UpfbEltc/0/da"><img src="http://feedads.g.doubleclick.net/~a/YuaK4FyD2UXjLlcXo35UpfbEltc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/YuaK4FyD2UXjLlcXo35UpfbEltc/1/da"><img src="http://feedads.g.doubleclick.net/~a/YuaK4FyD2UXjLlcXo35UpfbEltc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/VlPCCfT-eoU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/json-lib-una-libreria-java-per-elaborare-dati-in-formato-json/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/json-lib-una-libreria-java-per-elaborare-dati-in-formato-json/</feedburner:origLink></item>
		<item>
		<title>Sviluppare un’applicazione web Ajax con Java ed Ext JS</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/ZsRBGpHtrJM/</link>
		<comments>http://www.danieleserio.it/sviluppare-unapplicazione-web-ajax-con-java-ed-ext-js-2/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 09:00:33 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[Guide e Tutorial]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programmazione]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2320</guid>
		<description><![CDATA[In questo post vedremo come sviluppare un’applicazione web Ajax, acronimo di Asynchronous JavaScript and XML, utilizzando Java come tecnologia server side ed il framework JavaScript Ext JS per la parte Client side. Lo sviluppo di applicazioni web con Ajax si basa su uno scambio di dati in background fra web browser e server, che consente l’aggiornamento dinamico di una pagina web senza esplicito ricaricamento da [...]]]></description>
			<content:encoded><![CDATA[<p>In questo post vedremo come sviluppare un’applicazione web Ajax, acronimo di <strong>Asynchronous JavaScript and XML</strong>, utilizzando Java come tecnologia server side ed il framework JavaScript Ext JS per la parte Client side. Lo sviluppo di applicazioni web con Ajax si basa su uno scambio di dati in background fra web browser e server, che consente l’aggiornamento dinamico di una pagina web senza esplicito ricaricamento da parte dell’utente. Ajax è asincrono nel senso che i dati extra sono richiesti al server e caricati in background senza interferire con il comportamento della pagina esistente.<span id="more-2320"></span></p>
<p>Come formato di scambio dei dati utilizzeremo il protocollo JSON che è supportato nativamente da Ext JS, mentre per Java utilizzeremo la libreria <a href="http://www.appuntisoftware.it/json-lib-una-libreria-java-per-elaborare-dati-in-formato-json/" target="_blank">Json-lib</a> che consente di convertire i tipi di dati Java in tipi di dati JavaScript.</p>
<p>&nbsp;</p>
<p>La prima cosa da fare è scaricare la libreria .jar e relative dipendenze (si veda questo <a href="http://www.appuntisoftware.it/json-lib-una-libreria-java-per-elaborare-dati-in-formato-json/" target="_blank">articolo</a>) di Json-lib a questo indirizzo:</p>
<p><a href="http://sourceforge.net/projects/json-lib/files/json-lib/">http://sourceforge.net/projects/json-lib/files/json-lib/</a></p>
<p>Se abbiamo già seguito l’articolo su <a href="http://www.appuntisoftware.it/ext-js-un-framework-javascript-multiuso/" target="_blank">Ext JS</a>, possiamo saltare la fase seguente di download di Ext JS e configurazione del progetto Eclipse e cominciare da <a href="http://www.appuntisoftware.it/sviluppare-unapplicazione-web-ajax-con-java-ed-ext-js/#json-lib">qui</a>.</p>
<p>Altrimenti bisogna ottenere il framework Ext JS (giunta alla versione 4) da questo indirizzo:</p>
<p><a href="http://www.sencha.com/products/extjs/download/">http://www.sencha.com/products/extjs/download/ext-js-4/173</a></p>
<p>Per i nostri esempio utilizzeremo come di consueto l’IDE Eclipse, di conseguenza la prima cosa dare è creare un progetto di tipo Web Dinamico.</p>
<p>Dalla barra dei menu di Eclipse clicchiamo su File -&gt; New -&gt; Project…, nel wizard per il New Project, selezioniamo Web -&gt; Dynamic Web Project:</p>
<div>
<dl id="attachment_1480">
<dt></dt>
<dt><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/02/nuvo-progetto.jpg"><img title="Nuovo progetto" src="http://www.appuntisoftware.it/wp-content/uploads/2011/02/nuvo-progetto-300x300.jpg" alt="nuvo progetto 300x300 Sviluppare unapplicazione web Ajax con Java ed Ext JS" width="300" height="300" /></a></dt>
</dl>
</div>
<p>Clicchiamo su Next si aprirà questo pannello:</p>
<div><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/05/ext.png"><img title="ext" src="http://www.appuntisoftware.it/wp-content/uploads/2011/05/ext-222x300.png" alt="ext 222x300 Sviluppare unapplicazione web Ajax con Java ed Ext JS" width="222" height="300" /></a></p>
<p>Inseriamo in nome del nostro progetto e lasciamo il resto da Default</p>
</div>
<div> </div>
<p>Diamo un nome al nostro progetto, scegliamo in Configuration lasciamo Default e clicchiamo su Next fino ad arrivare al tasto Finish (non dobbiamo includere alcuna libreria jar o Runtime particolare).</p>
<p>Creiamo una cartella js all’interno di WebContent e vi copiamo i file ext-all.js, ext-all-debug.js e bootstrap.js che sono presenti nel pacchetto ext-4.0.0-gpl.zip che abbiamo scaricato in precedenza.</p>
<p>Copiamo poi la cartella resources all’interno di WebContent, possiamo copiarci anche la cartella locale (che contiene le stringhe per la localizzazione) anche se al momento non la usiamo.</p>
<p>Otteniamo queste cartelle nel notro progetto:</p>
<div><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/05/ext2.png"><img title="ext2" src="http://www.appuntisoftware.it/wp-content/uploads/2011/05/ext2.png" alt="ext2 Sviluppare unapplicazione web Ajax con Java ed Ext JS" width="277" height="292" /></a></p>
<p>La struttura del nostro progetto</p>
</div>
<p><a name="json-lib"></a>Includiamo ora nel Build Path le librerie che abbiamo scaricato precedentemente. Per farlo possiamo copiare la libreria direttamente nel folder /WebContent/WEB-INF/lib tramite drag and drop dalla cartella in cui l’abbiamo scaricata, così facendo ritroveremo la libreria sotto <em>Web App Libraries:</em></p>
<div><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/05/json2.png"><img title="json2" src="http://www.appuntisoftware.it/wp-content/uploads/2011/05/json2-300x202.png" alt="json2 300x202 Sviluppare unapplicazione web Ajax con Java ed Ext JS" width="300" height="202" /></a></p>
<p>Le librerie compariranno sotto il folder Web App Libraries</p>
</div>
<p>&nbsp;</p>
<p>Creiamo ora una pagina HTML5 nel nostro progetto, cliccando col tasto destro sulla cartella WebContent dello stesso e scegliendo poi New -&gt; Other…, nella categoria Web selezioniamo HTML File e clicchiamo Next. Digitiamo ora il nome della pagina e continuiamo con Next, nella prossima schermata, tra i vari template, scegliamo New HTML5 Page.</p>
<p>La pagina viene ora aperta all’interno del nostro editor e mostra il seguente codice:</p>
<div id="highlighter_543955">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;!DOCTYPE html&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>&lt;</code><code>html</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>&lt;</code><code>head</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>&lt;</code><code>meta</code> <code>charset</code><code>=</code><code>"ISO-8859-1"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>&lt;</code><code>title</code><code>&gt;Insert title here&lt;/</code><code>title</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>&lt;/</code><code>head</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>&lt;</code><code>body</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>&lt;/</code><code>body</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>&lt;/</code><code>html</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>creiamo al suo interno un pannello di tipo form utilizzando Ext JS, lo popoliamo con due campi ti testo semplici e due pulsanti, uno  di invio del form ed uno che azzeri i campi:</p>
<div id="highlighter_899748">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;!DOCTYPE html PUBLIC </code><code>"-//W3C//DTD HTML 4.01 Transitional//EN"</code><code>"<a href="http://www.w3.org/TR/html4/loose.dtd">http://www.w3.org/TR/html4/loose.dtd</a>"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>&lt;html&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>&lt;head&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>&lt;meta http-equiv=</code><code>"Content-Type"</code> <code>content=</code><code>"text/html; charset=ISO-8859-1"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>&lt;title&gt;AppuntiSoftware.it - Esempio Ajax&lt;/title&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>&lt;script type=</code><code>"text/javascript"</code> <code>src=</code><code>"./js/bootstrap.js"</code><code>&gt;&lt;/script&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>&lt;link rel=</code><code>"stylesheet"</code> <code>type=</code><code>"text/css"</code> <code>href=</code><code>"./resources/css/ext-all.css"</code> <code>/&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>&lt;script type=</code><code>"text/javascript"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>Ext.onReady(</code><code>function</code><code>(){</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code> </code><code>Ext.create(</code><code>'Ext.form.Panel'</code><code>, {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>  </code><code>title: </code><code>'Test Form'</code><code>,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>  </code><code>renderTo: Ext.getBody(),</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>  </code><code>bodyPadding: 5,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>  </code><code>width: 350,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>15</code></td>
<td><code>  </code><code>height: 200,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>16</code></td>
<td><code>  </code><code>// Il form invia una richiesta AJAX a questa URL</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>17</code></td>
<td><code>  </code><code>url: </code><code>'testAjax.jsp'</code><code>,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>18</code></td>
<td><code>  </code><code>layout: {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>19</code></td>
<td><code>   </code><code>type: </code><code>'vbox'</code><code>,       </code><code>// Posiziona i campi verticalmente</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>20</code></td>
<td><code>   </code><code>align: </code><code>'stretch'</code><code>,    </code><code>// Ognuno occupa tutta la larghezza</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>21</code></td>
<td><code>   </code><code>padding: 20</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>22</code></td>
<td><code>  </code><code>},</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>23</code></td>
<td><code>  </code><code>items: [{</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>24</code></td>
<td><code>   </code><code>fieldLabel: </code><code>'Nome'</code><code>,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>25</code></td>
<td><code>   </code><code>name: </code><code>'nome'</code><code>,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>26</code></td>
<td><code>   </code><code>minLength : 5,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>27</code></td>
<td><code>   </code><code>allowBlank: </code><code>false</code><code>,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>28</code></td>
<td><code>   </code><code>xtype: </code><code>'textfield'</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>29</code></td>
<td><code>   </code><code>},{</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>30</code></td>
<td><code>   </code><code>fieldLabel: </code><code>'Cognome'</code><code>,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>31</code></td>
<td><code>   </code><code>name: </code><code>'cognome'</code><code>,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>32</code></td>
<td><code>   </code><code>minLength : 5,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>33</code></td>
<td><code>   </code><code>allowBlank: </code><code>false</code><code>,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>34</code></td>
<td><code>   </code><code>xtype: </code><code>'textfield'</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>35</code></td>
<td><code>   </code><code>}],</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>36</code></td>
<td><code>  </code><code>buttons: [{</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>37</code></td>
<td><code>   </code><code>text: </code><code>'Reset'</code><code>,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>38</code></td>
<td><code>   </code><code>handler: </code><code>function</code><code>() {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>39</code></td>
<td><code>   </code><code>this</code><code>.up(</code><code>'form'</code><code>).getForm().reset();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>40</code></td>
<td><code>   </code><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>41</code></td>
<td><code>   </code><code>}, {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>42</code></td>
<td><code>   </code><code>text: </code><code>'Invia'</code><code>,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>43</code></td>
<td><code>   </code><code>handler: </code><code>function</code><code>() {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>44</code></td>
<td><code>    </code><code>// Il metodo getForm()ritorna una istanza di Ext.form.Basic</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>45</code></td>
<td><code>    </code><code>var</code> <code>form = </code><code>this</code><code>.up(</code><code>'form'</code><code>).getForm();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>46</code></td>
<td><code>    </code><code>if</code> <code>(form.isValid()) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>47</code></td>
<td><code>      </code><code>// Invia la richiesta Ajax e gestisci la risposta</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>48</code></td>
<td><code>      </code><code>form.submit({</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>49</code></td>
<td><code>       </code><code>success: </code><code>function</code><code>(form, action) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>50</code></td>
<td><code>        </code><code>Ext.Msg.alert(</code><code>'Successo'</code><code>, action.result.msg);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>51</code></td>
<td><code>        </code><code>},</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>52</code></td>
<td><code>      </code><code>failure: </code><code>function</code><code>(form, action) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>53</code></td>
<td><code>       </code><code>switch</code> <code>(action.failureType) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>54</code></td>
<td><code>        </code><code>case</code> <code>Ext.form.action.Action.CLIENT_INVALID:</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>55</code></td>
<td><code>          </code><code>Ext.Msg.alert(</code><code>'Errore'</code><code>, </code><code>'I campi del Form non possono essere inviati con valori errati'</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>56</code></td>
<td><code>        </code><code>break</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>57</code></td>
<td><code>        </code><code>case</code> <code>Ext.form.action.Action.CONNECT_FAILURE:</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>58</code></td>
<td><code>          </code><code>Ext.Msg.alert(</code><code>'Errore'</code><code>, </code><code>'Errore nella comunicazione Ajax'</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>59</code></td>
<td><code>        </code><code>break</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>60</code></td>
<td><code>         </code><code>case</code> <code>Ext.form.action.Action.SERVER_INVALID:</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>61</code></td>
<td><code>          </code><code>Ext.Msg.alert(</code><code>'Errore'</code><code>, </code><code>'Richiesta non valida'</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>62</code></td>
<td><code>     </code><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>63</code></td>
<td><code>    </code><code>},</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>64</code></td>
<td><code>    </code><code>waitMsg: </code><code>'Waiting...'</code><code>,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>65</code></td>
<td><code>    </code><code>waitTitle: </code><code>'Attendere prego'</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>66</code></td>
<td><code>    </code><code>});</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>67</code></td>
<td><code>  </code><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>68</code></td>
<td><code>  </code><code>else</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>69</code></td>
<td><code>    </code><code>Ext.Msg.alert(</code><code>'Errore'</code><code>, </code><code>"Campi del Form non validi!"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>70</code></td>
<td><code>  </code><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>71</code></td>
<td><code>  </code><code>}]</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>72</code></td>
<td><code> </code><code>});</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>73</code></td>
<td><code>});</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>74</code></td>
<td><code>&lt;/script&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>75</code></td>
<td><code>&lt;/head&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>76</code></td>
<td><code>&lt;body&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>77</code></td>
<td><code>&lt;/body&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>78</code></td>
<td><code>&lt;/html&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Dettagliamo meglio il codice scritto: come si vede esso è posizionato tutto all’interno della funzione onReady per essere sicuri che tutti gli elementi DOM siano caricati; dopo creiamo un form di tipo Ext.form.panel assegnandogli un titolo con l’attributo title, come posizione il tag html body, utilizzando Ext.getBody(), il padding e le dimensioni.<br />L’attributo url specifica l’indirizzo a cui verrà inoltrata la richiesta Ajax, nel nostro caso essa sarà diretta alla pagina jsp testAjax.jsp, supponendo che stiamo lavorando su localhost, l’indirizzo completo è il seguente:</p>
<pre>http://localhost:8080/nomeprogetto/testAjax.jsp</pre>
<p>Posizioniamo all’interno del pannello un layout di tipo vbox, così facendo i campi che aggiungiamo verranno disposti verticalmente occupando tutta la larghezza (attributo stretch).</p>
<p>Inseriamo i due field che saranno di tipo <em>textfield </em>(settando xtype: ‘textfield’) aggiungiamo anche un controllo sulla lunghezza (i dati inseriti devono essere lunghi almeno 5 caratteri e senza caratteri blank).</p>
<p>Infine vi sono i due pulsanti di invio e di reset. Quest’ultimo ha come handler una funzione che resetta tutti i campi nel momento in cui si clicca sul pulsante.</p>
<p>Il pulsante Invia ha invece una funzione handler la quale recupera il form e se è valido (i campi sono corretti) lo invia all’url che abbiamo specificato sopra.</p>
<p>In caso di successo viene recuperata la variabile <em>msg </em>dal risultato ottenuto e stampata a video, altrimenti viene richiamato l’handler failure e viene stampato a video la condizione di errore in base al codice ritornato.</p>
<p>Durante le operazioni di scambio messaggi, viene visualizzato un pannellino di attesa.</p>
<p>La risposta attesa dal form in formato JSON è di questo tipo:</p>
<div id="highlighter_831909">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>{</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code> </code><code>"success"</code><code>:</code><code>true</code><code>, </code><code>// di tipo Booleano e non String</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>"msg"</code><code>:</code><code>"Inviato con successo"</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>se la richiesta non è stata accettata, altrimenti:</p>
<div id="highlighter_419680">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>{</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code> </code><code>"success"</code><code>:</code><code>false</code><code>, </code><code>// di tipo Booleano e non String</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code> </code><code>"msg"</code><code>:</code><code>"Richiesta rifiutata"</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Creiamo ora una pagina jsp che con l’ausilio della libreria Json-lib, possa fornire una risposta JSON in quel formato:</p>
<div id="highlighter_125868">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;%</code><code>@page</code> <code>import</code><code>=</code><code>"net.sf.json.JSONObject"</code><code>%&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>&lt;%</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>String nome=request.getParameter(</code><code>"nome"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>String cognome=request.getParameter(</code><code>"cognome"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>String message = </code><code>"Ciao "</code><code>+nome+</code><code>" "</code><code>+cognome;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>JSONObject risposta=</code><code>new</code> <code>JSONObject();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>risposta.put(</code><code>"success"</code><code>, </code><code>true</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>risposta.put(</code><code>"msg"</code><code>,message);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>%&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>&lt;%=risposta%&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Recuperiamo i parametri nome e cognome dalla request (inviateci dal form) e costruiamo una risposta di tipo JSON utilizzando la classe JSONObject fornita dalla libreria.</p>
<p>Proviamo ora la nostra applicazione dovremmo ottenere il seguente risultato a video:</p>
<div id="attachment_1653"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/05/ajax.png"><img title="ajax" src="http://www.appuntisoftware.it/wp-content/uploads/2011/05/ajax-300x187.png" alt="ajax 300x187 Sviluppare unapplicazione web Ajax con Java ed Ext JS" width="300" height="187" /></a></p>
<p>Clicchiamo sul tasto Invia del form ed il server dovrebbe ritornarci la risposta corretta</p>
</div>
<p>Se sostituiamo il valore true con il valore false, nella variabile JSON <em>success</em>(risposta.put(“success”, false);), verrà richiamata la funzione failure dopo il submit e verrà ritornato un codice SERVER_INVALID di conseguenza otterremo questo risultato:</p>
<div id="attachment_1654"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/05/ajax2.png"><img title="ajax2" src="http://www.appuntisoftware.it/wp-content/uploads/2011/05/ajax2-300x176.png" alt="ajax2 300x176 Sviluppare unapplicazione web Ajax con Java ed Ext JS" width="300" height="176" /></a></p>
<p>Con la variabile success settata a false, viene ritornato un errore SERVER_INVALID</p>
</div>
<p>&nbsp;</p>

<p><a href="http://feedads.g.doubleclick.net/~a/yaYBaUcOcPbJCx4wE7SbDEDw67c/0/da"><img src="http://feedads.g.doubleclick.net/~a/yaYBaUcOcPbJCx4wE7SbDEDw67c/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/yaYBaUcOcPbJCx4wE7SbDEDw67c/1/da"><img src="http://feedads.g.doubleclick.net/~a/yaYBaUcOcPbJCx4wE7SbDEDw67c/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/ZsRBGpHtrJM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/sviluppare-unapplicazione-web-ajax-con-java-ed-ext-js-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/sviluppare-unapplicazione-web-ajax-con-java-ed-ext-js-2/</feedburner:origLink></item>
		<item>
		<title>Integrazione di Apache Tomcat su Apache HTTP Server</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/wmZ6918-AYM/</link>
		<comments>http://www.danieleserio.it/integrazione-di-apache-tomcat-su-apache-http-server-2/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 08:58:56 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[Guide e Tutorial]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2316</guid>
		<description><![CDATA[In questo post vedremo come poter integrare l’Application Server Apache Tomcat su di un server HTTP Apache, in questo modo potremo aggiungere la capacità di eseguire Servlet o pagine jsp ad un Server Web Apache già installato e funzionante. Il motivo che ci può condurre a questa scelta sono essenzialmente due: per maggior flessibilità, possiamo [...]]]></description>
			<content:encoded><![CDATA[<p>In questo post vedremo come poter integrare l’Application Server Apache Tomcat su di un server HTTP Apache, in questo modo potremo aggiungere la capacità di eseguire Servlet o pagine jsp ad un Server Web Apache già installato e funzionante.<span id="more-2316"></span></p>
<p>Il motivo che ci può condurre a questa scelta sono essenzialmente due:</p>
<ul>
<li>per maggior flessibilità, possiamo far girare Apache HTTP Server su di una macchina e Apache Tomcat su di un’altra, aggiungendo anche maggior sicurezza ad esempio posizionando il server su cui gira Tomcat dietro ad un firewall accessibile solo da Apche HTTP Server;</li>
<li>per maggior stabilità, Apache HTTP è notoriamente più stabile e veloce di Tomcat ed inoltre un eventuale crash di Tomcat renderebbe solo le jsp e le Servelt non raggiungibili.</li>
</ul>
<p>&nbsp;</p>
<p>Per poter perseguire i nostri scopi illustreremo due metodi possibili:</p>
<ol>
<li>utilizzando un Reverse Proxy (più lento ma semplice da configurare);</li>
<li>utilizzando il connettore jk (più efficiente ma leggermente più laborioso da configurare).</li>
</ol>
<p>Iniziamo col vedere come impostare un proxy di tipo reverse verso Tomcat, bisogna scegliere quale protocollo utilizzare:  HTTP o AJP; AJP offre migliori performance in quanto è un protocollo binario al contrario di HTTP che è un formato testuale (<a href="http://wiki.apache.org/tomcat/FAQ/Connectors#Q2">http://wiki.apache.org/tomcat/FAQ/Connectors#Q2</a>), HTTP potrebbe però essere l’unica scelta se i due Server (Apache e Tomcat) comunicano attraverso un Firewall per questioni di sicurezza come abbiamo spiegato in precedenza. Detto ciò forniremo un esempio per ognuno dei due casi. Un altro limite di AJP è che il formato dei pacchetti scambiati non può superare la dimensione di 8 KB.</p>
<p>Supponiamo di voler usare un proxy di tipo http, bisogna innanzitutto caricare i moduli mod_proxy.so e mod_proxy_http.so che sono già inclusi nella cartella modules di Apache:</p>
<div id="highlighter_273081">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>LoadModule proxy_module modules/mod_proxy.so</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>LoadModule proxy_http_module modules/mod_proxy_http.so</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>poi dobbiamo  inserire questa direttiva all’interno del file http.conf di Apache:</p>
<div id="highlighter_700390">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;</code><code>Location</code> <code>/esempi/&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>ProxyPass <a href="http://localhost:8080/examples/">http://localhost:8080/examples/</a></code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>ProxyPassReverse <a href="http://localhost:8080/examples/">http://localhost:8080/examples/</a></code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>&lt;/</code><code>Location</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>nel nostro esempio sia Apche che Tomcat si trovano sulla stessa macchina (di conseguenza possiamo usare localhost invece dell’ip della macchina) e Tomcat è in ascolto sulla porta 8080 (la porta di default), mentre supponiamo che Apache giri su porta 80. La porzione di url /esempi/  contenuta in Location indica che le nostre richieste per l’url <a href="http://localhost/esempi/" target="_blank">http://localhost/esempi/</a>vengano girate al context path <em>examples</em> che si trova nella cartella webapps (cartella di deploy di default di Tomcat) .</p>
<p>Se vogliamo usare il protocollo AJP dobbiamo includere questi moduli:</p>
<div id="highlighter_521255">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>LoadModule proxy_module modules/mod_proxy.so</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>LoadModule proxy_ajp_module modules/mod_proxy_ajp.so</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>e cambiare la direttiva in questo modo:</p>
<div id="highlighter_318132">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;</code><code>Location</code> <code>/esempi/&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>ProxyPass <a href="ajp://localhost:8009/examples/">ajp://localhost:8009/examples/</a></code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>&lt;/</code><code>Location</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>le modalità di redirecting restano le stesse.</p>
<p>Vediamo ora come usare il connettore mod_jk, che è l’evoluzione recente del precedente mod_jserv. I vantaggi rispetto ai moduli proxy sono una migliorata gestione del load balancing, del controllo degli errori ed un supporto per pacchetti AJP più grandi di 8 KB, di contro il modulo non è integrato nella distribuzione di Apache HTTP Server e potrebbe essere necessario effettuarne il build (compilazione) per uno specifico S.O. se esso non è disponibile.</p>
<p>Dunque per provare questo modulo bisogna scaricarlo dal sito Apache, lo facciamo andando a questa url e scegliendo quello giusto per il nostro Sistema Operativo:</p>
<p><a href="http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/">http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/</a></p>
<p>la versione che uso in questo articolo è la 1.2.31 del Novembre 2010 (versione Windows a 32 bit).</p>
<p>Scaricato il modulo lo rinominiamo<em> mod_jk.so</em> e lo posizioniamo nella cartella modules, a questo punto possiamo includerlo nel nostro file<em> httpd.conf </em>in questo modo:</p>
<div id="highlighter_117994">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>LoadModule jk_module modules/mod_jk.so</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>inseriamo poi questa direttiva</p>
<div id="highlighter_397075">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;</code><code>IfModule</code> <code>jk_module&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code># Path di workers.properties</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code># è consigliabile inserire workers.properties nella stessa cartella di httpd.conf</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>JkWorkersFile conf/workers.properties</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code># Path dei log di jk</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code># è  consigliabile inserire mod_jk.log nella stessa cartella di access_log</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>JkLogFile logs/mod_jk.log</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code># Settiamo il livello del log di jk [debug/error/info]</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>JkLogLevel info</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code># Settiamo il formato del log</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>15</code></td>
<td><code>JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>16</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>17</code></td>
<td><code># JkOptions indicano di inviare la SSL KEY SIZE,</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>18</code></td>
<td><code>JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>19</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>20</code></td>
<td><code># JkRequestLogFormat setta il formato della richiesta</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>21</code></td>
<td><code>JkRequestLogFormat "%w %V %T"</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>22</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>23</code></td>
<td><code># Inviat tutto per il context /examples al worker dal nome worker1 (ajp13)</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>24</code></td>
<td><code>JkMount /esempi/* worker1</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>25</code></td>
<td><code>&lt;/</code><code>IfModule</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Abbiamo indicato il path del file workers.properties e del file di log, inoltre abbiamo specificato delle opzioni del modulo JK, in particolare con <em>JKMount</em> abbiamo specificato che alla richiesta dell’url /esempi/  questa venga girata da Apache a Tomcat.</p>
<p>Dobbiamo ora creare un file<em> worker.properties</em> e lo posizioniamo nella cartella /conf di Apache:</p>
<div id="highlighter_406913">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code># Definiamo un worker che usi ajp13</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>worker.list=worker1</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code># Settiamo le proprietà per il worker1 (ajp13)</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>worker.worker1.type=ajp13</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>worker.worker1.host=localhost</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>worker.worker1.port=8009</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>worker.worker1.lbfactor=50</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>worker.worker1.cachesize=10</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>worker.worker1.cache_timeout=600</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>worker.worker1.socket_keepalive=1</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>worker.worker1.socket_timeout=300</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>alcune di queste proprietà sono deprecate e quindi possiamo anche eliminarle (cachesize e cache_timeout). Un worker Tomcat è una istanza di Tomcat che è in attesa per eseguire una Servlet o una pagina JSP, per cui abbiamo Apache HTTP Server che invia tramite forward una Servlet o una JSP ad un processo Tomcat (il worker dunque). Tramite il file di properties abbiamo specificato alcune proprietà del worker (lo abbiamo chiamato worker1), possiamo definirne degli altri semplicemente aggiungendo una lista separata da virgole dopo la entry<em>worker.list</em> (ad esempio<em> worker.list= worker1, worker2, etc…</em>). La proprietà type è l’unica obbligatoria e definisce il protocollo utilizzato (AJP versione 1.3) mentre host sarà l’indirizzo di Tomcat (nel nostro caso gira sulla stessa macchina di Apache) e port 8009 è la porta di default del protocollo AJP13. La lista completa di proprietà è a questo indirizzo :<a href="http://tomcat.apache.org/connectors-doc/reference/workers.html">http://tomcat.apache.org/connectors-doc/reference/workers.html</a>.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/zHyRwN9FnYGuSGic-UqFpW9lTBk/0/da"><img src="http://feedads.g.doubleclick.net/~a/zHyRwN9FnYGuSGic-UqFpW9lTBk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/zHyRwN9FnYGuSGic-UqFpW9lTBk/1/da"><img src="http://feedads.g.doubleclick.net/~a/zHyRwN9FnYGuSGic-UqFpW9lTBk/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/wmZ6918-AYM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/integrazione-di-apache-tomcat-su-apache-http-server-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/integrazione-di-apache-tomcat-su-apache-http-server-2/</feedburner:origLink></item>
		<item>
		<title>Apache MyFaces: un’implementazione Open Source delle specifiche JSF</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/z6MH_khp4UM/</link>
		<comments>http://www.danieleserio.it/apache-myfaces-unimplementazione-open-source-delle-specifiche-jsf-2/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 08:57:34 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[Guide e Tutorial]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programmazione]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2312</guid>
		<description><![CDATA[In questo articolo analizzeremo il progetto Apache MyFaces che ha come scopo di creare e manutenere una implementazione Open Source (secondo la licenza Apache versione 2) delle specifiche JavaServer Faces, inoltre include una serie di sotto progetti che forniscono componenti aggiuntivi, servizi di integrazione per altre tecnologie (ad esempio Portali), etc… . La lista completa [...]]]></description>
			<content:encoded><![CDATA[<p>In questo articolo analizzeremo il progetto Apache MyFaces che ha come scopo di creare e manutenere una implementazione Open Source (secondo la licenza Apache versione 2) delle specifiche JavaServer Faces, inoltre include una serie di sotto progetti che forniscono componenti aggiuntivi, servizi di integrazione per altre tecnologie (ad esempio Portali), etc… .<span id="more-2312"></span></p>
<p>La lista completa dei sotto progetti include:</p>
<ul>
<li><strong>Core</strong>: un’implementazione delle specifiche e dei componenti JSF 1.1, JSF 1.2, JSF 2.0 e JSF 2.1 come specificato dalle <a href="http://www.jcp.org/en/jsr/detail?id=127" rel="nofollow">JSR 127</a>, <a href="http://www.jcp.org/en/jsr/detail?id=252" rel="nofollow">JSR 252</a> and <a href="http://www.jcp.org/en/jsr/detail?id=314" rel="nofollow">JSR 314</a> rispettivamente;</li>
<li><strong>Portlet Bridge</strong>: un’implementazione delle specifiche JSF Portlet Bridge come specificato dalla <a href="http://www.jcp.org/en/jsr/detail?id=301" rel="nofollow">JSR 301</a>;</li>
<li><strong>Tomahawk</strong>: un set di componenti JSF components creati dal team di sviluppo MyFaces prima che passasse sotto l’egida Apache;</li>
<li><strong>Trinidad</strong>: un set di componenti JSF donati a MyFaces da Oracle, prima conosciuti come ADF Faces;</li>
<li><strong>Tobago</strong>: un set di componenti JSF sviluppati per MyFaces da Atanion GmbH;</li>
<li><strong>Orchestra</strong>: un framework utilizzato per gestire la persistenza delle sessioni attraverso scope diversi;</li>
<li><strong>Extensions Validator</strong>: un framework per la validazione JSF centrica, basato sulle annotazioni;</li>
<li><strong>Others</strong>: sotto progetti più piccoli quali ad esempio <strong>MyFaces Commons</strong> e <strong>MyFaces Shared</strong>.</li>
</ul>
<p>Come si può notare esiste un componente Core per ogni specifica versione di JSF, dalla 1.1 alla 2.1 che è la versione più recente disponibile e che andremo ad usare nei nostri esempi. La versione JSF 2.1 richiede come requisito la JVM 1.5 o successiva, e le implementazioni JSP 2.1, JSTL 1.2 e Java Servlet 2.5.</p>
<p>Il componente Core si divide poi in due sottomoduli:</p>
<ul>
<li><strong>MyFaces API:</strong> implementa tutte le classi che sono definite nella spefica JSF;</li>
<li><strong>MyFaces Impl: </strong>fornisce classi di supporto (invisibili) che il codice di uno sviluppatore non invoca direttamente, ma che sono necessarie per il funzionamento del framework. Ad esempio le classi di rendering per i componenti JSF.</li>
</ul>
<p>Iniziamo andando a  scaricare le librerie Core, che troviamo a questo indirizzo:</p>
<p><a href="http://myfaces.apache.org/download.html">http://myfaces.apache.org/download.html</a></p>
<p>la versione più recente al momento in cui scriviamo è la 2.1.1.</p>
<p>Nella stessa pagina in basso troviamo i link ai download per gli altri sotto progetti, in particolare se andiamo sul link di MyFaces Tomahawk (<a href="http://myfaces.apache.org/tomahawk/download.html">http://myfaces.apache.org/tomahawk/download.html</a>) possiamo recuperare un file .war di esempi che ci permettono di visionare tutti i componenti a disposizione.</p>
<p>Vediamo ora come creare un esempio funzionante utilizzando l’IDE Eclipse.</p>
<p>Dalla barra dei menu di Eclipse clicchiamo su File -&gt; New -&gt; Project…, nel wizard per il New Project, selezioniamo Web -&gt; Dynamic Web Project:</p>
<div><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/02/nuvo-progetto.jpg"><img title="Creiamo un nuovo Progetto Web Dinamico" src="http://www.appuntisoftware.it/wp-content/uploads/2011/02/nuvo-progetto-300x300.jpg" alt="nuvo progetto 300x300 Apache MyFaces: unimplementazione Open Source delle specifiche JSF" width="300" height="300" /></a></p>
<p>Creiamo un nuovo Progetto Web Dinamico</p>
</div>
<p>Clicchiamo su Next si aprirà questo pannello:</p>
<div id="attachment_1789"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/myfaces.png"><img title="myfaces" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/myfaces-246x300.png" alt="myfaces 246x300 Apache MyFaces: unimplementazione Open Source delle specifiche JSF" width="246" height="300" /></a></p>
<p>Inseriamo il nome del Progetto (TestMyFaces), il runtime Target (abbiamo scelto Tomcat v7.0) e per Configuration selezioniamo dalla tendina il valore JavaServer Faces v2.0.</p>
</div>
<p>Clicchiamo su Next finchè non arriviamo alla finestra JSF Capabilities:</p>
<div><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/02/Includiamo-JSF2.jpg"><img title="Includiamo JSF2" src="http://www.appuntisoftware.it/wp-content/uploads/2011/02/Includiamo-JSF2-222x300.jpg" alt="Includiamo JSF2 222x300 Apache MyFaces: unimplementazione Open Source delle specifiche JSF" width="222" height="300" /></a></p>
<p>Elenco delle librerie JSF presenti in Eclipse</p>
</div>
<p>Dobbiamo ora includere le librerie Core e Impl di MyFaces, lo facciamo cliccando su Manage Libraries:</p>
<div id="attachment_1790"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/myfaces3.png"><img title="myfaces3" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/myfaces3-281x300.png" alt="myfaces3 281x300 Apache MyFaces: unimplementazione Open Source delle specifiche JSF" width="281" height="300" /></a></p>
<p>clicchiamo su Manage libraries&#8230;</p>
</div>
<p>Clicchiamo poi su New… e come User Library Name inseriamo MyFaces-2.1.1:</p>
<div id="attachment_1791"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/myfaces2.png"><img title="myfaces2" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/myfaces2-293x300.png" alt="myfaces2 293x300 Apache MyFaces: unimplementazione Open Source delle specifiche JSF" width="293" height="300" /></a></p>
<p>Indichiamo il path delle nostre librerie MyFaces</p>
</div>
<p>Ora possiamo includere la libreria MyFaces ed infine clicchiamo su Finish:</p>
<div id="attachment_1792"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/MyFaces4.png"><img title="MyFaces4" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/MyFaces4-246x300.png" alt="MyFaces4 246x300 Apache MyFaces: unimplementazione Open Source delle specifiche JSF" width="246" height="300" /></a></p>
<p>Spuntiamo la casella di MyFaces-2.1.1</p>
</div>
<p>Dobbiamo ora includere le librerie prerequisito di MyFaces <strong>Core </strong>che sono:</p>
<ul>
<li>commons-beanutils-1.8.3.jar;</li>
<li>commons-codec-1.3.jar;</li>
<li>commons-collections-3.2.jar;</li>
<li>commons-digester-1.8.jar;</li>
<li>commons-logging-1.1.1.jar.</li>
</ul>
<p>queste librerie le troviamo all’interno del pacchetto zip o tar.gz che contiene le librerie Core.</p>
<p>Abbiamo inoltre bisogno delle librerie da cui dipende MyFaces <strong>Tomahawk</strong>, che troviamo nel pacchetto zip o tar.gz che contiene gli esempi (<a href="http://myfaces.apache.org/tomahawk/download.html">http://myfaces.apache.org/tomahawk/download.html</a>)):</p>
<ul>
<li>batik-awt-util-1.6-1.jar;</li>
<li>batik-ext-1.6-1.jar;</li>
<li>batik-gui-util-1.6-1.jar;</li>
<li>batik-util-1.6-1.jar;</li>
<li>commons-el-1.0.jar;</li>
<li>commons-fileupload-1.2.1.jar;</li>
<li>commons-io-1.3.2.jar;</li>
<li>commons-lang-2.4.jar;</li>
<li>commons-validator-1.3.1.jar;</li>
<li>jstl-1.2.jar;</li>
<li>oro-2.0.8.jar;</li>
<li>standard-1.1.2.jar;</li>
<li>tomahawk-1.1.10.jar;</li>
<li>xml-apis-1.0.b2.jar;</li>
<li>xmlParserAPIs-2.0.2.jar.</li>
</ul>
<p>Tutte queste librerie le inseriamo nella cartella WEB-INF/lib come mostrato in figura:</p>
<div id="attachment_1793"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/MyFaces5.png"><img title="MyFaces5" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/MyFaces5-169x300.png" alt="MyFaces5 169x300 Apache MyFaces: unimplementazione Open Source delle specifiche JSF" width="169" height="300" /></a></p>
<p>Inseriamo le librerie nella cartella WebContent/WEB-INF/lib</p>
</div>
<p>inserendole in quella cartella, le librerie saranno caricate automaticamente all’interno del Build Path del progetto, sotto la voce Web App libraries:</p>
<div id="attachment_1794"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/MyFaces6.png"><img title="MyFaces6" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/MyFaces6-300x244.png" alt="MyFaces6 300x244 Apache MyFaces: unimplementazione Open Source delle specifiche JSF" width="300" height="244" /></a></p>
<p>Ritroviamo le librerie sotto la voce Web App libraries</p>
</div>
<p>Dobbiamo ora configurare la Web Application andando a modificare il file <em>web.xml</em>. Lo apriamo in Eclipse e lo rendiamo uguale al seguente:</p>
<div id="highlighter_511582">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;?</code><code>xml</code> <code>version</code><code>=</code><code>"1.0"</code> <code>encoding</code><code>=</code><code>"ASCII"</code><code>?&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>&lt;</code><code>web-app</code> <code>xmlns:xsi</code><code>=</code><code>"<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"</code> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>xmlns</code><code>=</code><code>"<a href="http://java.sun.com/xml/ns/javaee">http://java.sun.com/xml/ns/javaee</a>"</code> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>xmlns:web</code><code>=</code><code>"<a href="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd</a>"</code> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>xsi:schemaLocation</code><code>=</code><code>"<a href="http://java.sun.com/xml/ns/javaee">http://java.sun.com/xml/ns/javaee</a><a href="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd</a>"</code> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>version</code><code>=</code><code>"3.0"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>&lt;</code><code>display-name</code><code>&gt;TestMyFaces&lt;/</code><code>display-name</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>&lt;</code><code>context-param</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>&lt;</code><code>param-name</code><code>&gt;org.apache.myfaces.CHECK_EXTENSIONS_FILTER&lt;/</code><code>param-name</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>&lt;</code><code>param-value</code><code>&gt;true&lt;/</code><code>param-value</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>&lt;/</code><code>context-param</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>&lt;</code><code>filter</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>&lt;</code><code>filter-name</code><code>&gt;extensionsFilter&lt;/</code><code>filter-name</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>&lt;</code><code>filter-class</code><code>&gt;org.apache.myfaces.webapp.filter.ExtensionsFilter</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>15</code></td>
<td><code>&lt;/</code><code>filter-class</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>16</code></td>
<td><code>&lt;</code><code>init-param</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>17</code></td>
<td><code>&lt;</code><code>param-name</code><code>&gt;uploadMaxFileSize&lt;/</code><code>param-name</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>18</code></td>
<td><code>&lt;</code><code>param-value</code><code>&gt;100m&lt;/</code><code>param-value</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>19</code></td>
<td><code>&lt;/</code><code>init-param</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>20</code></td>
<td><code>&lt;</code><code>init-param</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>21</code></td>
<td><code>&lt;</code><code>param-name</code><code>&gt;uploadThresholdSize&lt;/</code><code>param-name</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>22</code></td>
<td><code>&lt;</code><code>param-value</code><code>&gt;100k&lt;/</code><code>param-value</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>23</code></td>
<td><code>&lt;/</code><code>init-param</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>24</code></td>
<td><code>&lt;/</code><code>filter</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>25</code></td>
<td><code>&lt;</code><code>filter-mapping</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>26</code></td>
<td><code>&lt;</code><code>filter-name</code><code>&gt;extensionsFilter&lt;/</code><code>filter-name</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>27</code></td>
<td><code>&lt;</code><code>url-pattern</code><code>&gt;*.jsf&lt;/</code><code>url-pattern</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>28</code></td>
<td><code>&lt;/</code><code>filter-mapping</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>29</code></td>
<td><code>&lt;</code><code>filter-mapping</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>30</code></td>
<td><code>&lt;</code><code>filter-name</code><code>&gt;extensionsFilter&lt;/</code><code>filter-name</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>31</code></td>
<td><code>&lt;</code><code>url-pattern</code><code>&gt;/faces/*&lt;/</code><code>url-pattern</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>32</code></td>
<td><code>&lt;/</code><code>filter-mapping</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>33</code></td>
<td><code>&lt;</code><code>servlet</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>34</code></td>
<td><code>&lt;</code><code>servlet-name</code><code>&gt;Faces Servlet&lt;/</code><code>servlet-name</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>35</code></td>
<td><code>&lt;</code><code>servlet-class</code><code>&gt;javax.faces.webapp.FacesServlet&lt;/</code><code>servlet-class</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>36</code></td>
<td><code>&lt;</code><code>load-on-startup</code><code>&gt;1&lt;/</code><code>load-on-startup</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>37</code></td>
<td><code>&lt;/</code><code>servlet</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>38</code></td>
<td><code>&lt;</code><code>servlet-mapping</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>39</code></td>
<td><code>&lt;</code><code>servlet-name</code><code>&gt;Faces Servlet&lt;/</code><code>servlet-name</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>40</code></td>
<td><code>&lt;</code><code>url-pattern</code><code>&gt;/faces/*&lt;/</code><code>url-pattern</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>41</code></td>
<td><code>&lt;/</code><code>servlet-mapping</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>42</code></td>
<td><code>&lt;</code><code>context-param</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>43</code></td>
<td><code>&lt;</code><code>param-name</code><code>&gt;javax.servlet.jsp.jstl.fmt.localizationContext&lt;/</code><code>param-name</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>44</code></td>
<td><code>&lt;</code><code>param-value</code><code>&gt;resources.application&lt;/</code><code>param-value</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>45</code></td>
<td><code>&lt;/</code><code>context-param</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>46</code></td>
<td><code>&lt;</code><code>listener</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>47</code></td>
<td><code>&lt;</code><code>listener-class</code><code>&gt;org.apache.myfaces.webapp.StartupServletContextListener&lt;/</code><code>listener-class</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>48</code></td>
<td><code>&lt;/</code><code>listener</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>49</code></td>
<td><code>&lt;/</code><code>web-app</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Il parametro fondamentale da definire è il nome del Filtro <em>extensionFilter </em>mappato sulla classe <em>org.apache.myfaces.webapp.filter.ExtensionsFilter </em>è questa il cuore del framework che intercetta le chiamate durante il ciclo di vita della JSF. All’interno del web.xml  possono essere specificate dei parametri iniziali che sono definiti nella classe MyFacesConfig, tali parametri possono essere omessi e di conseguenza vengono settati al valore di default.</p>
<p>Creiamo ora una pagina di index della nostra applicazione che non farà altro che un redirect verso una pagina JSF (in formato xhtml):</p>
<div id="highlighter_31107">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;</code><code>html</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>&lt;</code><code>head</code><code>&gt; &lt;/</code><code>head</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>&lt;</code><code>body</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>&lt;</code><code>jsp:forward</code> <code>page</code><code>=</code><code>"/faces/testjsf.jsp"</code> <code>/&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>&lt;/</code><code>body</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>&lt;/</code><code>html</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Creiamo ora una pagina JSP, facendo click col tasto destro su WebContent -&gt; New -&gt; Other -&gt; Web -&gt; JSP File, inseriamo un nome ad esempio MyFacesPage ed infine scegliamo il template come mostrato in figura:</p>
<div id="attachment_1815"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/MyFaces71.png"><img title="MyFaces7" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/MyFaces71-300x257.png" alt="MyFaces71 300x257 Apache MyFaces: unimplementazione Open Source delle specifiche JSF" width="300" height="257" /></a></p>
<p>Scegliamo dai template disponibili quello JSF con sintassi xhtml e default view setup</p>
</div>
<p>Inseriamo il namespace dei tag Tomahawk (<em>xmlns:t=”http://myfaces.apache.org/tomahawk”</em>), e proviamo alcuni tag Tomahawk come ad esempio le label (<em>t:outputLabel</em>), gli input (<em>t:inputText</em>) ed un componente avanzato quale un Captcha (<em>t:captcha</em>):</p>
<div id="highlighter_758348">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;?</code><code>xml</code> <code>version</code><code>=</code><code>"1.0"</code> <code>encoding</code><code>=</code><code>"ISO-8859-1"</code> <code>?&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>&lt;</code><code>jsp:root</code> <code>xmlns:jsp</code><code>=</code><code>"<a href="http://java.sun.com/JSP/Page">http://java.sun.com/JSP/Page</a>"</code><code>xmlns:f</code><code>=</code><code>"<a href="http://java.sun.com/jsf/core">http://java.sun.com/jsf/core</a>"</code><code>xmlns:h</code><code>=</code><code>"<a href="http://java.sun.com/jsf/html">http://java.sun.com/jsf/html</a>"</code> <code>version</code><code>=</code><code>"2.0"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>&lt;</code><code>jsp:directive.page</code> <code>language</code><code>=</code><code>"java"</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>contentType</code><code>=</code><code>"text/html; charset=ISO-8859-1"</code> <code>pageEncoding</code><code>=</code><code>"ISO-8859-1"</code> <code>/&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>&lt;</code><code>jsp:text</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>&lt;![CDATA[ &lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt; ]]&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>&lt;/</code><code>jsp:text</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>&lt;</code><code>jsp:text</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>&lt;![CDATA[ &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>"&gt; ]]&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>&lt;/</code><code>jsp:text</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>&lt;</code><code>html</code> <code>xmlns</code><code>=</code><code>"<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>"</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>xmlns:f</code><code>=</code><code>"<a href="http://java.sun.com/jsf/core">http://java.sun.com/jsf/core</a>"</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>xmlns:h</code><code>=</code><code>"<a href="http://java.sun.com/jsf/html">http://java.sun.com/jsf/html</a>"</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>xmlns:t</code><code>=</code><code>"<a href="http://myfaces.apache.org/tomahawk">http://myfaces.apache.org/tomahawk</a>"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>15</code></td>
<td><code>&lt;</code><code>head</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>16</code></td>
<td><code>&lt;</code><code>meta</code> <code>http-equiv</code><code>=</code><code>"Content-Type"</code> <code>content</code><code>=</code><code>"text/html; charset=ISO-8859-1"</code> <code>/&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>17</code></td>
<td><code>&lt;</code><code>title</code><code>&gt;Insert title here&lt;/</code><code>title</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>18</code></td>
<td><code>&lt;/</code><code>head</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>19</code></td>
<td><code>&lt;</code><code>body</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>20</code></td>
<td><code>&lt;</code><code>f:view</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>21</code></td>
<td><code>&lt;</code><code>h:form</code> <code>id</code><code>=</code><code>"form"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>22</code></td>
<td><code>&lt;</code><code>h:panelGrid</code> <code>columns</code><code>=</code><code>"2"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>23</code></td>
<td><code>&lt;</code><code>t:outputLabel</code>  <code>value</code><code>=</code><code>"Inserisci il codice mostrato"</code><code>/&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>24</code></td>
<td><code>&lt;</code><code>t:inputText</code> <code>value</code><code>=</code><code>"#{testCaptchaBean.value}"</code><code>/&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>25</code></td>
<td><code>&lt;</code><code>h:commandLink</code> <code>value</code><code>=</code><code>"Ricarica immagine"</code> <code>/&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>26</code></td>
<td><code>&lt;</code><code>t:captcha</code> <code>captchaSessionKeyName</code><code>=</code><code>"#{testCaptchaBean.sessionKeyName}"</code><code>/&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>27</code></td>
<td><code>&lt;</code><code>h:commandButton</code> <code>value</code><code>=</code><code>"Invia"</code> <code>action</code><code>=</code><code>"#{testCaptchaBean.check}"</code><code>/&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>28</code></td>
<td><code>&lt;</code><code>t:outputLabel</code> <code>value</code><code>=</code><code>"#{testCaptchaBean.status}"</code><code>/&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>29</code></td>
<td><code>&lt;/</code><code>h:panelGrid</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>30</code></td>
<td><code>&lt;/</code><code>h:form</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>31</code></td>
<td><code>&lt;/</code><code>f:view</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>32</code></td>
<td><code>&lt;/</code><code>body</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>33</code></td>
<td><code>&lt;/</code><code>html</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>34</code></td>
<td><code>&lt;/</code><code>jsp:root</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Ora dobbiamo definire un Bean Java che mappi e conservi i valori degli attributi value dei componenti JSF ed implementi la action invocata dal commandButton, per fare questo basta creare una classe Java nella cartella src del nostro progetto ed inserire questo codice:</p>
<div id="highlighter_479780">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>package</code> <code>it.appuntisoftware;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>import</code> <code>javax.faces.context.FacesContext;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>import</code> <code>javax.servlet.http.HttpSession;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>public</code> <code>class</code> <code>TestCaptchaBean {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>public</code> <code>final</code> <code>static</code> <code>String SESSION_KEY_NAME = </code><code>"SessionKeyName"</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>public</code> <code>final</code> <code>static</code> <code>String CORRETTO = </code><code>"Corretto!"</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>public</code> <code>final</code> <code>static</code> <code>String SBAGLIATO = </code><code>"Sbagliato"</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>String status;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>String value;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>public</code> <code>String check() {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>// Compara il valore del CAPTCHA con quello inserito dall'utente.</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>String captchaValue = (String)((HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(</code><code>true</code><code>))</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>.getAttribute(SESSION_KEY_NAME);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>if</code><code>(captchaValue.equalsIgnoreCase(value)) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>15</code></td>
<td><code>status = CORRETTO;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>16</code></td>
<td><code>} </code><code>else</code> <code>{</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>17</code></td>
<td><code>status = SBAGLIATO;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>18</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>19</code></td>
<td><code>return</code> <code>""</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>20</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>21</code></td>
<td><code>public</code> <code>String getStatus() {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>22</code></td>
<td><code>return</code> <code>status;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>23</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>24</code></td>
<td><code>public</code> <code>void</code> <code>setStatus(String status) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>25</code></td>
<td><code>this</code><code>.status = status;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>26</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>27</code></td>
<td><code>public</code> <code>String getValue() {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>28</code></td>
<td><code>return</code> <code>value;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>29</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>30</code></td>
<td><code>public</code> <code>void</code> <code>setValue(String value) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>31</code></td>
<td><code>this</code><code>.value = value;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>32</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>33</code></td>
<td><code>public</code> <code>String getSessionKeyName() {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>34</code></td>
<td><code>return</code> <code>SESSION_KEY_NAME;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>35</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>36</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Infine bisogna inserire nel faces-config.xml il Bean che abbiamo creato in questo modo esso sarà istanziato automaticamente a runtime dal <em>VariableResolver</em> (ritorna un oggetto e lo crea se questo è referenziato per la prima volta), inoltre dobbiamo specificare lo scope del Bean che nel nostro caso sarà di tipo request:</p>
<div id="highlighter_695455">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;?</code><code>xml</code> <code>version</code><code>=</code><code>"1.0"</code> <code>encoding</code><code>=</code><code>"UTF-8"</code><code>?&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>&lt;</code><code>faces-config</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>xmlns</code><code>=</code><code>"<a href="http://java.sun.com/xml/ns/javaee">http://java.sun.com/xml/ns/javaee</a>"</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>xmlns:xsi</code><code>=</code><code>"<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>xsi:schemaLocation</code><code>=</code><code>"<a href="http://java.sun.com/xml/ns/javaee">http://java.sun.com/xml/ns/javaee</a><a href="http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd</a>"</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>version</code><code>=</code><code>"2.0"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>&lt;</code><code>managed-bean</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>&lt;</code><code>managed-bean-name</code><code>&gt;testCaptchaBean&lt;/</code><code>managed-bean-name</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>&lt;</code><code>managed-bean-class</code><code>&gt;it.appuntisoftware.TestCaptchaBean&lt;/</code><code>managed-bean-class</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>&lt;</code><code>managed-bean-scope</code><code>&gt;request&lt;/</code><code>managed-bean-scope</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>&lt;/</code><code>managed-bean</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>&lt;/</code><code>faces-config</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>A questo punto la nostra applicazione è completa, non ci resta che lanciarla sul nostro Application Server Tomcat e provarla. Se inseriamo il corretto valore del Captcha che ci viene presentato allora riceviamo come risposta il valore Corretto!, in caso contrario otteniamo il risultato Sbagliato:</p>
<div id="attachment_1810"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/MyFaces8.png"><img title="MyFaces8" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/MyFaces8-300x189.png" alt="MyFaces8 300x189 Apache MyFaces: unimplementazione Open Source delle specifiche JSF" width="300" height="189" /></a></p>
<p>La nostra applicazione di esempio</p>
</div>

<p><a href="http://feedads.g.doubleclick.net/~a/Y8EK-7d78TCNtDHrFPtpg-RwHOU/0/da"><img src="http://feedads.g.doubleclick.net/~a/Y8EK-7d78TCNtDHrFPtpg-RwHOU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Y8EK-7d78TCNtDHrFPtpg-RwHOU/1/da"><img src="http://feedads.g.doubleclick.net/~a/Y8EK-7d78TCNtDHrFPtpg-RwHOU/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/z6MH_khp4UM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/apache-myfaces-unimplementazione-open-source-delle-specifiche-jsf-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/apache-myfaces-unimplementazione-open-source-delle-specifiche-jsf-2/</feedburner:origLink></item>
		<item>
		<title>Creare e modificare bytecode Java a runtime con la libreria Javassist</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/kpTXlrswLDQ/</link>
		<comments>http://www.danieleserio.it/creare-e-modificare-bytecode-java-a-runtime-con-la-libreria-javassist-2/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 08:56:04 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[Guide e Tutorial]]></category>
		<category><![CDATA[Programmazione]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2309</guid>
		<description><![CDATA[In questo post analizzeremo la libreria Javassist (Java programming assistant) sviluppata da Shigeru Chiba professore presso il Tokyo Institute of Technology, ora un sotto progetto della Community JBoss. Questa libreria permette di manipolare il bytecode di una applicazione Java , in modo da poter cambiare l’implementazione di una classe a runtime (durante cioè il tempo di esecuzione dell’applicazione). Questa [...]]]></description>
			<content:encoded><![CDATA[<p>In questo post analizzeremo la libreria <strong>Javassist</strong> (<strong>Java</strong> programming <strong>assist</strong>ant) sviluppata da Shigeru Chiba professore presso il Tokyo Institute of Technology, ora un sotto progetto della Community JBoss. Questa libreria permette di manipolare il bytecode di una applicazione Java , in modo da poter cambiare l’implementazione di una classe a runtime (durante cioè il tempo di esecuzione dell’applicazione).<span id="more-2309"></span></p>
<p>Questa manipolazione del codice è ottenuta durante la fase di caricamento della classe oggetto di modifica (load time) grazie ad un Class Loader fornito con la libreria.</p>
<p>Javassist può essere utile nei seguenti casi:</p>
<ul>
<li>per compilare a runtime delle porzioni di codice sorgente, ad esempio fornito come input di un programma;</li>
<li>per l’Aspect Oriented Programming (AOP), introducendo dei nuovi metodi in una classe e per inserire advice di tipo before/after/around;</li>
<li>per la runtime reflection, introducendo un meta-oggetto che controlli le chiamate ai metodi.</li>
</ul>
<p>&nbsp;</p>
<p>Il bytecode Java è conservato in un file binario chiamato class file (e con estensione .class), ogni class file contiene esattamente una classe Java o una interfaccia. La classe<em>Javassist.CtClass</em> (abbreviazione di Compile Time Class) è una rappresentazione astratta di un class file. Un oggetto di tale classe ci permette di manipolare un class file. Per poter ottenere un oggetto CtClass dobbiamo prima istanziare un oggetto ClassPool che rappresenta appunto un contenitore di oggetti CtClass, tramite il metodo get() di ClassPool possiamo ottenere un riferimento ad un oggetto CtClass e assegnarlo ad una variabile per poterlo modificare, facciamo un esempio:</p>
<div id="highlighter_123776">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>ClassPool pool = ClassPool.getDefault();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>CtClass cc = pool.get(</code><code>"it.appuntisoftware.Rettangolo"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>cc.setSuperclass(pool.get(</code><code>"it.appuntisoftware.Punto"</code><code>));</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>cc.writeFile();</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>con questo codice otteniamo dal <em>ClassPool</em> un riferimento al class file “it.aapuntisoftware.Rettangolo”, lo modifichiamo assegnandogli come superclasse la classe “it.appuntisoftware.Punto” e lo salviamo di nuovo su file.</p>
<p>Il metodo statico <em>ClassPool.getDefault()</em> fa in modo che il ClassPool cerchi le classi nel medesimo <em>classpath </em>che ha la JVM, di conseguenza per le Web Application tale metodo non va utilizzato, ma bensì va fatta la chiamata al metodo <em>insertClassPath</em>():</p>
<div id="highlighter_384068">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>ClassPool pool = ClassPool.getDefault();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>pool.insertClassPath(</code><code>new</code> <code>ClassClassPath(</code><code>this</code><code>.getClass()));</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>questo statement registra come classpath quello che è stato usato per il loading dell’oggetto a cui la keyword <em>this </em>si riferisce.</p>
<p>Possiamo anche creare delle classi ex-novo utilizzando il metodo <em>makeClass()</em> di ClassPool:</p>
<div id="highlighter_292962">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>ClassPool pool = ClassPool.getDefault();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>CtClass cc = pool.makeClass(</code><code>"Punto"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>utilizzando poi il metodo <em>writeFile() </em>scriviamo la classe su file, non possiamo però modificare classi di cui già abbiamo fatto la write a meno di non chiamare il metodo defrost():</p>
<div id="highlighter_508293">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>CtClasss cc = ...;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>:</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>cc.writeFile();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>cc.defrost();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>cc.setSuperclass(...);</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Proviamo ora a fare qualche esempio più complesso e completo. Iniziamo scaricando la libreria dall’URL (la versione più recente che usiamo nel nostro articolo è la 3.11.0 GA):</p>
<p><a href="http://www.jboss.org/javassist/downloads">http://www.jboss.org/javassist/downloads</a></p>
<p>Per i nostri esempi utilizziamo Eclipse: creiamo un nuovo Progetto Java (File -&gt; New -&gt; Java Project), creiamo una cartella lib e vi copiamo la libreria <em>javassist.jar</em>, non dimentichiamoci poi di includerla nel Build Path del nostro progetto: click col tasto destro -&gt; Build Path -&gt; Configure Build Path):</p>
<div id="attachment_1849"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/javassist.png"><img title="javassist" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/javassist-300x241.png" alt="javassist 300x241 Creare e modificare bytecode Java a runtime con la libreria Javassist" width="300" height="241" /></a></p>
<p>Aggiungiamo la libreria javassist al Build Path del progetto</p>
<p>&nbsp;</p>
<p>Creiamo poi le seguenti classi all’interno del package <em>it.appuntisoftware</em>:</p>
<p><em>Somma.java</em></p>
<div id="highlighter_775432">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>package</code> <code>it.appuntisoftware;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>public</code> <code>class</code> <code>Somma {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>public</code> <code>int</code> <code>aggiungi(</code><code>int</code> <code>i) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>int</code> <code>result = i + </code><code>1</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>System.out.println(</code><code>"Classe: "</code> <code>+</code><code>this</code><code>.getClass());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>System.out.println(</code><code>"Sottoclasse di: "</code> <code>+</code><code>this</code><code>.getClass().getSuperclass());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>System.out.println(</code><code>"Risultato: "</code> <code>+ result);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>return</code> <code>result;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><em>Moltiplicazione.java</em></p>
<div id="highlighter_689245">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>package</code> <code>it.appuntisoftware;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>public</code> <code>class</code> <code>Moltiplicazione {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>public</code> <code>int</code> <code>moltiplica(</code><code>int</code> <code>i) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>int</code> <code>result = i * </code><code>2</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>System.out.println(</code><code>"Classe: "</code> <code>+</code><code>this</code><code>.getClass());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>System.out.println(</code><code>"Sottoclasse di: "</code> <code>+</code><code>this</code><code>.getClass().getSuperclass());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>System.out.println(</code><code>"Risultato: "</code> <code>+ result);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>return</code> <code>result;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p><em>TestJavassist.java</em></p>
<div id="highlighter_910816">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>package</code> <code>it.appuntisoftware;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>import</code> <code>java.lang.reflect.Method;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>import</code> <code>javassist.ClassPool;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>import</code> <code>javassist.CtClass;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>import</code> <code>javassist.CtMethod;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>import</code> <code>javassist.CtNewMethod;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>public</code> <code>class</code> <code>TestJavassist {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>public</code> <code>static</code> <code>void</code> <code>main(String[] args) </code><code>throws</code> <code>Exception {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>ClassPool pool = ClassPool.getDefault();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>CtClass sum = pool.get(</code><code>"it.appuntisoftware.Somma"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>CtClass mol = pool.get(</code><code>"it.appuntisoftware.Moltiplicazione"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>CtClass oper = pool.makeClass(</code><code>"it.appuntisoftware.Operazioni"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>CtMethod sMetodo = sum.getDeclaredMethod(</code><code>"aggiungi"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>15</code></td>
<td><code>CtMethod oMetodo = CtNewMethod.copy(sMetodo, </code><code>"aggiungiUno"</code><code>, oper,</code><code>null</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>16</code></td>
<td><code>oper.addMethod(oMetodo);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>17</code></td>
<td><code>oper.setSuperclass(mol);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>18</code></td>
<td><code>oper.writeFile();   </code><code>// scrivo il file su File System</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>19</code></td>
<td><code>System.out.println(</code><code>"Ho scritto il file Operazioni!"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>20</code></td>
<td><code>Class&lt;?&gt; operClass =oper.toClass();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>21</code></td>
<td><code>Object operObject =operClass.newInstance();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>22</code></td>
<td><code>Method methods=operClass.getMethod(</code><code>"aggiungiUno"</code><code>,</code><code>new</code> <code>Class[]{Integer.TYPE} );</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>23</code></td>
<td><code>methods.invoke(operObject, </code><code>2</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>24</code></td>
<td><code>methods=operClass.getMethod(</code><code>"moltiplica"</code><code>,</code><code>new</code> <code>Class[]{Integer.TYPE} );</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>25</code></td>
<td><code>methods.invoke(operObject, </code><code>2</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>26</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>27</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>28</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>L’output del programma sarà:</p>
<pre>Ho scritto il file Operazioni!
Classe: class it.appuntisoftware.Operazioni
Sottoclasse di: class it.appuntisoftware.Moltiplicazione
Risultato: 3
Classe: class it.appuntisoftware.Operazioni
Sottoclasse di: class it.appuntisoftware.Moltiplicazione
Risultato: 4</pre>
<p>Nel nostro programma <em>TestJavassist.java</em> abbiamo utilizzato solo le classi fornite da Javassist e quelle già disponibili per la Reflection in Java. Abbiamo creato a runtime una classe Operazioni a cui abbiamo aggiunto un metodo preso dalla classe Somma (aggiungi) e ridenominato aggiungiUno, poi l’abbiamo fatta estendere dalla classe Moltiplicazione (di conseguenza ha ereditato il metodo moltiplica. Dopo fatto ciò abbiamo scritto il class file su FileSystem, ritroviamo il file nella cartella del nostro progetto Eclipse.</p>
<p>A questo punto abbiamo invocato i due metodi della classe Operazioni utilizzando la Reflection tramite le API del package <em>Reflect </em>di Java.</p>
<p>Utilizzando un decompilatore,ad esempio Java Decompiler che abbiamo esaminato in questo<a href="http://www.appuntisoftware.it/java-decompiler-un-decompilatore-java/" target="_blank">articolo</a>, possiamo vedere il codice generato per la classe <em>Operazioni</em>:</p>
<div id="highlighter_89461">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>package</code> <code>it.appuntisoftware;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>import</code> <code>java.io.PrintStream;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>public</code> <code>class</code> <code>Operazioni </code><code>extends</code> <code>Moltiplicazione</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>{</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>public</code> <code>int</code> <code>aggiungiUno(</code><code>int</code> <code>i)</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>{</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>int</code> <code>result = i + </code><code>1</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>System.out.println(</code><code>"Classe: "</code> <code>+ getClass());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>System.out.println(</code><code>"Sottoclasse di: "</code> <code>+ getClass().getSuperclass());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>System.out.println(</code><code>"Risultato: "</code> <code>+ result);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>return</code> <code>result;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>oppure possiamo utilizzare il comando <em>javap</em> (incluso nella distribuzione Java) che disassembla il bytecode e ci mostra la struttura della classe e le firme dei metodi e dei costruttori (solo quelli con modificatore di accesso public, protected o package), ad esempio dando il comando:</p>
<pre>javap it.appuntisoftware.Operazioni</pre>
<p>otteniamo questo output:</p>
<div id="attachment_1857"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/javap.png"><img title="javap" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/javap-300x151.png" alt="javap 300x151 Creare e modificare bytecode Java a runtime con la libreria Javassist" width="300" height="151" /></a></p>
<p>Output del comando javap</p>
</div>
</div>

<p><a href="http://feedads.g.doubleclick.net/~a/UaMHEybfevyEE6cyWmTESgegIQo/0/da"><img src="http://feedads.g.doubleclick.net/~a/UaMHEybfevyEE6cyWmTESgegIQo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/UaMHEybfevyEE6cyWmTESgegIQo/1/da"><img src="http://feedads.g.doubleclick.net/~a/UaMHEybfevyEE6cyWmTESgegIQo/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/kpTXlrswLDQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/creare-e-modificare-bytecode-java-a-runtime-con-la-libreria-javassist-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/creare-e-modificare-bytecode-java-a-runtime-con-la-libreria-javassist-2/</feedburner:origLink></item>
		<item>
		<title>Installazione e configurazione del database IBM DB2</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/VEr_BQ3V4Ww/</link>
		<comments>http://www.danieleserio.it/installazione-e-configurazione-del-database-ibm-db2-2/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 08:52:52 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[Guide e Tutorial]]></category>
		<category><![CDATA[Programmazione]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2300</guid>
		<description><![CDATA[In questo articolo vedremo come installare e come configurare il Relational Database Management System (RDBMS) IBM DB2. Nato nel lontano (tecnologicamente parlando) 1983, scritto in linguaggio C e C++,  è considerato il primo DBMS ad aver introdotto l’uso del linguaggio SQL e la prima release girava solo su Mainframe IBM MVS. Durante gli anni 90 fu [...]]]></description>
			<content:encoded><![CDATA[<p>In questo articolo vedremo come installare e come configurare il Relational Database Management System (RDBMS) IBM DB2. Nato nel lontano (tecnologicamente parlando) 1983, scritto in linguaggio C e C++,  è considerato il primo DBMS ad aver introdotto l’uso del linguaggio SQL e la prima release girava solo su Mainframe IBM MVS. Durante gli anni 90 fu esteso il supporto anche alle piattaforme Windows e Linux. Nel 2001 con l’acquisizione di Informix da parte IBM, vengono introdotte le specifiche Object Oriented (ORDBMS) anche all’interno di DB2.</p>
<p><span id="more-2300"></span></p>
<p>Le versioni in cui è distribuito DB2 attualmente sono:</p>
<ul>
<li>DB2 Enterprise Server Edition: include librerie capaci di gestire i carichi di lavoro più esigenti;</li>
<li>DB2 Workgroup Server Edition: ideale per le piccole e medie aziende;</li>
<li>DB2 Express: è il livello base di RDBMS ed è l’ideale per il piccolo mercato;</li>
<li>DB2 Express-C: è la versione gratuita dell’IBM, l’ideale per piccole aziende, compagnie multi-branch, sviluppatori.</li>
</ul>
<p>&nbsp;</p>
<p>Il concetto fondamentale su cui si sviluppa un database DB2 è quello di istanza (instance, chiamata anche database manager), la quale è un ambiente logico dove sono organizzati e configurati i diversi database. E’ possibile creare e mantenere attive più istanze su di un server fisico in modo da avere un ambiente configurato diversamente per ognuna di esse. L’utilizzo di istanze multiple è ad esempio utile in questi casi:</p>
<ul>
<li>utilizzare un’istanza per l’ambiente di sviluppo e di un’altra istanza per quello di produzione;</li>
<li>effettuare il tuning di un’istanza per un particolare ambiente di lavoro;</li>
<li>limitare l’accesso ad una particolare istanza;</li>
<li>ottimizzare il database manager per ogni particolare istanza;</li>
<li>limitare l’impatto di una failure di un’istanza su di un’altra.</li>
</ul>
<p>Di contro istanze multiple richiedono maggiori risorse di sistema (in particolare di occupazione su disco e memoria virtuale) ed il dover gestire più configurazioni.</p>
<div id="attachment_1835"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/db2struct.gif"><img title="db2struct" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/db2struct-300x217.gif" alt="db2struct 300x217 Installazione e configurazione del database IBM DB2" width="300" height="217" /></a></p>
<p>Organizzazione di un database Db2</p>
</div>
<p>La directory dell’istanza (instance directory) contiene tutte le informazioni riguardanti i database presenti in essa. La locazione della directory non può essere cambiata una volta che è stata creata, essa contiene:</p>
<ul>
<li>i file di configurazione del database manager;</li>
<li>le directory dei database;</li>
<li>il directory del nodo;</li>
<li>la configurazione del nodo (db2nodes.cfg che definisce le partizioni dei database e l’IP del server per le comunicazioni tra le varie partizioni).</li>
</ul>
<p>Questa directory si trova per sistemi Linux / Unix al percorso INSTHOME/sqllib, dove INSTHOME è la directory <em>home</em> del proprietario dell’istanza (l’utente db2inst1 di default), per Windows si trova al path /sqllib nella directory dove è stato installato DB2.</p>
<p>Dopo questa breve introduzione, vediamo come installare e configurare un DBMS DB2.</p>
<p>Per le nostre prove utilizzeremo la versione Express-C v9.7 (l’ultima disponibile nel momento in cui scriviamo) che è possibile scaricare gratuitamente dall’url:</p>
<p><a href="http://www-01.ibm.com/software/data/db2/express/download.html">http://www-01.ibm.com/software/data/db2/express/download.html</a></p>
<p>qui possiamo scegliere tra le varie Piattaforme (Windows, Linux, Solaris e Mac) sia a 32 che a 64 bit. La versione Express-C gira su qualsiasi tipo di hardware, ma si limita ad usare un massimo di due Core (indipendentemente dal numero di processori installati) ed un massimo di 2 GB di ram, sottoscrivendo una particolare licenza denominata Fixed Term License o <strong>FTL </strong>si potranno utilizzare 4 Core e fino a 4 GB di ram.</p>
<p>E’ inoltre possibile scaricare un libro-guida<strong><em> Getting Started with DB2 Express-C </em></strong>(disponibile in varie lingue, la versione 9.5 anche in italiano) all’indirizzo:</p>
<p><a href="http://www.ibm.com/developerworks/wikis/display/DB2/FREE+Book-+Getting+Started+with+DB2+Express-C">http://www.ibm.com/developerworks/wikis/display/DB2/FREE+Book-+Getting+Started+with+DB2+Express-C</a></p>
<p>Per installare il database basta lanciare il programma<em> setup.exe </em>per Windows oppure dando il comando <em>./db2setup </em>per Linux e Unix. Completata l’installazione ritroveremo i file DB2 sotto le directory <em>C:\Programmi\IBM\SQLLIB\BIN\</em> per Windows e <em>/opt/ibm/db2/V9.7</em> per Linux e <em>/opt/IBM/db2/V9.1</em> per Unix.</p>
<p>Durante il processo di installazione verranno creati 3 nuovi utenti e 3 nuovi gruppi in ambiente Linux:</p>
<ul>
<li>l’utente proprietario delll’istanza DB2 (<em>owner</em>), denominato <em>db2inst1 </em>(la quale viene creata nella sua home directory nella cartella <em>sqllib</em>), questi controlla tutti i processi db2 ed è il proprietario di tutti i file ed i device usati dai database contenuti nella istanza, ci sono tanti utenti owner quante le istanze installate (il nome di questi saranno progressivi: <em>db2inst2</em>, <em>db2inst3</em>, etc…). Il suo gruppo di default è <em>db2iadm1</em>;</li>
<li>l’utente <em>fenced</em> (letteralmente recintato), denominato <em>db2fenc1</em>, questi è utilizzato per eseguire le funzioni definite dall’utente (le cosiddette user defined functions, UDF) e le stored procedure al di fuori dello spazio di indirizzamento usato da un database db2. Il gruppo di default è <em>db2fadm1</em>;</li>
<li>l’utente amministratore del db2, denominato <em>dasusr1</em>, questi è utilizzato per le operazioni di amministrazione dul server db2, da notare che esiste un solo amministratore e quindi utente per macchina anche se ci sono più istanze. Il gruppo di default è <em>dasadm1.</em></li>
</ul>
<p>Possiamo amministrare i nostri database e gestire le varie utilities offerte da DB2 utilizzando una comoda GUI offerta dal DB2 Control Center. Per poter accedere a questo tool in Windows basta cliccare sull’icona Centro di Controllo presente al percorso <em>Tutti i Programmi -&gt; IBM DB2 -&gt; DB2COPY -&gt; Strumenti di gestione generale</em>, in Linux dobbiamo essere loggati o con l’utente amministratore <em>dasusr1</em> o l’utente owner <em>db2inst1</em> ed aver avviato il server X, dopodichè avviamo una sessione di terminale e diamo il comando <em>db2cc:</em></p>
<p>&nbsp;</p>
<div id="attachment_1867"><em><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/db2.png"><img title="db2" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/db2-300x197.png" alt="db2 300x197 Installazione e configurazione del database IBM DB2" width="300" height="197" /></a></em></p>
<p>La schermata principale del Control Center</p>
</div>
<p>Possiamo anche operare in modalità totalmente testuale utilizzando la  DB2 Command Line Processor CLP dalla quale possiamo dare i nostri comandi DB2 ed istruzioni SQL. In Windows la lanciamo andando in <em>Tutti i Programmi -&gt; IBM DB2 -&gt; DB2COPY -&gt; Strumenti riga di comando </em>e clicchiamo su CLP (la quale lancia il comando db2cmd.exe), in Linux una volta collegati con l’utente dasusr1 o db2inst1, diamo il comando <em>db2,</em> apparirà questa schermata:</p>
<div id="attachment_1868"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/db22.png"><img title="db22" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/db22-300x150.png" alt="db22 300x150 Installazione e configurazione del database IBM DB2" width="300" height="150" /></a></p>
<p>La CLP in ambiente Windows</p>
</div>
<p>Creiamo ad esempio un database con il seguente comando SQL:</p>
<pre>create database esempio</pre>
<p>il sistema risponderà con un messaggio di successo, ricordiamo che per DB2 i nomi di database possono al massimo essere lunghi 8 caratteri.</p>
<p>Prima di poter eseguire un’istruzione SQL sul database appena creato, dobbiamo collegarci ad esso:</p>
<p>Per collegarci a un database scriviamo il comando:</p>
<pre>db2 CONNECT TO database USER userID USING password</pre>
<p>Per collegarci a un database in modo che DB2 ci richieda una password, scriviamo il comando:</p>
<pre>db2 CONNECT TO database USER userID</pre>
<p>Per collegarci a un database usando l’ID dell’utente predefinito, scriviamo il comando:</p>
<pre>db2 CONNECT TO database</pre>
<p>Di seguito elenchiamo alcuni comandi utili per recuperare delle informazioni e per configurare la istanza Db2 appena installata.</p>
<p>Per avere un elenco dei parametri su cui è configurata la istanza DB2 (database manager)  apriamo un terminale DB2 (dando il comando db2 da consolle) e diamo il comando:</p>
<pre>get database manager configuration</pre>
<p>oppure possiamo usare la forma abbreviata:</p>
<pre>get dbm cfg</pre>
<p>se invece vogliamo sapere i parametri di configurazione del singolo database, dobbiamo prima connetterci a questo (col comando <em>connect to nomedatabase</em>) e poi dare il comando:</p>
<pre>get database configuration</pre>
<p>oppure possiamo usare la forma abbreviata:</p>
<pre>get db cfg</pre>
<p>il comando per modificare una entry della configurazione è il seguente:</p>
<pre>update database manager configuration  using &lt;parameter-name&gt; &lt;parameter-value&gt;</pre>
<p>oppure</p>
<pre>update dbm cfg using &lt;parameter-name&gt; &lt;parameter-value&gt;</pre>
<p>e per i database:</p>
<pre>update database configuration (oppure update dbm cfg) using &lt;parameter-name&gt; &lt;parameter-value&gt;</pre>
<p>oppure</p>
<pre>update db cfg using &lt;parameter-name&gt; &lt;parameter-value&gt;</pre>
<p>Per conoscere il numero di  porta di connessione DB2 su Linux/unix:</p>
<ol>
<ol>
<li>Aprire un terminale DB2 e verificare che si è sulla istanza corretta dando il comando:
<pre>get instance</pre>
</li>
<li>dare il seguente comando per verificare il nome del servizio della nostra istanza:</li>
</ol>
</ol>
<pre>get dbm cfg | grep SVCE</pre>
<ol>
<ol>
<li>verrà generato un output del tipo:</li>
</ol>
</ol>
<pre>TCP/IP Service name          (SVCENAME) = db2cdb2inst24</pre>
<ol>
<li>digitare sulla console linux il comando:
<pre>grep <var>service_name</var> /etc/services</pre>
<p>ci saranno le informazioni riguardanti la porta del servizio, ad esempio:</p>
<pre><var>service_name</var>   50012/tcp   # Connection port for DB2 instance <var>instance</var></pre>
</li>
</ol>
<p>Per conoscere il nome delle istanze DB2 presenti sul sistema dare il comando:</p>
<pre>db2ilist</pre>
<p>di default avremo il nome <strong><em>DB2</em></strong> per sistemi Windows e <strong><em>db2inst1 </em></strong>per Linux/Unix.</p>
<p>Per stoppare il DB2 se il comando <em>db2stop </em>non funziona e ritorna come errore:</p>
<pre>SQL1025N  The database manager was not stopped because databases are still active.</pre>
<p>Utilizziamo :</p>
<p>db2 force application all</p>
<p>db2stop force</p>
<p>dove <em>force application &lt;command&gt;</em> disconnette tutti gli utenti remoti e locali per permettere la manutenzione del server.</p>
<p>Per visualizzare tutte le applicazioni e gli utenti connessi al DB possiamo utilizzare il comando:</p>
<pre>db2 list applications (è valido anche usando application)</pre>
<p>Per conoscere la versione di DB2 che abbiamo installato e la licenza registrata diamo il comando:</p>
<pre>db2licm -l</pre>
<p>dove il parametro -l sta ad indicare di visualizzare i dettagli dell’installazione.</p>
<p>Per conoscere invece quali fix packs sono stati installati diamo il comando:</p>
<pre>db2level</pre>
<p>tra le informazioni visualizzate possiamo anche sapere se è una versione a 32 bit o a 64.</p>
<p>Per configurare la manutenzione automatica del DB2 (automatic maintenance) è possibile agire dal relativo menù cliccando col tasto desto sul database da manutenere e scegliendo l’opzione<em>Configura manutenzione Automatica… </em>in alternativa è possibile farlo da linea di comando.</p>
<p>Per conoscere tutte gli schemi o le tabelle presenti in un determinato database,  bisogna interrogare rispettivamente la tabella SYSTABLES e SYSSCHEMATA presenti nello schema SYSIBM, o in alternativa interrogare le viste SCHEMATA e TABLES presenti nello schema SYSCAT, dunque per conoscere gli schema utilizziamo la seguente query SQL:</p>
<pre>select * from sysibm.sysschemata</pre>
<p>oppure</p>
<pre>select * from syscat.schemata</pre>
<p>mentre per conoscere tutte le tabelle:</p>
<pre>select * from sysibm.systables</pre>
<p>oppure</p>
<pre>select * from syscat.tables</pre>

<p><a href="http://feedads.g.doubleclick.net/~a/X8xELGK6VhM42cq8Y3YvL6pbVPQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/X8xELGK6VhM42cq8Y3YvL6pbVPQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/X8xELGK6VhM42cq8Y3YvL6pbVPQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/X8xELGK6VhM42cq8Y3YvL6pbVPQ/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/VEr_BQ3V4Ww" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/installazione-e-configurazione-del-database-ibm-db2-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/installazione-e-configurazione-del-database-ibm-db2-2/</feedburner:origLink></item>
		<item>
		<title>Apache PDFBox: una libreria Java per lavorare con i documenti PDF</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/2fkm1vItowk/</link>
		<comments>http://www.danieleserio.it/apache-pdfbox-una-libreria-java-per-lavorare-con-i-documenti-pdf-2/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 08:49:22 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[Guide e Tutorial]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programmazione]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2293</guid>
		<description><![CDATA[In questo articolo vedremo come utilizzare la libreria Java Apache PDFBox per manipolare documenti in formato PDF. PDFBox è una libreria Java rilasciata con licenza Open Source (Apache License v2.0), la quale permette di creare un nuovo documento PDF, manipolare documenti esistenti ed estrarre il contenuto da questi documenti. E’ possibile inoltre scaricarne una versione [...]]]></description>
			<content:encoded><![CDATA[<p>In questo articolo vedremo come utilizzare la libreria Java Apache PDFBox per manipolare documenti in formato PDF. PDFBox è una libreria Java rilasciata con licenza Open Source (Apache License v2.0), la quale permette di creare un nuovo documento PDF, manipolare documenti esistenti ed estrarre il contenuto da questi documenti.</p>
<p>E’ possibile inoltre scaricarne una versione stand-alone (cioè che funziona senza dover sviluppare codice che la utilizzi), che permette di effettuare una serie di operazioni agendo direttamente da linea di comando.<span id="more-2293"></span></p>
<p>Vediamo ora come è strutturato Apache PDFBox, dopo di che faremo degli esempi pratici in Java.</p>
<p>I documenti PDF sono degli stream di oggetti di tipo base, questi oggetti di basso livello sono rappresentati in PDFBox nel package <em>org.apache.pdfbox.cos</em> package. Gli oggetti base in PDF sono:</p>
<table border="1" cellspacing="0" cellpadding="1" align="center">
<tbody>
<tr>
<th align="left">PDF Type</th>
<th align="left">Descrizione</th>
<th align="left">Esempio</th>
<th align="left">Classi PDFBox</th>
</tr>
<tr>
<td align="left">Array</td>
<td align="left">Una lista ordinata di elementi</td>
<td align="left">[1 2 3]</td>
<td align="left">org.apache.pdfbox</p>
<p>&nbsp;</p>
<p>.cos.COSArray</p>
</td>
</tr>
<tr>
<td align="left">Boolean</td>
<td align="left">I valori True/False</td>
<td align="left">true</td>
<td align="left">org.apache.pdfbox</p>
<p>&nbsp;</p>
<p>.cos.COSBoolean</p>
</td>
</tr>
<tr>
<td align="left">Dictionary</td>
<td align="left">Una mappa di coppie chiave/valore</td>
<td align="left">&lt;&lt;<br />/Type /XObject<br />/Name (Name)<br />/Size 1<br />&gt;&gt;</td>
<td align="left">org.apache.pdfbox</p>
<p>&nbsp;</p>
<p>.cos.COSDictionary</p>
</td>
</tr>
<tr>
<td align="left">Number</td>
<td align="left">Numeri Interi e in virgola mobile</td>
<td align="left">1 2.3</td>
<td align="left">org.apache.pdfbox</p>
<p>&nbsp;</p>
<p>.cos.COSFloat<br />org.apache.pdfbox</p>
<p>.cos.COSInteger</p>
</td>
</tr>
<tr>
<td align="left">Name</td>
<td align="left">Un valore predefinito in un documento PDF, usato tipicamente come chiave in un dizionario</td>
<td align="left">/Type</td>
<td align="left">org.apache.pdfbox</p>
<p>&nbsp;</p>
<p>.cos.COSName</p>
</td>
</tr>
<tr>
<td align="left">Object</td>
<td align="left">Un Wrapper per ogni altrotipo di oggetto, il quale può essere utilizzato per referenziare un oggetto per più volte. Un oggetto è referenziato utilizzando due numeri: un number object e un generation number. All’inizio il generation number è 0 fino a che l’oggetto non venga rimpiazzato più tardi nello stream.</td>
<td align="left">12 0 obj &lt;&lt; /Type /XObject &gt;&gt; endobj</td>
<td align="left">org.apache.pdfbox</p>
<p>&nbsp;</p>
<p>.cos.COSObject</p>
</td>
</tr>
<tr>
<td align="left">Stream</td>
<td align="left">Uno stream di dati il più delle volte compresso. Questo viene usato per il contenuto della pagina, le immagini e per i font.</td>
<td align="left">12 0 obj &lt;&lt; /Type /XObject &gt;&gt; stream 030004040404040404 endstream</td>
<td align="left">org.apache.pdfbox</p>
<p>&nbsp;</p>
<p>.cos.COSStream</p>
</td>
</tr>
<tr>
<td align="left">String</td>
<td align="left">Una sequenza di caratteri.</td>
<td align="left">(This is a string)</td>
<td align="left">org.apache.pdfbox</p>
<p>&nbsp;</p>
<p>.cos.COSString</p>
</td>
</tr>
</tbody>
</table>
<p>Il modello basato su oggetti COS permette di accedere a qualsiasi elemento del documento PDF, ma per accedervi l’utente deve conoscere il nome dei parametri che vuole usare e ciò porta ad inevitabili errori. Di conseguenza è stato creato un altro Modello (PD Model) che offre delle agevolazioni per il programmatore. Ogni oggetto del documento ha un set di attributi definiti che possono essere disponibili nel dizionario. La libreria fornisce una classe PD Model per ogni tipo di oggetto del documento le quali forniscono dei metodi fortemente tipizzati che permetto di accedere agli attributi definiti. Di conseguenza il PD Model è collocabile al di sopra del COS Model come mostrato in figura:</p>
<div id="attachment_1721"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/cos-pdmodel-diagram.png"><img title="Struttura del COS Model e del PD Model" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/cos-pdmodel-diagram-300x198.png" alt="cos pdmodel diagram 300x198 Apache PDFBox: una libreria Java per lavorare con i documenti PDF" width="300" height="198" /></a></p>
<p>Struttura del COS Model e del PD Model</p>
</div>
<p>Ovviamente nei nostri esempi faremo sempre uso delle classi del PD Model.</p>
<p>A questo punto scarichiamo la libreria all’indirizzo:</p>
<p><a href="http://pdfbox.apache.org/download.html">http://pdfbox.apache.org/download.html</a></p>
<p>scegliendo il file .jar <em>pdfbox-version.jar</em> (la 1.5.0 nel momento in cui scriviamo), dobbiamo inoltre scaricare sempre dalla stessa pagina il file di dipendenza .jsr fontbox-version.jar (è un componente stand-alone che permette di manipolare i formati dei font).</p>
<p>Una ulteriore dipendenza da soddisfare è la libreria commons-logging che possiamo scaricare da questa url:</p>
<p><a href="http://apache.panu.it//commons/logging/binaries/commons-logging-1.1.1-bin.zip" target="_blank">http://apache.panu.it//commons/logging/binaries/commons-logging-1.1.1-bin.zip</a></p>
<p>Utilizzeremo per i nostri esempi Java l’IDE Eclipse.</p>
<p>Creiamo un nuovo Progetto Java in Eclipse (File -&gt; New -&gt; Java Project), creiamo una cartella lib e vi copiamo le libreria pdfbox-1.5.0.jar, fontbox-1.5.0.jar e commons-logging-1.1.1.jar, per cui avremo il nostro progetto così strutturato:</p>
<div id="attachment_1715"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/pdfbox3.png"><img title="La struttura del nostro Progetto Java" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/pdfbox3.png" alt="pdfbox3 Apache PDFBox: una libreria Java per lavorare con i documenti PDF" width="283" height="138" /></a></p>
<p>La struttura del nostro Progetto Java</p>
</div>
<p>Dobbiamo poi includerle nel Build Path del nostro progetto: click col tasto destro sul progetto -&gt; Build Path -&gt; Configure Build Path):</p>
<ul>
<li>pdfbox-1.5.0.jar;</li>
<li>fontbox-1.5.0.jar;</li>
<li>commons-logging-1.1.1.jar.</li>
</ul>
<div id="attachment_1714"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/pdfbox4.png"><img title="pdfbox4" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/pdfbox4-300x246.png" alt="pdfbox4 300x246 Apache PDFBox: una libreria Java per lavorare con i documenti PDF" width="300" height="246" /></a></p>
<p>Il Java Build Path del progetto</p>
</div>
<p>Creiamo ora una classe Java per poter provare la libreria (tasto destro sulla cartella src -&gt; New -&gt; Class), ed indichiamo il nome, il package e la JVM da utilizzare come riportato in figura:</p>
<div id="attachment_1716"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/pdfbox5.png"><img title="pdfbox5" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/pdfbox5-247x300.png" alt="pdfbox5 247x300 Apache PDFBox: una libreria Java per lavorare con i documenti PDF" width="247" height="300" /></a></p>
<p>Creiamo la nostra classe Java di esempio</p>
</div>
<p>Aggiungiamo del codice per creare una pagina PDF con un testo in una certa posizione della pagina:</p>
<div id="highlighter_803579">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>package</code> <code>it.appuntisoftware;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>import</code> <code>java.io.IOException;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>import</code> <code>org.apache.pdfbox.pdmodel.PDDocument;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>import</code> <code>org.apache.pdfbox.pdmodel.PDPage;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>import</code> <code>org.apache.pdfbox.pdmodel.edit.PDPageContentStream;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>import</code> <code>org.apache.pdfbox.pdmodel.font.PDFont;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>import</code> <code>org.apache.pdfbox.pdmodel.font.PDType1Font;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>public</code> <code>class</code> <code>test {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>public</code> <code>static</code> <code>void</code> <code>main(String[] args) </code><code>throws</code> <code>Exception{</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>PDDocument doc = </code><code>null</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>try</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>{</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>15</code></td>
<td><code>doc = </code><code>new</code> <code>PDDocument();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>16</code></td>
<td><code>PDPage page = </code><code>new</code> <code>PDPage();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>17</code></td>
<td><code>doc.addPage( page );</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>18</code></td>
<td><code>PDPageContentStream contentStream = </code><code>new</code> <code>PDPageContentStream(doc, page);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>19</code></td>
<td><code>PDFont font = PDType1Font.HELVETICA_BOLD;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>20</code></td>
<td><code>contentStream.beginText();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>21</code></td>
<td><code>contentStream.setFont( font, </code><code>12</code> <code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>22</code></td>
<td><code>contentStream.moveTextPositionByAmount( </code><code>100</code><code>, </code><code>700</code> <code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>23</code></td>
<td><code>contentStream.drawString( </code><code>"Ciao da AppuntiSoftware.it"</code> <code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>24</code></td>
<td><code>contentStream.endText();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>25</code></td>
<td><code>contentStream.close();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>26</code></td>
<td><code>doc.save(</code><code>"output.pdf"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>27</code></td>
<td><code>doc.close();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>28</code></td>
<td><code>} </code><code>catch</code> <code>(IOException e) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>29</code></td>
<td><code>e.printStackTrace();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>30</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>31</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>32</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>33</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>34</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Con il codice precedente viene creato un file pdf dal nome <em>output.pdf</em> che viene salvato nella directory root del nostro progetto, all’interno del quale viene scritta la Stringa che abbiamo passato all’oggetto PDPageContentStream. Come vediamo la prima cosa da fare è creare un documento PDF (istanza di PDDocument) e poi aggiungervi una pagina (istanza di PDPage) con il metodo addPage().</p>
<p>A questo punto istanziamo uno stream a cui passiamo come argomento il documento e la pagina su cui agire. Abbiamo inoltre settato un font (Helvetica_Bold) col metodo setFont (prima lo abbiamo definito utilizzando un campo statico della classe PDType1Font). Con il metodo moveTextPositionByAmount( x , y) posizioniamo il cursore da cui iniziare a scrivere, è importante notare che nei documenti PDF la posizione (0 , 0 ) rappresenta l’angolo in basso a sinistra. Dopo aver chiuso lo stream possiamo procedere al salvataggio con il metodo save(nomefile).</p>
<p>Scriviamo un’altra classe in cui andiamo ad aprire un file pdf già esistente, lo modifichiamo e lo scriviamo su di un altro file:</p>
<div id="highlighter_431640">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>package</code> <code>it.appuntisoftware;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>import</code> <code>java.io.IOException;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>import</code> <code>org.apache.pdfbox.exceptions.COSVisitorException;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>import</code> <code>org.apache.pdfbox.pdmodel.PDDocument;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>import</code> <code>org.apache.pdfbox.pdmodel.PDPage;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>import</code> <code>org.apache.pdfbox.pdmodel.edit.PDPageContentStream;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>import</code> <code>org.apache.pdfbox.pdmodel.font.PDFont;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>import</code> <code>org.apache.pdfbox.pdmodel.font.PDType1Font;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>public</code> <code>class</code> <code>TestPDFBox {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>public</code> <code>static</code> <code>void</code> <code>main(String[] args){</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>PDDocument doc = </code><code>null</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>15</code></td>
<td><code>try</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>16</code></td>
<td><code>{</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>17</code></td>
<td><code>doc = PDDocument.load(</code><code>"output.pdf"</code> <code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>18</code></td>
<td><code>PDPage page = (PDPage)doc.getDocumentCatalog().getAllPages().get(</code><code>0</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>19</code></td>
<td><code>PDPageContentStream contentStream = </code><code>new</code> <code>PDPageContentStream(doc, page, </code><code>true</code><code>, </code><code>true</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>20</code></td>
<td><code>PDFont font = PDType1Font.HELVETICA_BOLD;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>21</code></td>
<td><code>contentStream.beginText();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>22</code></td>
<td><code>contentStream.setFont( font, </code><code>12</code> <code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>23</code></td>
<td><code>contentStream.moveTextPositionByAmount( </code><code>260</code><code>, </code><code>700</code> <code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>24</code></td>
<td><code>contentStream.drawString( </code><code>"!!!!!"</code> <code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>25</code></td>
<td><code>contentStream.endText();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>26</code></td>
<td><code>contentStream.close();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>27</code></td>
<td><code>doc.save(</code><code>"outputMod.pdf"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>28</code></td>
<td><code>doc.close();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>29</code></td>
<td><code>} </code><code>catch</code> <code>(IOException e) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>30</code></td>
<td><code>e.printStackTrace();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>31</code></td>
<td><code>} </code><code>catch</code> <code>(COSVisitorException e) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>32</code></td>
<td><code>e.printStackTrace();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>33</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>34</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>35</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Le differenze con il precedente esempio sono l’utilizzo di PDDocument.load(nomefile) con il quale carichiamo in memoria il file  e con doc.getDocumentCatalog().getAllPages().get(indexpagina) recuperiamo la lista di tutte le pagine e ci posizioniamo sulla prima.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/KJf_DpkRkECAP66p2szfIQ6HGD0/0/da"><img src="http://feedads.g.doubleclick.net/~a/KJf_DpkRkECAP66p2szfIQ6HGD0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/KJf_DpkRkECAP66p2szfIQ6HGD0/1/da"><img src="http://feedads.g.doubleclick.net/~a/KJf_DpkRkECAP66p2szfIQ6HGD0/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/2fkm1vItowk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/apache-pdfbox-una-libreria-java-per-lavorare-con-i-documenti-pdf-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/apache-pdfbox-una-libreria-java-per-lavorare-con-i-documenti-pdf-2/</feedburner:origLink></item>
		<item>
		<title>Leggere un file XML in Java con la libreria JDOM</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/6hOQZWp2Q00/</link>
		<comments>http://www.danieleserio.it/leggere-un-file-xml-in-java-con-la-libreria-jdom-2/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 08:03:56 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[Guide e Tutorial]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programmazione]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2282</guid>
		<description><![CDATA[In questo post vedremo come poter leggere e scrivere un file XML in Java utilizzando la libreria JDOM. JDOM è una API Open Source, sviluppata da Brett McLaughlin e Jason Hunter, la quale interagisce con gli standard già esistenti quali SAX (Simple Api for XML) e DOM (Document Object Model), il cui obiettivo non è quello [...]]]></description>
			<content:encoded><![CDATA[<p>In questo post vedremo come poter leggere e scrivere un file XML in Java utilizzando la libreria JDOM. JDOM è una API Open Source, sviluppata da Brett McLaughlin e Jason Hunter, la quale interagisce con gli standard già esistenti quali SAX (Simple Api for XML) e DOM (Document Object Model), il cui obiettivo non è quello di creare uno strato di astrazione aggiuntivo o di potenziamento delle funzionalità di queste API, ma bensì quello di fornire un modello e degli strumenti che siano più familiari ad un programmatore Java, rendendo meno complessa e meno esigente di risorse la manipolazione di file XML.<span id="more-2282"></span></p>
<p>La versione che prendiamo in esame in questo articolo è la 1.1.1 (la più recente nel momento in cui scriviamo) nella quale è stato aggiunto il supporto alla Virtual Machine Dalvik (la VM di Android).</p>
<p>Per scaricarla possiamo farlo da questa URL:</p>
<p><a href="http://www.jdom.org/dist/binary/">http://www.jdom.org/dist/binary/</a></p>
<p>Iniziamo a vedere le classi basilari di questa libreria: l’istanza della classe <em>org.jdom.Document</em> è quella che rappresenterà il nostro documento XML una volta che sarà parserizzato. La prima cosa da notare è che tale classe non ha niente a che vedere con l’analogo Document del modello DOM (che in Java è implementato nelle API JAXP consultabili a questo indirizzo: <a href="http://download.oracle.com/javase/6/docs/technotes/guides/xml/index.html">http://download.oracle.com/javase/6/docs/technotes/guides/xml/index.html</a>), nè tanto meno le altre classi di JDOM che hanno un nome analogo (tra cui la classe <em>Element</em> o<em>Attribute</em>). Esse sono solo delle classi con le quali possiamo rappresentare una particolare “caratteristica” del nostro file XML, come ad esempio un Nodo, un Attributo, ecc…</p>
<p>Ritorniamo ora al nostro <em>Document, </em>il quale per essere istanziato ed associato ad un file XML ha bisogno dell’ausilio di un parser XML. Per istanziare ed utilizzare un Parser utilizziamo le classi Builder che possonoessere di due tipi:</p>
<ul>
<li>SAXBuilder;</li>
<li>DOMBuilder.</li>
</ul>
<p>come è facile intuire dai  nomi, il SaxBuilder caricherà ed effettuera il parsing di un documento XML utilizzando le API SAX, mentre il DOMBuilder utilizzerà il modello DOM. Entrambi i Builder utilizzano come default il Parser implementato in JAXP, il quale è incluso nella distribuzione Java e di conseguenza non dobbiamo aggiungere altre librerie al nostro progetto.</p>
<p>Il SAXBuilder accetta diversi tipi di formati in input, tramite il metodo overloaded <em>build()</em>, quali ad esempio un InputStream, un InputSource, un File, un URL o semplicemente una Stringa contenente il path del file XML, il DOMBuilder deve invece ricevere in input una istanza del documento XML già parserizzata secondo il modello DOM (un’istanza di<em>org.w3c.dom.Document</em>). Con il seguente codice istanziamo la classe Document a partire da un file XML parserizzato tramite SAX:</p>
<div id="highlighter_734502">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>SAXBuilder builder = </code><code>new</code> <code>SAXBuilder();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>Document doc = builder.build(</code><code>"rubrica.xml"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>E’ possibile validare il documento XML passando come parametro il valore <em>true</em> al costruttore del SAXBuilder (<em>new SAXBuilder(true)</em>). Se volessimo invece utilizzare un altro Parser quale ad esempio Xerces, allora dobbiamo specificare il nome della classe parser da utilizzare che nel caso di Xerces è<em> org.apache.xerces.parsers.SAXParser </em>e passarla al costruttore del SAXBuilder:</p>
<div id="highlighter_899239">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>SAXBuilder builder = </code><code>new</code><code>SAXBuilder(</code><code>"org.apache.xerces.parsers.SAXParser"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>ovviamente dobbiamo includere la libreria<em> xercesImpl.jar </em>(scaricabile dall’indirizzo <a href="http://xerces.apache.org/xerces-j/">http://xerces.apache.org/xerces-j/</a>) nel Build Path del progetto.</p>
<p>Ottenuto il Document possiamo navigare all’interno di esso in maniera molto facile utilizzando i metodi forniti dalle API JDOM: ad esempio possiamo ottenere l’elemento (nodo) radice con il seguente metodo:</p>
<div id="highlighter_753566">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>Element root = doc.getRootElement();</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>e su questo elemento andare a visionare i figli (del primo livello) con il metodo:</p>
<div id="highlighter_728794">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>List children = root.getChildren();</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>inoltre possiamo navigare su tutti i discendenti di un nodo utilizzando il seguente metodo:</p>
<div id="highlighter_779710">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>Iterator itr = doc.getDescendants();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>while</code> <code>(itr.hasNext()) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>Content c = (Content) itr.next();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>System.out.println(c);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>il metodo getDescendant() ritorna un iteratore il quale ci permette di scorrere tutti i discendenti in ordine. A tale metodo possiamo passare un Filter (ElementFilter) con il quale selezionare solo particolari tipi di Elementi, ad esempio con il seguente codice:</p>
<div id="highlighter_888273">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>itr = doc.getDescendants(</code><code>new</code> <code>ElementFilter());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>while</code> <code>(itr.hasNext()) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>Content c = (Content) itr.next();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>System.out.println(c);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Non specificando alcun valore per ElementFilter verranno selezionati solo i discendenti di tipo Element, se avessimo usato new ElementFilter(“contatto”), allora avremmo selezionato solo i discendenti con come elemento uguale a contatto (cioè con tag &lt;contatto&gt;).</p>
<p>I tipi di nodi che JDOM riconosce e mappa su di una sua classe sono i seguenti:</p>
<div id="attachment_1882"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/jdom-struct.gif"><img title="jdom struct" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/jdom-struct-240x300.gif" alt="jdom struct 240x300 Leggere un file XML in Java con la libreria JDOM" width="240" height="300" /></a></p>
<p>Le classi Core della libreria JDOM</p>
<p>Faremo ora un esempio concreto di utilizzo utilizzando Eclipse. Come sempre configuriamo un Progetto Java all’interno di Eclipse  cliccando su File -&gt; New -&gt; Java Project:</p>
<div id="attachment_1889"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/jdom1.png"><img title="jdom1" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/jdom1-226x300.png" alt="jdom1 226x300 Leggere un file XML in Java con la libreria JDOM" width="226" height="300" /></a></p>
<p>Nominiamo il nostro progetto TestJdom</p>
</div>
<p>poi creiamo una cartella lib e vi copiamo la libreria <em>jdom.jar</em>, non dimentichiamoci poi di includerla nel Build Path del nostro progetto: click col tasto destro -&gt; Build Path -&gt; Configure Build Path):</p>
<div id="attachment_1887"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/jdom2.png"><img title="jdom2" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/jdom2-300x244.png" alt="jdom2 300x244 Leggere un file XML in Java con la libreria JDOM" width="300" height="244" /></a></p>
<p>Includiamo JDOM nel Build Path del progetto</p>
</div>
<p>Creiamo una classe Java al suo interno e copiamo il codice seguente, il quale permette di leggere un file XML e di stampare i valori ed il tipo dei Nodi incontrati durante la visita del documento XML.</p>
<div id="highlighter_865380">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>package</code> <code>it.appuntisoftware;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>import</code> <code>java.io.IOException;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>import</code> <code>java.util.Iterator;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>import</code> <code>java.util.List;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>import</code> <code>org.jdom.Attribute;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>import</code> <code>org.jdom.CDATA;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>import</code> <code>org.jdom.Comment;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>import</code> <code>org.jdom.DocType;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>import</code> <code>org.jdom.Document;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>import</code> <code>org.jdom.Element;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>import</code> <code>org.jdom.JDOMException;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>import</code> <code>org.jdom.Text;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>import</code> <code>org.jdom.input.SAXBuilder;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>15</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>16</code></td>
<td><code>public</code> <code>class</code> <code>ReadXML {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>17</code></td>
<td><code>public</code> <code>static</code> <code>void</code> <code>main(String args[]){</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>18</code></td>
<td><code>SAXBuilder builder = </code><code>new</code> <code>SAXBuilder();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>19</code></td>
<td><code>Document doc;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>20</code></td>
<td><code>try</code> <code>{</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>21</code></td>
<td><code>doc = builder.build(</code><code>"rubrica.xml"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>22</code></td>
<td><code>listNodes(doc,</code><code>0</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>23</code></td>
<td><code>} </code><code>catch</code> <code>(IOException e) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>24</code></td>
<td><code>e.printStackTrace();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>25</code></td>
<td><code>} </code><code>catch</code> <code>(JDOMException e) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>26</code></td>
<td><code>e.printStackTrace();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>27</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>28</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>29</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>30</code></td>
<td><code>public</code> <code>static</code> <code>void</code> <code>listNodes(Object o, </code><code>int</code> <code>depth) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>31</code></td>
<td><code>stampaSpazi(depth);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>32</code></td>
<td><code>if</code> <code>(o </code><code>instanceof</code> <code>Element) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>33</code></td>
<td><code>Element element = (Element) o;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>34</code></td>
<td><code>if</code><code>(((Element) o).isRootElement())</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>35</code></td>
<td><code>System.out.println(</code><code>"Root Element:"</code><code>+ ((Element) o).getName());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>36</code></td>
<td><code>else</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>37</code></td>
<td><code>System.out.println(</code><code>"Element: "</code> <code>+ element.getName());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>38</code></td>
<td><code>//Itera sugli eventuali attributi dell'elemento</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>39</code></td>
<td><code>if</code><code>(!((Element) o).getAttributes().isEmpty()){</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>40</code></td>
<td><code>Iterator iter =element.getAttributes().iterator();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>41</code></td>
<td><code>while</code> <code>(iter.hasNext()) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>42</code></td>
<td><code>Object attribute = iter.next();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>43</code></td>
<td><code>listNodes(attribute, depth+</code><code>1</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>44</code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>45</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>46</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>47</code></td>
<td><code>//Itera sui figli dell'elemento</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>48</code></td>
<td><code>List children = element.getContent();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>49</code></td>
<td><code>Iterator iterator = children.iterator();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>50</code></td>
<td><code>while</code> <code>(iterator.hasNext()) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>51</code></td>
<td><code>Object child = iterator.next();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>52</code></td>
<td><code>listNodes(child, depth+</code><code>1</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>53</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>54</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>55</code></td>
<td><code>else</code> <code>if</code> <code>(o </code><code>instanceof</code> <code>Document) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>56</code></td>
<td><code>System.out.println(</code><code>"Document"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>57</code></td>
<td><code>Document doc = (Document) o;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>58</code></td>
<td><code>List children = doc.getContent();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>59</code></td>
<td><code>Iterator iterator = children.iterator();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>60</code></td>
<td><code>while</code> <code>(iterator.hasNext()) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>61</code></td>
<td><code>Object child = iterator.next();</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>62</code></td>
<td><code>listNodes(child, depth+</code><code>1</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>63</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>64</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>65</code></td>
<td><code>else</code> <code>if</code> <code>(o </code><code>instanceof</code> <code>Comment) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>66</code></td>
<td><code>System.out.println(</code><code>"Comment:"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>67</code></td>
<td><code>System.out.println(((Comment) o).getText());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>68</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>69</code></td>
<td><code>else</code> <code>if</code> <code>(o </code><code>instanceof</code> <code>CDATA) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>70</code></td>
<td><code>System.out.print(</code><code>"Sezione CDATA:"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>71</code></td>
<td><code>// CDATA è una sottoclasse di Text di conseguenza questo test</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>72</code></td>
<td><code>// va prima di quello per Text.</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>73</code></td>
<td><code>System.out.println(((CDATA) o).getText());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>74</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>75</code></td>
<td><code>else</code> <code>if</code> <code>(o </code><code>instanceof</code> <code>Text) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>76</code></td>
<td><code>System.out.print(</code><code>"Text:"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>77</code></td>
<td><code>System.out.println(((Text) o).getValue());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>78</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>79</code></td>
<td><code>else</code> <code>if</code> <code>(o </code><code>instanceof</code> <code>Attribute) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>80</code></td>
<td><code>System.out.print(</code><code>"Attribute:"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>81</code></td>
<td><code>System.out.print(((Attribute) o).getQualifiedName());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>82</code></td>
<td><code>System.out.println(((Attribute) o).getValue());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>83</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>84</code></td>
<td><code>else</code> <code>if</code> <code>(o </code><code>instanceof</code> <code>DocType) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>85</code></td>
<td><code>System.out.print(</code><code>"DocType:"</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>86</code></td>
<td><code>System.out.print(((DocType) o).getElementName());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>87</code></td>
<td><code>System.out.println(((DocType) o).getPublicID());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>88</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>89</code></td>
<td><code>else</code> <code>{</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>90</code></td>
<td><code>System.out.println(</code><code>"Tipo non previsto: "</code> <code>+ o.getClass());</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>91</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>92</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>93</code></td>
<td><code>private</code> <code>static</code> <code>void</code> <code>stampaSpazi(</code><code>int</code> <code>n) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>94</code></td>
<td><code>for</code> <code>(</code><code>int</code> <code>i = </code><code>0</code><code>; i &lt; n; i++) {</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>95</code></td>
<td><code>System.out.print(</code><code>' '</code><code>);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>96</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>97</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>98</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Possiamo provare questo programma utilizzando questo file XML, nel quale abbiamo inserito i tipi di Nodi più variegati possibili:</p>
<div id="highlighter_307417">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;?</code><code>xml</code> <code>version</code><code>=</code><code>"1.0"</code> <code>encoding</code><code>=</code><code>"UTF-8"</code><code>?&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>&lt;!DOCTYPE rubrica [</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>&lt;!ENTITY FS "Fisico"&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>]&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>&lt;</code><code>rubrica</code> <code>xmlns:xsi</code><code>=</code><code>"<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>&lt;!-- Rubrica Contatti --&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>&lt;</code><code>contatto</code> <code>id</code><code>=</code><code>"1"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>&lt;![CDATA[&lt;1° Contatto&gt;]]&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>&lt;</code><code>nome</code><code>&gt;Enrico&lt;/</code><code>nome</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>&lt;</code><code>cognome</code><code>&gt;Fermi&lt;/</code><code>cognome</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>&lt;</code><code>professione</code><code>&gt;&amp;FS;&lt;/</code><code>professione</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>&lt;/</code><code>contatto</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>&lt;</code><code>contatto</code> <code>id</code><code>=</code><code>"2"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>&lt;![CDATA[&lt;2° Contatto&gt;]]&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>15</code></td>
<td><code>&lt;</code><code>nome</code><code>&gt;Albert&lt;/</code><code>nome</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>16</code></td>
<td><code>&lt;</code><code>cognome</code><code>&gt;Einstein&lt;/</code><code>cognome</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>17</code></td>
<td><code>&lt;/</code><code>contatto</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>18</code></td>
<td><code>&lt;</code><code>contatto</code> <code>id</code><code>=</code><code>"3"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>19</code></td>
<td><code>&lt;![CDATA[&lt;3° Contatto&gt;]]&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>20</code></td>
<td><code>&lt;</code><code>nome</code><code>&gt;Isaac&lt;/</code><code>nome</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>21</code></td>
<td><code>&lt;</code><code>cognome</code><code>&gt;Newton&lt;/</code><code>cognome</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>22</code></td>
<td><code>&lt;/</code><code>contatto</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>23</code></td>
<td><code>&lt;</code><code>contatto</code> <code>id</code><code>=</code><code>"4"</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>24</code></td>
<td><code>&lt;![CDATA[&lt;4° Contatto&gt;]]&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>25</code></td>
<td><code>&lt;</code><code>nome</code><code>&gt;Johannes&lt;/</code><code>nome</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>26</code></td>
<td><code>&lt;</code><code>cognome</code><code>&gt;Stark&lt;/</code><code>cognome</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>27</code></td>
<td><code>&lt;/</code><code>contatto</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>28</code></td>
<td><code>&lt;/</code><code>rubrica</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>una volta lanciato il programma vedremo apparire sulla Console in output numerose diciture di tipo Text: con degli spazi vuoti, ciò è dovuto al fatto che il Parser considera come nodo Text anche i simboli di andata a capo ( gli “\n” per farla breve) e li valorizza correttamente come vuoti, per evitare ciò il file XML non dovrebbe avere queste rimandi a capo ma dovrebbe essere un’unica sequenza di tag (poco leggibile se  fosse riportata su questo articolo). Fatta questa precisazione di carattere per lo più estetico ma che non cambia nulla dal punto di vista funzionale, entriamo nel dettaglio dell’esempio: una volta ottenuto il Document dal SAXBuilder, utilizziamo una funzione ricorsiva per scorrere tutti i nodi dell’albero XML. A seconda del nodo incontrato ne stampiamo il tipo ed il valore contenuto.</p>
<p>Nel caso di Nodi di tipo Element, verifichiamo se essi abbiano degli attributi e stampiamo a video sia il loro nome che il valore contenuto. Ogni elemento contatto ha poi un nodo di tipo CDATA che viene correttamente interpretato dalla libreria JDOM, infatti esso contiene dei caratteri quali le virgolette &lt; e &gt; ed il simbolo ° che darebbero errore se inseriti in un tag XML (in CDATA possiamo inserire qualsiasi carattere dato che essi vengono sempre interpretati come sequenze di caratteri).</p>
<p>Un’altra particolarità è data dalla presenza di un valore (&amp;FS; presente nel tag &lt;professione&gt;) collegato ad un tag Entity (Entity Reference) , il quale viene correttamente interpretato e sostituito col valore della Entity (nel nostro caso il valore “Fisico”). Infine vengono correttamente stampati sia i valori dei Comment che del DocType.</p>
</div>

<p><a href="http://feedads.g.doubleclick.net/~a/cpsLnpYvXMmf0t4u8Rpzafbumv8/0/da"><img src="http://feedads.g.doubleclick.net/~a/cpsLnpYvXMmf0t4u8Rpzafbumv8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/cpsLnpYvXMmf0t4u8Rpzafbumv8/1/da"><img src="http://feedads.g.doubleclick.net/~a/cpsLnpYvXMmf0t4u8Rpzafbumv8/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/6hOQZWp2Q00" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/leggere-un-file-xml-in-java-con-la-libreria-jdom-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/leggere-un-file-xml-in-java-con-la-libreria-jdom-2/</feedburner:origLink></item>
		<item>
		<title>Creare un file eseguibile .exe per le applicazioni Java con Launch4j</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/hs_VLkccjKE/</link>
		<comments>http://www.danieleserio.it/creare-un-file-eseguibile-exe-per-le-applicazioni-java-con-launch4j-2/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 07:59:39 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[Guide e Tutorial]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programmazione]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2279</guid>
		<description><![CDATA[In questo articolo vedremo come poter creare un file .exe (un eseguibile in ambiente Windows) che permetta il lancio di una applicazione Java semplicemente facendo un doppio click su di esso, come avviene per qualsiasi applicazione Windows nativa. Possiamo raggiungere questo scopo utilizzando un applicazione cross-platform (è disponibile oltre che per Windows anche per Linux, [...]]]></description>
			<content:encoded><![CDATA[<p>In questo articolo vedremo come poter creare un file .exe (un eseguibile in ambiente Windows) che permetta il lancio di una applicazione Java semplicemente facendo un doppio click su di esso, come avviene per qualsiasi applicazione Windows nativa. Possiamo raggiungere questo scopo utilizzando un applicazione cross-platform (è disponibile oltre che per Windows anche per Linux, MacOs e Solaris) che si chiama Launch4j.<span id="more-2279"></span></p>
<p>Launch4j è un progetto Open Source ospitato sul sito SourceForge<a href="http://sourceforge.net/projects/launch4j/">http://sourceforge.net/projects/launch4j/</a>.</p>
<p>Tipicamente una applicazione Java consiste di una serie di file .class raggruppati per essere distribuiti, in un archivio .jar corredato da un file Manifest che descrive la <em>Main-Class</em>dell’archivio (cioè dove si trova il metodo main della nostra applicazione) ed eventualmente indica se bisogna includere altri file .jar nel classpath (utilizzando la direttiva classpath).</p>
<p>Un esempio di  file Manifest è il seguente:</p>
<div id="highlighter_91386">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>Manifest-Version: 1.0</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>Main-Class: it.appuntisoftware.testMain</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>Class-Path: appuntisoftware.jar</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>definito un opportuno Manifest per la nostra applicazione ed incluso nella cartella META-INF, possiamo eseguire l’applicazione con il seguente comando:</p>
<pre>java -jar applicazionediesempio.jar</pre>
<p>dunque bisogna aprire una console in Windows (Start -&gt; Esegui -&gt; cmd ) e digitare il comando sopra riportato, operazione non sempre banale per un utente medio di Windows.</p>
<p>Infatti non sempre il doppio click sul file .jar riesce a far eseguire l’applicazione in quanto il comando di default associato all’azione di doppio click prevede il solo passaggio del nome del  file .jar al comando <em>javaw.exe,</em> di conseguenza senza il parametro -jar viene visualizzato un errore Java del tipo:</p>
<pre>java.lang.NoClassDefFoundError: nomeapplicativo/jar</pre>
<p>In nostro aiuto viene Launch4j che permette la creazione di file .exe compatibili con Windows i quali possono includere totalmente il file .jar della nostra applicazione oppure possiamo scegliere di mantenere indipendente il file .jar.</p>
<p>Elenchiamo alcune delle caratteristiche offerte da Launch4j:</p>
<ul>
<li>possibilità di richiedere una particolare JRE (ad esempio una versione specifica) per l’esecuzione del nostro applicativo;</li>
<li>se una JRE non viene rilevata nel sistema dell’utente può essere indicato l’URL dal qual scaricare la JRE, aprendo una scheda del browser in automatico;</li>
<li>possibilità di includere una JRE nella distribuzione del nostro applicativo;</li>
<li>possibilità di visualizzare un’icona per il notro .exe;</li>
<li>possibilità di visualizzare uno Splash screen prima del lancio dell’applicazione e di settarne la durata;</li>
<li>possibilità di settare delle variabili di ambiente o di modificare i parametri con cui viene lanciata la JVM (ad esempio l’heap size);</li>
<li>customizzazione dei messaggi di errore.</li>
</ul>
<div id="attachment_1913"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/launch4j-use.gif"><img title="launch4j-use" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/launch4j-use-212x300.gif" alt="launch4j use 212x300 Creare un file eseguibile .exe per le applicazioni Java con Launch4j" width="212" height="300" /></a></p>
<p>Le possibili configurazioni offerte da Launch4j</p>
</div>
<p>Entriamo ora nei dettagli dell’applicativo, per far ciò bisogna dapprima scaricare ed installare il software Launch4j che possiamo trovare sul sito SourceForge:</p>
<p><a href="http://sourceforge.net/projects/launch4j/files/">http://sourceforge.net/projects/launch4j/files/</a></p>
<p>l’ultima versione è la 3.0.2 la quale è oggetto di questa prova.</p>
<p>Scaricata la corretta versione per il nostro S.O., lanciamo l’applicativo e dopo lo splash screen ci viene presentata la seguente schermata:</p>
<div id="attachment_1894"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/launch4j.png"><img title="launch4j" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/launch4j-258x300.png" alt="launch4j 258x300 Creare un file eseguibile .exe per le applicazioni Java con Launch4j" width="258" height="300" /></a></p>
<p>La schermata principale di Launch4j</p>
</div>
<p>in questa schermata definiamo le informazioni basilari per la creazione del nostro file .exe. Dobbiamo innanzitutto definire il nome ed il path dove verrà memorizzato del nostro file exe, dopo bisogna indicare il path del file .jar della nostra applicazione che si vuol rendere eseguibile.</p>
<p>La checkbox sottostante (<strong>Don’t wrap the jar, launch only</strong>) se non flaggata ingloberà il file .jar all’interno dell’exe in questo modo potremo distribuire il solo file .exe.</p>
<p>Se non è presente un file Manifest nel .jar dobbiamo indicarne uno esterno nel campo<strong>Manifest</strong>, mentre nel campo Icon indichiamo il file .ico che sarà l’icona del nostro file .exe.</p>
<p>Il parametro <strong>Change dir</strong> permette di specificare in quale directory spostarsi prima di eseguire l’applicazione: ciò è importante se l’applicazione fa riferimento a file utilizzando path relativi alla propria directory di esecuzione. Inserendo un punto (.) come valore Launch4j si sposterà nella directory dell’eseguibile prima di eseguire l’applicazione, altrimenti assume come directory di esecuzione quella dove è contenuto l’eseguibile<em> launch4j.exe</em> (tipicamente in C:\Programmi\Launch4j). In <strong>Command line args</strong> possiamo inserire tutti i parametri che l’applicazione deve ricevere da riga di comando.</p>
<p>Possiamo poi specificare il livello di priorità del processo in <strong>Process Priority </strong>e se customizzare il nome del processo. Infine se non viene rilevata una JRE compatibile con quella specificata nel tab JRE (che vedremo a breve) possiamo inserire il titolo dell’errore da lanciare (in <strong>Error Title</strong>) e l’URL da aprire nel browser per poter scaricare quella specifica JRE.</p>
<p>Esaminiamo ora la scheda JRE:</p>
<div id="attachment_1896"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/launch4j2.png"><img title="launch4j2" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/launch4j2-256x300.png" alt="launch4j2 256x300 Creare un file eseguibile .exe per le applicazioni Java con Launch4j" width="256" height="300" /></a></p>
<p>La scheda JRE</p>
</div>
<p>In essa possiamo specificare una eventuale JRE da includere nel nostro bundle tramite il campo Bundled JRE Path, nel quale indicheremo il path in cui si trova una JRE che abbiamo scaricato in formato .exe.</p>
<p>Inoltre, anche se non indicato, è obbligatorio specificare una versione minima della JRE richiesta (<strong>Min JRE version</strong>), mentre è opzionale indicare la massima (<strong>Max JRE version</strong>).</p>
<p>Possiamo inoltre indicare la dimensione dell’Heap da riservare all’inizio e quella massima sia in termini di MegaByte o in termini percentuali della memoria disponibile (<strong>Initial e Max Heap size</strong>).</p>
<p>Visualizziamo la scheda Splash:</p>
<div id="attachment_1897"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/launch4j3.png"><img title="launch4j3" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/launch4j3-257x300.png" alt="launch4j3 257x300 Creare un file eseguibile .exe per le applicazioni Java con Launch4j" width="257" height="300" /></a></p>
<p>La scheda Splash</p>
</div>
<p>In questa scheda possiamo abilitare la visualizazzione di uno splash screen prima del lancio del nostro applicativo, ne indichiamo il path dell’immagine ed il timeout di durata.</p>
<p>Esaminiamo la scheda Messages:</p>
<div id="attachment_1898"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/launch4j4.png"><img title="launch4j4" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/launch4j4-256x300.png" alt="launch4j4 256x300 Creare un file eseguibile .exe per le applicazioni Java con Launch4j" width="256" height="300" /></a></p>
<p>La scheda Messages</p>
</div>
<p>Nella scheda Messagges possiamo specificare e customizzare tutti i messaggi di errore che l’applicativo .exe può lanciare.</p>
<p>Infine vediamo la scheda Single Instance:</p>
<div id="attachment_1899"><a href="http://www.appuntisoftware.it/wp-content/uploads/2011/06/launch4j5.png"><img title="launch4j5" src="http://www.appuntisoftware.it/wp-content/uploads/2011/06/launch4j5-255x300.png" alt="launch4j5 255x300 Creare un file eseguibile .exe per le applicazioni Java con Launch4j" width="255" height="300" /></a></p>
<p>La scheda Single Instance</p>
</div>
<p>tramite questa scheda è possibile definire una variabile mutex in modo da permettere l’esecuzione di una singola istanza della nostra applicazione.</p>
<p>Una volta configurato il nostro applicativo dobbiamo salvare la configurazione in un file .xml tramite l’icona a forma di dischetto. Dopo aver salvato creiamo l’exe con il tasto a forma di rotellina e lo lanciamo col tasto play.</p>
<p>I file .xml di configurazione dell’applicativo sono di questo tipo:</p>
<div id="highlighter_613863">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;</code><code>launch4jConfig</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>&lt;</code><code>headerType</code><code>&gt;gui|console&lt;/</code><code>headerType</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>&lt;</code><code>outfile</code><code>&gt;file.exe&lt;/</code><code>outfile</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>&lt;</code><code>jar</code><code>&gt;file&lt;/</code><code>jar</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>&lt;</code><code>dontWrapJar</code><code>&gt;true|false&lt;/</code><code>dontWrapJar</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>&lt;</code><code>errTitle</code><code>&gt;text&lt;/</code><code>errTitle</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>&lt;</code><code>downloadUrl</code><code>&gt;<a href="http://java.com/download%3C/">http://java.com/download&lt;/</a></code><code>downloadUrl</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>&lt;</code><code>supportUrl</code><code>&gt;url&lt;/</code><code>supportUrl</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>&lt;</code><code>cmdLine</code><code>&gt;text&lt;/</code><code>cmdLine</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>&lt;</code><code>chdir</code><code>&gt;path&lt;/</code><code>chdir</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>&lt;</code><code>priority</code><code>&gt;normal|idle|high&lt;/</code><code>priority</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>&lt;</code><code>customProcName</code><code>&gt;true|false&lt;/</code><code>customProcName</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>&lt;</code><code>stayAlive</code><code>&gt;true|false&lt;/</code><code>stayAlive</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>&lt;</code><code>icon</code><code>&gt;file&lt;/</code><code>icon</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>15</code></td>
<td><code>&lt;</code><code>obj</code><code>&gt;header object file&lt;/</code><code>obj</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>16</code></td>
<td><code>...</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>17</code></td>
<td><code>&lt;</code><code>lib</code><code>&gt;w32api lib&lt;/</code><code>lib</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>18</code></td>
<td><code>...</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>19</code></td>
<td><code>&lt;</code><code>var</code><code>&gt;var=text&lt;/</code><code>var</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>20</code></td>
<td><code>...</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>21</code></td>
<td><code>&lt;</code><code>classPath</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>22</code></td>
<td><code>&lt;</code><code>mainClass</code><code>&gt;main class&lt;/</code><code>mainClass</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>23</code></td>
<td><code>&lt;</code><code>cp</code><code>&gt;classpath&lt;/</code><code>cp</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>24</code></td>
<td><code>...</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>25</code></td>
<td><code>&lt;/</code><code>classPath</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>26</code></td>
<td><code>&lt;</code><code>singleInstance</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>27</code></td>
<td><code>&lt;</code><code>mutexName</code><code>&gt;text&lt;/</code><code>mutexName</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>28</code></td>
<td><code>&lt;</code><code>windowTitle</code><code>&gt;text&lt;/</code><code>windowTitle</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>29</code></td>
<td><code>&lt;/</code><code>singleInstance</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>30</code></td>
<td><code>&lt;</code><code>jre</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>31</code></td>
<td><code>&lt;!-- Specify one of the following or both --&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>32</code></td>
<td><code>&lt;</code><code>path</code><code>&gt;bundled JRE path&lt;/</code><code>path</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>33</code></td>
<td><code>&lt;</code><code>minVersion</code><code>&gt;x.x.x[_xx]&lt;/</code><code>minVersion</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>34</code></td>
<td><code>&lt;</code><code>maxVersion</code><code>&gt;x.x.x[_xx]&lt;/</code><code>maxVersion</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>35</code></td>
<td><code>&lt;</code><code>jdkPreference</code><code>&gt;jreOnly|preferJre|preferJdk|jdkOnly&lt;/</code><code>jdkPreference</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>36</code></td>
<td><code>&lt;!-- Heap sizes in MB and % of free memory --&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>37</code></td>
<td><code>&lt;</code><code>initialHeapSize</code><code>&gt;MB&lt;/</code><code>initialHeapSize</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>38</code></td>
<td><code>&lt;</code><code>initialHeapPercent</code><code>&gt;%&lt;/</code><code>initialHeapPercent</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>39</code></td>
<td><code>&lt;</code><code>maxHeapSize</code><code>&gt;MB&lt;/</code><code>maxHeapSize</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>40</code></td>
<td><code>&lt;</code><code>maxHeapPercent</code><code>&gt;%&lt;/</code><code>maxHeapPercent</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>41</code></td>
<td><code>&lt;</code><code>opt</code><code>&gt;text&lt;/</code><code>opt</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>42</code></td>
<td><code>...</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>43</code></td>
<td><code>&lt;/</code><code>jre</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>44</code></td>
<td><code>&lt;</code><code>splash</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>45</code></td>
<td><code>&lt;</code><code>file</code><code>&gt;file&lt;/</code><code>file</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>46</code></td>
<td><code>&lt;</code><code>waitForWindow</code><code>&gt;true|false&lt;/</code><code>waitForWindow</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>47</code></td>
<td><code>&lt;</code><code>timeout</code><code>&gt;seconds [60]&lt;/</code><code>timeout</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>48</code></td>
<td><code>&lt;</code><code>timeoutErr</code><code>&gt;true|false&lt;/</code><code>timeoutErr</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>49</code></td>
<td><code>&lt;/</code><code>splash</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>50</code></td>
<td><code>&lt;</code><code>versionInfo</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>51</code></td>
<td><code>&lt;</code><code>fileVersion</code><code>&gt;x.x.x.x&lt;/</code><code>fileVersion</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>52</code></td>
<td><code>&lt;</code><code>txtFileVersion</code><code>&gt;text&lt;/</code><code>txtFileVersion</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>53</code></td>
<td><code>&lt;</code><code>fileDescription</code><code>&gt;text&lt;/</code><code>fileDescription</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>54</code></td>
<td><code>&lt;</code><code>copyright</code><code>&gt;text&lt;/</code><code>copyright</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>55</code></td>
<td><code>&lt;</code><code>productVersion</code><code>&gt;x.x.x.x&lt;/</code><code>productVersion</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>56</code></td>
<td><code>&lt;</code><code>txtProductVersion</code><code>&gt;text&lt;/</code><code>txtProductVersion</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>57</code></td>
<td><code>&lt;</code><code>productName</code><code>&gt;text&lt;/</code><code>productName</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>58</code></td>
<td><code>&lt;</code><code>companyName</code><code>&gt;text&lt;/</code><code>companyName</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>59</code></td>
<td><code>&lt;</code><code>internalName</code><code>&gt;filename&lt;/</code><code>internalName</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>60</code></td>
<td><code>&lt;</code><code>originalFilename</code><code>&gt;filename.exe&lt;/</code><code>originalFilename</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>61</code></td>
<td><code>&lt;/</code><code>versionInfo</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>62</code></td>
<td><code>&lt;</code><code>messages</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>63</code></td>
<td><code>&lt;</code><code>startupErr</code><code>&gt;text&lt;/</code><code>startupErr</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>64</code></td>
<td><code>&lt;</code><code>bundledJreErr</code><code>&gt;text&lt;/</code><code>bundledJreErr</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>65</code></td>
<td><code>&lt;</code><code>jreVersionErr</code><code>&gt;text&lt;/</code><code>jreVersionErr</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>66</code></td>
<td><code>&lt;</code><code>launcherErr</code><code>&gt;text&lt;/</code><code>launcherErr</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>67</code></td>
<td><code>&lt;/</code><code>messages</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>68</code></td>
<td><code>&lt;/</code><code>launch4jConfig</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>come possiamo notare i tag hanno un nome molto simile a quello presente nei campi delle varie schede di launch4j.</p>
<p>Resta solo un’ultima precisazione da fare nell’utilizzo di Launch4j, nel caso avessimo dei programmi che visualizzano dell’output in console non possiamo utilizzare il tool grafico ma dobbiamo lanciare la modalità da console tramite il comando launch4jc.exe. A questo applicativo va passato come input un file di configurazione come quello visto in precedenza dove nel campo headerType dobbiamo specificare il valore console:</p>
<div id="highlighter_333468">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;</code><code>headerType</code><code>&gt;console&lt;/</code><code>headerType</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Ad esempio un file xml minimale per un applicativo Java che funziona esclusivamente da console è il seguente:</p>
<div id="highlighter_501182">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>&lt;</code><code>launch4jConfig</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>&lt;</code><code>dontWrapJar</code><code>&gt;false&lt;/</code><code>dontWrapJar</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>&lt;</code><code>headerType</code><code>&gt;console&lt;/</code><code>headerType</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>4</code></td>
<td><code>&lt;</code><code>jar</code><code>&gt;C:\testlaunch4j\test.jar&lt;/</code><code>jar</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>5</code></td>
<td><code>&lt;</code><code>outfile</code><code>&gt;C:\testlaunch4j\test.exe&lt;/</code><code>outfile</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>6</code></td>
<td><code>&lt;</code><code>chdir</code><code>&gt;.&lt;/</code><code>chdir</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>7</code></td>
<td><code>&lt;</code><code>priority</code><code>&gt;normal&lt;/</code><code>priority</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>8</code></td>
<td><code>&lt;</code><code>downloadUrl</code><code>&gt;<a href="http://java.com/download%3C/">http://java.com/download&lt;/</a></code><code>downloadUrl</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>9</code></td>
<td><code>&lt;</code><code>supportUrl</code><code>&gt;&lt;/</code><code>supportUrl</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>10</code></td>
<td><code>&lt;</code><code>customProcName</code><code>&gt;true&lt;/</code><code>customProcName</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>11</code></td>
<td><code>&lt;</code><code>stayAlive</code><code>&gt;false&lt;/</code><code>stayAlive</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>12</code></td>
<td><code>&lt;</code><code>jre</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>13</code></td>
<td><code>&lt;</code><code>path</code><code>&gt;&lt;/</code><code>path</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>14</code></td>
<td><code>&lt;</code><code>minVersion</code><code>&gt;1.5.0&lt;/</code><code>minVersion</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>15</code></td>
<td><code>&lt;</code><code>maxVersion</code><code>&gt;&lt;/</code><code>maxVersion</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>16</code></td>
<td><code>&lt;</code><code>jdkPreference</code><code>&gt;preferJre&lt;/</code><code>jdkPreference</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>17</code></td>
<td><code>&lt;/</code><code>jre</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>18</code></td>
<td><code>&lt;/</code><code>launch4jConfig</code><code>&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>dove <em>test.jar</em> è l’applicazione Java e <em>test.exe</em> il file .exe di output. Scritto il file xml diamo il seguente comando per generare il file .exe:</p>
<p>LAUNCH4J_PATH\launch4jc.exe config.xml</p>
<p>dove LAUNCH4J_PATH è il path di installazione di launch4j (tipicamente C:\Programmi\Launch4j su Windows) e config.xml è il nome del file xml di configurazione che possiamo anche generare utilizzando il tool grafico e poi cambiando il valore dell’<em>headerType</em>da <em>gui</em> a <em>console.</em></p>
<p><strong>Riferimenti</strong></p>
<p>Sito web di Launch4j: <a href="http://launch4j.sourceforge.net/">http://launch4j.sourceforge.net/</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/GrSY9w173zleBozjoMZzfG_a6tc/0/da"><img src="http://feedads.g.doubleclick.net/~a/GrSY9w173zleBozjoMZzfG_a6tc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/GrSY9w173zleBozjoMZzfG_a6tc/1/da"><img src="http://feedads.g.doubleclick.net/~a/GrSY9w173zleBozjoMZzfG_a6tc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/hs_VLkccjKE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/creare-un-file-eseguibile-exe-per-le-applicazioni-java-con-launch4j-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/creare-un-file-eseguibile-exe-per-le-applicazioni-java-con-launch4j-2/</feedburner:origLink></item>
		<item>
		<title>Occhi puntati sul razzo italiano Vega, pronto al lancio</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/O4-9s1uS4o8/</link>
		<comments>http://www.danieleserio.it/occhi-puntati-sul-razzo-italiano-vega-pronto-al-lancio/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 23:03:29 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[Informatica & Tecnologia]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2258</guid>
		<description><![CDATA[Con un ultimo trasporto del satellite Lares sul vettore il 24 gennaio scorso, il razzo Vega già posizionato sulla rampa di lancio della base Esa di Kourou, in Guyana Francese, è ora completo e pronto ad affrontare l&#8217;ultima rassegna di test prima del lancio. Alto 30 metri e composto quasi interamente da carburante solido e [...]]]></description>
			<content:encoded><![CDATA[<p>Con un ultimo trasporto del <strong>satellite Lares</strong> sul vettore il 24 gennaio scorso, il razzo Vega già posizionato sulla rampa di lancio della base Esa di <strong>Kourou</strong>, in Guyana Francese, è ora <strong>completo e pronto</strong> ad affrontare l&#8217;ultima rassegna di test prima del lancio.</p>
<p>Alto <strong>30 metri</strong> e composto quasi interamente da <strong>carburante solido e liquido</strong> con relativi bruciatori, l&#8217;ultima parte arrivata è l&#8217;ogiva che contiene<strong> i satelliti che saranno immessi in orbita</strong> nel suo primo lancio.<br /><span id="more-2258"></span><br /><strong>Lares </strong>è il nome del satellite principale, commissionato da Asi a <strong>Cgs </strong>(gruppo <strong>Ohb</strong>, già responsabile di <strong>Galileo </strong>e <strong>Agile</strong>) costituito interamente di titanio e specchi riflettenti, grande quanto un pallone da basket ma incredibilmente pesante: infatti pesa ben 387 kg, fatto che lo rende <strong>l&#8217;oggetto più denso dell&#8217;intero sistema solare.</strong></p>
<p>La funzione di Lares rasenta la <strong>fantascienza</strong>, infatti dovrà misurare la <strong>distorsione spazio-temporale</strong> indotta dalla rotazione terrestre, tramite il riflesso di raggi laser sparati da terra. Ma non sarà da solo.</p>
<p>Insieme a Lares, Vega porterà in orbita anche sette altri piccoli satelliti, chiamati <strong>Cubesat</strong>, racchiusi in altrettante scatole. Si tratta di satelliti scientifici progettati dagli studenti di varie <strong>università </strong>europee, tra cui quella di <strong>Bologna </strong>con il suo <strong>Almasat-1</strong>.</p>
<p>Buona parte di Vega, un cilindro di 3 metri per 10 metri, è costituito dal <strong>motore P80</strong>, pieno di carburante allo stato solido, fabbricato direttamente nella base di Kourou negli stabilimenti Avio/ Safran. Al momento della partenza, questo primo motore <strong>brucerà il suo carico di 88 tonnellate </strong>di carburante <strong>in soli due minuti</strong> e una volta acceso non potrà più essere spento.</p>
<p>Gli altri due stadi del razzo forniranno ulteriore spinta e infine cederanno il controllo al quarto stadio, dotato di motore a carburante liquido, più preciso e in grado di essere acceso e spento fino a cinque volte, per liberare in orbite diverse i vari satelliti portati da Vega.</p>
<p>Progettare un razzo e tutte le strutture di terra per construirlo e approntarlo al lancio non è cosa da poco. Principale attore e responsabile della sua creazione è la società italiana <strong>Avio </strong>che, tramite la sua controllata <strong>Elv</strong>, ha coordinato <strong>40 aziende europee</strong> e ha progettato, sviluppato e prodotto gran parte del razzo stesso.</p>
<p>A terra, sfruttando parte delle strutture in precedenza usate dal razzo Ariane-1, la società italiana <strong>Vitrociset </strong>ha realizzato il segmento relativo alla rampa, alla base e alla campagna di lancio per il volo di qualifica.</p>
<p>E ancora <strong>Telespazio</strong>, con la sua consolidata presenza a Kourou, fornisce le basi per la  telemetria, radar, meteo e controllo; <strong>Cira </strong>fornisce algoritmi e studi di prestazioni di nuovi materiali e propulsori a liquido; <strong>Selex Galileo</strong> è responsabile della progettazione e produzione degli apparati del sottosistema di sicurezza (Sas).</p>
<p>La partecipazione italiana presentata da <strong>Asi </strong>ha portato il 63% di investimenti in Vega. Il nuovo lanciatore consente all&#8217;Europa e soprattutto al nostro Paese di disporre di una filiera produttiva del settore spaziale completa, in grado di progettare e realizzare dei <strong>sistemi &#8220;chiavi-in-mano&#8221; dai satelliti al lanciatore alle infrastruttura di terra</strong>, con evidenti quanto positive ricadute industriali.</p>
<p>Il<strong> lancio di Vega</strong> dalla base di lancio di Kourou (in Guyana francese) è<strong> previsto per il 9 febbraio</strong> ma la data potebbe slittare secondo le condizioni meteo.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/28MgWyL_LcV4OE0oy5JmLkb2Pnk/0/da"><img src="http://feedads.g.doubleclick.net/~a/28MgWyL_LcV4OE0oy5JmLkb2Pnk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/28MgWyL_LcV4OE0oy5JmLkb2Pnk/1/da"><img src="http://feedads.g.doubleclick.net/~a/28MgWyL_LcV4OE0oy5JmLkb2Pnk/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/O4-9s1uS4o8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/occhi-puntati-sul-razzo-italiano-vega-pronto-al-lancio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/occhi-puntati-sul-razzo-italiano-vega-pronto-al-lancio/</feedburner:origLink></item>
		<item>
		<title>Corpo celeste sulla Terra “Apophis”: anno dell’impatto il 2029</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/BQrQ6D_gLO4/</link>
		<comments>http://www.danieleserio.it/corpo-celeste-sulla-terra-apophis-anno-dellimpatto-il-2029/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 23:02:01 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[Informatica & Tecnologia]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2254</guid>
		<description><![CDATA[ Uno scenario hollywoodiano, ma non tanto da essere considerato irrealistico dall&#8217;Esa. Per questo l&#8217;Agenzia spaziale europea sta valutando l&#8217;ipotesi dell&#8217;impatto di un corpo celeste sulla Terra e ha deciso di investire milioni di euro per proteggere il globo, ipotizzando tre diversi scenari e relativi strumenti per deviarne la traiettoria. Il nome del piano d&#8217;attacco è [...]]]></description>
			<content:encoded><![CDATA[<div id="su_moduli">
<div> Uno<strong> scenario hollywoodiano</strong>, ma non tanto da essere considerato irrealistico dall&#8217;Esa. Per questo<strong> l&#8217;Agenzia spaziale europea</strong> sta valutando l&#8217;ipotesi dell&#8217;impatto di un corpo celeste sulla Terra e ha deciso di investire milioni di euro per proteggere il globo, ipotizzando tre diversi scenari e relativi strumenti per deviarne la traiettoria.</div>
</div>
<p>Il nome del piano d&#8217;attacco è<strong> Neosh</strong>ield, che sta per Near Earth Objects Shield, mentre l&#8217;asteroide in questione,<strong> 1000 chilometri di diametro</strong>, sarebbe stato già battezzato <strong>Apophis</strong>: anno dell&#8217;impatto il<strong> 2029</strong>.</p>
<p><span id="more-2254"></span></p>
<p>Il primo scenario prevede di inviare una sonda spaziale che colpisca l&#8217;asteroide a tutta velocità; il secondo ipotizza invece la deviazione indiretta della traiettoria del corpo celeste, con l&#8217;invio di una sonda il più vicino possibile all&#8217;asteroide, con l&#8217;obiettivo di restargli al fianco per diversi anni e attirarlo gravitazionalmente lontano dalla Terra; il terzo scenario invece, il più controverso, rappresenta<strong> &#8220;l&#8217;ultima spiaggia&#8221;:</strong> consiste nel far esplodere una carica nucleare vicinissimo all&#8217;asteroide.</p>
<p>In ogni caso, lo studio avviato dall&#8217;Esa non sembra essere una semplice esercitazione di stile, precisa Le Matin: &#8220;Il rischio che un asteroide incroci la traiettoria della Terra <strong>esiste ed è concreto</strong>&#8220;, affermava già nel 2008 Willy Benz, astrofisico e presidente della commissione scientifica dell&#8217;Esa.</p>
<p>Apophis passerà molto vicino alla Terra (circa 37 000 km) il 13 aprile 2029. La deflessione della sua traiettoria per effetto della gravità terrestre, in quel momento, aumenterà enormemente l&#8217;incertezza sulla sua orbita, rendendo difficile predire una possibile futura collisione con la Terra. Vi sono diverse date che (come il 31 luglio) hanno una leggera possibilità di impatto. In particolare, il 13 aprile 2036 ha una probabilità di impatto pari a 0,00012, con minori probabilità per il 14 aprile 2035 e per il 13 aprile 2037 [3]. Poiché il diametro di Apophis è di 320 m, l&#8217;asteroide potrebbe avere effetti distruttivi su un&#8217;ampia area locale. Apophis effettuerà passaggi ravvicinati (a circa 0,1 Unità Astronomiche (AU)) nel 2013 e nel 2021, che consentiranno accurate misurazioni della sua orbita.</p>
<p><strong>Cosa potrebbe succedere all&#8217;impatto sulla Terra?</strong></p>
<p>Nello scenario ipotizzato, in accordo con la Nasa, era stabilito che la palla di ferro e di iridio, di 320 metri di larghezza e 200 miliardi di tonnellate di peso, potrebbe cadere a pezzi nell&#8217;Oceano Atlantico, creando un enorme tsunami, distruggendo coste e zone interne, creando una fitta nube di polvere che andrebbe ad oscurare il cielo del nostro pianeta per un tempo indeterminato&#8230;</p>
<p style="text-align: center;"><a href="http://www.danieleserio.it/wp-content/uploads/2012/01/apophis1.jpg"><span style="color: #000000;"><br /></span><img class="size-medium wp-image-2263" title="apophis1" src="http://www.danieleserio.it/wp-content/uploads/2012/01/apophis1-300x226.jpg" alt="" width="300" height="226" /></a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/UHWRDbqypaqdBzzpKoZXaV077xw/0/da"><img src="http://feedads.g.doubleclick.net/~a/UHWRDbqypaqdBzzpKoZXaV077xw/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/UHWRDbqypaqdBzzpKoZXaV077xw/1/da"><img src="http://feedads.g.doubleclick.net/~a/UHWRDbqypaqdBzzpKoZXaV077xw/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/BQrQ6D_gLO4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/corpo-celeste-sulla-terra-apophis-anno-dellimpatto-il-2029/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/corpo-celeste-sulla-terra-apophis-anno-dellimpatto-il-2029/</feedburner:origLink></item>
		<item>
		<title>Come creare una mappa con GeoTools – un piccolo esempio</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/mvNvEJyWWSM/</link>
		<comments>http://www.danieleserio.it/come-creare-una-mappa-base-con-geotools/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 18:20:15 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[GeoTools]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programmazione]]></category>

		<guid isPermaLink="false">http://www.danieleserio.it/?p=2122</guid>
		<description><![CDATA[Vi presento un piccolo tutorial per poter creare una piccola applicazione base per la visualizzazione di un file SHAPE a video. La mappa creata ha le funzionalità base di un sistema GIS. In questo esempio ho utilizzato la libreria GeoTools versione 8 scaricabile liberamente dal sito ufficiale. Presto on line nuovi esempi più complessi.  package it.danieleserio.gis; import [...]]]></description>
			<content:encoded><![CDATA[<p>Vi presento un piccolo tutorial per poter creare una piccola applicazione base per la visualizzazione di un file SHAPE a video. La mappa creata ha le funzionalità base di un sistema GIS. In questo esempio ho utilizzato la libreria <strong>GeoTools</strong> versione 8 scaricabile liberamente dal sito ufficiale. Presto on line nuovi esempi più complessi.<img title="Continua..." src="http://www.danieleserio.it/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" alt="" /> <span id="more-2122"></span></p>
<pre class="brush:java">package it.danieleserio.gis;

import java.io.File;
import java.util.Locale;

import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapContent;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.data.JFileDataStoreChooser;
import org.geotools.swing.locale.LocaleUtils;

/**
 * Questa è una semplice applicazione GUI con SWING e GeoTools per la visualizzazione di un singolo SHAPE FILE
 * e lo visualizza in una finestra con controlli base.
 * */
public class ApplicazioneDemo {

    public static void main(String[] args) throws Exception {
    	LocaleUtils.setLocale(Locale.ITALIAN);

    	//Mostra la finestra di scelta del file SHAPE
        File file = JFileDataStoreChooser.showOpenFile("shp", null);
        if (file == null) {
            return;
        }

        FileDataStore store = FileDataStoreFinder.getDataStore(file);
        SimpleFeatureSource featureSource = store.getFeatureSource();

        //Crea la mappa
        MapContent map = new MapContent();
        map.setTitle("Applicazione Demo - www.DanieleSerio.it ver. 1.0");

        Style style = SLD.createSimpleStyle(featureSource.getSchema());
        Layer layer = new FeatureLayer(featureSource, style);
        map.addLayer(layer);

        //Visualizza la finestra con la mappa
        JMapFrame.showMap(map);
    }

}</pre>
<p><a href="http://www.danieleserio.it/wp-content/uploads/2012/01/winDemo1.png"><br /></a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/N6OMV6m4qvPMddWrpB-kRxBsxi8/0/da"><img src="http://feedads.g.doubleclick.net/~a/N6OMV6m4qvPMddWrpB-kRxBsxi8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/N6OMV6m4qvPMddWrpB-kRxBsxi8/1/da"><img src="http://feedads.g.doubleclick.net/~a/N6OMV6m4qvPMddWrpB-kRxBsxi8/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/mvNvEJyWWSM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/come-creare-una-mappa-base-con-geotools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/come-creare-una-mappa-base-con-geotools/</feedburner:origLink></item>
		<item>
		<title>MicroOLED: nuovo mirino elettronico OLED da 5,2 megapixel</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/O_YFh-NoYKk/</link>
		<comments>http://www.danieleserio.it/microoled-nuovo-mirino-elettronico-oled-da-52-megapixel/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 18:10:37 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://feeds.hwupgrade.it/c/32480/f/477556/s/1c3fe1ea/l/0L0Sfotografidigitali0Bit0Cnews0Cmicrooled0Enuovo0Emirino0Eelettronico0Eoled0Eda0E50E20Emegapixel0I40A4870Bhtml/story01.htm</guid>
		<description><![CDATA[MicroOLED presenta nuovo mirino elettronico OLED da 5,2 megapixel, che porta la risoluzione a 16 milioni di colori a 1280&#215;1024 punti]]></description>
			<content:encoded><![CDATA[<p>MicroOLED presenta nuovo mirino elettronico OLED da 5,2 megapixel, che porta la risoluzione a 16 milioni di colori a 1280&#215;1024 punti<img src="http://feeds.hwupgrade.it/c/32480/f/477556/s/1c3fe1ea/mf.gif" alt="" width="1" height="1" border="0" /></p>
<p><a href="http://da.feedsportal.com/r/123995824287/u/192/f/477556/c/32480/s/1c3fe1ea/a2.htm"><img src="http://da.feedsportal.com/r/123995824287/u/192/f/477556/c/32480/s/1c3fe1ea/a2.img" alt="" border="0" /></a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/2kqtEZru5_k8QSYL5wMjBR-mEQg/0/da"><img src="http://feedads.g.doubleclick.net/~a/2kqtEZru5_k8QSYL5wMjBR-mEQg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/2kqtEZru5_k8QSYL5wMjBR-mEQg/1/da"><img src="http://feedads.g.doubleclick.net/~a/2kqtEZru5_k8QSYL5wMjBR-mEQg/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/O_YFh-NoYKk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/microoled-nuovo-mirino-elettronico-oled-da-52-megapixel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/microoled-nuovo-mirino-elettronico-oled-da-52-megapixel/</feedburner:origLink></item>
		<item>
		<title>Avira AntiVir Rescue System</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/1y0NC8qZ7Y4/</link>
		<comments>http://www.danieleserio.it/avira-antivir-rescue-system/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 18:01:01 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://feeds.hwupgrade.it/c/32480/f/477556/s/1ae77fcd/l/0L0Shwfiles0Bit0Cdownload0Cscheda0C47510Cavira0Eantivir0Erescue0Esystem0C/story01.htm</guid>
		<description><![CDATA[Avira AntiVir Rescue System è un&#8217;applicazione basata su sistema operativo Linux che permette di accedere ad un PC che viceversa non potrebbe completare la fase di boot con il sistema operativo installato. Questo permette, quantomeno in teoria, di riparare il sistema danneggiato, ricuperare i dati o eseguire&#8230;]]></description>
			<content:encoded><![CDATA[<p>Avira AntiVir Rescue System è un&#8217;applicazione basata su sistema operativo Linux che permette di accedere ad un PC che viceversa non potrebbe completare la fase di boot con il sistema operativo installato. Questo permette, quantomeno in teoria, di riparare il sistema danneggiato, ricuperare i dati o eseguire&#8230;<img src="http://feeds.hwupgrade.it/c/32480/f/477556/s/1ae77fcd/mf.gif" alt="" width="1" height="1" border="0" /></p>
<p><a href="http://da.feedsportal.com/r/121221268004/u/192/f/477556/c/32480/s/1ae77fcd/a2.htm"><img src="http://da.feedsportal.com/r/121221268004/u/192/f/477556/c/32480/s/1ae77fcd/a2.img" alt="" border="0" /></a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/EwyklV2wGKezn2vcDqzZsUUSo8E/0/da"><img src="http://feedads.g.doubleclick.net/~a/EwyklV2wGKezn2vcDqzZsUUSo8E/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/EwyklV2wGKezn2vcDqzZsUUSo8E/1/da"><img src="http://feedads.g.doubleclick.net/~a/EwyklV2wGKezn2vcDqzZsUUSo8E/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/1y0NC8qZ7Y4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/avira-antivir-rescue-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/avira-antivir-rescue-system/</feedburner:origLink></item>
		<item>
		<title>PlayStation 4, Sony: Gli ultimi ad annunciare qualcosa</title>
		<link>http://feedproxy.google.com/~r/danieleserio/LnTo/~3/oQgB6CvWSG0/</link>
		<comments>http://www.danieleserio.it/playstation-4-sony-gli-ultimi-ad-annunciare-qualcosa/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 13:55:39 +0000</pubDate>
		<dc:creator>Daniele Serio</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://feeds.hwupgrade.it/c/32480/f/477556/s/1c417428/l/0L0Sgamemag0Bit0Cnews0Cplaystation0E40Esony0Egli0Eultimi0Ead0Eannunciare0Equalcosa0I40A4930Bhtml/story01.htm</guid>
		<description><![CDATA[Il CEO della divisione francese Sony dice che la propria compagnia non si sente sotto pressione in vista dell&#8217;introduzione di una nuova generazione.]]></description>
			<content:encoded><![CDATA[<p>Il CEO della divisione francese Sony dice che la propria compagnia non si sente sotto pressione in vista dell&#8217;introduzione di una nuova generazione.<img width='1' height='1' src='http://feeds.hwupgrade.it/c/32480/f/477556/s/1c417428/mf.gif' border='0'/><br/><br/><a href="http://da.feedsportal.com/r/123995833804/u/192/f/477556/c/32480/s/1c417428/kg/279/a2.htm"><img src="http://da.feedsportal.com/r/123995833804/u/192/f/477556/c/32480/s/1c417428/kg/279/a2.img" border="0"/></a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/SEC8Dstvh0RYUFmCy2AY2nzIEZ0/0/da"><img src="http://feedads.g.doubleclick.net/~a/SEC8Dstvh0RYUFmCy2AY2nzIEZ0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/SEC8Dstvh0RYUFmCy2AY2nzIEZ0/1/da"><img src="http://feedads.g.doubleclick.net/~a/SEC8Dstvh0RYUFmCy2AY2nzIEZ0/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/danieleserio/LnTo/~4/oQgB6CvWSG0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.danieleserio.it/playstation-4-sony-gli-ultimi-ad-annunciare-qualcosa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.danieleserio.it/playstation-4-sony-gli-ultimi-ad-annunciare-qualcosa/</feedburner:origLink></item>
	</channel>
</rss>

